blob: 7001165deeffb9ab0ef84835e93505e5dcad22b6 [file] [log] [blame]
Brian Paul02e8a032000-06-27 17:04:43 +00001/* $Id: winpos.c,v 1.2 2000/06/27 17:04:43 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Example of how to use the GL_MESA_window_pos extension.
5 * Brian Paul This file is in the public domain.
6 */
7
8
9/*
10 * $Log: winpos.c,v $
Brian Paul02e8a032000-06-27 17:04:43 +000011 * Revision 1.2 2000/06/27 17:04:43 brianp
12 * fixed compiler warnings
13 *
14 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
15 * Imported sources
jtgafb833d1999-08-19 00:55:39 +000016 *
17 * Revision 3.3 1999/03/28 18:24:37 brianp
18 * minor clean-up
19 *
20 * Revision 3.2 1998/11/05 04:34:04 brianp
21 * moved image files to ../images/ directory
22 *
23 * Revision 3.1 1998/02/22 16:36:10 brianp
24 * changed image file and set unpack alignment to 1
25 *
26 * Revision 3.0 1998/02/14 18:42:29 brianp
27 * initial rev
28 *
29 */
30
31
32#include <math.h>
33#include <string.h>
34#include <stdlib.h>
35#include <stdio.h>
Brian Paul02e8a032000-06-27 17:04:43 +000036#define GL_GLEXT_LEGACY
jtgafb833d1999-08-19 00:55:39 +000037#include "GL/glut.h"
38
39#include "../util/readtex.c" /* a hack, I know */
40
41#define IMAGE_FILE "../images/girl.rgb"
42
43
44#ifndef M_PI
45# define M_PI 3.14159265
46#endif
47
48
49
50static GLubyte *Image;
51static int ImgWidth, ImgHeight;
52static GLenum ImgFormat;
53
54
55
56static void draw( void )
57{
58 GLfloat angle;
59 char *extensions;
60
61 extensions = (char *) glGetString( GL_EXTENSIONS );
62 if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
63 printf("Sorry, GL_MESA_window_pos extension not available.\n");
64 return;
65 }
66
67 glClear( GL_COLOR_BUFFER_BIT );
68
69 for (angle = -45.0; angle <= 135.0; angle += 10.0) {
70 GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
71 GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
72
73 /* Don't need to worry about the modelview or projection matrices!!! */
74#ifdef GL_MESA_window_pos
75 glWindowPos2fMESA( x, y );
76#endif
77 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
78 }
79}
80
81
82
83
84static void key( unsigned char key, int x, int y )
85{
86 (void) x;
87 (void) y;
88 switch (key) {
89 case 27:
90 exit(0);
91 }
92}
93
94
95
96/* new window size or exposure */
97static void reshape( int width, int height )
98{
99 glViewport(0, 0, (GLint)width, (GLint)height);
100}
101
102
103static void init( void )
104{
105 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
106 if (!Image) {
107 printf("Couldn't read %s\n", IMAGE_FILE);
108 exit(0);
109 }
110 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
111}
112
113
114
115int main( int argc, char *argv[] )
116{
117 glutInitWindowPosition(0, 0);
118 glutInitWindowSize(500, 500);
119 glutInitDisplayMode( GLUT_RGB );
120
121 if (glutCreateWindow("winpos") <= 0) {
122 exit(0);
123 }
124
125 init();
126
127 glutReshapeFunc( reshape );
128 glutKeyboardFunc( key );
129 glutDisplayFunc( draw );
130 glutMainLoop();
131 return 0;
132}