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.

texgenmix.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Demonstrates mixed texgen/non-texgen texture coordinates.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <GL/glew.h>
  8. #include <GL/glut.h>
  9. #undef max
  10. #undef min
  11. #define max( a, b ) ((a) >= (b) ? (a) : (b))
  12. #define min( a, b ) ((a) <= (b) ? (a) : (b))
  13. GLfloat labelColor0[4] = { 1.0, 1.0, 1.0, 1.0 };
  14. GLfloat labelColor1[4] = { 1.0, 1.0, 0.4, 1.0 };
  15. GLfloat *labelInfoColor = labelColor0;
  16. GLboolean doubleBuffered = GL_TRUE;
  17. GLboolean drawTextured = GL_TRUE;
  18. int textureWidth = 64;
  19. int textureHeight = 64;
  20. int winWidth = 580, winHeight = 720;
  21. const GLfloat texmat_swap_rq[16] = { 1.0, 0.0, 0.0, 0.0,
  22. 0.0, 1.0, 0.0, 0.0,
  23. 0.0, 0.0, 0.0, 1.0,
  24. 0.0, 0.0, 1.0, 0.0};
  25. const GLfloat nullPlane[4] = { 0.0, 0.0, 0.0, 0.0 };
  26. const GLfloat ObjPlaneS1[4] = { 1.0, 0.0, 1.0, 0.0 };
  27. const GLfloat ObjPlaneS2[4] = { 0.5, 0.0, 0.0, 0.0 };
  28. const GLfloat ObjPlaneS3[4] = { 1.0, 0.0, 0.0, 0.0 };
  29. const GLfloat ObjPlaneT[4] = { 0.0, 1.0, 0.0, 0.0 };
  30. const GLfloat ObjPlaneT2[4] = { 0.0, 0.5, 0.0, 0.0 };
  31. const GLfloat ObjPlaneT3[4] = { 0.0, 1.0, 0.0, 0.0 };
  32. const GLfloat ObjPlaneR[4] = { 0.0, 0.0, 1.0, 0.0 };
  33. const GLfloat ObjPlaneQ[4] = { 0.0, 0.0, 0.0, 0.5 };
  34. static void checkErrors( void )
  35. {
  36. GLenum error;
  37. while ( (error = glGetError()) != GL_NO_ERROR ) {
  38. fprintf( stderr, "Error: %s\n", (char *) gluErrorString( error ) );
  39. }
  40. }
  41. static void drawString( const char *string, GLfloat x, GLfloat y,
  42. const GLfloat color[4] )
  43. {
  44. glColor4fv( color );
  45. glRasterPos2f( x, y );
  46. while ( *string ) {
  47. glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_10, *string );
  48. string++;
  49. }
  50. }
  51. static void begin2D( int width, int height )
  52. {
  53. glMatrixMode( GL_PROJECTION );
  54. glPushMatrix();
  55. glLoadIdentity();
  56. glOrtho( 0, width, 0, height, -1, 1 );
  57. glMatrixMode( GL_MODELVIEW );
  58. glPushMatrix();
  59. glLoadIdentity();
  60. }
  61. static void end2D( void )
  62. {
  63. glMatrixMode( GL_PROJECTION );
  64. glPopMatrix();
  65. glMatrixMode( GL_MODELVIEW );
  66. glPopMatrix();
  67. }
  68. static void initialize( void )
  69. {
  70. glMatrixMode( GL_PROJECTION );
  71. glLoadIdentity();
  72. glOrtho( -1.5, 1.5, -1.5, 1.5, -1.5, 1.5 );
  73. glMatrixMode(GL_MODELVIEW);
  74. glLoadIdentity();
  75. glShadeModel( GL_FLAT );
  76. }
  77. /* ARGSUSED1 */
  78. static void keyboard( unsigned char c, int x, int y )
  79. {
  80. switch ( c ) {
  81. case 't':
  82. drawTextured = !drawTextured;
  83. break;
  84. case 27: /* Escape key should force exit. */
  85. exit(0);
  86. break;
  87. default:
  88. break;
  89. }
  90. glutPostRedisplay();
  91. }
  92. /* ARGSUSED1 */
  93. static void special( int key, int x, int y )
  94. {
  95. switch ( key ) {
  96. case GLUT_KEY_DOWN:
  97. break;
  98. case GLUT_KEY_UP:
  99. break;
  100. case GLUT_KEY_LEFT:
  101. break;
  102. case GLUT_KEY_RIGHT:
  103. break;
  104. default:
  105. break;
  106. }
  107. glutPostRedisplay();
  108. }
  109. static void
  110. reshape( int w, int h )
  111. {
  112. winWidth = w;
  113. winHeight = h;
  114. /* No need to call glViewPort here since "draw" calls it! */
  115. }
  116. static void loadTexture( int width, int height )
  117. {
  118. int alphaSize = 1;
  119. int rgbSize = 3;
  120. GLubyte *texImage, *p;
  121. int elementsPerGroup, elementSize, groupSize, rowSize;
  122. int i, j;
  123. elementsPerGroup = alphaSize + rgbSize;
  124. elementSize = sizeof(GLubyte);
  125. groupSize = elementsPerGroup * elementSize;
  126. rowSize = width * groupSize;
  127. if ( (texImage = (GLubyte *) malloc( height * rowSize ) ) == NULL ) {
  128. fprintf( stderr, "texture malloc failed\n" );
  129. return;
  130. }
  131. for ( i = 0 ; i < height ; i++ )
  132. {
  133. p = texImage + i * rowSize;
  134. for ( j = 0 ; j < width ; j++ )
  135. {
  136. if ( rgbSize > 0 )
  137. {
  138. /**
  139. ** +-----+-----+
  140. ** | | |
  141. ** | R | G |
  142. ** | | |
  143. ** +-----+-----+
  144. ** | | |
  145. ** | Y | B |
  146. ** | | |
  147. ** +-----+-----+
  148. **/
  149. if ( i > height / 2 ) {
  150. if ( j < width / 2 ) {
  151. p[0] = 0xff;
  152. p[1] = 0x00;
  153. p[2] = 0x00;
  154. } else {
  155. p[0] = 0x00;
  156. p[1] = 0xff;
  157. p[2] = 0x00;
  158. }
  159. } else {
  160. if ( j < width / 2 ) {
  161. p[0] = 0xff;
  162. p[1] = 0xff;
  163. p[2] = 0x00;
  164. } else {
  165. p[0] = 0x00;
  166. p[1] = 0x00;
  167. p[2] = 0xff;
  168. }
  169. }
  170. p += 3 * elementSize;
  171. }
  172. if ( alphaSize > 0 )
  173. {
  174. /**
  175. ** +-----------+
  176. ** | W |
  177. ** | +-----+ |
  178. ** | | | |
  179. ** | | B | |
  180. ** | | | |
  181. ** | +-----+ |
  182. ** | |
  183. ** +-----------+
  184. **/
  185. int i2 = i - height / 2;
  186. int j2 = j - width / 2;
  187. int h8 = height / 8;
  188. int w8 = width / 8;
  189. if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) {
  190. p[0] = 0x00;
  191. } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) {
  192. p[0] = 0x55;
  193. } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) {
  194. p[0] = 0xaa;
  195. } else {
  196. p[0] = 0xff;
  197. }
  198. p += elementSize;
  199. }
  200. }
  201. }
  202. glTexImage2D( GL_TEXTURE_2D, 0,
  203. GL_RGBA, width, height, 0,
  204. GL_RGBA, GL_UNSIGNED_BYTE, texImage );
  205. free( texImage );
  206. }
  207. static void drawSample( int x, int y, int w, int h,
  208. int texgenenabled, int coordnr )
  209. {
  210. char buf[255];
  211. glViewport( x, y, w, h );
  212. glScissor( x, y, w, h );
  213. glClearColor( 0.1, 0.1, 0.1, 1.0 );
  214. glClear( GL_COLOR_BUFFER_BIT );
  215. begin2D( w, h );
  216. if (texgenenabled == 2) {
  217. sprintf( buf, "TexCoord%df", coordnr);
  218. drawString( buf, 10, h - 15, labelInfoColor );
  219. sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S" : "S/T");
  220. drawString( buf, 10, 5, labelInfoColor );
  221. }
  222. else if (texgenenabled == 0) {
  223. sprintf( buf, "TexCoord%df", coordnr);
  224. drawString( buf, 10, h - 15, labelInfoColor );
  225. drawString( "no texgen", 10, 5, labelInfoColor );
  226. }
  227. else if (texgenenabled == 1) {
  228. drawString( "no TexCoord", 10, h - 15, labelInfoColor );
  229. sprintf( buf, "texgen enabled for %s coordinate(s)",
  230. coordnr == 2 ? "S/T" : (coordnr == 3 ? "S/T/R" : "S/T/R/Q"));
  231. drawString( buf, 10, 5, labelInfoColor );
  232. }
  233. end2D();
  234. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
  235. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  236. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  237. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
  238. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
  239. loadTexture( textureWidth, textureHeight );
  240. if ( drawTextured ) {
  241. glEnable( GL_TEXTURE_2D );
  242. }
  243. glDisable( GL_TEXTURE_GEN_S );
  244. glDisable( GL_TEXTURE_GEN_T );
  245. glDisable( GL_TEXTURE_GEN_R );
  246. glDisable( GL_TEXTURE_GEN_Q );
  247. glMatrixMode( GL_TEXTURE );
  248. glLoadIdentity();
  249. glMatrixMode( GL_MODELVIEW );
  250. glPushMatrix();
  251. switch (coordnr) {
  252. case 2:
  253. switch (texgenenabled) {
  254. case 0:
  255. glBegin( GL_QUADS );
  256. glTexCoord2f( 0.0, 0.0 );
  257. glVertex2f( -0.8, -0.8 );
  258. glTexCoord2f( 1.0, 0.0 );
  259. glVertex2f( 0.8, -0.8 );
  260. glTexCoord2f( 1.0, 1.0 );
  261. glVertex2f( 0.8, 0.8 );
  262. glTexCoord2f( 0.0, 1.0 );
  263. glVertex2f( -0.8, 0.8 );
  264. glEnd();
  265. break;
  266. case 1:
  267. glTranslatef( -0.8, -0.8, 0.0 );
  268. glScalef( 1.6, 1.6, 1.0 );
  269. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  270. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  271. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  272. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  273. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS3);
  274. glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT3);
  275. glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
  276. glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
  277. glEnable( GL_TEXTURE_GEN_S );
  278. glEnable( GL_TEXTURE_GEN_T );
  279. /* Issue a texcoord here to be sure Q isn't left over from a
  280. * previous sample.
  281. */
  282. glTexCoord1f( 0.0 );
  283. glBegin( GL_QUADS );
  284. glVertex2f( 0.0, 0.0 );
  285. glVertex2f( 1.0, 0.0 );
  286. glVertex2f( 1.0, 1.0 );
  287. glVertex2f( 0.0, 1.0 );
  288. glEnd();
  289. break;
  290. case 2:
  291. /* make sure that texgen T and non-texgen S coordinate are wrong */
  292. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  293. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  294. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  295. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  296. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS1);
  297. glTexGenfv(GL_T, GL_OBJECT_PLANE, nullPlane);
  298. glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
  299. glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
  300. glEnable( GL_TEXTURE_GEN_S );
  301. glBegin( GL_QUADS );
  302. /* use z coordinate to get correct texgen values... */
  303. glTexCoord2f( 0.0, 0.0 );
  304. glVertex3f( -0.8, -0.8, 0.8 );
  305. glTexCoord2f( 0.0, 0.0 );
  306. glVertex3f( 0.8, -0.8, 0.2 );
  307. glTexCoord2f( 0.0, 1.0 );
  308. glVertex3f( 0.8, 0.8, 0.2 );
  309. glTexCoord2f( 0.0, 1.0 );
  310. glVertex3f( -0.8, 0.8, 0.8 );
  311. glEnd();
  312. break;
  313. }
  314. break;
  315. case 3:
  316. glMatrixMode( GL_TEXTURE );
  317. glLoadMatrixf( texmat_swap_rq );
  318. glMatrixMode( GL_MODELVIEW );
  319. glTranslatef( -0.8, -0.8, 0.0 );
  320. glScalef( 1.6, 1.6, 1.0 );
  321. switch (texgenenabled) {
  322. case 0:
  323. glBegin( GL_QUADS );
  324. glTexCoord3f( 0.0, 0.0, 0.5 );
  325. glVertex2f( 0.0, 0.0 );
  326. glTexCoord3f( 0.5, 0.0, 0.5 );
  327. glVertex2f( 1.0, 0.0 );
  328. glTexCoord3f( 0.5, 0.5, 0.5 );
  329. glVertex2f( 1.0, 1.0 );
  330. glTexCoord3f( 0.0, 0.5, 0.5 );
  331. glVertex2f( 0.0, 1.0 );
  332. glEnd();
  333. break;
  334. case 1:
  335. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  336. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  337. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  338. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  339. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
  340. glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
  341. glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR);
  342. glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
  343. glEnable( GL_TEXTURE_GEN_S );
  344. glEnable( GL_TEXTURE_GEN_T );
  345. glEnable( GL_TEXTURE_GEN_R );
  346. glTexCoord1f( 0.0 ); /* to make sure Q is 1.0 */
  347. glBegin( GL_QUADS );
  348. glVertex3f( 0.0, 0.0, 0.5 );
  349. glVertex3f( 1.0, 0.0, 0.5 );
  350. glVertex3f( 1.0, 1.0, 0.5 );
  351. glVertex3f( 0.0, 1.0, 0.5 );
  352. glEnd();
  353. break;
  354. case 2:
  355. /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
  356. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  357. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  358. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  359. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  360. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
  361. glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
  362. glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
  363. glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
  364. glEnable( GL_TEXTURE_GEN_S );
  365. glEnable( GL_TEXTURE_GEN_T );
  366. glBegin( GL_QUADS );
  367. glTexCoord3f( 0.0, 0.0, 0.5 );
  368. glVertex2f( 0.0, 0.0);
  369. glTexCoord3f( 0.0, 0.0, 0.5 );
  370. glVertex2f( 1.0, 0.0);
  371. glTexCoord3f( 0.0, 0.0, 0.5 );
  372. glVertex2f( 1.0, 1.0);
  373. glTexCoord3f( 0.0, 0.0, 0.5 );
  374. glVertex2f( 0.0, 1.0);
  375. glEnd();
  376. break;
  377. }
  378. break;
  379. case 4:
  380. switch (texgenenabled) {
  381. case 0:
  382. glBegin( GL_QUADS );
  383. /* don't need r coordinate but still setting it I'm mean */
  384. glTexCoord4f( 0.0, 0.0, 0.0, 0.5 );
  385. glVertex2f( -0.8, -0.8 );
  386. glTexCoord4f( 0.5, 0.0, 0.2, 0.5 );
  387. glVertex2f( 0.8, -0.8 );
  388. glTexCoord4f( 0.5, 0.5, 0.5, 0.5 );
  389. glVertex2f( 0.8, 0.8 );
  390. glTexCoord4f( 0.0, 0.5, 0.5, 0.5 );
  391. glVertex2f( -0.8, 0.8 );
  392. glEnd();
  393. break;
  394. case 1:
  395. glTranslatef( -0.8, -0.8, 0.0 );
  396. glScalef( 1.6, 1.6, 1.0 );
  397. /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
  398. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  399. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  400. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  401. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  402. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
  403. glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
  404. glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR);
  405. glTexGenfv(GL_Q, GL_OBJECT_PLANE, ObjPlaneQ);
  406. glEnable( GL_TEXTURE_GEN_S );
  407. glEnable( GL_TEXTURE_GEN_T );
  408. glEnable( GL_TEXTURE_GEN_R );
  409. glEnable( GL_TEXTURE_GEN_Q );
  410. glBegin( GL_QUADS );
  411. glVertex2f( 0.0, 0.0 );
  412. glVertex2f( 1.0, 0.0 );
  413. glVertex2f( 1.0, 1.0 );
  414. glVertex2f( 0.0, 1.0 );
  415. glEnd();
  416. break;
  417. case 2:
  418. glTranslatef( -0.8, -0.8, 0.0 );
  419. glScalef( 1.6, 1.6, 1.0 );
  420. /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */
  421. glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  422. glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  423. glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  424. glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  425. glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2);
  426. glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2);
  427. glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane);
  428. glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane);
  429. glEnable( GL_TEXTURE_GEN_S );
  430. glEnable( GL_TEXTURE_GEN_T );
  431. glBegin( GL_QUADS );
  432. glTexCoord4f( 0.0, 0.0, 0.0, 0.5 );
  433. glVertex2f( 0.0, 0.0 );
  434. glTexCoord4f( 0.0, 0.0, 0.2, 0.5 );
  435. glVertex2f( 1.0, 0.0 );
  436. glTexCoord4f( 0.0, 0.0, 0.5, 0.5 );
  437. glVertex2f( 1.0, 1.0 );
  438. glTexCoord4f( 0.0, 0.0, 0.75, 0.5 );
  439. glVertex2f( 0.0, 1.0 );
  440. glEnd();
  441. break;
  442. }
  443. break;
  444. }
  445. glPopMatrix();
  446. glDisable( GL_TEXTURE_2D );
  447. }
  448. static void display( void )
  449. {
  450. int numX = 3, numY = 3;
  451. float xBase = (float) winWidth * 0.01;
  452. float xOffset = (winWidth - xBase) / numX;
  453. float xSize = max( xOffset - xBase, 1 );
  454. float yBase = (float) winHeight * 0.01;
  455. float yOffset = (winHeight - yBase) / numY;
  456. float ySize = max( yOffset - yBase, 1 );
  457. float x, y;
  458. int i, j;
  459. glViewport( 0, 0, winWidth, winHeight );
  460. glDisable( GL_SCISSOR_TEST );
  461. glClearColor( 0.0, 0.0, 0.0, 0.0 );
  462. glClear( GL_COLOR_BUFFER_BIT );
  463. glEnable( GL_SCISSOR_TEST );
  464. x = xBase;
  465. y = (winHeight - 1) - yOffset;
  466. for ( i = 0 ; i < numY ; i++ )
  467. {
  468. labelInfoColor = labelColor1;
  469. for ( j = 0 ; j < numX ; j++ ) {
  470. drawSample( x, y, xSize, ySize, i, j+2 );
  471. x += xOffset;
  472. }
  473. x = xBase;
  474. y -= yOffset;
  475. }
  476. if ( doubleBuffered ) {
  477. glutSwapBuffers();
  478. } else {
  479. glFlush();
  480. }
  481. checkErrors();
  482. }
  483. static void usage( char *name )
  484. {
  485. fprintf( stderr, "usage: %s [ options ]\n", name );
  486. fprintf( stderr, "\n" );
  487. fprintf( stderr, "options:\n" );
  488. fprintf( stderr, " -sb single buffered\n" );
  489. fprintf( stderr, " -db double buffered\n" );
  490. fprintf( stderr, " -info print OpenGL driver info\n" );
  491. }
  492. static void instructions( void )
  493. {
  494. fprintf( stderr, "texgenmix - mixed texgen/non-texgen texture coordinate test\n" );
  495. fprintf( stderr, "all quads should look the same!\n" );
  496. fprintf( stderr, "\n" );
  497. fprintf( stderr, " [t] - toggle texturing\n" );
  498. }
  499. int main( int argc, char *argv[] )
  500. {
  501. GLboolean info = GL_FALSE;
  502. int i;
  503. glutInit( &argc, argv );
  504. for ( i = 1 ; i < argc ; i++ ) {
  505. if ( !strcmp( "-sb", argv[i] ) ) {
  506. doubleBuffered = GL_FALSE;
  507. } else if ( !strcmp( "-db", argv[i] ) ) {
  508. doubleBuffered = GL_TRUE;
  509. } else if ( !strcmp( "-info", argv[i] ) ) {
  510. info = GL_TRUE;
  511. } else {
  512. usage( argv[0] );
  513. exit( 1 );
  514. }
  515. }
  516. if ( doubleBuffered ) {
  517. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  518. } else {
  519. glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE );
  520. }
  521. glutInitWindowSize( winWidth, winHeight );
  522. glutInitWindowPosition( 0, 0 );
  523. glutCreateWindow( "Mixed texgen/non-texgen texture coordinate test" );
  524. glewInit();
  525. initialize();
  526. instructions();
  527. if ( info ) {
  528. printf( "\n" );
  529. printf( "GL_RENDERER = %s\n", (char *) glGetString( GL_RENDERER ) );
  530. printf( "GL_VERSION = %s\n", (char *) glGetString( GL_VERSION ) );
  531. printf( "GL_VENDOR = %s\n", (char *) glGetString( GL_VENDOR ) ) ;
  532. printf( "GL_EXTENSIONS = %s\n", (char *) glGetString( GL_EXTENSIONS ) );
  533. }
  534. glutDisplayFunc( display );
  535. glutReshapeFunc( reshape );
  536. glutKeyboardFunc( keyboard );
  537. glutSpecialFunc( special );
  538. glutMainLoop();
  539. return 0;
  540. }