#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glxew.h>
#include <GL/glut.h>
static int theRes[2] = {256, 256};
static GLubyte theFB[256][256][4];
void glErrorCheck(char *s)
{
GLenum error;
while((error = glGetError()) != GL_NO_ERROR)
{
fprintf(stderr, "ERROR (%s): %s\n", s, (char *)gluErrorString(error));
}
}
void idle(void)
{
glutPostRedisplay();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
glDrawPixels(theRes[0], theRes[1], GL_RGBA, GL_UNSIGNED_BYTE, theFB);
glReadPixels(0, 0, theRes[0], theRes[1], GL_RGBA, GL_UNSIGNED_BYTE, theFB);
glutSwapBuffers();
}
void init(void)
{
GLenum err = glewInit();
if(err != GLEW_OK)
{
fprintf(stderr, "ERROR: %s\n", glewGetErrorString(err));
exit(1);
}
reshape(theRes[0], theRes[1]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
for(register int i = 0; i < theRes[1]; ++i) {
for(register int j = 0; j < theRes[0]; ++j) {
for(register int c = 0; c < 4; ++c) {
theFB[i][j][c] = (GLubyte) 127;
}
}
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(theRes[0], theRes[1]);
glutCreateWindow("Read buffer problem");
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
init();
glutMainLoop();
return(0);
}