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.

yuvrect.c 4.3KB

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