home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / demos / winpos.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  2KB  |  103 lines

  1. /* winpos.c */
  2.  
  3. /*
  4.  * Example of how to use the GL_MESA_window_pos extension.
  5.  *
  6.  * Brian Paul
  7.  */
  8.  
  9.  
  10. #include <math.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include "gltk.h"
  15.  
  16.  
  17. #ifndef M_PI
  18. #  define M_PI 3.14159265
  19. #endif
  20.  
  21.  
  22. static TK_RGBImageRec *image;
  23.  
  24.  
  25.  
  26. static void draw( void )
  27. {
  28.    GLfloat angle;
  29.    char *extensions;
  30.  
  31.    extensions = (char *) glGetString( GL_EXTENSIONS );
  32.    if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  33.       printf("Sorry, GL_MESA_window_pos extension not available.\n");
  34.       return;
  35.    }
  36.  
  37.    glClear( GL_COLOR_BUFFER_BIT );
  38.  
  39.    for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  40.       GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  41.       GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  42.  
  43.       /* Don't need to worry about the modelview or projection matrices!!! */
  44. #ifdef GL_MESA_window_pos
  45.       glWindowPos2fMESA( x, y );
  46. #endif
  47.       glDrawPixels( image->sizeX, image->sizeY, GL_RGB,
  48.                     GL_UNSIGNED_BYTE, image->data );
  49.    }
  50. }
  51.  
  52.  
  53.  
  54.  
  55. static GLenum key(int k, GLenum mask)
  56. {
  57.    switch (k) {
  58.       case TK_ESCAPE:
  59.      tkQuit();
  60.    }
  61.    return GL_FALSE;
  62. }
  63.  
  64.  
  65.  
  66. /* new window size or exposure */
  67. static void reshape( int width, int height )
  68. {
  69.    GLfloat  h = (GLfloat) height / (GLfloat) width;
  70.    glViewport(0, 0, (GLint)width, (GLint)height);
  71. }
  72.  
  73.  
  74. static void init( void )
  75. {
  76.    char *filename = "../samples/1.rgb";
  77.    image = tkRGBImageLoad( filename );
  78.  
  79.    if (!image) {
  80.       printf("Error: couldn't load image file: %s\n", filename );
  81.       exit(1);
  82.    }
  83. }
  84.  
  85.  
  86. main( int argc, char *argv[] )
  87. {
  88.    tkInitPosition(0, 0, 500, 500);
  89.    tkInitDisplayMode( TK_RGB | TK_DIRECT );
  90.  
  91.    if (tkInitWindow("winpos") == GL_FALSE) {
  92.       tkQuit();
  93.    }
  94.  
  95.    init();
  96.  
  97.    tkExposeFunc( reshape );
  98.    tkReshapeFunc( reshape );
  99.    tkKeyDownFunc( key );
  100.    tkDisplayFunc( draw );
  101.    tkExec();
  102. }
  103.