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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* $Id: texline.c,v 1.1 2000/09/30 18:48:33 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_TRUE;
  16. static GLboolean Texture = GL_TRUE;
  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 void Idle( void )
  21. {
  22. if (Animate) {
  23. Zrot += DYrot;
  24. glutPostRedisplay();
  25. }
  26. }
  27. static void Display( void )
  28. {
  29. GLfloat x, t;
  30. glClear( GL_COLOR_BUFFER_BIT );
  31. glPushMatrix();
  32. glRotatef(Xrot, 1.0, 0.0, 0.0);
  33. glRotatef(Yrot, 0.0, 1.0, 0.0);
  34. glRotatef(Zrot, 0.0, 0.0, 1.0);
  35. glColor3f(1, 1, 1);
  36. glBegin(GL_LINES);
  37. for (t = 0.0; t <= 1.0; t += 0.0125) {
  38. x = t * 2.0 - 1.0;
  39. glTexCoord2f(t, 0.0); glVertex2f(x, -1.0);
  40. glTexCoord2f(t, 1.0); glVertex2f(x, 1.0);
  41. }
  42. glEnd();
  43. glPopMatrix();
  44. glutSwapBuffers();
  45. }
  46. static void Reshape( int width, int height )
  47. {
  48. GLfloat ar = (float) width / height;
  49. glViewport( 0, 0, width, height );
  50. glMatrixMode( GL_PROJECTION );
  51. glLoadIdentity();
  52. glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 );
  53. glMatrixMode( GL_MODELVIEW );
  54. glLoadIdentity();
  55. glTranslatef( 0.0, 0.0, -12.0 );
  56. }
  57. static void Key( unsigned char key, int x, int y )
  58. {
  59. (void) x;
  60. (void) y;
  61. switch (key) {
  62. case 'a':
  63. Antialias = !Antialias;
  64. if (Antialias) {
  65. glEnable(GL_LINE_SMOOTH);
  66. glEnable(GL_BLEND);
  67. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  68. }
  69. else {
  70. glDisable(GL_LINE_SMOOTH);
  71. glDisable(GL_BLEND);
  72. }
  73. break;
  74. case 't':
  75. Texture = !Texture;
  76. if (Texture)
  77. glEnable(GL_TEXTURE_2D);
  78. else
  79. glDisable(GL_TEXTURE_2D);
  80. break;
  81. case 'w':
  82. LineWidth -= 0.25;
  83. if (LineWidth < 0.25)
  84. LineWidth = 0.25;
  85. glLineWidth(LineWidth);
  86. break;
  87. case 'W':
  88. LineWidth += 0.25;
  89. if (LineWidth > 8.0)
  90. LineWidth = 8.0;
  91. glLineWidth(LineWidth);
  92. break;
  93. case ' ':
  94. Animate = !Animate;
  95. if (Animate)
  96. glutIdleFunc(Idle);
  97. else
  98. glutIdleFunc(NULL);
  99. break;
  100. case 27:
  101. exit(0);
  102. break;
  103. }
  104. printf("Width %f\n", LineWidth);
  105. glutPostRedisplay();
  106. }
  107. static void SpecialKey( int key, int x, int y )
  108. {
  109. float step = 3.0;
  110. (void) x;
  111. (void) y;
  112. switch (key) {
  113. case GLUT_KEY_UP:
  114. Xrot += step;
  115. break;
  116. case GLUT_KEY_DOWN:
  117. Xrot -= step;
  118. break;
  119. case GLUT_KEY_LEFT:
  120. Yrot += step;
  121. break;
  122. case GLUT_KEY_RIGHT:
  123. Yrot -= step;
  124. break;
  125. }
  126. glutPostRedisplay();
  127. }
  128. static void Init( int argc, char *argv[] )
  129. {
  130. glEnable(GL_TEXTURE_2D);
  131. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  132. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  133. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  134. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  135. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  136. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  137. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  138. printf("Error: couldn't load texture image\n");
  139. exit(1);
  140. }
  141. if (argc > 1 && strcmp(argv[1], "-info")==0) {
  142. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  143. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  144. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  145. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  146. }
  147. }
  148. int main( int argc, char *argv[] )
  149. {
  150. glutInit( &argc, argv );
  151. glutInitWindowSize( 400, 300 );
  152. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  153. glutCreateWindow(argv[0] );
  154. Init(argc, argv);
  155. glutReshapeFunc( Reshape );
  156. glutKeyboardFunc( Key );
  157. glutSpecialFunc( SpecialKey );
  158. glutDisplayFunc( Display );
  159. glutIdleFunc( Idle );
  160. glutMainLoop();
  161. return 0;
  162. }