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

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