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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Example of how to use the GL_MESA_window_pos extension.
  3. * Brian Paul This file is in the public domain.
  4. */
  5. #include <math.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #ifdef _WIN32
  10. #include <windows.h>
  11. #endif
  12. #define GL_GLEXT_PROTOTYPES
  13. #include "GL/glut.h"
  14. #include "readtex.h"
  15. #define IMAGE_FILE "../images/girl.rgb"
  16. #ifndef M_PI
  17. # define M_PI 3.14159265
  18. #endif
  19. static GLubyte *Image;
  20. static int ImgWidth, ImgHeight;
  21. static GLenum ImgFormat;
  22. typedef void (APIENTRY * PFNWINDOWPOSFUNC)(GLfloat x, GLfloat y);
  23. static PFNWINDOWPOSFUNC WindowPosFunc;
  24. static void draw( void )
  25. {
  26. GLfloat angle;
  27. glClear( GL_COLOR_BUFFER_BIT );
  28. for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  29. GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  30. GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  31. /* Don't need to worry about the modelview or projection matrices!!! */
  32. (*WindowPosFunc)( x, y );
  33. glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  34. }
  35. glFinish();
  36. }
  37. static void key( unsigned char key, int x, int y )
  38. {
  39. (void) x;
  40. (void) y;
  41. switch (key) {
  42. case 27:
  43. exit(0);
  44. }
  45. }
  46. /* new window size or exposure */
  47. static void reshape( int width, int height )
  48. {
  49. glViewport(0, 0, (GLint)width, (GLint)height);
  50. }
  51. static void init( void )
  52. {
  53. #ifdef GL_ARB_window_pos
  54. if (glutExtensionSupported("GL_ARB_window_pos")) {
  55. printf("Using GL_ARB_window_pos\n");
  56. WindowPosFunc = &glWindowPos2fARB;
  57. }
  58. else
  59. #elif defined(GL_MESA_window_pos)
  60. if (glutExtensionSupported("GL_MESA_window_pos")) {
  61. printf("Using GL_MESA_window_pos\n");
  62. WindowPosFunc = &glWindowPos2fMESA;
  63. }
  64. else
  65. #endif
  66. {
  67. printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
  68. exit(1);
  69. }
  70. Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
  71. if (!Image) {
  72. printf("Couldn't read %s\n", IMAGE_FILE);
  73. exit(0);
  74. }
  75. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  76. }
  77. int main( int argc, char *argv[] )
  78. {
  79. glutInit(&argc, argv);
  80. glutInitWindowPosition(0, 0);
  81. glutInitWindowSize(500, 500);
  82. glutInitDisplayMode( GLUT_RGB );
  83. if (glutCreateWindow("winpos") <= 0) {
  84. exit(0);
  85. }
  86. init();
  87. glutReshapeFunc( reshape );
  88. glutKeyboardFunc( key );
  89. glutDisplayFunc( draw );
  90. glutMainLoop();
  91. return 0;
  92. }