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.

texline.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* $Id: texline.c,v 1.3 2001/05/21 17:45:25 brianp Exp $ */
  2. /*
  3. * Test textured lines.
  4. *
  5. * Brian Paul
  6. * September 2000
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <GL/glut.h>
  12. #include "../util/readtex.c" /* I know, this is a hack. */
  13. #define TEXTURE_FILE "../images/girl.rgb"
  14. static GLboolean Antialias = GL_FALSE;
  15. static GLboolean Animate = GL_FALSE;
  16. static GLboolean Texture = GL_TRUE;
  17. static GLfloat LineWidth = 1.0;
  18. static GLboolean Multitex = GL_FALSE;
  19. static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0;
  20. static GLfloat DYrot = 1.0;
  21. static GLboolean Points = GL_FALSE;
  22. static void Idle( void )
  23. {
  24. if (Animate) {
  25. Zrot += DYrot;
  26. glutPostRedisplay();
  27. }
  28. }
  29. static void Display( void )
  30. {
  31. GLfloat x, y, s, t;
  32. glClear( GL_COLOR_BUFFER_BIT );
  33. glPushMatrix();
  34. glRotatef(Xrot, 1.0, 0.0, 0.0);
  35. glRotatef(Yrot, 0.0, 1.0, 0.0);
  36. glRotatef(Zrot, 0.0, 0.0, 1.0);
  37. if (Texture)
  38. glColor3f(1, 1, 1);
  39. if (Points) {
  40. glBegin(GL_POINTS);
  41. for (t = 0.0; t <= 1.0; t += 0.025) {
  42. for (s = 0.0; s <= 1.0; s += 0.025) {
  43. x = s * 2.0 - 1.0;
  44. y = t * 2.0 - 1.0;
  45. if (!Texture)
  46. glColor3f(1, 0, 1);
  47. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, t, s);
  48. glTexCoord2f(s, t);
  49. glVertex2f(x, y);
  50. }
  51. }
  52. glEnd();
  53. }
  54. else {
  55. glBegin(GL_LINES);
  56. for (t = 0.0; t <= 1.0; t += 0.025) {
  57. x = t * 2.0 - 1.0;
  58. if (!Texture)
  59. glColor3f(1, 0, 1);
  60. glTexCoord2f(t, 0.0);
  61. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, t);
  62. glVertex2f(x, -1.0);
  63. if (!Texture)
  64. glColor3f(0, 1, 0);
  65. glTexCoord2f(t, 1.0);
  66. glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, t);
  67. glVertex2f(x, 1.0);
  68. }
  69. glEnd();
  70. }
  71. glPopMatrix();
  72. glutSwapBuffers();
  73. }
  74. static void Reshape( int width, int height )
  75. {
  76. GLfloat ar = (float) width / height;
  77. glViewport( 0, 0, width, height );
  78. glMatrixMode( GL_PROJECTION );
  79. glLoadIdentity();
  80. glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 );
  81. glMatrixMode( GL_MODELVIEW );
  82. glLoadIdentity();
  83. glTranslatef( 0.0, 0.0, -12.0 );
  84. }
  85. static void Key( unsigned char key, int x, int y )
  86. {
  87. (void) x;
  88. (void) y;
  89. switch (key) {
  90. case 'a':
  91. Antialias = !Antialias;
  92. if (Antialias) {
  93. glEnable(GL_LINE_SMOOTH);
  94. glEnable(GL_POINT_SMOOTH);
  95. glEnable(GL_BLEND);
  96. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  97. }
  98. else {
  99. glDisable(GL_LINE_SMOOTH);
  100. glDisable(GL_POINT_SMOOTH);
  101. glDisable(GL_BLEND);
  102. }
  103. break;
  104. case 't':
  105. Texture = !Texture;
  106. if (Texture)
  107. glEnable(GL_TEXTURE_2D);
  108. else
  109. glDisable(GL_TEXTURE_2D);
  110. break;
  111. case 'w':
  112. LineWidth -= 0.25;
  113. if (LineWidth < 0.25)
  114. LineWidth = 0.25;
  115. glLineWidth(LineWidth);
  116. glPointSize(LineWidth);
  117. break;
  118. case 'W':
  119. LineWidth += 0.25;
  120. if (LineWidth > 8.0)
  121. LineWidth = 8.0;
  122. glLineWidth(LineWidth);
  123. glPointSize(LineWidth);
  124. break;
  125. case 'm':
  126. Multitex = !Multitex;
  127. if (Multitex) {
  128. glEnable(GL_TEXTURE_2D);
  129. }
  130. else {
  131. glDisable(GL_TEXTURE_2D);
  132. }
  133. break;
  134. case 'p':
  135. Points = !Points;
  136. break;
  137. case ' ':
  138. Animate = !Animate;
  139. if (Animate)
  140. glutIdleFunc(Idle);
  141. else
  142. glutIdleFunc(NULL);
  143. break;
  144. case 27:
  145. exit(0);
  146. break;
  147. }
  148. printf("LineWidth, PointSize = %f\n", LineWidth);
  149. glutPostRedisplay();
  150. }
  151. static void SpecialKey( int key, int x, int y )
  152. {
  153. float step = 3.0;
  154. (void) x;
  155. (void) y;
  156. switch (key) {
  157. case GLUT_KEY_UP:
  158. Xrot += step;
  159. break;
  160. case GLUT_KEY_DOWN:
  161. Xrot -= step;
  162. break;
  163. case GLUT_KEY_LEFT:
  164. Yrot += step;
  165. break;
  166. case GLUT_KEY_RIGHT:
  167. Yrot -= step;
  168. break;
  169. }
  170. glutPostRedisplay();
  171. }
  172. static void Init( int argc, char *argv[] )
  173. {
  174. GLuint u;
  175. for (u = 0; u < 2; u++) {
  176. glActiveTextureARB(GL_TEXTURE0_ARB + u);
  177. glBindTexture(GL_TEXTURE_2D, 10+u);
  178. if (u == 0 || Multitex)
  179. glEnable(GL_TEXTURE_2D);
  180. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  181. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  182. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  183. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  184. if (u == 0)
  185. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  186. else
  187. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
  188. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  189. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  190. printf("Error: couldn't load texture image\n");
  191. exit(1);
  192. }
  193. }
  194. if (argc > 1 && strcmp(argv[1], "-info")==0) {
  195. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  196. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  197. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  198. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  199. }
  200. }
  201. int main( int argc, char *argv[] )
  202. {
  203. glutInit( &argc, argv );
  204. glutInitWindowSize( 400, 300 );
  205. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  206. glutCreateWindow(argv[0] );
  207. Init(argc, argv);
  208. glutReshapeFunc( Reshape );
  209. glutKeyboardFunc( Key );
  210. glutSpecialFunc( SpecialKey );
  211. glutDisplayFunc( Display );
  212. if (Animate)
  213. glutIdleFunc( Idle );
  214. glutMainLoop();
  215. return 0;
  216. }