blob: 2dfa9af600764cb56c6bdc4d0807a0f8f17f2061 [file] [log] [blame]
Brian Paulfdd631a2002-04-22 16:03:37 +00001/* $Id: winpos.c,v 1.5 2002/04/22 16:03:37 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
jtgafb833d1999-08-19 00:55:39 +00008#include <math.h>
9#include <string.h>
10#include <stdlib.h>
11#include <stdio.h>
Karl Schultz164ce122002-01-16 00:48:43 +000012#ifdef _WIN32
13#include <windows.h>
14#endif
Brian Paul02e8a032000-06-27 17:04:43 +000015#define GL_GLEXT_LEGACY
jtgafb833d1999-08-19 00:55:39 +000016#include "GL/glut.h"
17
pescod1ff1f62000-12-24 22:53:54 +000018#include "readtex.c" /* a hack, I know */
jtgafb833d1999-08-19 00:55:39 +000019
20#define IMAGE_FILE "../images/girl.rgb"
21
22
23#ifndef M_PI
24# define M_PI 3.14159265
25#endif
26
27
28
29static GLubyte *Image;
30static int ImgWidth, ImgHeight;
31static GLenum ImgFormat;
32
33
34
35static void draw( void )
36{
37 GLfloat angle;
38 char *extensions;
39
40 extensions = (char *) glGetString( GL_EXTENSIONS );
41 if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
42 printf("Sorry, GL_MESA_window_pos extension not available.\n");
43 return;
44 }
45
46 glClear( GL_COLOR_BUFFER_BIT );
47
48 for (angle = -45.0; angle <= 135.0; angle += 10.0) {
49 GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
50 GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
51
52 /* Don't need to worry about the modelview or projection matrices!!! */
53#ifdef GL_MESA_window_pos
54 glWindowPos2fMESA( x, y );
55#endif
56 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
57 }
58}
59
60
61
62
63static void key( unsigned char key, int x, int y )
64{
65 (void) x;
66 (void) y;
67 switch (key) {
68 case 27:
69 exit(0);
70 }
71}
72
73
74
75/* new window size or exposure */
76static void reshape( int width, int height )
77{
78 glViewport(0, 0, (GLint)width, (GLint)height);
79}
80
81
82static void init( void )
83{
84 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
85 if (!Image) {
86 printf("Couldn't read %s\n", IMAGE_FILE);
87 exit(0);
88 }
89 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90}
91
92
93
94int main( int argc, char *argv[] )
95{
96 glutInitWindowPosition(0, 0);
97 glutInitWindowSize(500, 500);
98 glutInitDisplayMode( GLUT_RGB );
99
100 if (glutCreateWindow("winpos") <= 0) {
101 exit(0);
102 }
103
104 init();
105
106 glutReshapeFunc( reshape );
107 glutKeyboardFunc( key );
108 glutDisplayFunc( draw );
109 glutMainLoop();
110 return 0;
111}