Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

texline.c 4.4KB

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