progs/tests: also test stencil INCR_WRAP mode if supported
[mesa.git] / progs / tests / drawbuffers.c
index 8583bac0ddfec0dd14e0b09af62232683e7b7100..7a19933e6273e7795825846297bc118795f5d2ca 100644 (file)
@@ -7,11 +7,11 @@
  */
 
 
-#define GL_GLEXT_PROTOTYPES
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <GL/glew.h>
 #include <GL/glut.h>
 #include "extfuncs.h"
 
@@ -19,6 +19,7 @@ static int Win;
 static int Width = 400, Height = 400;
 static GLuint FBobject, RBobjects[3];
 static GLfloat Xrot = 0.0, Yrot = 0.0;
+static GLuint Program;
 
 
 static void
@@ -40,6 +41,10 @@ Display(void)
       GL_COLOR_ATTACHMENT1_EXT
    };
 
+   glUseProgram_func(Program);
+
+   glEnable(GL_DEPTH_TEST);
+
    /* draw to user framebuffer */
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject);
 
@@ -65,16 +70,23 @@ Display(void)
    glPopMatrix();
 
    /* read from user framebuffer */
-   /* bottom half = colorbuffer 0 */
+   /* left half = colorbuffer 0 */
    glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
-   glReadPixels(0, 0, Width, Height / 2, GL_RGBA, GL_UNSIGNED_BYTE,
+   glPixelStorei(GL_PACK_ROW_LENGTH, Width);
+   glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
+   glReadPixels(0, 0, Width / 2, Height, GL_RGBA, GL_UNSIGNED_BYTE,
                 buffer);
-   /* top half = colorbuffer 1 */
+
+   /* right half = colorbuffer 1 */
    glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
-   glReadPixels(0, Height/2, Width, Height / 2, GL_RGBA, GL_UNSIGNED_BYTE,
-                buffer + Width * Height / 2 * 4);
+   glPixelStorei(GL_PACK_SKIP_PIXELS, Width / 2);
+   glReadPixels(Width / 2, 0, Width - Width / 2, Height,
+                GL_RGBA, GL_UNSIGNED_BYTE,
+                buffer);
 
    /* draw to window */
+   glUseProgram_func(0);
+   glDisable(GL_DEPTH_TEST);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    glWindowPos2iARB(0, 0);
    glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
@@ -243,15 +255,15 @@ SetupShaders(void)
       "   gl_FragData[1] = vec4(1.0) - gl_Color; \n"
       "}\n";
 
-   GLuint fragShader, program;
+   GLuint fragShader;
 
    fragShader = LoadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText);
-   program = glCreateProgram_func();
+   Program = glCreateProgram_func();
 
-   glAttachShader_func(program, fragShader);
-   glLinkProgram_func(program);
-   CheckLink(program);
-   glUseProgram_func(program);
+   glAttachShader_func(Program, fragShader);
+   glLinkProgram_func(Program);
+   CheckLink(Program);
+   glUseProgram_func(Program);
 }
 
 
@@ -289,6 +301,7 @@ main(int argc, char *argv[])
    glutInitWindowSize(Width, Height);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    Win = glutCreateWindow(argv[0]);
+   glewInit();
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(Key);
    glutDisplayFunc(Display);