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