2 * glRead/DrawPixels test
6 #define GL_GLEXT_PROTOTYPES
12 static int Width
= 250, Height
= 250;
13 static GLfloat Zoom
= 1.0;
15 static void Init(void)
17 fprintf(stderr
, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
18 fprintf(stderr
, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
19 fprintf(stderr
, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
20 glClearColor(0.3, 0.1, 0.3, 0.0);
23 static void Reshape(int width
, int height
)
27 /* draw on left half (we'll read that area) */
28 glViewport(0, 0, Width
, height
);
29 glMatrixMode(GL_PROJECTION
);
31 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
32 glMatrixMode(GL_MODELVIEW
);
35 static void Key(unsigned char key
, int x
, int y
)
46 static void Draw(void)
48 GLfloat
*image
= (GLfloat
*) malloc(Width
* Height
* 4 * sizeof(GLfloat
));
50 glClear(GL_COLOR_BUFFER_BIT
);
52 glBegin(GL_TRIANGLES
);
54 glVertex3f(-0.9, -0.9, -30.0);
56 glVertex3f( 0.9, -0.9, -30.0);
58 glVertex3f( 0.0, 0.9, -30.0);
63 glVertex2f(-1.0, -1.0);
64 glVertex2f(-0.9, -1.0);
65 glVertex2f(-0.9, -0.9);
66 glVertex2f(-1.0, -0.9);
69 glReadPixels(0, 0, Width
, Height
, GL_RGBA
, GL_FLOAT
, image
);
70 printf("Pixel(0,0) = %f, %f, %f, %f\n",
71 image
[0], image
[1], image
[2], image
[3]);
72 /* draw to right half of window */
73 glWindowPos2iARB(Width
, 0);
74 glPixelZoom(Zoom
, Zoom
);
75 glDrawPixels(Width
, Height
, GL_RGBA
, GL_FLOAT
, image
);
81 int main(int argc
, char **argv
)
83 glutInit(&argc
, argv
);
84 glutInitWindowPosition(0, 0);
85 glutInitWindowSize(Width
*2, Height
);
86 glutInitDisplayMode(GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
);
87 if (glutCreateWindow(argv
[0]) == GL_FALSE
) {
96 glutReshapeFunc(Reshape
);
97 glutKeyboardFunc(Key
);
98 glutDisplayFunc(Draw
);