Karl Schultz | 164ce12 | 2002-01-16 00:48:43 +0000 | [diff] [blame] | 1 | /* $Id: winpos.c,v 1.4 2002/01/16 00:48:43 kschultz 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 | |
| 8 | |
| 9 | /* |
| 10 | * $Log: winpos.c,v $ |
Karl Schultz | 164ce12 | 2002-01-16 00:48:43 +0000 | [diff] [blame] | 11 | * Revision 1.4 2002/01/16 00:48:43 kschultz |
| 12 | * Demo updates for Windows (Robert Bergkvist) |
| 13 | * |
pesco | d1ff1f6 | 2000-12-24 22:53:54 +0000 | [diff] [blame] | 14 | * Revision 1.3 2000/12/24 22:53:54 pesco |
| 15 | * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util. |
| 16 | * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus: |
| 17 | * Essentially the same. |
| 18 | * Program files updated to include "readtex.c", not "../util/readtex.c". |
| 19 | * * demos/reflect.c: Likewise for "showbuffer.c". |
| 20 | * |
| 21 | * |
| 22 | * * Makefile.am (EXTRA_DIST): Added top-level regular files. |
| 23 | * |
| 24 | * * include/GL/Makefile.am (INC_X11): Added glxext.h. |
| 25 | * |
| 26 | * |
| 27 | * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include |
| 28 | * Mesa GGI headers in dist even if HAVE_GGI is not given. |
| 29 | * |
| 30 | * * configure.in: Look for GLUT and demo source dirs in $srcdir. |
| 31 | * |
| 32 | * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch]. |
| 33 | * More source list updates in various Makefile.am's. |
| 34 | * |
| 35 | * * Makefile.am (dist-hook): Remove CVS directory from distribution. |
| 36 | * (DIST_SUBDIRS): List all possible subdirs here. |
| 37 | * (SUBDIRS): Only list subdirs selected for build again. |
| 38 | * The above two applied to all subdir Makefile.am's also. |
| 39 | * |
Brian Paul | 02e8a03 | 2000-06-27 17:04:43 +0000 | [diff] [blame] | 40 | * Revision 1.2 2000/06/27 17:04:43 brianp |
| 41 | * fixed compiler warnings |
| 42 | * |
| 43 | * Revision 1.1.1.1 1999/08/19 00:55:40 jtg |
| 44 | * Imported sources |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 45 | * |
| 46 | * Revision 3.3 1999/03/28 18:24:37 brianp |
| 47 | * minor clean-up |
| 48 | * |
| 49 | * Revision 3.2 1998/11/05 04:34:04 brianp |
| 50 | * moved image files to ../images/ directory |
| 51 | * |
| 52 | * Revision 3.1 1998/02/22 16:36:10 brianp |
| 53 | * changed image file and set unpack alignment to 1 |
| 54 | * |
| 55 | * Revision 3.0 1998/02/14 18:42:29 brianp |
| 56 | * initial rev |
| 57 | * |
| 58 | */ |
| 59 | |
| 60 | |
| 61 | #include <math.h> |
| 62 | #include <string.h> |
| 63 | #include <stdlib.h> |
| 64 | #include <stdio.h> |
Karl Schultz | 164ce12 | 2002-01-16 00:48:43 +0000 | [diff] [blame] | 65 | #ifdef _WIN32 |
| 66 | #include <windows.h> |
| 67 | #endif |
Brian Paul | 02e8a03 | 2000-06-27 17:04:43 +0000 | [diff] [blame] | 68 | #define GL_GLEXT_LEGACY |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 69 | #include "GL/glut.h" |
| 70 | |
pesco | d1ff1f6 | 2000-12-24 22:53:54 +0000 | [diff] [blame] | 71 | #include "readtex.c" /* a hack, I know */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 72 | |
| 73 | #define IMAGE_FILE "../images/girl.rgb" |
| 74 | |
| 75 | |
| 76 | #ifndef M_PI |
| 77 | # define M_PI 3.14159265 |
| 78 | #endif |
| 79 | |
| 80 | |
| 81 | |
| 82 | static GLubyte *Image; |
| 83 | static int ImgWidth, ImgHeight; |
| 84 | static GLenum ImgFormat; |
| 85 | |
| 86 | |
| 87 | |
| 88 | static void draw( void ) |
| 89 | { |
| 90 | GLfloat angle; |
| 91 | char *extensions; |
| 92 | |
| 93 | extensions = (char *) glGetString( GL_EXTENSIONS ); |
| 94 | if (strstr( extensions, "GL_MESA_window_pos")==NULL) { |
| 95 | printf("Sorry, GL_MESA_window_pos extension not available.\n"); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | glClear( GL_COLOR_BUFFER_BIT ); |
| 100 | |
| 101 | for (angle = -45.0; angle <= 135.0; angle += 10.0) { |
| 102 | GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 ); |
| 103 | GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 ); |
| 104 | |
| 105 | /* Don't need to worry about the modelview or projection matrices!!! */ |
| 106 | #ifdef GL_MESA_window_pos |
| 107 | glWindowPos2fMESA( x, y ); |
| 108 | #endif |
| 109 | glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | static void key( unsigned char key, int x, int y ) |
| 117 | { |
| 118 | (void) x; |
| 119 | (void) y; |
| 120 | switch (key) { |
| 121 | case 27: |
| 122 | exit(0); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | /* new window size or exposure */ |
| 129 | static void reshape( int width, int height ) |
| 130 | { |
| 131 | glViewport(0, 0, (GLint)width, (GLint)height); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | static void init( void ) |
| 136 | { |
| 137 | Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); |
| 138 | if (!Image) { |
| 139 | printf("Couldn't read %s\n", IMAGE_FILE); |
| 140 | exit(0); |
| 141 | } |
| 142 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | |
| 147 | int main( int argc, char *argv[] ) |
| 148 | { |
| 149 | glutInitWindowPosition(0, 0); |
| 150 | glutInitWindowSize(500, 500); |
| 151 | glutInitDisplayMode( GLUT_RGB ); |
| 152 | |
| 153 | if (glutCreateWindow("winpos") <= 0) { |
| 154 | exit(0); |
| 155 | } |
| 156 | |
| 157 | init(); |
| 158 | |
| 159 | glutReshapeFunc( reshape ); |
| 160 | glutKeyboardFunc( key ); |
| 161 | glutDisplayFunc( draw ); |
| 162 | glutMainLoop(); |
| 163 | return 0; |
| 164 | } |