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