Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

yuvsquare.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions.
  3. *
  4. * Brian Paul 13 September 2002
  5. */
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <GL/glew.h>
  11. #include <GL/glut.h>
  12. #include "../util/readtex.c" /* I know, this is a hack. */
  13. #define TEXTURE_FILE "../images/tile.rgb"
  14. static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
  15. static GLint ImgWidth, ImgHeight;
  16. static GLushort *ImageYUV = NULL;
  17. static GLubyte *ImageRGB = NULL;
  18. static const GLuint yuvObj = 100;
  19. static const GLuint rgbObj = 101;
  20. static void DrawObject(void)
  21. {
  22. glBegin(GL_QUADS);
  23. glTexCoord2f(0, 0);
  24. glVertex2f(-1.0, -1.0);
  25. glTexCoord2f(1, 0);
  26. glVertex2f(1.0, -1.0);
  27. glTexCoord2f(1, 1);
  28. glVertex2f(1.0, 1.0);
  29. glTexCoord2f(0, 1);
  30. glVertex2f(-1.0, 1.0);
  31. glEnd();
  32. }
  33. static void Display( void )
  34. {
  35. glClear( GL_COLOR_BUFFER_BIT );
  36. glPushMatrix();
  37. glTranslatef( -1.1, 0.0, -15.0 );
  38. glRotatef(Xrot, 1.0, 0.0, 0.0);
  39. glRotatef(Yrot, 0.0, 1.0, 0.0);
  40. glRotatef(Zrot, 0.0, 0.0, 1.0);
  41. glBindTexture(GL_TEXTURE_2D, yuvObj);
  42. DrawObject();
  43. glPopMatrix();
  44. glPushMatrix();
  45. glTranslatef( 1.1, 0.0, -15.0 );
  46. glRotatef(Xrot, 1.0, 0.0, 0.0);
  47. glRotatef(Yrot, 0.0, 1.0, 0.0);
  48. glRotatef(Zrot, 0.0, 0.0, 1.0);
  49. glBindTexture(GL_TEXTURE_2D, rgbObj);
  50. DrawObject();
  51. glPopMatrix();
  52. glutSwapBuffers();
  53. }
  54. static void Reshape( int width, int height )
  55. {
  56. glViewport( 0, 0, width, height );
  57. glMatrixMode( GL_PROJECTION );
  58. glLoadIdentity();
  59. glFrustum( -1.1, 1.1, -1.1, 1.1, 10.0, 100.0 );
  60. glMatrixMode( GL_MODELVIEW );
  61. glLoadIdentity();
  62. glTranslatef( 0.0, 0.0, -15.0 );
  63. }
  64. static void Key( unsigned char key, int x, int y )
  65. {
  66. (void) x;
  67. (void) y;
  68. switch (key) {
  69. case 27:
  70. exit(0);
  71. break;
  72. }
  73. glutPostRedisplay();
  74. }
  75. static void SpecialKey( int key, int x, int y )
  76. {
  77. float step = 3.0;
  78. (void) x;
  79. (void) y;
  80. switch (key) {
  81. case GLUT_KEY_UP:
  82. Xrot += step;
  83. break;
  84. case GLUT_KEY_DOWN:
  85. Xrot -= step;
  86. break;
  87. case GLUT_KEY_LEFT:
  88. Yrot += step;
  89. break;
  90. case GLUT_KEY_RIGHT:
  91. Yrot -= step;
  92. break;
  93. }
  94. glutPostRedisplay();
  95. }
  96. #define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
  97. /* #define LINEAR_FILTER */
  98. static void Init( int argc, char *argv[] )
  99. {
  100. const char *file;
  101. GLenum format;
  102. if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) {
  103. printf("Sorry, GL_MESA_ycbcr_texture is required\n");
  104. exit(0);
  105. }
  106. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  107. if (argc > 1)
  108. file = argv[1];
  109. else
  110. file = TEXTURE_FILE;
  111. /* First load the texture as YCbCr.
  112. */
  113. glBindTexture(GL_TEXTURE_2D, yuvObj);
  114. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  115. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  116. ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight );
  117. if (!ImageYUV) {
  118. printf("Couldn't read %s\n", TEXTURE_FILE);
  119. exit(0);
  120. }
  121. printf("Image: %dx%d\n", ImgWidth, ImgHeight);
  122. glTexImage2D(GL_TEXTURE_2D, 0,
  123. GL_YCBCR_MESA,
  124. ImgWidth, ImgHeight, 0,
  125. GL_YCBCR_MESA,
  126. GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV);
  127. glEnable(GL_TEXTURE_2D);
  128. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  129. /* Now load the texture as RGB.
  130. */
  131. glBindTexture(GL_TEXTURE_2D, rgbObj);
  132. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  133. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  134. ImageRGB = LoadRGBImage(file, &ImgWidth, &ImgHeight, &format );
  135. if (!ImageRGB) {
  136. printf("Couldn't read %s\n", TEXTURE_FILE);
  137. exit(0);
  138. }
  139. printf("Image: %dx%d\n", ImgWidth, ImgHeight);
  140. glTexImage2D(GL_TEXTURE_2D, 0,
  141. format,
  142. ImgWidth, ImgHeight, 0,
  143. format,
  144. GL_UNSIGNED_BYTE, ImageRGB);
  145. glEnable(GL_TEXTURE_2D);
  146. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  147. glShadeModel(GL_FLAT);
  148. glClearColor(0.3, 0.3, 0.4, 1.0);
  149. if (argc > 1 && strcmp(argv[1], "-info")==0) {
  150. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  151. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  152. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  153. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  154. }
  155. printf( "Both images should appear the same.\n" );
  156. }
  157. int main( int argc, char *argv[] )
  158. {
  159. glutInit( &argc, argv );
  160. glutInitWindowSize( 300, 300 );
  161. glutInitWindowPosition( 0, 0 );
  162. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  163. glutCreateWindow(argv[0] );
  164. glewInit();
  165. Init( argc, argv );
  166. glutReshapeFunc( Reshape );
  167. glutKeyboardFunc( Key );
  168. glutSpecialFunc( SpecialKey );
  169. glutDisplayFunc( Display );
  170. glutMainLoop();
  171. return 0;
  172. }