blob: f6415263d46f9f951163bf1709cd8ea88ea1cb5e [file] [log] [blame]
Brian Paul66fa33e2002-12-03 03:13:17 +00001/* $Id: winpos.c,v 1.6 2002/12/03 03:13:17 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 Paul66fa33e2002-12-03 03:13:17 +000015#define GL_GLEXT_PROTOTYPES
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
Brian Paul66fa33e2002-12-03 03:13:17 +000033static void (*WindowPosFunc)(GLfloat x, GLfloat y);
jtgafb833d1999-08-19 00:55:39 +000034
35
36static void draw( void )
37{
38 GLfloat angle;
jtgafb833d1999-08-19 00:55:39 +000039
40 glClear( GL_COLOR_BUFFER_BIT );
41
42 for (angle = -45.0; angle <= 135.0; angle += 10.0) {
43 GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
44 GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
45
46 /* Don't need to worry about the modelview or projection matrices!!! */
Brian Paul66fa33e2002-12-03 03:13:17 +000047 (*WindowPosFunc)( x, y );
48
jtgafb833d1999-08-19 00:55:39 +000049 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
50 }
Brian Paul66fa33e2002-12-03 03:13:17 +000051 glFinish();
jtgafb833d1999-08-19 00:55:39 +000052}
53
54
jtgafb833d1999-08-19 00:55:39 +000055static void key( unsigned char key, int x, int y )
56{
57 (void) x;
58 (void) y;
59 switch (key) {
60 case 27:
61 exit(0);
62 }
63}
64
65
jtgafb833d1999-08-19 00:55:39 +000066/* new window size or exposure */
67static void reshape( int width, int height )
68{
69 glViewport(0, 0, (GLint)width, (GLint)height);
70}
71
72
73static void init( void )
74{
Brian Paul66fa33e2002-12-03 03:13:17 +000075#ifdef GL_ARB_window_pos
76 if (glutExtensionSupported("GL_ARB_window_pos")) {
77 printf("Using GL_ARB_window_pos\n");
78 WindowPosFunc = &glWindowPos2fARB;
79 }
80 else
81#elif defined(GL_ARB_window_pos)
82 if (glutExtensionSupported("GL_MESA_window_pos")) {
83 printf("Using GL_MESA_window_pos\n");
84 WindowPosFunc = &glWindowPos2fMESA;
85 }
86 else
87#endif
88 {
89 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
90 exit(1);
91 }
92
jtgafb833d1999-08-19 00:55:39 +000093 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
94 if (!Image) {
95 printf("Couldn't read %s\n", IMAGE_FILE);
96 exit(0);
97 }
98 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
99}
100
101
jtgafb833d1999-08-19 00:55:39 +0000102int main( int argc, char *argv[] )
103{
104 glutInitWindowPosition(0, 0);
105 glutInitWindowSize(500, 500);
106 glutInitDisplayMode( GLUT_RGB );
107
108 if (glutCreateWindow("winpos") <= 0) {
109 exit(0);
110 }
111
112 init();
113
114 glutReshapeFunc( reshape );
115 glutKeyboardFunc( key );
116 glutDisplayFunc( draw );
117 glutMainLoop();
118 return 0;
119}