diff options
author | Younes Manton <[email protected]> | 2010-03-07 12:47:45 -0500 |
---|---|---|
committer | Younes Manton <[email protected]> | 2010-03-12 01:37:49 -0500 |
commit | a8238bb08a95e7ea4430450c304a6bee210df1a6 (patch) | |
tree | 00f4e852473dc1d6a86aece436f3e5bf89d029c7 /progs/redbook | |
parent | 80468464897682b8e10aeab310f20fdd7ddc6cb4 (diff) | |
parent | 45df4bad9fc0379f05197bee10c03fd351f24094 (diff) |
Merge remote branch 'origin/master' into pipe-video
Conflicts:
configure.ac
src/gallium/auxiliary/vl/Makefile
src/gallium/auxiliary/vl/SConscript
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/auxiliary/vl/vl_compositor.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/drivers/nouveau/nouveau_winsys.h
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/include/pipe/p_video_state.h
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/xorg/xvmc/surface.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/g3dvl/nouveau/Makefile
Diffstat (limited to 'progs/redbook')
79 files changed, 3245 insertions, 330 deletions
diff --git a/progs/redbook/Makefile b/progs/redbook/Makefile index 0ba5fbbb986..b41e488729b 100644 --- a/progs/redbook/Makefile +++ b/progs/redbook/Makefile @@ -7,16 +7,84 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) - -PROGS = aaindex aapoly aargb accanti accpersp alpha alpha3D anti \ - bezcurve bezmesh checker clip colormat cube depthcue dof \ - double drawf feedback fog fogindex font hello image light \ - lines list material mipmap model movelight nurbs pickdepth \ - picksquare plane planet polyoff polys quadric robot sccolorlight \ - scene scenebamb sceneflat select smooth stencil stroke surface \ - teaambient teapots tess tesswind texbind texgen texprox texsub \ - texturesurf torus trim unproject varray wrap +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) + +PROGS = aaindex \ + aapoly \ + aargb \ + accanti \ + accpersp \ + alpha \ + alpha3D \ + anti \ + bezcurve \ + bezmesh \ + checker \ + clip \ + colormat \ + combiner \ + convolution \ + cube \ + cubemap \ + depthcue \ + dof \ + double \ + drawf \ + feedback \ + fog \ + fogcoord \ + fogindex \ + font \ + hello \ + histogram \ + image \ + light \ + lines \ + list \ + material \ + minmax \ + mipmap \ + model \ + movelight \ + multitex \ + multisamp \ + mvarray \ + nurbs \ + pickdepth \ + picksquare \ + plane \ + planet \ + pointp \ + polyoff \ + polys \ + quadric \ + robot \ + sccolorlight \ + scene \ + scenebamb \ + sceneflat \ + select \ + shadowmap \ + smooth \ + stencil \ + stroke \ + surface \ + surfpoints \ + teaambient \ + teapots \ + tess \ + tesswind \ + texbind \ + texgen \ + texprox \ + texsub \ + texturesurf \ + texture3d \ + torus \ + trim \ + unproject \ + varray \ + wrap diff --git a/progs/redbook/SConscript b/progs/redbook/SConscript index 242cb6647fc..750ad36fe01 100644 --- a/progs/redbook/SConscript +++ b/progs/redbook/SConscript @@ -1,23 +1,5 @@ Import('*') -if not env['GLUT']: - Return() - -env = env.Clone() - -env.Prepend(CPPPATH = [ - '../util', -]) - -env.Prepend(LIBS = [ - util, - '$GLUT_LIB' -]) - -if env['platform'] == 'windows': - env.Append(CPPDEFINES = ['NOMINMAX']) - env.Prepend(LIBS = ['winmm']) - progs = [ 'aaindex', 'aapoly', @@ -32,29 +14,39 @@ progs = [ 'checker', 'clip', 'colormat', + 'combiner', + 'convolution', 'cube', + 'cubemap', 'depthcue', 'dof', 'double', 'drawf', 'feedback', 'fog', + 'fogcoord', 'fogindex', 'font', 'hello', + 'histogram', 'image', 'light', 'lines', 'list', 'material', + 'minmax', 'mipmap', 'model', 'movelight', + 'multisamp', + 'multitex', + 'mvarray', 'nurbs', 'pickdepth', 'picksquare', 'plane', 'planet', + 'pointp', 'polyoff', 'polys', 'quadric', @@ -64,10 +56,12 @@ progs = [ 'scene', 'sceneflat', 'select', + 'shadowmap', 'smooth', 'stencil', 'stroke', 'surface', + 'surfpoints', 'teaambient', 'teapots', 'tess', @@ -77,6 +71,7 @@ progs = [ 'texprox', 'texsub', 'texturesurf', + 'texture3d', 'torus', 'trim', 'unproject', @@ -85,7 +80,7 @@ progs = [ ] for prog in progs: - env.Program( + progs_env.Program( target = prog, source = prog + '.c', ) diff --git a/progs/redbook/aaindex.c b/progs/redbook/aaindex.c index 7dbc7b4b9b2..6011ec44b67 100644 --- a/progs/redbook/aaindex.c +++ b/progs/redbook/aaindex.c @@ -56,7 +56,7 @@ static float rotAngle = 0.; * at RAMP1START, and a blue color ramp starting * at RAMP2START. The ramps must be a multiple of 16. */ -void init(void) +static void init(void) { int i; @@ -76,7 +76,7 @@ void init(void) /* Draw 2 diagonal lines to form an X */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); @@ -101,7 +101,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -117,7 +117,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'r': diff --git a/progs/redbook/aapoly.c b/progs/redbook/aapoly.c index 757f0f48c43..64d06b7b3da 100644 --- a/progs/redbook/aapoly.c +++ b/progs/redbook/aapoly.c @@ -45,7 +45,6 @@ #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> -#include <string.h> GLboolean polySmooth = GL_TRUE; @@ -59,7 +58,7 @@ static void init(void) #define NFACE 6 #define NVERT 8 -void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1, +static void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1, GLdouble z0, GLdouble z1) { static GLfloat v[8][3]; @@ -101,7 +100,7 @@ void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1, /* Note: polygons must be drawn from front to back * for proper blending. */ -void display(void) +static void display(void) { if (polySmooth) { glClear (GL_COLOR_BUFFER_BIT); @@ -126,7 +125,7 @@ void display(void) glFlush (); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -137,7 +136,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 't': diff --git a/progs/redbook/aargb.c b/progs/redbook/aargb.c index f51984170e6..0021b549c2e 100644 --- a/progs/redbook/aargb.c +++ b/progs/redbook/aargb.c @@ -51,7 +51,7 @@ static float rotAngle = 0.; * blending, hint, and line width. Print out implementation * specific info on line width granularity and width. */ -void init(void) +static void init(void) { GLfloat values[2]; glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); @@ -72,7 +72,7 @@ void init(void) /* Draw 2 diagonal lines to form an X */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); @@ -97,7 +97,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); @@ -113,7 +113,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'r': diff --git a/progs/redbook/accanti.c b/progs/redbook/accanti.c index 12ca16f7a52..d1b25678419 100644 --- a/progs/redbook/accanti.c +++ b/progs/redbook/accanti.c @@ -45,7 +45,7 @@ /* Initialize lighting and other values. */ -void myinit(void) +static void myinit(void) { GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -68,7 +68,7 @@ void myinit(void) glClearAccum(0.0, 0.0, 0.0, 0.0); } -void displayObjects(void) +static void displayObjects(void) { GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 }; @@ -111,7 +111,7 @@ void displayObjects(void) #define ACSIZE 8 -void display(void) +static void display(void) { GLint viewport[4]; int jitter; @@ -137,7 +137,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/accpersp.c b/progs/redbook/accpersp.c index 46e369ae631..e172d0a917f 100644 --- a/progs/redbook/accpersp.c +++ b/progs/redbook/accpersp.c @@ -62,7 +62,7 @@ * probably want to insure that your ModelView matrix has been * initialized to identity before calling accFrustum(). */ -void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, +static void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) { @@ -99,7 +99,7 @@ void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, * * Note that accPerspective() calls accFrustum(). */ -void accPerspective(GLdouble fovy, GLdouble aspect, +static void accPerspective(GLdouble fovy, GLdouble aspect, GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) { @@ -119,7 +119,7 @@ void accPerspective(GLdouble fovy, GLdouble aspect, /* Initialize lighting and other values. */ -void init(void) +static void init(void) { GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -141,7 +141,7 @@ void init(void) glClearAccum(0.0, 0.0, 0.0, 0.0); } -void displayObjects(void) +static void displayObjects(void) { GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 }; @@ -185,7 +185,7 @@ void displayObjects(void) #define ACSIZE 8 -void display(void) +static void display(void) { GLint viewport[4]; int jitter; @@ -205,13 +205,13 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/alpha.c b/progs/redbook/alpha.c index 6eeb45b96f1..b77c65e2c83 100644 --- a/progs/redbook/alpha.c +++ b/progs/redbook/alpha.c @@ -80,7 +80,7 @@ static void drawRightTriangle(void) glEnd(); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); @@ -96,7 +96,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -108,7 +108,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 't': diff --git a/progs/redbook/alpha3D.c b/progs/redbook/alpha3D.c index 6169bd162be..494b1879d22 100644 --- a/progs/redbook/alpha3D.c +++ b/progs/redbook/alpha3D.c @@ -80,7 +80,7 @@ static void init(void) glEndList(); } -void display(void) +static void display(void) { GLfloat mat_solid[] = { 0.75, 0.75, 0.0, 1.0 }; GLfloat mat_zero[] = { 0.0, 0.0, 0.0, 1.0 }; @@ -113,7 +113,7 @@ void display(void) glutSwapBuffers(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLint) w, (GLint) h); glMatrixMode(GL_PROJECTION); @@ -128,7 +128,7 @@ void reshape(int w, int h) glLoadIdentity(); } -void animate(void) +static void animate(void) { static double t0 = -1.; if (solidZ <= MINZ || transparentZ >= MAXZ) @@ -150,7 +150,7 @@ void animate(void) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'a': diff --git a/progs/redbook/anti.c b/progs/redbook/anti.c index 9eab0bc3511..a97a3ebc948 100644 --- a/progs/redbook/anti.c +++ b/progs/redbook/anti.c @@ -49,7 +49,7 @@ * blending, hint, and line width. Print out implementation * specific info on line width granularity and width. */ -void myinit(void) +static void myinit(void) { GLfloat values[2]; glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); @@ -73,7 +73,7 @@ void myinit(void) /* display() draws an icosahedron with a large alpha value, 1.0. */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor4f (1.0, 1.0, 1.0, 1.0); @@ -81,7 +81,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/bezcurve.c b/progs/redbook/bezcurve.c index 5dee440396b..60a9c680802 100644 --- a/progs/redbook/bezcurve.c +++ b/progs/redbook/bezcurve.c @@ -45,7 +45,7 @@ GLfloat ctrlpoints[4][3] = { { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}}; -void init(void) +static void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -53,7 +53,7 @@ void init(void) glEnable(GL_MAP1_VERTEX_3); } -void display(void) +static void display(void) { int i; @@ -73,7 +73,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -89,7 +89,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/bezmesh.c b/progs/redbook/bezmesh.c index 55e7e827f2b..1abc7488bcb 100644 --- a/progs/redbook/bezmesh.c +++ b/progs/redbook/bezmesh.c @@ -68,7 +68,7 @@ GLfloat ctrlpoints[4][4][3] = {1.5, 1.5, -1.0}} }; -void +static void initlights(void) { GLfloat ambient[] = @@ -93,7 +93,7 @@ initlights(void) glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); } -void +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -104,7 +104,7 @@ display(void) glFlush(); } -void +static void myinit(void) { glClearColor(0.0, 0.0, 0.0, 1.0); @@ -118,7 +118,7 @@ myinit(void) initlights(); /* for lighted version only */ } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/checker.c b/progs/redbook/checker.c index 06cbae7dd7e..60e6f7b60c8 100644 --- a/progs/redbook/checker.c +++ b/progs/redbook/checker.c @@ -50,7 +50,7 @@ #define checkImageHeight 64 GLubyte checkImage[checkImageWidth][checkImageHeight][3]; -void makeCheckImage(void) +static void makeCheckImage(void) { int i, j, c; @@ -64,7 +64,7 @@ void makeCheckImage(void) } } -void myinit(void) +static void myinit(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); @@ -84,7 +84,7 @@ void myinit(void) glShadeModel(GL_FLAT); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); @@ -101,7 +101,7 @@ void display(void) glutSwapBuffers(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/clip.c b/progs/redbook/clip.c index 90816f2e278..85c464720db 100644 --- a/progs/redbook/clip.c +++ b/progs/redbook/clip.c @@ -42,13 +42,13 @@ #include <GL/glut.h> #include <stdlib.h> -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0}; GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0}; @@ -73,7 +73,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -83,7 +83,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/colormat.c b/progs/redbook/colormat.c index 9db4491bac5..d77fcb1ed46 100644 --- a/progs/redbook/colormat.c +++ b/progs/redbook/colormat.c @@ -49,7 +49,7 @@ GLfloat diffuseMaterial[4] = { 0.5, 0.5, 0.5, 1.0 }; /* Initialize material property, light source, lighting model, * and depth buffer. */ -void init(void) +static void init(void) { GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; @@ -68,14 +68,14 @@ void init(void) glEnable(GL_COLOR_MATERIAL); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere(1.0, 20, 16); glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -91,7 +91,7 @@ void reshape (int w, int h) } /* ARGSUSED2 */ -void mouse(int button, int state, int x, int y) +static void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: @@ -127,7 +127,7 @@ void mouse(int button, int state, int x, int y) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/combiner.c b/progs/redbook/combiner.c new file mode 100644 index 00000000000..7682e0c0324 --- /dev/null +++ b/progs/redbook/combiner.c @@ -0,0 +1,379 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* combiner.c + * This program renders a variety of quads showing different + * effects of texture combiner functions. + * + * The first row renders an untextured polygon (so you can + * compare the fragment colors) and then the 2 textures. + * The second row shows several different combiner functions + * on a single texture: replace, modulate, add, add-signed, + * and subtract. + * The third row shows the interpolate combiner function + * on a single texture with a constant color/alpha value, + * varying the amount of interpolation. + * The fourth row uses multitexturing with two textures + * and different combiner functions. + * The fifth row are some combiner experiments: using the + * scaling factor and reversing the order of subtraction + * for a combination function. + */ +#include <GL/glew.h> +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#define imageWidth 8 +#define imageHeight 8 +/* arrays for two textures */ +static GLubyte image0[imageHeight][imageWidth][4]; +static GLubyte image1[imageHeight][imageWidth][4]; + +static GLuint texName[4]; + +static void makeImages(void) +{ + int i, j, c; + for (i = 0; i < imageHeight; i++) { + for (j = 0; j < imageWidth; j++) { + c = ((i&2)==0)*255; /* horiz b & w stripes */ + image0[i][j][0] = (GLubyte) c; + image0[i][j][1] = (GLubyte) c; + image0[i][j][2] = (GLubyte) c; + image0[i][j][3] = (GLubyte) 255; + c = ((j&4)!=0)*128; /* wider vertical 50% cyan and black stripes */ + image1[i][j][0] = (GLubyte) 0; + image1[i][j][1] = (GLubyte) c; + image1[i][j][2] = (GLubyte) c; + image1[i][j][3] = (GLubyte) 255; + } + } +} + +static void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_SMOOTH); + + makeImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glGenTextures(4, texName); + + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, image0); + + glBindTexture(GL_TEXTURE_2D, texName[1]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, image1); + +/* smooth-shaded polygon with multiple texture coordinates */ + glNewList (1, GL_COMPILE); + glBegin(GL_QUADS); + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0); + glColor3f (0.5, 1.0, 0.25); + glVertex3f(0.0, 0.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 2.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 2.0); + glColor3f (1.0, 1.0, 1.0); + glVertex3f(0.0, 1.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 2.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 2.0, 2.0); + glColor3f (1.0, 1.0, 1.0); + glVertex3f(1.0, 1.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 2.0, 0.0); + glColor3f (1.0, 0.5, 0.25); + glVertex3f(1.0, 0.0, 0.0); + glEnd(); + glEndList (); +} + +static void display(void) +{ + static GLfloat constColor[4] = {0.0, 0.0, 0.0, 0.0}; /* for use as constant texture color */ + + glClear(GL_COLOR_BUFFER_BIT); + + glDisable(GL_TEXTURE_2D); /* untextured polygon--see the "fragment" colors */ + glPushMatrix(); + glTranslatef(0.0, 5.0, 0.0); + glCallList(1); + glPopMatrix(); + + glEnable(GL_TEXTURE_2D); +/* draw ordinary textured polys; 1 texture unit; combine mode disabled */ + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glPushMatrix(); + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTranslatef(1.0, 5.0, 0.0); + glCallList(1); + glPopMatrix(); + + glPushMatrix(); + glBindTexture(GL_TEXTURE_2D, texName[1]); + glTranslatef(2.0, 5.0, 0.0); + glCallList(1); + glPopMatrix(); + +/* different combine modes enabled; 1 texture unit + * defaults are: + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + */ + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + glPushMatrix(); + glTranslatef(1.0, 4.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + glPushMatrix(); + glTranslatef(2.0, 4.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD); + glPushMatrix(); + glTranslatef(3.0, 4.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB); + glPushMatrix(); + glTranslatef(4.0, 4.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_SUBTRACT_ARB); + glPushMatrix(); + glTranslatef(5.0, 4.0, 0.0); + glCallList(1); + glPopMatrix(); + +/* interpolate combine with constant color; 1 texture unit + * use different alpha values for constant color + * defaults are: + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA); + */ + constColor[3] = 0.2; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor); + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA); + glPushMatrix(); + glTranslatef(1.0, 3.0, 0.0); + glCallList(1); + glPopMatrix(); + + constColor[3] = 0.4; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor); + glPushMatrix(); + glTranslatef(2.0, 3.0, 0.0); + glCallList(1); + glPopMatrix(); + + constColor[3] = 0.6; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor); + glPushMatrix(); + glTranslatef(3.0, 3.0, 0.0); + glCallList(1); + glPopMatrix(); + + constColor[3] = 0.8; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor); + glPushMatrix(); + glTranslatef(4.0, 3.0, 0.0); + glCallList(1); + glPopMatrix(); + +/* combine textures 0 & 1 + * defaults are: + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + * glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); + * glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + */ + + glActiveTextureARB (GL_TEXTURE0_ARB); + glEnable (GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glActiveTextureARB (GL_TEXTURE1_ARB); + glEnable (GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texName[1]); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); + glPushMatrix(); + glTranslatef(1.0, 2.0, 0.0); + glCallList(1); + glPopMatrix(); + + /* try different combiner modes of texture unit 1 */ + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glPushMatrix(); + glTranslatef(2.0, 2.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD); + glPushMatrix(); + glTranslatef(3.0, 2.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB); + glPushMatrix(); + glTranslatef(4.0, 2.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_SUBTRACT_ARB); + glPushMatrix(); + glTranslatef(5.0, 2.0, 0.0); + glCallList(1); + glPopMatrix(); + +/* some experiments */ + +/* see the effect of RGB_SCALE */ + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); + glPushMatrix(); + glTranslatef(1.0, 1.0, 0.0); + glCallList(1); + glPopMatrix(); + + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); + glPushMatrix(); + glTranslatef(2.0, 1.0, 0.0); + glCallList(1); + glPopMatrix(); + glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0); + +/* using SOURCE0 and SOURCE1, reverse the order of subtraction Arg1-Arg0 */ + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_SUBTRACT_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); + glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); + glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); + glPushMatrix(); + glTranslatef(5.0, 1.0, 0.0); + glCallList(1); + glPopMatrix(); + + glActiveTextureARB (GL_TEXTURE1_ARB); /* deactivate multitexturing */ + glDisable (GL_TEXTURE_2D); + glActiveTextureARB (GL_TEXTURE0_ARB); /* activate single texture unit */ + + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.0, 7.0, 0.0, 7.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(400, 400); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/convolution.c b/progs/redbook/convolution.c new file mode 100644 index 00000000000..c04a8727a71 --- /dev/null +++ b/progs/redbook/convolution.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * convolution.c + * Use various 2D convolutions filters to find edges in an image. + * + */ +#include <GL/glew.h> +#include <GL/glut.h> +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + + +static GLuint bswap(GLuint x) +{ + const GLuint ui = 1; + const GLubyte *ubp = (const GLubyte *) &ui; + if (*ubp == 1) { + /* we're on little endiang so byteswap x */ + GLsizei y = ((x >> 24) + | ((x >> 8) & 0xff00) + | ((x << 8) & 0xff0000) + | ((x << 24) & 0xff000000)); + return y; + } + else { + return x; + } +} + + +static GLubyte * +readImage( const char* filename, GLsizei* width, GLsizei *height ) +{ + int n; + GLubyte* pixels; + size_t num_read; + + FILE* infile = fopen( filename, "rb" ); + + if ( !infile ) { + fprintf( stderr, "Unable to open file '%s'\n", filename ); + exit(1); + } + + num_read = fread( width, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + num_read = fread( height, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + + *width = bswap(*width); + *height = bswap(*height); + + assert(*width > 0); + assert(*height > 0); + + n = 3 * (*width) * (*height); + + pixels = (GLubyte *) malloc( n * sizeof( GLubyte )); + if ( !pixels ) { + fprintf( stderr, "Unable to malloc() bytes for pixels\n" ); + fclose( infile ); + return NULL; + } + + num_read = fread( pixels, sizeof( GLubyte ), n, infile ); + assert(num_read == n); + + fclose( infile ); + + return pixels; +} + + +GLubyte *pixels; +GLsizei width, height; + +GLfloat horizontal[3][3] = { + { 0, -1, 0 }, + { 0, 1, 0 }, + { 0, 0, 0 } +}; + +GLfloat vertical[3][3] = { + { 0, 0, 0 }, + { -1, 1, 0 }, + { 0, 0, 0 } +}; + +GLfloat laplacian[3][3] = { + { -0.125, -0.125, -0.125 }, + { -0.125, 1.0 , -0.125 }, + { -0.125, -0.125, -0.125 }, +}; + + +static void init(void) +{ + if (!glutExtensionSupported("GL_ARB_imaging")) { + fprintf(stderr, "Sorry, this program requires GL_ARB_imaging.\n"); + exit(1); + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glClearColor(0.0, 0.0, 0.0, 0.0); + + printf("Using the horizontal filter\n"); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, + 3, 3, GL_LUMINANCE, GL_FLOAT, horizontal); + glEnable(GL_CONVOLUTION_2D); +} + +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glRasterPos2i( 1, 1); + glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, w, 0, h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'h' : + printf("Using a horizontal filter\n"); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, 3, 3, + GL_LUMINANCE, GL_FLOAT, horizontal); + break; + + case 'v' : + printf("Using the vertical filter\n"); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, 3, 3, + GL_LUMINANCE, GL_FLOAT, vertical); + break; + + case 'l' : + printf("Using the laplacian filter\n"); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, 3, 3, + GL_LUMINANCE, GL_FLOAT, laplacian); + break; + + case 27: + exit(0); + } + glutPostRedisplay(); +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + pixels = readImage("leeds.bin", &width, &height); + + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); + glutInitWindowSize(width, height); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/cube.c b/progs/redbook/cube.c index 5ecc6280f33..3c6becb2157 100644 --- a/progs/redbook/cube.c +++ b/progs/redbook/cube.c @@ -44,13 +44,13 @@ #include <GL/glut.h> #include <stdlib.h> -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -62,7 +62,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -72,7 +72,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/cubemap.c b/progs/redbook/cubemap.c new file mode 100644 index 00000000000..92026c70897 --- /dev/null +++ b/progs/redbook/cubemap.c @@ -0,0 +1,205 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* cubemap.c + * + * This program demonstrates cube map textures. + * Six different colored checker board textures are + * created and applied to a lit sphere. + * + * Pressing the 'f' and 'b' keys translate the viewer + * forward and backward. + */ + +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#define imageSize 4 +static GLubyte image1[imageSize][imageSize][4]; +static GLubyte image2[imageSize][imageSize][4]; +static GLubyte image3[imageSize][imageSize][4]; +static GLubyte image4[imageSize][imageSize][4]; +static GLubyte image5[imageSize][imageSize][4]; +static GLubyte image6[imageSize][imageSize][4]; + +static GLdouble ztrans = 0.0; + +static void makeImages(void) +{ + int i, j, c; + + for (i = 0; i < imageSize; i++) { + for (j = 0; j < imageSize; j++) { + c = ( ((i & 0x1) == 0) ^ ((j & 0x1) == 0) ) * 255; + image1[i][j][0] = (GLubyte) c; + image1[i][j][1] = (GLubyte) c; + image1[i][j][2] = (GLubyte) c; + image1[i][j][3] = (GLubyte) 255; + + image2[i][j][0] = (GLubyte) c; + image2[i][j][1] = (GLubyte) c; + image2[i][j][2] = (GLubyte) 0; + image2[i][j][3] = (GLubyte) 255; + + image3[i][j][0] = (GLubyte) c; + image3[i][j][1] = (GLubyte) 0; + image3[i][j][2] = (GLubyte) c; + image3[i][j][3] = (GLubyte) 255; + + image4[i][j][0] = (GLubyte) 0; + image4[i][j][1] = (GLubyte) c; + image4[i][j][2] = (GLubyte) c; + image4[i][j][3] = (GLubyte) 255; + + image5[i][j][0] = (GLubyte) 255; + image5[i][j][1] = (GLubyte) c; + image5[i][j][2] = (GLubyte) c; + image5[i][j][3] = (GLubyte) 255; + + image6[i][j][0] = (GLubyte) c; + image6[i][j][1] = (GLubyte) c; + image6[i][j][2] = (GLubyte) 255; + image6[i][j][3] = (GLubyte) 255; + } + } +} + +static void init(void) +{ + GLfloat diffuse[4] = {1.0, 1.0, 1.0, 1.0}; + + glClearColor (0.0, 0.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + + makeImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_R, GL_REPEAT); + glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image1); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image4); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image5); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image3); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, 0, GL_RGBA, imageSize, + imageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image6); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT); + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glEnable(GL_TEXTURE_CUBE_MAP_EXT); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse); +} + +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glTranslatef (0.0, 0.0, ztrans); + glutSolidSphere (5.0, 20, 10); + glPopMatrix (); + glutSwapBuffers(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 300.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -20.0); +} + +static void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 'f': + ztrans = ztrans - 0.2; + glutPostRedisplay(); + break; + case 'b': + ztrans = ztrans + 0.2; + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(400, 400); + glutInitWindowPosition(100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/depthcue.c b/progs/redbook/depthcue.c index a3e5b743aa7..d4b604baf13 100644 --- a/progs/redbook/depthcue.c +++ b/progs/redbook/depthcue.c @@ -48,7 +48,7 @@ /* Initialize linear fog for depth cueing. */ -void myinit(void) +static void myinit(void) { GLfloat fogColor[4] = {0.0, 0.0, 0.0, 1.0}; @@ -67,7 +67,7 @@ void myinit(void) /* display() draws an icosahedron. */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -75,7 +75,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/dof.c b/progs/redbook/dof.c index 6673dc2d54f..8558f02deea 100644 --- a/progs/redbook/dof.c +++ b/progs/redbook/dof.c @@ -68,7 +68,7 @@ * probably want to insure that your ModelView matrix has been * initialized to identity before calling accFrustum(). */ -void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, +static void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) { @@ -105,7 +105,7 @@ void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, * * Note that accPerspective() calls accFrustum(). */ -void accPerspective(GLdouble fovy, GLdouble aspect, +static void accPerspective(GLdouble fovy, GLdouble aspect, GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) { @@ -123,7 +123,7 @@ void accPerspective(GLdouble fovy, GLdouble aspect, pixdx, pixdy, eyedx, eyedy, focus); } -void myinit(void) +static void myinit(void) { GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -155,7 +155,7 @@ void myinit(void) glClearAccum(0.0, 0.0, 0.0, 0.0); } -void renderTeapot (GLfloat x, GLfloat y, GLfloat z, +static void renderTeapot (GLfloat x, GLfloat y, GLfloat z, GLfloat ambr, GLfloat ambg, GLfloat ambb, GLfloat difr, GLfloat difg, GLfloat difb, GLfloat specr, GLfloat specg, GLfloat specb, GLfloat shine) @@ -182,7 +182,7 @@ void renderTeapot (GLfloat x, GLfloat y, GLfloat z, * magnitude of the accPerspective() jitter; in this example, 0.33. * In this example, the teapots are drawn 8 times. See jitter.h */ -void display(void) +static void display(void) { int jitter; GLint viewport[4]; @@ -214,7 +214,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); } diff --git a/progs/redbook/double.c b/progs/redbook/double.c index 3153c70cc1d..c4ead224dc8 100644 --- a/progs/redbook/double.c +++ b/progs/redbook/double.c @@ -47,7 +47,7 @@ static GLfloat spin = 0.0; static GLdouble t0 = 0.; -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); @@ -59,12 +59,12 @@ void display(void) glutSwapBuffers(); } -GLdouble gettime(void) +static GLdouble gettime(void) { return (GLdouble)(glutGet(GLUT_ELAPSED_TIME)) / 1000.; } -void spinDisplay(void) +static void spinDisplay(void) { GLdouble t, dt; t = gettime(); @@ -76,13 +76,13 @@ void spinDisplay(void) glutPostRedisplay(); } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -93,7 +93,7 @@ void reshape(int w, int h) } /* ARGSUSED2 */ -void mouse(int button, int state, int x, int y) +static void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: diff --git a/progs/redbook/drawf.c b/progs/redbook/drawf.c index 5bcccb6aeac..6c048be7844 100644 --- a/progs/redbook/drawf.c +++ b/progs/redbook/drawf.c @@ -48,13 +48,13 @@ GLubyte rasters[24] = { 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0}; -void init(void) +static void init(void) { glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glClearColor (0.0, 0.0, 0.0, 0.0); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -65,7 +65,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -75,7 +75,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/feedback.c b/progs/redbook/feedback.c index cc685d55d34..3c8c8cc7eaf 100644 --- a/progs/redbook/feedback.c +++ b/progs/redbook/feedback.c @@ -48,7 +48,7 @@ /* Initialize lighting. */ -void init(void) +static void init(void) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); @@ -58,7 +58,7 @@ void init(void) * be clipped. If in feedback mode, a passthrough token * is issued between the each primitive. */ -void drawGeometry (GLenum mode) +static void drawGeometry (GLenum mode) { glBegin (GL_LINE_STRIP); glNormal3f (0.0, 0.0, 1.0); @@ -80,8 +80,8 @@ void drawGeometry (GLenum mode) } /* Write contents of one vertex to stdout. */ -void print3DcolorVertex (GLint size, GLint *count, - GLfloat *buffer) +static void print3DcolorVertex (GLint size, GLint *count, + GLfloat *buffer) { int i; @@ -94,7 +94,7 @@ void print3DcolorVertex (GLint size, GLint *count, } /* Write contents of entire buffer. (Parse tokens!) */ -void printBuffer(GLint size, GLfloat *buffer) +static void printBuffer(GLint size, GLfloat *buffer) { GLint count; GLfloat token; @@ -124,7 +124,7 @@ void printBuffer(GLint size, GLfloat *buffer) } } -void display(void) +static void display(void) { GLfloat feedBuffer[1024]; GLint size; @@ -148,7 +148,7 @@ void display(void) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/fog.c b/progs/redbook/fog.c index 14c7700eccf..4f4b8e3cc0a 100644 --- a/progs/redbook/fog.c +++ b/progs/redbook/fog.c @@ -52,7 +52,7 @@ GLint fogMode; -void +static void selectFog(int mode) { switch(mode) { @@ -73,7 +73,7 @@ selectFog(int mode) /* Initialize z-buffer, projection matrix, light source, * and lighting model. Do not specify a material property here. */ -void +static void myinit(void) { GLfloat position[] = @@ -106,7 +106,7 @@ myinit(void) } } -void +static void renderRedTeapot(GLfloat x, GLfloat y, GLfloat z) { float mat[4]; @@ -133,7 +133,7 @@ renderRedTeapot(GLfloat x, GLfloat y, GLfloat z) /* display() draws 5 teapots at different z positions. */ -void +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -145,7 +145,7 @@ display(void) glFlush(); } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/fogcoord.c b/progs/redbook/fogcoord.c new file mode 100644 index 00000000000..17ef7ae5f3a --- /dev/null +++ b/progs/redbook/fogcoord.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * fogcoord.c + * + * This program demonstrates the use of explicit fog + * coordinates. You can press the keyboard and change + * the fog coordinate value at any vertex. You can + * also switch between using explicit fog coordinates + * and the default fog generation mode. + * + * Pressing the 'f' and 'b' keys move the viewer forward + * and backwards. + * Pressing 'c' initiates the default fog generation. + * Pressing capital 'C' restores explicit fog coordinates. + * Pressing '1', '2', '3', '8', '9', and '0' add or + * subtract from the fog coordinate values at one of the + * three vertices of the triangle. + */ + +#include <GL/glew.h> +#include <GL/glut.h> +#include <math.h> +#include <stdlib.h> +#include <stdio.h> + +static GLfloat f1, f2, f3; + +/* Initialize fog + */ +static void init(void) +{ + GLfloat fogColor[4] = {0.0, 0.25, 0.25, 1.0}; + f1 = 1.0f; + f2 = 5.0f; + f3 = 10.0f; + + glEnable(GL_FOG); + glFogi (GL_FOG_MODE, GL_EXP); + glFogfv (GL_FOG_COLOR, fogColor); + glFogf (GL_FOG_DENSITY, 0.25); + glHint (GL_FOG_HINT, GL_DONT_CARE); + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + glClearColor(0.0, 0.25, 0.25, 1.0); /* fog color */ +} + +/* display() draws a triangle at an angle. + */ +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f (1.0f, 0.75f, 0.0f); + glBegin (GL_TRIANGLES); + glFogCoordfEXT (f1); + glVertex3f (2.0f, -2.0f, 0.0f); + glFogCoordfEXT (f2); + glVertex3f (-2.0f, 0.0f, -5.0f); + glFogCoordfEXT (f3); + glVertex3f (0.0f, 2.0f, -10.0f); + glEnd(); + + glutSwapBuffers(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, 1.0, 0.25, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity (); + glTranslatef (0.0, 0.0, -5.0); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'c': + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); + glutPostRedisplay(); + break; + case 'C': + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + glutPostRedisplay(); + break; + case '1': + f1 = f1 + 0.25; + glutPostRedisplay(); + break; + case '2': + f2 = f2 + 0.25; + glutPostRedisplay(); + break; + case '3': + f3 = f3 + 0.25; + glutPostRedisplay(); + break; + case '8': + if (f1 > 0.25) { + f1 = f1 - 0.25; + glutPostRedisplay(); + } + break; + case '9': + if (f2 > 0.25) { + f2 = f2 - 0.25; + glutPostRedisplay(); + } + break; + case '0': + if (f3 > 0.25) { + f3 = f3 - 0.25; + glutPostRedisplay(); + } + break; + case 'b': + glMatrixMode (GL_MODELVIEW); + glTranslatef (0.0, 0.0, -0.25); + glutPostRedisplay(); + break; + case 'f': + glMatrixMode (GL_MODELVIEW); + glTranslatef (0.0, 0.0, 0.25); + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, depth buffer, and handle input events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize(500, 500); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/fogindex.c b/progs/redbook/fogindex.c index b8bb691e288..6b5aa353caa 100644 --- a/progs/redbook/fogindex.c +++ b/progs/redbook/fogindex.c @@ -53,7 +53,7 @@ #define NUM_COLORS 32 #define RAMPSTART 16 -void +static void myinit(void) { int i; @@ -77,7 +77,7 @@ myinit(void) /* display() renders 3 cones at different z positions. */ -void +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -104,7 +104,7 @@ display(void) glFlush(); } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/font.c b/progs/redbook/font.c index 2d92e9b6003..c7a1035aa99 100644 --- a/progs/redbook/font.c +++ b/progs/redbook/font.c @@ -80,7 +80,7 @@ GLubyte letters[][13] = { GLuint fontOffset; -void makeRasterFont(void) +static void makeRasterFont(void) { GLuint i, j; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -96,13 +96,13 @@ void makeRasterFont(void) glEndList(); } -void init(void) +static void init(void) { glShadeModel (GL_FLAT); makeRasterFont(); } -void printString(char *s) +static void printString(char *s) { glPushAttrib (GL_LIST_BIT); glListBase(fontOffset); @@ -115,7 +115,7 @@ void printString(char *s) * to call makeRasterFont() before you start making * calls to printString(). */ -void display(void) +static void display(void) { GLfloat white[3] = { 1.0, 1.0, 1.0 }; @@ -129,7 +129,7 @@ void display(void) glFlush (); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -139,7 +139,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/hello.c b/progs/redbook/hello.c index fb3dae13252..84183b25b9f 100644 --- a/progs/redbook/hello.c +++ b/progs/redbook/hello.c @@ -42,7 +42,7 @@ #include <stdlib.h> #include <GL/glut.h> -void display(void) +static void display(void) { /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); @@ -64,7 +64,7 @@ void display(void) glFlush (); } -void init (void) +static void init (void) { /* select clearing color */ glClearColor (0.0, 0.0, 0.0, 0.0); diff --git a/progs/redbook/histogram.c b/progs/redbook/histogram.c new file mode 100644 index 00000000000..12b0e315ca1 --- /dev/null +++ b/progs/redbook/histogram.c @@ -0,0 +1,213 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * histogram.c + * Compute the histogram of the image. This program illustrates the + * use of the glHistogram() function. + */ + +#include <GL/glew.h> +#include <GL/glut.h> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> + +#define HISTOGRAM_SIZE 256 /* Must be a power of 2 */ + + +static GLubyte *pixels; +static GLsizei width, height; + + + +static GLuint bswap(GLuint x) +{ + const GLuint ui = 1; + const GLubyte *ubp = (const GLubyte *) &ui; + if (*ubp == 1) { + /* we're on little endiang so byteswap x */ + GLsizei y = ((x >> 24) + | ((x >> 8) & 0xff00) + | ((x << 8) & 0xff0000) + | ((x << 24) & 0xff000000)); + return y; + } + else { + return x; + } +} + + +static GLubyte* +readImage( const char* filename, GLsizei* width, GLsizei *height ) +{ + int n; + GLubyte* pixels; + size_t num_read; + + FILE* infile = fopen( filename, "rb" ); + + if ( !infile ) { + fprintf( stderr, "Unable to open file '%s'\n", filename ); + exit(1); + } + + num_read = fread( width, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + num_read = fread( height, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + + *width = bswap(*width); + *height = bswap(*height); + + n = 3 * (*width) * (*height); + + pixels = (GLubyte *) malloc( n * sizeof( GLubyte )); + if ( !pixels ) { + fprintf( stderr, "Unable to malloc() bytes for pixels\n" ); + fclose( infile ); + return NULL; + } + + num_read = fread( pixels, sizeof( GLubyte ), n, infile ); + assert(num_read == n); + + fclose( infile ); + + return pixels; +} + +static void init(void) +{ + if (!glutExtensionSupported("GL_ARB_imaging")) { + fprintf(stderr, "Sorry, this program requires GL_ARB_imaging.\n"); + exit(1); + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glClearColor(0.0, 0.0, 0.0, 0.0); + + glHistogram(GL_HISTOGRAM, HISTOGRAM_SIZE, GL_RGB, GL_FALSE); + glEnable(GL_HISTOGRAM); +} + +static void display(void) +{ + int i; + GLushort values[HISTOGRAM_SIZE][3]; + + glClear(GL_COLOR_BUFFER_BIT); + glRasterPos2i(1, 1); + glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_SHORT, values); + + /* Plot histogram */ + + glBegin(GL_LINE_STRIP); + glColor3f(1.0, 0.0, 0.0); + for ( i = 0; i < HISTOGRAM_SIZE; i++ ) + glVertex2s(i, values[i][0]); + glEnd(); + + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 1.0, 0.0); + for ( i = 0; i < HISTOGRAM_SIZE; i++ ) + glVertex2s(i, values[i][1]); + glEnd(); + + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 0.0, 1.0); + for ( i = 0; i < HISTOGRAM_SIZE; i++ ) + glVertex2s(i, values[i][2]); + glEnd(); + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, 256, 0, 10000, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); +} + +static void keyboard(unsigned char key, int x, int y) +{ + static GLboolean sink = GL_FALSE; + + switch (key) { + case 's' : + sink = !sink; + glHistogram(GL_HISTOGRAM, HISTOGRAM_SIZE, GL_RGB, sink); + break; + + case 27: + exit(0); + } + glutPostRedisplay(); + +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + pixels = readImage("leeds.bin", &width, &height); + + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(width, height); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/image.c b/progs/redbook/image.c index dc1a7246eba..fa3b46f5ed4 100644 --- a/progs/redbook/image.c +++ b/progs/redbook/image.c @@ -58,7 +58,7 @@ GLubyte checkImage[checkImageHeight][checkImageWidth][3]; static GLdouble zoomFactor = 1.0; static GLint height; -void makeCheckImage(void) +static void makeCheckImage(void) { int i, j, c; @@ -72,7 +72,7 @@ void makeCheckImage(void) } } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -80,7 +80,7 @@ void init(void) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i(0, 0); @@ -89,7 +89,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); height = (GLint) h; @@ -100,7 +100,7 @@ void reshape(int w, int h) glLoadIdentity(); } -void motion(int x, int y) +static void motion(int x, int y) { static GLint screeny; @@ -113,7 +113,7 @@ void motion(int x, int y) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'r': diff --git a/progs/redbook/leeds.bin b/progs/redbook/leeds.bin Binary files differnew file mode 100644 index 00000000000..5dc105e6768 --- /dev/null +++ b/progs/redbook/leeds.bin diff --git a/progs/redbook/light.c b/progs/redbook/light.c index 0eed85e10c2..9431dce508e 100644 --- a/progs/redbook/light.c +++ b/progs/redbook/light.c @@ -47,7 +47,7 @@ /* Initialize material property, light source, lighting model, * and depth buffer. */ -void init(void) +static void init(void) { GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; @@ -65,14 +65,14 @@ void init(void) glEnable(GL_DEPTH_TEST); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere (1.0, 20, 16); glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -88,7 +88,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/lines.c b/progs/redbook/lines.c index b34d4c418c6..9f12da9acfe 100644 --- a/progs/redbook/lines.c +++ b/progs/redbook/lines.c @@ -46,13 +46,13 @@ #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \ glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd(); -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { int i; @@ -104,7 +104,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -113,7 +113,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/list.c b/progs/redbook/list.c index 3b4f44bd6da..5dea26fcad1 100644 --- a/progs/redbook/list.c +++ b/progs/redbook/list.c @@ -69,7 +69,7 @@ static void drawLine (void) glEnd (); } -void display(void) +static void display(void) { GLuint i; @@ -82,7 +82,7 @@ void display(void) glFlush (); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); @@ -97,7 +97,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/material.c b/progs/redbook/material.c index f9a4fc59288..5edddd9ef84 100644 --- a/progs/redbook/material.c +++ b/progs/redbook/material.c @@ -49,7 +49,7 @@ /* Initialize z-buffer, projection matrix, light source, * and lighting model. Do not specify a material property here. */ -void myinit(void) +static void myinit(void) { GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -87,7 +87,7 @@ void myinit(void) * glTranslatef() is used to move spheres to their appropriate locations. */ -void display(void) +static void display(void) { GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 }; @@ -260,7 +260,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/minmax.c b/progs/redbook/minmax.c new file mode 100644 index 00000000000..2c1356c9de4 --- /dev/null +++ b/progs/redbook/minmax.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * minmax.c + * Determine the minimum and maximum values of a group of pixels. + * This demonstrates use of the glMinmax() call. + */ +#include <GL/glew.h> +#include <GL/glut.h> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> + + +static GLubyte *pixels; +static GLsizei width, height; + + +static GLuint bswap(GLuint x) +{ + const GLuint ui = 1; + const GLubyte *ubp = (const GLubyte *) &ui; + if (*ubp == 1) { + /* we're on little endiang so byteswap x */ + GLsizei y = ((x >> 24) + | ((x >> 8) & 0xff00) + | ((x << 8) & 0xff0000) + | ((x << 24) & 0xff000000)); + return y; + } + else { + return x; + } +} + + +static GLubyte * +readImage( const char* filename, GLsizei* width, GLsizei *height ) +{ + int n; + GLubyte* pixels; + size_t num_read; + + FILE* infile = fopen( filename, "rb" ); + + if ( !infile ) { + fprintf( stderr, "Unable to open file '%s'\n", filename ); + return NULL; + } + + num_read = fread( width, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + num_read = fread( height, sizeof( GLsizei ), 1, infile ); + assert(num_read == 1); + + *width = bswap(*width); + *height = bswap(*height); + + n = 3 * (*width) * (*height); + + pixels = (GLubyte *) malloc( n * sizeof( GLubyte )); + if ( !pixels ) { + fprintf( stderr, "Unable to malloc() bytes for pixels\n" ); + fclose( infile ); + return NULL; + } + + num_read = fread( pixels, sizeof( GLubyte ), n, infile ); + assert(num_read == n); + + fclose( infile ); + + return pixels; +} + +static void init(void) +{ + if (!glutExtensionSupported("GL_ARB_imaging")) { + fprintf(stderr, "Sorry, this program requires GL_ARB_imaging.\n"); + exit(1); + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glClearColor(0.0, 0.0, 0.0, 0.0); + + glMinmax(GL_MINMAX, GL_RGB, GL_FALSE); + glEnable(GL_MINMAX); +} + +static void display(void) +{ + GLubyte values[6]; + + glClear(GL_COLOR_BUFFER_BIT); + glRasterPos2i(1, 1); + glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + glFlush(); + + glGetMinmax(GL_MINMAX, GL_TRUE, GL_RGB, GL_UNSIGNED_BYTE, values); + printf(" Red : min = %d max = %d\n", values[0], values[3]); + printf(" Green : min = %d max = %d\n", values[1], values[4]); + printf(" Blue : min = %d max = %d\n", values[2], values[5]); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, w, 0, h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + } +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + pixels = readImage("leeds.bin", &width, &height); + + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(width, height); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/mipmap.c b/progs/redbook/mipmap.c index d32dd725f4b..dadde055bef 100644 --- a/progs/redbook/mipmap.c +++ b/progs/redbook/mipmap.c @@ -54,7 +54,7 @@ GLubyte mipmapImage4[4][4][3]; GLubyte mipmapImage2[2][2][3]; GLubyte mipmapImage1[1][1][3]; -void makeImages(void) +static void makeImages(void) { int i, j; @@ -98,7 +98,7 @@ void makeImages(void) mipmapImage1[0][0][2] = 255; } -void myinit(void) +static void myinit(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); @@ -128,7 +128,7 @@ void myinit(void) glEnable(GL_TEXTURE_2D); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); @@ -140,7 +140,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/model.c b/progs/redbook/model.c index 8411ef355f1..f7c92f4f87c 100644 --- a/progs/redbook/model.c +++ b/progs/redbook/model.c @@ -42,13 +42,13 @@ #include <GL/glut.h> #include <stdlib.h> -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void draw_triangle(void) +static void draw_triangle(void) { glBegin (GL_LINE_LOOP); glVertex2f(0.0, 25.0); @@ -57,7 +57,7 @@ void draw_triangle(void) glEnd(); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -86,7 +86,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -101,7 +101,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/movelight.c b/progs/redbook/movelight.c index a108cad439a..93758a222a4 100644 --- a/progs/redbook/movelight.c +++ b/progs/redbook/movelight.c @@ -58,7 +58,7 @@ static int spin = 0; /* Initialize material property, light source, lighting model, * and depth buffer. */ -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); @@ -72,7 +72,7 @@ void init(void) * light at a new position in world coordinates. The cube * represents the position of the light. */ -void display(void) +static void display(void) { GLfloat position[] = { 0.0, 0.0, 1.5, 1.0 }; @@ -96,7 +96,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -107,7 +107,7 @@ void reshape (int w, int h) } /* ARGSUSED2 */ -void mouse(int button, int state, int x, int y) +static void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: @@ -122,7 +122,7 @@ void mouse(int button, int state, int x, int y) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/multisamp.c b/progs/redbook/multisamp.c new file mode 100644 index 00000000000..38bd572fc13 --- /dev/null +++ b/progs/redbook/multisamp.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * multisamp.c + * This program draws shows how to use multisampling to + * draw anti-aliased geometric primitives. The same + * display list, a pinwheel of triangles and lines of + * varying widths, is rendered twice. Multisampling is + * enabled when the left side is drawn. Multisampling is + * disabled when the right side is drawn. + * + * Pressing the 'b' key toggles drawing of the checkerboard + * background. Antialiasing is sometimes easier to see + * when objects are rendered over a contrasting background. + */ +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +static int bgtoggle = 1; + +/* + * Print out state values related to multisampling. + * Create display list with "pinwheel" of lines and + * triangles. + */ +static void init(void) +{ + static GLint buf[1], sbuf[1]; + int i, j; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glGetIntegerv (GL_SAMPLE_BUFFERS_ARB, buf); + printf ("number of sample buffers is %d\n", buf[0]); + glGetIntegerv (GL_SAMPLES_ARB, sbuf); + printf ("number of samples is %d\n", sbuf[0]); + + glNewList (1, GL_COMPILE); + for (i = 0; i < 19; i++) { + glPushMatrix(); + glRotatef(360.0*(float)i/19.0, 0.0, 0.0, 1.0); + glColor3f (1.0, 1.0, 1.0); + glLineWidth((i%3)+1.0); + glBegin (GL_LINES); + glVertex2f (0.25, 0.05); + glVertex2f (0.9, 0.2); + glEnd (); + glColor3f (0.0, 1.0, 1.0); + glBegin (GL_TRIANGLES); + glVertex2f (0.25, 0.0); + glVertex2f (0.9, 0.0); + glVertex2f (0.875, 0.10); + glEnd (); + glPopMatrix(); + } + glEndList (); + + glNewList (2, GL_COMPILE); + glColor3f (1.0, 0.5, 0.0); + glBegin (GL_QUADS); + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + if (((i + j) % 2) == 0) { + glVertex2f (-2.0 + (i * 0.25), -2.0 + (j * 0.25)); + glVertex2f (-2.0 + (i * 0.25), -1.75 + (j * 0.25)); + glVertex2f (-1.75 + (i * 0.25), -1.75 + (j * 0.25)); + glVertex2f (-1.75 + (i * 0.25), -2.0 + (j * 0.25)); + } + } + } + glEnd (); + glEndList (); +} + +/* Draw two sets of primitives, so that you can + * compare the user of multisampling against its absence. + * + * This code enables antialiasing and draws one display list + * and disables and draws the other display list + */ +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + if (bgtoggle) + glCallList (2); + + glEnable (GL_MULTISAMPLE_ARB); + glPushMatrix(); + glTranslatef (-1.0, 0.0, 0.0); + glCallList (1); + glPopMatrix(); + + glDisable (GL_MULTISAMPLE_ARB); + glPushMatrix(); + glTranslatef (1.0, 0.0, 0.0); + glCallList (1); + glPopMatrix(); + glutSwapBuffers(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= (2 * h)) + gluOrtho2D (-2.0, 2.0, + -2.0*(GLfloat)h/(GLfloat)w, 2.0*(GLfloat)h/(GLfloat)w); + else + gluOrtho2D (-2.0*(GLfloat)w/(GLfloat)h, + 2.0*(GLfloat)w/(GLfloat)h, -2.0, 2.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'b': + case 'B': + bgtoggle = !bgtoggle; + glutPostRedisplay(); + break; + case 27: /* Escape Key */ + exit(0); + default: + break; + } +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE); + glutInitWindowSize (600, 300); + glutCreateWindow (argv[0]); + init(); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/multitex.c b/progs/redbook/multitex.c new file mode 100644 index 00000000000..118f0ea77ee --- /dev/null +++ b/progs/redbook/multitex.c @@ -0,0 +1,177 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* multitex.c + */ +#include <GL/glew.h> +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + + +static GLubyte texels0[32][32][4]; +static GLubyte texels1[16][16][4]; + +static void makeCheckImages(void) +{ + int i, j; + + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + texels0[i][j][0] = (GLubyte) (255 * i / 31); + texels0[i][j][1] = (GLubyte) (255 * j / 31); + texels0[i][j][2] = (GLubyte) (i*j)/255; + texels0[i][j][3] = (GLubyte) 255; + } + } + + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + texels1[i][j][0] = (GLubyte) 255; + texels1[i][j][1] = (GLubyte) (255 * i / 15); + texels1[i][j][2] = (GLubyte) (255 * j / 15); + texels1[i][j][3] = (GLubyte) 255; + } + } +} + +static void init(void) +{ + GLuint texNames[2]; + + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + makeCheckImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glGenTextures(2, texNames); + glBindTexture(GL_TEXTURE_2D, texNames[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, + GL_UNSIGNED_BYTE, texels0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBindTexture(GL_TEXTURE_2D, texNames[1]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, + GL_UNSIGNED_BYTE, texels1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + /* Use the two texture objects to define two texture units + * for use in multitexturing */ + glActiveTextureARB (GL_TEXTURE0_ARB); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texNames[0]); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glMatrixMode (GL_TEXTURE); + glLoadIdentity(); + glTranslatef(0.5f, 0.5f, 0.0f); + glRotatef(45.0f, 0.0f, 0.0f, 1.0f); + glTranslatef(-0.5f, -0.5f, 0.0f); + glMatrixMode (GL_MODELVIEW); + glActiveTextureARB (GL_TEXTURE1_ARB); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texNames[1]); + glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_TRIANGLES); + glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 0.0, 0.0); + glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0, 0.0); + glVertex2f(0.0, 0.0); + glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 0.5, 1.0); + glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 0.5, 0.0); + glVertex2f(50.0, 100.0); + glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 1.0, 0.0); + glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0, 1.0); + glVertex2f(100.0, 0.0); + glEnd(); + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D(0.0, 100.0, 0.0, 100.0 * (GLdouble)h/(GLdouble)w); + else + gluOrtho2D(0.0, 100.0 * (GLdouble)w/(GLdouble)h, 0.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(250, 250); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/mvarray.c b/progs/redbook/mvarray.c new file mode 100644 index 00000000000..1022723ad94 --- /dev/null +++ b/progs/redbook/mvarray.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * mvarray.c + * This program demonstrates multiple vertex arrays, + * specifically the OpenGL routine glMultiDrawElements(). + */ + +#include <GL/glew.h> +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef GL_VERSION_1_3 + +static void setupPointer(void) +{ + static GLint vertices[] = {25, 25, + 75, 75, + 100, 125, + 150, 75, + 200, 175, + 250, 150, + 300, 125, + 100, 200, + 150, 250, + 200, 225, + 250, 300, + 300, 250}; + + glEnableClientState (GL_VERTEX_ARRAY); + glVertexPointer (2, GL_INT, 0, vertices); +} + +static void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + setupPointer (); +} + +static void display(void) +{ + static GLubyte oneIndices[] = {0, 1, 2, 3, 4, 5, 6}; + static GLubyte twoIndices[] = {1, 7, 8, 9, 10, 11}; + static GLsizei count[] = {7, 6}; + static GLvoid * indices[2] = {oneIndices, twoIndices}; + + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glMultiDrawElementsEXT (GL_LINE_STRIP, count, GL_UNSIGNED_BYTE, + (const GLvoid **) indices, 2); + glFlush (); +} + +static void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (350, 350); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + glewInit(); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} +#else +int main(int argc, char** argv) +{ + fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n"); + fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n"); + fprintf (stderr, "you may be able to modify this program to make it run.\n"); + return 0; +} +#endif diff --git a/progs/redbook/nurbs.c b/progs/redbook/nurbs.c index a7c6f0c696e..fe03ce667ed 100644 --- a/progs/redbook/nurbs.c +++ b/progs/redbook/nurbs.c @@ -89,7 +89,7 @@ GLUnurbsObj *theNurb; /* Initialize material property, light source, lighting model, * and depth buffer. */ -void myinit(void) +static void myinit(void) { GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_diffuse[] = { 1.0, 0.2, 1.0, 1.0 }; @@ -122,7 +122,7 @@ void myinit(void) gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -147,7 +147,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/pickdepth.c b/progs/redbook/pickdepth.c index ad5bdc81994..91d44a38c0a 100644 --- a/progs/redbook/pickdepth.c +++ b/progs/redbook/pickdepth.c @@ -51,7 +51,7 @@ #include <stdio.h> #include <GL/glut.h> -void +static void myinit(void) { glClearColor(0.0, 0.0, 0.0, 0.0); @@ -65,7 +65,7 @@ myinit(void) * each rectangle is given the same name. Note that * each rectangle is drawn with a different z value. */ -void +static void drawRects(GLenum mode) { if (mode == GL_SELECT) @@ -100,7 +100,7 @@ drawRects(GLenum mode) /* processHits() prints out the contents of the * selection array. */ -void +static void processHits(GLint hits, GLuint buffer[]) { GLint i; @@ -131,7 +131,7 @@ processHits(GLint hits, GLuint buffer[]) */ #define BUFSIZE 512 -void +static void pickRects(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; @@ -164,7 +164,7 @@ pickRects(int button, int state, int x, int y) processHits(hits, selectBuf); } -void +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -172,7 +172,7 @@ display(void) glutSwapBuffers(); } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/picksquare.c b/progs/redbook/picksquare.c index 636edc97b4b..cc092dbf538 100644 --- a/progs/redbook/picksquare.c +++ b/progs/redbook/picksquare.c @@ -49,7 +49,7 @@ int board[3][3]; /* amount of color for each square */ /* Clear color value for every square on the board */ -void init(void) +static void init(void) { int i, j; for (i = 0; i < 3; i++) @@ -64,7 +64,7 @@ void init(void) * square is determined by its position on the grid, and * the value in the board[][] array. */ -void drawSquares(GLenum mode) +static void drawSquares(GLenum mode) { GLuint i, j; for (i = 0; i < 3; i++) { @@ -85,7 +85,7 @@ void drawSquares(GLenum mode) /* processHits prints out the contents of the * selection array. */ -void processHits (GLint hits, GLuint buffer[]) +static void processHits (GLint hits, GLuint buffer[]) { GLint i; GLuint j, ii = 0, jj = 0, names, *ptr; @@ -117,7 +117,7 @@ void processHits (GLint hits, GLuint buffer[]) */ #define BUFSIZE 512 -void pickSquares(int button, int state, int x, int y) +static void pickSquares(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; GLint hits; @@ -152,14 +152,14 @@ void pickSquares(int button, int state, int x, int y) glutPostRedisplay(); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); drawSquares (GL_RENDER); glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); @@ -170,7 +170,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/plane.c b/progs/redbook/plane.c index dc17f7b2386..2c2e2d24d93 100644 --- a/progs/redbook/plane.c +++ b/progs/redbook/plane.c @@ -47,7 +47,7 @@ /* Initialize material property, light source, and lighting model. */ -void myinit(void) +static void myinit(void) { GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; /* mat_specular and mat_shininess are NOT default values */ @@ -75,7 +75,7 @@ void myinit(void) glEnable(GL_DEPTH_TEST); } -void drawPlane(void) +static void drawPlane(void) { glBegin (GL_QUADS); glNormal3f (0.0, 0.0, 1.0); @@ -104,7 +104,7 @@ void drawPlane(void) glEnd(); } -void display (void) +static void display (void) { GLfloat infinite_light[] = { 1.0, 1.0, 1.0, 0.0 }; GLfloat local_light[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -125,7 +125,7 @@ void display (void) glFlush (); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport (0, 0, w, h); glMatrixMode (GL_PROJECTION); diff --git a/progs/redbook/planet.c b/progs/redbook/planet.c index e13672d3f63..cc428b4e427 100644 --- a/progs/redbook/planet.c +++ b/progs/redbook/planet.c @@ -47,13 +47,13 @@ static int year = 0, day = 0; -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -68,7 +68,7 @@ void display(void) glutSwapBuffers(); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -80,7 +80,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 'd': diff --git a/progs/redbook/pointp.c b/progs/redbook/pointp.c new file mode 100644 index 00000000000..b273623d856 --- /dev/null +++ b/progs/redbook/pointp.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * pointp.c + * This program demonstrates point parameters and their effect + * on point primitives. + * 250 points are randomly generated within a 10 by 10 by 40 + * region, centered at the origin. In some modes (including the + * default), points that are closer to the viewer will appear larger. + * + * Pressing the 'l', 'q', and 'c' keys switch the point + * parameters attenuation mode to linear, quadratic, or constant, + * respectively. + * Pressing the 'f' and 'b' keys move the viewer forward + * and backwards. In either linear or quadratic attenuation + * mode, the distance from the viewer to the point will change + * the size of the point primitive. + * Pressing the '+' and '-' keys will change the current point + * size. In this program, the point size is bounded, so it + * will not get less than 2.0, nor greater than GL_POINT_SIZE_MAX. + */ + +#include <GL/glew.h> +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +static GLfloat psize = 7.0; +static GLfloat pmax[1]; +static GLfloat constant[3] = {1.0, 0.0, 0.0}; +static GLfloat linear[3] = {0.0, 0.12, 0.0}; +static GLfloat quadratic[3] = {0.0, 0.0, 0.01}; + +static void init(void) +{ + int i; + + srand (12345); + + glNewList(1, GL_COMPILE); + glBegin (GL_POINTS); + for (i = 0; i < 250; i++) { + glColor3f (1.0, ((rand()/(float) RAND_MAX) * 0.5) + 0.5, + rand()/(float) RAND_MAX); +/* randomly generated vertices: + -5 < x < 5; -5 < y < 5; -5 < z < -45 */ + glVertex3f ( ((rand()/(float)RAND_MAX) * 10.0) - 5.0, + ((rand()/(float)RAND_MAX) * 10.0) - 5.0, + ((rand()/(float)RAND_MAX) * 40.0) - 45.0); + } + glEnd(); + glEndList(); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_POINT_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glPointSize(psize); + glGetFloatv(GL_POINT_SIZE_MAX_EXT, pmax); + + glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, linear); + glPointParameterfEXT (GL_POINT_FADE_THRESHOLD_SIZE_EXT, 2.0); +} + +static void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glCallList (1); + glutSwapBuffers (); +} + +static void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluPerspective (35.0, 1.0, 0.25, 200.0); + glMatrixMode (GL_MODELVIEW); + glTranslatef (0.0, 0.0, -10.0); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'b': + glMatrixMode (GL_MODELVIEW); + glTranslatef (0.0, 0.0, -0.5); + glutPostRedisplay(); + break; + case 'c': + glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, constant); + glutPostRedisplay(); + break; + case 'f': + glMatrixMode (GL_MODELVIEW); + glTranslatef (0.0, 0.0, 0.5); + glutPostRedisplay(); + break; + case 'l': + glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, linear); + glutPostRedisplay(); + break; + case 'q': + glPointParameterfvEXT (GL_DISTANCE_ATTENUATION_EXT, quadratic); + glutPostRedisplay(); + break; + case '+': + if (psize < (pmax[0] + 1.0)) + psize = psize + 1.0; + glPointSize (psize); + glutPostRedisplay(); + break; + case '-': + if (psize >= 2.0) + psize = psize - 1.0; + glPointSize (psize); + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + glewInit(); + init (); + glutDisplayFunc (display); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/polyoff.c b/progs/redbook/polyoff.c index de34b2e7675..0e0ce86ec91 100644 --- a/progs/redbook/polyoff.c +++ b/progs/redbook/polyoff.c @@ -60,7 +60,7 @@ GLboolean doubleBuffer; /* display() draws two spheres, one with a gray, diffuse material, * the other sphere with a magenta material with a specular highlight. */ -void display (void) +static void display (void) { GLfloat gray[] = { 0.8, 0.8, 0.8, 1.0 }; GLfloat black[] = { 0.0, 0.0, 0.0, 1.0 }; @@ -108,7 +108,7 @@ void display (void) * create display list with sphere * initialize lighting and depth buffer */ -void gfxinit (void) +static void gfxinit (void) { GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -134,7 +134,7 @@ void gfxinit (void) } /* call when window is resized */ -void reshape(int width, int height) +static void reshape(int width, int height) { glViewport (0, 0, width, height); glMatrixMode (GL_PROJECTION); @@ -176,7 +176,7 @@ static void Benchmark( float xdiff, float ydiff ) /* call when mouse button is pressed */ /* ARGSUSED2 */ -void mouse(int button, int state, int x, int y) { +static void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: switch (state) { @@ -213,7 +213,7 @@ void mouse(int button, int state, int x, int y) { } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 't': @@ -268,20 +268,7 @@ void keyboard (unsigned char key, int x, int y) fflush(stdout); } -static void -key(unsigned char k, int x, int y) -{ - switch (k) { - case 27: /* Escape */ - exit(0); - break; - default: - return; - } - glutPostRedisplay(); -} - -GLenum Args(int argc, char **argv) +static GLenum Args(int argc, char **argv) { GLint i; diff --git a/progs/redbook/polys.c b/progs/redbook/polys.c index 409abd17531..eeffe2301ce 100644 --- a/progs/redbook/polys.c +++ b/progs/redbook/polys.c @@ -44,7 +44,7 @@ #include <stdlib.h> #include <GL/glut.h> -void display(void) +static void display(void) { GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, @@ -89,7 +89,7 @@ void display(void) glFlush (); } -void myinit (void) +static void myinit (void) { /* clear background to black */ glClearColor (0.0, 0.0, 0.0, 0.0); diff --git a/progs/redbook/quadric.c b/progs/redbook/quadric.c index 7e99098304a..1cbd395e47b 100644 --- a/progs/redbook/quadric.c +++ b/progs/redbook/quadric.c @@ -54,7 +54,7 @@ GLuint startList; -void CALLBACK errorCallback(GLenum errorCode) +static void CALLBACK errorCallback(GLenum errorCode) { const GLubyte *estring; @@ -63,7 +63,7 @@ void CALLBACK errorCallback(GLenum errorCode) exit(0); } -void init(void) +static void init(void) { GLUquadricObj *qobj; GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; @@ -120,7 +120,7 @@ void init(void) gluDeleteQuadric(qobj); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); @@ -150,7 +150,7 @@ void display(void) glFlush(); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -166,7 +166,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/robot.c b/progs/redbook/robot.c index 94e20ac71eb..c90b72ab3ea 100644 --- a/progs/redbook/robot.c +++ b/progs/redbook/robot.c @@ -47,13 +47,13 @@ static int shoulder = 0, elbow = 0; -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); glPushMatrix(); @@ -77,7 +77,7 @@ void display(void) glutSwapBuffers(); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -89,7 +89,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 's': diff --git a/progs/redbook/sccolorlight.c b/progs/redbook/sccolorlight.c index 0ea750e5846..d9e0a254e90 100644 --- a/progs/redbook/sccolorlight.c +++ b/progs/redbook/sccolorlight.c @@ -49,7 +49,7 @@ /* Initialize material property and light source. */ -void myinit(void) +static void myinit(void) { GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 0.0, 1.0, 1.0 }; @@ -68,7 +68,7 @@ void myinit(void) glEnable(GL_DEPTH_TEST); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); @@ -95,7 +95,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/scene.c b/progs/redbook/scene.c index c3abc727b78..6f336a8db46 100644 --- a/progs/redbook/scene.c +++ b/progs/redbook/scene.c @@ -48,7 +48,7 @@ /* Initialize material property and light source. */ -void myinit (void) +static void myinit (void) { GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -67,7 +67,7 @@ void myinit (void) glEnable(GL_DEPTH_TEST); } -void display (void) +static void display (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -95,7 +95,7 @@ void display (void) glFlush (); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport (0, 0, w, h); glMatrixMode (GL_PROJECTION); diff --git a/progs/redbook/scenebamb.c b/progs/redbook/scenebamb.c index e7264d2003f..ea605f8c737 100644 --- a/progs/redbook/scenebamb.c +++ b/progs/redbook/scenebamb.c @@ -47,7 +47,7 @@ /* Initialize light source and lighting. */ -void myinit(void) +static void myinit(void) { GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -66,7 +66,7 @@ void myinit(void) glEnable(GL_DEPTH_TEST); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -94,7 +94,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/sceneflat.c b/progs/redbook/sceneflat.c index 10891fb9977..1b277334f5c 100644 --- a/progs/redbook/sceneflat.c +++ b/progs/redbook/sceneflat.c @@ -46,7 +46,7 @@ /* Initialize light source and shading model (GL_FLAT). */ -void myinit(void) +static void myinit(void) { GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -66,7 +66,7 @@ void myinit(void) glShadeModel (GL_FLAT); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -94,7 +94,7 @@ void display(void) glFlush(); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/select.c b/progs/redbook/select.c index 928373b8796..537d5194d46 100644 --- a/progs/redbook/select.c +++ b/progs/redbook/select.c @@ -57,7 +57,7 @@ /* draw a triangle with vertices at (x1, y1), (x2, y2) * and (x3, y3) at z units away from the origin. */ -void drawTriangle (GLfloat x1, GLfloat y1, GLfloat x2, +static void drawTriangle (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat z) { glBegin (GL_TRIANGLES); @@ -68,8 +68,8 @@ void drawTriangle (GLfloat x1, GLfloat y1, GLfloat x2, } /* draw a rectangular box with these outer x, y, and z values */ -void drawViewVolume (GLfloat x1, GLfloat x2, GLfloat y1, - GLfloat y2, GLfloat z1, GLfloat z2) +static void drawViewVolume (GLfloat x1, GLfloat x2, GLfloat y1, + GLfloat y2, GLfloat z1, GLfloat z2) { glColor3f (1.0, 1.0, 1.0); glBegin (GL_LINE_LOOP); @@ -101,7 +101,7 @@ void drawViewVolume (GLfloat x1, GLfloat x2, GLfloat y1, /* drawScene draws 4 triangles and a wire frame * which represents the viewing volume. */ -void drawScene (void) +static void drawScene (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); @@ -122,7 +122,7 @@ void drawScene (void) /* processHits prints out the contents of the selection array */ -void processHits (GLint hits, GLuint buffer[]) +static void processHits (GLint hits, GLuint buffer[]) { GLint i; GLuint j, names, *ptr; @@ -150,7 +150,7 @@ void processHits (GLint hits, GLuint buffer[]) */ #define BUFSIZE 512 -void selectObjects(void) +static void selectObjects(void) { GLuint selectBuf[BUFSIZE]; GLint hits; @@ -181,13 +181,13 @@ void selectObjects(void) processHits (hits, selectBuf); } -void init (void) +static void init (void) { glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); } -void display(void) +static void display(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -197,7 +197,7 @@ void display(void) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/shadowmap.c b/progs/redbook/shadowmap.c new file mode 100644 index 00000000000..f37191d9ff3 --- /dev/null +++ b/progs/redbook/shadowmap.c @@ -0,0 +1,352 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> +/*#include "helpers.h"*/ + +#define SHADOW_MAP_WIDTH 256 +#define SHADOW_MAP_HEIGHT 256 + +#define PI 3.14159265359 + +GLdouble fovy = 60.0; +GLdouble nearPlane = 10.0; +GLdouble farPlane = 100.0; + +GLfloat angle = 0.0; +GLfloat torusAngle = 0.0; + +GLfloat lightPos[] = { 25.0, 25.0, 25.0, 1.0 }; +GLfloat lookat[] = { 0.0, 0.0, 0.0 }; +GLfloat up[] = { 0.0, 0.0, 1.0 }; + +GLboolean showShadow = GL_FALSE; + +static void +init( void ) +{ + GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; + + glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, + SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, 0, + GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL ); + + glLightfv( GL_LIGHT0, GL_POSITION, lightPos ); + glLightfv( GL_LIGHT0, GL_SPECULAR, white ); + glLightfv( GL_LIGHT0, GL_DIFFUSE, white ); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); + glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, + GL_COMPARE_R_TO_TEXTURE ); + + glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); + glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); + glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); + glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); + + glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); + + glCullFace( GL_BACK ); + + glEnable( GL_DEPTH_TEST ); + glEnable( GL_LIGHT0 ); + glEnable( GL_LIGHTING ); + glEnable( GL_TEXTURE_2D ); + glEnable( GL_TEXTURE_GEN_S ); + glEnable( GL_TEXTURE_GEN_T ); + glEnable( GL_TEXTURE_GEN_R ); + glEnable( GL_TEXTURE_GEN_Q ); + glEnable( GL_COLOR_MATERIAL ); + glEnable( GL_CULL_FACE ); +} + +static void +reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + gluPerspective( fovy, (GLdouble) width/height, nearPlane, farPlane ); + glMatrixMode( GL_MODELVIEW ); +} + +static void +idle( void ) +{ + angle += PI / 10000; + torusAngle += .1; + glutPostRedisplay(); +} + +static void +keyboard( unsigned char key, int x, int y ) +{ + switch( key ) { + case 27: /* Escape */ + exit( 0 ); + break; + + case 't': { + static GLboolean textureOn = GL_TRUE; + textureOn = !textureOn; + if ( textureOn ) + glEnable( GL_TEXTURE_2D ); + else + glDisable( GL_TEXTURE_2D ); + } + break; + + case 'm': { + static GLboolean compareMode = GL_TRUE; + compareMode = !compareMode; + printf( "Compare mode %s\n", compareMode ? "On" : "Off" ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, + compareMode ? GL_COMPARE_R_TO_TEXTURE : GL_NONE ); + } + break; + + case 'f': { + static GLboolean funcMode = GL_TRUE; + funcMode = !funcMode; + printf( "Operator %s\n", funcMode ? "GL_LEQUAL" : "GL_GEQUAL" ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, + funcMode ? GL_LEQUAL : GL_GEQUAL ); + } + break; + + case 's': + showShadow = !showShadow; + break; + + case 'p': { + static GLboolean animate = GL_TRUE; + animate = !animate; + glutIdleFunc( animate ? idle : NULL ); + } + break; + } + + glutPostRedisplay(); +} + +static void +transposeMatrix( GLfloat m[16] ) +{ + GLfloat tmp; +#define Swap( a, b ) tmp = a; a = b; b = tmp + Swap( m[1], m[4] ); + Swap( m[2], m[8] ); + Swap( m[3], m[12] ); + Swap( m[6], m[9] ); + Swap( m[7], m[13] ); + Swap( m[11], m[14] ); +#undef Swap +} + +static void +drawObjects( GLboolean shadowRender ) +{ + GLboolean textureOn = glIsEnabled( GL_TEXTURE_2D ); + + if ( shadowRender ) + glDisable( GL_TEXTURE_2D ); + + if ( !shadowRender ) { + glNormal3f( 0, 0, 1 ); + glColor3f( 1, 1, 1 ); + glRectf( -20.0, -20.0, 20.0, 20.0 ); + } + + glPushMatrix(); + glTranslatef( 11, 11, 11 ); + glRotatef( 54.73, -5, 5, 0 ); + glRotatef( torusAngle, 1, 0, 0 ); + glColor3f( 1, 0, 0 ); + glutSolidTorus( 1, 4, 8, 36 ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( 2, 2, 2 ); + glColor3f( 0, 0, 1 ); + glutSolidCube( 4 ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( lightPos[0], lightPos[1], lightPos[2] ); + glColor3f( 1, 1, 1 ); + glutWireSphere( 0.5, 6, 6 ); + glPopMatrix(); + + if ( shadowRender && textureOn ) + glEnable( GL_TEXTURE_2D ); +} + +static void +generateShadowMap( void ) +{ + GLint viewport[4]; + GLfloat lightPos[4]; + + glGetLightfv( GL_LIGHT0, GL_POSITION, lightPos ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + glViewport( 0, 0, SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + gluPerspective( 80.0, 1.0, 10.0, 1000.0 ); + glMatrixMode( GL_MODELVIEW ); + + glPushMatrix(); + glLoadIdentity(); + gluLookAt( lightPos[0], lightPos[1], lightPos[2], + lookat[0], lookat[1], lookat[2], + up[0], up[1], up[2] ); + + drawObjects( GL_TRUE ); + + glPopMatrix(); + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + + glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, + SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, 0 ); + + glViewport( viewport[0], viewport[1], viewport[2], viewport[3] ); + + if ( showShadow ) { + GLfloat depthImage[SHADOW_MAP_WIDTH][SHADOW_MAP_HEIGHT]; + glReadPixels( 0, 0, SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, + GL_DEPTH_COMPONENT, GL_FLOAT, depthImage ); + glWindowPos2f( viewport[2]/2, 0 ); + glDrawPixels( SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, GL_LUMINANCE, + GL_FLOAT, depthImage ); + glutSwapBuffers(); + } +} + +static void +generateTextureMatrix( void ) +{ + GLfloat tmpMatrix[16]; + + /* + * Set up projective texture matrix. We use the GL_MODELVIEW matrix + * stack and OpenGL matrix commands to make the matrix. + */ + glPushMatrix(); + glLoadIdentity(); + glTranslatef( 0.5, 0.5, 0.0 ); + glScalef( 0.5, 0.5, 1.0 ); + gluPerspective( 60.0, 1.0, 1.0, 1000.0 ); + gluLookAt( lightPos[0], lightPos[1], lightPos[2], + lookat[0], lookat[1], lookat[2], + up[0], up[1], up[2] ); + glGetFloatv( GL_MODELVIEW_MATRIX, tmpMatrix ); + glPopMatrix(); + + transposeMatrix( tmpMatrix ); + + glTexGenfv( GL_S, GL_OBJECT_PLANE, &tmpMatrix[0] ); + glTexGenfv( GL_T, GL_OBJECT_PLANE, &tmpMatrix[4] ); + glTexGenfv( GL_R, GL_OBJECT_PLANE, &tmpMatrix[8] ); + glTexGenfv( GL_Q, GL_OBJECT_PLANE, &tmpMatrix[12] ); +} + +static void +display( void ) +{ + GLfloat radius = 30; + + generateShadowMap(); + generateTextureMatrix(); + + if ( showShadow ) + return; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + gluLookAt( radius*cos(angle), radius*sin(angle), 30, + lookat[0], lookat[1], lookat[2], + up[0], up[1], up[2] ); + drawObjects( GL_FALSE ); + glPopMatrix(); + + glutSwapBuffers(); +} + +int +main( int argc, char** argv ) +{ + glutInit( &argc, argv ); + glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE ); + glutInitWindowSize( 512, 512 ); + glutInitWindowPosition( 100, 100 ); + glutCreateWindow( argv[0] ); + glewInit(); + + init(); + + glutDisplayFunc( display ); + glutReshapeFunc( reshape ); + glutKeyboardFunc( keyboard ); + glutIdleFunc( idle ); + + glutMainLoop(); + + return 0; +} diff --git a/progs/redbook/smooth.c b/progs/redbook/smooth.c index 9d22fc90251..874033d5adf 100644 --- a/progs/redbook/smooth.c +++ b/progs/redbook/smooth.c @@ -43,13 +43,13 @@ #include <GL/glut.h> #include <stdlib.h> -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); } -void triangle(void) +static void triangle(void) { glBegin (GL_TRIANGLES); glColor3f (1.0, 0.0, 0.0); @@ -61,14 +61,14 @@ void triangle(void) glEnd(); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); triangle (); glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -81,7 +81,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/stencil.c b/progs/redbook/stencil.c index b33e40a0307..5325abf8b77 100644 --- a/progs/redbook/stencil.c +++ b/progs/redbook/stencil.c @@ -64,7 +64,7 @@ #define YELLOWMAT 1 #define BLUEMAT 2 -void myinit (void) +static void myinit (void) { GLfloat yellow_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; GLfloat yellow_specular[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -101,7 +101,7 @@ void myinit (void) /* Draw a sphere in a diamond-shaped section in the * middle of a window with 2 tori. */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -132,7 +132,7 @@ void display(void) /* Whenever the window is reshaped, redefine the * coordinate system and redraw the stencil area. */ -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/stroke.c b/progs/redbook/stroke.c index 19b0391cbae..68b639abf4f 100644 --- a/progs/redbook/stroke.c +++ b/progs/redbook/stroke.c @@ -87,7 +87,7 @@ CP Sdata[] = { /* drawLetter() interprets the instructions from the array * for that letter and renders the letter with line segments. */ -void drawLetter(CP *l) +static void drawLetter(CP *l) { glBegin(GL_LINE_STRIP); for (;;) { @@ -111,7 +111,7 @@ void drawLetter(CP *l) } /* Create a display list for each of 6 characters */ -void myinit (void) +static void myinit (void) { GLuint base; @@ -130,13 +130,13 @@ void myinit (void) char *test1 = "A SPARE SERAPE APPEARS AS"; char *test2 = "APES PREPARE RARE PEPPERS"; -void printStrokedString(char *s) +static void printStrokedString(char *s) { GLsizei len = (GLsizei) strlen(s); glCallLists(len, GL_BYTE, (GLbyte *)s); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); diff --git a/progs/redbook/surface.c b/progs/redbook/surface.c index e33ce14f4fc..f0c5ab0b47c 100644 --- a/progs/redbook/surface.c +++ b/progs/redbook/surface.c @@ -53,7 +53,7 @@ GLUnurbsObj *theNurb; * Initializes the control points of the surface to a small hill. * The control points range from -3 to +3 in x, y, and z */ -void init_surface(void) +static void init_surface(void) { int u, v; for (u = 0; u < 4; u++) { @@ -71,7 +71,7 @@ void init_surface(void) /* Initialize material property and depth buffer. */ -void myinit(void) +static void myinit(void) { GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -100,7 +100,7 @@ void myinit(void) glTranslatef (0.0, 0.0, -5.0); } -void display(void) +static void display(void) { GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0}; int i, j; @@ -140,7 +140,7 @@ void display(void) glutSwapBuffers(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); @@ -150,7 +150,7 @@ void reshape(int w, int h) glMatrixMode(GL_MODELVIEW); } -void +static void menu(int value) { switch (value) { @@ -171,7 +171,7 @@ menu(int value) int down = 0, lastx; /* ARGSUSED1 */ -void +static void motion(int x, int y) { if (down) { @@ -182,7 +182,7 @@ motion(int x, int y) } /* ARGSUSED3 */ -void +static void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON) { diff --git a/progs/redbook/surfpoints.c b/progs/redbook/surfpoints.c new file mode 100644 index 00000000000..094f0dada80 --- /dev/null +++ b/progs/redbook/surfpoints.c @@ -0,0 +1,280 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * surfpoints.c + * This program is a modification of the earlier surface.c + * program. The vertex data are not directly rendered, + * but are instead passed to the callback function. + * The values of the tessellated vertices are printed + * out there. + * + * This program draws a NURBS surface in the shape of a + * symmetrical hill. The 'c' keyboard key allows you to + * toggle the visibility of the control points themselves. + * Note that some of the control points are hidden by the + * surface itself. + */ +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef GLU_VERSION_1_3 + +#ifndef CALLBACK +#define CALLBACK +#endif + +GLfloat ctlpoints[4][4][3]; +int showPoints = 0; + +GLUnurbsObj *theNurb; + +/* + * Initializes the control points of the surface to a small hill. + * The control points range from -3 to +3 in x, y, and z + */ +static void init_surface(void) +{ + int u, v; + for (u = 0; u < 4; u++) { + for (v = 0; v < 4; v++) { + ctlpoints[u][v][0] = 2.0*((GLfloat)u - 1.5); + ctlpoints[u][v][1] = 2.0*((GLfloat)v - 1.5); + + if ( (u == 1 || u == 2) && (v == 1 || v == 2)) + ctlpoints[u][v][2] = 3.0; + else + ctlpoints[u][v][2] = -3.0; + } + } +} + +static void CALLBACK nurbsError(GLenum errorCode) +{ + const GLubyte *estring; + + estring = gluErrorString(errorCode); + fprintf (stderr, "Nurbs Error: %s\n", estring); + exit (0); +} + +static void CALLBACK beginCallback(GLenum whichType) +{ + glBegin (whichType); /* resubmit rendering directive */ + printf ("glBegin("); + switch (whichType) { /* print diagnostic message */ + case GL_LINES: + printf ("GL_LINES)\n"); + break; + case GL_LINE_LOOP: + printf ("GL_LINE_LOOP)\n"); + break; + case GL_LINE_STRIP: + printf ("GL_LINE_STRIP)\n"); + break; + case GL_TRIANGLES: + printf ("GL_TRIANGLES)\n"); + break; + case GL_TRIANGLE_STRIP: + printf ("GL_TRIANGLE_STRIP)\n"); + break; + case GL_TRIANGLE_FAN: + printf ("GL_TRIANGLE_FAN)\n"); + break; + case GL_QUADS: + printf ("GL_QUADS)\n"); + break; + case GL_QUAD_STRIP: + printf ("GL_QUAD_STRIP)\n"); + break; + case GL_POLYGON: + printf ("GL_POLYGON)\n"); + break; + default: + break; + } +} + +static void CALLBACK endCallback() +{ + glEnd(); /* resubmit rendering directive */ + printf ("glEnd()\n"); +} + +static void CALLBACK vertexCallback(GLfloat *vertex) +{ + glVertex3fv(vertex); /* resubmit rendering directive */ + printf ("glVertex3f (%5.3f, %5.3f, %5.3f)\n", + vertex[0], vertex[1], vertex[2]); +} + +static void CALLBACK normalCallback(GLfloat *normal) +{ + glNormal3fv(normal); /* resubmit rendering directive */ + printf ("glNormal3f (%5.3f, %5.3f, %5.3f)\n", + normal[0], normal[1], normal[2]); +} + +/* Initialize material property and depth buffer. + */ +static void init(void) +{ + GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 100.0 }; + + glClearColor (0.0, 0.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + + init_surface(); + + theNurb = gluNewNurbsRenderer(); + gluNurbsProperty(theNurb, GLU_NURBS_MODE, + GLU_NURBS_TESSELLATOR); + gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); + gluNurbsCallback(theNurb, GLU_ERROR, nurbsError); + gluNurbsCallback(theNurb, GLU_NURBS_BEGIN, beginCallback); + gluNurbsCallback(theNurb, GLU_NURBS_VERTEX, vertexCallback); + gluNurbsCallback(theNurb, GLU_NURBS_NORMAL, normalCallback); + gluNurbsCallback(theNurb, GLU_NURBS_END, endCallback); + +} + +static void display(void) +{ + GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0}; + int i, j; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(330.0, 1.,0.,0.); + glScalef (0.5, 0.5, 0.5); + + gluBeginSurface(theNurb); + gluNurbsSurface(theNurb, + 8, knots, 8, knots, + 4 * 3, 3, &ctlpoints[0][0][0], + 4, 4, GL_MAP2_VERTEX_3); + gluEndSurface(theNurb); + + if (showPoints) { + glPointSize(5.0); + glDisable(GL_LIGHTING); + glColor3f(1.0, 1.0, 0.0); + glBegin(GL_POINTS); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + glVertex3f(ctlpoints[i][j][0], + ctlpoints[i][j][1], ctlpoints[i][j][2]); + } + } + glEnd(); + glEnable(GL_LIGHTING); + } + glPopMatrix(); + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, (GLdouble)w/(GLdouble)h, 3.0, 8.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef (0.0, 0.0, -5.0); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'c': + case 'C': + showPoints = !showPoints; + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow(argv[0]); + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} + +#else +int main(int argc, char** argv) +{ + fprintf (stderr, "This program demonstrates a feature which is introduced in the\n"); + fprintf (stderr, "OpenGL Utility Library (GLU) Version 1.3.\n"); + fprintf (stderr, "If your implementation of GLU has the right extensions,\n"); + fprintf (stderr, "you may be able to modify this program to make it run.\n"); + return 0; +} +#endif + diff --git a/progs/redbook/teaambient.c b/progs/redbook/teaambient.c index 53b5111752f..20ff1a4a33b 100644 --- a/progs/redbook/teaambient.c +++ b/progs/redbook/teaambient.c @@ -47,7 +47,7 @@ /* Initialize light source and lighting model. */ -void +static void myinit(void) { GLfloat light_ambient[] = @@ -78,7 +78,7 @@ myinit(void) glEnable(GL_DEPTH_TEST); } -void +static void display(void) { GLfloat low_ambient[] = @@ -114,7 +114,7 @@ display(void) glFlush(); } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/teapots.c b/progs/redbook/teapots.c index fb7aed380eb..102c18a3e33 100644 --- a/progs/redbook/teapots.c +++ b/progs/redbook/teapots.c @@ -49,7 +49,7 @@ * Initialize depth buffer, projection matrix, light source, and lighting * model. Do not specify a material property here. */ -void +static void myinit(void) { GLfloat ambient[] = @@ -83,7 +83,7 @@ myinit(void) * Move object into position. Use 3rd through 12th parameters to specify the * material property. Draw a teapot. */ -void +static void renderTeapot(GLfloat x, GLfloat y, GLfloat ambr, GLfloat ambg, GLfloat ambb, GLfloat difr, GLfloat difg, GLfloat difb, @@ -117,7 +117,7 @@ renderTeapot(GLfloat x, GLfloat y, * 3rd column: black, cyan, green, red, white, yellow plastic * 4th column: black, cyan, green, red, white, yellow rubber */ -void +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -173,7 +173,7 @@ display(void) glFlush(); } -void +static void myReshape(int w, int h) { glViewport(0, 0, w, h); diff --git a/progs/redbook/tess.c b/progs/redbook/tess.c index 238a469aff2..0bf8a8eb986 100644 --- a/progs/redbook/tess.c +++ b/progs/redbook/tess.c @@ -61,7 +61,7 @@ GLuint startList; -void display (void) { +static void display (void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glCallList(startList); @@ -69,12 +69,12 @@ void display (void) { glFlush(); } -void CALLBACK beginCallback(GLenum which) +static void CALLBACK beginCallback(GLenum which) { glBegin(which); } -void CALLBACK errorCallback(GLenum errorCode) +static void CALLBACK errorCallback(GLenum errorCode) { const GLubyte *estring; @@ -83,12 +83,12 @@ void CALLBACK errorCallback(GLenum errorCode) exit(0); } -void CALLBACK endCallback(void) +static void CALLBACK endCallback(void) { glEnd(); } -void CALLBACK vertexCallback(GLvoid *vertex) +static void CALLBACK vertexCallback(GLvoid *vertex) { const GLdouble *pointer; @@ -102,7 +102,7 @@ void CALLBACK vertexCallback(GLvoid *vertex) * but weight[4] may be used to average color, normal, or texture * coordinate data. In this program, color is weighted. */ -void CALLBACK combineCallback(GLdouble coords[3], +static void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut ) { @@ -122,7 +122,7 @@ void CALLBACK combineCallback(GLdouble coords[3], *dataOut = vertex; } -void init (void) +static void init (void) { GLUtesselator *tobj; GLdouble rect[4][3] = {{50.0, 50.0, 0.0}, @@ -199,7 +199,7 @@ void init (void) gluDeleteTess(tobj); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -208,7 +208,7 @@ void reshape (int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/tesswind.c b/progs/redbook/tesswind.c index 7d00c9f907d..4729880a57e 100644 --- a/progs/redbook/tesswind.c +++ b/progs/redbook/tesswind.c @@ -61,7 +61,7 @@ GLuint list; /* Make four display lists, * each with a different tessellated object. */ -void makeNewLists (void) { +static void makeNewLists (void) { int i; static GLdouble rects[12][3] = {{ 50.0, 50.0, 0.0}, {300.0, 50.0, 0.0}, @@ -153,7 +153,7 @@ void makeNewLists (void) { glEndList(); } -void display (void) { +static void display (void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); @@ -168,12 +168,12 @@ void display (void) { glFlush(); } -void CALLBACK beginCallback(GLenum which) +static void CALLBACK beginCallback(GLenum which) { glBegin(which); } -void CALLBACK errorCallback(GLenum errorCode) +static void CALLBACK errorCallback(GLenum errorCode) { const GLubyte *estring; @@ -182,7 +182,7 @@ void CALLBACK errorCallback(GLenum errorCode) exit(0); } -void CALLBACK endCallback(void) +static void CALLBACK endCallback(void) { glEnd(); } @@ -193,7 +193,7 @@ void CALLBACK endCallback(void) * coordinate data. */ /* ARGSUSED */ -void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4], +static void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4], GLfloat weight[4], GLdouble **dataOut ) { GLdouble *vertex; @@ -205,7 +205,7 @@ void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4], *dataOut = vertex; } -void init(void) +static void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -226,7 +226,7 @@ void init(void) makeNewLists(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -240,7 +240,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'w': diff --git a/progs/redbook/texbind.c b/progs/redbook/texbind.c index 6a828ab2bdf..b6404b32d8c 100644 --- a/progs/redbook/texbind.c +++ b/progs/redbook/texbind.c @@ -52,7 +52,7 @@ static GLubyte otherImage[checkImageHeight][checkImageWidth][4]; static GLuint texName[2]; -void makeCheckImages(void) +static void makeCheckImages(void) { int i, j, c; @@ -72,7 +72,7 @@ void makeCheckImages(void) } } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -105,7 +105,7 @@ void init(void) glEnable(GL_TEXTURE_2D); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, texName[0]); @@ -125,7 +125,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -137,7 +137,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/texgen.c b/progs/redbook/texgen.c index 7c1802a3be9..5cb97e5a43d 100644 --- a/progs/redbook/texgen.c +++ b/progs/redbook/texgen.c @@ -60,7 +60,7 @@ GLubyte stripeImage[4*stripeImageWidth]; static GLuint texName; #endif -void makeStripeImage(void) +static void makeStripeImage(void) { int j; @@ -79,7 +79,7 @@ static GLfloat *currentCoeff; static GLenum currentPlane; static GLint currentGenMode; -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); @@ -122,7 +122,7 @@ void init(void) glMaterialf (GL_FRONT, GL_SHININESS, 64.0); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -136,7 +136,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -152,7 +152,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 'e': diff --git a/progs/redbook/texprox.c b/progs/redbook/texprox.c index 6f1e853facd..c2d699a71b2 100644 --- a/progs/redbook/texprox.c +++ b/progs/redbook/texprox.c @@ -53,7 +53,7 @@ #define GL_TEXTURE_INTERNAL_FORMAT GL_TEXTURE_COMPONENTS #endif -void init(void) +static void init(void) { GLint proxyComponents; @@ -84,12 +84,12 @@ void init(void) putchar('\n'); } -void display(void) +static void display(void) { exit(0); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); diff --git a/progs/redbook/texsub.c b/progs/redbook/texsub.c index 4e829675aba..7827d5a45f3 100644 --- a/progs/redbook/texsub.c +++ b/progs/redbook/texsub.c @@ -58,7 +58,7 @@ static GLubyte subImage[subImageHeight][subImageWidth][4]; static GLuint texName; -void makeCheckImages(void) +static void makeCheckImages(void) { int i, j, c; @@ -82,7 +82,7 @@ void makeCheckImages(void) } } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -102,7 +102,7 @@ void init(void) 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); @@ -123,7 +123,7 @@ void display(void) glDisable(GL_TEXTURE_2D); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -135,7 +135,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 's': diff --git a/progs/redbook/texture3d.c b/progs/redbook/texture3d.c new file mode 100644 index 00000000000..c7b77c1caeb --- /dev/null +++ b/progs/redbook/texture3d.c @@ -0,0 +1,163 @@ +/* + * Copyright (c) 1993-2003, 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. + * 1500 Crittenden Lane + * Mountain View, CA 94043 + * United State of America + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* texture3d.c + * This program demonstrates using a three-dimensional texture. + * It creates a 3D texture and then renders two rectangles + * with different texture coordinates to obtain different + * "slices" of the 3D texture. + */ +#include <GL/glew.h> +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef GL_VERSION_1_2 +#define iWidth 16 +#define iHeight 16 +#define iDepth 16 + +static GLubyte image[iDepth][iHeight][iWidth][3]; +static GLuint texName; + +/* Create a 16x16x16x3 array with different color values in + * each array element [r, g, b]. Values range from 0 to 255. + */ + +static void makeImage(void) +{ + int s, t, r; + + for (s = 0; s < 16; s++) + for (t = 0; t < 16; t++) + for (r = 0; r < 16; r++) { + image[r][t][s][0] = (GLubyte) (s * 17); + image[r][t][s][1] = (GLubyte) (t * 17); + image[r][t][s][2] = (GLubyte) (r * 17); + } +} + +static void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + makeImage(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glGenTextures(1, &texName); + glBindTexture(GL_TEXTURE_3D, texName); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, iWidth, iHeight, + iDepth, 0, GL_RGB, GL_UNSIGNED_BYTE, image); + glEnable(GL_TEXTURE_3D); +} + +static void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord3f(0.0, 0.0, 0.0); glVertex3f(-2.25, -1.0, 0.0); + glTexCoord3f(0.0, 1.0, 0.0); glVertex3f(-2.25, 1.0, 0.0); + glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(-0.25, 1.0, 0.0); + glTexCoord3f(1.0, 0.0, 1.0); glVertex3f(-0.25, -1.0, 0.0); + + glTexCoord3f(0.0, 0.0, 1.0); glVertex3f(0.25, -1.0, 0.0); + glTexCoord3f(0.0, 1.0, 1.0); glVertex3f(0.25, 1.0, 0.0); + glTexCoord3f(1.0, 1.0, 0.0); glVertex3f(2.25, 1.0, 0.0); + glTexCoord3f(1.0, 0.0, 0.0); glVertex3f(2.25, -1.0, 0.0); + glEnd(); + glFlush(); +} + +static void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -4.0); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(250, 250); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + glewInit(); + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} +#else +int main(int argc, char** argv) +{ + fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0 or 1.1.\n"); + fprintf (stderr, "If your implementation of OpenGL has the right extensions,\n"); + fprintf (stderr, "you may be able to modify this program to make it run.\n"); + return 0; +} +#endif + diff --git a/progs/redbook/texturesurf.c b/progs/redbook/texturesurf.c index 0170070eaa5..2023072dba8 100644 --- a/progs/redbook/texturesurf.c +++ b/progs/redbook/texturesurf.c @@ -60,7 +60,7 @@ GLfloat ctrlpoints[4][4][3] = { GLfloat texpts[2][2][2] = {{{0.0, 0.0}, {0.0, 1.0}}, {{1.0, 0.0}, {1.0, 1.0}}}; -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); @@ -72,7 +72,7 @@ void display(void) #define imageHeight 64 GLubyte image[3*imageWidth*imageHeight]; -void makeImage(void) +static void makeImage(void) { int i, j; float ti, tj; @@ -89,7 +89,7 @@ void makeImage(void) } } -void myinit(void) +static void myinit(void) { glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]); @@ -112,7 +112,7 @@ void myinit(void) glShadeModel (GL_FLAT); } -void myReshape(int w, int h) +static void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); diff --git a/progs/redbook/torus.c b/progs/redbook/torus.c index 7ae4d41e263..a67d48e0f59 100644 --- a/progs/redbook/torus.c +++ b/progs/redbook/torus.c @@ -89,7 +89,7 @@ static void init(void) } /* Clear window and draw torus */ -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); @@ -98,7 +98,7 @@ void display(void) } /* Handle window resize */ -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -112,7 +112,7 @@ void reshape(int w, int h) /* Rotate about x-axis when "x" typed; rotate about y-axis when "y" typed; "i" returns torus to original view */ /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'x': diff --git a/progs/redbook/trim.c b/progs/redbook/trim.c index f17674f6840..216f62a7c2f 100644 --- a/progs/redbook/trim.c +++ b/progs/redbook/trim.c @@ -59,7 +59,7 @@ GLUnurbsObj *theNurb; * Initializes the control points of the surface to a small hill. * The control points range from -3 to +3 in x, y, and z */ -void init_surface(void) +static void init_surface(void) { int u, v; for (u = 0; u < 4; u++) { @@ -75,7 +75,7 @@ void init_surface(void) } } -void nurbsError(GLenum errorCode) +static void nurbsError(GLenum errorCode) { const GLubyte *estring; @@ -86,7 +86,7 @@ void nurbsError(GLenum errorCode) /* Initialize material property and depth buffer. */ -void init(void) +static void init(void) { GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; @@ -112,7 +112,7 @@ void init(void) (GLvoid (CALLBACK*) ()) nurbsError); } -void display(void) +static void display(void) { GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0}; GLfloat edgePt[5][2] = /* counter clockwise */ @@ -147,7 +147,7 @@ void display(void) glFlush(); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -160,7 +160,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/unproject.c b/progs/redbook/unproject.c index 134c361bac5..6d1c7dbeded 100644 --- a/progs/redbook/unproject.c +++ b/progs/redbook/unproject.c @@ -45,14 +45,14 @@ #include <stdlib.h> #include <stdio.h> -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT); glFlush(); } /* Change these values for a different transformation */ -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -62,7 +62,7 @@ void reshape(int w, int h) glLoadIdentity(); } -void mouse(int button, int state, int x, int y) +static void mouse(int button, int state, int x, int y) { GLint viewport[4]; GLdouble mvmatrix[16], projmatrix[16]; @@ -98,7 +98,7 @@ void mouse(int button, int state, int x, int y) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/varray.c b/progs/redbook/varray.c index b22e723e0ec..8ce39d77633 100644 --- a/progs/redbook/varray.c +++ b/progs/redbook/varray.c @@ -54,7 +54,7 @@ int setupMethod = POINTER; int derefMethod = DRAWARRAY; -void setupPointers(void) +static void setupPointers(void) { static GLint vertices[] = {25, 25, 100, 325, @@ -76,7 +76,7 @@ void setupPointers(void) glColorPointer (3, GL_FLOAT, 0, colors); } -void setupInterleave(void) +static void setupInterleave(void) { static GLfloat intertwined[] = {1.0, 0.2, 1.0, 100.0, 100.0, 0.0, @@ -89,14 +89,14 @@ void setupInterleave(void) glInterleavedArrays (GL_C3F_V3F, 0, intertwined); } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); setupPointers (); } -void display(void) +static void display(void) { glClear (GL_COLOR_BUFFER_BIT); @@ -117,7 +117,7 @@ void display(void) glFlush (); } -void reshape (int w, int h) +static void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); @@ -126,7 +126,7 @@ void reshape (int w, int h) } /* ARGSUSED2 */ -void mouse (int button, int state, int x, int y) +static void mouse (int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: @@ -160,7 +160,7 @@ void mouse (int button, int state, int x, int y) } /* ARGSUSED1 */ -void keyboard(unsigned char key, int x, int y) +static void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: diff --git a/progs/redbook/wrap.c b/progs/redbook/wrap.c index f9a1f162ab6..67749716e83 100644 --- a/progs/redbook/wrap.c +++ b/progs/redbook/wrap.c @@ -59,7 +59,7 @@ static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; static GLuint texName; #endif -void makeCheckImage(void) +static void makeCheckImage(void) { int i, j, c; @@ -74,7 +74,7 @@ void makeCheckImage(void) } } -void init(void) +static void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); @@ -101,7 +101,7 @@ void init(void) #endif } -void display(void) +static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); @@ -125,7 +125,7 @@ void display(void) glDisable(GL_TEXTURE_2D); } -void reshape(int w, int h) +static void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); @@ -137,7 +137,7 @@ void reshape(int w, int h) } /* ARGSUSED1 */ -void keyboard (unsigned char key, int x, int y) +static void keyboard (unsigned char key, int x, int y) { switch (key) { case 's': |