Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

fbotest1.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Test GL_EXT_framebuffer_object
  3. *
  4. * Brian Paul
  5. * 7 Feb 2005
  6. */
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <assert.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12. #include <GL/glut.h>
  13. static int Win;
  14. static int Width = 400, Height = 400;
  15. static GLuint MyFB, MyRB;
  16. static void
  17. CheckError(int line)
  18. {
  19. GLenum err = glGetError();
  20. if (err) {
  21. printf("GL Error 0x%x at line %d\n", (int) err, line);
  22. }
  23. }
  24. static void
  25. Display( void )
  26. {
  27. GLubyte *buffer = malloc(Width * Height * 4);
  28. GLenum status;
  29. /* draw to user framebuffer */
  30. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
  31. glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
  32. glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
  33. status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  34. if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
  35. printf("Framebuffer incomplete!!!\n");
  36. }
  37. glClearColor(0.5, 0.5, 1.0, 0.0);
  38. glClear( GL_COLOR_BUFFER_BIT );
  39. glBegin(GL_POLYGON);
  40. glColor3f(1, 0, 0);
  41. glVertex2f(-1, -1);
  42. glColor3f(0, 1, 0);
  43. glVertex2f(1, -1);
  44. glColor3f(0, 0, 1);
  45. glVertex2f(0, 1);
  46. glEnd();
  47. /* read from user framebuffer */
  48. glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  49. /* draw to window */
  50. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  51. glWindowPos2iARB(0, 0);
  52. glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  53. free(buffer);
  54. glutSwapBuffers();
  55. CheckError(__LINE__);
  56. }
  57. static void
  58. Reshape( int width, int height )
  59. {
  60. #if 0
  61. float ar = (float) width / (float) height;
  62. #endif
  63. glViewport( 0, 0, width, height );
  64. glMatrixMode( GL_PROJECTION );
  65. glLoadIdentity();
  66. #if 0
  67. glFrustum( -ar, ar, -1.0, 1.0, 5.0, 25.0 );
  68. #else
  69. glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  70. #endif
  71. glMatrixMode( GL_MODELVIEW );
  72. glLoadIdentity();
  73. glTranslatef( 0.0, 0.0, -15.0 );
  74. Width = width;
  75. Height = height;
  76. glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
  77. }
  78. static void
  79. CleanUp(void)
  80. {
  81. glDeleteFramebuffersEXT(1, &MyFB);
  82. glDeleteRenderbuffersEXT(1, &MyRB);
  83. assert(!glIsFramebufferEXT(MyFB));
  84. assert(!glIsRenderbufferEXT(MyRB));
  85. glutDestroyWindow(Win);
  86. exit(0);
  87. }
  88. static void
  89. Key( unsigned char key, int x, int y )
  90. {
  91. (void) x;
  92. (void) y;
  93. switch (key) {
  94. case 27:
  95. CleanUp();
  96. break;
  97. }
  98. glutPostRedisplay();
  99. }
  100. static void
  101. Init( void )
  102. {
  103. GLint i;
  104. if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
  105. printf("GL_EXT_framebuffer_object not found!\n");
  106. /*exit(0);*/
  107. }
  108. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  109. glGenFramebuffersEXT(1, &MyFB);
  110. assert(MyFB);
  111. assert(!glIsFramebufferEXT(MyFB));
  112. glDeleteFramebuffersEXT(1, &MyFB);
  113. assert(!glIsFramebufferEXT(MyFB));
  114. /* Note, continue to use MyFB below */
  115. glGenRenderbuffersEXT(1, &MyRB);
  116. assert(MyRB);
  117. assert(!glIsRenderbufferEXT(MyRB));
  118. glDeleteRenderbuffersEXT(1, &MyRB);
  119. assert(!glIsRenderbufferEXT(MyRB));
  120. MyRB = 42; /* an arbitrary ID */
  121. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB);
  122. assert(glIsFramebufferEXT(MyFB));
  123. glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRB);
  124. assert(glIsRenderbufferEXT(MyRB));
  125. glGetIntegerv(GL_RENDERBUFFER_BINDING_EXT, &i);
  126. assert(i == MyRB);
  127. glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &i);
  128. assert(i == MyFB);
  129. CheckError(__LINE__);
  130. glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
  131. GL_RENDERBUFFER_EXT, MyRB);
  132. glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height);
  133. CheckError(__LINE__);
  134. {
  135. GLint r, g, b, a;
  136. glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT,
  137. GL_RENDERBUFFER_RED_SIZE_EXT, &r);
  138. glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT,
  139. GL_RENDERBUFFER_GREEN_SIZE_EXT, &g);
  140. glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT,
  141. GL_RENDERBUFFER_BLUE_SIZE_EXT, &b);
  142. glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT,
  143. GL_RENDERBUFFER_ALPHA_SIZE_EXT, &a);
  144. CheckError(__LINE__);
  145. printf("renderbuffer RGBA sizes = %d %d %d %d\n", r, g, b, a);
  146. glGetIntegerv(GL_RED_BITS, &r);
  147. glGetIntegerv(GL_GREEN_BITS, &g);
  148. glGetIntegerv(GL_BLUE_BITS, &b);
  149. glGetIntegerv(GL_ALPHA_BITS, &a);
  150. printf("Visual RGBA sizes = %d %d %d %d\n", r, g, b, a);
  151. }
  152. /* restore to default */
  153. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  154. CheckError(__LINE__);
  155. }
  156. int
  157. main( int argc, char *argv[] )
  158. {
  159. glutInit( &argc, argv );
  160. glutInitWindowPosition( 0, 0 );
  161. glutInitWindowSize(Width, Height);
  162. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  163. Win = glutCreateWindow(argv[0]);
  164. glutReshapeFunc( Reshape );
  165. glutKeyboardFunc( Key );
  166. glutDisplayFunc( Display );
  167. Init();
  168. glutMainLoop();
  169. return 0;
  170. }