Make ESC quit.
[mesa.git] / progs / demos / winpos.c
1 /* $Id: winpos.c,v 1.3 2000/12/24 22:53:54 pesco Exp $ */
2
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 $
11 * Revision 1.3 2000/12/24 22:53:54 pesco
12 * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
13 * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
14 * Essentially the same.
15 * Program files updated to include "readtex.c", not "../util/readtex.c".
16 * * demos/reflect.c: Likewise for "showbuffer.c".
17 *
18 *
19 * * Makefile.am (EXTRA_DIST): Added top-level regular files.
20 *
21 * * include/GL/Makefile.am (INC_X11): Added glxext.h.
22 *
23 *
24 * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
25 * Mesa GGI headers in dist even if HAVE_GGI is not given.
26 *
27 * * configure.in: Look for GLUT and demo source dirs in $srcdir.
28 *
29 * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
30 * More source list updates in various Makefile.am's.
31 *
32 * * Makefile.am (dist-hook): Remove CVS directory from distribution.
33 * (DIST_SUBDIRS): List all possible subdirs here.
34 * (SUBDIRS): Only list subdirs selected for build again.
35 * The above two applied to all subdir Makefile.am's also.
36 *
37 * Revision 1.2 2000/06/27 17:04:43 brianp
38 * fixed compiler warnings
39 *
40 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
41 * Imported sources
42 *
43 * Revision 3.3 1999/03/28 18:24:37 brianp
44 * minor clean-up
45 *
46 * Revision 3.2 1998/11/05 04:34:04 brianp
47 * moved image files to ../images/ directory
48 *
49 * Revision 3.1 1998/02/22 16:36:10 brianp
50 * changed image file and set unpack alignment to 1
51 *
52 * Revision 3.0 1998/02/14 18:42:29 brianp
53 * initial rev
54 *
55 */
56
57
58 #include <math.h>
59 #include <string.h>
60 #include <stdlib.h>
61 #include <stdio.h>
62 #define GL_GLEXT_LEGACY
63 #include "GL/glut.h"
64
65 #include "readtex.c" /* a hack, I know */
66
67 #define IMAGE_FILE "../images/girl.rgb"
68
69
70 #ifndef M_PI
71 # define M_PI 3.14159265
72 #endif
73
74
75
76 static GLubyte *Image;
77 static int ImgWidth, ImgHeight;
78 static GLenum ImgFormat;
79
80
81
82 static void draw( void )
83 {
84 GLfloat angle;
85 char *extensions;
86
87 extensions = (char *) glGetString( GL_EXTENSIONS );
88 if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
89 printf("Sorry, GL_MESA_window_pos extension not available.\n");
90 return;
91 }
92
93 glClear( GL_COLOR_BUFFER_BIT );
94
95 for (angle = -45.0; angle <= 135.0; angle += 10.0) {
96 GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
97 GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
98
99 /* Don't need to worry about the modelview or projection matrices!!! */
100 #ifdef GL_MESA_window_pos
101 glWindowPos2fMESA( x, y );
102 #endif
103 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
104 }
105 }
106
107
108
109
110 static void key( unsigned char key, int x, int y )
111 {
112 (void) x;
113 (void) y;
114 switch (key) {
115 case 27:
116 exit(0);
117 }
118 }
119
120
121
122 /* new window size or exposure */
123 static void reshape( int width, int height )
124 {
125 glViewport(0, 0, (GLint)width, (GLint)height);
126 }
127
128
129 static void init( void )
130 {
131 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
132 if (!Image) {
133 printf("Couldn't read %s\n", IMAGE_FILE);
134 exit(0);
135 }
136 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
137 }
138
139
140
141 int main( int argc, char *argv[] )
142 {
143 glutInitWindowPosition(0, 0);
144 glutInitWindowSize(500, 500);
145 glutInitDisplayMode( GLUT_RGB );
146
147 if (glutCreateWindow("winpos") <= 0) {
148 exit(0);
149 }
150
151 init();
152
153 glutReshapeFunc( reshape );
154 glutKeyboardFunc( key );
155 glutDisplayFunc( draw );
156 glutMainLoop();
157 return 0;
158 }