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

  1. /* $Id: winpos.c,v 1.2 1996/05/08 16:47:42 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995-1996  Brian Paul  (brianp@ssec.wisc.edu)
  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.2  1996/05/08  16:47:42  brianp
  27.  * added glWindowPos[234]f[v]() functions
  28.  *
  29.  * Revision 1.1  1996/05/01  20:46:26  brianp
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. /*
  36.  * GL_MESA_window_pos extension
  37.  *
  38.  * This extension offers a set of functions named glWindowPos*MESA() which
  39.  * directly set the current raster position to the given window coordinate.
  40.  * glWindowPos*MESA() are similar to glRasterPos*() but bypass the
  41.  * modelview, projection and viewport transformations.
  42.  *
  43.  * These functions should be very handy in conjunction with glDrawPixels()
  44.  * and glCopyPixels().
  45.  *
  46.  * If your application uses glWindowPos*MESA() and may be compiled with
  47.  * a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files
  48.  * into your source tree and compile them with the rest of your code
  49.  * since glWindowPos*MESA() can, and is, implemented in terms of standard
  50.  * OpenGL commands when not using Mesa.  In your source files which use
  51.  * glWindowPos*MESA() just #include "winpos.h".
  52.  */
  53.  
  54.  
  55.  
  56. #include <GL/gl.h>
  57.  
  58.  
  59. #ifdef GL_MESA_window_pos
  60.  
  61.  
  62. #include "context.h"
  63. #include "draw.h"
  64. #include "list.h"
  65. #include "macros.h"
  66.  
  67.  
  68. /*
  69.  * Mesa implementation of glWindowPos*MESA()
  70.  */
  71. void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  72. {
  73.    if (CC.CompileFlag) {
  74.       gl_save_windowpos( x, y, z, w );
  75.    }
  76.    if (CC.ExecuteFlag) {
  77.       gl_windowpos( x, y, z, w );
  78.    }
  79. }
  80.  
  81.  
  82. #else
  83.  
  84.  
  85. /*
  86.  * OpenGL implementation of glWindowPos*MESA()
  87.  */
  88. void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  89. {
  90.    GLfloat fx, fy;
  91.  
  92.    /* Push current matrix mode and viewport attributes */
  93.    glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
  94.  
  95.    /* Setup projection parameters */
  96.    glMatrixMode( GL_PROJECTION );
  97.    glPushMatrix();
  98.    glLoadIdentity();
  99.    glMatrixMode( GL_MODELVIEW );
  100.    glPushMatrix();
  101.    glLoadIdentity();
  102.  
  103.    glDepthRange( z, z );
  104.    glViewport( (int) x - 1, (int) y - 1, 2, 2 );
  105.  
  106.    /* set the raster (window) position */
  107.    fx = x - (int) x;
  108.    fy = y - (int) y;
  109.    glRasterPos4f( fx, fy, 0.0, w );
  110.  
  111.    /* restore matrices, viewport and matrix mode */
  112.    glPopMatrix();
  113.    glMatrixMode( GL_PROJECTION );
  114.    glPopMatrix();
  115.  
  116.    glPopAttrib();
  117. }
  118.  
  119.  
  120. #endif
  121.  
  122.  
  123.  
  124. /*
  125.  * Remaining glWindowPos*MESA() variations
  126.  */
  127.  
  128. void glWindowPos2iMESA( GLint x, GLint y )
  129. {
  130.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, 0.0F, 1.0F );
  131. }
  132.  
  133. void glWindowPos2sMESA( GLshort x, GLshort y )
  134. {
  135.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, 0.0F, 1.0F );
  136. }
  137.  
  138. void glWindowPos2fMESA( GLfloat x, GLfloat y )
  139. {
  140.    glWindowPos4fMESA( x, y, 0.0F, 1.0F );
  141. }
  142.  
  143. void glWindowPos2dMESA( GLdouble x, GLdouble y )
  144. {
  145.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, 0.0F, 1.0F );
  146. }
  147.  
  148.  
  149. void glWindowPos2ivMESA( const GLint *p )
  150. {
  151.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], 0.0F, 1.0F );
  152. }
  153.  
  154. void glWindowPos2svMESA( const GLshort *p )
  155. {
  156.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], 0.0F, 1.0F );
  157. }
  158.  
  159. void glWindowPos2fvMESA( const GLfloat *p )
  160. {
  161.    glWindowPos4fMESA( p[0], p[1], 0.0F, 1.0F );
  162. }
  163.  
  164. void glWindowPos2dvMESA( const GLdouble *p )
  165. {
  166.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], 0.0F, 1.0F );
  167. }
  168.  
  169.  
  170. void glWindowPos3iMESA( GLint x, GLint y, GLint z )
  171. {
  172.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F );
  173. }
  174.  
  175. void glWindowPos3sMESA( GLshort x, GLshort y, GLshort z )
  176. {
  177.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F );
  178. }
  179.  
  180. void glWindowPos3fMESA( GLfloat x, GLfloat y, GLfloat z )
  181. {
  182.    glWindowPos4fMESA( x, y, z, 1.0F );
  183. }
  184.  
  185. void glWindowPos3dMESA( GLdouble x, GLdouble y, GLdouble z )
  186. {
  187.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0F );
  188. }
  189.  
  190.  
  191. void glWindowPos3ivMESA( const GLint *p )
  192. {
  193.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], (GLfloat) p[2], 1.0F );
  194. }
  195.  
  196. void glWindowPos3svMESA( const GLshort *p )
  197. {
  198.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], (GLfloat) p[2], 1.0F );
  199. }
  200.  
  201. void glWindowPos3fvMESA( const GLfloat *p )
  202. {
  203.    glWindowPos4fMESA( p[0], p[1], p[2], 1.0F );
  204. }
  205.  
  206. void glWindowPos3dvMESA( const GLdouble *p )
  207. {
  208.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1], (GLfloat) p[2], 1.0F );
  209. }
  210.  
  211.  
  212. void glWindowPos4iMESA( GLint x, GLint y, GLint z, GLint w )
  213. {
  214.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w );
  215. }
  216.  
  217. void glWindowPos4sMESA( GLshort x, GLshort y, GLshort z, GLshort w )
  218. {
  219.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w );
  220. }
  221.  
  222. void glWindowPos4dMESA( GLdouble x, GLdouble y, GLdouble z, GLdouble w )
  223. {
  224.    glWindowPos4fMESA( (GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w );
  225. }
  226.  
  227.  
  228. void glWindowPos4ivMESA( const GLint *p )
  229. {
  230.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1],
  231.                       (GLfloat) p[2], (GLfloat) p[3] );
  232. }
  233.  
  234. void glWindowPos4svMESA( const GLshort *p )
  235. {
  236.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1],
  237.                       (GLfloat) p[2], (GLfloat) p[3] );
  238. }
  239.  
  240. void glWindowPos4fvMESA( const GLfloat *p )
  241. {
  242.    glWindowPos4fMESA( p[0], p[1], p[2], p[3] );
  243. }
  244.  
  245. void glWindowPos4dvMESA( const GLdouble *p )
  246. {
  247.    glWindowPos4fMESA( (GLfloat) p[0], (GLfloat) p[1],
  248.                       (GLfloat) p[2], (GLfloat) p[3] );
  249. }
  250.  
  251.