3 * Example of how to use the GL_MESA_window_pos extension.
4 * Brian Paul This file is in the public domain.
14 #define GL_GLEXT_PROTOTYPES
19 #define IMAGE_FILE "../images/girl.rgb"
23 # define M_PI 3.14159265
28 static GLubyte
*Image
;
29 static int ImgWidth
, ImgHeight
;
30 static GLenum ImgFormat
;
32 typedef void (APIENTRY
* PFNWINDOWPOSFUNC
)(GLfloat x
, GLfloat y
);
33 static PFNWINDOWPOSFUNC WindowPosFunc
;
35 static void draw( void )
39 glClear( GL_COLOR_BUFFER_BIT
);
41 for (angle
= -45.0; angle
<= 135.0; angle
+= 10.0) {
42 GLfloat x
= 50.0 + 200.0 * cos( angle
* M_PI
/ 180.0 );
43 GLfloat y
= 50.0 + 200.0 * sin( angle
* M_PI
/ 180.0 );
45 /* Don't need to worry about the modelview or projection matrices!!! */
46 (*WindowPosFunc
)( x
, y
);
48 glDrawPixels( ImgWidth
, ImgHeight
, ImgFormat
, GL_UNSIGNED_BYTE
, Image
);
54 static void key( unsigned char key
, int x
, int y
)
65 /* new window size or exposure */
66 static void reshape( int width
, int height
)
68 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
72 static void init( void )
74 #ifdef GL_ARB_window_pos
75 if (glutExtensionSupported("GL_ARB_window_pos")) {
76 printf("Using GL_ARB_window_pos\n");
77 WindowPosFunc
= &glWindowPos2fARB
;
80 #elif defined(GL_MESA_window_pos)
81 if (glutExtensionSupported("GL_MESA_window_pos")) {
82 printf("Using GL_MESA_window_pos\n");
83 WindowPosFunc
= &glWindowPos2fMESA
;
88 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
92 Image
= LoadRGBImage( IMAGE_FILE
, &ImgWidth
, &ImgHeight
, &ImgFormat
);
94 printf("Couldn't read %s\n", IMAGE_FILE
);
97 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
101 int main( int argc
, char *argv
[] )
103 glutInit(&argc
, argv
);
104 glutInitWindowPosition(0, 0);
105 glutInitWindowSize(500, 500);
106 glutInitDisplayMode( GLUT_RGB
);
108 if (glutCreateWindow("winpos") <= 0) {
114 glutReshapeFunc( reshape
);
115 glutKeyboardFunc( key
);
116 glutDisplayFunc( draw
);