Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

multiarb.c 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /* $Id: multiarb.c,v 1.10 2001/06/20 19:12:30 brianp Exp $ */
  2. /*
  3. * GL_ARB_multitexture demo
  4. *
  5. * Command line options:
  6. * -info print GL implementation information
  7. *
  8. *
  9. * Brian Paul November 1998 This program is in the public domain.
  10. */
  11. /*
  12. * $Log: multiarb.c,v $
  13. * Revision 1.10 2001/06/20 19:12:30 brianp
  14. * also print GL_MAX_TEXTURE_SIZE
  15. *
  16. * Revision 1.9 2001/06/13 14:33:16 brianp
  17. * moved glTexEnvi calls to better logical locations
  18. *
  19. * Revision 1.8 2000/12/24 22:53:54 pesco
  20. * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
  21. * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
  22. * Essentially the same.
  23. * Program files updated to include "readtex.c", not "../util/readtex.c".
  24. * * demos/reflect.c: Likewise for "showbuffer.c".
  25. *
  26. *
  27. * * Makefile.am (EXTRA_DIST): Added top-level regular files.
  28. *
  29. * * include/GL/Makefile.am (INC_X11): Added glxext.h.
  30. *
  31. *
  32. * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
  33. * Mesa GGI headers in dist even if HAVE_GGI is not given.
  34. *
  35. * * configure.in: Look for GLUT and demo source dirs in $srcdir.
  36. *
  37. * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
  38. * More source list updates in various Makefile.am's.
  39. *
  40. * * Makefile.am (dist-hook): Remove CVS directory from distribution.
  41. * (DIST_SUBDIRS): List all possible subdirs here.
  42. * (SUBDIRS): Only list subdirs selected for build again.
  43. * The above two applied to all subdir Makefile.am's also.
  44. *
  45. * Revision 1.7 2000/11/01 16:02:01 brianp
  46. * print number of texture units
  47. *
  48. * Revision 1.6 2000/05/23 23:21:00 brianp
  49. * set default window pos
  50. *
  51. * Revision 1.5 2000/02/02 17:31:45 brianp
  52. * changed > to >=
  53. *
  54. * Revision 1.4 2000/02/02 01:07:21 brianp
  55. * limit Drift to [0, 1]
  56. *
  57. * Revision 1.3 1999/10/21 16:40:32 brianp
  58. * added -info command line option
  59. *
  60. * Revision 1.2 1999/10/13 12:02:13 brianp
  61. * use texture objects now
  62. *
  63. * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
  64. * Imported sources
  65. *
  66. * Revision 1.3 1999/03/28 18:20:49 brianp
  67. * minor clean-up
  68. *
  69. * Revision 1.2 1998/11/05 04:34:04 brianp
  70. * moved image files to ../images/ directory
  71. *
  72. * Revision 1.1 1998/11/03 01:36:33 brianp
  73. * Initial revision
  74. *
  75. */
  76. #include <math.h>
  77. #include <stdio.h>
  78. #include <stdlib.h>
  79. #include <string.h>
  80. #include <GL/glut.h>
  81. #include "readtex.c" /* I know, this is a hack. */
  82. #define TEXTURE_1_FILE "../images/girl.rgb"
  83. #define TEXTURE_2_FILE "../images/reflect.rgb"
  84. #define TEX0 1
  85. #define TEX1 2
  86. #define TEXBOTH 3
  87. #define ANIMATE 10
  88. #define QUIT 100
  89. static GLboolean Animate = GL_TRUE;
  90. static GLfloat Drift = 0.0;
  91. static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0;
  92. static void Idle( void )
  93. {
  94. if (Animate) {
  95. Drift += 0.05;
  96. if (Drift >= 1.0)
  97. Drift = 0.0;
  98. #ifdef GL_ARB_multitexture
  99. glActiveTextureARB(GL_TEXTURE0_ARB);
  100. #endif
  101. glMatrixMode(GL_TEXTURE);
  102. glLoadIdentity();
  103. glTranslatef(Drift, 0.0, 0.0);
  104. glMatrixMode(GL_MODELVIEW);
  105. #ifdef GL_ARB_multitexture
  106. glActiveTextureARB(GL_TEXTURE1_ARB);
  107. #endif
  108. glMatrixMode(GL_TEXTURE);
  109. glLoadIdentity();
  110. glTranslatef(0.0, Drift, 0.0);
  111. glMatrixMode(GL_MODELVIEW);
  112. glutPostRedisplay();
  113. }
  114. }
  115. static void DrawObject(void)
  116. {
  117. glBegin(GL_QUADS);
  118. #ifdef GL_ARB_multitexture
  119. glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
  120. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
  121. glVertex2f(-1.0, -1.0);
  122. glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 0.0);
  123. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
  124. glVertex2f(1.0, -1.0);
  125. glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 2.0);
  126. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
  127. glVertex2f(1.0, 1.0);
  128. glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 2.0);
  129. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
  130. glVertex2f(-1.0, 1.0);
  131. #else
  132. glTexCoord2f(0.0, 0.0);
  133. glVertex2f(-1.0, -1.0);
  134. glTexCoord2f(1.0, 0.0);
  135. glVertex2f(1.0, -1.0);
  136. glTexCoord2f(1.0, 1.0);
  137. glVertex2f(1.0, 1.0);
  138. glTexCoord2f(0.0, 1.0);
  139. glVertex2f(-1.0, 1.0);
  140. #endif
  141. glEnd();
  142. }
  143. static void Display( void )
  144. {
  145. glClear( GL_COLOR_BUFFER_BIT );
  146. glPushMatrix();
  147. glRotatef(Xrot, 1.0, 0.0, 0.0);
  148. glRotatef(Yrot, 0.0, 1.0, 0.0);
  149. glRotatef(Zrot, 0.0, 0.0, 1.0);
  150. glScalef(5.0, 5.0, 5.0);
  151. DrawObject();
  152. glPopMatrix();
  153. glutSwapBuffers();
  154. }
  155. static void Reshape( int width, int height )
  156. {
  157. glViewport( 0, 0, width, height );
  158. glMatrixMode( GL_PROJECTION );
  159. glLoadIdentity();
  160. glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
  161. /*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/
  162. glMatrixMode( GL_MODELVIEW );
  163. glLoadIdentity();
  164. glTranslatef( 0.0, 0.0, -70.0 );
  165. }
  166. static void ModeMenu(int entry)
  167. {
  168. GLboolean enable0 = GL_FALSE, enable1 = GL_FALSE;
  169. if (entry==TEX0) {
  170. enable0 = GL_TRUE;
  171. }
  172. else if (entry==TEX1) {
  173. enable1 = GL_TRUE;
  174. }
  175. else if (entry==TEXBOTH) {
  176. enable0 = GL_TRUE;
  177. enable1 = GL_TRUE;
  178. }
  179. else if (entry==ANIMATE) {
  180. Animate = !Animate;
  181. }
  182. else if (entry==QUIT) {
  183. exit(0);
  184. }
  185. if (entry != ANIMATE) {
  186. #ifdef GL_ARB_multitexture
  187. glActiveTextureARB(GL_TEXTURE0_ARB);
  188. #endif
  189. if (enable0) {
  190. glEnable(GL_TEXTURE_2D);
  191. }
  192. else
  193. glDisable(GL_TEXTURE_2D);
  194. #ifdef GL_ARB_multitexture
  195. glActiveTextureARB(GL_TEXTURE1_ARB);
  196. #endif
  197. if (enable1) {
  198. glEnable(GL_TEXTURE_2D);
  199. }
  200. else
  201. glDisable(GL_TEXTURE_2D);
  202. }
  203. glutPostRedisplay();
  204. }
  205. static void Key( unsigned char key, int x, int y )
  206. {
  207. (void) x;
  208. (void) y;
  209. switch (key) {
  210. case 27:
  211. exit(0);
  212. break;
  213. }
  214. glutPostRedisplay();
  215. }
  216. static void SpecialKey( int key, int x, int y )
  217. {
  218. float step = 3.0;
  219. (void) x;
  220. (void) y;
  221. switch (key) {
  222. case GLUT_KEY_UP:
  223. Xrot += step;
  224. break;
  225. case GLUT_KEY_DOWN:
  226. Xrot -= step;
  227. break;
  228. case GLUT_KEY_LEFT:
  229. Yrot += step;
  230. break;
  231. case GLUT_KEY_RIGHT:
  232. Yrot -= step;
  233. break;
  234. }
  235. glutPostRedisplay();
  236. }
  237. static void Init( int argc, char *argv[] )
  238. {
  239. GLuint texObj[2];
  240. GLint units, size;
  241. const char *exten = (const char *) glGetString(GL_EXTENSIONS);
  242. if (!strstr(exten, "GL_ARB_multitexture")) {
  243. printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
  244. exit(1);
  245. }
  246. glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &units);
  247. printf("%d texture units supported\n", units);
  248. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
  249. printf("%d x %d max texture size\n", size, size);
  250. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  251. /* allocate two texture objects */
  252. glGenTextures(2, texObj);
  253. /* setup texture obj 0 */
  254. glBindTexture(GL_TEXTURE_2D, texObj[0]);
  255. #ifdef LINEAR_FILTER
  256. /* linear filtering looks much nicer but is much slower for Mesa */
  257. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  258. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  259. #else
  260. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  261. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  262. #endif
  263. if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) {
  264. printf("Error: couldn't load texture image\n");
  265. exit(1);
  266. }
  267. /* setup texture obj 1 */
  268. glBindTexture(GL_TEXTURE_2D, texObj[1]);
  269. #ifdef LINEAR_FILTER
  270. /* linear filtering looks much nicer but is much slower for Mesa */
  271. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  272. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  273. #else
  274. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  275. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  276. #endif
  277. if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) {
  278. printf("Error: couldn't load texture image\n");
  279. exit(1);
  280. }
  281. /* now bind the texture objects to the respective texture units */
  282. #ifdef GL_ARB_multitexture
  283. glActiveTextureARB(GL_TEXTURE0_ARB);
  284. glBindTexture(GL_TEXTURE_2D, texObj[0]);
  285. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  286. glActiveTextureARB(GL_TEXTURE1_ARB);
  287. glBindTexture(GL_TEXTURE_2D, texObj[1]);
  288. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  289. #endif
  290. glShadeModel(GL_FLAT);
  291. glClearColor(0.3, 0.3, 0.4, 1.0);
  292. ModeMenu(TEXBOTH);
  293. if (argc > 1 && strcmp(argv[1], "-info")==0) {
  294. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  295. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  296. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  297. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  298. }
  299. }
  300. int main( int argc, char *argv[] )
  301. {
  302. glutInit( &argc, argv );
  303. glutInitWindowSize( 300, 300 );
  304. glutInitWindowPosition( 0, 0 );
  305. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  306. glutCreateWindow(argv[0] );
  307. Init( argc, argv );
  308. glutReshapeFunc( Reshape );
  309. glutKeyboardFunc( Key );
  310. glutSpecialFunc( SpecialKey );
  311. glutDisplayFunc( Display );
  312. glutIdleFunc( Idle );
  313. glutCreateMenu(ModeMenu);
  314. glutAddMenuEntry("Texture 0", TEX0);
  315. glutAddMenuEntry("Texture 1", TEX1);
  316. glutAddMenuEntry("Multi-texture", TEXBOTH);
  317. glutAddMenuEntry("Toggle Animation", ANIMATE);
  318. glutAddMenuEntry("Quit", QUIT);
  319. glutAttachMenu(GLUT_RIGHT_BUTTON);
  320. glutMainLoop();
  321. return 0;
  322. }