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.0KB

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