home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / winpos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  3.2 KB  |  133 lines

  1. /* $Id: winpos.c,v 1.5 1997/07/24 01:31:39 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.4
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: winpos.c,v $
  26.  * Revision 1.5  1997/07/24 01:31:39  brianp
  27.  * changed precompiled header symbol from PCH to PC_HEADER
  28.  *
  29.  * Revision 1.4  1997/05/28 03:27:11  brianp
  30.  * added precompiled header (PCH) support
  31.  *
  32.  * Revision 1.3  1997/04/01 04:21:43  brianp
  33.  * changed #include's
  34.  *
  35.  * Revision 1.2  1996/09/15 01:50:05  brianp
  36.  * fixed #includes
  37.  *
  38.  * Revision 1.1  1996/09/13 01:38:16  brianp
  39.  * Initial revision
  40.  *
  41.  */
  42.  
  43.  
  44. /*
  45.  * GL_MESA_window_pos extension
  46.  *
  47.  * This extension offers a set of functions named glWindowPos*MESA() which
  48.  * directly set the current raster position to the given window coordinate.
  49.  * glWindowPos*MESA() are similar to glRasterPos*() but bypass the
  50.  * modelview, projection and viewport transformations.
  51.  *
  52.  * These functions should be very handy in conjunction with glDrawPixels()
  53.  * and glCopyPixels().
  54.  *
  55.  * If your application uses glWindowPos*MESA() and may be compiled with
  56.  * a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files
  57.  * into your source tree and compile them with the rest of your code
  58.  * since glWindowPos*MESA() can, and is, implemented in terms of standard
  59.  * OpenGL commands when not using Mesa.  In your source files which use
  60.  * glWindowPos*MESA() just #include "winpos.h".
  61.  */
  62.  
  63.  
  64.  
  65. #ifdef PC_HEADER
  66. #include "all.h"
  67. #else
  68. #include "GL/gl.h"
  69. #endif
  70.  
  71. #ifdef GL_MESA_window_pos
  72.  
  73.  
  74. #ifndef PC_HEADER
  75. #include "rastpos.h"
  76. #include "winpos.h"
  77. #endif
  78.  
  79.  
  80.  
  81. /*
  82.  * Mesa implementation of glWindowPos*MESA()
  83.  */
  84. void gl_WindowPos4fMESA( GLcontext *ctx,
  85.                          GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  86. {
  87.    gl_windowpos( ctx, x, y, z, w );
  88. }
  89.  
  90.  
  91. #else
  92.  
  93.  
  94. /*
  95.  * OpenGL implementation of glWindowPos*MESA()
  96.  */
  97. void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  98. {
  99.    GLfloat fx, fy;
  100.  
  101.    /* Push current matrix mode and viewport attributes */
  102.    glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
  103.  
  104.    /* Setup projection parameters */
  105.    glMatrixMode( GL_PROJECTION );
  106.    glPushMatrix();
  107.    glLoadIdentity();
  108.    glMatrixMode( GL_MODELVIEW );
  109.    glPushMatrix();
  110.    glLoadIdentity();
  111.  
  112.    glDepthRange( z, z );
  113.    glViewport( (int) x - 1, (int) y - 1, 2, 2 );
  114.  
  115.    /* set the raster (window) position */
  116.    fx = x - (int) x;
  117.    fy = y - (int) y;
  118.    glRasterPos4f( fx, fy, 0.0, w );
  119.  
  120.    /* restore matrices, viewport and matrix mode */
  121.    glPopMatrix();
  122.    glMatrixMode( GL_PROJECTION );
  123.    glPopMatrix();
  124.  
  125.    glPopAttrib();
  126. }
  127.  
  128.  
  129. #endif
  130.  
  131.  
  132.  
  133.