jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | |
| 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 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 7 | #include <math.h> |
| 8 | #include <string.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <stdio.h> |
Karl Schultz | 164ce12 | 2002-01-16 00:48:43 +0000 | [diff] [blame] | 11 | #ifdef _WIN32 |
| 12 | #include <windows.h> |
| 13 | #endif |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 14 | #define GL_GLEXT_PROTOTYPES |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 15 | #include "GL/glut.h" |
| 16 | |
Brian Paul | 575d24a | 2005-01-09 17:15:41 +0000 | [diff] [blame] | 17 | #include "readtex.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 18 | |
| 19 | #define IMAGE_FILE "../images/girl.rgb" |
| 20 | |
| 21 | |
| 22 | #ifndef M_PI |
| 23 | # define M_PI 3.14159265 |
| 24 | #endif |
| 25 | |
| 26 | |
| 27 | |
| 28 | static GLubyte *Image; |
| 29 | static int ImgWidth, ImgHeight; |
| 30 | static GLenum ImgFormat; |
| 31 | |
Karl Schultz | e921844 | 2003-02-27 19:43:02 +0000 | [diff] [blame] | 32 | typedef void (APIENTRY * PFNWINDOWPOSFUNC)(GLfloat x, GLfloat y); |
| 33 | static PFNWINDOWPOSFUNC WindowPosFunc; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 34 | |
| 35 | static void draw( void ) |
| 36 | { |
| 37 | GLfloat angle; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 38 | |
| 39 | glClear( GL_COLOR_BUFFER_BIT ); |
| 40 | |
| 41 | for (angle = -45.0; angle <= 135.0; angle += 10.0) { |
| 42 | GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 ); |
| 43 | GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 ); |
| 44 | |
| 45 | /* Don't need to worry about the modelview or projection matrices!!! */ |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 46 | (*WindowPosFunc)( x, y ); |
| 47 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 48 | glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image ); |
| 49 | } |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 50 | glFinish(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 54 | static void key( unsigned char key, int x, int y ) |
| 55 | { |
| 56 | (void) x; |
| 57 | (void) y; |
| 58 | switch (key) { |
| 59 | case 27: |
| 60 | exit(0); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 65 | /* new window size or exposure */ |
| 66 | static void reshape( int width, int height ) |
| 67 | { |
| 68 | glViewport(0, 0, (GLint)width, (GLint)height); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | static void init( void ) |
| 73 | { |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 74 | #ifdef GL_ARB_window_pos |
| 75 | if (glutExtensionSupported("GL_ARB_window_pos")) { |
| 76 | printf("Using GL_ARB_window_pos\n"); |
| 77 | WindowPosFunc = &glWindowPos2fARB; |
| 78 | } |
| 79 | else |
Brian | 9f37be6 | 2007-02-28 11:58:06 -0700 | [diff] [blame] | 80 | #elif defined(GL_MESA_window_pos) |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 81 | if (glutExtensionSupported("GL_MESA_window_pos")) { |
| 82 | printf("Using GL_MESA_window_pos\n"); |
| 83 | WindowPosFunc = &glWindowPos2fMESA; |
| 84 | } |
| 85 | else |
| 86 | #endif |
| 87 | { |
| 88 | printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); |
| 89 | exit(1); |
| 90 | } |
| 91 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 92 | Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); |
| 93 | if (!Image) { |
| 94 | printf("Couldn't read %s\n", IMAGE_FILE); |
| 95 | exit(0); |
| 96 | } |
| 97 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 98 | } |
| 99 | |
| 100 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 101 | int main( int argc, char *argv[] ) |
| 102 | { |
| 103 | glutInitWindowPosition(0, 0); |
| 104 | glutInitWindowSize(500, 500); |
| 105 | glutInitDisplayMode( GLUT_RGB ); |
| 106 | |
| 107 | if (glutCreateWindow("winpos") <= 0) { |
| 108 | exit(0); |
| 109 | } |
| 110 | |
| 111 | init(); |
| 112 | |
| 113 | glutReshapeFunc( reshape ); |
| 114 | glutKeyboardFunc( key ); |
| 115 | glutDisplayFunc( draw ); |
| 116 | glutMainLoop(); |
| 117 | return 0; |
| 118 | } |