Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

winpos.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* $Id: winpos.c,v 1.2 2000/06/27 17:04:43 brianp Exp $ */
  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. /*
  7. * $Log: winpos.c,v $
  8. * Revision 1.2 2000/06/27 17:04:43 brianp
  9. * fixed compiler warnings
  10. *
  11. * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
  12. * Imported sources
  13. *
  14. * Revision 3.3 1999/03/28 18:24:37 brianp
  15. * minor clean-up
  16. *
  17. * Revision 3.2 1998/11/05 04:34:04 brianp
  18. * moved image files to ../images/ directory
  19. *
  20. * Revision 3.1 1998/02/22 16:36:10 brianp
  21. * changed image file and set unpack alignment to 1
  22. *
  23. * Revision 3.0 1998/02/14 18:42:29 brianp
  24. * initial rev
  25. *
  26. */
  27. #include <math.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #define GL_GLEXT_LEGACY
  32. #include "GL/glut.h"
  33. #include "../util/readtex.c" /* a hack, I know */
  34. #define IMAGE_FILE "../images/girl.rgb"
  35. #ifndef M_PI
  36. # define M_PI 3.14159265
  37. #endif
  38. static GLubyte *Image;
  39. static int ImgWidth, ImgHeight;
  40. static GLenum ImgFormat;
  41. static void draw( void )
  42. {
  43. GLfloat angle;
  44. char *extensions;
  45. extensions = (char *) glGetString( GL_EXTENSIONS );
  46. if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  47. printf("Sorry, GL_MESA_window_pos extension not available.\n");
  48. return;
  49. }
  50. glClear( GL_COLOR_BUFFER_BIT );
  51. for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  52. GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  53. GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  54. /* Don't need to worry about the modelview or projection matrices!!! */
  55. #ifdef GL_MESA_window_pos
  56. glWindowPos2fMESA( x, y );
  57. #endif
  58. glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  59. }
  60. }
  61. static void key( unsigned char key, int x, int y )
  62. {
  63. (void) x;
  64. (void) y;
  65. switch (key) {
  66. case 27:
  67. exit(0);
  68. }
  69. }
  70. /* new window size or exposure */
  71. static void reshape( int width, int height )
  72. {
  73. glViewport(0, 0, (GLint)width, (GLint)height);
  74. }
  75. static void init( void )
  76. {
  77. Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
  78. if (!Image) {
  79. printf("Couldn't read %s\n", IMAGE_FILE);
  80. exit(0);
  81. }
  82. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  83. }
  84. int main( int argc, char *argv[] )
  85. {
  86. glutInitWindowPosition(0, 0);
  87. glutInitWindowSize(500, 500);
  88. glutInitDisplayMode( GLUT_RGB );
  89. if (glutCreateWindow("winpos") <= 0) {
  90. exit(0);
  91. }
  92. init();
  93. glutReshapeFunc( reshape );
  94. glutKeyboardFunc( key );
  95. glutDisplayFunc( draw );
  96. glutMainLoop();
  97. return 0;
  98. }