Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fbotexture.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Test GL_EXT_framebuffer_object render-to-texture
  3. *
  4. * Draw a teapot into a texture image with stenciling.
  5. * Then draw a textured quad using that texture.
  6. *
  7. * Brian Paul
  8. * 18 Apr 2005
  9. */
  10. #include <GL/glut.h>
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <math.h>
  16. #include "extfuncs.h"
  17. /* For debug */
  18. #define DEPTH 1
  19. #define STENCIL 1
  20. #define DRAW 1
  21. static int Win = 0;
  22. static int Width = 400, Height = 400;
  23. #if 1
  24. static GLenum TexTarget = GL_TEXTURE_2D;
  25. static int TexWidth = 512, TexHeight = 512;
  26. static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */
  27. #else
  28. static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB;
  29. static int TexWidth = 200, TexHeight = 200;
  30. static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */
  31. #endif
  32. static GLuint TextureLevel = 0; /* which texture level to render to */
  33. static GLuint MyFB;
  34. static GLuint TexObj;
  35. static GLuint DepthRB = 0, StencilRB = 0;
  36. static GLboolean Anim = GL_FALSE;
  37. static GLfloat Rot = 0.0;
  38. static GLboolean UsePackedDepthStencil = GL_FALSE;
  39. static GLboolean UsePackedDepthStencilBoth = GL_FALSE;
  40. static GLboolean Use_ARB_fbo = GL_FALSE;
  41. static GLboolean Cull = GL_FALSE;
  42. static GLboolean Wireframe = GL_FALSE;
  43. static void
  44. CheckError(int line)
  45. {
  46. GLenum err = glGetError();
  47. if (err) {
  48. printf("GL Error 0x%x at line %d\n", (int) err, line);
  49. }
  50. }
  51. static void
  52. Idle(void)
  53. {
  54. Rot = glutGet(GLUT_ELAPSED_TIME) * 0.1;
  55. glutPostRedisplay();
  56. }
  57. static void
  58. RenderTexture(void)
  59. {
  60. GLenum status;
  61. glMatrixMode(GL_PROJECTION);
  62. glLoadIdentity();
  63. glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
  64. glMatrixMode(GL_MODELVIEW);
  65. glLoadIdentity();
  66. glTranslatef(0.0, 0.0, -15.0);
  67. /* draw to texture image */
  68. glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, MyFB);
  69. status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT);
  70. if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
  71. printf("Framebuffer incomplete!!!\n");
  72. }
  73. glViewport(0, 0, TexWidth, TexHeight);
  74. glClearColor(0.5, 0.5, 1.0, 0.0);
  75. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  76. CheckError(__LINE__);
  77. #if DEPTH
  78. glEnable(GL_DEPTH_TEST);
  79. #endif
  80. #if STENCIL
  81. glEnable(GL_STENCIL_TEST);
  82. glStencilFunc(GL_NEVER, 1, ~0);
  83. glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE);
  84. #endif
  85. CheckError(__LINE__);
  86. #if DEPTH || STENCIL
  87. /* draw diamond-shaped stencil pattern */
  88. glColor3f(0, 1, 0);
  89. glBegin(GL_POLYGON);
  90. glVertex2f(-0.2, 0.0);
  91. glVertex2f( 0.0, -0.2);
  92. glVertex2f( 0.2, 0.0);
  93. glVertex2f( 0.0, 0.2);
  94. glEnd();
  95. #endif
  96. /* draw teapot where stencil != 1 */
  97. #if STENCIL
  98. glStencilFunc(GL_NOTEQUAL, 1, ~0);
  99. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  100. #endif
  101. CheckError(__LINE__);
  102. if (Wireframe) {
  103. glPolygonMode(GL_FRONT, GL_LINE);
  104. }
  105. else {
  106. glPolygonMode(GL_FRONT, GL_FILL);
  107. }
  108. if (Cull) {
  109. /* cull back */
  110. glCullFace(GL_BACK);
  111. glEnable(GL_CULL_FACE);
  112. }
  113. else {
  114. glDisable(GL_CULL_FACE);
  115. }
  116. #if 0
  117. glBegin(GL_POLYGON);
  118. glColor3f(1, 0, 0);
  119. glVertex2f(-1, -1);
  120. glColor3f(0, 1, 0);
  121. glVertex2f(1, -1);
  122. glColor3f(0, 0, 1);
  123. glVertex2f(0, 1);
  124. glEnd();
  125. #else
  126. glEnable(GL_LIGHTING);
  127. glEnable(GL_LIGHT0);
  128. glPushMatrix();
  129. glRotatef(0.5 * Rot, 1.0, 0.0, 0.0);
  130. glFrontFace(GL_CW); /* Teapot patches backward */
  131. glutSolidTeapot(0.5);
  132. glFrontFace(GL_CCW);
  133. glPopMatrix();
  134. glDisable(GL_LIGHTING);
  135. /*
  136. PrintStencilHistogram(TexWidth, TexHeight);
  137. */
  138. #endif
  139. glDisable(GL_DEPTH_TEST);
  140. glDisable(GL_STENCIL_TEST);
  141. glDisable(GL_CULL_FACE);
  142. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  143. #if DRAW
  144. /* Bind normal framebuffer */
  145. glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, 0);
  146. #endif
  147. CheckError(__LINE__);
  148. }
  149. static void
  150. Display(void)
  151. {
  152. float ar = (float) Width / (float) Height;
  153. RenderTexture();
  154. /* draw textured quad in the window */
  155. #if DRAW
  156. glMatrixMode(GL_PROJECTION);
  157. glLoadIdentity();
  158. glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0);
  159. glMatrixMode(GL_MODELVIEW);
  160. glLoadIdentity();
  161. glTranslatef(0.0, 0.0, -7.0);
  162. glViewport(0, 0, Width, Height);
  163. glClearColor(0.25, 0.25, 0.25, 0);
  164. glClear(GL_COLOR_BUFFER_BIT);
  165. glPushMatrix();
  166. glRotatef(Rot, 0, 1, 0);
  167. glEnable(TexTarget);
  168. glBindTexture(TexTarget, TexObj);
  169. glBegin(GL_POLYGON);
  170. glColor3f(0.25, 0.25, 0.25);
  171. if (TexTarget == GL_TEXTURE_2D) {
  172. glTexCoord2f(0, 0);
  173. glVertex2f(-1, -1);
  174. glTexCoord2f(1, 0);
  175. glVertex2f(1, -1);
  176. glColor3f(1.0, 1.0, 1.0);
  177. glTexCoord2f(1, 1);
  178. glVertex2f(1, 1);
  179. glTexCoord2f(0, 1);
  180. glVertex2f(-1, 1);
  181. }
  182. else {
  183. assert(TexTarget == GL_TEXTURE_RECTANGLE_ARB);
  184. glTexCoord2f(0, 0);
  185. glVertex2f(-1, -1);
  186. glTexCoord2f(TexWidth, 0);
  187. glVertex2f(1, -1);
  188. glColor3f(1.0, 1.0, 1.0);
  189. glTexCoord2f(TexWidth, TexHeight);
  190. glVertex2f(1, 1);
  191. glTexCoord2f(0, TexHeight);
  192. glVertex2f(-1, 1);
  193. }
  194. glEnd();
  195. glPopMatrix();
  196. glDisable(TexTarget);
  197. #endif
  198. glutSwapBuffers();
  199. CheckError(__LINE__);
  200. }
  201. static void
  202. Reshape(int width, int height)
  203. {
  204. glViewport(0, 0, width, height);
  205. Width = width;
  206. Height = height;
  207. }
  208. static void
  209. CleanUp(void)
  210. {
  211. #if DEPTH
  212. glDeleteRenderbuffers_func(1, &DepthRB);
  213. #endif
  214. #if STENCIL
  215. glDeleteRenderbuffers_func(1, &StencilRB);
  216. #endif
  217. glDeleteFramebuffers_func(1, &MyFB);
  218. glDeleteTextures(1, &TexObj);
  219. glutDestroyWindow(Win);
  220. exit(0);
  221. }
  222. static void
  223. Key(unsigned char key, int x, int y)
  224. {
  225. (void) x;
  226. (void) y;
  227. switch (key) {
  228. case 'a':
  229. Anim = !Anim;
  230. if (Anim)
  231. glutIdleFunc(Idle);
  232. else
  233. glutIdleFunc(NULL);
  234. break;
  235. case 'c':
  236. Cull = !Cull;
  237. break;
  238. case 'w':
  239. Wireframe = !Wireframe;
  240. break;
  241. case 's':
  242. Rot += 2.0;
  243. break;
  244. case 'S':
  245. Rot -= 2.0;
  246. break;
  247. case 27:
  248. CleanUp();
  249. break;
  250. }
  251. glutPostRedisplay();
  252. }
  253. /**
  254. * Attach depth and stencil renderbuffer(s) to the given framebuffer object.
  255. * \param tryDepthStencil if true, try to use a combined depth+stencil buffer
  256. * \param bindDepthStencil if true, and tryDepthStencil is true, bind with
  257. * the GL_DEPTH_STENCIL_ATTACHMENT target.
  258. * \return GL_TRUE for success, GL_FALSE for failure
  259. */
  260. static GLboolean
  261. AttachDepthAndStencilBuffers(GLuint fbo,
  262. GLsizei width, GLsizei height,
  263. GLboolean tryDepthStencil,
  264. GLboolean bindDepthStencil,
  265. GLuint *depthRbOut, GLuint *stencilRbOut)
  266. {
  267. GLenum status;
  268. *depthRbOut = *stencilRbOut = 0;
  269. glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, fbo);
  270. if (tryDepthStencil) {
  271. GLuint rb;
  272. glGenRenderbuffers_func(1, &rb);
  273. glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb);
  274. glRenderbufferStorage_func(GL_RENDERBUFFER_EXT,
  275. GL_DEPTH24_STENCIL8_EXT,
  276. width, height);
  277. if (glGetError())
  278. return GL_FALSE;
  279. if (bindDepthStencil) {
  280. /* attach to both depth and stencil at once */
  281. glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT,
  282. GL_DEPTH_STENCIL_ATTACHMENT,
  283. GL_RENDERBUFFER_EXT, rb);
  284. if (glGetError())
  285. return GL_FALSE;
  286. }
  287. else {
  288. /* attach to depth attachment point */
  289. glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT,
  290. GL_DEPTH_ATTACHMENT_EXT,
  291. GL_RENDERBUFFER_EXT, rb);
  292. if (glGetError())
  293. return GL_FALSE;
  294. /* and attach to stencil attachment point */
  295. glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT,
  296. GL_STENCIL_ATTACHMENT_EXT,
  297. GL_RENDERBUFFER_EXT, rb);
  298. if (glGetError())
  299. return GL_FALSE;
  300. }
  301. status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT);
  302. if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
  303. return GL_FALSE;
  304. *depthRbOut = *stencilRbOut = rb;
  305. return GL_TRUE;
  306. }
  307. /* just depth renderbuffer */
  308. {
  309. GLuint rb;
  310. glGenRenderbuffers_func(1, &rb);
  311. glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb);
  312. glRenderbufferStorage_func(GL_RENDERBUFFER_EXT,
  313. GL_DEPTH_COMPONENT,
  314. width, height);
  315. if (glGetError())
  316. return GL_FALSE;
  317. /* attach to depth attachment point */
  318. glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT,
  319. GL_DEPTH_ATTACHMENT_EXT,
  320. GL_RENDERBUFFER_EXT, rb);
  321. if (glGetError())
  322. return GL_FALSE;
  323. status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT);
  324. if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
  325. return GL_FALSE;
  326. *depthRbOut = rb;
  327. }
  328. /* just stencil renderbuffer */
  329. {
  330. GLuint rb;
  331. glGenRenderbuffers_func(1, &rb);
  332. glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, rb);
  333. glRenderbufferStorage_func(GL_RENDERBUFFER_EXT,
  334. GL_STENCIL_INDEX,
  335. width, height);
  336. if (glGetError())
  337. return GL_FALSE;
  338. /* attach to depth attachment point */
  339. glFramebufferRenderbuffer_func(GL_FRAMEBUFFER_EXT,
  340. GL_STENCIL_ATTACHMENT_EXT,
  341. GL_RENDERBUFFER_EXT, rb);
  342. if (glGetError())
  343. return GL_FALSE;
  344. status = glCheckFramebufferStatus_func(GL_FRAMEBUFFER_EXT);
  345. if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
  346. glDeleteRenderbuffers_func(1, depthRbOut);
  347. *depthRbOut = 0;
  348. glDeleteRenderbuffers_func(1, &rb);
  349. return GL_FALSE;
  350. }
  351. *stencilRbOut = rb;
  352. }
  353. return GL_TRUE;
  354. }
  355. static void
  356. ParseArgs(int argc, char *argv[])
  357. {
  358. GLint i;
  359. for (i = 1; i < argc; i++) {
  360. if (strcmp(argv[i], "-ds") == 0) {
  361. if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) {
  362. printf("GL_EXT_packed_depth_stencil not found!\n");
  363. exit(0);
  364. }
  365. UsePackedDepthStencil = GL_TRUE;
  366. printf("Using GL_EXT_packed_depth_stencil\n");
  367. }
  368. else if (strcmp(argv[i], "-ds2") == 0) {
  369. if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) {
  370. printf("GL_EXT_packed_depth_stencil not found!\n");
  371. exit(0);
  372. }
  373. if (!glutExtensionSupported("GL_ARB_framebuffer_object")) {
  374. printf("GL_ARB_framebuffer_object not found!\n");
  375. exit(0);
  376. }
  377. UsePackedDepthStencilBoth = GL_TRUE;
  378. printf("Using GL_EXT_packed_depth_stencil and GL_DEPTH_STENCIL attachment point\n");
  379. }
  380. else if (strcmp(argv[i], "-arb") == 0) {
  381. if (!glutExtensionSupported("GL_ARB_framebuffer_object")) {
  382. printf("Sorry, GL_ARB_framebuffer object not supported!\n");
  383. }
  384. else {
  385. Use_ARB_fbo = GL_TRUE;
  386. }
  387. }
  388. else {
  389. printf("Unknown option: %s\n", argv[i]);
  390. }
  391. }
  392. }
  393. static void
  394. SetupFunctionPointers(void)
  395. {
  396. GetExtensionFuncs();
  397. if (Use_ARB_fbo) {
  398. /* no-op: use the ARB functions as-is */
  399. }
  400. else {
  401. /* set the ARB-flavor function pointers to point to the EXT functions */
  402. glIsRenderbuffer_func = glIsRenderbufferEXT_func;
  403. glBindRenderbuffer_func = glBindRenderbufferEXT_func;
  404. glDeleteRenderbuffers_func = glDeleteRenderbuffersEXT_func;
  405. glGenRenderbuffers_func = glGenRenderbuffersEXT_func;
  406. glRenderbufferStorage_func = glRenderbufferStorageEXT_func;
  407. glGetRenderbufferParameteriv_func = glGetRenderbufferParameterivEXT_func;
  408. glIsFramebuffer_func = glIsFramebufferEXT_func;
  409. glBindFramebuffer_func = glBindFramebufferEXT_func;
  410. glDeleteFramebuffers_func = glDeleteFramebuffersEXT_func;
  411. glGenFramebuffers_func = glGenFramebuffersEXT_func;
  412. glCheckFramebufferStatus_func = glCheckFramebufferStatusEXT_func;
  413. glFramebufferTexture1D_func = glFramebufferTexture1DEXT_func;
  414. glFramebufferTexture2D_func = glFramebufferTexture2DEXT_func;
  415. glFramebufferTexture3D_func = glFramebufferTexture3DEXT_func;
  416. glFramebufferRenderbuffer_func = glFramebufferRenderbufferEXT_func;
  417. glGetFramebufferAttachmentParameteriv_func = glGetFramebufferAttachmentParameterivEXT_func;
  418. glGenerateMipmap_func = glGenerateMipmapEXT_func;
  419. }
  420. }
  421. /*
  422. * Make FBO to render into given texture.
  423. */
  424. static GLuint
  425. MakeFBO_RenderTexture(GLuint texObj)
  426. {
  427. GLuint fb;
  428. GLint sizeFudge = 0;
  429. glGenFramebuffers_func(1, &fb);
  430. glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, fb);
  431. /* Render color to texture */
  432. glFramebufferTexture2D_func(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
  433. TexTarget, texObj, TextureLevel);
  434. if (Use_ARB_fbo) {
  435. /* use a smaller depth buffer to see what happens */
  436. sizeFudge = 90;
  437. }
  438. /* Setup depth and stencil buffers */
  439. {
  440. GLboolean b;
  441. b = AttachDepthAndStencilBuffers(fb,
  442. TexWidth - sizeFudge,
  443. TexHeight - sizeFudge,
  444. UsePackedDepthStencil,
  445. UsePackedDepthStencilBoth,
  446. &DepthRB, &StencilRB);
  447. if (!b) {
  448. /* try !UsePackedDepthStencil */
  449. b = AttachDepthAndStencilBuffers(fb,
  450. TexWidth - sizeFudge,
  451. TexHeight - sizeFudge,
  452. !UsePackedDepthStencil,
  453. UsePackedDepthStencilBoth,
  454. &DepthRB, &StencilRB);
  455. }
  456. if (!b) {
  457. printf("Unable to create/attach depth and stencil renderbuffers "
  458. " to FBO!\n");
  459. exit(1);
  460. }
  461. }
  462. /* queries */
  463. {
  464. GLint bits, w, h, name;
  465. glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, DepthRB);
  466. glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT,
  467. GL_RENDERBUFFER_WIDTH_EXT, &w);
  468. glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT,
  469. GL_RENDERBUFFER_HEIGHT_EXT, &h);
  470. printf("Color/Texture size: %d x %d\n", TexWidth, TexHeight);
  471. printf("Depth buffer size: %d x %d\n", w, h);
  472. glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT,
  473. GL_RENDERBUFFER_DEPTH_SIZE_EXT, &bits);
  474. printf("Depth renderbuffer size = %d bits\n", bits);
  475. glBindRenderbuffer_func(GL_RENDERBUFFER_EXT, StencilRB);
  476. glGetRenderbufferParameteriv_func(GL_RENDERBUFFER_EXT,
  477. GL_RENDERBUFFER_STENCIL_SIZE_EXT, &bits);
  478. printf("Stencil renderbuffer size = %d bits\n", bits);
  479. glGetFramebufferAttachmentParameteriv_func(GL_FRAMEBUFFER_EXT,
  480. GL_COLOR_ATTACHMENT0,
  481. GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT,
  482. &name);
  483. printf("Render to texture name: %d\n", texObj);
  484. printf("Color attachment[0] name: %d\n", name);
  485. assert(texObj == name);
  486. glGetFramebufferAttachmentParameteriv_func(GL_FRAMEBUFFER_EXT,
  487. GL_STENCIL_ATTACHMENT,
  488. GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT,
  489. &name);
  490. printf("Stencil attachment name: %d\n", name);
  491. glGetFramebufferAttachmentParameteriv_func(GL_FRAMEBUFFER_EXT,
  492. GL_DEPTH_ATTACHMENT,
  493. GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT,
  494. &name);
  495. printf("Depth attachment name: %d\n", name);
  496. }
  497. /* bind the regular framebuffer */
  498. glBindFramebuffer_func(GL_FRAMEBUFFER_EXT, 0);
  499. return fb;
  500. }
  501. static void
  502. Init(void)
  503. {
  504. if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
  505. printf("GL_EXT_framebuffer_object not found!\n");
  506. exit(0);
  507. }
  508. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  509. SetupFunctionPointers();
  510. /* lighting */
  511. {
  512. static const GLfloat mat[4] = { 1.0, 0.5, 0.5, 1.0 };
  513. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat);
  514. }
  515. /*
  516. * Make texture object/image (we'll render into this texture)
  517. */
  518. {
  519. glGenTextures(1, &TexObj);
  520. glBindTexture(TexTarget, TexObj);
  521. /* make two image levels */
  522. glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0,
  523. GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  524. if (TexTarget == GL_TEXTURE_2D) {
  525. glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0,
  526. GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  527. TexWidth = TexWidth >> TextureLevel;
  528. TexHeight = TexHeight >> TextureLevel;
  529. glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel);
  530. }
  531. glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  532. glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  533. glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel);
  534. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  535. }
  536. MyFB = MakeFBO_RenderTexture(TexObj);
  537. }
  538. static void
  539. Usage(void)
  540. {
  541. printf("Usage:\n");
  542. printf(" -ds Use combined depth/stencil renderbuffer\n");
  543. printf(" -arb Try GL_ARB_framebuffer_object's mismatched buffer sizes\n");
  544. printf(" -ds2 Try GL_ARB_framebuffer_object's GL_DEPTH_STENCIL_ATTACHMENT\n");
  545. printf("Keys:\n");
  546. printf(" a Toggle animation\n");
  547. printf(" s/s Step/rotate\n");
  548. printf(" c Toggle back-face culling\n");
  549. printf(" w Toggle wireframe mode (front-face only)\n");
  550. printf(" Esc Exit\n");
  551. }
  552. int
  553. main(int argc, char *argv[])
  554. {
  555. glutInit(&argc, argv);
  556. glutInitWindowPosition(0, 0);
  557. glutInitWindowSize(Width, Height);
  558. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  559. Win = glutCreateWindow(argv[0]);
  560. glutReshapeFunc(Reshape);
  561. glutKeyboardFunc(Key);
  562. glutDisplayFunc(Display);
  563. if (Anim)
  564. glutIdleFunc(Idle);
  565. ParseArgs(argc, argv);
  566. Init();
  567. Usage();
  568. glutMainLoop();
  569. return 0;
  570. }