3 * Example of how to use the GL_MESA_window_pos extension.
4 * Brian Paul This file is in the public domain.
14 #include "glad/glad.h"
15 #include "glut_wrap.h"
19 #define IMAGE_FILE DEMOS_DATA_DIR "girl.rgb"
23 # define M_PI 3.14159265
28 static GLubyte
*Image
;
29 static int ImgWidth
, ImgHeight
;
30 static GLenum ImgFormat
;
32 static PFNGLWINDOWPOS2FPROC WindowPosFunc
;
34 static void draw( void )
38 glClear( GL_COLOR_BUFFER_BIT
);
40 for (angle
= -45.0; angle
<= 135.0; angle
+= 10.0) {
41 GLfloat x
= 50.0 + 200.0 * cos( angle
* M_PI
/ 180.0 );
42 GLfloat y
= 50.0 + 200.0 * sin( angle
* M_PI
/ 180.0 );
44 /* Don't need to worry about the modelview or projection matrices!!! */
45 (*WindowPosFunc
)( x
, y
);
47 glDrawPixels( ImgWidth
, ImgHeight
, ImgFormat
, GL_UNSIGNED_BYTE
, Image
);
53 static void key( unsigned char key
, int x
, int y
)
64 /* new window size or exposure */
65 static void reshape( int width
, int height
)
67 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
71 static void init( void )
73 if (GLAD_GL_ARB_window_pos
) {
74 printf("Using GL_ARB_window_pos\n");
75 WindowPosFunc
= glWindowPos2fARB
;
78 if (GLAD_GL_MESA_window_pos
) {
79 printf("Using GL_MESA_window_pos\n");
80 WindowPosFunc
= glWindowPos2fMESA
;
84 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
88 Image
= LoadRGBImage( IMAGE_FILE
, &ImgWidth
, &ImgHeight
, &ImgFormat
);
90 printf("Couldn't read %s\n", IMAGE_FILE
);
93 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
97 int main( int argc
, char *argv
[] )
99 glutInitWindowSize(500, 500);
100 glutInit(&argc
, argv
);
101 glutInitDisplayMode( GLUT_RGB
);
103 if (glutCreateWindow("winpos") <= 0) {
111 glutReshapeFunc( reshape
);
112 glutKeyboardFunc( key
);
113 glutDisplayFunc( draw
);