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>
42 #define IMAGE_FILE "../images/tree3.rgb"
44 static int Width
= 420;
45 static int Height
= 150;
46 static const GLfloat Near
= 5.0, Far
= 25.0;
48 static GLubyte
* image
= NULL
;
49 static GLubyte
* temp_image
= NULL
;
50 static GLuint img_width
= 0;
51 static GLuint img_height
= 0;
52 static GLuint img_format
= 0;
54 PFNGLWINDOWPOS2IPROC win_pos_2i
= NULL
;
57 static void Display( void )
62 glClearColor(0.2, 0.2, 0.8, 0);
63 glClear( GL_COLOR_BUFFER_BIT
);
66 /* This is the "reference" square.
69 (*win_pos_2i
)( 5, 5 );
70 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, image
);
72 glPixelStorei( GL_PACK_INVERT_MESA
, GL_FALSE
);
74 if ( err
!= GL_NO_ERROR
) {
75 printf( "Setting PACK_INVERT_MESA to false generated an error (0x%04x).\n",
79 glReadPixels( 5, 5, img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
80 (*win_pos_2i
)( 5 + 1 * (10 + img_width
), 5 );
81 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
83 glPixelStorei( GL_PACK_INVERT_MESA
, GL_TRUE
);
85 if ( err
!= GL_NO_ERROR
) {
86 printf( "Setting PACK_INVERT_MESA to true generated an error (0x%04x).\n",
90 glReadPixels( 5, 5, img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
91 (*win_pos_2i
)( 5 + 2 * (10 + img_width
), 5 );
92 glDrawPixels( img_width
, img_height
, img_format
, GL_UNSIGNED_BYTE
, temp_image
);
98 static void Reshape( int width
, int height
)
100 GLfloat ar
= (float) width
/ (float) height
;
103 glViewport( 0, 0, width
, height
);
104 glMatrixMode( GL_PROJECTION
);
106 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
107 glMatrixMode( GL_MODELVIEW
);
109 glTranslatef( 0.0, 0.0, -15.0 );
113 static void Key( unsigned char key
, int x
, int y
)
126 static void Init( void )
128 const char * const ver_string
= (const char * const)
129 glGetString( GL_VERSION
);
130 const float ver
= strtof( ver_string
, NULL
);
133 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
134 printf("GL_VERSION = %s\n", ver_string
);
136 if ( !glutExtensionSupported("GL_MESA_pack_invert") ) {
137 printf("\nSorry, this program requires GL_MESA_pack_invert.\n");
142 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2i" );
144 else if ( glutExtensionSupported("GL_ARB_window_pos") ) {
145 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2iARB" );
147 else if ( glutExtensionSupported("GL_MESA_window_pos") ) {
148 win_pos_2i
= (PFNGLWINDOWPOS2IPROC
) glutGetProcAddress( "glWindowPos2iMESA" );
152 /* Do this check as a separate if-statement instead of as an else in case
153 * one of the required extensions is supported but glutGetProcAddress
157 if ( win_pos_2i
== NULL
) {
158 printf("\nSorry, this program requires either GL 1.4 (or higher),\n"
159 "GL_ARB_window_pos, or GL_MESA_window_pos.\n");
163 printf("\nThe left 2 squares should be the same color, and the right\n"
164 "square should look upside-down.\n");
167 image
= LoadRGBImage( IMAGE_FILE
, & img_width
, & img_height
,
169 if ( image
== NULL
) {
170 printf( "Could not open image file \"%s\".\n", IMAGE_FILE
);
174 temp_image
= malloc( 3 * img_height
* img_width
);
175 if ( temp_image
== NULL
) {
176 printf( "Could not allocate memory for temporary image.\n" );
182 int main( int argc
, char *argv
[] )
184 glutInit( &argc
, argv
);
185 glutInitWindowPosition( 0, 0 );
186 glutInitWindowSize( Width
, Height
);
187 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
188 glutCreateWindow( "GL_MESA_pack_invert test" );
189 glutReshapeFunc( Reshape
);
190 glutKeyboardFunc( Key
);
191 glutDisplayFunc( Display
);