2 * Test GL_EXT_framebuffer_object
9 #define GL_GLEXT_PROTOTYPES
16 static int Width
= 400, Height
= 400;
23 GLenum err
= glGetError();
25 printf("GL Error 0x%x at line %d\n", (int) err
, line
);
33 GLubyte
*buffer
= malloc(Width
* Height
* 4);
36 /* draw to user framebuffer */
37 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, MyFB
);
38 glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT
);
39 glReadBuffer(GL_COLOR_ATTACHMENT1_EXT
);
41 status
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
42 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
43 printf("Framebuffer incomplete!!!\n");
46 glClearColor(0.5, 0.5, 1.0, 0.0);
47 glClear( GL_COLOR_BUFFER_BIT
);
58 /* read from user framebuffer */
59 glReadPixels(0, 0, Width
, Height
, GL_RGBA
, GL_UNSIGNED_BYTE
, buffer
);
62 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
63 glWindowPos2iARB(0, 0);
64 glDrawPixels(Width
, Height
, GL_RGBA
, GL_UNSIGNED_BYTE
, buffer
);
72 Reshape( int width
, int height
)
74 float ar
= (float) width
/ (float) height
;
75 glViewport( 0, 0, width
, height
);
76 glMatrixMode( GL_PROJECTION
);
79 glFrustum( -ar
, ar
, -1.0, 1.0, 5.0, 25.0 );
81 glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
83 glMatrixMode( GL_MODELVIEW
);
85 glTranslatef( 0.0, 0.0, -15.0 );
88 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT
, GL_RGB
, Width
, Height
);
93 Key( unsigned char key
, int x
, int y
)
112 if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
113 printf("GL_EXT_framebuffer_object not found!\n");
116 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
118 glGenFramebuffersEXT(1, &MyFB
);
120 assert(glIsFramebufferEXT(MyFB
));
121 glDeleteFramebuffersEXT(1, &MyFB
);
122 assert(!glIsFramebufferEXT(MyFB
));
123 /* Note, continue to use MyFB below */
125 glGenRenderbuffersEXT(1, &rb
);
127 assert(glIsRenderbufferEXT(rb
));
128 glDeleteRenderbuffersEXT(1, &rb
);
129 assert(!glIsRenderbufferEXT(rb
));
130 rb
= 42; /* an arbitrary ID */
132 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, MyFB
);
133 assert(glIsFramebufferEXT(MyFB
));
134 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT
, rb
);
135 assert(glIsRenderbufferEXT(rb
));
137 glGetIntegerv(GL_RENDERBUFFER_BINDING_EXT
, &i
);
140 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT
, &i
);
143 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT
, GL_COLOR_ATTACHMENT1_EXT
,
144 GL_RENDERBUFFER_EXT
, rb
);
146 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT
, GL_RGB
, Width
, Height
);
150 glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT
,
151 GL_RENDERBUFFER_RED_SIZE_EXT
, &r
);
152 glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT
,
153 GL_RENDERBUFFER_GREEN_SIZE_EXT
, &g
);
154 glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT
,
155 GL_RENDERBUFFER_BLUE_SIZE_EXT
, &b
);
156 glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT
,
157 GL_RENDERBUFFER_ALPHA_SIZE_EXT
, &a
);
158 printf("renderbuffer RGBA sizes = %d %d %d %d\n", r
, g
, b
, a
);
161 CheckError(__LINE__
);
163 /* restore to default */
164 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0);
169 main( int argc
, char *argv
[] )
171 glutInit( &argc
, argv
);
172 glutInitWindowPosition( 0, 0 );
173 glutInitWindowSize(Width
, Height
);
174 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
175 glutCreateWindow(argv
[0]);
176 glutReshapeFunc( Reshape
);
177 glutKeyboardFunc( Key
);
178 glutDisplayFunc( Display
);