2 * (C) Copyright IBM Corporation 2005
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:
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
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.
28 * Simple test of GL_MESA_pack_invert functionality. Three squares are
29 * drawn. The first two should look the same, and the third one should
32 * \author Ian Romanick <idr@us.ibm.com>
43 #define IMAGE_FILE "../images/tree3.rgb"
45 static int Width
= 420;
46 static int Height
= 150;
47 static const GLfloat Near
= 5.0, Far
= 25.0;
49 static GLubyte
* image
= NULL
;
50 static GLubyte
* temp_image
= NULL
;
51 static GLuint img_width
= 0;
52 static GLuint img_height
= 0;
53 static GLuint img_format
= 0;
55 PFNGLWINDOWPOS2IPROC win_pos_2i
= NULL
;
58 static void Display( void )
63 glClearColor(0.2, 0.2, 0.8, 0);
64 glClear( GL_COLOR_BUFFER_BIT
);
67 /* This is the "reference" square.
70 (*win_pos_2i
)( 5, 5 );
71 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, image
);
73 glPixelStorei( GL_PACK_INVERT_MESA
, GL_FALSE
);
75 if ( err
!= GL_NO_ERROR
) {
76 printf( "Setting PACK_INVERT_MESA to false generated an error (0x%04x).\n",
80 glReadPixels( 5, 5, img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
81 (*win_pos_2i
)( 5 + 1 * (10 + img_width
), 5 );
82 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
84 glPixelStorei( GL_PACK_INVERT_MESA
, GL_TRUE
);
86 if ( err
!= GL_NO_ERROR
) {
87 printf( "Setting PACK_INVERT_MESA to true generated an error (0x%04x).\n",
91 glReadPixels( 5, 5, img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
92 (*win_pos_2i
)( 5 + 2 * (10 + img_width
), 5 );
93 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
99 static void Reshape( int width
, int height
)
101 GLfloat ar
= (float) width
/ (float) height
;
104 glViewport( 0, 0, width
, height
);
105 glMatrixMode( GL_PROJECTION
);
107 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
108 glMatrixMode( GL_MODELVIEW
);
110 glTranslatef( 0.0, 0.0, -15.0 );
114 static void Key( unsigned char key
, int x
, int y
)
127 static void Init( void )
129 const char * const ver_string
= (const char * const)
130 glGetString( GL_VERSION
);
131 const float ver
= strtod( ver_string
, NULL
);
134 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
135 printf("GL_VERSION = %s\n", ver_string
);
137 if ( !glutExtensionSupported("GL_MESA_pack_invert") ) {
138 printf("\nSorry, this program requires GL_MESA_pack_invert.\n");
143 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2i" );
145 else if ( glutExtensionSupported("GL_ARB_window_pos") ) {
146 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2iARB" );
148 else if ( glutExtensionSupported("GL_MESA_window_pos") ) {
149 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2iMESA" );
153 /* Do this check as a separate if-statement instead of as an else in case
154 * one of the required extensions is supported but glutGetProcAddress
158 if ( win_pos_2i
== NULL
) {
159 printf("\nSorry, this program requires either GL 1.4 (or higher),\n"
160 "GL_ARB_window_pos, or GL_MESA_window_pos.\n");
164 printf("\nThe left 2 squares should be the same color, and the right\n"
165 "square should look upside-down.\n");
168 image
= LoadRGBImage( IMAGE_FILE
, (GLint
*) & img_width
, (GLint
*) & img_height
,
170 if ( image
== NULL
) {
171 printf( "Could not open image file \"%s\".\n", IMAGE_FILE
);
175 temp_image
= malloc( 3 * img_height
* img_width
);
176 if ( temp_image
== NULL
) {
177 printf( "Could not allocate memory for temporary image.\n" );
183 int main( int argc
, char *argv
[] )
185 glutInit( &argc
, argv
);
186 glutInitWindowPosition( 0, 0 );
187 glutInitWindowSize( Width
, Height
);
188 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
189 glutCreateWindow( "GL_MESA_pack_invert test" );
191 glutReshapeFunc( Reshape
);
192 glutKeyboardFunc( Key
);
193 glutDisplayFunc( Display
);