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 6.3KB

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