blob: f935f9bee0f1ae829fb67b9743bc755f0cd3d1fa [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
2/*
3 * Example of how to use the GL_MESA_window_pos extension.
4 * Brian Paul This file is in the public domain.
5 */
6
jtgafb833d1999-08-19 00:55:39 +00007#include <math.h>
8#include <string.h>
9#include <stdlib.h>
10#include <stdio.h>
Karl Schultz164ce122002-01-16 00:48:43 +000011#ifdef _WIN32
12#include <windows.h>
13#endif
José Fonseca9aa73cf2009-02-01 12:00:07 +000014#include "GL/glew.h"
jtgafb833d1999-08-19 00:55:39 +000015#include "GL/glut.h"
16
Brian Paul575d24a2005-01-09 17:15:41 +000017#include "readtex.h"
jtgafb833d1999-08-19 00:55:39 +000018
19#define IMAGE_FILE "../images/girl.rgb"
20
21
22#ifndef M_PI
23# define M_PI 3.14159265
24#endif
25
26
27
28static GLubyte *Image;
29static int ImgWidth, ImgHeight;
30static GLenum ImgFormat;
31
José Fonseca9aa73cf2009-02-01 12:00:07 +000032static PFNGLWINDOWPOS2FPROC WindowPosFunc;
jtgafb833d1999-08-19 00:55:39 +000033
34static void draw( void )
35{
36 GLfloat angle;
jtgafb833d1999-08-19 00:55:39 +000037
38 glClear( GL_COLOR_BUFFER_BIT );
39
40 for (angle = -45.0; angle <= 135.0; angle += 10.0) {
41 GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
42 GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
43
44 /* Don't need to worry about the modelview or projection matrices!!! */
Brian Paul66fa33e2002-12-03 03:13:17 +000045 (*WindowPosFunc)( x, y );
46
jtgafb833d1999-08-19 00:55:39 +000047 glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
48 }
Brian Paul66fa33e2002-12-03 03:13:17 +000049 glFinish();
jtgafb833d1999-08-19 00:55:39 +000050}
51
52
jtgafb833d1999-08-19 00:55:39 +000053static void key( unsigned char key, int x, int y )
54{
55 (void) x;
56 (void) y;
57 switch (key) {
58 case 27:
59 exit(0);
60 }
61}
62
63
jtgafb833d1999-08-19 00:55:39 +000064/* new window size or exposure */
65static void reshape( int width, int height )
66{
67 glViewport(0, 0, (GLint)width, (GLint)height);
68}
69
70
71static void init( void )
72{
José Fonseca9aa73cf2009-02-01 12:00:07 +000073 if (GLEW_ARB_window_pos) {
Brian Paul66fa33e2002-12-03 03:13:17 +000074 printf("Using GL_ARB_window_pos\n");
José Fonseca9aa73cf2009-02-01 12:00:07 +000075 WindowPosFunc = glWindowPos2fARB;
Brian Paul66fa33e2002-12-03 03:13:17 +000076 }
77 else
José Fonseca9aa73cf2009-02-01 12:00:07 +000078 if (GLEW_MESA_window_pos) {
Brian Paul66fa33e2002-12-03 03:13:17 +000079 printf("Using GL_MESA_window_pos\n");
José Fonseca9aa73cf2009-02-01 12:00:07 +000080 WindowPosFunc = glWindowPos2fMESA;
Brian Paul66fa33e2002-12-03 03:13:17 +000081 }
82 else
Brian Paul66fa33e2002-12-03 03:13:17 +000083 {
84 printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
85 exit(1);
86 }
87
jtgafb833d1999-08-19 00:55:39 +000088 Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
89 if (!Image) {
90 printf("Couldn't read %s\n", IMAGE_FILE);
91 exit(0);
92 }
93 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
94}
95
96
jtgafb833d1999-08-19 00:55:39 +000097int main( int argc, char *argv[] )
98{
jtgafb833d1999-08-19 00:55:39 +000099 glutInitWindowSize(500, 500);
Brian Paul263f4322009-12-18 08:12:55 -0700100 glutInit(&argc, argv);
jtgafb833d1999-08-19 00:55:39 +0000101 glutInitDisplayMode( GLUT_RGB );
102
103 if (glutCreateWindow("winpos") <= 0) {
104 exit(0);
105 }
106
José Fonseca9aa73cf2009-02-01 12:00:07 +0000107 glewInit();
108
jtgafb833d1999-08-19 00:55:39 +0000109 init();
110
111 glutReshapeFunc( reshape );
112 glutKeyboardFunc( key );
113 glutDisplayFunc( draw );
114 glutMainLoop();
115 return 0;
116}