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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include "GL/glew.h"
  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. static PFNGLWINDOWPOS2FPROC WindowPosFunc;
  23. static void draw( void )
  24. {
  25. GLfloat angle;
  26. glClear( GL_COLOR_BUFFER_BIT );
  27. for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  28. GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  29. GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  30. /* Don't need to worry about the modelview or projection matrices!!! */
  31. (*WindowPosFunc)( x, y );
  32. glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  33. }
  34. glFinish();
  35. }
  36. static void key( unsigned char key, int x, int y )
  37. {
  38. (void) x;
  39. (void) y;
  40. switch (key) {
  41. case 27:
  42. exit(0);
  43. }
  44. }
  45. /* new window size or exposure */
  46. static void reshape( int width, int height )
  47. {
  48. glViewport(0, 0, (GLint)width, (GLint)height);
  49. }
  50. static void init( void )
  51. {
  52. if (GLEW_ARB_window_pos) {
  53. printf("Using GL_ARB_window_pos\n");
  54. WindowPosFunc = glWindowPos2fARB;
  55. }
  56. else
  57. if (GLEW_MESA_window_pos) {
  58. printf("Using GL_MESA_window_pos\n");
  59. WindowPosFunc = glWindowPos2fMESA;
  60. }
  61. else
  62. {
  63. printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
  64. exit(1);
  65. }
  66. Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
  67. if (!Image) {
  68. printf("Couldn't read %s\n", IMAGE_FILE);
  69. exit(0);
  70. }
  71. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  72. }
  73. int main( int argc, char *argv[] )
  74. {
  75. glutInitWindowSize(500, 500);
  76. glutInit(&argc, argv);
  77. glutInitDisplayMode( GLUT_RGB );
  78. if (glutCreateWindow("winpos") <= 0) {
  79. exit(0);
  80. }
  81. glewInit();
  82. init();
  83. glutReshapeFunc( reshape );
  84. glutKeyboardFunc( key );
  85. glutDisplayFunc( draw );
  86. glutMainLoop();
  87. return 0;
  88. }