Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

invert.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * (C) Copyright IBM Corporation 2005
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file invert.c
  26. *
  27. * Simple test of GL_MESA_pack_invert functionality. Three squares are
  28. * drawn. The first two should look the same, and the third one should
  29. * look inverted.
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <GL/glut.h>
  37. #include "readtex.h"
  38. #define IMAGE_FILE "../images/tree3.rgb"
  39. static int Width = 420;
  40. static int Height = 150;
  41. static const GLfloat Near = 5.0, Far = 25.0;
  42. static GLubyte * image = NULL;
  43. static GLubyte * temp_image = NULL;
  44. static GLuint img_width = 0;
  45. static GLuint img_height = 0;
  46. static GLuint img_format = 0;
  47. PFNGLWINDOWPOS2IPROC win_pos_2i = NULL;
  48. static void Display( void )
  49. {
  50. GLint err;
  51. glClearColor(0.2, 0.2, 0.8, 0);
  52. glClear( GL_COLOR_BUFFER_BIT );
  53. /* This is the "reference" square.
  54. */
  55. (*win_pos_2i)( 5, 5 );
  56. glDrawPixels( img_width, img_height, img_format, GL_UNSIGNED_BYTE, image );
  57. glPixelStorei( GL_PACK_INVERT_MESA, GL_FALSE );
  58. err = glGetError();
  59. if ( err != GL_NO_ERROR ) {
  60. printf( "Setting PACK_INVERT_MESA to false generated an error (0x%04x).\n",
  61. err );
  62. }
  63. glReadPixels( 5, 5, img_width, img_height, img_format, GL_UNSIGNED_BYTE, temp_image );
  64. (*win_pos_2i)( 5 + 1 * (10 + img_width), 5 );
  65. glDrawPixels( img_width, img_height, img_format, GL_UNSIGNED_BYTE, temp_image );
  66. glPixelStorei( GL_PACK_INVERT_MESA, GL_TRUE );
  67. err = glGetError();
  68. if ( err != GL_NO_ERROR ) {
  69. printf( "Setting PACK_INVERT_MESA to true generated an error (0x%04x).\n",
  70. err );
  71. }
  72. glReadPixels( 5, 5, img_width, img_height, img_format, GL_UNSIGNED_BYTE, temp_image );
  73. (*win_pos_2i)( 5 + 2 * (10 + img_width), 5 );
  74. glDrawPixels( img_width, img_height, img_format, GL_UNSIGNED_BYTE, temp_image );
  75. glutSwapBuffers();
  76. }
  77. static void Reshape( int width, int height )
  78. {
  79. GLfloat ar = (float) width / (float) height;
  80. Width = width;
  81. Height = height;
  82. glViewport( 0, 0, width, height );
  83. glMatrixMode( GL_PROJECTION );
  84. glLoadIdentity();
  85. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  86. glMatrixMode( GL_MODELVIEW );
  87. glLoadIdentity();
  88. glTranslatef( 0.0, 0.0, -15.0 );
  89. }
  90. static void Key( unsigned char key, int x, int y )
  91. {
  92. (void) x;
  93. (void) y;
  94. switch (key) {
  95. case 27:
  96. exit(0);
  97. break;
  98. }
  99. glutPostRedisplay();
  100. }
  101. static void Init( void )
  102. {
  103. const char * const ver_string = (const char * const)
  104. glGetString( GL_VERSION );
  105. const float ver = strtof( ver_string, NULL );
  106. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  107. printf("GL_VERSION = %s\n", ver_string);
  108. if ( !glutExtensionSupported("GL_MESA_pack_invert") ) {
  109. printf("\nSorry, this program requires GL_MESA_pack_invert.\n");
  110. exit(1);
  111. }
  112. if ( ver >= 1.4 ) {
  113. win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2i" );
  114. }
  115. else if ( glutExtensionSupported("GL_ARB_window_pos") ) {
  116. win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2iARB" );
  117. }
  118. else if ( glutExtensionSupported("GL_MESA_window_pos") ) {
  119. win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2iMESA" );
  120. }
  121. /* Do this check as a separate if-statement instead of as an else in case
  122. * one of the required extensions is supported but glutGetProcAddress
  123. * returns NULL.
  124. */
  125. if ( win_pos_2i == NULL ) {
  126. printf("\nSorry, this program requires either GL 1.4 (or higher),\n"
  127. "GL_ARB_window_pos, or GL_MESA_window_pos.\n");
  128. exit(1);
  129. }
  130. printf("\nThe left 2 squares should be the same color, and the right\n"
  131. "square should look upside-down.\n");
  132. image = LoadRGBImage( IMAGE_FILE, & img_width, & img_height,
  133. & img_format );
  134. if ( image == NULL ) {
  135. printf( "Could not open image file \"%s\".\n", IMAGE_FILE );
  136. exit(1);
  137. }
  138. temp_image = malloc( 3 * img_height * img_width );
  139. if ( temp_image == NULL ) {
  140. printf( "Could not allocate memory for temporary image.\n" );
  141. exit(1);
  142. }
  143. }
  144. int main( int argc, char *argv[] )
  145. {
  146. glutInit( &argc, argv );
  147. glutInitWindowPosition( 0, 0 );
  148. glutInitWindowSize( Width, Height );
  149. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  150. glutCreateWindow( "GL_MESA_pack_invert test" );
  151. glutReshapeFunc( Reshape );
  152. glutKeyboardFunc( Key );
  153. glutDisplayFunc( Display );
  154. Init();
  155. glutMainLoop();
  156. return 0;
  157. }