Use glad instead of GLEW.
[mesa-demos.git] / src / demos / winpos.c
blob8aa88a83861fdca2743bb5573c14e2ce4a71a500
2 /*
3 * Example of how to use the GL_MESA_window_pos extension.
4 * Brian Paul This file is in the public domain.
5 */
7 #include <math.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #ifdef _WIN32
12 #include <windows.h>
13 #endif
14 #include "glad/glad.h"
15 #include "glut_wrap.h"
17 #include "readtex.h"
19 #define IMAGE_FILE DEMOS_DATA_DIR "girl.rgb"
22 #ifndef M_PI
23 # define M_PI 3.14159265
24 #endif
28 static GLubyte *Image;
29 static int ImgWidth, ImgHeight;
30 static GLenum ImgFormat;
32 static PFNGLWINDOWPOS2FPROC WindowPosFunc;
34 static void draw( void )
36 GLfloat angle;
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 );
49 glFinish();
53 static void key( unsigned char key, int x, int y )
55 (void) x;
56 (void) y;
57 switch (key) {
58 case 27:
59 exit(0);
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;
77 else
78 if (GLAD_GL_MESA_window_pos) {
79 printf("Using GL_MESA_window_pos\n");
80 WindowPosFunc = glWindowPos2fMESA;
82 else
84 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
85 exit(1);
88 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
89 if (!Image) {
90 printf("Couldn't read %s\n", IMAGE_FILE);
91 exit(0);
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) {
104 exit(0);
107 gladLoadGL();
109 init();
111 glutReshapeFunc( reshape );
112 glutKeyboardFunc( key );
113 glutDisplayFunc( draw );
114 glutMainLoop();
115 return 0;