Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* $Id: paltex.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
  2. /*
  3. * Paletted texture demo. Written by Brian Paul. This file in public domain.
  4. */
  5. /*
  6. * $Log: paltex.c,v $
  7. * Revision 1.1 1999/08/19 00:55:40 jtg
  8. * Initial revision
  9. *
  10. * Revision 3.1 1999/03/28 18:20:49 brianp
  11. * minor clean-up
  12. *
  13. * Revision 3.0 1998/02/14 18:42:29 brianp
  14. * initial rev
  15. *
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <math.h>
  20. #include <GL/glut.h>
  21. static float Rot = 0.0;
  22. static void Idle( void )
  23. {
  24. Rot += 5.0;
  25. glutPostRedisplay();
  26. }
  27. static void Display( void )
  28. {
  29. glClear( GL_COLOR_BUFFER_BIT );
  30. glPushMatrix();
  31. glRotatef(Rot, 0, 0, 1);
  32. glBegin(GL_POLYGON);
  33. glTexCoord2f(0, 1); glVertex2f(-1, -1);
  34. glTexCoord2f(1, 1); glVertex2f( 1, -1);
  35. glTexCoord2f(1, 0); glVertex2f( 1, 1);
  36. glTexCoord2f(0, 0); glVertex2f(-1, 1);
  37. glEnd();
  38. glPopMatrix();
  39. glutSwapBuffers();
  40. }
  41. static void Reshape( int width, int height )
  42. {
  43. glViewport( 0, 0, width, height );
  44. glMatrixMode( GL_PROJECTION );
  45. glLoadIdentity();
  46. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  47. glMatrixMode( GL_MODELVIEW );
  48. glLoadIdentity();
  49. glTranslatef( 0.0, 0.0, -15.0 );
  50. }
  51. static void Key( unsigned char key, int x, int y )
  52. {
  53. (void) x;
  54. (void) y;
  55. switch (key) {
  56. case 27:
  57. exit(0);
  58. break;
  59. }
  60. glutPostRedisplay();
  61. }
  62. static void SpecialKey( int key, int x, int y )
  63. {
  64. (void) x;
  65. (void) y;
  66. switch (key) {
  67. case GLUT_KEY_UP:
  68. break;
  69. case GLUT_KEY_DOWN:
  70. break;
  71. case GLUT_KEY_LEFT:
  72. break;
  73. case GLUT_KEY_RIGHT:
  74. break;
  75. }
  76. glutPostRedisplay();
  77. }
  78. static void Init( void )
  79. {
  80. GLubyte texture[8][8] = { /* PT = Paletted Texture! */
  81. { 0, 0, 0, 0, 0, 0, 0, 0},
  82. { 0, 100, 100, 100, 0, 180, 180, 180},
  83. { 0, 100, 0, 100, 0, 0, 180, 0},
  84. { 0, 100, 0, 100, 0, 0, 180, 0},
  85. { 0, 100, 100, 100, 0, 0, 180, 0},
  86. { 0, 100, 0, 0, 0, 0, 180, 0},
  87. { 0, 100, 0, 0, 0, 0, 180, 0},
  88. { 0, 100, 255, 0, 0, 0, 180, 250},
  89. };
  90. GLubyte table[256][4];
  91. int i;
  92. if (!glutExtensionSupported("GL_EXT_paletted_texture")) {
  93. printf("Sorry, GL_EXT_paletted_texture not supported\n");
  94. exit(0);
  95. }
  96. /* put some wacky colors into the texture palette */
  97. for (i=0;i<256;i++) {
  98. table[i][0] = i;
  99. table[i][1] = 0;
  100. table[i][2] = 127 + i / 2;
  101. table[i][3] = 255;
  102. }
  103. #ifdef GL_EXT_paletted_texture
  104. #if defined(GL_EXT_shared_texture_palette) && defined(SHARED_PALETTE)
  105. printf("Using shared palette\n");
  106. glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, /* target */
  107. GL_RGBA, /* internal format */
  108. 256, /* table size */
  109. GL_RGBA, /* table format */
  110. GL_UNSIGNED_BYTE, /* table type */
  111. table); /* the color table */
  112. glEnable(GL_SHARED_TEXTURE_PALETTE_EXT);
  113. #else
  114. glColorTableEXT(GL_TEXTURE_2D, /* target */
  115. GL_RGBA, /* internal format */
  116. 256, /* table size */
  117. GL_RGBA, /* table format */
  118. GL_UNSIGNED_BYTE, /* table type */
  119. table); /* the color table */
  120. #endif
  121. glTexImage2D(GL_TEXTURE_2D, /* target */
  122. 0, /* level */
  123. GL_COLOR_INDEX8_EXT, /* internal format */
  124. 8, 8, /* width, height */
  125. 0, /* border */
  126. GL_COLOR_INDEX, /* texture format */
  127. GL_UNSIGNED_BYTE, /* texture type */
  128. texture); /* teh texture */
  129. #endif
  130. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  131. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  132. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  133. glEnable(GL_TEXTURE_2D);
  134. }
  135. int main( int argc, char *argv[] )
  136. {
  137. glutInit( &argc, argv );
  138. glutInitWindowPosition( 0, 0 );
  139. glutInitWindowSize( 400, 400 );
  140. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  141. glutCreateWindow(argv[0]);
  142. Init();
  143. glutReshapeFunc( Reshape );
  144. glutKeyboardFunc( Key );
  145. glutSpecialFunc( SpecialKey );
  146. glutDisplayFunc( Display );
  147. glutIdleFunc( Idle );
  148. glutMainLoop();
  149. return 0;
  150. }