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 |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 14 | #include "GL/glew.h" |
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 | |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 32 | static PFNGLWINDOWPOS2FPROC WindowPosFunc; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | |
| 34 | static void draw( void ) |
| 35 | { |
| 36 | GLfloat angle; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 37 | |
| 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 Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 45 | (*WindowPosFunc)( x, y ); |
| 46 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 47 | glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image ); |
| 48 | } |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 49 | glFinish(); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 53 | static 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 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 64 | /* new window size or exposure */ |
| 65 | static void reshape( int width, int height ) |
| 66 | { |
| 67 | glViewport(0, 0, (GLint)width, (GLint)height); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static void init( void ) |
| 72 | { |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 73 | if (GLEW_ARB_window_pos) { |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 74 | printf("Using GL_ARB_window_pos\n"); |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 75 | WindowPosFunc = glWindowPos2fARB; |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 76 | } |
| 77 | else |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 78 | if (GLEW_MESA_window_pos) { |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 79 | printf("Using GL_MESA_window_pos\n"); |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 80 | WindowPosFunc = glWindowPos2fMESA; |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 81 | } |
| 82 | else |
Brian Paul | 66fa33e | 2002-12-03 03:13:17 +0000 | [diff] [blame] | 83 | { |
| 84 | printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); |
| 85 | exit(1); |
| 86 | } |
| 87 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 88 | 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 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 97 | int main( int argc, char *argv[] ) |
| 98 | { |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 99 | glutInitWindowSize(500, 500); |
Brian Paul | 263f432 | 2009-12-18 08:12:55 -0700 | [diff] [blame] | 100 | glutInit(&argc, argv); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 101 | glutInitDisplayMode( GLUT_RGB ); |
| 102 | |
| 103 | if (glutCreateWindow("winpos") <= 0) { |
| 104 | exit(0); |
| 105 | } |
| 106 | |
José Fonseca | 9aa73cf | 2009-02-01 12:00:07 +0000 | [diff] [blame] | 107 | glewInit(); |
| 108 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | init(); |
| 110 | |
| 111 | glutReshapeFunc( reshape ); |
| 112 | glutKeyboardFunc( key ); |
| 113 | glutDisplayFunc( draw ); |
| 114 | glutMainLoop(); |
| 115 | return 0; |
| 116 | } |