blob: 62504198dd637d4780d02f28a18cf233e9dba3b4 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
2/*
3 * Example of how to use the GL_MESA_window_pos extension.
4 * Brian Paul This file is in the public domain.
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007#include <math.h>
8#include <string.h>
9#include <stdlib.h>
10#include <stdio.h>
Karl Schultz164ce122002-01-16 00:48:43 +000011#ifdef _WIN32
12#include <windows.h>
13#endif
Brian Paul66fa33e2002-12-03 03:13:17 +000014#define GL_GLEXT_PROTOTYPES
jtgafb833d1999-08-19 00:55:39 +000015#include "GL/glut.h"
16
pescod1ff1f62000-12-24 22:53:54 +000017#include "readtex.c" /* a hack, I know */
jtgafb833d1999-08-19 00:55:39 +000018
19#define IMAGE_FILE "../images/girl.rgb"
20
21
22#ifndef M_PI
23# define M_PI 3.14159265
24#endif
25
26
27
28static GLubyte *Image;
29static int ImgWidth, ImgHeight;
30static GLenum ImgFormat;
31
Karl Schultze9218442003-02-27 19:43:02 +000032typedef void (APIENTRY * PFNWINDOWPOSFUNC)(GLfloat x, GLfloat y);
33static PFNWINDOWPOSFUNC WindowPosFunc;
jtgafb833d1999-08-19 00:55:39 +000034
35static void draw( void )
36{
37 GLfloat angle;
jtgafb833d1999-08-19 00:55:39 +000038
39 glClear( GL_COLOR_BUFFER_BIT );
40
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 );
44
45 /* Don't need to worry about the modelview or projection matrices!!! */
Brian Paul66fa33e2002-12-03 03:13:17 +000046 (*WindowPosFunc)( x, y );
47
jtgafb833d1999-08-19 00:55:39 +000048 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
49 }
Brian Paul66fa33e2002-12-03 03:13:17 +000050 glFinish();
jtgafb833d1999-08-19 00:55:39 +000051}
52
53
jtgafb833d1999-08-19 00:55:39 +000054static void key( unsigned char key, int x, int y )
55{
56 (void) x;
57 (void) y;
58 switch (key) {
59 case 27:
60 exit(0);
61 }
62}
63
64
jtgafb833d1999-08-19 00:55:39 +000065/* new window size or exposure */
66static void reshape( int width, int height )
67{
68 glViewport(0, 0, (GLint)width, (GLint)height);
69}
70
71
72static void init( void )
73{
Brian Paul66fa33e2002-12-03 03:13:17 +000074#ifdef GL_ARB_window_pos
75 if (glutExtensionSupported("GL_ARB_window_pos")) {
76 printf("Using GL_ARB_window_pos\n");
77 WindowPosFunc = &glWindowPos2fARB;
78 }
79 else
80#elif defined(GL_ARB_window_pos)
81 if (glutExtensionSupported("GL_MESA_window_pos")) {
82 printf("Using GL_MESA_window_pos\n");
83 WindowPosFunc = &glWindowPos2fMESA;
84 }
85 else
86#endif
87 {
88 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
89 exit(1);
90 }
91
jtgafb833d1999-08-19 00:55:39 +000092 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
93 if (!Image) {
94 printf("Couldn't read %s\n", IMAGE_FILE);
95 exit(0);
96 }
97 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
98}
99
100
jtgafb833d1999-08-19 00:55:39 +0000101int main( int argc, char *argv[] )
102{
103 glutInitWindowPosition(0, 0);
104 glutInitWindowSize(500, 500);
105 glutInitDisplayMode( GLUT_RGB );
106
107 if (glutCreateWindow("winpos") <= 0) {
108 exit(0);
109 }
110
111 init();
112
113 glutReshapeFunc( reshape );
114 glutKeyboardFunc( key );
115 glutDisplayFunc( draw );
116 glutMainLoop();
117 return 0;
118}