Brian Paul | fdd631a | 2002-04-22 16:03:37 +0000 | [diff] [blame^] | 1 | /* $Id: winpos.c,v 1.5 2002/04/22 16:03:37 brianp Exp $ */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 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 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | #include <math.h> |
| 9 | #include <string.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <stdio.h> |
Karl Schultz | 164ce12 | 2002-01-16 00:48:43 +0000 | [diff] [blame] | 12 | #ifdef _WIN32 |
| 13 | #include <windows.h> |
| 14 | #endif |
Brian Paul | 02e8a03 | 2000-06-27 17:04:43 +0000 | [diff] [blame] | 15 | #define GL_GLEXT_LEGACY |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | #include "GL/glut.h" |
| 17 | |
pesco | d1ff1f6 | 2000-12-24 22:53:54 +0000 | [diff] [blame] | 18 | #include "readtex.c" /* a hack, I know */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | |
| 20 | #define IMAGE_FILE "../images/girl.rgb" |
| 21 | |
| 22 | |
| 23 | #ifndef M_PI |
| 24 | # define M_PI 3.14159265 |
| 25 | #endif |
| 26 | |
| 27 | |
| 28 | |
| 29 | static GLubyte *Image; |
| 30 | static int ImgWidth, ImgHeight; |
| 31 | static GLenum ImgFormat; |
| 32 | |
| 33 | |
| 34 | |
| 35 | static 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 | |
| 63 | static 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 */ |
| 76 | static void reshape( int width, int height ) |
| 77 | { |
| 78 | glViewport(0, 0, (GLint)width, (GLint)height); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | static 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 | |
| 94 | int 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 | } |