Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* $Id: winpos.c,v 1.3 2000/12/24 22:53:54 pesco 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.3 2000/12/24 22:53:54 pesco
  9. * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util.
  10. * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus:
  11. * Essentially the same.
  12. * Program files updated to include "readtex.c", not "../util/readtex.c".
  13. * * demos/reflect.c: Likewise for "showbuffer.c".
  14. *
  15. *
  16. * * Makefile.am (EXTRA_DIST): Added top-level regular files.
  17. *
  18. * * include/GL/Makefile.am (INC_X11): Added glxext.h.
  19. *
  20. *
  21. * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include
  22. * Mesa GGI headers in dist even if HAVE_GGI is not given.
  23. *
  24. * * configure.in: Look for GLUT and demo source dirs in $srcdir.
  25. *
  26. * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch].
  27. * More source list updates in various Makefile.am's.
  28. *
  29. * * Makefile.am (dist-hook): Remove CVS directory from distribution.
  30. * (DIST_SUBDIRS): List all possible subdirs here.
  31. * (SUBDIRS): Only list subdirs selected for build again.
  32. * The above two applied to all subdir Makefile.am's also.
  33. *
  34. * Revision 1.2 2000/06/27 17:04:43 brianp
  35. * fixed compiler warnings
  36. *
  37. * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
  38. * Imported sources
  39. *
  40. * Revision 3.3 1999/03/28 18:24:37 brianp
  41. * minor clean-up
  42. *
  43. * Revision 3.2 1998/11/05 04:34:04 brianp
  44. * moved image files to ../images/ directory
  45. *
  46. * Revision 3.1 1998/02/22 16:36:10 brianp
  47. * changed image file and set unpack alignment to 1
  48. *
  49. * Revision 3.0 1998/02/14 18:42:29 brianp
  50. * initial rev
  51. *
  52. */
  53. #include <math.h>
  54. #include <string.h>
  55. #include <stdlib.h>
  56. #include <stdio.h>
  57. #define GL_GLEXT_LEGACY
  58. #include "GL/glut.h"
  59. #include "readtex.c" /* a hack, I know */
  60. #define IMAGE_FILE "../images/girl.rgb"
  61. #ifndef M_PI
  62. # define M_PI 3.14159265
  63. #endif
  64. static GLubyte *Image;
  65. static int ImgWidth, ImgHeight;
  66. static GLenum ImgFormat;
  67. static void draw( void )
  68. {
  69. GLfloat angle;
  70. char *extensions;
  71. extensions = (char *) glGetString( GL_EXTENSIONS );
  72. if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  73. printf("Sorry, GL_MESA_window_pos extension not available.\n");
  74. return;
  75. }
  76. glClear( GL_COLOR_BUFFER_BIT );
  77. for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  78. GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  79. GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  80. /* Don't need to worry about the modelview or projection matrices!!! */
  81. #ifdef GL_MESA_window_pos
  82. glWindowPos2fMESA( x, y );
  83. #endif
  84. glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  85. }
  86. }
  87. static void key( unsigned char key, int x, int y )
  88. {
  89. (void) x;
  90. (void) y;
  91. switch (key) {
  92. case 27:
  93. exit(0);
  94. }
  95. }
  96. /* new window size or exposure */
  97. static void reshape( int width, int height )
  98. {
  99. glViewport(0, 0, (GLint)width, (GLint)height);
  100. }
  101. static void init( void )
  102. {
  103. Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
  104. if (!Image) {
  105. printf("Couldn't read %s\n", IMAGE_FILE);
  106. exit(0);
  107. }
  108. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  109. }
  110. int main( int argc, char *argv[] )
  111. {
  112. glutInitWindowPosition(0, 0);
  113. glutInitWindowSize(500, 500);
  114. glutInitDisplayMode( GLUT_RGB );
  115. if (glutCreateWindow("winpos") <= 0) {
  116. exit(0);
  117. }
  118. init();
  119. glutReshapeFunc( reshape );
  120. glutKeyboardFunc( key );
  121. glutDisplayFunc( draw );
  122. glutMainLoop();
  123. return 0;
  124. }