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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* $Id: winpos.c,v 1.5 2002/04/22 16:03:37 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. #include <math.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #ifdef _WIN32
  11. #include <windows.h>
  12. #endif
  13. #define GL_GLEXT_LEGACY
  14. #include "GL/glut.h"
  15. #include "readtex.c" /* a hack, I know */
  16. #define IMAGE_FILE "../images/girl.rgb"
  17. #ifndef M_PI
  18. # define M_PI 3.14159265
  19. #endif
  20. static GLubyte *Image;
  21. static int ImgWidth, ImgHeight;
  22. static GLenum ImgFormat;
  23. static void draw( void )
  24. {
  25. GLfloat angle;
  26. char *extensions;
  27. extensions = (char *) glGetString( GL_EXTENSIONS );
  28. if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  29. printf("Sorry, GL_MESA_window_pos extension not available.\n");
  30. return;
  31. }
  32. glClear( GL_COLOR_BUFFER_BIT );
  33. for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  34. GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  35. GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  36. /* Don't need to worry about the modelview or projection matrices!!! */
  37. #ifdef GL_MESA_window_pos
  38. glWindowPos2fMESA( x, y );
  39. #endif
  40. glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  41. }
  42. }
  43. static void key( unsigned char key, int x, int y )
  44. {
  45. (void) x;
  46. (void) y;
  47. switch (key) {
  48. case 27:
  49. exit(0);
  50. }
  51. }
  52. /* new window size or exposure */
  53. static void reshape( int width, int height )
  54. {
  55. glViewport(0, 0, (GLint)width, (GLint)height);
  56. }
  57. static void init( void )
  58. {
  59. Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
  60. if (!Image) {
  61. printf("Couldn't read %s\n", IMAGE_FILE);
  62. exit(0);
  63. }
  64. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  65. }
  66. int main( int argc, char *argv[] )
  67. {
  68. glutInitWindowPosition(0, 0);
  69. glutInitWindowSize(500, 500);
  70. glutInitDisplayMode( GLUT_RGB );
  71. if (glutCreateWindow("winpos") <= 0) {
  72. exit(0);
  73. }
  74. init();
  75. glutReshapeFunc( reshape );
  76. glutKeyboardFunc( key );
  77. glutDisplayFunc( draw );
  78. glutMainLoop();
  79. return 0;
  80. }