| 1 |
/* $Id: winpos.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Mesa 3-D graphics library |
| 5 |
* Version: 2.0 |
| 6 |
* Copyright (C) 1995-1996 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 |
* GL_MESA_window_pos extension |
| 25 |
* |
| 26 |
* This extension offers a set of functions named glWindowPos*MESA() which |
| 27 |
* directly set the current raster position to the given window coordinate. |
| 28 |
* glWindowPos*MESA() are similar to glRasterPos*() but bypass the |
| 29 |
* modelview, projection and viewport transformations. |
| 30 |
* |
| 31 |
* These functions should be very handy in conjunction with glDrawPixels() |
| 32 |
* and glCopyPixels(). |
| 33 |
* |
| 34 |
* If your application uses glWindowPos*MESA() and may be compiled with |
| 35 |
* a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files |
| 36 |
* into your source tree and compile them with the rest of your code |
| 37 |
* since glWindowPos*MESA() can, and is, implemented in terms of standard |
| 38 |
* OpenGL commands when not using Mesa. In your source files which use |
| 39 |
* glWindowPos*MESA() just #include "winpos.h". |
| 40 |
*/ |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#include "GL/gl.h" |
| 45 |
|
| 46 |
|
| 47 |
#ifdef GL_MESA_window_pos |
| 48 |
|
| 49 |
|
| 50 |
#include "draw.h" |
| 51 |
#include "dlist.h" |
| 52 |
#include "macros.h" |
| 53 |
#include "types.h" |
| 54 |
#include "winpos.h" |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
/* |
| 59 |
* Mesa implementation of glWindowPos*MESA() |
| 60 |
*/ |
| 61 |
void gl_WindowPos4fMESA( GLcontext *ctx, |
| 62 |
GLfloat x, GLfloat y, GLfloat z, GLfloat w ) |
| 63 |
{ |
| 64 |
gl_windowpos( ctx, x, y, z, w ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
#else |
| 69 |
|
| 70 |
|
| 71 |
/* |
| 72 |
* OpenGL implementation of glWindowPos*MESA() |
| 73 |
*/ |
| 74 |
void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w ) |
| 75 |
{ |
| 76 |
GLfloat fx, fy; |
| 77 |
|
| 78 |
/* Push current matrix mode and viewport attributes */ |
| 79 |
glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT ); |
| 80 |
|
| 81 |
/* Setup projection parameters */ |
| 82 |
glMatrixMode( GL_PROJECTION ); |
| 83 |
glPushMatrix(); |
| 84 |
glLoadIdentity(); |
| 85 |
glMatrixMode( GL_MODELVIEW ); |
| 86 |
glPushMatrix(); |
| 87 |
glLoadIdentity(); |
| 88 |
|
| 89 |
glDepthRange( z, z ); |
| 90 |
glViewport( (int) x - 1, (int) y - 1, 2, 2 ); |
| 91 |
|
| 92 |
/* set the raster (window) position */ |
| 93 |
fx = x - (int) x; |
| 94 |
fy = y - (int) y; |
| 95 |
glRasterPos4f( fx, fy, 0.0, w ); |
| 96 |
|
| 97 |
/* restore matrices, viewport and matrix mode */ |
| 98 |
glPopMatrix(); |
| 99 |
glMatrixMode( GL_PROJECTION ); |
| 100 |
glPopMatrix(); |
| 101 |
|
| 102 |
glPopAttrib(); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
#endif |
| 107 |
|
| 108 |
|
| 109 |
|