Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

paltex.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* $Id: paltex.c,v 1.4 2000/06/27 17:12:10 brianp Exp $ */
  2. /*
  3. * Paletted texture demo. Written by Brian Paul.
  4. * This program is in the public domain.
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <math.h>
  9. #define GL_GLEXT_LEGACY
  10. #include <GL/glut.h>
  11. static float Rot = 0.0;
  12. static void Idle( void )
  13. {
  14. Rot += 5.0;
  15. glutPostRedisplay();
  16. }
  17. static void Display( void )
  18. {
  19. glClear( GL_COLOR_BUFFER_BIT );
  20. glPushMatrix();
  21. glRotatef(Rot, 0, 0, 1);
  22. glBegin(GL_POLYGON);
  23. glTexCoord2f(0, 1); glVertex2f(-1, -0.5);
  24. glTexCoord2f(1, 1); glVertex2f( 1, -0.5);
  25. glTexCoord2f(1, 0); glVertex2f( 1, 0.5);
  26. glTexCoord2f(0, 0); glVertex2f(-1, 0.5);
  27. glEnd();
  28. glPopMatrix();
  29. glutSwapBuffers();
  30. }
  31. static void Reshape( int width, int height )
  32. {
  33. glViewport( 0, 0, width, height );
  34. glMatrixMode( GL_PROJECTION );
  35. glLoadIdentity();
  36. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  37. glMatrixMode( GL_MODELVIEW );
  38. glLoadIdentity();
  39. glTranslatef( 0.0, 0.0, -7.0 );
  40. }
  41. static void Key( unsigned char key, int x, int y )
  42. {
  43. (void) x;
  44. (void) y;
  45. switch (key) {
  46. case 27:
  47. exit(0);
  48. break;
  49. }
  50. glutPostRedisplay();
  51. }
  52. static void Init( void )
  53. {
  54. #define HEIGHT 8
  55. #define WIDTH 32
  56. static char texture[HEIGHT][WIDTH] = {
  57. " ",
  58. " MMM EEEE SSS AAA ",
  59. " M M M E S S A A ",
  60. " M M M EEEE SS A A ",
  61. " M M M E SS AAAAA ",
  62. " M M E S S A A ",
  63. " M M EEEE SSS A A ",
  64. " "
  65. };
  66. GLubyte table[256][4];
  67. if (!glutExtensionSupported("GL_EXT_paletted_texture")) {
  68. printf("Sorry, GL_EXT_paletted_texture not supported\n");
  69. exit(0);
  70. }
  71. /* load the color table for each texel-index */
  72. table[' '][0] = 50;
  73. table[' '][1] = 50;
  74. table[' '][2] = 50;
  75. table[' '][3] = 50;
  76. table['M'][0] = 255;
  77. table['M'][1] = 0;
  78. table['M'][2] = 0;
  79. table['M'][3] = 0;
  80. table['E'][0] = 0;
  81. table['E'][1] = 255;
  82. table['E'][2] = 0;
  83. table['E'][3] = 0;
  84. table['S'][0] = 40;
  85. table['S'][1] = 40;
  86. table['S'][2] = 255;
  87. table['S'][3] = 0;
  88. table['A'][0] = 255;
  89. table['A'][1] = 255;
  90. table['A'][2] = 0;
  91. table['A'][3] = 0;
  92. #ifdef GL_EXT_paletted_texture
  93. #if defined(GL_EXT_shared_texture_palette) && defined(USE_SHARED_PALETTE)
  94. printf("Using shared palette\n");
  95. glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, /* target */
  96. GL_RGBA, /* internal format */
  97. 256, /* table size */
  98. GL_RGBA, /* table format */
  99. GL_UNSIGNED_BYTE, /* table type */
  100. table); /* the color table */
  101. glEnable(GL_SHARED_TEXTURE_PALETTE_EXT);
  102. #else
  103. glColorTableEXT(GL_TEXTURE_2D, /* target */
  104. GL_RGBA, /* internal format */
  105. 256, /* table size */
  106. GL_RGBA, /* table format */
  107. GL_UNSIGNED_BYTE, /* table type */
  108. table); /* the color table */
  109. #endif
  110. glTexImage2D(GL_TEXTURE_2D, /* target */
  111. 0, /* level */
  112. GL_COLOR_INDEX8_EXT, /* internal format */
  113. WIDTH, HEIGHT, /* width, height */
  114. 0, /* border */
  115. GL_COLOR_INDEX, /* texture format */
  116. GL_UNSIGNED_BYTE, /* texture type */
  117. texture); /* teh texture */
  118. #endif
  119. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  120. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  121. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  122. glEnable(GL_TEXTURE_2D);
  123. }
  124. int main( int argc, char *argv[] )
  125. {
  126. glutInit( &argc, argv );
  127. glutInitWindowPosition( 0, 0 );
  128. glutInitWindowSize( 400, 400 );
  129. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  130. glutCreateWindow(argv[0]);
  131. Init();
  132. glutReshapeFunc( Reshape );
  133. glutKeyboardFunc( Key );
  134. glutDisplayFunc( Display );
  135. glutIdleFunc( Idle );
  136. glutMainLoop();
  137. return 0;
  138. }