forked from KolibriOS/kolibrios
upload sdk
git-svn-id: svn://kolibrios.org@4349 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
1676
contrib/sdk/samples/Mesa/engdemo.c
Normal file
1676
contrib/sdk/samples/Mesa/engdemo.c
Normal file
File diff suppressed because it is too large
Load Diff
253
contrib/sdk/samples/Mesa/gears.c
Normal file
253
contrib/sdk/samples/Mesa/gears.c
Normal file
@@ -0,0 +1,253 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "GL/osmesa.h"
|
||||
#include "GL/glu.h"
|
||||
|
||||
#define XK_Left 176
|
||||
#define XK_Right 179
|
||||
#define XK_Up 178
|
||||
#define XK_Down 177
|
||||
|
||||
extern GLfloat view_rotx, view_roty, view_rotz;
|
||||
GLint gear1, gear2, gear3;
|
||||
extern GLfloat angle;
|
||||
|
||||
static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth)
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
if (i < teeth) {
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
width * 0.5);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
|
||||
width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
if (i < teeth) {
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
-width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
-width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
|
||||
-width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
|
||||
width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
|
||||
-width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
|
||||
-width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Draw(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/* new window size or exposure */
|
||||
void Reshape(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
|
||||
GLfloat h = (GLfloat) height / (GLfloat) width;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
|
||||
void Init(void)
|
||||
{
|
||||
static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
|
||||
static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
|
||||
static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
|
||||
static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
void Key(unsigned char code, int x, int y)
|
||||
{
|
||||
int i;
|
||||
(void) x; (void) y;
|
||||
|
||||
if (code == XK_Left) {
|
||||
view_roty += 5.0;
|
||||
}
|
||||
else if (code == XK_Right) {
|
||||
view_roty -= 5.0;
|
||||
}
|
||||
else if (code == XK_Up) {
|
||||
view_rotx += 5.0;
|
||||
}
|
||||
else if (code == XK_Down) {
|
||||
view_rotx -= 5.0;
|
||||
}
|
||||
};
|
||||
|
||||
void Idle(void)
|
||||
{
|
||||
angle += 70.0 * 0.05; /* 70 degrees per second */
|
||||
if (angle > 3600.0)
|
||||
angle -= 3600.0;
|
||||
}
|
||||
|
||||
|
48
contrib/sdk/samples/Mesa/gluint.h
Normal file
48
contrib/sdk/samples/Mesa/gluint.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
||||
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice including the dates of first publication and
|
||||
* either this permission notice or a reference to
|
||||
* http://oss.sgi.com/projects/FreeB/
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Silicon Graphics, Inc.
|
||||
* shall not be used in advertising or otherwise to promote the sale, use or
|
||||
* other dealings in this Software without prior written authorization from
|
||||
* Silicon Graphics, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __gluint_h__
|
||||
#define __gluint_h__
|
||||
|
||||
extern const unsigned char *__gluNURBSErrorString( int errnum );
|
||||
|
||||
extern const unsigned char *__gluTessErrorString( int errnum );
|
||||
|
||||
#ifdef _EXTENSIONS_
|
||||
#define COS cosf
|
||||
#define SIN sinf
|
||||
#define SQRT sqrtf
|
||||
#else
|
||||
#define COS cos
|
||||
#define SIN sin
|
||||
#define SQRT sqrt
|
||||
#endif
|
||||
|
||||
#endif /* __gluint_h__ */
|
72
contrib/sdk/samples/Mesa/gluos.h
Normal file
72
contrib/sdk/samples/Mesa/gluos.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
** gluos.h - operating system dependencies for GLU
|
||||
**
|
||||
*/
|
||||
#ifdef __VMS
|
||||
#ifdef __cplusplus
|
||||
#pragma message disable nocordel
|
||||
#pragma message disable codeunreachable
|
||||
#pragma message disable codcauunr
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
/* Disable *lots* of warnings to get a clean build. I can't be bothered fixing the
|
||||
* code at the moment, as it is pretty ugly.
|
||||
*/
|
||||
#pragma warning 7 10
|
||||
#pragma warning 13 10
|
||||
#pragma warning 14 10
|
||||
#pragma warning 367 10
|
||||
#pragma warning 379 10
|
||||
#pragma warning 726 10
|
||||
#pragma warning 836 10
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_FOR_SNAP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#include <stdlib.h> /* For _MAX_PATH definition */
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOGDI
|
||||
#define NOIME
|
||||
#define NOMINMAX
|
||||
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#ifndef STRICT
|
||||
#define STRICT 1
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/* Disable warnings */
|
||||
#pragma warning(disable : 4101)
|
||||
#pragma warning(disable : 4244)
|
||||
#pragma warning(disable : 4761)
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1300
|
||||
#pragma comment(linker, "/OPT:NOWIN98")
|
||||
#endif
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#define WINGDIAPI
|
||||
|
||||
#else
|
||||
|
||||
/* Disable Microsoft-specific keywords */
|
||||
//#define GLAPIENTRY
|
||||
//#define WINGDIAPI
|
||||
|
||||
#endif
|
610
contrib/sdk/samples/Mesa/glut_shapes.c
Normal file
610
contrib/sdk/samples/Mesa/glut_shapes.c
Normal file
@@ -0,0 +1,610 @@
|
||||
|
||||
/* Copyright (c) Mark J. Kilgard, 1994, 1997. */
|
||||
|
||||
/**
|
||||
(c) Copyright 1993, Silicon Graphics, Inc.
|
||||
|
||||
ALL RIGHTS RESERVED
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
for any purpose and without fee is hereby granted, provided
|
||||
that the above copyright notice appear in all copies and that
|
||||
both the copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of Silicon
|
||||
Graphics, Inc. not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific,
|
||||
written prior permission.
|
||||
|
||||
THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU
|
||||
"AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR
|
||||
OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO
|
||||
EVENT SHALL SILICON GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE
|
||||
ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER,
|
||||
INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE,
|
||||
SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR
|
||||
NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
US Government Users Restricted Rights
|
||||
|
||||
Use, duplication, or disclosure by the Government is subject to
|
||||
restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
(c)(1)(ii) of the Rights in Technical Data and Computer
|
||||
Software clause at DFARS 252.227-7013 and/or in similar or
|
||||
successor clauses in the FAR or the DOD or NASA FAR
|
||||
Supplement. Unpublished-- rights reserved under the copyright
|
||||
laws of the United States. Contractor/manufacturer is Silicon
|
||||
Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA
|
||||
94039-7311.
|
||||
|
||||
OpenGL(TM) is a trademark of Silicon Graphics, Inc.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "gluos.h"
|
||||
#include "gluint.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
//#include "glutint.h"
|
||||
#define GLUTAPIENTRY
|
||||
|
||||
/* Some <math.h> files do not define M_PI... */
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
static GLUquadricObj *quadObj;
|
||||
|
||||
#define QUAD_OBJ_INIT() { if(!quadObj) initQuadObj(); }
|
||||
|
||||
|
||||
static void
|
||||
initQuadObj(void)
|
||||
{
|
||||
quadObj = gluNewQuadric();
|
||||
if (!quadObj)
|
||||
{
|
||||
printf("%s: out of memory.\n", __FUNCTION__);
|
||||
abort();
|
||||
};
|
||||
// __glutFatalError("out of memory.");
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
|
||||
{
|
||||
QUAD_OBJ_INIT();
|
||||
gluQuadricDrawStyle(quadObj, GLU_LINE);
|
||||
gluQuadricNormals(quadObj, GLU_SMOOTH);
|
||||
/* If we ever changed/used the texture or orientation state
|
||||
of quadObj, we'd need to change it to the defaults here
|
||||
with gluQuadricTexture and/or gluQuadricOrientation. */
|
||||
gluSphere(quadObj, radius, slices, stacks);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
|
||||
{
|
||||
QUAD_OBJ_INIT();
|
||||
gluQuadricDrawStyle(quadObj, GLU_FILL);
|
||||
gluQuadricNormals(quadObj, GLU_SMOOTH);
|
||||
/* If we ever changed/used the texture or orientation state
|
||||
of quadObj, we'd need to change it to the defaults here
|
||||
with gluQuadricTexture and/or gluQuadricOrientation. */
|
||||
gluSphere(quadObj, radius, slices, stacks);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutWireCone(GLdouble base, GLdouble height,
|
||||
GLint slices, GLint stacks)
|
||||
{
|
||||
QUAD_OBJ_INIT();
|
||||
gluQuadricDrawStyle(quadObj, GLU_LINE);
|
||||
gluQuadricNormals(quadObj, GLU_SMOOTH);
|
||||
/* If we ever changed/used the texture or orientation state
|
||||
of quadObj, we'd need to change it to the defaults here
|
||||
with gluQuadricTexture and/or gluQuadricOrientation. */
|
||||
gluCylinder(quadObj, base, 0.0, height, slices, stacks);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidCone(GLdouble base, GLdouble height,
|
||||
GLint slices, GLint stacks)
|
||||
{
|
||||
QUAD_OBJ_INIT();
|
||||
gluQuadricDrawStyle(quadObj, GLU_FILL);
|
||||
gluQuadricNormals(quadObj, GLU_SMOOTH);
|
||||
/* If we ever changed/used the texture or orientation state
|
||||
of quadObj, we'd need to change it to the defaults here
|
||||
with gluQuadricTexture and/or gluQuadricOrientation. */
|
||||
gluCylinder(quadObj, base, 0.0, height, slices, stacks);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
static void
|
||||
drawBox(GLfloat size, GLenum type)
|
||||
{
|
||||
static GLfloat n[6][3] =
|
||||
{
|
||||
{-1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, -1.0, 0.0},
|
||||
{0.0, 0.0, 1.0},
|
||||
{0.0, 0.0, -1.0}
|
||||
};
|
||||
static GLint faces[6][4] =
|
||||
{
|
||||
{0, 1, 2, 3},
|
||||
{3, 2, 6, 7},
|
||||
{7, 6, 5, 4},
|
||||
{4, 5, 1, 0},
|
||||
{5, 6, 2, 1},
|
||||
{7, 4, 0, 3}
|
||||
};
|
||||
GLfloat v[8][3];
|
||||
GLint i;
|
||||
|
||||
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
|
||||
v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
|
||||
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
|
||||
v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
|
||||
v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
|
||||
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
|
||||
|
||||
for (i = 5; i >= 0; i--) {
|
||||
glBegin(type);
|
||||
glNormal3fv(&n[i][0]);
|
||||
glVertex3fv(&v[faces[i][0]][0]);
|
||||
glVertex3fv(&v[faces[i][1]][0]);
|
||||
glVertex3fv(&v[faces[i][2]][0]);
|
||||
glVertex3fv(&v[faces[i][3]][0]);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireCube(GLdouble size)
|
||||
{
|
||||
drawBox(size, GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidCube(GLdouble size)
|
||||
{
|
||||
drawBox(size, GL_QUADS);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
static void
|
||||
doughnut(GLfloat r, GLfloat R, GLint nsides, GLint rings)
|
||||
{
|
||||
int i, j;
|
||||
GLfloat theta, phi, theta1;
|
||||
GLfloat cosTheta, sinTheta;
|
||||
GLfloat cosTheta1, sinTheta1;
|
||||
GLfloat ringDelta, sideDelta;
|
||||
|
||||
ringDelta = 2.0 * M_PI / rings;
|
||||
sideDelta = 2.0 * M_PI / nsides;
|
||||
|
||||
theta = 0.0;
|
||||
cosTheta = 1.0;
|
||||
sinTheta = 0.0;
|
||||
for (i = rings - 1; i >= 0; i--) {
|
||||
theta1 = theta + ringDelta;
|
||||
cosTheta1 = cos(theta1);
|
||||
sinTheta1 = sin(theta1);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
phi = 0.0;
|
||||
for (j = nsides; j >= 0; j--) {
|
||||
GLfloat cosPhi, sinPhi, dist;
|
||||
|
||||
phi += sideDelta;
|
||||
cosPhi = cos(phi);
|
||||
sinPhi = sin(phi);
|
||||
dist = R + r * cosPhi;
|
||||
|
||||
glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
|
||||
glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
|
||||
glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
|
||||
glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
|
||||
}
|
||||
glEnd();
|
||||
theta = theta1;
|
||||
cosTheta = cosTheta1;
|
||||
sinTheta = sinTheta1;
|
||||
}
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireTorus(GLdouble innerRadius, GLdouble outerRadius,
|
||||
GLint nsides, GLint rings)
|
||||
{
|
||||
glPushAttrib(GL_POLYGON_BIT);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
doughnut(innerRadius, outerRadius, nsides, rings);
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius,
|
||||
GLint nsides, GLint rings)
|
||||
{
|
||||
doughnut(innerRadius, outerRadius, nsides, rings);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
static GLfloat dodec[20][3];
|
||||
|
||||
static void
|
||||
initDodecahedron(void)
|
||||
{
|
||||
GLfloat alpha, beta;
|
||||
|
||||
alpha = sqrt(2.0 / (3.0 + sqrt(5.0)));
|
||||
beta = 1.0 + sqrt(6.0 / (3.0 + sqrt(5.0)) -
|
||||
2.0 + 2.0 * sqrt(2.0 / (3.0 + sqrt(5.0))));
|
||||
/* *INDENT-OFF* */
|
||||
dodec[0][0] = -alpha; dodec[0][1] = 0; dodec[0][2] = beta;
|
||||
dodec[1][0] = alpha; dodec[1][1] = 0; dodec[1][2] = beta;
|
||||
dodec[2][0] = -1; dodec[2][1] = -1; dodec[2][2] = -1;
|
||||
dodec[3][0] = -1; dodec[3][1] = -1; dodec[3][2] = 1;
|
||||
dodec[4][0] = -1; dodec[4][1] = 1; dodec[4][2] = -1;
|
||||
dodec[5][0] = -1; dodec[5][1] = 1; dodec[5][2] = 1;
|
||||
dodec[6][0] = 1; dodec[6][1] = -1; dodec[6][2] = -1;
|
||||
dodec[7][0] = 1; dodec[7][1] = -1; dodec[7][2] = 1;
|
||||
dodec[8][0] = 1; dodec[8][1] = 1; dodec[8][2] = -1;
|
||||
dodec[9][0] = 1; dodec[9][1] = 1; dodec[9][2] = 1;
|
||||
dodec[10][0] = beta; dodec[10][1] = alpha; dodec[10][2] = 0;
|
||||
dodec[11][0] = beta; dodec[11][1] = -alpha; dodec[11][2] = 0;
|
||||
dodec[12][0] = -beta; dodec[12][1] = alpha; dodec[12][2] = 0;
|
||||
dodec[13][0] = -beta; dodec[13][1] = -alpha; dodec[13][2] = 0;
|
||||
dodec[14][0] = -alpha; dodec[14][1] = 0; dodec[14][2] = -beta;
|
||||
dodec[15][0] = alpha; dodec[15][1] = 0; dodec[15][2] = -beta;
|
||||
dodec[16][0] = 0; dodec[16][1] = beta; dodec[16][2] = alpha;
|
||||
dodec[17][0] = 0; dodec[17][1] = beta; dodec[17][2] = -alpha;
|
||||
dodec[18][0] = 0; dodec[18][1] = -beta; dodec[18][2] = alpha;
|
||||
dodec[19][0] = 0; dodec[19][1] = -beta; dodec[19][2] = -alpha;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
}
|
||||
|
||||
#define DIFF3(_a,_b,_c) { \
|
||||
(_c)[0] = (_a)[0] - (_b)[0]; \
|
||||
(_c)[1] = (_a)[1] - (_b)[1]; \
|
||||
(_c)[2] = (_a)[2] - (_b)[2]; \
|
||||
}
|
||||
|
||||
static void
|
||||
crossprod(GLfloat v1[3], GLfloat v2[3], GLfloat prod[3])
|
||||
{
|
||||
GLfloat p[3]; /* in case prod == v1 or v2 */
|
||||
|
||||
p[0] = v1[1] * v2[2] - v2[1] * v1[2];
|
||||
p[1] = v1[2] * v2[0] - v2[2] * v1[0];
|
||||
p[2] = v1[0] * v2[1] - v2[0] * v1[1];
|
||||
prod[0] = p[0];
|
||||
prod[1] = p[1];
|
||||
prod[2] = p[2];
|
||||
}
|
||||
|
||||
static void
|
||||
normalize(GLfloat v[3])
|
||||
{
|
||||
GLfloat d;
|
||||
|
||||
d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
if (d == 0.0) {
|
||||
// __glutWarning("normalize: zero length vector");
|
||||
v[0] = d = 1.0;
|
||||
}
|
||||
d = 1 / d;
|
||||
v[0] *= d;
|
||||
v[1] *= d;
|
||||
v[2] *= d;
|
||||
}
|
||||
|
||||
static void
|
||||
pentagon(int a, int b, int c, int d, int e, GLenum shadeType)
|
||||
{
|
||||
GLfloat n0[3], d1[3], d2[3];
|
||||
|
||||
DIFF3(dodec[a], dodec[b], d1);
|
||||
DIFF3(dodec[b], dodec[c], d2);
|
||||
crossprod(d1, d2, n0);
|
||||
normalize(n0);
|
||||
|
||||
glBegin(shadeType);
|
||||
glNormal3fv(n0);
|
||||
glVertex3fv(&dodec[a][0]);
|
||||
glVertex3fv(&dodec[b][0]);
|
||||
glVertex3fv(&dodec[c][0]);
|
||||
glVertex3fv(&dodec[d][0]);
|
||||
glVertex3fv(&dodec[e][0]);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
dodecahedron(GLenum type)
|
||||
{
|
||||
static int inited = 0;
|
||||
|
||||
if (inited == 0) {
|
||||
inited = 1;
|
||||
initDodecahedron();
|
||||
}
|
||||
pentagon(0, 1, 9, 16, 5, type);
|
||||
pentagon(1, 0, 3, 18, 7, type);
|
||||
pentagon(1, 7, 11, 10, 9, type);
|
||||
pentagon(11, 7, 18, 19, 6, type);
|
||||
pentagon(8, 17, 16, 9, 10, type);
|
||||
pentagon(2, 14, 15, 6, 19, type);
|
||||
pentagon(2, 13, 12, 4, 14, type);
|
||||
pentagon(2, 19, 18, 3, 13, type);
|
||||
pentagon(3, 0, 5, 12, 13, type);
|
||||
pentagon(6, 15, 8, 10, 11, type);
|
||||
pentagon(4, 17, 8, 15, 14, type);
|
||||
pentagon(4, 12, 5, 16, 17, type);
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireDodecahedron(void)
|
||||
{
|
||||
dodecahedron(GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidDodecahedron(void)
|
||||
{
|
||||
dodecahedron(GL_TRIANGLE_FAN);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
static void
|
||||
recorditem(GLfloat * n1, GLfloat * n2, GLfloat * n3,
|
||||
GLenum shadeType)
|
||||
{
|
||||
GLfloat q0[3], q1[3];
|
||||
|
||||
DIFF3(n1, n2, q0);
|
||||
DIFF3(n2, n3, q1);
|
||||
crossprod(q0, q1, q1);
|
||||
normalize(q1);
|
||||
|
||||
glBegin(shadeType);
|
||||
glNormal3fv(q1);
|
||||
glVertex3fv(n1);
|
||||
glVertex3fv(n2);
|
||||
glVertex3fv(n3);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
subdivide(GLfloat * v0, GLfloat * v1, GLfloat * v2,
|
||||
GLenum shadeType)
|
||||
{
|
||||
int depth;
|
||||
GLfloat w0[3], w1[3], w2[3];
|
||||
GLfloat l;
|
||||
int i, j, k, n;
|
||||
|
||||
depth = 1;
|
||||
for (i = 0; i < depth; i++) {
|
||||
for (j = 0; i + j < depth; j++) {
|
||||
k = depth - i - j;
|
||||
for (n = 0; n < 3; n++) {
|
||||
w0[n] = (i * v0[n] + j * v1[n] + k * v2[n]) / depth;
|
||||
w1[n] = ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n])
|
||||
/ depth;
|
||||
w2[n] = (i * v0[n] + (j + 1) * v1[n] + (k - 1) * v2[n])
|
||||
/ depth;
|
||||
}
|
||||
l = sqrt(w0[0] * w0[0] + w0[1] * w0[1] + w0[2] * w0[2]);
|
||||
w0[0] /= l;
|
||||
w0[1] /= l;
|
||||
w0[2] /= l;
|
||||
l = sqrt(w1[0] * w1[0] + w1[1] * w1[1] + w1[2] * w1[2]);
|
||||
w1[0] /= l;
|
||||
w1[1] /= l;
|
||||
w1[2] /= l;
|
||||
l = sqrt(w2[0] * w2[0] + w2[1] * w2[1] + w2[2] * w2[2]);
|
||||
w2[0] /= l;
|
||||
w2[1] /= l;
|
||||
w2[2] /= l;
|
||||
recorditem(w1, w0, w2, shadeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drawtriangle(int i, GLfloat data[][3], int ndx[][3],
|
||||
GLenum shadeType)
|
||||
{
|
||||
GLfloat *x0, *x1, *x2;
|
||||
|
||||
x0 = data[ndx[i][0]];
|
||||
x1 = data[ndx[i][1]];
|
||||
x2 = data[ndx[i][2]];
|
||||
subdivide(x0, x1, x2, shadeType);
|
||||
}
|
||||
|
||||
/* octahedron data: The octahedron produced is centered at the
|
||||
origin and has radius 1.0 */
|
||||
static GLfloat odata[6][3] =
|
||||
{
|
||||
{1.0, 0.0, 0.0},
|
||||
{-1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0},
|
||||
{0.0, -1.0, 0.0},
|
||||
{0.0, 0.0, 1.0},
|
||||
{0.0, 0.0, -1.0}
|
||||
};
|
||||
|
||||
static int ondex[8][3] =
|
||||
{
|
||||
{0, 4, 2},
|
||||
{1, 2, 4},
|
||||
{0, 3, 4},
|
||||
{1, 4, 3},
|
||||
{0, 2, 5},
|
||||
{1, 5, 2},
|
||||
{0, 5, 3},
|
||||
{1, 3, 5}
|
||||
};
|
||||
|
||||
static void
|
||||
octahedron(GLenum shadeType)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 7; i >= 0; i--) {
|
||||
drawtriangle(i, odata, ondex, shadeType);
|
||||
}
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireOctahedron(void)
|
||||
{
|
||||
octahedron(GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidOctahedron(void)
|
||||
{
|
||||
octahedron(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
/* icosahedron data: These numbers are rigged to make an
|
||||
icosahedron of radius 1.0 */
|
||||
|
||||
#define X .525731112119133606
|
||||
#define Z .850650808352039932
|
||||
|
||||
static GLfloat idata[12][3] =
|
||||
{
|
||||
{-X, 0, Z},
|
||||
{X, 0, Z},
|
||||
{-X, 0, -Z},
|
||||
{X, 0, -Z},
|
||||
{0, Z, X},
|
||||
{0, Z, -X},
|
||||
{0, -Z, X},
|
||||
{0, -Z, -X},
|
||||
{Z, X, 0},
|
||||
{-Z, X, 0},
|
||||
{Z, -X, 0},
|
||||
{-Z, -X, 0}
|
||||
};
|
||||
|
||||
static int index[20][3] =
|
||||
{
|
||||
{0, 4, 1},
|
||||
{0, 9, 4},
|
||||
{9, 5, 4},
|
||||
{4, 5, 8},
|
||||
{4, 8, 1},
|
||||
{8, 10, 1},
|
||||
{8, 3, 10},
|
||||
{5, 3, 8},
|
||||
{5, 2, 3},
|
||||
{2, 7, 3},
|
||||
{7, 10, 3},
|
||||
{7, 6, 10},
|
||||
{7, 11, 6},
|
||||
{11, 0, 6},
|
||||
{0, 1, 6},
|
||||
{6, 1, 10},
|
||||
{9, 0, 11},
|
||||
{9, 11, 2},
|
||||
{9, 2, 5},
|
||||
{7, 2, 11},
|
||||
};
|
||||
|
||||
static void
|
||||
icosahedron(GLenum shadeType)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 19; i >= 0; i--) {
|
||||
drawtriangle(i, idata, index, shadeType);
|
||||
}
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireIcosahedron(void)
|
||||
{
|
||||
icosahedron(GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidIcosahedron(void)
|
||||
{
|
||||
icosahedron(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
||||
|
||||
/* tetrahedron data: */
|
||||
|
||||
#define T 1.73205080756887729
|
||||
|
||||
static GLfloat tdata[4][3] =
|
||||
{
|
||||
{T, T, T},
|
||||
{T, -T, -T},
|
||||
{-T, T, -T},
|
||||
{-T, -T, T}
|
||||
};
|
||||
|
||||
static int tndex[4][3] =
|
||||
{
|
||||
{0, 1, 3},
|
||||
{2, 1, 0},
|
||||
{3, 2, 0},
|
||||
{1, 2, 3}
|
||||
};
|
||||
|
||||
static void
|
||||
tetrahedron(GLenum shadeType)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 3; i >= 0; i--)
|
||||
drawtriangle(i, tdata, tndex, shadeType);
|
||||
}
|
||||
|
||||
/* CENTRY */
|
||||
void GLUTAPIENTRY
|
||||
glutWireTetrahedron(void)
|
||||
{
|
||||
tetrahedron(GL_LINE_LOOP);
|
||||
}
|
||||
|
||||
void GLUTAPIENTRY
|
||||
glutSolidTetrahedron(void)
|
||||
{
|
||||
tetrahedron(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
/* ENDCENTRY */
|
798
contrib/sdk/samples/Mesa/glutint.h
Normal file
798
contrib/sdk/samples/Mesa/glutint.h
Normal file
@@ -0,0 +1,798 @@
|
||||
#ifndef __glutint_h__
|
||||
#define __glutint_h__
|
||||
|
||||
/* Copyright (c) Mark J. Kilgard, 1994, 1997, 1998. */
|
||||
|
||||
/* This program is freely distributable without licensing fees
|
||||
and is provided without guarantee or warrantee expressed or
|
||||
implied. This program is -not- in the public domain. */
|
||||
|
||||
#ifdef __VMS
|
||||
#include <GL/vms_x_fix.h>
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN32__)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#define SUPPORT_FORTRAN /* With GLUT 3.7, everyone supports Fortran. */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "glutwin32.h"
|
||||
#else
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#define GLX_GLXEXT_PROTOTYPES
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
|
||||
#ifndef GLUT_BUILDING_LIB
|
||||
#define GLUT_BUILDING_LIB /* Building the GLUT library itself. */
|
||||
#endif
|
||||
|
||||
#include <GL/glut.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
/* added by BrianP: */
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY GLAPIENTRY
|
||||
#endif
|
||||
#define __cdecl GLAPIENTRY
|
||||
#define CDECL GLAPIENTRY
|
||||
#endif
|
||||
|
||||
/* GLUT_BUILDING_LIB is used by <GL/glut.h> to 1) not #pragma link
|
||||
with the GLUT library, and 2) avoid the Win32 atexit hack. */
|
||||
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
#include <GL/glutf90.h>
|
||||
#endif
|
||||
|
||||
#ifdef __vms
|
||||
#if ( __VMS_VER < 70000000 )
|
||||
#define OLD_VMS
|
||||
struct timeval6 {
|
||||
__int64 val;
|
||||
};
|
||||
extern int sys$gettim(struct timeval6 *);
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#if !defined(_WIN32) || defined(__CYGWIN32__)
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__vms) && ( __VMS_VER < 70000000 )
|
||||
|
||||
/* For VMS6.2 or lower :
|
||||
One TICK on VMS is 100 nanoseconds; 0.1 microseconds or
|
||||
0.0001 milliseconds. This means that there are 0.01
|
||||
ticks/ns, 10 ticks/us, 10,000 ticks/ms and 10,000,000
|
||||
ticks/second. */
|
||||
|
||||
#define TICKS_PER_MILLISECOND 10000
|
||||
#define TICKS_PER_SECOND 10000000
|
||||
|
||||
#define GETTIMEOFDAY(_x) (void) sys$gettim (_x);
|
||||
|
||||
#define ADD_TIME(dest, src1, src2) { \
|
||||
(dest).val = (src1).val + (src2).val; \
|
||||
}
|
||||
|
||||
#define TIMEDELTA(dest, src1, src2) { \
|
||||
(dest).val = (src1).val - (src2).val; \
|
||||
}
|
||||
|
||||
#define IS_AFTER(t1, t2) ((t2).val > (t1).val)
|
||||
|
||||
#define IS_AT_OR_AFTER(t1, t2) ((t2).val >= (t1).val)
|
||||
|
||||
#else
|
||||
#if defined(SVR4) && !defined(sun) /* Sun claims SVR4, but
|
||||
wants 2 args. */
|
||||
#define GETTIMEOFDAY(_x) gettimeofday(_x)
|
||||
#else
|
||||
#define GETTIMEOFDAY(_x) gettimeofday(_x, NULL)
|
||||
#endif
|
||||
#define ADD_TIME(dest, src1, src2) { \
|
||||
if(((dest).tv_usec = \
|
||||
(src1).tv_usec + (src2).tv_usec) >= 1000000) { \
|
||||
(dest).tv_usec -= 1000000; \
|
||||
(dest).tv_sec = (src1).tv_sec + (src2).tv_sec + 1; \
|
||||
} else { \
|
||||
(dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
|
||||
if(((dest).tv_sec >= 1) && (((dest).tv_usec <0))) { \
|
||||
(dest).tv_sec --;(dest).tv_usec += 1000000; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define TIMEDELTA(dest, src1, src2) { \
|
||||
if(((dest).tv_usec = (src1).tv_usec - (src2).tv_usec) < 0) { \
|
||||
(dest).tv_usec += 1000000; \
|
||||
(dest).tv_sec = (src1).tv_sec - (src2).tv_sec - 1; \
|
||||
} else { \
|
||||
(dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
|
||||
} \
|
||||
}
|
||||
#define IS_AFTER(t1, t2) \
|
||||
(((t2).tv_sec > (t1).tv_sec) || \
|
||||
(((t2).tv_sec == (t1).tv_sec) && \
|
||||
((t2).tv_usec > (t1).tv_usec)))
|
||||
#define IS_AT_OR_AFTER(t1, t2) \
|
||||
(((t2).tv_sec > (t1).tv_sec) || \
|
||||
(((t2).tv_sec == (t1).tv_sec) && \
|
||||
((t2).tv_usec >= (t1).tv_usec)))
|
||||
#endif
|
||||
|
||||
#define IGNORE_IN_GAME_MODE() \
|
||||
{ if (__glutGameModeWindow) return; }
|
||||
|
||||
#define GLUT_WIND_IS_RGB(x) (((x) & GLUT_INDEX) == 0)
|
||||
#define GLUT_WIND_IS_INDEX(x) (((x) & GLUT_INDEX) != 0)
|
||||
#define GLUT_WIND_IS_SINGLE(x) (((x) & GLUT_DOUBLE) == 0)
|
||||
#define GLUT_WIND_IS_DOUBLE(x) (((x) & GLUT_DOUBLE) != 0)
|
||||
#define GLUT_WIND_HAS_ACCUM(x) (((x) & GLUT_ACCUM) != 0)
|
||||
#define GLUT_WIND_HAS_ALPHA(x) (((x) & GLUT_ALPHA) != 0)
|
||||
#define GLUT_WIND_HAS_DEPTH(x) (((x) & GLUT_DEPTH) != 0)
|
||||
#define GLUT_WIND_HAS_STENCIL(x) (((x) & GLUT_STENCIL) != 0)
|
||||
#define GLUT_WIND_IS_MULTISAMPLE(x) (((x) & GLUT_MULTISAMPLE) != 0)
|
||||
#define GLUT_WIND_IS_STEREO(x) (((x) & GLUT_STEREO) != 0)
|
||||
#define GLUT_WIND_IS_LUMINANCE(x) (((x) & GLUT_LUMINANCE) != 0)
|
||||
#define GLUT_MAP_WORK (1 << 0)
|
||||
#define GLUT_EVENT_MASK_WORK (1 << 1)
|
||||
#define GLUT_REDISPLAY_WORK (1 << 2)
|
||||
#define GLUT_CONFIGURE_WORK (1 << 3)
|
||||
#define GLUT_COLORMAP_WORK (1 << 4)
|
||||
#define GLUT_DEVICE_MASK_WORK (1 << 5)
|
||||
#define GLUT_FINISH_WORK (1 << 6)
|
||||
#define GLUT_DEBUG_WORK (1 << 7)
|
||||
#define GLUT_DUMMY_WORK (1 << 8)
|
||||
#define GLUT_FULL_SCREEN_WORK (1 << 9)
|
||||
#define GLUT_OVERLAY_REDISPLAY_WORK (1 << 10)
|
||||
#define GLUT_REPAIR_WORK (1 << 11)
|
||||
#define GLUT_OVERLAY_REPAIR_WORK (1 << 12)
|
||||
|
||||
/* Frame buffer capability macros and types. */
|
||||
#define RGBA 0
|
||||
#define BUFFER_SIZE 1
|
||||
#define DOUBLEBUFFER 2
|
||||
#define STEREO 3
|
||||
#define AUX_BUFFERS 4
|
||||
#define RED_SIZE 5 /* Used as mask bit for
|
||||
"color selected". */
|
||||
#define GREEN_SIZE 6
|
||||
#define BLUE_SIZE 7
|
||||
#define ALPHA_SIZE 8
|
||||
#define DEPTH_SIZE 9
|
||||
#define STENCIL_SIZE 10
|
||||
#define ACCUM_RED_SIZE 11 /* Used as mask bit for
|
||||
"acc selected". */
|
||||
#define ACCUM_GREEN_SIZE 12
|
||||
#define ACCUM_BLUE_SIZE 13
|
||||
#define ACCUM_ALPHA_SIZE 14
|
||||
#define LEVEL 15
|
||||
|
||||
#define NUM_GLXCAPS (LEVEL + 1)
|
||||
|
||||
#define XVISUAL (NUM_GLXCAPS + 0)
|
||||
#define TRANSPARENT (NUM_GLXCAPS + 1)
|
||||
#define SAMPLES (NUM_GLXCAPS + 2)
|
||||
#define XSTATICGRAY (NUM_GLXCAPS + 3) /* Used as
|
||||
mask bit
|
||||
for "any
|
||||
visual type
|
||||
selected". */
|
||||
#define XGRAYSCALE (NUM_GLXCAPS + 4)
|
||||
#define XSTATICCOLOR (NUM_GLXCAPS + 5)
|
||||
#define XPSEUDOCOLOR (NUM_GLXCAPS + 6)
|
||||
#define XTRUECOLOR (NUM_GLXCAPS + 7)
|
||||
#define XDIRECTCOLOR (NUM_GLXCAPS + 8)
|
||||
#define SLOW (NUM_GLXCAPS + 9)
|
||||
#define CONFORMANT (NUM_GLXCAPS + 10)
|
||||
|
||||
#define NUM_CAPS (NUM_GLXCAPS + 11)
|
||||
|
||||
/* Frame buffer capablities that don't have a corresponding
|
||||
FrameBufferMode entry. These get used as mask bits. */
|
||||
#define NUM (NUM_CAPS + 0)
|
||||
#define RGBA_MODE (NUM_CAPS + 1)
|
||||
#define CI_MODE (NUM_CAPS + 2)
|
||||
#define LUMINANCE_MODE (NUM_CAPS + 3)
|
||||
|
||||
#define NONE 0
|
||||
#define EQ 1
|
||||
#define NEQ 2
|
||||
#define LTE 3
|
||||
#define GTE 4
|
||||
#define GT 5
|
||||
#define LT 6
|
||||
#define MIN 7
|
||||
|
||||
typedef struct _Criterion {
|
||||
int capability;
|
||||
int comparison;
|
||||
int value;
|
||||
} Criterion;
|
||||
|
||||
typedef struct _FrameBufferMode {
|
||||
XVisualInfo *vi;
|
||||
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
|
||||
|
||||
/* fbc is non-NULL when the XVisualInfo* is not OpenGL-capable
|
||||
(ie, GLX_USE_GL is false), but the SGIX_fbconfig extension shows
|
||||
the visual's fbconfig is OpenGL-capable. The reason for this is typically
|
||||
an RGBA luminance fbconfig such as 16-bit StaticGray that could
|
||||
not be advertised as a GLX visual since StaticGray visuals are
|
||||
required (by the GLX specification) to be color index. The
|
||||
SGIX_fbconfig allows StaticGray visuals to instead advertised as
|
||||
fbconfigs that can provide RGBA luminance support. */
|
||||
|
||||
GLXFBConfigSGIX fbc;
|
||||
#endif
|
||||
int valid;
|
||||
int cap[NUM_CAPS];
|
||||
} FrameBufferMode;
|
||||
|
||||
/* DisplayMode capability macros for game mode. */
|
||||
#define DM_WIDTH 0 /* "width" */
|
||||
#define DM_HEIGHT 1 /* "height" */
|
||||
#define DM_PIXEL_DEPTH 2 /* "bpp" (bits per pixel) */
|
||||
#define DM_HERTZ 3 /* "hertz" */
|
||||
#define DM_NUM 4 /* "num" */
|
||||
|
||||
#define NUM_DM_CAPS (DM_NUM+1)
|
||||
|
||||
typedef struct _DisplayMode {
|
||||
#ifdef _WIN32
|
||||
DEVMODE devmode;
|
||||
#else
|
||||
/* XXX The X Window System does not have a standard
|
||||
mechanism for display setting changes. On SGI
|
||||
systems, GLUT could use the XSGIvc (SGI X video
|
||||
control extension). Perhaps this can be done in
|
||||
a future release of GLUT. */
|
||||
#endif
|
||||
int valid;
|
||||
int cap[NUM_DM_CAPS];
|
||||
} DisplayMode;
|
||||
|
||||
/* GLUT function types */
|
||||
typedef void (GLUTCALLBACK *GLUTdisplayCB) (void);
|
||||
typedef void (GLUTCALLBACK *GLUTreshapeCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTkeyboardCB) (unsigned char, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTmouseCB) (int, int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTmotionCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTpassiveCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTentryCB) (int);
|
||||
typedef void (GLUTCALLBACK *GLUTvisibilityCB) (int);
|
||||
typedef void (GLUTCALLBACK *GLUTwindowStatusCB) (int);
|
||||
typedef void (GLUTCALLBACK *GLUTidleCB) (void);
|
||||
typedef void (GLUTCALLBACK *GLUTtimerCB) (int);
|
||||
typedef void (GLUTCALLBACK *GLUTmenuStateCB) (int); /* DEPRICATED. */
|
||||
typedef void (GLUTCALLBACK *GLUTmenuStatusCB) (int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTselectCB) (int);
|
||||
typedef void (GLUTCALLBACK *GLUTspecialCB) (int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTspaceMotionCB) (int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTspaceRotateCB) (int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTspaceButtonCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTdialsCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTbuttonBoxCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTtabletMotionCB) (int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTtabletButtonCB) (int, int, int, int);
|
||||
typedef void (GLUTCALLBACK *GLUTjoystickCB) (unsigned int buttonMask, int x, int y, int z);
|
||||
|
||||
typedef struct _GLUTcolorcell GLUTcolorcell;
|
||||
struct _GLUTcolorcell {
|
||||
/* GLUT_RED, GLUT_GREEN, GLUT_BLUE */
|
||||
GLfloat component[3];
|
||||
};
|
||||
|
||||
typedef struct _GLUTcolormap GLUTcolormap;
|
||||
struct _GLUTcolormap {
|
||||
Visual *visual; /* visual of the colormap */
|
||||
Colormap cmap; /* X colormap ID */
|
||||
int refcnt; /* number of windows using colormap */
|
||||
int size; /* number of cells in colormap */
|
||||
int transparent; /* transparent pixel, or -1 if opaque */
|
||||
GLUTcolorcell *cells; /* array of cells */
|
||||
GLUTcolormap *next; /* next colormap in list */
|
||||
};
|
||||
|
||||
typedef struct _GLUTwindow GLUTwindow;
|
||||
typedef struct _GLUToverlay GLUToverlay;
|
||||
struct _GLUTwindow {
|
||||
int num; /* Small integer window id (0-based). */
|
||||
|
||||
/* Window system related state. */
|
||||
#if defined(_WIN32)
|
||||
int pf; /* Pixel format. */
|
||||
HDC hdc; /* Window's Win32 device context. */
|
||||
#endif
|
||||
Window win; /* X window for GLUT window */
|
||||
GLXContext ctx; /* OpenGL context GLUT glut window */
|
||||
XVisualInfo *vis; /* visual for window */
|
||||
Bool visAlloced; /* if vis needs deallocate on destroy */
|
||||
Colormap cmap; /* RGB colormap for window; None if CI */
|
||||
GLUTcolormap *colormap; /* colormap; NULL if RGBA */
|
||||
GLUToverlay *overlay; /* overlay; NULL if no overlay */
|
||||
#if defined(_WIN32)
|
||||
HDC renderDc; /* Win32's device context for rendering. */
|
||||
#endif
|
||||
Window renderWin; /* X window for rendering (might be
|
||||
overlay) */
|
||||
GLXContext renderCtx; /* OpenGL context for rendering (might
|
||||
be overlay) */
|
||||
/* GLUT settable or visible window state. */
|
||||
int width; /* window width in pixels */
|
||||
int height; /* window height in pixels */
|
||||
int cursor; /* cursor name */
|
||||
int visState; /* visibility state (-1 is unknown) */
|
||||
int shownState; /* if window mapped */
|
||||
int entryState; /* entry state (-1 is unknown) */
|
||||
#define GLUT_MAX_MENUS 3
|
||||
|
||||
int menu[GLUT_MAX_MENUS]; /* attatched menu nums */
|
||||
/* Window relationship state. */
|
||||
GLUTwindow *parent; /* parent window */
|
||||
GLUTwindow *children; /* list of children */
|
||||
GLUTwindow *siblings; /* list of siblings */
|
||||
/* Misc. non-API visible (hidden) state. */
|
||||
Bool treatAsSingle; /* treat this window as single-buffered
|
||||
(it might be "fake" though) */
|
||||
Bool forceReshape; /* force reshape before display */
|
||||
#if !defined(_WIN32)
|
||||
Bool isDirect; /* if direct context (X11 only) */
|
||||
#endif
|
||||
Bool usedSwapBuffers; /* if swap buffers used last display */
|
||||
long eventMask; /* mask of X events selected for */
|
||||
int buttonUses; /* number of button uses, ref cnt */
|
||||
int tabletPos[2]; /* tablet position (-1 is invalid) */
|
||||
/* Work list related state. */
|
||||
unsigned int workMask; /* mask of window work to be done */
|
||||
GLUTwindow *prevWorkWin; /* link list of windows to work on */
|
||||
Bool desiredMapState; /* how to mapped window if on map work
|
||||
list */
|
||||
Bool ignoreKeyRepeat; /* if window ignores autorepeat */
|
||||
int desiredConfMask; /* mask of desired window configuration
|
||||
*/
|
||||
int desiredX; /* desired X location */
|
||||
int desiredY; /* desired Y location */
|
||||
int desiredWidth; /* desired window width */
|
||||
int desiredHeight; /* desired window height */
|
||||
int desiredStack; /* desired window stack */
|
||||
/* Per-window callbacks. */
|
||||
GLUTdisplayCB display; /* redraw */
|
||||
GLUTreshapeCB reshape; /* resize (width,height) */
|
||||
GLUTmouseCB mouse; /* mouse (button,state,x,y) */
|
||||
GLUTmotionCB motion; /* motion (x,y) */
|
||||
GLUTpassiveCB passive; /* passive motion (x,y) */
|
||||
GLUTentryCB entry; /* window entry/exit (state) */
|
||||
GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */
|
||||
GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */
|
||||
GLUTwindowStatusCB windowStatus; /* window status */
|
||||
GLUTvisibilityCB visibility; /* visibility */
|
||||
GLUTspecialCB special; /* special key */
|
||||
GLUTspecialCB specialUp; /* special up key */
|
||||
GLUTbuttonBoxCB buttonBox; /* button box */
|
||||
GLUTdialsCB dials; /* dials */
|
||||
GLUTspaceMotionCB spaceMotion; /* Spaceball motion */
|
||||
GLUTspaceRotateCB spaceRotate; /* Spaceball rotate */
|
||||
GLUTspaceButtonCB spaceButton; /* Spaceball button */
|
||||
GLUTtabletMotionCB tabletMotion; /* tablet motion */
|
||||
GLUTtabletButtonCB tabletButton; /* tablet button */
|
||||
#ifdef _WIN32
|
||||
GLUTjoystickCB joystick; /* joystick */
|
||||
int joyPollInterval; /* joystick polling interval */
|
||||
#endif
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
GLUTdisplayFCB fdisplay; /* Fortran display */
|
||||
GLUTreshapeFCB freshape; /* Fortran reshape */
|
||||
GLUTmouseFCB fmouse; /* Fortran mouse */
|
||||
GLUTmotionFCB fmotion; /* Fortran motion */
|
||||
GLUTpassiveFCB fpassive; /* Fortran passive */
|
||||
GLUTentryFCB fentry; /* Fortran entry */
|
||||
GLUTkeyboardFCB fkeyboard; /* Fortran keyboard */
|
||||
GLUTkeyboardFCB fkeyboardUp; /* Fortran keyboard up */
|
||||
GLUTwindowStatusFCB fwindowStatus; /* Fortran window status */
|
||||
GLUTvisibilityFCB fvisibility; /* Fortran visibility */
|
||||
GLUTspecialFCB fspecial; /* special key */
|
||||
GLUTspecialFCB fspecialUp; /* special key up */
|
||||
GLUTbuttonBoxFCB fbuttonBox; /* button box */
|
||||
GLUTdialsFCB fdials; /* dials */
|
||||
GLUTspaceMotionFCB fspaceMotion; /* Spaceball motion */
|
||||
GLUTspaceRotateFCB fspaceRotate; /* Spaceball rotate */
|
||||
GLUTspaceButtonFCB fspaceButton; /* Spaceball button */
|
||||
GLUTtabletMotionFCB ftabletMotion; /* tablet motion */
|
||||
GLUTtabletButtonFCB ftabletButton; /* tablet button */
|
||||
#ifdef _WIN32
|
||||
GLUTjoystickFCB fjoystick; /* joystick */
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _GLUToverlay {
|
||||
#if defined(_WIN32)
|
||||
int pf;
|
||||
HDC hdc;
|
||||
#endif
|
||||
Window win;
|
||||
GLXContext ctx;
|
||||
XVisualInfo *vis; /* visual for window */
|
||||
Bool visAlloced; /* if vis needs deallocate on destroy */
|
||||
Colormap cmap; /* RGB colormap for window; None if CI */
|
||||
GLUTcolormap *colormap; /* colormap; NULL if RGBA */
|
||||
int shownState; /* if overlay window mapped */
|
||||
Bool treatAsSingle; /* treat as single-buffered */
|
||||
#if !defined(_WIN32)
|
||||
Bool isDirect; /* if direct context */
|
||||
#endif
|
||||
int transparentPixel; /* transparent pixel value */
|
||||
GLUTdisplayCB display; /* redraw */
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
GLUTdisplayFCB fdisplay; /* redraw */
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct _GLUTstale GLUTstale;
|
||||
struct _GLUTstale {
|
||||
GLUTwindow *window;
|
||||
Window win;
|
||||
GLUTstale *next;
|
||||
};
|
||||
|
||||
extern GLUTstale *__glutStaleWindowList;
|
||||
|
||||
#define GLUT_OVERLAY_EVENT_FILTER_MASK \
|
||||
(ExposureMask | \
|
||||
StructureNotifyMask | \
|
||||
EnterWindowMask | \
|
||||
LeaveWindowMask)
|
||||
#define GLUT_DONT_PROPAGATE_FILTER_MASK \
|
||||
(ButtonReleaseMask | \
|
||||
ButtonPressMask | \
|
||||
KeyPressMask | \
|
||||
KeyReleaseMask | \
|
||||
PointerMotionMask | \
|
||||
Button1MotionMask | \
|
||||
Button2MotionMask | \
|
||||
Button3MotionMask)
|
||||
#define GLUT_HACK_STOP_PROPAGATE_MASK \
|
||||
(KeyPressMask | \
|
||||
KeyReleaseMask)
|
||||
|
||||
typedef struct _GLUTmenu GLUTmenu;
|
||||
typedef struct _GLUTmenuItem GLUTmenuItem;
|
||||
struct _GLUTmenu {
|
||||
int id; /* small integer menu id (0-based) */
|
||||
Window win; /* X window for the menu */
|
||||
GLUTselectCB select; /* function of menu */
|
||||
GLUTmenuItem *list; /* list of menu entries */
|
||||
int num; /* number of entries */
|
||||
#if !defined(_WIN32)
|
||||
Bool managed; /* are the InputOnly windows size
|
||||
validated? */
|
||||
Bool searched; /* help detect menu loops */
|
||||
int pixheight; /* height of menu in pixels */
|
||||
int pixwidth; /* width of menu in pixels */
|
||||
#endif
|
||||
int submenus; /* number of submenu entries */
|
||||
GLUTmenuItem *highlighted; /* pointer to highlighted menu
|
||||
entry, NULL not highlighted */
|
||||
GLUTmenu *cascade; /* currently cascading this menu */
|
||||
GLUTmenuItem *anchor; /* currently anchored to this entry */
|
||||
int x; /* current x origin relative to the
|
||||
root window */
|
||||
int y; /* current y origin relative to the
|
||||
root window */
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
GLUTselectFCB fselect; /* function of menu */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _GLUTmenuItem {
|
||||
Window win; /* InputOnly X window for entry */
|
||||
GLUTmenu *menu; /* menu entry belongs to */
|
||||
Bool isTrigger; /* is a submenu trigger? */
|
||||
int value; /* value to return for selecting this
|
||||
entry; doubles as submenu id
|
||||
(0-base) if submenu trigger */
|
||||
#if defined(_WIN32)
|
||||
UINT unique; /* unique menu item id (Win32 only) */
|
||||
#endif
|
||||
char *label; /* __glutStrdup'ed label string */
|
||||
int len; /* length of label string */
|
||||
int pixwidth; /* width of X window in pixels */
|
||||
GLUTmenuItem *next; /* next menu entry on list for menu */
|
||||
};
|
||||
|
||||
typedef struct _GLUTtimer GLUTtimer;
|
||||
struct _GLUTtimer {
|
||||
GLUTtimer *next; /* list of timers */
|
||||
#ifdef OLD_VMS
|
||||
struct timeval6 timeout; /* time to be called */
|
||||
#else
|
||||
struct timeval timeout; /* time to be called */
|
||||
#endif
|
||||
GLUTtimerCB func; /* timer (value) */
|
||||
int value; /* return value */
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
GLUTtimerFCB ffunc; /* Fortran timer */
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct _GLUTeventParser GLUTeventParser;
|
||||
struct _GLUTeventParser {
|
||||
int (*func) (XEvent *);
|
||||
GLUTeventParser *next;
|
||||
};
|
||||
|
||||
/* Declarations to implement glutFullScreen support with
|
||||
mwm/4Dwm. */
|
||||
|
||||
/* The following X property format is defined in Motif 1.1's
|
||||
Xm/MwmUtils.h, but GLUT should not depend on that header
|
||||
file. Note: Motif 1.2 expanded this structure with
|
||||
uninteresting fields (to GLUT) so just stick with the
|
||||
smaller Motif 1.1 structure. */
|
||||
typedef struct {
|
||||
#define MWM_HINTS_DECORATIONS 2
|
||||
long flags;
|
||||
long functions;
|
||||
long decorations;
|
||||
long input_mode;
|
||||
} MotifWmHints;
|
||||
|
||||
/* Make current and buffer swap macros. */
|
||||
#ifdef _WIN32
|
||||
#define MAKE_CURRENT_LAYER(window) \
|
||||
{ \
|
||||
HGLRC currentContext = wglGetCurrentContext(); \
|
||||
HDC currentDc = wglGetCurrentDC(); \
|
||||
\
|
||||
if (currentContext != window->renderCtx \
|
||||
|| currentDc != window->renderDc) { \
|
||||
wglMakeCurrent(window->renderDc, window->renderCtx); \
|
||||
} \
|
||||
}
|
||||
#define MAKE_CURRENT_WINDOW(window) \
|
||||
{ \
|
||||
HGLRC currentContext = wglGetCurrentContext(); \
|
||||
HDC currentDc = wglGetCurrentDC(); \
|
||||
\
|
||||
if (currentContext != window->ctx || currentDc != window->hdc) { \
|
||||
wglMakeCurrent(window->hdc, window->ctx); \
|
||||
} \
|
||||
}
|
||||
#define MAKE_CURRENT_OVERLAY(overlay) \
|
||||
wglMakeCurrent(overlay->hdc, overlay->ctx)
|
||||
#define UNMAKE_CURRENT() \
|
||||
wglMakeCurrent(NULL, NULL)
|
||||
#define SWAP_BUFFERS_WINDOW(window) \
|
||||
SwapBuffers(window->hdc)
|
||||
#define SWAP_BUFFERS_LAYER(window) \
|
||||
SwapBuffers(window->renderDc)
|
||||
#else
|
||||
#define MAKE_CURRENT_LAYER(window) \
|
||||
glXMakeCurrent(__glutDisplay, window->renderWin, window->renderCtx)
|
||||
#define MAKE_CURRENT_WINDOW(window) \
|
||||
glXMakeCurrent(__glutDisplay, window->win, window->ctx)
|
||||
#define MAKE_CURRENT_OVERLAY(overlay) \
|
||||
glXMakeCurrent(__glutDisplay, overlay->win, overlay->ctx)
|
||||
#define UNMAKE_CURRENT() \
|
||||
glXMakeCurrent(__glutDisplay, None, NULL)
|
||||
#define SWAP_BUFFERS_WINDOW(window) \
|
||||
glXSwapBuffers(__glutDisplay, window->win)
|
||||
#define SWAP_BUFFERS_LAYER(window) \
|
||||
glXSwapBuffers(__glutDisplay, window->renderWin)
|
||||
#endif
|
||||
|
||||
/* private variables from glut_event.c */
|
||||
extern GLUTwindow *__glutWindowWorkList;
|
||||
extern int __glutWindowDamaged;
|
||||
#ifdef SUPPORT_FORTRAN
|
||||
extern GLUTtimer *__glutTimerList;
|
||||
extern GLUTtimer *__glutNewTimer;
|
||||
#endif
|
||||
extern GLUTmenu *__glutMappedMenu;
|
||||
|
||||
extern void (*__glutUpdateInputDeviceMaskFunc) (GLUTwindow *);
|
||||
#if !defined(_WIN32)
|
||||
extern void (*__glutMenuItemEnterOrLeave)(GLUTmenuItem * item,
|
||||
int num, int type);
|
||||
extern void (*__glutFinishMenu)(Window win, int x, int y);
|
||||
extern void (*__glutPaintMenu)(GLUTmenu * menu);
|
||||
extern void (*__glutStartMenu)(GLUTmenu * menu,
|
||||
GLUTwindow * window, int x, int y, int x_win, int y_win);
|
||||
extern GLUTmenu * (*__glutGetMenuByNum)(int menunum);
|
||||
extern GLUTmenuItem * (*__glutGetMenuItem)(GLUTmenu * menu,
|
||||
Window win, int *which);
|
||||
extern GLUTmenu * (*__glutGetMenu)(Window win);
|
||||
#endif
|
||||
|
||||
/* private variables from glut_init.c */
|
||||
extern Atom __glutWMDeleteWindow;
|
||||
extern Display *__glutDisplay;
|
||||
extern unsigned int __glutDisplayMode;
|
||||
extern char *__glutDisplayString;
|
||||
extern XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle,
|
||||
Criterion * requiredCriteria, int nRequired, int requiredMask, void **fbc);
|
||||
extern GLboolean __glutDebug;
|
||||
extern GLboolean __glutForceDirect;
|
||||
extern GLboolean __glutIconic;
|
||||
extern GLboolean __glutTryDirect;
|
||||
extern Window __glutRoot;
|
||||
extern XSizeHints __glutSizeHints;
|
||||
extern char **__glutArgv;
|
||||
extern char *__glutProgramName;
|
||||
extern int __glutArgc;
|
||||
extern int __glutConnectionFD;
|
||||
extern int __glutInitHeight;
|
||||
extern int __glutInitWidth;
|
||||
extern int __glutInitX;
|
||||
extern int __glutInitY;
|
||||
extern int __glutScreen;
|
||||
extern int __glutScreenHeight;
|
||||
extern int __glutScreenWidth;
|
||||
extern Atom __glutMotifHints;
|
||||
extern unsigned int __glutModifierMask;
|
||||
#ifdef _WIN32
|
||||
extern void (__cdecl *__glutExitFunc)(int retval);
|
||||
#endif
|
||||
extern char *__glutPPMFile;
|
||||
|
||||
/* private variables from glut_menu.c */
|
||||
extern GLUTmenuItem *__glutItemSelected;
|
||||
extern GLUTmenu **__glutMenuList;
|
||||
extern void (GLUTCALLBACK *__glutMenuStatusFunc) (int, int, int);
|
||||
extern void __glutMenuModificationError(void);
|
||||
extern void __glutSetMenuItem(GLUTmenuItem * item,
|
||||
const char *label, int value, Bool isTrigger);
|
||||
|
||||
/* private variables from glut_win.c */
|
||||
extern GLUTwindow **__glutWindowList;
|
||||
extern GLUTwindow *__glutCurrentWindow;
|
||||
extern GLUTwindow *__glutMenuWindow;
|
||||
extern GLUTmenu *__glutCurrentMenu;
|
||||
extern int __glutWindowListSize;
|
||||
extern void (*__glutFreeOverlayFunc) (GLUToverlay *);
|
||||
extern void __glutFreeOverlay(GLUToverlay * overlay);
|
||||
extern XVisualInfo *__glutDetermineWindowVisual(Bool * treatAsSingle,
|
||||
Bool * visAlloced, void **fbc);
|
||||
|
||||
/* private variables from glut_ppm.c */
|
||||
extern void __glutWritePPMFile(void);
|
||||
|
||||
/* private variables from glut_mesa.c */
|
||||
extern int __glutMesaSwapHackSupport;
|
||||
|
||||
/* private variables from glut_gamemode.c */
|
||||
extern GLUTwindow *__glutGameModeWindow;
|
||||
|
||||
/* private routines from glut_cindex.c */
|
||||
extern GLUTcolormap * __glutAssociateNewColormap(XVisualInfo * vis);
|
||||
extern void __glutFreeColormap(GLUTcolormap *);
|
||||
|
||||
/* private routines from glut_cmap.c */
|
||||
extern void __glutSetupColormap(
|
||||
XVisualInfo * vi,
|
||||
GLUTcolormap ** colormap,
|
||||
Colormap * cmap);
|
||||
#if !defined(_WIN32)
|
||||
extern void __glutEstablishColormapsProperty(
|
||||
GLUTwindow * window);
|
||||
extern GLUTwindow *__glutToplevelOf(GLUTwindow * window);
|
||||
#endif
|
||||
|
||||
/* private routines from glut_cursor.c */
|
||||
extern void __glutSetCursor(GLUTwindow *window);
|
||||
|
||||
/* private routines from glut_event.c */
|
||||
extern void __glutPutOnWorkList(GLUTwindow * window,
|
||||
int work_mask);
|
||||
extern void __glutRegisterEventParser(GLUTeventParser * parser);
|
||||
extern void __glutPostRedisplay(GLUTwindow * window, int layerMask);
|
||||
extern void handleTimeouts(void);
|
||||
|
||||
/* private routines from glut_init.c */
|
||||
#if !defined(_WIN32)
|
||||
extern void __glutOpenXConnection(char *display);
|
||||
#else
|
||||
extern void __glutOpenWin32Connection(char *display);
|
||||
#endif
|
||||
#ifdef OLD_VMS
|
||||
extern void __glutInitTime(struct timeval6 *beginning);
|
||||
#else
|
||||
extern void __glutInitTime(struct timeval *beginning);
|
||||
#endif
|
||||
|
||||
/* private routines for glut_menu.c (or win32_menu.c) */
|
||||
#if defined(_WIN32)
|
||||
extern GLUTmenu *__glutGetMenu(Window win);
|
||||
extern GLUTmenu *__glutGetMenuByNum(int menunum);
|
||||
extern GLUTmenuItem *__glutGetMenuItem(GLUTmenu * menu,
|
||||
Window win, int *which);
|
||||
extern void __glutStartMenu(GLUTmenu * menu,
|
||||
GLUTwindow * window, int x, int y, int x_win, int y_win);
|
||||
extern void __glutFinishMenu(Window win, int x, int y);
|
||||
#endif
|
||||
extern void __glutSetMenu(GLUTmenu * menu);
|
||||
|
||||
/* private routines from glut_util.c */
|
||||
extern char * __glutStrdup(const char *string);
|
||||
extern void __glutWarning(char *format,...);
|
||||
extern void __glutFatalError(char *format,...);
|
||||
extern void __glutFatalUsage(char *format,...);
|
||||
|
||||
/* private routines from glut_win.c */
|
||||
extern GLUTwindow *__glutGetWindow(Window win);
|
||||
extern void __glutChangeWindowEventMask(long mask, Bool add);
|
||||
extern XVisualInfo *__glutDetermineVisual(
|
||||
unsigned int mode,
|
||||
Bool * fakeSingle,
|
||||
XVisualInfo * (getVisualInfo) (unsigned int));
|
||||
extern XVisualInfo *__glutGetVisualInfo(unsigned int mode);
|
||||
extern void __glutSetWindow(GLUTwindow * window);
|
||||
extern void __glutReshapeFunc(GLUTreshapeCB reshapeFunc,
|
||||
int callingConvention);
|
||||
extern void GLUTCALLBACK __glutDefaultReshape(int, int);
|
||||
extern GLUTwindow *__glutCreateWindow(
|
||||
GLUTwindow * parent,
|
||||
int x, int y, int width, int height, int gamemode);
|
||||
extern void __glutDestroyWindow(
|
||||
GLUTwindow * window,
|
||||
GLUTwindow * initialWindow);
|
||||
|
||||
#if !defined(_WIN32)
|
||||
/* private routines from glut_glxext.c */
|
||||
extern int __glutIsSupportedByGLX(char *);
|
||||
extern int __glut_glXBindChannelToWindowSGIX(Display *dpy, int screen,
|
||||
int channel, Window window);
|
||||
extern int __glut_glXChannelRectSGIX(Display *dpy, int screen, int channel,
|
||||
int x, int y, int w, int h);
|
||||
extern int __glut_glXQueryChannelRectSGIX(Display *dpy, int screen,
|
||||
int channel, int *x, int *y,
|
||||
int *w, int *h);
|
||||
extern int __glut_glXQueryChannelDeltasSGIX(Display *dpy, int screen,
|
||||
int channel, int *dx, int *dy,
|
||||
int *dw, int *dh);
|
||||
extern int __glut_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel,
|
||||
GLenum synctype);
|
||||
extern GLXContext __glut_glXCreateContextWithConfigSGIX(Display *dpy,
|
||||
GLXFBConfigSGIX config,
|
||||
int render_type,
|
||||
GLXContext share_list,
|
||||
Bool direct);
|
||||
extern int __glut_glXGetFBConfigAttribSGIX(Display *dpy,
|
||||
GLXFBConfigSGIX config,
|
||||
int attribute,
|
||||
int *value);
|
||||
extern GLXFBConfigSGIX __glut_glXGetFBConfigFromVisualSGIX(Display *dpy,
|
||||
XVisualInfo *vis);
|
||||
#endif
|
||||
|
||||
/* private routines from glut_input.c */
|
||||
extern void __glutUpdateInputDeviceMask(GLUTwindow * window);
|
||||
|
||||
/* private routines from glut_mesa.c */
|
||||
extern void __glutDetermineMesaSwapHackSupport(void);
|
||||
|
||||
/* private routines from glut_gameglut.c */
|
||||
extern void __glutCloseDownGameMode(void);
|
||||
|
||||
/* private variables from glut_swap.c (BrianP) */
|
||||
extern GLint __glutFPS;
|
||||
extern GLint __glutSwapCount;
|
||||
extern GLint __glutSwapTime;
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* private routines from win32_*.c */
|
||||
extern LONG WINAPI __glutWindowProc(HWND win, UINT msg, WPARAM w, LPARAM l);
|
||||
extern HDC XHDC;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __glutint_h__ */
|
8940
contrib/sdk/samples/Mesa/mipmap.c
Normal file
8940
contrib/sdk/samples/Mesa/mipmap.c
Normal file
File diff suppressed because it is too large
Load Diff
180
contrib/sdk/samples/Mesa/osdemo.c
Normal file
180
contrib/sdk/samples/Mesa/osdemo.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Demo of off-screen Mesa rendering
|
||||
*
|
||||
* See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions.
|
||||
*
|
||||
* If you want to render BIG images you'll probably have to increase
|
||||
* MAX_WIDTH and MAX_Height in src/config.h.
|
||||
*
|
||||
* This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*
|
||||
* PPM output provided by Joerg Schmalzl.
|
||||
* ASCII PPM output added by Brian Paul.
|
||||
*
|
||||
* Usage: osdemo [filename]
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "GL/osmesa.h"
|
||||
#include <GL/glext.h>
|
||||
#include "GL/glu.h"
|
||||
#include "shaderutil.h"
|
||||
#include <kos32sys.h>
|
||||
|
||||
int _CRT_MT=0;
|
||||
|
||||
static int Width = 500;
|
||||
static int Height = 400;
|
||||
|
||||
int check_events();
|
||||
|
||||
GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
GLfloat angle = 0.0;
|
||||
|
||||
GLboolean animate = GL_TRUE; /* Animation */
|
||||
GLfloat eyesep = 5.0; /* Eye separation. */
|
||||
GLfloat fix_point = 40.0; /* Fixation point distance. */
|
||||
GLfloat left, right, asp; /* Stereo frustum params. */
|
||||
|
||||
void Init( void );
|
||||
void Reshape( int width, int height );
|
||||
void Draw( void );
|
||||
void Idle();
|
||||
void Key(unsigned char key, int x, int y);
|
||||
|
||||
|
||||
inline void Blit(void *bitmap, int dst_x, int dst_y,
|
||||
int src_x, int src_y, int w, int h,
|
||||
int src_w, int src_h, int stride)
|
||||
{
|
||||
volatile struct blit_call bc;
|
||||
|
||||
bc.dstx = dst_x;
|
||||
bc.dsty = dst_y;
|
||||
bc.w = w;
|
||||
bc.h = h;
|
||||
bc.srcx = src_x;
|
||||
bc.srcy = src_y;
|
||||
bc.srcw = src_w;
|
||||
bc.srch = src_h;
|
||||
bc.stride = stride;
|
||||
bc.bitmap = bitmap;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"int $0x40"
|
||||
::"a"(73),"b"(0),"c"(&bc.dstx));
|
||||
|
||||
};
|
||||
|
||||
|
||||
static inline uint32_t wait_os_event(int time)
|
||||
{
|
||||
uint32_t val;
|
||||
__asm__ __volatile__(
|
||||
"int $0x40"
|
||||
:"=a"(val)
|
||||
:"a"(23),"b"(time));
|
||||
return val;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSMesaContext ctx;
|
||||
void *buffer;
|
||||
char *filename = NULL;
|
||||
int ev;
|
||||
int repeat=1;
|
||||
|
||||
/* Create an RGBA-mode context */
|
||||
/* specify Z, stencil, accum sizes */
|
||||
|
||||
ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
|
||||
if (!ctx) {
|
||||
printf("OSMesaCreateContext failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate the image buffer */
|
||||
buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
|
||||
if (!buffer) {
|
||||
printf("Alloc image buffer failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// __asm__ __volatile__("int3");
|
||||
|
||||
/* Bind the buffer to the context and make it current */
|
||||
if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
|
||||
printf("OSMesaMakeCurrent failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
{
|
||||
int z, s, a;
|
||||
glGetIntegerv(GL_DEPTH_BITS, &z);
|
||||
glGetIntegerv(GL_STENCIL_BITS, &s);
|
||||
glGetIntegerv(GL_ACCUM_RED_BITS, &a);
|
||||
printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
|
||||
}
|
||||
|
||||
Reshape(Width, Height);
|
||||
Init();
|
||||
Draw();
|
||||
|
||||
printf("all done\n");
|
||||
|
||||
DrawWindow(10, 10, Width+9, Height+26, "OpenGL Engine Demo", 0x000000, 0x74);
|
||||
Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
|
||||
|
||||
while(repeat)
|
||||
{
|
||||
oskey_t key;
|
||||
|
||||
ev = wait_os_event(1);
|
||||
switch(ev)
|
||||
{
|
||||
case 1:
|
||||
DrawWindow(10, 10, Width+9, Width+26, NULL, 0x000000,0x74);
|
||||
Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
|
||||
continue;
|
||||
|
||||
case 2:
|
||||
key = get_key();
|
||||
Key(key.code, 0, 0);
|
||||
Draw();
|
||||
Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
|
||||
continue;
|
||||
|
||||
case 3:
|
||||
if(get_os_button()==1)
|
||||
repeat=0;
|
||||
continue;
|
||||
};
|
||||
Idle();
|
||||
Draw();
|
||||
Blit(buffer, 5, 22, 0, 0, Width, Height, Width,Height,Width*4);
|
||||
};
|
||||
|
||||
/* free the image buffer */
|
||||
free( buffer );
|
||||
|
||||
/* destroy the context */
|
||||
OSMesaDestroyContext( ctx );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int atexit(void (*func)(void))
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
1155
contrib/sdk/samples/Mesa/quad.c
Normal file
1155
contrib/sdk/samples/Mesa/quad.c
Normal file
File diff suppressed because it is too large
Load Diff
494
contrib/sdk/samples/Mesa/readtex.c
Normal file
494
contrib/sdk/samples/Mesa/readtex.c
Normal file
@@ -0,0 +1,494 @@
|
||||
/* readtex.c */
|
||||
|
||||
/*
|
||||
* Read an SGI .rgb image file and generate a mipmap texture set.
|
||||
* Much of this code was borrowed from SGI's tk OpenGL toolkit.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "readtex.h"
|
||||
|
||||
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** RGB Image Structure
|
||||
*/
|
||||
|
||||
typedef struct _TK_RGBImageRec {
|
||||
GLint sizeX, sizeY;
|
||||
GLint components;
|
||||
unsigned char *data;
|
||||
} TK_RGBImageRec;
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
typedef struct _rawImageRec {
|
||||
unsigned short imagic;
|
||||
unsigned short type;
|
||||
unsigned short dim;
|
||||
unsigned short sizeX, sizeY, sizeZ;
|
||||
unsigned long min, max;
|
||||
unsigned long wasteBytes;
|
||||
char name[80];
|
||||
unsigned long colorMap;
|
||||
FILE *file;
|
||||
unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA;
|
||||
unsigned long rleEnd;
|
||||
GLuint *rowStart;
|
||||
GLint *rowSize;
|
||||
} rawImageRec;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void ConvertShort(unsigned short *array, long length)
|
||||
{
|
||||
unsigned long b1, b2;
|
||||
unsigned char *ptr;
|
||||
|
||||
ptr = (unsigned char *)array;
|
||||
while (length--) {
|
||||
b1 = *ptr++;
|
||||
b2 = *ptr++;
|
||||
*array++ = (unsigned short) ((b1 << 8) | (b2));
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertLong(GLuint *array, long length)
|
||||
{
|
||||
unsigned long b1, b2, b3, b4;
|
||||
unsigned char *ptr;
|
||||
|
||||
ptr = (unsigned char *)array;
|
||||
while (length--) {
|
||||
b1 = *ptr++;
|
||||
b2 = *ptr++;
|
||||
b3 = *ptr++;
|
||||
b4 = *ptr++;
|
||||
*array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
|
||||
}
|
||||
}
|
||||
|
||||
static rawImageRec *RawImageOpen(const char *fileName)
|
||||
{
|
||||
union {
|
||||
int testWord;
|
||||
char testByte[4];
|
||||
} endianTest;
|
||||
rawImageRec *raw;
|
||||
GLenum swapFlag;
|
||||
int x;
|
||||
size_t result;
|
||||
|
||||
endianTest.testWord = 1;
|
||||
if (endianTest.testByte[0] == 1) {
|
||||
swapFlag = GL_TRUE;
|
||||
} else {
|
||||
swapFlag = GL_FALSE;
|
||||
}
|
||||
|
||||
raw = (rawImageRec *)calloc(1, sizeof(rawImageRec));
|
||||
if (raw == NULL) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
return NULL;
|
||||
}
|
||||
raw->file = fopen(fileName, "rb");
|
||||
if (raw->file == NULL) {
|
||||
const char *baseName = strrchr(fileName, '/');
|
||||
if(baseName)
|
||||
raw->file = fopen(baseName + 1, "rb");
|
||||
if(raw->file == NULL) {
|
||||
free(raw);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
result = fread(raw, 1, 12, raw->file);
|
||||
assert(result == 12);
|
||||
|
||||
if (swapFlag) {
|
||||
ConvertShort(&raw->imagic, 1);
|
||||
ConvertShort(&raw->type, 1);
|
||||
ConvertShort(&raw->dim, 1);
|
||||
ConvertShort(&raw->sizeX, 1);
|
||||
ConvertShort(&raw->sizeY, 1);
|
||||
ConvertShort(&raw->sizeZ, 1);
|
||||
}
|
||||
|
||||
raw->tmp = (unsigned char *)malloc(raw->sizeX*256);
|
||||
raw->tmpR = (unsigned char *)malloc(raw->sizeX*256);
|
||||
raw->tmpG = (unsigned char *)malloc(raw->sizeX*256);
|
||||
raw->tmpB = (unsigned char *)malloc(raw->sizeX*256);
|
||||
if (raw->sizeZ==4) {
|
||||
raw->tmpA = (unsigned char *)malloc(raw->sizeX*256);
|
||||
}
|
||||
if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL ||
|
||||
raw->tmpB == NULL) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
free(raw->tmp);
|
||||
free(raw->tmpR);
|
||||
free(raw->tmpG);
|
||||
free(raw->tmpB);
|
||||
free(raw->tmpA);
|
||||
free(raw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((raw->type & 0xFF00) == 0x0100) {
|
||||
x = raw->sizeY * raw->sizeZ * sizeof(GLuint);
|
||||
raw->rowStart = (GLuint *)malloc(x);
|
||||
raw->rowSize = (GLint *)malloc(x);
|
||||
if (raw->rowStart == NULL || raw->rowSize == NULL) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
free(raw->tmp);
|
||||
free(raw->tmpR);
|
||||
free(raw->tmpG);
|
||||
free(raw->tmpB);
|
||||
free(raw->tmpA);
|
||||
free(raw->rowStart);
|
||||
free(raw->rowSize);
|
||||
free(raw);
|
||||
return NULL;
|
||||
}
|
||||
raw->rleEnd = 512 + (2 * x);
|
||||
fseek(raw->file, 512, SEEK_SET);
|
||||
result = fread(raw->rowStart, 1, x, raw->file);
|
||||
assert(result == x);
|
||||
result = fread(raw->rowSize, 1, x, raw->file);
|
||||
assert(result == x);
|
||||
if (swapFlag) {
|
||||
ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint)));
|
||||
ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint)));
|
||||
}
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
static void RawImageClose(rawImageRec *raw)
|
||||
{
|
||||
fclose(raw->file);
|
||||
free(raw->tmp);
|
||||
free(raw->tmpR);
|
||||
free(raw->tmpG);
|
||||
free(raw->tmpB);
|
||||
if (raw->rowStart)
|
||||
free(raw->rowStart);
|
||||
if (raw->rowSize)
|
||||
free(raw->rowSize);
|
||||
if (raw->sizeZ>3) {
|
||||
free(raw->tmpA);
|
||||
}
|
||||
free(raw);
|
||||
}
|
||||
|
||||
static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z)
|
||||
{
|
||||
unsigned char *iPtr, *oPtr, pixel;
|
||||
int count, done = 0;
|
||||
size_t result;
|
||||
|
||||
if ((raw->type & 0xFF00) == 0x0100) {
|
||||
fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET);
|
||||
result = fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY],
|
||||
raw->file);
|
||||
assert(result == (unsigned int)raw->rowSize[y+z*raw->sizeY]);
|
||||
|
||||
iPtr = raw->tmp;
|
||||
oPtr = buf;
|
||||
while (!done) {
|
||||
pixel = *iPtr++;
|
||||
count = (int)(pixel & 0x7F);
|
||||
if (!count) {
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
if (pixel & 0x80) {
|
||||
while (count--) {
|
||||
*oPtr++ = *iPtr++;
|
||||
}
|
||||
} else {
|
||||
pixel = *iPtr++;
|
||||
while (count--) {
|
||||
*oPtr++ = pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY),
|
||||
SEEK_SET);
|
||||
result = fread(buf, 1, raw->sizeX, raw->file);
|
||||
assert(result == raw->sizeX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void RawImageGetData(rawImageRec *raw, TK_RGBImageRec *final)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
int i, j;
|
||||
|
||||
final->data = (unsigned char *)malloc((raw->sizeX+1)*(raw->sizeY+1)*4);
|
||||
if (final->data == NULL) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = final->data;
|
||||
for (i = 0; i < (int)(raw->sizeY); i++) {
|
||||
RawImageGetRow(raw, raw->tmpR, i, 0);
|
||||
RawImageGetRow(raw, raw->tmpG, i, 1);
|
||||
RawImageGetRow(raw, raw->tmpB, i, 2);
|
||||
if (raw->sizeZ>3) {
|
||||
RawImageGetRow(raw, raw->tmpA, i, 3);
|
||||
}
|
||||
for (j = 0; j < (int)(raw->sizeX); j++) {
|
||||
*ptr++ = *(raw->tmpR + j);
|
||||
*ptr++ = *(raw->tmpG + j);
|
||||
*ptr++ = *(raw->tmpB + j);
|
||||
if (raw->sizeZ>3) {
|
||||
*ptr++ = *(raw->tmpA + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static TK_RGBImageRec *tkRGBImageLoad(const char *fileName)
|
||||
{
|
||||
rawImageRec *raw;
|
||||
TK_RGBImageRec *final;
|
||||
|
||||
raw = RawImageOpen(fileName);
|
||||
if (!raw) {
|
||||
fprintf(stderr, "File not found\n");
|
||||
return NULL;
|
||||
}
|
||||
final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec));
|
||||
if (final == NULL) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
RawImageClose(raw);
|
||||
return NULL;
|
||||
}
|
||||
final->sizeX = raw->sizeX;
|
||||
final->sizeY = raw->sizeY;
|
||||
final->components = raw->sizeZ;
|
||||
RawImageGetData(raw, final);
|
||||
RawImageClose(raw);
|
||||
return final;
|
||||
}
|
||||
|
||||
|
||||
static void FreeImage( TK_RGBImageRec *image )
|
||||
{
|
||||
free(image->data);
|
||||
free(image);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load an SGI .rgb file and generate a set of 2-D mipmaps from it.
|
||||
* Input: imageFile - name of .rgb to read
|
||||
* intFormat - internal texture format to use, or number of components
|
||||
* Return: GL_TRUE if success, GL_FALSE if error.
|
||||
*/
|
||||
GLboolean LoadRGBMipmaps( const char *imageFile, GLint intFormat )
|
||||
{
|
||||
GLint w, h;
|
||||
return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h );
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target,
|
||||
GLint intFormat, GLint *width, GLint *height )
|
||||
{
|
||||
GLint error;
|
||||
GLenum format;
|
||||
TK_RGBImageRec *image;
|
||||
|
||||
image = tkRGBImageLoad( imageFile );
|
||||
if (!image) {
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (image->components==3) {
|
||||
format = GL_RGB;
|
||||
}
|
||||
else if (image->components==4) {
|
||||
format = GL_RGBA;
|
||||
}
|
||||
else {
|
||||
/* not implemented */
|
||||
fprintf(stderr,
|
||||
"Error in LoadRGBMipmaps %d-component images not implemented\n",
|
||||
image->components );
|
||||
FreeImage(image);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
error = gluBuild2DMipmaps( target,
|
||||
intFormat,
|
||||
image->sizeX, image->sizeY,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
image->data );
|
||||
|
||||
*width = image->sizeX;
|
||||
*height = image->sizeY;
|
||||
|
||||
FreeImage(image);
|
||||
|
||||
return error ? GL_FALSE : GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Load an SGI .rgb file and return a pointer to the image data.
|
||||
* Input: imageFile - name of .rgb to read
|
||||
* Output: width - width of image
|
||||
* height - height of image
|
||||
* format - format of image (GL_RGB or GL_RGBA)
|
||||
* Return: pointer to image data or NULL if error
|
||||
*/
|
||||
GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height,
|
||||
GLenum *format )
|
||||
{
|
||||
TK_RGBImageRec *image;
|
||||
GLint bytes;
|
||||
GLubyte *buffer;
|
||||
|
||||
image = tkRGBImageLoad( imageFile );
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (image->components==3) {
|
||||
*format = GL_RGB;
|
||||
}
|
||||
else if (image->components==4) {
|
||||
*format = GL_RGBA;
|
||||
}
|
||||
else {
|
||||
/* not implemented */
|
||||
fprintf(stderr,
|
||||
"Error in LoadRGBImage %d-component images not implemented\n",
|
||||
image->components );
|
||||
FreeImage(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*width = image->sizeX;
|
||||
*height = image->sizeY;
|
||||
|
||||
bytes = image->sizeX * image->sizeY * image->components;
|
||||
buffer = (GLubyte *) malloc(bytes);
|
||||
if (!buffer) {
|
||||
FreeImage(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy( (void *) buffer, (void *) image->data, bytes );
|
||||
|
||||
FreeImage(image);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
|
||||
|
||||
|
||||
static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes,
|
||||
const GLubyte *src,
|
||||
GLushort *dest)
|
||||
{
|
||||
GLint i, j;
|
||||
|
||||
for (i = 0; i < h; i++) {
|
||||
for (j = 0; j < w; j++) {
|
||||
const GLfloat r = (src[0]) / 255.0;
|
||||
const GLfloat g = (src[1]) / 255.0;
|
||||
const GLfloat b = (src[2]) / 255.0;
|
||||
GLfloat y, cr, cb;
|
||||
GLint iy, icr, icb;
|
||||
|
||||
y = r * 65.481 + g * 128.553 + b * 24.966 + 16;
|
||||
cb = r * -37.797 + g * -74.203 + b * 112.0 + 128;
|
||||
cr = r * 112.0 + g * -93.786 + b * -18.214 + 128;
|
||||
/*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/
|
||||
iy = (GLint) CLAMP(y, 0, 254);
|
||||
icb = (GLint) CLAMP(cb, 0, 254);
|
||||
icr = (GLint) CLAMP(cr, 0, 254);
|
||||
|
||||
if (j & 1) {
|
||||
/* odd */
|
||||
*dest = (iy << 8) | icr;
|
||||
}
|
||||
else {
|
||||
/* even */
|
||||
*dest = (iy << 8) | icb;
|
||||
}
|
||||
dest++;
|
||||
src += texel_bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load an SGI .rgb file and return a pointer to the image data, converted
|
||||
* to 422 yuv.
|
||||
*
|
||||
* Input: imageFile - name of .rgb to read
|
||||
* Output: width - width of image
|
||||
* height - height of image
|
||||
* Return: pointer to image data or NULL if error
|
||||
*/
|
||||
GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height )
|
||||
{
|
||||
TK_RGBImageRec *image;
|
||||
GLushort *buffer;
|
||||
|
||||
image = tkRGBImageLoad( imageFile );
|
||||
if (!image) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (image->components != 3 && image->components !=4 ) {
|
||||
/* not implemented */
|
||||
fprintf(stderr,
|
||||
"Error in LoadYUVImage %d-component images not implemented\n",
|
||||
image->components );
|
||||
FreeImage(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*width = image->sizeX;
|
||||
*height = image->sizeY;
|
||||
|
||||
buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 );
|
||||
|
||||
if (buffer)
|
||||
ConvertRGBtoYUV( image->sizeX,
|
||||
image->sizeY,
|
||||
image->components,
|
||||
image->data,
|
||||
buffer );
|
||||
|
||||
|
||||
FreeImage(image);
|
||||
return buffer;
|
||||
}
|
||||
|
26
contrib/sdk/samples/Mesa/readtex.h
Normal file
26
contrib/sdk/samples/Mesa/readtex.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* readtex.h */
|
||||
|
||||
#ifndef READTEX_H
|
||||
#define READTEX_H
|
||||
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
||||
extern GLboolean
|
||||
LoadRGBMipmaps( const char *imageFile, GLint intFormat );
|
||||
|
||||
|
||||
extern GLboolean
|
||||
LoadRGBMipmaps2( const char *imageFile, GLenum target,
|
||||
GLint intFormat, GLint *width, GLint *height );
|
||||
|
||||
|
||||
extern GLubyte *
|
||||
LoadRGBImage( const char *imageFile,
|
||||
GLint *width, GLint *height, GLenum *format );
|
||||
|
||||
extern GLushort *
|
||||
LoadYUVImage( const char *imageFile, GLint *width, GLint *height );
|
||||
|
||||
#endif
|
BIN
contrib/sdk/samples/Mesa/reflect.rgb
Normal file
BIN
contrib/sdk/samples/Mesa/reflect.rgb
Normal file
Binary file not shown.
63
contrib/sdk/samples/Mesa/shaderutil.h
Normal file
63
contrib/sdk/samples/Mesa/shaderutil.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef SHADER_UTIL_H
|
||||
#define SHADER_UTIL_H
|
||||
|
||||
|
||||
|
||||
struct uniform_info
|
||||
{
|
||||
const char *name;
|
||||
GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */
|
||||
GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */
|
||||
GLfloat value[4];
|
||||
GLint location; /**< filled in by InitUniforms() */
|
||||
};
|
||||
|
||||
#define END_OF_UNIFORMS { NULL, 0, GL_NONE, { 0, 0, 0, 0 }, -1 }
|
||||
|
||||
|
||||
struct attrib_info
|
||||
{
|
||||
const char *name;
|
||||
GLuint size; /**< number of value[] elements: 1, 2, 3 or 4 */
|
||||
GLenum type; /**< GL_FLOAT, GL_FLOAT_VEC4, GL_INT, etc */
|
||||
GLint location;
|
||||
};
|
||||
|
||||
|
||||
extern GLboolean
|
||||
ShadersSupported(void);
|
||||
|
||||
extern GLuint
|
||||
CompileShaderText(GLenum shaderType, const char *text);
|
||||
|
||||
extern GLuint
|
||||
CompileShaderFile(GLenum shaderType, const char *filename);
|
||||
|
||||
extern GLuint
|
||||
LinkShaders(GLuint vertShader, GLuint fragShader);
|
||||
|
||||
extern GLboolean
|
||||
ValidateShaderProgram(GLuint program);
|
||||
|
||||
extern GLdouble
|
||||
GetShaderCompileTime(void);
|
||||
|
||||
extern GLdouble
|
||||
GetShaderLinkTime(void);
|
||||
|
||||
extern void
|
||||
SetUniformValues(GLuint program, struct uniform_info uniforms[]);
|
||||
|
||||
extern GLuint
|
||||
GetUniforms(GLuint program, struct uniform_info uniforms[]);
|
||||
|
||||
extern void
|
||||
PrintUniforms(const struct uniform_info uniforms[]);
|
||||
|
||||
extern GLuint
|
||||
GetAttribs(GLuint program, struct attrib_info attribs[]);
|
||||
|
||||
extern void
|
||||
PrintAttribs(const struct attrib_info attribs[]);
|
||||
|
||||
#endif /* SHADER_UTIL_H */
|
Reference in New Issue
Block a user