// Demonstrate correctness of OpenGL blit #include // Header File For Standard Input / Output #include // Header File For Variable Argument Routines #include // Header File For String Management #include #include // Header File For The OpenGL32 Library //#include // Header File For The GLu32 Library #include // Header File For The GLUT Library #include // Constants ----------------------------------------------------------------- #define kWindowWidth 600 #define kWindowHeight 600 int ww = kWindowWidth; int hh = kWindowHeight; GLuint fbIds[1] = {0}; GLuint rbIds[1] = {0}; // Function Prototypes ------------------------------------------------------- GLvoid InitGL(GLvoid); GLvoid DrawGLScene(GLvoid); GLvoid ReSizeGLScene(int Width, int Height); void glError(int ll) { int errnum = glGetError(); if (errnum != 0) { printf("OpenGL Error: %d %x\n", ll, errnum); switch (errnum) { case GL_INVALID_ENUM: printf("Invalid Enum\n"); break; case GL_INVALID_VALUE: printf("Invalid Value\n"); break; default: break; } } } // Main ---------------------------------------------------------------------- int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (kWindowWidth, kWindowHeight); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); InitGL(); glutDisplayFunc(DrawGLScene); glutReshapeFunc(ReSizeGLScene); glutMainLoop(); return 0; } // Init ---------------------------------------------------------------------- GLvoid InitGL(GLvoid) { printf("InitGL\n"); } // DrawGLScene --------------------------------------------------------------- GLvoid DrawGLScene(GLvoid) { printf("DrawGLScene\n"); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0, 0, 1, 0.5); glClear(GL_COLOR_BUFFER_BIT); } glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbIds[0]); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); glBlitFramebufferEXT(0, 0, ww, hh, 0, 0, ww, hh, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glFlush(); glError(999); } // ReSizeGLScene ------------------------------------------------------------ GLvoid ReSizeGLScene(int Width, int Height) { printf("Resize: %d %d\n", Width, Height); ww = Width; hh = Height; if (fbIds[0] == 0) { // The framebuffer has never been allocated glGenFramebuffersEXT(1, fbIds); } if (rbIds[0] != 0) { // Remove the renderbuffer if window has changed size glDeleteRenderbuffersEXT(1, rbIds); } glFlush(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbIds[0]); glGenRenderbuffersEXT(1, rbIds); glFlush(); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbIds[0]); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB8, ww, hh); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbIds[0]); glFlush(); int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { printf("Buffer not completed: %d\n", status); } glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glError(1999); }