Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

yuvrect.c 4.3KB

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