From afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c Mon Sep 17 00:00:00 2001 From: jtg Date: Thu, 19 Aug 1999 00:55:39 +0000 Subject: Initial revision --- progs/beos/Makefile | 42 + progs/beos/demo.cpp | 153 + progs/beos/sample.cpp | 212 ++ progs/demos/Makefile.BeOS-R4 | 96 + progs/demos/Makefile.X11 | 60 + progs/demos/Makefile.cygnus | 76 + progs/demos/bounce.c | 240 ++ progs/demos/clearspd.c | 221 ++ progs/demos/descrip.mms | 63 + progs/demos/drawpix.c | 307 ++ progs/demos/gamma.c | 176 + progs/demos/gears.c | 356 ++ progs/demos/glinfo.c | 50 + progs/demos/glutfx.c | 207 ++ progs/demos/isosurf.c | 821 +++++ progs/demos/isosurf.dat | 7179 ++++++++++++++++++++++++++++++++++++++++ progs/demos/morph3d.c | 892 +++++ progs/demos/multiarb.c | 307 ++ progs/demos/osdemo.c | 169 + progs/demos/paltex.c | 186 ++ progs/demos/pointblast.c | 506 +++ progs/demos/reflect.c | 435 +++ progs/demos/renormal.c | 123 + progs/demos/spectex.c | 277 ++ progs/demos/stex3d.c | 578 ++++ progs/demos/tessdemo.c | 439 +++ progs/demos/texcyl.c | 261 ++ progs/demos/texobj.c | 289 ++ progs/demos/trispd.c | 277 ++ progs/demos/winpos.c | 128 + progs/images/girl.rgb | Bin 0 -> 89287 bytes progs/images/reflect.rgb | Bin 0 -> 39632 bytes progs/images/tile.rgb | Bin 0 -> 206534 bytes progs/redbook/Imakefile | 222 ++ progs/redbook/Makefile.BeOS-R4 | 70 + progs/redbook/Makefile.X11 | 64 + progs/redbook/Makefile.win | 81 + progs/redbook/README | 41 + progs/redbook/aaindex.c | 153 + progs/redbook/aapoly.c | 172 + progs/redbook/aargb.c | 149 + progs/redbook/accanti.c | 168 + progs/redbook/accpersp.c | 240 ++ progs/redbook/alpha.c | 143 + progs/redbook/alpha3D.c | 175 + progs/redbook/anti.c | 111 + progs/redbook/bezcurve.c | 114 + progs/redbook/bezmesh.c | 148 + progs/redbook/checker.c | 125 + progs/redbook/clip.c | 108 + progs/redbook/colormat.c | 153 + progs/redbook/cube.c | 97 + progs/redbook/depthcue.c | 102 + progs/redbook/dof.c | 238 ++ progs/redbook/double.c | 119 + progs/redbook/drawf.c | 103 + progs/redbook/feedback.c | 171 + progs/redbook/fog.c | 186 ++ progs/redbook/fogindex.c | 138 + progs/redbook/font.c | 167 + progs/redbook/hello.c | 95 + progs/redbook/image.c | 159 + progs/redbook/jitter.h | 222 ++ progs/redbook/light.c | 113 + progs/redbook/lines.c | 138 + progs/redbook/list.c | 125 + progs/redbook/material.c | 293 ++ progs/redbook/mipmap.c | 165 + progs/redbook/model.c | 126 + progs/redbook/movelight.c | 148 + progs/redbook/nurbs.c | 176 + progs/redbook/pickdepth.c | 203 ++ progs/redbook/picksquare.c | 197 ++ progs/redbook/plane.c | 157 + progs/redbook/planet.c | 123 + progs/redbook/polyoff.c | 237 ++ progs/redbook/polys.c | 124 + progs/redbook/quadric.c | 189 ++ progs/redbook/robot.c | 132 + progs/redbook/sccolorlight.c | 127 + progs/redbook/scene.c | 127 + progs/redbook/scenebamb.c | 126 + progs/redbook/sceneflat.c | 126 + progs/redbook/select.c | 222 ++ progs/redbook/smooth.c | 106 + progs/redbook/stencil.c | 162 + progs/redbook/stroke.c | 181 + progs/redbook/surface.c | 217 ++ progs/redbook/teaambient.c | 148 + progs/redbook/teapots.c | 206 ++ progs/redbook/tess.c | 241 ++ progs/redbook/tesswind.c | 290 ++ progs/redbook/texbind.c | 172 + progs/redbook/texgen.c | 207 ++ progs/redbook/texprox.c | 120 + progs/redbook/texsub.c | 187 ++ progs/redbook/texturesurf.c | 141 + progs/redbook/torus.c | 152 + progs/redbook/trim.c | 187 ++ progs/redbook/unproject.c | 126 + progs/redbook/varray.c | 195 ++ progs/redbook/wrap.c | 180 + progs/samples/Imakefile | 102 + progs/samples/Makefile.BeOS-R4 | 64 + progs/samples/Makefile.DJ | 36 + progs/samples/Makefile.X11 | 61 + progs/samples/Makefile.dja | 26 + progs/samples/README | 520 +++ progs/samples/accum.c | 157 + progs/samples/bitmap1.c | 250 ++ progs/samples/bitmap2.c | 787 +++++ progs/samples/blendeq.c | 295 ++ progs/samples/blendxor.c | 174 + progs/samples/copy.c | 193 ++ progs/samples/cursor.c | 150 + progs/samples/depth.c | 209 ++ progs/samples/eval.c | 472 +++ progs/samples/fog.c | 311 ++ progs/samples/font.c | 273 ++ progs/samples/line.c | 219 ++ progs/samples/loadppm.c | 72 + progs/samples/logo.c | 1630 +++++++++ progs/samples/nurb.c | 355 ++ progs/samples/oglinfo.c | 218 ++ progs/samples/olympic.c | 375 +++ progs/samples/overlay.c | 378 +++ progs/samples/point.c | 234 ++ progs/samples/prim.c | 546 +++ progs/samples/quad.c | 455 +++ progs/samples/rgbtoppm.c | 273 ++ progs/samples/select.c | 456 +++ progs/samples/shape.c | 345 ++ progs/samples/sphere.c | 1034 ++++++ progs/samples/star.c | 331 ++ progs/samples/stencil.c | 143 + progs/samples/stretch.c | 375 +++ progs/samples/texture.c | 474 +++ progs/samples/tkmap.c | 71 + progs/samples/tri.c | 403 +++ progs/samples/wave.c | 602 ++++ progs/util/README | 22 + progs/util/dumpstate.c | 1959 +++++++++++ progs/util/errcheck.c | 27 + progs/util/glstate.c | 504 +++ progs/util/glstate.h | 53 + progs/util/glutskel.c | 145 + progs/util/idproj.c | 26 + progs/util/imagesgi.cpp | 369 +++ progs/util/imagesgi.h | 55 + progs/util/mwmborder.c | 91 + progs/util/readtex.c | 353 ++ progs/util/sampleMakefile | 49 + progs/util/showbuffer.c | 192 ++ progs/util/showbuffer.h | 36 + progs/util/winpos.c | 42 + progs/xdemos/Makefile.X11 | 58 + progs/xdemos/descrip.mms | 79 + progs/xdemos/glxdemo.c | 136 + progs/xdemos/glxpixmap.c | 160 + progs/xdemos/offset.c | 323 ++ progs/xdemos/shape.c | 305 ++ progs/xdemos/vgears.c | 282 ++ progs/xdemos/vindex.c | 66 + progs/xdemos/vtest.c | 83 + progs/xdemos/xdemo.c | 347 ++ progs/xdemos/xfont.c | 148 + 166 files changed, 44931 insertions(+) create mode 100644 progs/beos/Makefile create mode 100644 progs/beos/demo.cpp create mode 100644 progs/beos/sample.cpp create mode 100644 progs/demos/Makefile.BeOS-R4 create mode 100644 progs/demos/Makefile.X11 create mode 100644 progs/demos/Makefile.cygnus create mode 100644 progs/demos/bounce.c create mode 100644 progs/demos/clearspd.c create mode 100644 progs/demos/descrip.mms create mode 100644 progs/demos/drawpix.c create mode 100644 progs/demos/gamma.c create mode 100644 progs/demos/gears.c create mode 100644 progs/demos/glinfo.c create mode 100644 progs/demos/glutfx.c create mode 100644 progs/demos/isosurf.c create mode 100644 progs/demos/isosurf.dat create mode 100644 progs/demos/morph3d.c create mode 100644 progs/demos/multiarb.c create mode 100644 progs/demos/osdemo.c create mode 100644 progs/demos/paltex.c create mode 100644 progs/demos/pointblast.c create mode 100644 progs/demos/reflect.c create mode 100644 progs/demos/renormal.c create mode 100644 progs/demos/spectex.c create mode 100644 progs/demos/stex3d.c create mode 100644 progs/demos/tessdemo.c create mode 100644 progs/demos/texcyl.c create mode 100644 progs/demos/texobj.c create mode 100644 progs/demos/trispd.c create mode 100644 progs/demos/winpos.c create mode 100644 progs/images/girl.rgb create mode 100644 progs/images/reflect.rgb create mode 100644 progs/images/tile.rgb create mode 100644 progs/redbook/Imakefile create mode 100644 progs/redbook/Makefile.BeOS-R4 create mode 100644 progs/redbook/Makefile.X11 create mode 100644 progs/redbook/Makefile.win create mode 100644 progs/redbook/README create mode 100644 progs/redbook/aaindex.c create mode 100644 progs/redbook/aapoly.c create mode 100644 progs/redbook/aargb.c create mode 100644 progs/redbook/accanti.c create mode 100644 progs/redbook/accpersp.c create mode 100644 progs/redbook/alpha.c create mode 100644 progs/redbook/alpha3D.c create mode 100644 progs/redbook/anti.c create mode 100644 progs/redbook/bezcurve.c create mode 100644 progs/redbook/bezmesh.c create mode 100644 progs/redbook/checker.c create mode 100644 progs/redbook/clip.c create mode 100644 progs/redbook/colormat.c create mode 100644 progs/redbook/cube.c create mode 100644 progs/redbook/depthcue.c create mode 100644 progs/redbook/dof.c create mode 100644 progs/redbook/double.c create mode 100644 progs/redbook/drawf.c create mode 100644 progs/redbook/feedback.c create mode 100644 progs/redbook/fog.c create mode 100644 progs/redbook/fogindex.c create mode 100644 progs/redbook/font.c create mode 100644 progs/redbook/hello.c create mode 100644 progs/redbook/image.c create mode 100644 progs/redbook/jitter.h create mode 100644 progs/redbook/light.c create mode 100644 progs/redbook/lines.c create mode 100644 progs/redbook/list.c create mode 100644 progs/redbook/material.c create mode 100644 progs/redbook/mipmap.c create mode 100644 progs/redbook/model.c create mode 100644 progs/redbook/movelight.c create mode 100644 progs/redbook/nurbs.c create mode 100644 progs/redbook/pickdepth.c create mode 100644 progs/redbook/picksquare.c create mode 100644 progs/redbook/plane.c create mode 100644 progs/redbook/planet.c create mode 100644 progs/redbook/polyoff.c create mode 100644 progs/redbook/polys.c create mode 100644 progs/redbook/quadric.c create mode 100644 progs/redbook/robot.c create mode 100644 progs/redbook/sccolorlight.c create mode 100644 progs/redbook/scene.c create mode 100644 progs/redbook/scenebamb.c create mode 100644 progs/redbook/sceneflat.c create mode 100644 progs/redbook/select.c create mode 100644 progs/redbook/smooth.c create mode 100644 progs/redbook/stencil.c create mode 100644 progs/redbook/stroke.c create mode 100644 progs/redbook/surface.c create mode 100644 progs/redbook/teaambient.c create mode 100644 progs/redbook/teapots.c create mode 100644 progs/redbook/tess.c create mode 100644 progs/redbook/tesswind.c create mode 100644 progs/redbook/texbind.c create mode 100644 progs/redbook/texgen.c create mode 100644 progs/redbook/texprox.c create mode 100644 progs/redbook/texsub.c create mode 100644 progs/redbook/texturesurf.c create mode 100644 progs/redbook/torus.c create mode 100644 progs/redbook/trim.c create mode 100644 progs/redbook/unproject.c create mode 100644 progs/redbook/varray.c create mode 100644 progs/redbook/wrap.c create mode 100644 progs/samples/Imakefile create mode 100644 progs/samples/Makefile.BeOS-R4 create mode 100644 progs/samples/Makefile.DJ create mode 100644 progs/samples/Makefile.X11 create mode 100644 progs/samples/Makefile.dja create mode 100644 progs/samples/README create mode 100644 progs/samples/accum.c create mode 100644 progs/samples/bitmap1.c create mode 100644 progs/samples/bitmap2.c create mode 100644 progs/samples/blendeq.c create mode 100644 progs/samples/blendxor.c create mode 100644 progs/samples/copy.c create mode 100644 progs/samples/cursor.c create mode 100644 progs/samples/depth.c create mode 100644 progs/samples/eval.c create mode 100644 progs/samples/fog.c create mode 100644 progs/samples/font.c create mode 100644 progs/samples/line.c create mode 100644 progs/samples/loadppm.c create mode 100644 progs/samples/logo.c create mode 100644 progs/samples/nurb.c create mode 100644 progs/samples/oglinfo.c create mode 100644 progs/samples/olympic.c create mode 100644 progs/samples/overlay.c create mode 100644 progs/samples/point.c create mode 100644 progs/samples/prim.c create mode 100644 progs/samples/quad.c create mode 100644 progs/samples/rgbtoppm.c create mode 100644 progs/samples/select.c create mode 100644 progs/samples/shape.c create mode 100644 progs/samples/sphere.c create mode 100644 progs/samples/star.c create mode 100644 progs/samples/stencil.c create mode 100644 progs/samples/stretch.c create mode 100644 progs/samples/texture.c create mode 100644 progs/samples/tkmap.c create mode 100644 progs/samples/tri.c create mode 100644 progs/samples/wave.c create mode 100644 progs/util/README create mode 100644 progs/util/dumpstate.c create mode 100644 progs/util/errcheck.c create mode 100644 progs/util/glstate.c create mode 100644 progs/util/glstate.h create mode 100644 progs/util/glutskel.c create mode 100644 progs/util/idproj.c create mode 100644 progs/util/imagesgi.cpp create mode 100644 progs/util/imagesgi.h create mode 100644 progs/util/mwmborder.c create mode 100644 progs/util/readtex.c create mode 100644 progs/util/sampleMakefile create mode 100644 progs/util/showbuffer.c create mode 100644 progs/util/showbuffer.h create mode 100644 progs/util/winpos.c create mode 100644 progs/xdemos/Makefile.X11 create mode 100644 progs/xdemos/descrip.mms create mode 100644 progs/xdemos/glxdemo.c create mode 100644 progs/xdemos/glxpixmap.c create mode 100644 progs/xdemos/offset.c create mode 100644 progs/xdemos/shape.c create mode 100644 progs/xdemos/vgears.c create mode 100644 progs/xdemos/vindex.c create mode 100644 progs/xdemos/vtest.c create mode 100644 progs/xdemos/xdemo.c create mode 100644 progs/xdemos/xfont.c (limited to 'progs') diff --git a/progs/beos/Makefile b/progs/beos/Makefile new file mode 100644 index 0000000000..0d9c27b539 --- /dev/null +++ b/progs/beos/Makefile @@ -0,0 +1,42 @@ +# $Id: Makefile,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Makefile for BeOS demos + +# Written by Brian Paul +# This file is in the public domain. + + + +CC = g++ + +# Use Mesa: +CFLAGS = -I../include -c -g +LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lMesaGL + +# Use BeOS OpenGL: +#CFLAGS = -I/boot/develop/headers/be/opengl -c -g +#LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lGL + + +PROGRAMS = demo sample + +default: $(PROGRAMS) + + +clean: + rm -f demo sample + rm -f *.o + + +demo: demo.o + $(CC) demo.o $(LFLAGS) -o $@ + +demo.o: demo.cpp + $(CC) $(CFLAGS) demo.cpp + + +sample: sample.o + $(CC) sample.o $(LFLAGS) -o $@ + +sample.o: sample.cpp + $(CC) $(CFLAGS) sample.cpp diff --git a/progs/beos/demo.cpp b/progs/beos/demo.cpp new file mode 100644 index 0000000000..c25eb93075 --- /dev/null +++ b/progs/beos/demo.cpp @@ -0,0 +1,153 @@ +// $Id: demo.cpp,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +// Simple BeOS GLView demo +// Written by Brian Paul +// This file is in the public domain. + + + +#include +#include +#include +#include + + +class MyWindow : public BWindow +{ +public: + MyWindow(BRect frame); + virtual bool QuitRequested(); +}; + + +MyWindow::MyWindow(BRect frame) + : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE) +{ + // no-op +} + +bool MyWindow::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +class MyGL : public BGLView +{ +public: + MyGL(BRect rect, char *name, ulong options); + +// virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + virtual void Pulse(); + virtual void FrameResized(float w, float h); +private: + float mAngle; +}; + + +MyGL::MyGL(BRect rect, char *name, ulong options) + : BGLView(rect, name, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, options) +{ + mAngle = 0.0; +} + + +#if 0 +void MyGL::AttachedToWindow() +{ + BGLView::AttachedToWindow(); + LockGL(); + glClearColor(.7, .7, 0, 0); + UnlockGL(); +} +#endif + + +void MyGL::FrameResized(float w, float h) +{ + BGLView::FrameResized(w, h); + + printf("FrameResized\n"); + LockGL(); + BGLView::FrameResized(w,h); + glViewport(0, 0, (int) (w + 1), (int) (h + 1)); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 10, 30); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -18); + UnlockGL(); +} + + + +void MyGL::Draw(BRect r) +{ + printf("MyGL::Draw\n"); + BGLView::Draw(r); + LockGL(); + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(mAngle, 0, 0, 1); + glColor3f(0, 0, 1); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + SwapBuffers(); + UnlockGL(); +} + + +void MyGL::Pulse() +{ + printf("pulse\n"); + BGLView::Pulse(); + mAngle += 1.0; + + LockGL(); + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(mAngle, 0, 0, 1); + glColor3f(0, 0, 1); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + SwapBuffers(); + UnlockGL(); +} + + + +int main(int argc, char *argv[]) +{ + BApplication *app = new BApplication("application/demo"); + + // make top-level window + int x = 500, y = 500; + int w = 400, h = 400; + MyWindow *win = new MyWindow(BRect(x, y, x + w, y + h)); + // win->Lock(); + // win->Unlock(); + win->Show(); + + // Make OpenGL view and put it in the window + MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB | BGL_DOUBLE); + // MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB ); + win->AddChild(gl); + + printf("calling app->Run\n"); + app->Run(); + + delete app; + + return 0; +} diff --git a/progs/beos/sample.cpp b/progs/beos/sample.cpp new file mode 100644 index 0000000000..2310b33882 --- /dev/null +++ b/progs/beos/sample.cpp @@ -0,0 +1,212 @@ +// sample BGLView app from the Be Book + + +#include +#include +#include +#include + + +class SampleGLView : public BGLView +{ +public: + SampleGLView(BRect frame, uint32 type); + virtual void AttachedToWindow(void); + virtual void FrameResized(float newWidth, float newHeight); + virtual void ErrorCallback(GLenum which); + + void Render(void); + +private: + void gInit(void); + void gDraw(void); + void gReshape(int width, int height); + + float width; + float height; +}; + + + +class SampleGLWindow : public BWindow +{ +public: + SampleGLWindow(BRect frame, uint32 type); + virtual bool QuitRequested() { return true; } + +private: + SampleGLView *theView; +}; + + +class SampleGLApp : public BApplication +{ +public: + SampleGLApp(); +private: + SampleGLWindow *theWindow; +}; + + +SampleGLApp::SampleGLApp() + : BApplication("application/x-vnd.sample") +{ + BRect windowRect; + uint32 type = BGL_RGB|BGL_DOUBLE; + + windowRect.Set(50, 50, 350, 350); + + theWindow = new SampleGLWindow(windowRect, type); +} + + + +SampleGLWindow::SampleGLWindow(BRect frame, uint32 type) + : BWindow(frame, "OpenGL Test", B_TITLED_WINDOW, 0) +{ + theView = new SampleGLView(Bounds(), type); + AddChild(theView); + Show(); + theView->Render(); +} + + + +SampleGLView::SampleGLView(BRect frame, uint32 type) + : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type) +{ + width = frame.right-frame.left; + height = frame.bottom-frame.top; +} + + +void SampleGLView::AttachedToWindow(void) +{ + LockGL(); + BGLView::AttachedToWindow(); + gInit(); + gReshape(width, height); + UnlockGL(); +} + + +void SampleGLView::FrameResized(float newWidth, float newHeight) +{ + LockGL(); + BGLView::FrameResized(width, height); + width = newWidth; + height = newHeight; + + gReshape(width,height); + + UnlockGL(); + Render(); +} + + +void SampleGLView::ErrorCallback(GLenum whichError) +{ +// fprintf(stderr, "Unexpected error occured (%d):\\n", whichError); +// fprintf(stderr, " %s\\n", gluErrorString(whichError)); +} + + + +// globals +GLenum use_stipple_mode; // GL_TRUE to use dashed lines +GLenum use_smooth_mode; // GL_TRUE to use anti-aliased lines +GLint linesize; // Line width +GLint pointsize; // Point diameter + +float pntA[3] = { + -160.0, 0.0, 0.0 +}; +float pntB[3] = { + -130.0, 0.0, 0.0 +}; + + + +void SampleGLView::gInit(void) +{ + glClearColor(0.0, 0.0, 0.0, 0.0); + glLineStipple(1, 0xF0E0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + use_stipple_mode = GL_FALSE; + use_smooth_mode = GL_TRUE; + linesize = 2; + pointsize = 4; +} + + + +void SampleGLView::gDraw(void) +{ + GLint i; + + glClear(GL_COLOR_BUFFER_BIT); + glLineWidth(linesize); + + if (use_stipple_mode) { + glEnable(GL_LINE_STIPPLE); + } else { + glDisable(GL_LINE_STIPPLE); + } + + if (use_smooth_mode) { + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + } else { + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glPushMatrix(); + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0,0,1); // Rotate right 5 degrees + glColor3f(1.0, 1.0, 0.0); // Set color for line + glBegin(GL_LINE_STRIP); // And create the line + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glPointSize(pointsize); // Set size for point + glColor3f(0.0, 1.0, 0.0); // Set color for point + glBegin(GL_POINTS); + glVertex3fv(pntA); // Draw point at one end + glVertex3fv(pntB); // Draw point at other end + glEnd(); + } + + glPopMatrix(); // Done with matrix +} + + +void SampleGLView::gReshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-175, 175, -175, 175, -1, 1); + glMatrixMode(GL_MODELVIEW); +} + + +void SampleGLView::Render(void) +{ + LockGL(); + gDraw(); + SwapBuffers(); + UnlockGL(); +} + + + +int main(int argc, char *argv[]) +{ + SampleGLApp *app = new SampleGLApp; + app->Run(); + delete app; + return 0; +} diff --git a/progs/demos/Makefile.BeOS-R4 b/progs/demos/Makefile.BeOS-R4 new file mode 100644 index 0000000000..c0d990e4a0 --- /dev/null +++ b/progs/demos/Makefile.BeOS-R4 @@ -0,0 +1,96 @@ +# $Id: Makefile.BeOS-R4,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1999 Brian Paul +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +# Makefile for GLUT-based demo programs for BeOS R4 + + +# $Log: Makefile.BeOS-R4,v $ +# Revision 1.1 1999/08/19 00:55:40 jtg +# Initial revision +# +# Revision 1.5 1999/06/22 12:50:11 brianp +# removed multitex demo +# +# Revision 1.4 1999/02/03 03:57:26 brianp +# replace multiext with multiarb +# +# Revision 1.3 1999/02/02 04:47:45 brianp +# removed glutfx from targets +# +# Revision 1.2 1999/02/02 04:46:23 brianp +# removed tessdemo from targets +# +# Revision 1.1 1999/02/02 04:43:27 brianp +# Initial revision +# + + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -L/boot/home/config/lib -Xlinker -rpath $(LIBDIR) -lbe -lglut -lMesaGLU -lMesaGL $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = bounce clearspd drawpix gamma gears glinfo isosurf \ + morph3d multiarb osdemo paltex pointblast reflect \ + renormal spectex stex3d texcyl texobj trispd winpos + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config + diff --git a/progs/demos/Makefile.X11 b/progs/demos/Makefile.X11 new file mode 100644 index 0000000000..9d475a6ac0 --- /dev/null +++ b/progs/demos/Makefile.X11 @@ -0,0 +1,60 @@ +# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1998 Brian Paul + + +# Makefile for GLUT-based demo programs for Unix/X11 + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = bounce clearspd drawpix gamma gears glinfo glutfx isosurf \ + morph3d multiarb osdemo paltex pointblast reflect \ + renormal spectex stex3d tessdemo texcyl texobj trispd winpos + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config + diff --git a/progs/demos/Makefile.cygnus b/progs/demos/Makefile.cygnus new file mode 100644 index 0000000000..69012b13be --- /dev/null +++ b/progs/demos/Makefile.cygnus @@ -0,0 +1,76 @@ +# Makefile for demo programs +# Stephane Rehel (rehel@worldnet.fr) April 13 1997 + +# Mesa 3-D graphics library +# Version: 3.0 +# Copyright (C) 1995-1998 Brian Paul +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +# $Id: Makefile.cygnus,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# $Log: Makefile.cygnus,v $ +# Revision 1.1 1999/08/19 00:55:40 jtg +# Initial revision +# +# Revision 3.1 1999/06/22 12:50:29 brianp +# removed multitex demo +# +# Revision 3.0 1998/06/10 02:55:51 brianp +# initial revision +# + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -lglut -lMesaGLU -lMesaGL -lm $(WLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = clearspd drawpix gamma gears glinfo glutfx isosurf \ + morph3d multiext osdemo paltex pointblast reflect \ + renormal spectex stex3d tessdemo texcyl texobj trispd winpos + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS:=.exe) + -rm *.o *~ + +targets: $(PROGS) + +include ../Make-config + + diff --git a/progs/demos/bounce.c b/progs/demos/bounce.c new file mode 100644 index 0000000000..876ce589dc --- /dev/null +++ b/progs/demos/bounce.c @@ -0,0 +1,240 @@ +/* $Id: bounce.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Bouncing ball demo. Color index mode only! + * + * This program is in the public domain + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log: bounce.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.3 1999/03/18 08:16:14 joukj + * + * cmpstr needs string.h to included to avoid warnings + * + * Revision 3.2 1998/11/28 01:13:02 brianp + * now sets an initial window position and size + * + * Revision 3.1 1998/11/28 01:06:57 brianp + * now works in RGB mode by default + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + +#define COS(X) cos( (X) * 3.14159/180.0 ) +#define SIN(X) sin( (X) * 3.14159/180.0 ) + +#define RED 1 +#define WHITE 2 +#define CYAN 3 + +GLboolean IndexMode = GL_FALSE; +GLuint Ball; +GLenum Mode; +GLfloat Zrot = 0.0, Zstep = 6.0; +GLfloat Xpos = 0.0, Ypos = 1.0; +GLfloat Xvel = 0.2, Yvel = 0.0; +GLfloat Xmin = -4.0, Xmax = 4.0; +GLfloat Ymin = -3.8, Ymax = 4.0; +GLfloat G = -0.1; + +static GLuint +make_ball(void) +{ + GLuint list; + GLfloat a, b; + GLfloat da = 18.0, db = 18.0; + GLfloat radius = 1.0; + GLuint color; + GLfloat x, y, z; + + list = glGenLists(1); + + glNewList(list, GL_COMPILE); + + color = 0; + for (a = -90.0; a + da <= 90.0; a += da) { + + glBegin(GL_QUAD_STRIP); + for (b = 0.0; b <= 360.0; b += db) { + + if (color) { + glIndexi(RED); + glColor3f(1, 0, 0); + } else { + glIndexi(WHITE); + glColor3f(1, 1, 1); + } + + x = COS(b) * COS(a); + y = SIN(b) * COS(a); + z = SIN(a); + glVertex3f(x, y, z); + + x = radius * COS(b) * COS(a + da); + y = radius * SIN(b) * COS(a + da); + z = radius * SIN(a + da); + glVertex3f(x, y, z); + + color = 1 - color; + } + glEnd(); + + } + + glEndList(); + + return list; +} + +static void +reshape(int width, int height) +{ + float aspect = (float) width / (float) height; + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-6.0 * aspect, 6.0 * aspect, -6.0, 6.0, -6.0, 6.0); + glMatrixMode(GL_MODELVIEW); +} + +/* ARGSUSED1 */ +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + } +} + +static void +draw(void) +{ + GLint i; + + glClear(GL_COLOR_BUFFER_BIT); + + glIndexi(CYAN); + glColor3f(0, 1, 1); + glBegin(GL_LINES); + for (i = -5; i <= 5; i++) { + glVertex2i(i, -5); + glVertex2i(i, 5); + } + for (i = -5; i <= 5; i++) { + glVertex2i(-5, i); + glVertex2i(5, i); + } + for (i = -5; i <= 5; i++) { + glVertex2i(i, -5); + glVertex2f(i * 1.15, -5.9); + } + glVertex2f(-5.3, -5.35); + glVertex2f(5.3, -5.35); + glVertex2f(-5.75, -5.9); + glVertex2f(5.75, -5.9); + glEnd(); + + glPushMatrix(); + glTranslatef(Xpos, Ypos, 0.0); + glScalef(2.0, 2.0, 2.0); + glRotatef(8.0, 0.0, 0.0, 1.0); + glRotatef(90.0, 1.0, 0.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + + glCallList(Ball); + + glPopMatrix(); + + glFlush(); + glutSwapBuffers(); +} + +static void +idle(void) +{ + static float vel0 = -100.0; + + Zrot += Zstep; + + Xpos += Xvel; + if (Xpos >= Xmax) { + Xpos = Xmax; + Xvel = -Xvel; + Zstep = -Zstep; + } + if (Xpos <= Xmin) { + Xpos = Xmin; + Xvel = -Xvel; + Zstep = -Zstep; + } + Ypos += Yvel; + Yvel += G; + if (Ypos < Ymin) { + Ypos = Ymin; + if (vel0 == -100.0) + vel0 = fabs(Yvel); + Yvel = vel0; + } + glutPostRedisplay(); +} + +void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); +} + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(600, 450); + + + IndexMode = argc > 1 && strcmp(argv[1], "-ci") == 0; + if (IndexMode) + glutInitDisplayMode(GLUT_INDEX | GLUT_DOUBLE); + else + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + + glutCreateWindow("Bounce"); + Ball = make_ball(); + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutVisibilityFunc(visible); + glutKeyboardFunc(key); + + if (IndexMode) { + glutSetColor(RED, 1.0, 0.0, 0.0); + glutSetColor(WHITE, 1.0, 1.0, 1.0); + glutSetColor(CYAN, 0.0, 1.0, 1.0); + } + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/clearspd.c b/progs/demos/clearspd.c new file mode 100644 index 0000000000..b2edf32069 --- /dev/null +++ b/progs/demos/clearspd.c @@ -0,0 +1,221 @@ +/* $Id: clearspd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Simple GLUT program to measure glClear() and glutSwapBuffers() speed. + * Brian Paul February 15, 1997 This file in public domain. + */ + +/* + * $Log: clearspd.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.3 1999/03/28 18:18:33 brianp + * minor clean-up + * + * Revision 3.2 1999/03/18 08:16:34 joukj + * + * cmpstr needs string.h to included to avoid warnings + * + * Revision 3.1 1998/06/29 02:38:30 brianp + * removed unneeded includes + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include +#include + + +static float MinPeriod = 2.0; /* 2 seconds */ +static int ColorMode = GLUT_RGB; +static int Width = 400.0; +static int Height = 400.0; +static int Loops = 100; +static float ClearColor = 0.0; +static GLbitfield BufferMask = GL_COLOR_BUFFER_BIT; +static GLboolean SwapFlag = GL_FALSE; + + + +static void Idle( void ) +{ + glutPostRedisplay(); +} + + +static void Display( void ) +{ + double t0, t1; + double clearRate; + double pixelRate; + int i; + + glClearColor( ClearColor, ClearColor, ClearColor, 0.0 ); + ClearColor += 0.1; + if (ClearColor>1.0) + ClearColor = 0.0; + + if (SwapFlag) { + t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + for (i=0;i +#include +#include +#include + +#include "../util/readtex.c" /* a hack, I know */ + +#define IMAGE_FILE "../images/girl.rgb" + +static int ImgWidth, ImgHeight; +static GLenum ImgFormat; +static GLubyte *Image = NULL; + +static int Xpos, Ypos; +static int SkipPixels, SkipRows; +static int DrawWidth, DrawHeight; +static int Scissor = 0; +static float Xzoom, Yzoom; + + + +static void Reset( void ) +{ + Xpos = Ypos = 20; + DrawWidth = ImgWidth; + DrawHeight = ImgHeight; + SkipPixels = SkipRows = 0; + Scissor = 0; + Xzoom = Yzoom = 1.0; +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + +#if 0 + glRasterPos2i(Xpos, Ypos); +#else + /* This allows negative raster positions: */ + glRasterPos2i(0, 0); + glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL); +#endif + + glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows); + + glPixelZoom( Xzoom, Yzoom ); + + if (Scissor) + glEnable(GL_SCISSOR_TEST); + + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + + glDisable(GL_SCISSOR_TEST); + + glutSwapBuffers(); +} + + +static void Benchmark( void ) +{ + int startTime, endTime; + int draws = 500; + double seconds, pixelsPerSecond; + + printf("Benchmarking...\n"); + /* GL set-up */ + glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows); + glPixelZoom( Xzoom, Yzoom ); + if (Scissor) + glEnable(GL_SCISSOR_TEST); + + /* Run timing test */ + draws = 0; + startTime = glutGet(GLUT_ELAPSED_TIME); + do { + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + draws++; + endTime = glutGet(GLUT_ELAPSED_TIME); + } while (endTime - startTime < 4000); /* 4 seconds */ + + /* GL clean-up */ + glDisable(GL_SCISSOR_TEST); + + /* Results */ + seconds = (double) (endTime - startTime) / 1000.0; + pixelsPerSecond = draws * DrawWidth * DrawHeight / seconds; + printf("Result: %d draws in %f seconds = %f pixels/sec\n", + draws, seconds, pixelsPerSecond); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glScissor(width/4, height/4, width/2, height/2); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case ' ': + Reset(); + break; + case 'w': + if (DrawWidth > 0) + DrawWidth--; + break; + case 'W': + DrawWidth++; + break; + case 'h': + if (DrawHeight > 0) + DrawHeight--; + break; + case 'H': + DrawHeight++; + break; + case 'p': + if (SkipPixels > 0) + SkipPixels--; + break; + case 'P': + SkipPixels++; + break; + case 'r': + if (SkipRows > 0) + SkipRows--; + break; + case 'R': + SkipRows++; + break; + case 's': + Scissor = !Scissor; + break; + case 'x': + Xzoom -= 0.1; + break; + case 'X': + Xzoom += 0.1; + break; + case 'y': + Yzoom -= 0.1; + break; + case 'Y': + Yzoom += 0.1; + break; + case 'b': + Benchmark(); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + Ypos += 1; + break; + case GLUT_KEY_DOWN: + Ypos -= 1; + break; + case GLUT_KEY_LEFT: + Xpos -= 1; + break; + case GLUT_KEY_RIGHT: + Xpos += 1; + break; + } + glutPostRedisplay(); +} + + +static void Init( GLboolean ciMode ) +{ + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); + if (!Image) { + printf("Couldn't read %s\n", IMAGE_FILE); + exit(0); + } + + if (ciMode) { + /* Convert RGB image to grayscale */ + GLubyte *indexImage = malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i 1 && strcmp(argv[1], "-ci")==0) { + ciMode = GL_TRUE; + } + + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 500, 400 ); + + if (ciMode) + glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE ); + else + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0]); + + Init(ciMode); + Usage(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/gamma.c b/progs/demos/gamma.c new file mode 100644 index 0000000000..a3b0bd8c67 --- /dev/null +++ b/progs/demos/gamma.c @@ -0,0 +1,176 @@ + +/* $Id: gamma.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* Draw test patterns to help determine correct gamma value for a display. + When the intensities of the inner squares nearly match the intensities + of their frames (from some distance the borders should disappear) then + you've found the right gamma value. + + You can set Mesa's gamma values (for red, green and blue) with the + MESA_GAMMA environment variable. But only on X windows! + For example: + setenv MESA_GAMMA 1.5 1.6 1.4 + Sets the red gamma value to 1.5, green to 1.6 and blue to 1.4. + See the main README file for more information. + + For more info about gamma correction see: + http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html + + This program is in the public domain + + Brian Paul 19 Oct 1995 + Kai Schuetz 05 Jun 1999 */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log: gamma.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.1 1999/06/19 01:35:38 brianp + * merged in Kai Schuetz's RGB changes + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glShadeModel(GL_FLAT); +} + +/* ARGSUSED1 */ +static void +key_esc(unsigned char key, int x, int y) +{ + if(key == 27) exit(0); /* Exit on Escape */ +} + +static GLubyte p25[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, +}; + +static GLubyte p50[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, + 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, +}; + +static GLubyte p75[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, + 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, +}; + +static GLubyte *stippletab[4] = {NULL, p25, p50, p75}; + +static void +gamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b) +{ + GLint d; + + glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */ + glRectf(-1.0, yoffs, -0.6, yoffs + 0.5); + + for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */ + GLfloat xcoord = (-1.0 + d*0.4); + + glColor3f(r*d / 5.0, g*d / 5.0, b*d / 5.0); /* draw outer rect */ + glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5); + + glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */ + glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); + + glColor3f(r, g, b); /* draw stippled inner rect */ + glEnable(GL_POLYGON_STIPPLE); + glPolygonStipple(stippletab[d]); + glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); + glDisable(GL_POLYGON_STIPPLE); + } + glColor3f(r, g, b); /* solid color, no stipple */ + glRectf(0.6, yoffs, 1.0, yoffs + 0.5); +} + +static void +display(void) +{ + gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */ + gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */ + gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */ + gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */ + glFlush(); +} + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); + + glutInitWindowPosition(50, 50); + glutInitWindowSize(500, 400); + + glutCreateWindow("gamma test patterns"); + glutReshapeFunc(Reshape); + glutDisplayFunc(display); + glutKeyboardFunc(key_esc); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/gears.c b/progs/demos/gears.c new file mode 100644 index 0000000000..8d99a8d317 --- /dev/null +++ b/progs/demos/gears.c @@ -0,0 +1,356 @@ +/* $Id: gears.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log: gears.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.2 1999/06/03 17:07:36 brianp + * an extra quad was being drawn in front and back faces + * + * Revision 3.1 1998/11/03 02:49:10 brianp + * added fps output + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +static GLint T0 = 0; +static GLint Frames = 0; + + +/** + + Draw a gear wheel. You'll probably want to call this function when + building a display list since we do a lot of trig here. + + Input: inner_radius - radius of hole at center + outer_radius - radius at center of teeth + width - width of gear + teeth - number of teeth + tooth_depth - depth of tooth + + **/ + +static void +gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); + glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); + +} + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +static void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + } + } +} + + +static void +idle(void) +{ + angle += 2.0; + glutPostRedisplay(); +} + +/* change view angle, exit upon ESC */ +/* ARGSUSED1 */ +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* change view angle */ +/* ARGSUSED1 */ +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + view_rotx += 5.0; + break; + case GLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + case GLUT_KEY_LEFT: + view_roty += 5.0; + break; + case GLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + default: + return; + } + glutPostRedisplay(); +} + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + +static void +init(void) +{ + static GLfloat pos[4] = + {5.0, 5.0, 10.0, 0.0}; + static GLfloat red[4] = + {0.8, 0.1, 0.0, 1.0}; + static GLfloat green[4] = + {0.0, 0.8, 0.2, 1.0}; + static GLfloat blue[4] = + {0.2, 0.2, 1.0, 1.0}; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); +} + +void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); +} + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(300, 300); + glutCreateWindow("Gears"); + init(); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutVisibilityFunc(visible); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/glinfo.c b/progs/demos/glinfo.c new file mode 100644 index 0000000000..a61e365474 --- /dev/null +++ b/progs/demos/glinfo.c @@ -0,0 +1,50 @@ +/* $Id: glinfo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Print GL, GLU and GLUT version and extension info + * + * Brian Paul This file in public domain. + * October 3, 1997 + */ + + +/* + * $Log: glinfo.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.2 1999/02/02 04:45:49 brianp + * include stdio.h before glut.h + * + * Revision 3.1 1998/02/22 16:42:54 brianp + * added casts to prevent compiler warnings + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitDisplayMode( GLUT_RGB ); + glutCreateWindow(argv[0]); + + printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_EXTENSIONS: %s\n", (char *) glGetString(GL_EXTENSIONS)); + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR)); + printf("GLU_VERSION: %s\n", (char *) gluGetString(GLU_VERSION)); + printf("GLU_EXTENSIONS: %s\n", (char *) gluGetString(GLU_EXTENSIONS)); + printf("GLUT_API_VERSION: %d\n", GLUT_API_VERSION); +#ifdef GLUT_XLIB_IMPLEMENTATION + printf("GLUT_XLIB_IMPLEMENTATION: %d\n", GLUT_XLIB_IMPLEMENTATION); +#endif + + return 0; +} diff --git a/progs/demos/glutfx.c b/progs/demos/glutfx.c new file mode 100644 index 0000000000..278d726bcb --- /dev/null +++ b/progs/demos/glutfx.c @@ -0,0 +1,207 @@ +/* $Id: glutfx.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Example of how one might use GLUT with the 3Dfx driver in full-screen mode. + * Note: this only works with X since we're using Mesa's GLX "hack" for + * using Glide. + * + * Goals: + * easy setup and input event handling with GLUT + * use 3Dfx hardware + * automatically set MESA environment variables + * don't lose mouse input focus + * + * Brian Paul This file is in the public domain. + */ + +/* + * $Log: glutfx.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.2 1999/03/28 18:18:33 brianp + * minor clean-up + * + * Revision 3.1 1998/06/29 02:37:30 brianp + * minor changes for Windows (Ted Jump) + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + + +#define WIDTH 640 +#define HEIGHT 480 + + +static int Window = 0; +static int ScreenWidth, ScreenHeight; +static GLuint Torus = 0; +static GLfloat Xrot = 0.0, Yrot = 0.0; + + + +static void Display( void ) +{ + static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0}; + static GLfloat red[4] = {1.0, 0.2, 0.2, 1.0}; + static GLfloat green[4] = {0.2, 1.0, 0.2, 1.0}; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); + glCallList(Torus); + + glRotatef(90.0, 1, 0, 0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); + glCallList(Torus); + + glRotatef(90.0, 0, 1, 0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); + glCallList(Torus); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + float ratio = (float) width / (float) height; + + ScreenWidth = width; + ScreenHeight = height; + + /* + * The 3Dfx driver is limited to 640 x 480 but the X window may be larger. + * Enforce that here. + */ + if (width > WIDTH) + width = WIDTH; + if (height > HEIGHT) + height = HEIGHT; + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -20.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Window); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + break; + case GLUT_KEY_DOWN: + break; + case GLUT_KEY_LEFT: + break; + case GLUT_KEY_RIGHT: + break; + } + glutPostRedisplay(); +} + + +static void MouseMove( int x, int y ) +{ + Xrot = y - ScreenWidth / 2; + Yrot = x - ScreenHeight / 2; + glutPostRedisplay(); +} + + +static void Init( void ) +{ + Torus = glGenLists(1); + glNewList(Torus, GL_COMPILE); + glutSolidTorus(0.5, 2.0, 10, 20); + glEndList(); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +} + + +int main( int argc, char *argv[] ) +{ +#ifndef _WIN32 + printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this"); + printf(" program as root.\n\n"); + printf("Move the mouse. Press ESC to exit.\n\n"); + sleep(2); +#endif + + /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */ + putenv("MESA_GLX_FX=fullscreen"); + + /* Disable 3Dfx Glide splash screen */ + putenv("FX_GLIDE_NO_SPLASH="); + + /* Give an initial size and position so user doesn't have to place window */ + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit( &argc, argv ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + + Window = glutCreateWindow(argv[0]); + if (!Window) { + printf("Error, couldn't open window\n"); + exit(1); + } + + /* + * Want the X window to fill the screen so that we don't have to + * worry about losing the mouse input focus. + * Note that we won't actually see the X window since we never draw + * to it, hence, the original X screen's contents aren't disturbed. + */ + glutFullScreen(); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutPassiveMotionFunc( MouseMove ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c new file mode 100644 index 0000000000..393197f66d --- /dev/null +++ b/progs/demos/isosurf.c @@ -0,0 +1,821 @@ +/* $Id: isosurf.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Display an isosurface of 3-D wind speed volume. Use arrow keys to + * rotate, S toggles smooth shading, L toggles lighting + * Brian Paul This file in public domain. + */ + +/* + * $Log: isosurf.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.4 1999/04/24 01:10:47 keithw + * clip planes, materials + * + * Revision 3.3 1999/03/31 19:42:14 keithw + * support for cva + * + * Revision 3.1 1998/11/01 20:30:20 brianp + * added benchmark feature (b key) + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + + +#include +#include +#include +#include +#include "GL/glut.h" + +#include "../util/readtex.c" /* I know, this is a hack. KW: me too. */ +#define TEXTURE_FILE "../images/reflect.rgb" + +#define LIT 0x1 +#define UNLIT 0x2 +#define TEXTURE 0x4 +#define NO_TEXTURE 0x8 +#define REFLECT 0x10 +#define NO_REFLECT 0x20 +#define POINT_FILTER 0x40 +#define LINEAR_FILTER 0x80 +#define IMMEDIATE 0x100 +#define DRAW_ARRAYS 0x200 /* or draw_elts, if compiled */ +#define ARRAY_ELT 0x400 +#define COMPILED 0x800 +#define NOT_COMPILED 0x1000 +#define SHADE_SMOOTH 0x2000 +#define SHADE_FLAT 0x4000 +#define TRIANGLES 0x8000 +#define STRIPS 0x10000 +#define USER_CLIP 0x20000 +#define NO_USER_CLIP 0x40000 +#define MATERIALS 0x80000 +#define NO_MATERIALS 0x100000 +#define QUIT 0x800000 + +#define LIGHT_MASK (LIT|UNLIT) +#define TEXTURE_MASK (TEXTURE|NO_TEXTURE) +#define REFLECT_MASK (REFLECT|NO_REFLECT) +#define FILTER_MASK (POINT_FILTER|LINEAR_FILTER) +#define RENDER_STYLE_MASK (IMMEDIATE|DRAW_ARRAYS|ARRAY_ELT) +#define COMPILED_MASK (COMPILED|NOT_COMPILED) +#define MATERIAL_MASK (MATERIALS|NO_MATERIALS) +#define PRIMITIVE_MASK (TRIANGLES|STRIPS) +#define CLIP_MASK (USER_CLIP|NO_USER_CLIP) +#define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT) + +#define MAXVERTS 10000 +static float data[MAXVERTS][6]; +static float compressed_data[MAXVERTS][6]; +static GLuint indices[MAXVERTS]; +static GLuint tri_indices[MAXVERTS*3]; +static GLfloat col[100][4]; +static GLint numverts, num_tri_verts, numuniq; + +static GLfloat xrot; +static GLfloat yrot; +static GLint state, allowed = ~0; +static GLboolean doubleBuffer = GL_TRUE; +static GLdouble plane[4] = {1.0, 0.0, -1.0, 0.0}; + + +static void read_surface( char *filename ) +{ + FILE *f; + + f = fopen(filename,"r"); + if (!f) { + printf("couldn't read %s\n", filename); + exit(1); + } + + numverts = 0; + while (!feof(f) && numverts 0) return 1; \ + return 0; \ +} + +COMPARE_FUNC(0) +COMPARE_FUNC(1) +COMPARE_FUNC(2) +COMPARE_FUNC(3) +COMPARE_FUNC(4) +COMPARE_FUNC(5) +COMPARE_FUNC(6) + +int (*(compare[7]))( const void *a, const void *b ) = +{ + compare_axis_0, + compare_axis_1, + compare_axis_2, + compare_axis_3, + compare_axis_4, + compare_axis_5, + compare_axis_6, +}; + + +#define VEC_ELT(f, s, i) (float *)(((char *)f) + s * i) + +static int sort_axis( int axis, + int vec_size, + int vec_stride, + struct data_idx *indices, + int start, + int finish, + float *out, + int uniq, + const float fudge ) +{ + int i; + + if (finish-start > 2) + { + qsort( indices+start, finish-start, sizeof(*indices), compare[axis] ); + } + else if (indices[start].data[axis] > indices[start+1].data[axis]) + { + struct data_idx tmp = indices[start]; + indices[start] = indices[start+1]; + indices[start+1] = tmp; + } + + if (axis == vec_size-1) { + for (i = start ; i < finish ; ) { + float max = indices[i].data[axis] + fudge; + float *dest = VEC_ELT(out, vec_stride, uniq); + int j; + + for (j = 0 ; j < vec_size ; j++) + dest[j] = indices[i].data[j]; + + for ( ; i < finish && max >= indices[i].data[axis]; i++) + indices[i].uniq_idx = uniq; + + uniq++; + } + } else { + for (i = start ; i < finish ; ) { + int j = i + 1; + float max = indices[i].data[axis] + fudge; + while (j < finish && max >= indices[j].data[axis]) j++; + if (j == i+1) { + float *dest = VEC_ELT(out, vec_stride, uniq); + int k; + + indices[i].uniq_idx = uniq; + + for (k = 0 ; k < vec_size ; k++) + dest[k] = indices[i].data[k]; + + uniq++; + } else { + uniq = sort_axis( axis+1, vec_size, vec_stride, + indices, i, j, out, uniq, fudge ); + } + i = j; + } + } + + return uniq; +} + + +static void extract_indices1( const struct data_idx *in, unsigned int *out, + int n ) +{ + int i; + for ( i = 0 ; i < n ; i++ ) { + out[in[i].idx] = in[i].uniq_idx; + } +} + + +static void compactify_arrays() +{ + int i; + struct data_idx *ind; + + ind = (struct data_idx *) malloc( sizeof(struct data_idx) * numverts ); + + for (i = 0 ; i < numverts ; i++) { + ind[i].idx = i; + ind[i].data = data[i]; + } + + numuniq = sort_axis(0, + sizeof(compressed_data[0])/sizeof(float), + sizeof(compressed_data[0]), + ind, + 0, + numverts, + (float *)compressed_data, + 0, + 1e-6); + + printf("Nr unique vertex/normal pairs: %d\n", numuniq); + + extract_indices1( ind, indices, numverts ); + free( ind ); +} + +static float myrand( float max ) +{ + return max*rand()/(RAND_MAX+1.0); +} + + +static void make_tri_indices( void ) +{ + unsigned int *v = tri_indices; + unsigned int parity = 0; + unsigned int i, j; + + for (j=2;j where T=(sqrt(5)+1)/2 + ICOSAHEDRON : (3*sqrt(3)+sqrt(15))/12 + +I've not found any reference about the mentioned angles, so I needed to +calculate them, not a trivial task until I figured out how :) +Curiously these angles are the same for the tetrahedron and octahedron. +A way to obtain this value is inscribing the tetrahedron inside the cube +by matching their vertexes. So you'll notice that the remaining unmatched +vertexes are in the same straight line starting in the cube/tetrahedron +center and crossing the center of each tetrahedron's face. At this point +it's easy to obtain the bigger angle of the isosceles triangle formed by +the center of the cube and two opposite vertexes on the same cube face. +The edges of this triangle have the following lenghts: sqrt(2) for the base +and sqrt(3)/2 for the other two other edges. So the angle we want is: + +-----------------------------------------------------------+ + | 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees | + +-----------------------------------------------------------+ +For the cube this angle is obvious, but just for formality it can be +easily obtained because we also know it's isosceles edge lenghts: +sqrt(2)/2 for the base and 1/2 for the other two edges. So the angle we +want is: + +-----------------------------------------------------------+ + | 2*ARCSIN((sqrt(2)/2)/1) = 90.000000000000000000 degrees | + +-----------------------------------------------------------+ +For the octahedron we use the same idea used for the tetrahedron, but now +we inscribe the cube inside the octahedron so that all cubes's vertexes +matches excatly the center of each octahedron's face. It's now clear that +this angle is the same of the thetrahedron one: + +-----------------------------------------------------------+ + | 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees | + +-----------------------------------------------------------+ +For the dodecahedron it's a little bit harder because it's only relationship +with the cube is useless to us. So we need to solve the problem by another +way. The concept of Face radius also exists on 2D polygons with the name +Edge radius: + Edge Radius For Pentagon (ERp) + ERp = (1/2)/TAN(36 degrees) * VRp = 0.6881909602355867905 + (VRp is the pentagon's vertex radio). + Face Radius For Dodecahedron + FRd = T^2 * sqrt((T+2)/5) / 2 = 1.1135163644116068404 +Why we need ERp? Well, ERp and FRd segments forms a 90 degrees angle, +completing this triangle, the lesser angle is a half of the angle we are +looking for, so this angle is: + +-----------------------------------------------------------+ + | 2*ARCTAN(ERp/FRd) = 63.434948822922009981 degrees | + +-----------------------------------------------------------+ +For the icosahedron we can use the same method used for dodecahedron (well +the method used for dodecahedron may be used for all regular polyhedra) + Edge Radius For Triangle (this one is well known: 1/3 of the triangle height) + ERt = sin(60)/3 = sqrt(3)/6 = 0.2886751345948128655 + Face Radius For Icosahedron + FRi= (3*sqrt(3)+sqrt(15))/12 = 0.7557613140761707538 +So the angle is: + +-----------------------------------------------------------+ + | 2*ARCTAN(ERt/FRi) = 41.810314895778596167 degrees | + +-----------------------------------------------------------+ + +*/ + + +#include +#include +#ifndef _WIN32 +#include +#endif +#include +#include +#include + +#define Scale 0.3 + +#define VectMul(X1,Y1,Z1,X2,Y2,Z2) (Y1)*(Z2)-(Z1)*(Y2),(Z1)*(X2)-(X1)*(Z2),(X1)*(Y2)-(Y1)*(X2) +#define sqr(A) ((A)*(A)) + +/* Increasing this values produces better image quality, the price is speed. */ +/* Very low values produces erroneous/incorrect plotting */ +#define tetradivisions 23 +#define cubedivisions 20 +#define octadivisions 21 +#define dodecadivisions 10 +#define icodivisions 15 + +#define tetraangle 109.47122063449069174 +#define cubeangle 90.000000000000000000 +#define octaangle 109.47122063449069174 +#define dodecaangle 63.434948822922009981 +#define icoangle 41.810314895778596167 + +#ifndef Pi +#define Pi 3.1415926535897932385 +#endif +#define SQRT2 1.4142135623730951455 +#define SQRT3 1.7320508075688771932 +#define SQRT5 2.2360679774997898051 +#define SQRT6 2.4494897427831778813 +#define SQRT15 3.8729833462074170214 +#define cossec36_2 0.8506508083520399322 +#define cos72 0.3090169943749474241 +#define sin72 0.9510565162951535721 +#define cos36 0.8090169943749474241 +#define sin36 0.5877852522924731292 + +/*************************************************************************/ + +static int mono=0; +static int smooth=1; +static GLint WindH, WindW; +static GLfloat step=0; +static GLfloat seno; +static int object; +static int edgedivisions; +static void (*draw_object)( void ); +static float Magnitude; +static float *MaterialColor[20]; + +static float front_shininess[] = {60.0}; +static float front_specular[] = { 0.7, 0.7, 0.7, 1.0 }; +static float ambient[] = { 0.0, 0.0, 0.0, 1.0 }; +static float diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; +static float position0[] = { 1.0, 1.0, 1.0, 0.0 }; +static float position1[] = {-1.0,-1.0, 1.0, 0.0 }; +static float lmodel_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; +static float lmodel_twoside[] = {GL_TRUE}; + +static float MaterialRed[] = { 0.7, 0.0, 0.0, 1.0 }; +static float MaterialGreen[] = { 0.1, 0.5, 0.2, 1.0 }; +static float MaterialBlue[] = { 0.0, 0.0, 0.7, 1.0 }; +static float MaterialCyan[] = { 0.2, 0.5, 0.7, 1.0 }; +static float MaterialYellow[] = { 0.7, 0.7, 0.0, 1.0 }; +static float MaterialMagenta[] = { 0.6, 0.2, 0.5, 1.0 }; +static float MaterialWhite[] = { 0.7, 0.7, 0.7, 1.0 }; +static float MaterialGray[] = { 0.2, 0.2, 0.2, 1.0 }; + +#define TRIANGLE(Edge, Amp, Divisions, Z) \ +{ \ + GLfloat Xf,Yf,Xa,Yb,Xf2,Yf2; \ + GLfloat Factor,Factor1,Factor2; \ + GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \ + GLfloat Ax,Ay,Bx; \ + int Ri,Ti; \ + GLfloat Vr=(Edge)*SQRT3/3; \ + GLfloat AmpVr2=(Amp)/sqr(Vr); \ + GLfloat Zf=(Edge)*(Z); \ + \ + Ax=(Edge)*(+0.5/(Divisions)), Ay=(Edge)*(-SQRT3/(2*Divisions)); \ + Bx=(Edge)*(-0.5/(Divisions)); \ + \ + for (Ri=1; Ri<=(Divisions); Ri++) { \ + glBegin(GL_TRIANGLE_STRIP); \ + for (Ti=0; Ti +#include +#include +#include +#include + +#include "../util/readtex.c" /* I know, this is a hack. */ + +#define TEXTURE_1_FILE "../images/girl.rgb" +#define TEXTURE_2_FILE "../images/reflect.rgb" + +#define TEX0 1 +#define TEX1 2 +#define TEXBOTH 3 +#define ANIMATE 10 +#define QUIT 100 + +static GLboolean Animate = GL_TRUE; + +static GLfloat Drift = 0.0; +static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0; + + + +static void Idle( void ) +{ + if (Animate) { + Drift += 0.05; + +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE0_ARB); +#endif + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glTranslatef(Drift, 0.0, 0.0); + glMatrixMode(GL_MODELVIEW); + +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE1_ARB); +#endif + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glTranslatef(0.0, Drift, 0.0); + glMatrixMode(GL_MODELVIEW); + + glutPostRedisplay(); + } +} + + +static void DrawObject(void) +{ + glBegin(GL_QUADS); + +#ifdef GL_ARB_multitexture + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0); + glVertex2f(-1.0, -1.0); + + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 0.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0); + glVertex2f(1.0, -1.0); + + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 2.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0); + glVertex2f(1.0, 1.0); + + glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 2.0); + glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0); + glVertex2f(-1.0, 1.0); +#else + glTexCoord2f(0.0, 0.0); + glVertex2f(-1.0, -1.0); + + glTexCoord2f(1.0, 0.0); + glVertex2f(1.0, -1.0); + + glTexCoord2f(1.0, 1.0); + glVertex2f(1.0, 1.0); + + glTexCoord2f(0.0, 1.0); + glVertex2f(-1.0, 1.0); +#endif + + glEnd(); +} + + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1.0, 0.0, 0.0); + glRotatef(Yrot, 0.0, 1.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + glScalef(5.0, 5.0, 5.0); + DrawObject(); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ); + /*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/ + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -70.0 ); +} + + +static void ModeMenu(int entry) +{ + GLboolean enable0 = GL_FALSE, enable1 = GL_FALSE; + if (entry==TEX0) { + enable0 = GL_TRUE; + } + else if (entry==TEX1) { + enable1 = GL_TRUE; + } + else if (entry==TEXBOTH) { + enable0 = GL_TRUE; + enable1 = GL_TRUE; + } + else if (entry==ANIMATE) { + Animate = !Animate; + } + else if (entry==QUIT) { + exit(0); + } + + if (entry != ANIMATE) { +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE0_ARB); +#endif + if (enable0) { + glEnable(GL_TEXTURE_2D); + } + else + glDisable(GL_TEXTURE_2D); + +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE1_ARB); +#endif + if (enable1) { + glEnable(GL_TEXTURE_2D); + } + else + glDisable(GL_TEXTURE_2D); + } + + glutPostRedisplay(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + float step = 3.0; + (void) x; + (void) y; + + switch (key) { + case GLUT_KEY_UP: + Xrot += step; + break; + case GLUT_KEY_DOWN: + Xrot -= step; + break; + case GLUT_KEY_LEFT: + Yrot += step; + break; + case GLUT_KEY_RIGHT: + Yrot -= step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char *exten = (const char *) glGetString(GL_EXTENSIONS); + if (!strstr(exten, "GL_ARB_multitexture")) { + printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n"); + exit(1); + } + + /* setup texture env 0 */ +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE0_ARB); +#endif +#ifdef LINEAR_FILTER + /* linear filtering looks much nicer but is much slower for Mesa */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#else + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +#endif + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + + + /* setup texture env 1 */ +#ifdef GL_ARB_multitexture + glActiveTextureARB(GL_TEXTURE1_ARB); +#endif +#ifdef LINEAR_FILTER + /* linear filtering looks much nicer but is much slower for Mesa */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#else + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +#endif + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + + glShadeModel(GL_FLAT); + glClearColor(0.3, 0.3, 0.4, 1.0); + + ModeMenu(TEXBOTH); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowSize( 300, 300 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow(argv[0] ); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("Texture 0", TEX0); + glutAddMenuEntry("Texture 1", TEX1); + glutAddMenuEntry("Multi-texture", TEXBOTH); + glutAddMenuEntry("Toggle Animation", ANIMATE); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/osdemo.c b/progs/demos/osdemo.c new file mode 100644 index 0000000000..f69cd22fad --- /dev/null +++ b/progs/demos/osdemo.c @@ -0,0 +1,169 @@ +/* $Id: osdemo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Demo of off-screen Mesa rendering + * + * See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions. + * + * If you want to render BIG images you'll probably have to increase + * MAX_WIDTH and MAX_HEIGHT in src/config.h. + * + * This program is in the public domain. + * + * Brian Paul + * + * PPM output provided by Joerg Schmalzl. + * ASCII PPM output added by Brian Paul. + */ + + +/* + * $Log: osdemo.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + + +#include +#include +#include "GL/osmesa.h" +#include "GL/glut.h" + + + +#define WIDTH 400 +#define HEIGHT 400 + + + +static void render_image( void ) +{ + GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + GLfloat red_mat[] = { 1.0, 0.2, 0.2, 1.0 }; + GLfloat green_mat[] = { 0.2, 1.0, 0.2, 1.0 }; + GLfloat blue_mat[] = { 0.2, 0.2, 1.0, 1.0 }; + + + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-2.5, 2.5, -2.5, 2.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(20.0, 1.0, 0.0, 0.0); + + glPushMatrix(); + glTranslatef(-0.75, 0.5, 0.0); + glRotatef(90.0, 1.0, 0.0, 0.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat ); + glutSolidTorus(0.275, 0.85, 20, 20); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-0.75, -0.5, 0.0); + glRotatef(270.0, 1.0, 0.0, 0.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat ); + glutSolidCone(1.0, 2.0, 16, 1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.75, 0.0, -1.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat ); + glutSolidSphere(1.0, 20, 20); + glPopMatrix(); + + glPopMatrix(); +} + + + +int main( int argc, char *argv[] ) +{ + OSMesaContext ctx; + void *buffer; + + /* Create an RGBA-mode context */ + ctx = OSMesaCreateContext( GL_RGBA, NULL ); + + /* Allocate the image buffer */ + buffer = malloc( WIDTH * HEIGHT * 4 ); + + /* Bind the buffer to the context and make it current */ + OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, WIDTH, HEIGHT ); + + render_image(); + + if (argc>1) { + /* write PPM file */ + FILE *f = fopen( argv[1], "w" ); + if (f) { + int i, x, y; + GLubyte *ptr = (GLubyte *) buffer; +#define BINARY 0 +#if BINARY + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by %s\n", argv[0]); + fprintf(f,"%i %i\n", WIDTH,HEIGHT); + fprintf(f,"255\n"); + fclose(f); + f = fopen( argv[1], "ab" ); /* reopen in binary append mode */ + for (y=HEIGHT-1; y>=0; y--) { + for (x=0; x=0; y--) { + for (x=0; x +#include +#include +#include + + +static float Rot = 0.0; + + +static void Idle( void ) +{ + Rot += 5.0; + glutPostRedisplay(); +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Rot, 0, 0, 1); + + glBegin(GL_POLYGON); + glTexCoord2f(0, 1); glVertex2f(-1, -1); + glTexCoord2f(1, 1); glVertex2f( 1, -1); + glTexCoord2f(1, 0); glVertex2f( 1, 1); + glTexCoord2f(0, 0); glVertex2f(-1, 1); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + break; + case GLUT_KEY_DOWN: + break; + case GLUT_KEY_LEFT: + break; + case GLUT_KEY_RIGHT: + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + GLubyte texture[8][8] = { /* PT = Paletted Texture! */ + { 0, 0, 0, 0, 0, 0, 0, 0}, + { 0, 100, 100, 100, 0, 180, 180, 180}, + { 0, 100, 0, 100, 0, 0, 180, 0}, + { 0, 100, 0, 100, 0, 0, 180, 0}, + { 0, 100, 100, 100, 0, 0, 180, 0}, + { 0, 100, 0, 0, 0, 0, 180, 0}, + { 0, 100, 0, 0, 0, 0, 180, 0}, + { 0, 100, 255, 0, 0, 0, 180, 250}, + }; + + GLubyte table[256][4]; + int i; + + if (!glutExtensionSupported("GL_EXT_paletted_texture")) { + printf("Sorry, GL_EXT_paletted_texture not supported\n"); + exit(0); + } + + /* put some wacky colors into the texture palette */ + for (i=0;i<256;i++) { + table[i][0] = i; + table[i][1] = 0; + table[i][2] = 127 + i / 2; + table[i][3] = 255; + } + +#ifdef GL_EXT_paletted_texture + +#if defined(GL_EXT_shared_texture_palette) && defined(SHARED_PALETTE) + printf("Using shared palette\n"); + glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, /* target */ + GL_RGBA, /* internal format */ + 256, /* table size */ + GL_RGBA, /* table format */ + GL_UNSIGNED_BYTE, /* table type */ + table); /* the color table */ + glEnable(GL_SHARED_TEXTURE_PALETTE_EXT); +#else + glColorTableEXT(GL_TEXTURE_2D, /* target */ + GL_RGBA, /* internal format */ + 256, /* table size */ + GL_RGBA, /* table format */ + GL_UNSIGNED_BYTE, /* table type */ + table); /* the color table */ +#endif + + glTexImage2D(GL_TEXTURE_2D, /* target */ + 0, /* level */ + GL_COLOR_INDEX8_EXT, /* internal format */ + 8, 8, /* width, height */ + 0, /* border */ + GL_COLOR_INDEX, /* texture format */ + GL_UNSIGNED_BYTE, /* texture type */ + texture); /* teh texture */ +#endif + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable(GL_TEXTURE_2D); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 400, 400 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0]); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/pointblast.c b/progs/demos/pointblast.c new file mode 100644 index 0000000000..a36046f585 --- /dev/null +++ b/progs/demos/pointblast.c @@ -0,0 +1,506 @@ + +/* Copyright (c) Mark J. Kilgard, 1997. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +/* This example demonstrates how to render particle effects + with OpenGL. A cloud of pinkish/orange particles explodes with the + particles bouncing off the ground. When the EXT_point_parameters + is present , the particle size is attenuated based on eye distance. */ + + +/* + * $Log: pointblast.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.3 1998/07/26 01:24:27 brianp + * removed include of gl.h + * + * Revision 3.2 1998/02/14 18:51:46 brianp + * fixed a small compiler warning + * + * Revision 3.1 1998/02/14 18:45:25 brianp + * optimized to use flat shading, don't blend ground polygon + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include /* for cos(), sin(), and sqrt() */ +#include + +/* Some files do not define M_PI... */ +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +#if 0 /* For debugging. */ +#undef GL_EXT_point_parameters +#endif + +static GLfloat angle = -150; /* in degrees */ +static int spin = 0; +static int moving, begin; +static int newModel = 1; +static float theTime; +static int repeat = 1; +static int blend = 1; +int useMipmaps = 1; +int linearFiltering = 1; + +static GLfloat constant[3] = { 1/5.0, 0.0, 0.0 }; +static GLfloat linear[3] = { 0.0, 1/5.0, 0.0 }; +static GLfloat theQuad[3] = { 0.25, 0.0, 1/60.0 }; + +#define MAX_POINTS 2000 + +static int numPoints = 200; + +static GLfloat pointList[MAX_POINTS][3]; +static GLfloat pointTime[MAX_POINTS]; +static GLfloat pointVelocity[MAX_POINTS][2]; +static GLfloat pointDirection[MAX_POINTS][2]; +static int colorList[MAX_POINTS]; +static int animate = 1, motion = 0; + +static GLfloat colorSet[][4] = { + /* Shades of red. */ + { 0.7, 0.2, 0.4, 0.5 }, + { 0.8, 0.0, 0.7, 0.5 }, + { 1.0, 0.0, 0.0, 0.5 }, + { 0.9, 0.3, 0.6, 0.5 }, + { 1.0, 0.4, 0.0, 0.5 }, + { 1.0, 0.0, 0.5, 0.5 }, +}; + +#define NUM_COLORS (sizeof(colorSet)/sizeof(colorSet[0])) + +#define DEAD (NUM_COLORS+1) + + +#if 0 /* drand48 might be better on Unix machines */ +#define RANDOM_RANGE(lo, hi) ((lo) + (hi - lo) * drand48()) +#else +static float float_rand(void) { return rand() / (float) RAND_MAX; } +#define RANDOM_RANGE(lo, hi) ((lo) + (hi - lo) * float_rand()) +#endif + +#define MEAN_VELOCITY 3.0 +#define GRAVITY 2.0 +#define TIME_DELTA 0.025 /* The speed of time. */ + +/* Modeling units of ground extent in each X and Z direction. */ +#define EDGE 12 + +void +makePointList(void) +{ + float angle, velocity, direction; + int i; + + motion = 1; + for (i=0; i EDGE) { + /* Particle has hit ground past the distance duration of + the particles. Mark particle as dead. */ + colorList[i] = NUM_COLORS; /* Not moving. */ + continue; + } + + pointVelocity[i][1] *= 0.8; /* 80% of previous up velocity. */ + pointTime[i] = 0.0; /* Reset the particles sense of up time. */ + } + motion = 1; + pointTime[i] += TIME_DELTA; + } + theTime += TIME_DELTA; + if (!motion && !spin) { + if (repeat) { + makePointList(); + } else { + glutIdleFunc(NULL); + } + } +} + +void +idle(void) +{ + updatePointList(); + if (spin) { + angle += 0.3; + newModel = 1; + } + glutPostRedisplay(); +} + +void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) { + if (animate && (motion || spin)) { + glutIdleFunc(idle); + } + } else { + glutIdleFunc(NULL); + } +} + +void +recalcModelView(void) +{ + glPopMatrix(); + glPushMatrix(); + glRotatef(angle, 0.0, 1.0, 0.0); + newModel = 0; +} + +void +redraw(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (newModel) + recalcModelView(); + + glDepthMask(GL_FALSE); + + /* Draw the floor. */ +/* glEnable(GL_TEXTURE_2D);*/ + glColor3f(0.5, 1.0, 0.5); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex3f(-EDGE, -0.05, -EDGE); + glTexCoord2f(20.0, 0.0); + glVertex3f(EDGE, -0.05, -EDGE); + glTexCoord2f(20.0, 20.0); + glVertex3f(EDGE, -0.05, EDGE); + glTexCoord2f(0.0, 20.0); + glVertex3f(-EDGE, -0.05, EDGE); + glEnd(); + + /* Allow particles to blend with each other. */ + glDepthMask(GL_TRUE); + + if (blend) + glEnable(GL_BLEND); + + glDisable(GL_TEXTURE_2D); + glBegin(GL_POINTS); + for (i=0; i +#include +#include +#include "GL/glut.h" + +#include "../util/readtex.c" /* a hack, I know */ + + +#define DEG2RAD (3.14159/180.0) + + +#define TABLE_TEXTURE "../images/tile.rgb" + +static int ImgWidth, ImgHeight; +static GLenum ImgFormat; +static GLubyte *Image = NULL; + +#define MAX_OBJECTS 2 + +static GLint table_list; +static GLint objects_list[MAX_OBJECTS]; + + +static GLfloat xrot, yrot; +static GLfloat spin; + + + +static void make_table( void ) +{ + static GLfloat table_mat[] = { 1.0, 1.0, 1.0, 0.6 }; + static GLfloat gray[] = { 0.4, 0.4, 0.4, 1.0 }; + + table_list = glGenLists(1); + glNewList( table_list, GL_COMPILE ); + + /* load table's texture */ + glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, table_mat ); +/* glMaterialfv( GL_FRONT, GL_EMISSION, gray );*/ + glMaterialfv( GL_FRONT, GL_DIFFUSE, table_mat ); + glMaterialfv( GL_FRONT, GL_AMBIENT, gray ); + + /* draw textured square for the table */ + glPushMatrix(); + glScalef( 4.0, 4.0, 4.0 ); + glBegin( GL_POLYGON ); + glNormal3f( 0.0, 1.0, 0.0 ); + glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, 0.0, 1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1.0, 0.0, 1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, 0.0, -1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, 0.0, -1.0 ); + glEnd(); + glPopMatrix(); + + glDisable( GL_TEXTURE_2D ); + + glEndList(); +} + + +static void make_objects( void ) +{ + GLUquadricObj *q; + + static GLfloat cyan[] = { 0.0, 1.0, 1.0, 1.0 }; + static GLfloat green[] = { 0.2, 1.0, 0.2, 1.0 }; + static GLfloat black[] = { 0.0, 0.0, 0.0, 0.0 }; + + q = gluNewQuadric(); + gluQuadricDrawStyle( q, GLU_FILL ); + gluQuadricNormals( q, GLU_SMOOTH ); + + objects_list[0] = glGenLists(1); + glNewList( objects_list[0], GL_COMPILE ); + glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan ); + glMaterialfv( GL_FRONT, GL_EMISSION, black ); + gluCylinder( q, 0.5, 0.5, 1.0, 15, 1 ); + glEndList(); + + objects_list[1] = glGenLists(1); + glNewList( objects_list[1], GL_COMPILE ); + glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green ); + glMaterialfv( GL_FRONT, GL_EMISSION, black ); + gluCylinder( q, 1.5, 0.0, 2.5, 15, 1 ); + glEndList(); +} + + +static GLfloat light_pos[] = { 0.0, 20.0, 0.0, 1.0 }; + +static void init( void ) +{ + make_table(); + make_objects(); + + /* Setup texture */ +#ifdef USE_TEXTURE + + Image = LoadRGBImage( TABLE_TEXTURE, &ImgWidth, &ImgHeight, &ImgFormat ); + if (!Image) { + printf("Couldn't read %s\n", TABLE_TEXTURE); + exit(0); + } + + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ImgWidth, ImgHeight, + ImgFormat, GL_UNSIGNED_BYTE, Image); + + 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_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); +#endif + + + xrot = 30.0; + yrot = 50.0; + spin = 0.0; + +#ifndef USE_ZBUFFER + glEnable( GL_CULL_FACE ); +#endif + + glShadeModel( GL_FLAT ); + + glEnable( GL_LIGHT0 ); + glEnable( GL_LIGHTING ); + + glClearColor( 0.5, 0.5, 0.9, 1.0 ); + + glEnable( GL_NORMALIZE ); +} + + + +static void reshape(int w, int h) +{ + GLfloat aspect = (float) w / (float) h; + + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -aspect, aspect, -1.0, 1.0, 4.0, 300.0 ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + + +static void draw_objects( GLfloat eyex, GLfloat eyey, GLfloat eyez ) +{ + (void) eyex; + (void) eyey; + (void) eyez; +#ifndef USE_ZBUFFER + if (eyex<0.5) + { +#endif + glPushMatrix(); + glTranslatef( 1.0, 1.5, 0.0 ); + glRotatef( spin, 1.0, 0.5, 0.0 ); + glRotatef( 0.5*spin, 0.0, 0.5, 1.0 ); + glCallList( objects_list[0] ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*spin) ), 0.0 ); + glRotatef( 0.5*spin, 0.0, 0.5, 1.0 ); + glRotatef( spin, 1.0, 0.5, 0.0 ); + glScalef( 0.5, 0.5, 0.5 ); + glCallList( objects_list[1] ); + glPopMatrix(); +#ifndef USE_ZBUFFER + } + else + { + glPushMatrix(); + glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*spin) ), 0.0 ); + glRotatef( 0.5*spin, 0.0, 0.5, 1.0 ); + glRotatef( spin, 1.0, 0.5, 0.0 ); + glScalef( 0.5, 0.5, 0.5 ); + glCallList( objects_list[1] ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( 1.0, 1.5, 0.0 ); + glRotatef( spin, 1.0, 0.5, 0.0 ); + glRotatef( 0.5*spin, 0.0, 0.5, 1.0 ); + glCallList( objects_list[0] ); + glPopMatrix(); + } +#endif +} + + + +static void draw_table( void ) +{ + glCallList( table_list ); +} + + + +static void draw_scene( void ) +{ + GLfloat dist = 20.0; + GLfloat eyex, eyey, eyez; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + + eyex = dist * cos(yrot*DEG2RAD) * cos(xrot*DEG2RAD); + eyez = dist * sin(yrot*DEG2RAD) * cos(xrot*DEG2RAD); + eyey = dist * sin(xrot*DEG2RAD); + + /* view from top */ + glPushMatrix(); + gluLookAt( eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); + + glLightfv( GL_LIGHT0, GL_POSITION, light_pos ); + + /* draw table into stencil planes */ + glEnable( GL_STENCIL_TEST ); +#ifdef USE_ZBUFFER + glDisable( GL_DEPTH_TEST ); +#endif + glStencilFunc( GL_ALWAYS, 1, 0xffffffff ); + glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE ); + glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); + draw_table(); + glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); + +#ifdef USE_ZBUFFER + glEnable( GL_DEPTH_TEST ); +#endif + + + /* render view from below (reflected viewport) */ + /* only draw where stencil==1 */ + if (eyey>0.0) { + glPushMatrix(); + + glStencilFunc( GL_EQUAL, 1, 0xffffffff ); /* draw if ==1 */ + glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); + glScalef( 1.0, -1.0, 1.0 ); + + /* Reposition light in reflected space. */ + glLightfv(GL_LIGHT0, GL_POSITION, light_pos); + + draw_objects(eyex, eyey, eyez); + glPopMatrix(); + + /* Restore light's original unreflected position. */ + glLightfv(GL_LIGHT0, GL_POSITION, light_pos); + } + + glDisable( GL_STENCIL_TEST ); + + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + +#ifdef USE_TEXTURE + glEnable( GL_TEXTURE_2D ); +#endif + draw_table(); + glDisable( GL_TEXTURE_2D ); + glDisable( GL_BLEND ); + + /* view from top */ + glPushMatrix(); + + draw_objects(eyex, eyey, eyez); + + glPopMatrix(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + + +#if 0 +void draw_scene(void) +{ + GLfloat dist = 20.0; + GLfloat eyex, eyey, eyez; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + + eyex = dist * cos(yrot*DEG2RAD) * cos(xrot*DEG2RAD); + eyez = dist * sin(yrot*DEG2RAD) * cos(xrot*DEG2RAD); + eyey = dist * sin(xrot*DEG2RAD); + + /* view from top */ + glPushMatrix(); + gluLookAt( eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); + + draw_table(); + + glPopMatrix(); + + glutSwapBuffers(); +} +#endif + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + if (key==27) + exit(0); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + xrot += 3.0; +#ifndef USE_ZBUFFER + if ( xrot > 180 ) xrot = 180; +#endif + break; + case GLUT_KEY_DOWN: + xrot -= 3.0; +#ifndef USE_ZBUFFER + if ( xrot < 0 ) xrot = 0; +#endif + break; + case GLUT_KEY_LEFT: + yrot += 3.0; + break; + case GLUT_KEY_RIGHT: + yrot -= 3.0; + break; + } + glutPostRedisplay(); +} + + + +static void idle( void ) +{ + spin += 2.0; + yrot += 3.0; + glutPostRedisplay(); +} + + + +int main( int argc, char *argv[] ) +{ + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB +#ifdef USE_ZBUFFER + | GLUT_DEPTH +#endif + | GLUT_STENCIL); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize(400, 300 ); + glutCreateWindow(argv[0]); + glutReshapeFunc(reshape); + glutDisplayFunc(draw_scene); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutIdleFunc(idle); + + init(); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/renormal.c b/progs/demos/renormal.c new file mode 100644 index 0000000000..bd099dcdc8 --- /dev/null +++ b/progs/demos/renormal.c @@ -0,0 +1,123 @@ +/* $Id: renormal.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Test GL_EXT_rescale_normal extension + * Brian Paul January 1998 This program is in the public domain. + */ + +/* + * $Id: renormal.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ + */ + + +#include +#include +#include +#include + + +static GLfloat Phi = 0.0; + + +static void Idle(void) +{ + Phi += 0.1; + glutPostRedisplay(); +} + + +static void Display( void ) +{ + GLfloat scale = 0.6 + 0.5 * sin(Phi); + glClear( GL_COLOR_BUFFER_BIT ); + glPushMatrix(); + glScalef(scale, scale, scale); + glutSolidSphere(2.0, 20, 20); + glPopMatrix(); + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); +} + + + +static void Init( void ) +{ + static GLfloat mat[4] = { 0.8, 0.8, 0.0, 1.0 }; + static GLfloat pos[4] = { -1.0, 1.0, 1.0, 0.0 }; + + /* setup lighting, etc */ + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + + glEnable(GL_CULL_FACE); + + glDisable(GL_RESCALE_NORMAL_EXT); + glDisable(GL_NORMALIZE); +} + + +#define UNSCALED 1 +#define NORMALIZE 2 +#define RESCALE 3 +#define QUIT 4 + + +static void ModeMenu(int entry) +{ + if (entry==UNSCALED) { + glDisable(GL_RESCALE_NORMAL_EXT); + glDisable(GL_NORMALIZE); + } + else if (entry==NORMALIZE) { + glEnable(GL_NORMALIZE); + glDisable(GL_RESCALE_NORMAL_EXT); + } + else if (entry==RESCALE) { + glDisable(GL_NORMALIZE); + glEnable(GL_RESCALE_NORMAL_EXT); + } + else if (entry==QUIT) { + exit(0); + } + glutPostRedisplay(); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowSize( 400, 400 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0]); + + Init(); + + glutIdleFunc( Idle ); + glutReshapeFunc( Reshape ); + glutDisplayFunc( Display ); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("Unscaled", UNSCALED); + glutAddMenuEntry("Normalize", NORMALIZE); + glutAddMenuEntry("Rescale EXT", RESCALE); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/spectex.c b/progs/demos/spectex.c new file mode 100644 index 0000000000..412f442e4a --- /dev/null +++ b/progs/demos/spectex.c @@ -0,0 +1,277 @@ +/* $Id: spectex.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * GLUT demonstration of texturing with specular highlights. + * + * When drawing a lit, textured surface one usually wants the specular + * highlight to override the texture colors. However, OpenGL applies + * texturing after lighting so the specular highlight is modulated by + * the texture. + * + * The solution here shown here is a two-pass algorithm: + * 1. Draw the textured surface without specular lighting. + * 2. Enable blending to add the next pass: + * 3. Redraw the surface with a matte white material and only the + * specular components of light sources enabled. + * + * Brian Paul February 1997 + */ + + +/* + * $Log: spectex.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.2 1999/03/28 18:22:05 brianp + * minor clean-up + * + * Revision 3.1 1998/02/14 18:47:48 brianp + * added OpenGL 1.2 separate specular interpolation support + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + + +static GLUquadricObj *Quadric; +static GLuint Sphere; +static GLfloat LightPos[4] = {10.0, 10.0, 10.0, 1.0}; +static GLfloat Delta = 1.0; +static GLint Mode = 0; + +/*static GLfloat Blue[4] = {0.0, 0.0, 1.0, 1.0};*/ +/*static GLfloat Gray[4] = {0.5, 0.5, 0.5, 1.0};*/ +static GLfloat Black[4] = {0.0, 0.0, 0.0, 1.0}; +static GLfloat White[4] = {1.0, 1.0, 1.0, 1.0}; + + + +static void Idle( void ) +{ + LightPos[0] += Delta; + if (LightPos[0]>15.0) + Delta = -1.0; + else if (LightPos[0]<-15.0) + Delta = 1.0; + + glutPostRedisplay(); +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glLightfv(GL_LIGHT0, GL_POSITION, LightPos); + + glPushMatrix(); + glRotatef(90.0, 1.0, 0.0, 0.0); + + if (Mode==0) { + /* Typical method: diffuse + specular + texture */ + glEnable(GL_TEXTURE_2D); + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */ +#ifdef GL_VERSION_1_2 + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + glCallList(Sphere); + } + else if (Mode==1) { + /* just specular highlight */ + glDisable(GL_TEXTURE_2D); + glLightfv(GL_LIGHT0, GL_DIFFUSE, Black); /* disable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */ +#ifdef GL_VERSION_1_2 + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + glCallList(Sphere); + } + else if (Mode==2) { + /* diffuse textured */ + glEnable(GL_TEXTURE_2D); + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, Black); /* disable specular */ +#ifdef GL_VERSION_1_2 + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + glCallList(Sphere); + } + else if (Mode==3) { + /* 2-pass: diffuse textured then add specular highlight*/ + glEnable(GL_TEXTURE_2D); + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, Black); /* disable specular */ +#ifdef GL_VERSION_1_2 + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); +#endif + glCallList(Sphere); + /* specular highlight */ + glDepthFunc(GL_EQUAL); /* redraw same pixels */ + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); /* add */ + glLightfv(GL_LIGHT0, GL_DIFFUSE, Black); /* disable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */ + glCallList(Sphere); + glDepthFunc(GL_LESS); + glDisable(GL_BLEND); + } + else if (Mode==4) { + /* OpenGL 1.2's separate diffuse and specular color */ + glEnable(GL_TEXTURE_2D); + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */ + glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */ +#ifdef GL_VERSION_1_2 + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); +#endif + glCallList(Sphere); + } + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -12.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + break; + case GLUT_KEY_DOWN: + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + int i, j; + GLubyte texImage[64][64][3]; + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Black); + + glMaterialfv(GL_FRONT, GL_DIFFUSE, White); + glMaterialfv(GL_FRONT, GL_SPECULAR, White); + glMaterialf(GL_FRONT, GL_SHININESS, 20.0); + + /* Actually, these are set again later */ + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); + glLightfv(GL_LIGHT0, GL_SPECULAR, White); + + Quadric = gluNewQuadric(); + gluQuadricTexture( Quadric, GL_TRUE ); + + Sphere= glGenLists(1); + glNewList( Sphere, GL_COMPILE ); + gluSphere( Quadric, 1.0, 24, 24 ); + glEndList(); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + + for (i=0;i<64;i++) { + for (j=0;j<64;j++) { + int k = ((i>>3)&1) ^ ((j>>3)&1); + texImage[i][j][0] = 255*k; + texImage[i][j][1] = 255*(1-k); + texImage[i][j][2] = 0; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D( GL_TEXTURE_2D, + 0, + 3, + 64, 64, + 0, + GL_RGB, GL_UNSIGNED_BYTE, + texImage ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glEnable(GL_TEXTURE_2D); + + glBlendFunc(GL_ONE, GL_ONE); +} + + +static void ModeMenu(int entry) +{ + if (entry==99) + exit(0); + Mode = entry; +} + + +int main( int argc, char *argv[] ) +{ + + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 300, 300 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + + glutCreateWindow( "spectex" ); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutCreateMenu( ModeMenu ); + glutAddMenuEntry("1-pass lighting + texturing", 0); + glutAddMenuEntry("specular lighting", 1); + glutAddMenuEntry("diffuse lighting + texturing", 2); + glutAddMenuEntry("2-pass lighting + texturing", 3); +#ifdef GL_VERSION_1_2 + glutAddMenuEntry("OpenGL 1.2 separate specular", 4); +#endif + glutAddMenuEntry("Quit", 99); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c new file mode 100644 index 0000000000..7c478c79b4 --- /dev/null +++ b/progs/demos/stex3d.c @@ -0,0 +1,578 @@ +/* $Id: stex3d.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/*----------------------------- + * stex3d.c GL example of the mesa 3d-texture extention to simulate procedural + * texturing, it uses a perlin noise and turbulence functions. + * + * Author: Daniel Barrero + * barrero@irit.fr + * dbarrero@pegasus.uniandes.edu.co + * + * Converted to GLUT by brianp on 1/1/98 + * + * + * cc stex3d.c -o stex3d -lglut -lMesaGLU -lMesaGL -lX11 -lXext -lm + * + *---------------------------- */ + +/* + * $Log: stex3d.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.1 1998/06/09 01:53:49 brianp + * main() should return an int + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include +#include +#include +/* function declarations */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +void init(void), + printHelp(void), + create3Dtexture(void), + setDefaults(void), + drawScene(void), + resize(int w, int h), + buildFigure(void), + initNoise(void); +float turbulence(float point[3], float lofreq, float hifreq); + +int isExtSupported(char *ext); +void KeyHandler( unsigned char key, int x, int y ); +GLenum parseCmdLine(int argc, char **argv); +float noise3(float vec[3]); + +/* global variables */ +GLenum rgb, doubleBuffer, directRender, windType; /* visualization state*/ +float tex_width,tex_height,tex_depth; /* texture volume dimensions */ +unsigned char *voxels; /* texture data ptr */ +int angx,angy,angz; +GLuint figure; + +/*function definitions */ +int main(int argc, char **argv) +{ + + if (parseCmdLine(argc, argv) == GL_FALSE) { + exit(0); + } + + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + windType |= GLUT_DEPTH; + glutInitDisplayMode(windType); + + if (glutCreateWindow("stex3d") <= 0) { + exit(0); + } + /* init all */ + init(); + + glutReshapeFunc(resize); + glutKeyboardFunc(KeyHandler); + glutDisplayFunc(drawScene); + glutMainLoop(); + return 0; +} + +void init() +{ + /* init light */ + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 25.0 }; + GLfloat gray[] = { 0.6, 0.6, 0.6, 0.0 }; + GLfloat white[] = { 1.0, 1.0, 1.0, 0.0 }; + GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 }; + + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT1, GL_POSITION, light_position); + glLightfv(GL_LIGHT1, GL_AMBIENT, gray); + glLightfv(GL_LIGHT1, GL_DIFFUSE, white); + glLightfv(GL_LIGHT1, GL_SPECULAR, white); + glColorMaterial(GL_FRONT, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT1); + + /* create torus for texturing */ + figure=glGenLists(1); + buildFigure(); +/* tkSolidTorus(figure,0.3,1.2);*/ + + /* start the noise function variables */ + initNoise(); + + /* see if the texture 3d extention is supported */ + if (!isExtSupported("GL_EXT_texture3D")) { + printf("Sorry this GL implementation (%s) does not support 3d texture extentions\n", + (char *)(glGetString(GL_RENDERER))); +/* tkQuit();*/ + } + + /* if texture is supported then generate the texture */ + create3Dtexture(); + + glEnable(GL_TEXTURE_3D_EXT); + /* + glBlendFunc(GL_SRC_COLOR, GL_SRC_ALPHA); + glEnable(GL_BLEND); + */ + glEnable(GL_DEPTH_TEST); + + glShadeModel(GL_FLAT); + glColor3f(0.6,0.7,0.8); +} + +void buildFigure(void) +{ GLint i, j; + float theta1, phi1, theta2, phi2, rings, sides; + float v0[03], v1[3], v2[3], v3[3]; + float t0[03], t1[3], t2[3], t3[3]; + float n0[3], n1[3], n2[3], n3[3]; + float innerRadius=0.4; + float outerRadius=0.8; + float scalFac; + + rings = 8; + sides = 10; + scalFac=1/(outerRadius*2); + + glNewList(figure, GL_COMPILE); + for (i = 0; i < rings; i++) { + theta1 = (float)i * 2.0 * M_PI / rings; + theta2 = (float)(i + 1) * 2.0 * M_PI / rings; + for (j = 0; j < sides; j++) { + phi1 = (float)j * 2.0 * M_PI / sides; + phi2 = (float)(j + 1) * 2.0 * M_PI / sides; + + v0[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi1)); + v0[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi1)); + v0[2] = innerRadius * sin(phi1); + + v1[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi1)); + v1[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi1)); + v1[2] = innerRadius * sin(phi1); + v2[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi2)); + v2[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi2)); + v2[2] = innerRadius * sin(phi2); + + v3[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi2)); + v3[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi2)); + v3[2] = innerRadius * sin(phi2); + + n0[0] = cos(theta1) * (cos(phi1)); + n0[1] = -sin(theta1) * (cos(phi1)); + n0[2] = sin(phi1); + + n1[0] = cos(theta2) * (cos(phi1)); + n1[1] = -sin(theta2) * (cos(phi1)); + n1[2] = sin(phi1); + + n2[0] = cos(theta2) * (cos(phi2)); + n2[1] = -sin(theta2) * (cos(phi2)); + n2[2] = sin(phi2); + + n3[0] = cos(theta1) * (cos(phi2)); + n3[1] = -sin(theta1) * (cos(phi2)); + n3[2] = sin(phi2); + + t0[0] = v0[0]*scalFac + 0.5; + t0[1] = v0[1]*scalFac + 0.5; + t0[2] = v0[2]*scalFac + 0.5; + + t1[0] = v1[0]*scalFac + 0.5; + t1[1] = v1[1]*scalFac + 0.5; + t1[2] = v1[2]*scalFac + 0.5; + + t2[0] = v2[0]*scalFac + 0.5; + t2[1] = v2[1]*scalFac + 0.5; + t2[2] = v2[2]*scalFac + 0.5; + + t3[0] = v3[0]*scalFac + 0.5; + t3[1] = v3[1]*scalFac + 0.5; + t3[2] = v3[2]*scalFac + 0.5; + + glBegin(GL_POLYGON); + glNormal3fv(n3); glTexCoord3fv(t3); glVertex3fv(v3); + glNormal3fv(n2); glTexCoord3fv(t2); glVertex3fv(v2); + glNormal3fv(n1); glTexCoord3fv(t1); glVertex3fv(v1); + glNormal3fv(n0); glTexCoord3fv(t0); glVertex3fv(v0); + glEnd(); + } + } + glEndList(); +} + +void create3Dtexture() +{ + int i,j,k; + unsigned char *vp; + float vec[3]; + int tmp; + + printf("creating 3d textures...\n"); + voxels = (unsigned char *) malloc((4*tex_width*tex_height*tex_depth)); + vp=voxels; + for (i=0;i\n"); + printf(" cmd line options:\n"); + printf(" -help print this help!\n"); + printf(" -rgb RGBA mode. (Default)\n"); + printf(" -ci Color index mode.\n"); + printf(" -sb Single buffer mode. (Default)\n"); + printf(" -db Double buffer mode. \n"); + printf(" -dr Direct render mode.\n"); + printf(" -ir Indirect render mode. (Default)\n"); + printf(" -wxxx Width of the texture (Default=64)\n"); + printf(" -hxxx Height of the texture (Default=64)\n"); + printf(" -dxxx Depth of the texture (Default=64)\n"); + printf(" Keyboard Options:\n"); + printf(" 1 Object Texture coordinates (Default)\n"); + printf(" 2 Eye Texture coordinates \n"); + printf(" x rotate around x clockwise\n"); + printf(" X rotate around x counter clockwise\n"); + printf(" y rotate around y clockwise\n"); + printf(" Y rotate around y counter clockwise\n"); + printf(" z rotate around z clockwise\n"); + printf(" Z rotate around z counter clockwise\n"); + printf(" t enable 3-D texuring (Default)\n"); + printf(" T disable 3-D texuring\n"); + printf(" s smooth shading \n"); + printf(" S flat shading (Default)\n"); +} + +void setDefaults() +{ + /* visualization defaults */ + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + directRender = GL_TRUE; + angx=130; + angy=30; + angz=0; + /* texture values */ + tex_width=64; + tex_height=64; + tex_depth=64; +} + +GLenum parseCmdLine(int argc, char **argv) +{ + GLint i; + + setDefaults(); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-dr") == 0) { + directRender = GL_TRUE; + } else if (strcmp(argv[i], "-ir") == 0) { + directRender = GL_FALSE; + } else if (strstr(argv[i], "-w") == 0) { + tex_width=atoi((argv[i])+2); + } else if (strstr(argv[i], "-h") == 0) { + tex_height=atoi((argv[i])+2); + } else if (strstr(argv[i], "-d") == 0) { + tex_depth=atoi((argv[i])+2); + } else if (strcmp(argv[i], "-help") == 0) { + printHelp(); + return GL_FALSE; + } else { + printf("%s (Bad option).\n", argv[i]); + printHelp(); + return GL_FALSE; + } + } + if(tex_width==0 || tex_height==0 || tex_depth==0) { + printf("%s (Bad option).\n", "size parameters can't be 0"); + printHelp(); + return GL_FALSE; + } + return GL_TRUE; +} + +void drawScene() +{ + /* clear background, z buffer etc */ + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + glRotatef(angx,1.0,0.0,0.0); + glRotatef(angy,0.0,1.0,0.0); + glRotatef(angz,0.0,0.0,1.0); + + glCallList(figure); + glPopMatrix(); + glFlush(); + if(doubleBuffer) + glutSwapBuffers(); + ; +} + +void resize(int w, int h) +{ + glViewport(0, 0, (GLint)w, (GLint)h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-2,2,-2,2,-5,10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0,0,-5); +} + +void cleanEverything(void) +{ +/* free(voxels); */ +} + + +void KeyHandler( unsigned char key, int x, int y ) +{ + switch(key) { + case 27: + case 'q': + case 'Q': /* quit game. */ + cleanEverything(); + exit(0); + break; + case 'x': + angx+=10; + break; + case 'X': + angx-=10; + break; + case 'y': + angy+=10; + break; + case 'Y': + angy-=10; + break; + case 'z': + angz+=10; + break; + case 'Z': + angz-=10; + break; + case 't': + glEnable(GL_TEXTURE_3D_EXT); + break; + case 'T': + glDisable(GL_TEXTURE_3D_EXT); + break; + case 's': + glShadeModel(GL_SMOOTH); + break; + case 'S': + glShadeModel(GL_FLAT); + break; + case '1': + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + break; + case '2': + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + break; + default: + break; + } + glutPostRedisplay(); +} + +/*-------------------------------------------------------------------- + noise function over R3 - implemented by a pseudorandom tricubic spline + EXCERPTED FROM SIGGRAPH 92, COURSE 23 + PROCEDURAL MODELING + Ken Perlin + New York University +----------------------------------------------------------------------*/ + + +#define DOT(a,b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) +#define B 256 +static int p[B + B + 2]; +static float g[B + B + 2][3]; +#define setup(i,b0,b1,r0,r1) \ + t = vec[i] + 10000.; \ + b0 = ((int)t) & (B-1); \ + b1 = (b0+1) & (B-1); \ + r0 = t - (int)t; \ + r1 = r0 - 1.; + +float noise3(float vec[3]) +{ + int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; + float rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v; + register int i, j; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + setup(2, bz0,bz1, rz0,rz1); + + i = p[ bx0 ]; + j = p[ bx1 ]; + + b00 = p[ i + by0 ]; + b10 = p[ j + by0 ]; + b01 = p[ i + by1 ]; + b11 = p[ j + by1 ]; + +#define at(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) +#define surve(t) ( t * t * (3. - 2. * t) ) +#define lerp(t, a, b) ( a + t * (b - a) ) + + sx = surve(rx0); + sy = surve(ry0); + sz = surve(rz0); + + q = g[ b00 + bz0 ] ; u = at(rx0,ry0,rz0); + q = g[ b10 + bz0 ] ; v = at(rx1,ry0,rz0); + a = lerp(sx, u, v); + + q = g[ b01 + bz0 ] ; u = at(rx0,ry1,rz0); + q = g[ b11 + bz0 ] ; v = at(rx1,ry1,rz0); + b = lerp(sx, u, v); + + c = lerp(sy, a, b); /* interpolate in y at lo x */ + + q = g[ b00 + bz1 ] ; u = at(rx0,ry0,rz1); + q = g[ b10 + bz1 ] ; v = at(rx1,ry0,rz1); + a = lerp(sx, u, v); + + q = g[ b01 + bz1 ] ; u = at(rx0,ry1,rz1); + q = g[ b11 + bz1 ] ; v = at(rx1,ry1,rz1); + b = lerp(sx, u, v); + + d = lerp(sy, a, b); /* interpolate in y at hi x */ + + return 1.5 * lerp(sz, c, d); /* interpolate in z */ +} + +void initNoise() +{ + /*long random();*/ + int i, j, k; + float v[3], s; + +/* Create an array of random gradient vectors uniformly on the unit sphere */ + /*srandom(1);*/ + srand(1); + for (i = 0 ; i < B ; i++) { + do { /* Choose uniformly in a cube */ for (j=0 ; j<3 ; j++) + v[j] = (float)((rand() % (B + B)) - B) / B; + s = DOT(v,v); + } while (s > 1.0); /* If not in sphere try again */ s = sqrt(s); + for (j = 0 ; j < 3 ; j++) /* Else normalize */ + g[i][j] = v[j] / s; + } + +/* Create a pseudorandom permutation of [1..B] */ + for (i = 0 ; i < B ; i++) + p[i] = i; + for (i = B ; i > 0 ; i -= 2) { + k = p[i]; + p[i] = p[j = rand() % B]; + p[j] = k; + } + +/* Extend g and p arrays to allow for faster indexing */ + for (i = 0 ; i < B + 2 ; i++) { + p[B + i] = p[i]; + for (j = 0 ; j < 3 ; j++) + g[B + i][j] = g[i][j]; + } +} + +float turbulence(float point[3], float lofreq, float hifreq) +{ + float freq, t, p[3]; + + p[0] = point[0] + 123.456; + p[1] = point[1]; + p[2] = point[2]; + + t = 0; + for (freq = lofreq ; freq < hifreq ; freq *= 2.) { + t += fabs(noise3(p)) / freq; + p[0] *= 2.; + p[1] *= 2.; + p[2] *= 2.; + } + return t - 0.3; /* readjust to make mean value = 0.0 */ +} + diff --git a/progs/demos/tessdemo.c b/progs/demos/tessdemo.c new file mode 100644 index 0000000000..497b105a88 --- /dev/null +++ b/progs/demos/tessdemo.c @@ -0,0 +1,439 @@ +/* $Id: tessdemo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * A demo of the GLU polygon tesselation functions written by Bogdan Sikorski. + * This demo isn't built by the Makefile because it needs GLUT. After you've + * installed GLUT you can try this demo. + * Here's the command for IRIX, for example: + cc -g -ansi -prototypes -fullwarn -float -I../include -DSHM tess_demo.c -L../lib -lglut -lMesaGLU -lMesaGL -lm -lX11 -lXext -lXmu -lfpe -lXext -o tess_demo + */ + + +/* + * $Log: tessdemo.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.5 1999/03/28 18:24:37 brianp + * minor clean-up + * + * Revision 3.4 1999/02/14 03:37:07 brianp + * fixed callback problem + * + * Revision 3.3 1998/07/26 01:25:26 brianp + * removed include of gl.h and glu.h + * + * Revision 3.2 1998/06/29 02:37:30 brianp + * minor changes for Windows (Ted Jump) + * + * Revision 3.1 1998/06/09 01:53:49 brianp + * main() should return an int + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + +#define MAX_POINTS 200 +#define MAX_CONTOURS 50 + +int menu; +typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries; +typedef enum{ DEFINE, TESSELATED } mode_type; +struct +{ + GLint p[MAX_POINTS][2]; + GLuint point_cnt; +} contours[MAX_CONTOURS]; +GLuint contour_cnt; +GLsizei width,height; +mode_type mode; + +struct +{ + GLsizei no; + GLfloat color[3]; + GLint p[3][2]; + GLclampf p_color[3][3]; +} triangle; + + +#ifndef GLCALLBACK +#ifdef CALLBACK +#define GLCALLBACK CALLBACK +#else +#define GLCALLBACK +#endif +#endif + + +void GLCALLBACK my_error(GLenum err) +{ + int len,i; + char const *str; + + glColor3f(0.9,0.9,0.9); + glRasterPos2i(5,5); + str=(const char *)gluErrorString(err); + len=strlen(str); + for(i=0;i2) + { + glBegin(GL_LINES); + glVertex2iv(contours[contour_cnt].p[0]); + glVertex2iv(contours[contour_cnt].p[point_cnt-1]); + contours[contour_cnt].p[point_cnt][0]= -1; + glEnd(); + glFinish(); + contour_cnt++; + contours[contour_cnt].point_cnt=0; + } +} + +void mouse_clicked(int button,int state,int x,int y) +{ + x-= x%10; + y-= y%10; + switch(button) + { + case GLUT_LEFT_BUTTON: + if(state==GLUT_DOWN) + left_down(x,y); + break; + case GLUT_MIDDLE_BUTTON: + if(state==GLUT_DOWN) + middle_down(x,y); + break; + } +} + +void display(void) +{ + GLuint i,j; + GLuint point_cnt; + + glClear(GL_COLOR_BUFFER_BIT); + switch(mode) + { + case DEFINE: + /* draw grid */ + glColor3f (0.6,0.5,0.5); + glBegin(GL_LINES); + for(i=0;i +#include +#include +#include + +#include "../util/readtex.c" /* I know, this is a hack. */ + +#define TEXTURE_FILE "../images/reflect.rgb" + +#define LIT 1 +#define TEXTURED 2 +#define REFLECT 3 +#define ANIMATE 10 +#define POINT_FILTER 20 +#define LINEAR_FILTER 21 +#define QUIT 100 + +static GLuint CylinderObj = 0; +static GLboolean Animate = GL_TRUE; + +static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; +static GLfloat DXrot = 1.0, DYrot = 2.5; + + +static void Idle( void ) +{ + if (Animate) { + Xrot += DXrot; + Yrot += DYrot; + glutPostRedisplay(); + } +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1.0, 0.0, 0.0); + glRotatef(Yrot, 0.0, 1.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + glScalef(5.0, 5.0, 5.0); + glCallList(CylinderObj); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -70.0 ); +} + + +static void SetMode(GLuint m) +{ + /* disable everything */ + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + + /* enable what's needed */ + if (m==LIT) { + glEnable(GL_LIGHTING); + } + else if (m==TEXTURED) { + glEnable(GL_TEXTURE_2D); + } + else if (m==REFLECT) { + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } +} + + +static void ModeMenu(int entry) +{ + if (entry==ANIMATE) { + Animate = !Animate; + } + else if (entry==POINT_FILTER) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + else if (entry==LINEAR_FILTER) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + else if (entry==QUIT) { + exit(0); + } + else { + SetMode(entry); + } + glutPostRedisplay(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + float step = 3.0; + (void) x; + (void) y; + + switch (key) { + case GLUT_KEY_UP: + Xrot += step; + break; + case GLUT_KEY_DOWN: + Xrot -= step; + break; + case GLUT_KEY_LEFT: + Yrot += step; + break; + case GLUT_KEY_RIGHT: + Yrot -= step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + GLUquadricObj *q = gluNewQuadric(); + CylinderObj = glGenLists(1); + glNewList(CylinderObj, GL_COMPILE); + + glTranslatef(0.0, 0.0, -1.0); + + /* cylinder */ + gluQuadricNormals(q, GL_SMOOTH); + gluQuadricTexture(q, GL_TRUE); + gluCylinder(q, 0.6, 0.6, 2.0, 24, 1); + + /* end cap */ + glTranslatef(0.0, 0.0, 2.0); + gluDisk(q, 0.0, 0.6, 24, 1); + + /* other end cap */ + glTranslatef(0.0, 0.0, -2.0); + gluQuadricOrientation(q, GLU_INSIDE); + gluDisk(q, 0.0, 0.6, 24, 1); + + glEndList(); + gluDeleteQuadric(q); + + /* lighting */ + glEnable(GL_LIGHTING); + { + GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0}; + GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; + GLfloat teal[4] = { 0.0, 1.0, 0.8, 1.0 }; + glMaterialfv(GL_FRONT, GL_DIFFUSE, teal); + glLightfv(GL_LIGHT0, GL_AMBIENT, gray); + glLightfv(GL_LIGHT0, GL_DIFFUSE, white); + glEnable(GL_LIGHT0); + } + + /* fitering = nearest, initially */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + + glEnable(GL_CULL_FACE); /* don't need Z testing for convex objects */ + + SetMode(LIT); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowSize( 400, 400 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0] ); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("Lit", LIT); + glutAddMenuEntry("Textured", TEXTURED); + glutAddMenuEntry("Reflect", REFLECT); + glutAddMenuEntry("Point Filtered", POINT_FILTER); + glutAddMenuEntry("Linear Filtered", LINEAR_FILTER); + glutAddMenuEntry("Toggle Animation", ANIMATE); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/texobj.c b/progs/demos/texobj.c new file mode 100644 index 0000000000..673923cb79 --- /dev/null +++ b/progs/demos/texobj.c @@ -0,0 +1,289 @@ +/* $Id: texobj.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */ + +/* + * Example of using the 1.1 texture object functions. + * Also, this demo utilizes Mesa's fast texture map path. + * + * Brian Paul June 1996 This file is in the public domain. + */ + + +/* + * $Log: texobj.c,v $ + * Revision 1.1 1999/08/19 00:55:40 jtg + * Initial revision + * + * Revision 3.1 1999/03/28 18:24:37 brianp + * minor clean-up + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include +#include +#include +#include "GL/glut.h" + +static GLuint Window = 0; + +static GLuint TexObj[2]; +static GLfloat Angle = 0.0f; +static GLboolean HaveTexObj = GL_FALSE; + + +#if defined(GL_VERSION_1_1) +# define TEXTURE_OBJECT 1 +#elif defined(GL_EXT_texture_object) +# define TEXTURE_OBJECT 1 +# define glBindTexture(A,B) glBindTextureEXT(A,B) +# define glGenTextures(A,B) glGenTexturesEXT(A,B) +# define glDeleteTextures(A,B) glDeleteTexturesEXT(A,B) +#endif + + + + +static void draw( void ) +{ + glDepthFunc(GL_EQUAL); + /* glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );*/ + glClear( GL_COLOR_BUFFER_BIT ); + + glColor3f( 1.0, 1.0, 1.0 ); + + /* draw first polygon */ + glPushMatrix(); + glTranslatef( -1.0, 0.0, 0.0 ); + glRotatef( Angle, 0.0, 0.0, 1.0 ); + if (HaveTexObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[0] ); +#endif + } + else { + glCallList( TexObj[0] ); + } + glBegin( GL_POLYGON ); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); + glEnd(); + glPopMatrix(); + + /* draw second polygon */ + glPushMatrix(); + glTranslatef( 1.0, 0.0, 0.0 ); + glRotatef( Angle-90.0, 0.0, 1.0, 0.0 ); + if (HaveTexObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[1] ); +#endif + } + else { + glCallList( TexObj[0] ); + } + glBegin( GL_POLYGON ); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); + glEnd(); + glPopMatrix(); + + glutSwapBuffers(); +} + + + +static void idle( void ) +{ + Angle += 2.0; + glutPostRedisplay(); +} + + + +/* change view Angle, exit upon ESC */ +static void key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 27: +#ifdef TEXTURE_OBJECT + glDeleteTextures( 2, TexObj ); +#endif + glutDestroyWindow(Window); + exit(0); + } +} + + + +/* new window size or exposure */ +static void reshape( int width, int height ) +{ + glViewport(0, 0, (GLint)width, (GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/ + glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -8.0 ); +} + + +static void init( void ) +{ + static int width=8, height=8; + static GLubyte tex1[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + static GLubyte tex2[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, 2, 0, 0, 0, + 0, 0, 2, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 2, 0, 0, 0, 0, + 0, 0, 2, 2, 2, 2, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + GLubyte tex[64][3]; + GLint i, j; + + + glDisable( GL_DITHER ); + + /* Setup texturing */ + glEnable( GL_TEXTURE_2D ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); + + + /* generate texture object IDs */ + if (HaveTexObj) { +#ifdef TEXTURE_OBJECT + glGenTextures( 2, TexObj ); +#endif + } + else { + TexObj[0] = glGenLists(2); + TexObj[1] = TexObj[0]+1; + } + + /* setup first texture object */ + if (HaveTexObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[0] ); +#endif + } + else { + glNewList( TexObj[0], GL_COMPILE ); + } + /* red on white */ + for (i=0;i +#include +#include +#include +#include + + +static float MinPeriod = 2.0; /* 2 seconds */ +static float Width = 400.0; +static float Height = 400.0; +static int Loops = 1; +static int Size = 50; +static int Texture = 0; + + + +static void Idle( void ) +{ + glutPostRedisplay(); +} + + +static void Display( void ) +{ + float x, y; + float xStep; + float yStep; + double t0, t1; + double triRate; + double pixelRate; + int triCount; + int i; + float red[3] = { 1.0, 0.0, 0.0 }; + float blue[3] = { 0.0, 0.0, 1.0 }; + + xStep = yStep = sqrt( 2.0 * Size ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + triCount = 0; + t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + if (Texture) { + float uStep = xStep / Width; + float vStep = yStep / Height; + float u, v; + for (i=0; i +#include +#include +#include +#include "GL/glut.h" + +#include "../util/readtex.c" /* a hack, I know */ + +#define IMAGE_FILE "../images/girl.rgb" + + +#ifndef M_PI +# define M_PI 3.14159265 +#endif + + + +static GLubyte *Image; +static int ImgWidth, ImgHeight; +static GLenum ImgFormat; + + + +static void draw( void ) +{ + GLfloat angle; + char *extensions; + + extensions = (char *) glGetString( GL_EXTENSIONS ); + if (strstr( extensions, "GL_MESA_window_pos")==NULL) { + printf("Sorry, GL_MESA_window_pos extension not available.\n"); + return; + } + + glClear( GL_COLOR_BUFFER_BIT ); + + for (angle = -45.0; angle <= 135.0; angle += 10.0) { + GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 ); + GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 ); + + /* Don't need to worry about the modelview or projection matrices!!! */ +#ifdef GL_MESA_window_pos + glWindowPos2fMESA( x, y ); +#endif + glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image ); + } +} + + + + +static void key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + } +} + + + +/* new window size or exposure */ +static void reshape( int width, int height ) +{ + glViewport(0, 0, (GLint)width, (GLint)height); +} + + +static void init( void ) +{ + Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); + if (!Image) { + printf("Couldn't read %s\n", IMAGE_FILE); + exit(0); + } + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} + + + +int main( int argc, char *argv[] ) +{ + glutInitWindowPosition(0, 0); + glutInitWindowSize(500, 500); + glutInitDisplayMode( GLUT_RGB ); + + if (glutCreateWindow("winpos") <= 0) { + exit(0); + } + + init(); + + glutReshapeFunc( reshape ); + glutKeyboardFunc( key ); + glutDisplayFunc( draw ); + glutMainLoop(); + return 0; +} diff --git a/progs/images/girl.rgb b/progs/images/girl.rgb new file mode 100644 index 0000000000..8901e45e19 Binary files /dev/null and b/progs/images/girl.rgb differ diff --git a/progs/images/reflect.rgb b/progs/images/reflect.rgb new file mode 100644 index 0000000000..45319e9634 Binary files /dev/null and b/progs/images/reflect.rgb differ diff --git a/progs/images/tile.rgb b/progs/images/tile.rgb new file mode 100644 index 0000000000..5c1c73b06e Binary files /dev/null and b/progs/images/tile.rgb differ diff --git a/progs/redbook/Imakefile b/progs/redbook/Imakefile new file mode 100644 index 0000000000..23a6b165ad --- /dev/null +++ b/progs/redbook/Imakefile @@ -0,0 +1,222 @@ +LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\Mesaaux.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a + +INCLUDES = -I$(TOP)\include + +SRCS = accanti.c \ + accnot.c \ + accpersp.c \ + accum.c \ + aim.c \ + alpha.c \ + alpha3D.c \ + anti.c \ + antiindex.c \ + antipindex.c \ + antipoint.c \ + antipoly.c \ + bezcurve.c \ + bezmesh.c \ + bezsurf.c \ + checker.c \ + checker2.c \ + chess.c \ + clip.c \ + colormat.c \ + cone.c \ + cube.c \ + curve.c \ + depthcue.c \ + disk.c \ + dof.c \ + dofnot.c \ + double.c \ + drawf.c \ + feedback.c \ + fog.c \ + fogindex.c \ + font.c \ + light.c \ + linelist.c \ + lines.c \ + list.c \ + list2.c \ + maplight.c \ + material.c \ + mipmap.c \ + model.c \ + movelight.c \ + nurbs.c \ + pickdepth.c \ + pickline.c \ + picksquare.c \ + plane.c \ + planet.c \ + planetup.c \ + polys.c \ + robot.c \ + sccolorlight.c \ + scene.c \ + scenebamb.c \ + sceneflat.c \ + select.c \ + simple.c \ + smooth.c \ + sphere.c \ + stencil.c \ + stroke.c \ + surface.c \ + tea.c \ + teaambient.c \ + teapots.c \ + texgen.c \ + texturesurf.c \ + trim.c \ + xfont.c + +PROGRAMS = ProgramTargetName(accanti) \ + ProgramTargetName(accnot) \ + ProgramTargetName(accpersp) \ + ProgramTargetName(accum) \ + ProgramTargetName(aim) \ + ProgramTargetName(alpha) \ + ProgramTargetName(alpha3D) \ + ProgramTargetName(anti) \ + ProgramTargetName(antiindex) \ + ProgramTargetName(antipindex) \ + ProgramTargetName(antipoint) \ + ProgramTargetName(antipoly) \ + ProgramTargetName(bezcurve) \ + ProgramTargetName(bezmesh) \ + ProgramTargetName(bezsurf) \ + ProgramTargetName(checker) \ + ProgramTargetName(checker2) \ + ProgramTargetName(chess) \ + ProgramTargetName(clip) \ + ProgramTargetName(colormat) \ + ProgramTargetName(cone) \ + ProgramTargetName(cube) \ + ProgramTargetName(curve) \ + ProgramTargetName(depthcue) \ + ProgramTargetName(disk) \ + ProgramTargetName(dof) \ + ProgramTargetName(dofnot) \ + ProgramTargetName(double) \ + ProgramTargetName(drawf) \ + ProgramTargetName(feedback) \ + ProgramTargetName(fog) \ + ProgramTargetName(fogindex) \ + ProgramTargetName(font) \ + ProgramTargetName(light) \ + ProgramTargetName(linelist) \ + ProgramTargetName(lines) \ + ProgramTargetName(list) \ + ProgramTargetName(list2) \ + ProgramTargetName(maplight) \ + ProgramTargetName(material) \ + ProgramTargetName(mipmap) \ + ProgramTargetName(model) \ + ProgramTargetName(movelight) \ + ProgramTargetName(nurbs) \ + ProgramTargetName(pickdepth) \ + ProgramTargetName(pickline) \ + ProgramTargetName(picksquare) \ + ProgramTargetName(plane) \ + ProgramTargetName(planet) \ + ProgramTargetName(planetup) \ + ProgramTargetName(polys) \ + ProgramTargetName(robot) \ + ProgramTargetName(sccolorlight) \ + ProgramTargetName(scene) \ + ProgramTargetName(scenebamb) \ + ProgramTargetName(sceneflat) \ + ProgramTargetName(select) \ + ProgramTargetName(simple) \ + ProgramTargetName(smooth) \ + ProgramTargetName(sphere) \ + ProgramTargetName(stencil) \ + ProgramTargetName(stroke) \ + ProgramTargetName(surface) \ + ProgramTargetName(tea) \ + ProgramTargetName(teaambient) \ + ProgramTargetName(teapots) \ + ProgramTargetName(texgen) \ + ProgramTargetName(texturesurf) \ + ProgramTargetName(trim) \ + ProgramTargetName(xfont) + +AllTarget($(PROGRAMS)) + +NormalProgramTarget(accanti,accanti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(accnot,accnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(accpersp,accpersp.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(aim,aim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(alpha,alpha.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(alpha3D,alpha3D.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(anti,anti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(antiindex,antiindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(antipindex,antipindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(antipoint,antipoint.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(antipoly,antipoly.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(bezcurve,bezcurve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(bezmesh,bezmesh.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(bezsurf,bezsurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(checker,checker.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(checker2,checker2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(chess,chess.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(clip,clip.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(colormat,colormat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(cone,cone.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(cube,cube.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(curve,curve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(depthcue,depthcue.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(disk,disk.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(dof,dof.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(dofnot,dofnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(double,double.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(drawf,drawf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(feedback,feedback.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(fogindex,fogindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(light,light.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(linelist,linelist.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(lines,lines.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(list,list.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(list2,list2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(maplight,maplight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(material,material.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(mipmap,mipmap.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(model,model.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(movelight,movelight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(nurbs,nurbs.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(pickdepth,pickdepth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(pickline,pickline.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(picksquare,picksquare.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(plane,plane.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(planet,planet.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(planetup,planetup.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(polys,polys.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(robot,robot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(sccolorlight,sccolorlight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(scene,scene.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(scenebamb,scenebamb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(sceneflat,sceneflat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(simple,simple.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(smooth,smooth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(stroke,stroke.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(surface,surface.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(tea,tea.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(teaambient,teaambient.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(teapots,teapots.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(texgen,texgen.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(texturesurf,texturesurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(trim,trim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(xfont,xfont.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) + +DependTarget() + + \ No newline at end of file diff --git a/progs/redbook/Makefile.BeOS-R4 b/progs/redbook/Makefile.BeOS-R4 new file mode 100644 index 0000000000..f99e8edf4c --- /dev/null +++ b/progs/redbook/Makefile.BeOS-R4 @@ -0,0 +1,70 @@ +# $Id: Makefile.BeOS-R4,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Makefile for OpenGL Programming Guide programs for BeOS R4 +# This file is in the public domain. + + +# $Log: Makefile.BeOS-R4,v $ +# Revision 1.1 1999/08/19 00:55:40 jtg +# Initial revision +# +# Revision 1.1 1999/02/25 02:13:06 brianp +# initial check-in +# + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -L/boot/home/config/lib -Xlinker -rpath $(LIBDIR) -lbe -lglut -lMesaGLU -lMesaGL $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +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 robot sccolorlight \ + scene scenebamb sceneflat select smooth stencil stroke surface \ + teaambient teapots tess tesswind texbind texgen texprox texsub \ + texturesurf torus unproject varray wrap + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config + diff --git a/progs/redbook/Makefile.X11 b/progs/redbook/Makefile.X11 new file mode 100644 index 0000000000..129918c241 --- /dev/null +++ b/progs/redbook/Makefile.X11 @@ -0,0 +1,64 @@ +# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:40 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1998 Brian Paul + +# Makefile for programs from the OpenGL Programming Guide + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +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 + + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ###### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config diff --git a/progs/redbook/Makefile.win b/progs/redbook/Makefile.win new file mode 100644 index 0000000000..79c4f67551 --- /dev/null +++ b/progs/redbook/Makefile.win @@ -0,0 +1,81 @@ +# Makefile for Win32 + +TOP = .. + +!include "$(TOP)/names.win" + +!include + +SRCS= \ + accanti.c \ + accnot.c \ + accum.c \ + aim.c \ + alpha.c \ + alpha3D.c \ + anti.c \ + antiindex.c \ + antipindex.c \ + antipoint.c \ + antipoly.c \ + bezcurve.c \ + bezmesh.c \ + bezsurf.c \ + checker.c \ + checker2.c \ + chess.c \ + clip.c \ + colormat.c \ + cone.c \ + cube.c \ + curve.c \ + depthcue.c \ + disk.c \ + dof.c \ + dofnot.c \ + double.c \ + drawf.c \ + feedback.c \ + fog.c \ + fogindex.c \ + font.c \ + light.c \ + linelist.c \ + lines.c \ + list.c \ + list2.c \ + maplight.c \ + material.c \ + mipmap.c \ + model.c \ + movelight.c \ + nurbs.c \ + pickdepth.c \ + pickline.c \ + picksquare.c \ + plane.c \ + planet.c \ + planetup.c \ + polys.c \ + robot.c \ + sccolorlight.c \ + scene.c \ + scenebamb.c \ + sceneflat.c \ + select.c \ + smooth.c \ + sphere.c \ + stencil.c \ + stroke.c \ + surface.c \ + tea.c \ + teaambient.c \ + teapots.c \ + texgen.c \ + texturesurf.c \ + trim.c + +EXTRALIBS = $(MESAGL).lib $(MESAGLU).lib $(MESATK).lib $(MESAAUX).lib + +!include "$(TOP)/mesawin32.mak" + diff --git a/progs/redbook/README b/progs/redbook/README new file mode 100644 index 0000000000..4c8d5a74c9 --- /dev/null +++ b/progs/redbook/README @@ -0,0 +1,41 @@ +/* + * For the software in this directory + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +The source code examples in this directory accompany the examples +printed in the _OpenGL Programming Guide_, published by Addison-Wesley; +ISBN 0-201-63274-8. diff --git a/progs/redbook/aaindex.c b/progs/redbook/aaindex.c new file mode 100644 index 0000000000..7dbc7b4b9b --- /dev/null +++ b/progs/redbook/aaindex.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * aaindex.c + * This program draws shows how to draw anti-aliased lines in color + * index mode. It draws two diagonal lines to form an X; when 'r' + * is typed in the window, the lines are rotated in opposite + * directions. + */ +#include +#include "stdlib.h" + +#define RAMPSIZE 16 +#define RAMP1START 32 +#define RAMP2START 48 + +static float rotAngle = 0.; + +/* Initialize antialiasing for color index mode, + * including loading a green color ramp starting + * at RAMP1START, and a blue color ramp starting + * at RAMP2START. The ramps must be a multiple of 16. + */ +void init(void) +{ + int i; + + for (i = 0; i < RAMPSIZE; i++) { + GLfloat shade; + shade = (GLfloat) i/(GLfloat) RAMPSIZE; + glutSetColor(RAMP1START+(GLint)i, 0., shade, 0.); + glutSetColor(RAMP2START+(GLint)i, 0., 0., shade); + } + + glEnable (GL_LINE_SMOOTH); + glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); + glLineWidth (1.5); + + glClearIndex ((GLfloat) RAMP1START); +} + +/* Draw 2 diagonal lines to form an X + */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glIndexi(RAMP1START); + glPushMatrix(); + glRotatef(-rotAngle, 0.0, 0.0, 0.1); + glBegin (GL_LINES); + glVertex2f (-0.5, 0.5); + glVertex2f (0.5, -0.5); + glEnd (); + glPopMatrix(); + + glIndexi(RAMP2START); + glPushMatrix(); + glRotatef(rotAngle, 0.0, 0.0, 0.1); + glBegin (GL_LINES); + glVertex2f (0.5, 0.5); + glVertex2f (-0.5, -0.5); + glEnd (); + glPopMatrix(); + + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D (-1.0, 1.0, + -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w); + else + gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h, + 1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'r': + case 'R': + rotAngle += 20.; + if (rotAngle >= 360.) rotAngle = 0.; + glutPostRedisplay(); + break; + case 27: /* Escape Key */ + exit(0); + break; + default: + break; + } +} + +/* Main Loop + * Open window with initial window size, title bar, + * color index display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_INDEX); + glutInitWindowSize (200, 200); + glutCreateWindow (argv[0]); + init(); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/aapoly.c b/progs/redbook/aapoly.c new file mode 100644 index 0000000000..757f0f48c4 --- /dev/null +++ b/progs/redbook/aapoly.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * aapoly.c + * This program draws filled polygons with antialiased + * edges. The special GL_SRC_ALPHA_SATURATE blending + * function is used. + * Pressing the 't' key turns the antialiasing on and off. + */ +#include +#include +#include +#include + +GLboolean polySmooth = GL_TRUE; + +static void init(void) +{ + glCullFace (GL_BACK); + glEnable (GL_CULL_FACE); + glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE); + glClearColor (0.0, 0.0, 0.0, 0.0); +} + +#define NFACE 6 +#define NVERT 8 +void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1, + GLdouble z0, GLdouble z1) +{ + static GLfloat v[8][3]; + static GLfloat c[8][4] = { + {0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0}, + {0.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0}, + {0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0}, + {0.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0} + }; + +/* indices of front, top, left, bottom, right, back faces */ + static GLubyte indices[NFACE][4] = { + {4, 5, 6, 7}, {2, 3, 7, 6}, {0, 4, 7, 3}, + {0, 1, 5, 4}, {1, 5, 6, 2}, {0, 3, 2, 1} + }; + + v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0; + v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1; + v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0; + v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1; + v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0; + v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1; + +#ifdef GL_VERSION_1_1 + glEnableClientState (GL_VERTEX_ARRAY); + glEnableClientState (GL_COLOR_ARRAY); + glVertexPointer (3, GL_FLOAT, 0, v); + glColorPointer (4, GL_FLOAT, 0, c); + glDrawElements (GL_QUADS, NFACE*4, GL_UNSIGNED_BYTE, indices); + glDisableClientState (GL_VERTEX_ARRAY); + glDisableClientState (GL_COLOR_ARRAY); +#else + printf ("If this is GL Version 1.0, "); + printf ("vertex arrays are not supported.\n"); + exit(1); +#endif +} + +/* Note: polygons must be drawn from front to back + * for proper blending. + */ +void display(void) +{ + if (polySmooth) { + glClear (GL_COLOR_BUFFER_BIT); + glEnable (GL_BLEND); + glEnable (GL_POLYGON_SMOOTH); + glDisable (GL_DEPTH_TEST); + } + else { + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glDisable (GL_BLEND); + glDisable (GL_POLYGON_SMOOTH); + glEnable (GL_DEPTH_TEST); + } + + glPushMatrix (); + glTranslatef (0.0, 0.0, -8.0); + glRotatef (30.0, 1.0, 0.0, 0.0); + glRotatef (60.0, 0.0, 1.0, 0.0); + drawCube(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5); + glPopMatrix (); + + glFlush (); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(30.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 't': + case 'T': + polySmooth = !polySmooth; + glutPostRedisplay(); + break; + case 27: + exit(0); /* Escape key */ + break; + default: + break; + } +} + +/* Main Loop + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB + | GLUT_ALPHA | GLUT_DEPTH); + glutInitWindowSize(200, 200); + glutCreateWindow(argv[0]); + init (); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} + diff --git a/progs/redbook/aargb.c b/progs/redbook/aargb.c new file mode 100644 index 0000000000..f51984170e --- /dev/null +++ b/progs/redbook/aargb.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * aargb.c + * This program draws shows how to draw anti-aliased lines. It draws + * two diagonal lines to form an X; when 'r' is typed in the window, + * the lines are rotated in opposite directions. + */ +#include +#include +#include + +static float rotAngle = 0.; + +/* Initialize antialiasing for RGBA mode, including alpha + * blending, hint, and line width. Print out implementation + * specific info on line width granularity and width. + */ +void init(void) +{ + GLfloat values[2]; + glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); + printf ("GL_LINE_WIDTH_GRANULARITY value is %3.1f\n", values[0]); + + glGetFloatv (GL_LINE_WIDTH_RANGE, values); + printf ("GL_LINE_WIDTH_RANGE values are %3.1f %3.1f\n", + values[0], values[1]); + + glEnable (GL_LINE_SMOOTH); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); + glLineWidth (1.5); + + glClearColor(0.0, 0.0, 0.0, 0.0); +} + +/* Draw 2 diagonal lines to form an X + */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f (0.0, 1.0, 0.0); + glPushMatrix(); + glRotatef(-rotAngle, 0.0, 0.0, 0.1); + glBegin (GL_LINES); + glVertex2f (-0.5, 0.5); + glVertex2f (0.5, -0.5); + glEnd (); + glPopMatrix(); + + glColor3f (0.0, 0.0, 1.0); + glPushMatrix(); + glRotatef(rotAngle, 0.0, 0.0, 0.1); + glBegin (GL_LINES); + glVertex2f (0.5, 0.5); + glVertex2f (-0.5, -0.5); + glEnd (); + glPopMatrix(); + + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D (-1.0, 1.0, + -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w); + else + gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h, + 1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'r': + case 'R': + rotAngle += 20.; + if (rotAngle >= 360.) rotAngle = 0.; + glutPostRedisplay(); + break; + case 27: /* Escape Key */ + exit(0); + break; + 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_SINGLE | GLUT_RGB); + glutInitWindowSize (200, 200); + glutCreateWindow (argv[0]); + init(); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/accanti.c b/progs/redbook/accanti.c new file mode 100644 index 0000000000..d45cf9e64e --- /dev/null +++ b/progs/redbook/accanti.c @@ -0,0 +1,168 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* accanti.c + */ +#include +#include +#include "jitter.h" + +/* Initialize lighting and other values. + */ +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 }; + GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 }; + GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 50.0); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel (GL_FLAT); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearAccum(0.0, 0.0, 0.0, 0.0); +} + +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 }; + GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 }; + GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 }; + + glPushMatrix (); + glRotatef (30.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.80, 0.35, 0.0); + glRotatef (100.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse); + glutSolidTorus (0.275, 0.85, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.50, 0.0); + glRotatef (45.0, 0.0, 0.0, 1.0); + glRotatef (45.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse); + glutSolidCube (1.5); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.60, 0.0); + glRotatef (30.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse); + glutSolidSphere (1.0, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.70, -0.90, 0.25); + glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse); + glutSolidOctahedron (); + glPopMatrix (); + + glPopMatrix (); +} + +#define ACSIZE 8 + +void display(void) +{ + GLint viewport[4]; + int jitter; + + glGetIntegerv (GL_VIEWPORT, viewport); + + glClear(GL_ACCUM_BUFFER_BIT); + for (jitter = 0; jitter < ACSIZE; jitter++) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix (); +/* Note that 4.5 is the distance in world space between + * left and right and bottom and top. + * This formula converts fractional pixel movement to + * world coordinates. + */ + glTranslatef (j8[jitter].x*4.5/viewport[2], + j8[jitter].y*4.5/viewport[3], 0.0); + displayObjects (); + glPopMatrix (); + glAccum(GL_ACCUM, 1.0/ACSIZE); + } + glAccum (GL_RETURN, 1.0); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-2.25, 2.25, -2.25*h/w, 2.25*h/w, -10.0, 10.0); + else + glOrtho (-2.25*w/h, 2.25*w/h, -2.25, 2.25, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB + | GLUT_ACCUM | GLUT_DEPTH); + glutInitWindowSize (250, 250); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/accpersp.c b/progs/redbook/accpersp.c new file mode 100644 index 0000000000..46e369ae63 --- /dev/null +++ b/progs/redbook/accpersp.c @@ -0,0 +1,240 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* accpersp.c + * Use the accumulation buffer to do full-scene antialiasing + * on a scene with perspective projection, using the special + * routines accFrustum() and accPerspective(). + */ +#include +#include +#include +#include "jitter.h" + +#define PI_ 3.14159265358979323846 + +/* accFrustum() + * The first 6 arguments are identical to the glFrustum() call. + * + * pixdx and pixdy are anti-alias jitter in pixels. + * Set both equal to 0.0 for no anti-alias jitter. + * eyedx and eyedy are depth-of field jitter in pixels. + * Set both equal to 0.0 for no depth of field effects. + * + * focus is distance from eye to plane in focus. + * focus must be greater than, but not equal to 0.0. + * + * Note that accFrustum() calls glTranslatef(). You will + * probably want to insure that your ModelView matrix has been + * initialized to identity before calling accFrustum(). + */ +void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble nnear, GLdouble ffar, GLdouble pixdx, + GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) +{ + GLdouble xwsize, ywsize; + GLdouble dx, dy; + GLint viewport[4]; + + glGetIntegerv (GL_VIEWPORT, viewport); + + xwsize = right - left; + ywsize = top - bottom; + + dx = -(pixdx*xwsize/(GLdouble) viewport[2] + eyedx*nnear/focus); + dy = -(pixdy*ywsize/(GLdouble) viewport[3] + eyedy*nnear/focus); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum (left + dx, right + dx, bottom + dy, top + dy, nnear, ffar); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef (-eyedx, -eyedy, 0.0); +} + +/* accPerspective() + * + * The first 4 arguments are identical to the gluPerspective() call. + * pixdx and pixdy are anti-alias jitter in pixels. + * Set both equal to 0.0 for no anti-alias jitter. + * eyedx and eyedy are depth-of field jitter in pixels. + * Set both equal to 0.0 for no depth of field effects. + * + * focus is distance from eye to plane in focus. + * focus must be greater than, but not equal to 0.0. + * + * Note that accPerspective() calls accFrustum(). + */ +void accPerspective(GLdouble fovy, GLdouble aspect, + GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, + GLdouble eyedx, GLdouble eyedy, GLdouble focus) +{ + GLdouble fov2,left,right,bottom,top; + + fov2 = ((fovy*PI_) / 180.0) / 2.0; + + top = nnear / (cos(fov2) / sin(fov2)); + bottom = -top; + + right = top * aspect; + left = -right; + + accFrustum (left, right, bottom, top, nnear, ffar, + pixdx, pixdy, eyedx, eyedy, focus); +} + +/* Initialize lighting and other values. + */ +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 }; + GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 }; + GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 50.0); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + glShadeModel (GL_FLAT); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearAccum(0.0, 0.0, 0.0, 0.0); +} + +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 }; + GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 }; + GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 }; + + glPushMatrix (); + glTranslatef (0.0, 0.0, -5.0); + glRotatef (30.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.80, 0.35, 0.0); + glRotatef (100.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse); + glutSolidTorus (0.275, 0.85, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.50, 0.0); + glRotatef (45.0, 0.0, 0.0, 1.0); + glRotatef (45.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse); + glutSolidCube (1.5); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.60, 0.0); + glRotatef (30.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse); + glutSolidSphere (1.0, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.70, -0.90, 0.25); + glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse); + glutSolidOctahedron (); + glPopMatrix (); + + glPopMatrix (); +} + +#define ACSIZE 8 + +void display(void) +{ + GLint viewport[4]; + int jitter; + + glGetIntegerv (GL_VIEWPORT, viewport); + + glClear(GL_ACCUM_BUFFER_BIT); + for (jitter = 0; jitter < ACSIZE; jitter++) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + accPerspective (50.0, + (GLdouble) viewport[2]/(GLdouble) viewport[3], + 1.0, 15.0, j8[jitter].x, j8[jitter].y, 0.0, 0.0, 1.0); + displayObjects (); + glAccum(GL_ACCUM, 1.0/ACSIZE); + } + glAccum (GL_RETURN, 1.0); + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* Main Loop + * Be certain you request an accumulation buffer. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB + | GLUT_ACCUM | GLUT_DEPTH); + glutInitWindowSize (250, 250); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/alpha.c b/progs/redbook/alpha.c new file mode 100644 index 0000000000..6eeb45b96f --- /dev/null +++ b/progs/redbook/alpha.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * alpha.c + * This program draws several overlapping filled polygons + * to demonstrate the effect order has on alpha blending results. + * Use the 't' key to toggle the order of drawing polygons. + */ +#include +#include + +static int leftFirst = GL_TRUE; + +/* Initialize alpha blending function. + */ +static void init(void) +{ + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glShadeModel (GL_FLAT); + glClearColor (0.0, 0.0, 0.0, 0.0); +} + +static void drawLeftTriangle(void) +{ + /* draw yellow triangle on LHS of screen */ + + glBegin (GL_TRIANGLES); + glColor4f(1.0, 1.0, 0.0, 0.75); + glVertex3f(0.1, 0.9, 0.0); + glVertex3f(0.1, 0.1, 0.0); + glVertex3f(0.7, 0.5, 0.0); + glEnd(); +} + +static void drawRightTriangle(void) +{ + /* draw cyan triangle on RHS of screen */ + + glBegin (GL_TRIANGLES); + glColor4f(0.0, 1.0, 1.0, 0.75); + glVertex3f(0.9, 0.9, 0.0); + glVertex3f(0.3, 0.5, 0.0); + glVertex3f(0.9, 0.1, 0.0); + glEnd(); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + if (leftFirst) { + drawLeftTriangle(); + drawRightTriangle(); + } + else { + drawRightTriangle(); + drawLeftTriangle(); + } + + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w); + else + gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 't': + case 'T': + leftFirst = !leftFirst; + glutPostRedisplay(); + break; + case 27: /* Escape key */ + exit(0); + break; + 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_SINGLE | GLUT_RGB); + glutInitWindowSize (200, 200); + glutCreateWindow (argv[0]); + init(); + glutReshapeFunc (reshape); + glutKeyboardFunc (keyboard); + glutDisplayFunc (display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/alpha3D.c b/progs/redbook/alpha3D.c new file mode 100644 index 0000000000..413836edd5 --- /dev/null +++ b/progs/redbook/alpha3D.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * alpha3D.c + * This program demonstrates how to intermix opaque and + * alpha blended polygons in the same scene, by using + * glDepthMask. Press the 'a' key to animate moving the + * transparent object through the opaque object. Press + * the 'r' key to reset the scene. + */ +#include +#include +#include + +#define MAXZ 8.0 +#define MINZ -8.0 +#define ZINC 0.4 + +static float solidZ = MAXZ; +static float transparentZ = MINZ; +static GLuint sphereList, cubeList; + +static void init(void) +{ + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 0.15 }; + GLfloat mat_shininess[] = { 100.0 }; + GLfloat position[] = { 0.5, 0.5, 1.0, 0.0 }; + + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT0, GL_POSITION, position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + sphereList = glGenLists(1); + glNewList(sphereList, GL_COMPILE); + glutSolidSphere (0.4, 16, 16); + glEndList(); + + cubeList = glGenLists(1); + glNewList(cubeList, GL_COMPILE); + glutSolidCube (0.6); + glEndList(); +} + +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 }; + GLfloat mat_transparent[] = { 0.0, 0.8, 0.8, 0.6 }; + GLfloat mat_emission[] = { 0.0, 0.3, 0.3, 0.6 }; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glTranslatef (-0.15, -0.15, solidZ); + glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid); + glCallList (sphereList); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.15, 0.15, transparentZ); + glRotatef (15.0, 1.0, 1.0, 0.0); + glRotatef (30.0, 0.0, 1.0, 0.0); + glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_transparent); + glEnable (GL_BLEND); + glDepthMask (GL_FALSE); + glBlendFunc (GL_SRC_ALPHA, GL_ONE); + glCallList (cubeList); + glDepthMask (GL_TRUE); + glDisable (GL_BLEND); + glPopMatrix (); + + glutSwapBuffers(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLint) w, (GLint) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, + 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-1.5*(GLfloat)w/(GLfloat)h, + 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +void animate(void) +{ + if (solidZ <= MINZ || transparentZ >= MAXZ) + glutIdleFunc(NULL); + else { + solidZ -= ZINC; + transparentZ += ZINC; + glutPostRedisplay(); + } +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'a': + case 'A': + solidZ = MAXZ; + transparentZ = MINZ; + glutIdleFunc(animate); + break; + case 'r': + case 'R': + solidZ = MAXZ; + transparentZ = MINZ; + glutPostRedisplay(); + break; + case 27: + exit(0); + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(500, 500); + glutCreateWindow(argv[0]); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/anti.c b/progs/redbook/anti.c new file mode 100644 index 0000000000..12aa5f8a21 --- /dev/null +++ b/progs/redbook/anti.c @@ -0,0 +1,111 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * anti.c + * This program draws antialiased lines in RGBA mode. + */ +#include +#include +#include + +/* Initialize antialiasing for RGBA mode, including alpha + * blending, hint, and line width. Print out implementation + * specific info on line width granularity and width. + */ +void myinit(void) +{ + GLfloat values[2]; + glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); + printf ("GL_LINE_WIDTH_GRANULARITY value is %3.1f\n", values[0]); + + glGetFloatv (GL_LINE_WIDTH_RANGE, values); + printf ("GL_LINE_WIDTH_RANGE values are %3.1f %3.1f\n", + values[0], values[1]); + + glEnable (GL_LINE_SMOOTH); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); + glLineWidth (1.5); + + glShadeModel(GL_FLAT); + glClearColor(0.0, 0.0, 0.0, 0.0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +/* display() draws an icosahedron with a large alpha value, 1.0. + */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glColor4f (1.0, 1.0, 1.0, 1.0); + glutWireIcosahedron(); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 3.0, 5.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity (); + glTranslatef (0.0, 0.0, -4.0); /* move object into view */ +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + diff --git a/progs/redbook/bezcurve.c b/progs/redbook/bezcurve.c new file mode 100644 index 0000000000..5dee440396 --- /dev/null +++ b/progs/redbook/bezcurve.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* bezcurve.c + * This program uses evaluators to draw a Bezier curve. + */ +#include +#include + +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) +{ + glClearColor(0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); + glEnable(GL_MAP1_VERTEX_3); +} + +void display(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 1.0, 1.0); + glBegin(GL_LINE_STRIP); + for (i = 0; i <= 30; i++) + glEvalCoord1f((GLfloat) i/30.0); + glEnd(); + /* The following code displays the control points as dots. */ + glPointSize(5.0); + glColor3f(1.0, 1.0, 0.0); + glBegin(GL_POINTS); + for (i = 0; i < 4; i++) + glVertex3fv(&ctrlpoints[i][0]); + glEnd(); + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, + 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0); + else + glOrtho(-5.0*(GLfloat)w/(GLfloat)h, + 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/bezmesh.c b/progs/redbook/bezmesh.c new file mode 100644 index 0000000000..eb7f0f7a84 --- /dev/null +++ b/progs/redbook/bezmesh.c @@ -0,0 +1,148 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/** + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* bezsurf.c + * This program renders a lighted, filled Bezier surface, + * using two-dimensional evaluators. + */ +#include +#include + +GLfloat ctrlpoints[4][4][3] = +{ + { + {-1.5, -1.5, 4.0}, + {-0.5, -1.5, 2.0}, + {0.5, -1.5, -1.0}, + {1.5, -1.5, 2.0}}, + { + {-1.5, -0.5, 1.0}, + {-0.5, -0.5, 3.0}, + {0.5, -0.5, 0.0}, + {1.5, -0.5, -1.0}}, + { + {-1.5, 0.5, 4.0}, + {-0.5, 0.5, 0.0}, + {0.5, 0.5, 3.0}, + {1.5, 0.5, 4.0}}, + { + {-1.5, 1.5, -2.0}, + {-0.5, 1.5, -2.0}, + {0.5, 1.5, 0.0}, + {1.5, 1.5, -1.0}} +}; + +void +initlights(void) +{ + GLfloat ambient[] = + {0.2, 0.2, 0.2, 1.0}; + GLfloat position[] = + {0.0, 0.0, 2.0, 1.0}; + GLfloat mat_diffuse[] = + {0.6, 0.6, 0.6, 1.0}; + GLfloat mat_specular[] = + {1.0, 1.0, 1.0, 1.0}; + GLfloat mat_shininess[] = + {50.0}; + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_POSITION, position); + + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); +} + +void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + glRotatef(85.0, 1.0, 1.0, 1.0); + glEvalMesh2(GL_FILL, 0, 20, 0, 20); + glPopMatrix(); + glFlush(); +} + +void +myinit(void) +{ + glClearColor(0.0, 0.0, 0.0, 1.0); + glEnable(GL_DEPTH_TEST); + glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, + 0, 1, 12, 4, &ctrlpoints[0][0][0]); + glEnable(GL_MAP2_VERTEX_3); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); + initlights(); /* for lighted version only */ +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w, + 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0); + else + glOrtho(-4.0 * (GLfloat) w / (GLfloat) h, + 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/checker.c b/progs/redbook/checker.c new file mode 100644 index 0000000000..34853b0c6e --- /dev/null +++ b/progs/redbook/checker.c @@ -0,0 +1,125 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* checker.c + * This program texture maps a checkerboard image onto + * two rectangles. This program clamps the texture, if + * the texture coordinates fall outside 0.0 and 1.0. + */ +#include + +/* Create checkerboard texture */ +#define checkImageWidth 64 +#define checkImageHeight 64 +GLubyte checkImage[checkImageWidth][checkImageHeight][3]; + +void makeCheckImage(void) +{ + int i, j, c; + + for (i = 0; i < checkImageWidth; i++) { + for (j = 0; j < checkImageHeight; j++) { + c = ((((i&0x8)==0)^((j&0x8))==0))*255; + checkImage[i][j][0] = (GLubyte) c; + checkImage[i][j][1] = (GLubyte) c; + checkImage[i][j][2] = (GLubyte) c; + } + } +} + +void myinit(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + + makeCheckImage(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth, + checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, + &checkImage[0][0][0]); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); + glShadeModel(GL_FLAT); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); + glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); + + glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421); + glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); + glEnd(); + glutSwapBuffers(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -3.6); +} + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow("checker"); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/clip.c b/progs/redbook/clip.c new file mode 100644 index 0000000000..90816f2e27 --- /dev/null +++ b/progs/redbook/clip.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * clip.c + * This program demonstrates arbitrary clipping planes. + */ +#include +#include + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +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}; + + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f (1.0, 1.0, 1.0); + glPushMatrix(); + glTranslatef (0.0, 0.0, -5.0); + +/* clip lower half -- y < 0 */ + glClipPlane (GL_CLIP_PLANE0, eqn); + glEnable (GL_CLIP_PLANE0); +/* clip left half -- x < 0 */ + glClipPlane (GL_CLIP_PLANE1, eqn2); + glEnable (GL_CLIP_PLANE1); + + glRotatef (90.0, 1.0, 0.0, 0.0); + glutWireSphere(1.0, 20, 16); + glPopMatrix(); + + glFlush (); +} + +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, 20.0); + glMatrixMode (GL_MODELVIEW); +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/colormat.c b/progs/redbook/colormat.c new file mode 100644 index 0000000000..9db4491bac --- /dev/null +++ b/progs/redbook/colormat.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * colormat.c + * After initialization, the program will be in + * ColorMaterial mode. Interaction: pressing the + * mouse buttons will change the diffuse reflection values. + */ +#include +#include + +GLfloat diffuseMaterial[4] = { 0.5, 0.5, 0.5, 1.0 }; + +/* Initialize material property, light source, lighting model, + * and depth buffer. + */ +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 }; + + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 25.0); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glColorMaterial(GL_FRONT, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glutSolidSphere(1.0, 20, 16); + glFlush (); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, + 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-1.5*(GLfloat)w/(GLfloat)h, + 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED2 */ +void mouse(int button, int state, int x, int y) +{ + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN) { + diffuseMaterial[0] += 0.1; + if (diffuseMaterial[0] > 1.0) + diffuseMaterial[0] = 0.0; + glColor4fv(diffuseMaterial); + glutPostRedisplay(); + } + break; + case GLUT_MIDDLE_BUTTON: + if (state == GLUT_DOWN) { + diffuseMaterial[1] += 0.1; + if (diffuseMaterial[1] > 1.0) + diffuseMaterial[1] = 0.0; + glColor4fv(diffuseMaterial); + glutPostRedisplay(); + } + break; + case GLUT_RIGHT_BUTTON: + if (state == GLUT_DOWN) { + diffuseMaterial[2] += 0.1; + if (diffuseMaterial[2] > 1.0) + diffuseMaterial[2] = 0.0; + glColor4fv(diffuseMaterial); + glutPostRedisplay(); + } + break; + default: + break; + } +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/cube.c b/progs/redbook/cube.c new file mode 100644 index 0000000000..5ecc6280f3 --- /dev/null +++ b/progs/redbook/cube.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * cube.c + * This program demonstrates a single modeling transformation, + * glScalef() and a single viewing transformation, gluLookAt(). + * A wireframe cube is rendered. + */ +#include +#include + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glLoadIdentity (); /* clear the matrix */ + /* viewing transformation */ + gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); + glScalef (1.0, 2.0, 1.0); /* modeling transformation */ + glutWireCube (1.0); + glFlush (); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); + glMatrixMode (GL_MODELVIEW); +} + +/* ARGSUSED1 */ +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 (500, 500); + 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 new file mode 100644 index 0000000000..41af19cf96 --- /dev/null +++ b/progs/redbook/depthcue.c @@ -0,0 +1,102 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * depthcue.c + * This program draws a wireframe model, which uses + * intensity (brightness) to give clues to distance. + * Fog is used to achieve this effect. + */ +#include +#include + +/* Initialize linear fog for depth cueing. + */ +void myinit(void) +{ + GLfloat fogColor[4] = {0.0, 0.0, 0.0, 1.0}; + + glEnable(GL_FOG); + glFogi (GL_FOG_MODE, GL_LINEAR); + glHint (GL_FOG_HINT, GL_NICEST); /* per pixel */ + glFogf (GL_FOG_START, 3.0); + glFogf (GL_FOG_END, 5.0); + glFogfv (GL_FOG_COLOR, fogColor); + glClearColor(0.0, 0.0, 0.0, 1.0); + + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_FLAT); +} + +/* display() draws an icosahedron. + */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glutWireIcosahedron(); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 3.0, 5.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity (); + glTranslatef (0.0, 0.0, -4.0); /* move object into view */ +} + +/* Main Loop + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + diff --git a/progs/redbook/dof.c b/progs/redbook/dof.c new file mode 100644 index 0000000000..166ca9e62f --- /dev/null +++ b/progs/redbook/dof.c @@ -0,0 +1,238 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * dof.c + * This program demonstrates use of the accumulation buffer to + * create an out-of-focus depth-of-field effect. The teapots + * are drawn several times into the accumulation buffer. The + * viewing volume is jittered, except at the focal point, where + * the viewing volume is at the same position, each time. In + * this case, the gold teapot remains in focus. + */ +#include +#include +#include +#include "jitter.h" + +#define PI_ 3.14159265358979323846 + +/* accFrustum() + * The first 6 arguments are identical to the glFrustum() call. + * + * pixdx and pixdy are anti-alias jitter in pixels. + * Set both equal to 0.0 for no anti-alias jitter. + * eyedx and eyedy are depth-of field jitter in pixels. + * Set both equal to 0.0 for no depth of field effects. + * + * focus is distance from eye to plane in focus. + * focus must be greater than, but not equal to 0.0. + * + * Note that accFrustum() calls glTranslatef(). You will + * probably want to insure that your ModelView matrix has been + * initialized to identity before calling accFrustum(). + */ +void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble nnear, GLdouble ffar, GLdouble pixdx, + GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus) +{ + GLdouble xwsize, ywsize; + GLdouble dx, dy; + GLint viewport[4]; + + glGetIntegerv (GL_VIEWPORT, viewport); + + xwsize = right - left; + ywsize = top - bottom; + + dx = -(pixdx*xwsize/(GLdouble) viewport[2] + eyedx*nnear/focus); + dy = -(pixdy*ywsize/(GLdouble) viewport[3] + eyedy*nnear/focus); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum (left + dx, right + dx, bottom + dy, top + dy, nnear, ffar); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef (-eyedx, -eyedy, 0.0); +} + +/* accPerspective() + * + * The first 4 arguments are identical to the gluPerspective() call. + * pixdx and pixdy are anti-alias jitter in pixels. + * Set both equal to 0.0 for no anti-alias jitter. + * eyedx and eyedy are depth-of field jitter in pixels. + * Set both equal to 0.0 for no depth of field effects. + * + * focus is distance from eye to plane in focus. + * focus must be greater than, but not equal to 0.0. + * + * Note that accPerspective() calls accFrustum(). + */ +void accPerspective(GLdouble fovy, GLdouble aspect, + GLdouble nnear, GLdouble ffar, GLdouble pixdx, GLdouble pixdy, + GLdouble eyedx, GLdouble eyedy, GLdouble focus) +{ + GLdouble fov2,left,right,bottom,top; + + fov2 = ((fovy*PI_) / 180.0) / 2.0; + + top = nnear / (cos(fov2) / sin(fov2)); + bottom = -top; + + right = top * aspect; + left = -right; + + accFrustum (left, right, bottom, top, nnear, ffar, + pixdx, pixdy, eyedx, eyedy, focus); +} + +void myinit(void) +{ + GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat position[] = { 0.0, 3.0, 3.0, 0.0 }; + + GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + GLfloat local_view[] = { 0.0 }; + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); + + glFrontFace (GL_CW); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearAccum(0.0, 0.0, 0.0, 0.0); +} + +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) +{ + float mat[4]; + + glPushMatrix(); + glTranslatef (x, y, z); + mat[0] = ambr; mat[1] = ambg; mat[2] = ambb; mat[3] = 1.0; + glMaterialfv (GL_FRONT, GL_AMBIENT, mat); + mat[0] = difr; mat[1] = difg; mat[2] = difb; + glMaterialfv (GL_FRONT, GL_DIFFUSE, mat); + mat[0] = specr; mat[1] = specg; mat[2] = specb; + glMaterialfv (GL_FRONT, GL_SPECULAR, mat); + glMaterialf (GL_FRONT, GL_SHININESS, shine*128.0); + glutSolidTeapot(0.5); + glPopMatrix(); +} + +/* display() draws 5 teapots into the accumulation buffer + * several times; each time with a jittered perspective. + * The focal point is at z = 5.0, so the gold teapot will + * stay in focus. The amount of jitter is adjusted by the + * 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) +{ + int jitter; + GLint viewport[4]; + + glGetIntegerv (GL_VIEWPORT, viewport); + glClear(GL_ACCUM_BUFFER_BIT); + + for (jitter = 0; jitter < 8; jitter++) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + accPerspective (45.0, + (GLdouble) viewport[2]/(GLdouble) viewport[3], + 1.0, 15.0, 0.0, 0.0, + 0.33*j8[jitter].x, 0.33*j8[jitter].y, 5.0); +/* ruby, gold, silver, emerald, and cyan teapots */ + renderTeapot (-1.1, -0.5, -4.5, 0.1745, 0.01175, 0.01175, + 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6); + renderTeapot (-0.5, -0.5, -5.0, 0.24725, 0.1995, 0.0745, + 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4); + renderTeapot (0.2, -0.5, -5.5, 0.19225, 0.19225, 0.19225, + 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4); + renderTeapot (1.0, -0.5, -6.0, 0.0215, 0.1745, 0.0215, + 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6); + renderTeapot (1.8, -0.5, -6.5, 0.0, 0.1, 0.06, 0.0, 0.50980392, + 0.50980392, 0.50196078, 0.50196078, 0.50196078, .25); + glAccum (GL_ACCUM, 0.125); + } + + glAccum (GL_RETURN, 1.0); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); +} + +/* 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_SINGLE | GLUT_RGB + | GLUT_ACCUM | GLUT_DEPTH); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + diff --git a/progs/redbook/double.c b/progs/redbook/double.c new file mode 100644 index 0000000000..65dfd4b2a3 --- /dev/null +++ b/progs/redbook/double.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * double.c + * This is a simple double buffered program. + * Pressing the left mouse button rotates the rectangle. + * Pressing the middle mouse button stops the rotation. + */ +#include +#include + +static GLfloat spin = 0.0; + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(spin, 0.0, 0.0, 1.0); + glColor3f(1.0, 1.0, 1.0); + glRectf(-25.0, -25.0, 25.0, 25.0); + glPopMatrix(); + + glutSwapBuffers(); +} + +void spinDisplay(void) +{ + spin = spin + 2.0; + if (spin > 360.0) + spin = spin - 360.0; + glutPostRedisplay(); +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void reshape(int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED2 */ +void mouse(int button, int state, int x, int y) +{ + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN) + glutIdleFunc(spinDisplay); + break; + case GLUT_MIDDLE_BUTTON: + if (state == GLUT_DOWN) + glutIdleFunc(NULL); + break; + default: + break; + } +} + +/* + * Request double buffer display mode. + * Register mouse input callback functions + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize (250, 250); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMouseFunc(mouse); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/drawf.c b/progs/redbook/drawf.c new file mode 100644 index 0000000000..5bcccb6aea --- /dev/null +++ b/progs/redbook/drawf.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * drawf.c + * Draws the bitmapped letter F on the screen (several times). + * This demonstrates use of the glBitmap() call. + */ +#include +#include + +GLubyte rasters[24] = { + 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, + 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, + 0xff, 0xc0, 0xff, 0xc0}; + +void init(void) +{ + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + glClearColor (0.0, 0.0, 0.0, 0.0); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glRasterPos2i (20, 20); + glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); + glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); + glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); + glFlush(); +} + +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); +} + +/* ARGSUSED1 */ +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) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(100, 100); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/feedback.c b/progs/redbook/feedback.c new file mode 100644 index 0000000000..4981854d95 --- /dev/null +++ b/progs/redbook/feedback.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * feedback.c + * This program demonstrates use of OpenGL feedback. First, + * a lighting environment is set up and a few lines are drawn. + * Then feedback mode is entered, and the same lines are + * drawn. The results in the feedback buffer are printed. + */ +#include +#include +#include + +/* Initialize lighting. + */ +void init(void) +{ + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); +} + +/* Draw a few lines and two points, one of which will + * be clipped. If in feedback mode, a passthrough token + * is issued between the each primitive. + */ +void drawGeometry (GLenum mode) +{ + glBegin (GL_LINE_STRIP); + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (30.0, 30.0, 0.0); + glVertex3f (50.0, 60.0, 0.0); + glVertex3f (70.0, 40.0, 0.0); + glEnd (); + if (mode == GL_FEEDBACK) + glPassThrough (1.0); + glBegin (GL_POINTS); + glVertex3f (-100.0, -100.0, -100.0); /* will be clipped */ + glEnd (); + if (mode == GL_FEEDBACK) + glPassThrough (2.0); + glBegin (GL_POINTS); + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (50.0, 50.0, 0.0); + glEnd (); +} + +/* Write contents of one vertex to stdout. */ +void print3DcolorVertex (GLint size, GLint *count, + GLfloat *buffer) +{ + int i; + + printf (" "); + for (i = 0; i < 7; i++) { + printf ("%4.2f ", buffer[size-(*count)]); + *count = *count - 1; + } + printf ("\n"); +} + +/* Write contents of entire buffer. (Parse tokens!) */ +void printBuffer(GLint size, GLfloat *buffer) +{ + GLint count; + GLfloat token; + + count = size; + while (count) { + token = buffer[size-count]; count--; + if (token == GL_PASS_THROUGH_TOKEN) { + printf ("GL_PASS_THROUGH_TOKEN\n"); + printf (" %4.2f\n", buffer[size-count]); + count--; + } + else if (token == GL_POINT_TOKEN) { + printf ("GL_POINT_TOKEN\n"); + print3DcolorVertex (size, &count, buffer); + } + else if (token == GL_LINE_TOKEN) { + printf ("GL_LINE_TOKEN\n"); + print3DcolorVertex (size, &count, buffer); + print3DcolorVertex (size, &count, buffer); + } + else if (token == GL_LINE_RESET_TOKEN) { + printf ("GL_LINE_RESET_TOKEN\n"); + print3DcolorVertex (size, &count, buffer); + print3DcolorVertex (size, &count, buffer); + } + } +} + +void display(void) +{ + GLfloat feedBuffer[1024]; + GLint size; + + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glOrtho (0.0, 100.0, 0.0, 100.0, 0.0, 1.0); + + glClearColor (0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + drawGeometry (GL_RENDER); + + glFeedbackBuffer (1024, GL_3D_COLOR, feedBuffer); + (void) glRenderMode (GL_FEEDBACK); + drawGeometry (GL_FEEDBACK); + + size = glRenderMode (GL_RENDER); + printBuffer (size, feedBuffer); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* Main Loop */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (100, 100); + glutInitWindowPosition (100, 100); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/fog.c b/progs/redbook/fog.c new file mode 100644 index 0000000000..5f8a4e4e76 --- /dev/null +++ b/progs/redbook/fog.c @@ -0,0 +1,186 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/** + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * fog.c + * This program draws 5 red teapots, each at a different + * z distance from the eye, in different types of fog. + * Pressing the left mouse button chooses between 3 types of + * fog: exponential, exponential squared, and linear. + * In this program, there is a fixed density value, as well + * as fixed start and end values for the linear fog. + */ +#include +#include +#include + +GLint fogMode; + +void +selectFog(int mode) +{ + switch(mode) { + case GL_LINEAR: + glFogf(GL_FOG_START, 1.0); + glFogf(GL_FOG_END, 5.0); + /* falls through */ + case GL_EXP2: + case GL_EXP: + glFogi(GL_FOG_MODE, mode); + glutPostRedisplay(); + break; + case 0: + exit(0); + } +} + +/* Initialize z-buffer, projection matrix, light source, + * and lighting model. Do not specify a material property here. + */ +void +myinit(void) +{ + GLfloat position[] = + {0.0, 3.0, 3.0, 0.0}; + GLfloat local_view[] = + {0.0}; + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); + + glFrontFace(GL_CW); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glEnable(GL_FOG); + { + GLfloat fogColor[4] = + {0.5, 0.5, 0.5, 1.0}; + + fogMode = GL_EXP; + glFogi(GL_FOG_MODE, fogMode); + glFogfv(GL_FOG_COLOR, fogColor); + glFogf(GL_FOG_DENSITY, 0.35); + glHint(GL_FOG_HINT, GL_DONT_CARE); + glClearColor(0.5, 0.5, 0.5, 1.0); + } +} + +void +renderRedTeapot(GLfloat x, GLfloat y, GLfloat z) +{ + float mat[4]; + + glPushMatrix(); + glTranslatef(x, y, z); + mat[0] = 0.1745; + mat[1] = 0.01175; + mat[2] = 0.01175; + mat[3] = 1.0; + glMaterialfv(GL_FRONT, GL_AMBIENT, mat); + mat[0] = 0.61424; + mat[1] = 0.04136; + mat[2] = 0.04136; + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat); + mat[0] = 0.727811; + mat[1] = 0.626959; + mat[2] = 0.626959; + glMaterialfv(GL_FRONT, GL_SPECULAR, mat); + glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0); + glutSolidTeapot(1.0); + glPopMatrix(); +} + +/* display() draws 5 teapots at different z positions. + */ +void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + renderRedTeapot(-4.0, -0.5, -1.0); + renderRedTeapot(-2.0, -0.5, -2.0); + renderRedTeapot(0.0, -0.5, -3.0); + renderRedTeapot(2.0, -0.5, -4.0); + renderRedTeapot(4.0, -0.5, -5.0); + glFlush(); +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= (h * 3)) + glOrtho(-6.0, 6.0, -2.0 * ((GLfloat) h * 3) / (GLfloat) w, + 2.0 * ((GLfloat) h * 3) / (GLfloat) w, 0.0, 10.0); + else + glOrtho(-6.0 * (GLfloat) w / ((GLfloat) h * 3), + 6.0 * (GLfloat) w / ((GLfloat) h * 3), -2.0, 2.0, 0.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(450, 150); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutCreateMenu(selectFog); + glutAddMenuEntry("Fog EXP", GL_EXP); + glutAddMenuEntry("Fog EXP2", GL_EXP2); + glutAddMenuEntry("Fog LINEAR", GL_LINEAR); + glutAddMenuEntry("Quit", 0); + glutAttachMenu(GLUT_RIGHT_BUTTON); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/fogindex.c b/progs/redbook/fogindex.c new file mode 100644 index 0000000000..b409c95ac9 --- /dev/null +++ b/progs/redbook/fogindex.c @@ -0,0 +1,138 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * fogindex.c + * This program demonstrates fog in color index mode. + * Three cones are drawn at different z values in a linear + * fog. 32 contiguous colors (from 16 to 47) are loaded + * with a color ramp. + */ +#include +#include + +/* Initialize color map and fog. Set screen clear color + * to end of color ramp. + */ +#define NUM_COLORS 32 +#define RAMPSTART 16 + +void +myinit(void) +{ + int i; + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + for (i = 0; i < NUM_COLORS; i++) { + GLfloat shade; + shade = (GLfloat) (NUM_COLORS - i) / (GLfloat) NUM_COLORS; + glutSetColor(16 + i, shade, shade, shade); + } + glEnable(GL_FOG); + + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogi(GL_FOG_INDEX, NUM_COLORS); + glFogf(GL_FOG_START, 0.0); + glFogf(GL_FOG_END, 4.0); + glHint(GL_FOG_HINT, GL_NICEST); + glClearIndex((GLfloat) (NUM_COLORS + RAMPSTART - 1)); +} + +/* display() renders 3 cones at different z positions. + */ +void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + glTranslatef(-1.0, -1.0, -1.0); + glRotatef(-90.0, 1.0, 0.0, 0.0); + glIndexi(RAMPSTART); + glutSolidCone(1.0, 2.0, 10, 10); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.0, -1.0, -2.25); + glRotatef(-90.0, 1.0, 0.0, 0.0); + glIndexi(RAMPSTART); + glutSolidCone(1.0, 2.0, 10, 10); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(1.0, -1.0, -3.5); + glRotatef(-90.0, 1.0, 0.0, 0.0); + glIndexi(RAMPSTART); + glutSolidCone(1.0, 2.0, 10, 10); + glPopMatrix(); + glFlush(); +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, + 2.0 * (GLfloat) h / (GLfloat) w, 0.0, 10.0); + else + glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, + 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, 0.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* 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_SINGLE | GLUT_INDEX | GLUT_DEPTH); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/font.c b/progs/redbook/font.c new file mode 100644 index 0000000000..2d92e9b600 --- /dev/null +++ b/progs/redbook/font.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * font.c + * + * Draws some text in a bitmapped font. Uses glBitmap() + * and other pixel routines. Also demonstrates use of + * display lists. + */ +#include +#include +#include + +GLubyte space[] = +{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +GLubyte letters[][13] = { +{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18}, +{0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, +{0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, +{0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc}, +{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff}, +{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff}, +{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, +{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, +{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e}, +{0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06}, +{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3}, +{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0}, +{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xff, 0xff, 0xe7, 0xc3}, +{0x00, 0x00, 0xc7, 0xc7, 0xcf, 0xcf, 0xdf, 0xdb, 0xfb, 0xf3, 0xf3, 0xe3, 0xe3}, +{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xe7, 0x7e}, +{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, +{0x00, 0x00, 0x3f, 0x6e, 0xdf, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c}, +{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, +{0x00, 0x00, 0x7e, 0xe7, 0x03, 0x03, 0x07, 0x7e, 0xe0, 0xc0, 0xc0, 0xe7, 0x7e}, +{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff}, +{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, +{0x00, 0x00, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, +{0x00, 0x00, 0xc3, 0xe7, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, +{0x00, 0x00, 0xc3, 0x66, 0x66, 0x3c, 0x3c, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3}, +{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3}, +{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff} +}; + +GLuint fontOffset; + +void makeRasterFont(void) +{ + GLuint i, j; + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + fontOffset = glGenLists (128); + for (i = 0,j = 'A'; i < 26; i++,j++) { + glNewList(fontOffset + j, GL_COMPILE); + glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]); + glEndList(); + } + glNewList(fontOffset + ' ', GL_COMPILE); + glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space); + glEndList(); +} + +void init(void) +{ + glShadeModel (GL_FLAT); + makeRasterFont(); +} + +void printString(char *s) +{ + glPushAttrib (GL_LIST_BIT); + glListBase(fontOffset); + glCallLists((GLsizei) strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s); + glPopAttrib (); +} + +/* Everything above this line could be in a library + * that defines a font. To make it work, you've got + * to call makeRasterFont() before you start making + * calls to printString(). + */ +void display(void) +{ + GLfloat white[3] = { 1.0, 1.0, 1.0 }; + + glClear(GL_COLOR_BUFFER_BIT); + glColor3fv(white); + + glRasterPos2i(20, 60); + printString("THE QUICK BROWN FOX JUMPS"); + glRasterPos2i(20, 40); + printString("OVER A LAZY DOG"); + glFlush (); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho (0.0, w, 0.0, h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); +} + +/* ARGSUSED1 */ +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) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(300, 100); + glutInitWindowPosition (100, 100); + glutCreateWindow(argv[0]); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/hello.c b/progs/redbook/hello.c new file mode 100644 index 0000000000..516c9ecc00 --- /dev/null +++ b/progs/redbook/hello.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * hello.c + * This is a simple, introductory OpenGL program. + */ +#include + +void display(void) +{ +/* clear all pixels */ + glClear (GL_COLOR_BUFFER_BIT); + +/* draw white polygon (rectangle) with corners at + * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) + */ + glColor3f (1.0, 1.0, 1.0); + glBegin(GL_POLYGON); + glVertex3f (0.25, 0.25, 0.0); + glVertex3f (0.75, 0.25, 0.0); + glVertex3f (0.75, 0.75, 0.0); + glVertex3f (0.25, 0.75, 0.0); + glEnd(); + +/* don't wait! + * start processing buffered OpenGL routines + */ + glFlush (); +} + +void init (void) +{ +/* select clearing color */ + glClearColor (0.0, 0.0, 0.0, 0.0); + +/* initialize viewing values */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); +} + +/* + * Declare initial window size, position, and display mode + * (single buffer and RGBA). Open window with "hello" + * in its title bar. Call initialization routines. + * Register callback function to display graphics. + * Enter main loop and process events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (250, 250); + glutInitWindowPosition (100, 100); + glutCreateWindow ("hello"); + init (); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/image.c b/progs/redbook/image.c new file mode 100644 index 0000000000..8e62f5afd3 --- /dev/null +++ b/progs/redbook/image.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* image.c + * This program demonstrates drawing pixels and shows the effect + * of glDrawPixels(), glCopyPixels(), and glPixelZoom(). + * Interaction: moving the mouse while pressing the mouse button + * will copy the image in the lower-left corner of the window + * to the mouse position, using the current pixel zoom factors. + * There is no attempt to prevent you from drawing over the original + * image. If you press the 'r' key, the original image and zoom + * factors are reset. If you press the 'z' or 'Z' keys, you change + * the zoom factors. + */ +#include +#include +#include + +/* Create checkerboard image */ +#define checkImageWidth 64 +#define checkImageHeight 64 +GLubyte checkImage[checkImageHeight][checkImageWidth][3]; + +static GLdouble zoomFactor = 1.0; +static GLint height; + +void makeCheckImage(void) +{ + int i, j, c; + + for (i = 0; i < checkImageHeight; i++) { + for (j = 0; j < checkImageWidth; j++) { + c = ((((i&0x8)==0)^((j&0x8))==0))*255; + checkImage[i][j][0] = (GLubyte) c; + checkImage[i][j][1] = (GLubyte) c; + checkImage[i][j][2] = (GLubyte) c; + } + } +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + makeCheckImage(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glRasterPos2i(0, 0); + glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB, + GL_UNSIGNED_BYTE, checkImage); + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + height = (GLint) h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +void motion(int x, int y) +{ + static GLint screeny; + + screeny = height - (GLint) y; + glRasterPos2i (x, screeny); + glPixelZoom (zoomFactor, zoomFactor); + glCopyPixels (0, 0, checkImageWidth, checkImageHeight, GL_COLOR); + glPixelZoom (1.0, 1.0); + glFlush (); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'r': + case 'R': + zoomFactor = 1.0; + glutPostRedisplay(); + printf ("zoomFactor reset to 1.0\n"); + break; + case 'z': + zoomFactor += 0.5; + if (zoomFactor >= 3.0) + zoomFactor = 3.0; + printf ("zoomFactor is now %4.1f\n", zoomFactor); + break; + case 'Z': + zoomFactor -= 0.5; + if (zoomFactor <= 0.5) + zoomFactor = 0.5; + printf ("zoomFactor is now %4.1f\n", zoomFactor); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(250, 250); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMotionFunc(motion); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/jitter.h b/progs/redbook/jitter.h new file mode 100644 index 0000000000..1ec08c87fd --- /dev/null +++ b/progs/redbook/jitter.h @@ -0,0 +1,222 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* +jitter.h + +This file contains jitter point arrays for 2,3,4,8,15,24 and 66 jitters. + +The arrays are named j2, j3, etc. Each element in the array has the form, +for example, j8[0].x and j8[0].y + +Values are floating point in the range -.5 < x < .5, -.5 < y < .5, and +have a gaussian distribution around the origin. + +Use these to do model jittering for scene anti-aliasing and view volume +jittering for depth of field effects. Use in conjunction with the +accwindow() routine. +*/ + +typedef struct +{ + GLfloat x, y; +} jitter_point; + +#define MAX_SAMPLES 66 + + +/* 2 jitter points */ +jitter_point j2[] = +{ + { 0.246490, 0.249999}, + {-0.246490, -0.249999} +}; + + +/* 3 jitter points */ +jitter_point j3[] = +{ + {-0.373411, -0.250550}, + { 0.256263, 0.368119}, + { 0.117148, -0.117570} +}; + + +/* 4 jitter points */ +jitter_point j4[] = +{ + {-0.208147, 0.353730}, + { 0.203849, -0.353780}, + {-0.292626, -0.149945}, + { 0.296924, 0.149994} +}; + + +/* 8 jitter points */ +jitter_point j8[] = +{ + {-0.334818, 0.435331}, + { 0.286438, -0.393495}, + { 0.459462, 0.141540}, + {-0.414498, -0.192829}, + {-0.183790, 0.082102}, + {-0.079263, -0.317383}, + { 0.102254, 0.299133}, + { 0.164216, -0.054399} +}; + + +/* 15 jitter points */ +jitter_point j15[] = +{ + { 0.285561, 0.188437}, + { 0.360176, -0.065688}, + {-0.111751, 0.275019}, + {-0.055918, -0.215197}, + {-0.080231, -0.470965}, + { 0.138721, 0.409168}, + { 0.384120, 0.458500}, + {-0.454968, 0.134088}, + { 0.179271, -0.331196}, + {-0.307049, -0.364927}, + { 0.105354, -0.010099}, + {-0.154180, 0.021794}, + {-0.370135, -0.116425}, + { 0.451636, -0.300013}, + {-0.370610, 0.387504} +}; + + +/* 24 jitter points */ +jitter_point j24[] = +{ + { 0.030245, 0.136384}, + { 0.018865, -0.348867}, + {-0.350114, -0.472309}, + { 0.222181, 0.149524}, + {-0.393670, -0.266873}, + { 0.404568, 0.230436}, + { 0.098381, 0.465337}, + { 0.462671, 0.442116}, + { 0.400373, -0.212720}, + {-0.409988, 0.263345}, + {-0.115878, -0.001981}, + { 0.348425, -0.009237}, + {-0.464016, 0.066467}, + {-0.138674, -0.468006}, + { 0.144932, -0.022780}, + {-0.250195, 0.150161}, + {-0.181400, -0.264219}, + { 0.196097, -0.234139}, + {-0.311082, -0.078815}, + { 0.268379, 0.366778}, + {-0.040601, 0.327109}, + {-0.234392, 0.354659}, + {-0.003102, -0.154402}, + { 0.297997, -0.417965} +}; + + +/* 66 jitter points */ +jitter_point j66[] = +{ + { 0.266377, -0.218171}, + {-0.170919, -0.429368}, + { 0.047356, -0.387135}, + {-0.430063, 0.363413}, + {-0.221638, -0.313768}, + { 0.124758, -0.197109}, + {-0.400021, 0.482195}, + { 0.247882, 0.152010}, + {-0.286709, -0.470214}, + {-0.426790, 0.004977}, + {-0.361249, -0.104549}, + {-0.040643, 0.123453}, + {-0.189296, 0.438963}, + {-0.453521, -0.299889}, + { 0.408216, -0.457699}, + { 0.328973, -0.101914}, + {-0.055540, -0.477952}, + { 0.194421, 0.453510}, + { 0.404051, 0.224974}, + { 0.310136, 0.419700}, + {-0.021743, 0.403898}, + {-0.466210, 0.248839}, + { 0.341369, 0.081490}, + { 0.124156, -0.016859}, + {-0.461321, -0.176661}, + { 0.013210, 0.234401}, + { 0.174258, -0.311854}, + { 0.294061, 0.263364}, + {-0.114836, 0.328189}, + { 0.041206, -0.106205}, + { 0.079227, 0.345021}, + {-0.109319, -0.242380}, + { 0.425005, -0.332397}, + { 0.009146, 0.015098}, + {-0.339084, -0.355707}, + {-0.224596, -0.189548}, + { 0.083475, 0.117028}, + { 0.295962, -0.334699}, + { 0.452998, 0.025397}, + { 0.206511, -0.104668}, + { 0.447544, -0.096004}, + {-0.108006, -0.002471}, + {-0.380810, 0.130036}, + {-0.242440, 0.186934}, + {-0.200363, 0.070863}, + {-0.344844, -0.230814}, + { 0.408660, 0.345826}, + {-0.233016, 0.305203}, + { 0.158475, -0.430762}, + { 0.486972, 0.139163}, + {-0.301610, 0.009319}, + { 0.282245, -0.458671}, + { 0.482046, 0.443890}, + {-0.121527, 0.210223}, + {-0.477606, -0.424878}, + {-0.083941, -0.121440}, + {-0.345773, 0.253779}, + { 0.234646, 0.034549}, + { 0.394102, -0.210901}, + {-0.312571, 0.397656}, + { 0.200906, 0.333293}, + { 0.018703, -0.261792}, + {-0.209349, -0.065383}, + { 0.076248, 0.478538}, + {-0.073036, -0.355064}, + { 0.145087, 0.221726} +}; diff --git a/progs/redbook/light.c b/progs/redbook/light.c new file mode 100644 index 0000000000..0eed85e10c --- /dev/null +++ b/progs/redbook/light.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * light.c + * This program demonstrates the use of the OpenGL lighting + * model. A sphere is drawn using a grey material characteristic. + * A single light source illuminates the object. + */ +#include +#include + +/* Initialize material property, light source, lighting model, + * and depth buffer. + */ +void init(void) +{ + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 50.0 }; + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glutSolidSphere (1.0, 20, 16); + glFlush (); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, + 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-1.5*(GLfloat)w/(GLfloat)h, + 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/lines.c b/progs/redbook/lines.c new file mode 100644 index 0000000000..b34d4c418c --- /dev/null +++ b/progs/redbook/lines.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * lines.c + * This program demonstrates geometric primitives and + * their attributes. + */ +#include +#include + +#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \ + glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd(); + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + int i; + + glClear (GL_COLOR_BUFFER_BIT); + +/* select white for all lines */ + glColor3f (1.0, 1.0, 1.0); + +/* in 1st row, 3 lines, each with a different stipple */ + glEnable (GL_LINE_STIPPLE); + + glLineStipple (1, 0x0101); /* dotted */ + drawOneLine (50.0, 125.0, 150.0, 125.0); + glLineStipple (1, 0x00FF); /* dashed */ + drawOneLine (150.0, 125.0, 250.0, 125.0); + glLineStipple (1, 0x1C47); /* dash/dot/dash */ + drawOneLine (250.0, 125.0, 350.0, 125.0); + +/* in 2nd row, 3 wide lines, each with different stipple */ + glLineWidth (5.0); + glLineStipple (1, 0x0101); /* dotted */ + drawOneLine (50.0, 100.0, 150.0, 100.0); + glLineStipple (1, 0x00FF); /* dashed */ + drawOneLine (150.0, 100.0, 250.0, 100.0); + glLineStipple (1, 0x1C47); /* dash/dot/dash */ + drawOneLine (250.0, 100.0, 350.0, 100.0); + glLineWidth (1.0); + +/* in 3rd row, 6 lines, with dash/dot/dash stipple */ +/* as part of a single connected line strip */ + glLineStipple (1, 0x1C47); /* dash/dot/dash */ + glBegin (GL_LINE_STRIP); + for (i = 0; i < 7; i++) + glVertex2f (50.0 + ((GLfloat) i * 50.0), 75.0); + glEnd (); + +/* in 4th row, 6 independent lines with same stipple */ + for (i = 0; i < 6; i++) { + drawOneLine (50.0 + ((GLfloat) i * 50.0), 50.0, + 50.0 + ((GLfloat)(i+1) * 50.0), 50.0); + } + +/* in 5th row, 1 line, with dash/dot/dash stipple */ +/* and a stipple repeat factor of 5 */ + glLineStipple (5, 0x1C47); /* dash/dot/dash */ + drawOneLine (50.0, 25.0, 350.0, 25.0); + + glDisable (GL_LINE_STIPPLE); + glFlush (); +} + +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); +} + +/* ARGSUSED1 */ +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 (400, 150); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/list.c b/progs/redbook/list.c new file mode 100644 index 0000000000..3b4f44bd6d --- /dev/null +++ b/progs/redbook/list.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * list.c + * This program demonstrates how to make and execute a + * display list. Note that attributes, such as current + * color and matrix, are changed. + */ +#include +#include + +GLuint listName; + +static void init (void) +{ + listName = glGenLists (1); + glNewList (listName, GL_COMPILE); + glColor3f (1.0, 0.0, 0.0); /* current color red */ + glBegin (GL_TRIANGLES); + glVertex2f (0.0, 0.0); + glVertex2f (1.0, 0.0); + glVertex2f (0.0, 1.0); + glEnd (); + glTranslatef (1.5, 0.0, 0.0); /* move position */ + glEndList (); + glShadeModel (GL_FLAT); +} + +static void drawLine (void) +{ + glBegin (GL_LINES); + glVertex2f (0.0, 0.5); + glVertex2f (15.0, 0.5); + glEnd (); +} + +void display(void) +{ + GLuint i; + + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (0.0, 1.0, 0.0); /* current color green */ + for (i = 0; i < 10; i++) /* draw 10 triangles */ + glCallList (listName); + drawLine (); /* is this line green? NO! */ + /* where is the line drawn? */ + glFlush (); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D (0.0, 2.0, -0.5 * (GLfloat) h/(GLfloat) w, + 1.5 * (GLfloat) h/(GLfloat) w); + else + gluOrtho2D (0.0, 2.0 * (GLfloat) w/(GLfloat) h, -0.5, 1.5); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + 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_SINGLE | GLUT_RGB); + glutInitWindowSize(650, 50); + glutCreateWindow(argv[0]); + init (); + glutReshapeFunc (reshape); + glutDisplayFunc (display); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/material.c b/progs/redbook/material.c new file mode 100644 index 0000000000..f8d6a918f4 --- /dev/null +++ b/progs/redbook/material.c @@ -0,0 +1,293 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * material.c + * This program demonstrates the use of the GL lighting model. + * Several objects are drawn using different material characteristics. + * A single light source illuminates the objects. + */ +#include +#include + +/* Initialize z-buffer, projection matrix, light source, + * and lighting model. Do not specify a material property here. + */ +void myinit(void) +{ + GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 }; + GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; + GLfloat local_view[] = { 0.0 }; + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glClearColor(0.0, 0.1, 0.1, 0.0); +} + +/* Draw twelve spheres in 3 rows with 4 columns. + * The spheres in the first row have materials with no ambient reflection. + * The second row has materials with significant ambient reflection. + * The third row has materials with colored ambient reflection. + * + * The first column has materials with blue, diffuse reflection only. + * The second column has blue diffuse reflection, as well as specular + * reflection with a low shininess exponent. + * The third column has blue diffuse reflection, as well as specular + * reflection with a high shininess exponent (a more concentrated highlight). + * The fourth column has materials which also include an emissive component. + * + * glTranslatef() is used to move spheres to their appropriate locations. + */ + +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 }; + GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 }; + GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat no_shininess[] = { 0.0 }; + GLfloat low_shininess[] = { 5.0 }; + GLfloat high_shininess[] = { 100.0 }; + GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0}; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + +/* draw sphere in first row, first column + * diffuse reflection only; no ambient or specular + */ + glPushMatrix(); + glTranslatef (-3.75, 3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in first row, second column + * diffuse and specular reflection; low shininess; no ambient + */ + glPushMatrix(); + glTranslatef (-1.25, 3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in first row, third column + * diffuse and specular reflection; high shininess; no ambient + */ + glPushMatrix(); + glTranslatef (1.25, 3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in first row, fourth column + * diffuse reflection; emission; no ambient or specular reflection + */ + glPushMatrix(); + glTranslatef (3.75, 3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in second row, first column + * ambient and diffuse reflection; no specular + */ + glPushMatrix(); + glTranslatef (-3.75, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in second row, second column + * ambient, diffuse and specular reflection; low shininess + */ + glPushMatrix(); + glTranslatef (-1.25, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in second row, third column + * ambient, diffuse and specular reflection; high shininess + */ + glPushMatrix(); + glTranslatef (1.25, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in second row, fourth column + * ambient and diffuse reflection; emission; no specular + */ + glPushMatrix(); + glTranslatef (3.75, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in third row, first column + * colored ambient and diffuse reflection; no specular + */ + glPushMatrix(); + glTranslatef (-3.75, -3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in third row, second column + * colored ambient, diffuse and specular reflection; low shininess + */ + glPushMatrix(); + glTranslatef (-1.25, -3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in third row, third column + * colored ambient, diffuse and specular reflection; high shininess + */ + glPushMatrix(); + glTranslatef (1.25, -3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + +/* draw sphere in third row, fourth column + * colored ambient and diffuse reflection; emission; no specular + */ + glPushMatrix(); + glTranslatef (3.75, -3.0, 0.0); + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat); + glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); + glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission); + glutSolidSphere(1.0, 16, 16); + glPopMatrix(); + + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= (h * 2)) + glOrtho (-6.0, 6.0, -3.0*((GLfloat)h*2)/(GLfloat)w, + 3.0*((GLfloat)h*2)/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-6.0*(GLfloat)w/((GLfloat)h*2), + 6.0*(GLfloat)w/((GLfloat)h*2), -3.0, 3.0, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (600, 450); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + diff --git a/progs/redbook/mipmap.c b/progs/redbook/mipmap.c new file mode 100644 index 0000000000..96ef394f60 --- /dev/null +++ b/progs/redbook/mipmap.c @@ -0,0 +1,165 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* mipmap.c + * This program demonstrates using mipmaps for texture maps. + * To overtly show the effect of mipmaps, each mipmap reduction + * level has a solidly colored, contrasting texture image. + * Thus, the quadrilateral which is drawn is drawn with several + * different colors. + */ +#include +#include + +GLubyte mipmapImage32[32][32][3]; +GLubyte mipmapImage16[16][16][3]; +GLubyte mipmapImage8[8][8][3]; +GLubyte mipmapImage4[4][4][3]; +GLubyte mipmapImage2[2][2][3]; +GLubyte mipmapImage1[1][1][3]; + +void makeImages(void) +{ + int i, j; + + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + mipmapImage32[i][j][0] = 255; + mipmapImage32[i][j][1] = 255; + mipmapImage32[i][j][2] = 0; + } + } + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + mipmapImage16[i][j][0] = 255; + mipmapImage16[i][j][1] = 0; + mipmapImage16[i][j][2] = 255; + } + } + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + mipmapImage8[i][j][0] = 255; + mipmapImage8[i][j][1] = 0; + mipmapImage8[i][j][2] = 0; + } + } + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + mipmapImage4[i][j][0] = 0; + mipmapImage4[i][j][1] = 255; + mipmapImage4[i][j][2] = 0; + } + } + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + mipmapImage2[i][j][0] = 0; + mipmapImage2[i][j][1] = 0; + mipmapImage2[i][j][2] = 255; + } + } + mipmapImage1[0][0][0] = 255; + mipmapImage1[0][0][1] = 255; + mipmapImage1[0][0][2] = 255; +} + +void myinit(void) +{ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_FLAT); + + glTranslatef(0.0, 0.0, -3.6); + makeImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage32[0][0][0]); + glTexImage2D(GL_TEXTURE_2D, 1, 3, 16, 16, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage16[0][0][0]); + glTexImage2D(GL_TEXTURE_2D, 2, 3, 8, 8, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage8[0][0][0]); + glTexImage2D(GL_TEXTURE_2D, 3, 3, 4, 4, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage4[0][0][0]); + glTexImage2D(GL_TEXTURE_2D, 4, 3, 2, 2, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage2[0][0][0]); + glTexImage2D(GL_TEXTURE_2D, 5, 3, 1, 1, 0, + GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage1[0][0][0]); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST_MIPMAP_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0); + glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0); + glEnd(); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + diff --git a/progs/redbook/model.c b/progs/redbook/model.c new file mode 100644 index 0000000000..8411ef355f --- /dev/null +++ b/progs/redbook/model.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * model.c + * This program demonstrates modeling transformations + */ +#include +#include + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void draw_triangle(void) +{ + glBegin (GL_LINE_LOOP); + glVertex2f(0.0, 25.0); + glVertex2f(25.0, -25.0); + glVertex2f(-25.0, -25.0); + glEnd(); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + + glLoadIdentity (); + glColor3f (1.0, 1.0, 1.0); + draw_triangle (); + + glEnable (GL_LINE_STIPPLE); + glLineStipple (1, 0xF0F0); + glLoadIdentity (); + glTranslatef (-20.0, 0.0, 0.0); + draw_triangle (); + + glLineStipple (1, 0xF00F); + glLoadIdentity (); + glScalef (1.5, 0.5, 1.0); + draw_triangle (); + + glLineStipple (1, 0x8888); + glLoadIdentity (); + glRotatef (90.0, 0.0, 0.0, 1.0); + draw_triangle (); + glDisable (GL_LINE_STIPPLE); + + glFlush (); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (w <= h) + glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w, + 50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0); + else + glOrtho (-50.0*(GLfloat)w/(GLfloat)h, + 50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/movelight.c b/progs/redbook/movelight.c new file mode 100644 index 0000000000..a108cad439 --- /dev/null +++ b/progs/redbook/movelight.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * movelight.c + * This program demonstrates when to issue lighting and + * transformation commands to render a model with a light + * which is moved by a modeling transformation (rotate or + * translate). The light position is reset after the modeling + * transformation is called. The eye position does not change. + * + * A sphere is drawn using a grey material characteristic. + * A single light source illuminates the object. + * + * Interaction: pressing the left mouse button alters + * the modeling transformation (x rotation) by 30 degrees. + * The scene is then redrawn with the light in a new position. + */ +#include +#include + +static int spin = 0; + +/* Initialize material property, light source, lighting model, + * and depth buffer. + */ +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); +} + +/* Here is where the light position is reset after the modeling + * transformation (glRotated) is called. This places the + * light at a new position in world coordinates. The cube + * represents the position of the light. + */ +void display(void) +{ + GLfloat position[] = { 0.0, 0.0, 1.5, 1.0 }; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix (); + gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); + + glPushMatrix (); + glRotated ((GLdouble) spin, 1.0, 0.0, 0.0); + glLightfv (GL_LIGHT0, GL_POSITION, position); + + glTranslated (0.0, 0.0, 1.5); + glDisable (GL_LIGHTING); + glColor3f (0.0, 1.0, 1.0); + glutWireCube (0.1); + glEnable (GL_LIGHTING); + glPopMatrix (); + + glutSolidTorus (0.275, 0.85, 8, 15); + glPopMatrix (); + glFlush (); +} + +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, 20.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED2 */ +void mouse(int button, int state, int x, int y) +{ + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN) { + spin = (spin + 30) % 360; + glutPostRedisplay(); + } + break; + default: + break; + } +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/nurbs.c b/progs/redbook/nurbs.c new file mode 100644 index 0000000000..513868e7d1 --- /dev/null +++ b/progs/redbook/nurbs.c @@ -0,0 +1,176 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * nurbs.c + * This program shows a NURBS (Non-uniform rational B-splines) + * surface, shaped like a heart. + */ +#include +#include + +#define S_NUMPOINTS 13 +#define S_ORDER 3 +#define S_NUMKNOTS (S_NUMPOINTS + S_ORDER) +#define T_NUMPOINTS 3 +#define T_ORDER 3 +#define T_NUMKNOTS (T_NUMPOINTS + T_ORDER) +#define SQRT2 1.41421356237309504880 + +/* initialized local data */ + +GLfloat sknots[S_NUMKNOTS] = + {-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, + 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0}; +GLfloat tknots[T_NUMKNOTS] = {1.0, 1.0, 1.0, 2.0, 2.0, 2.0}; + +GLfloat ctlpoints[S_NUMPOINTS][T_NUMPOINTS][4] = { +{ {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} }, +{ {5.,4.,2.,1.},{5.,4.,2.5,1.},{5.,4.,3.0,1.} }, +{ {6.,5.,2.,1.},{6.,5.,2.5,1.},{6.,5.,3.0,1.} }, +{ {SQRT2*6.,SQRT2*6.,SQRT2*2.,SQRT2}, + {SQRT2*6.,SQRT2*6.,SQRT2*2.5,SQRT2}, + {SQRT2*6.,SQRT2*6.,SQRT2*3.0,SQRT2} }, +{ {5.2,6.7,2.,1.},{5.2,6.7,2.5,1.},{5.2,6.7,3.0,1.} }, +{ {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2}, + {SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2}, + {SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} }, +{ {4.,5.2,2.,1.},{4.,4.6,2.5,1.},{4.,5.2,3.0,1.} }, +{ {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2}, + {SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2}, + {SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} }, +{ {2.8,6.7,2.,1.},{2.8,6.7,2.5,1.},{2.8,6.7,3.0,1.} }, +{ {SQRT2*2.,SQRT2*6.,SQRT2*2.,SQRT2}, + {SQRT2*2.,SQRT2*6.,SQRT2*2.5,SQRT2}, + {SQRT2*2.,SQRT2*6.,SQRT2*3.0,SQRT2} }, +{ {2.,5.,2.,1.},{2.,5.,2.5,1.},{2.,5.,3.0,1.} }, +{ {3.,4.,2.,1.},{3.,4.,2.5,1.},{3.,4.,3.0,1.} }, +{ {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} } +}; + +GLUnurbsObj *theNurb; + +/* Initialize material property, light source, lighting model, + * and depth buffer. + */ +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 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 50.0 }; + + GLfloat light0_position[] = { 1.0, 0.1, 1.0, 0.0 }; + GLfloat light1_position[] = { -1.0, 0.1, 1.0, 0.0 }; + + GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT0, GL_POSITION, light0_position); + glLightfv(GL_LIGHT1, GL_POSITION, light1_position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glEnable(GL_AUTO_NORMAL); + + theNurb = gluNewNurbsRenderer(); + + gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glTranslatef (4., 4.5, 2.5); + glRotatef (220.0, 1., 0., 0.); + glRotatef (115.0, 0., 1., 0.); + glTranslatef (-4., -4.5, -2.5); + + gluBeginSurface(theNurb); + gluNurbsSurface(theNurb, + S_NUMKNOTS, sknots, + T_NUMKNOTS, tknots, + 4 * T_NUMPOINTS, + 4, + &ctlpoints[0][0][0], + S_ORDER, T_ORDER, + GL_MAP2_VERTEX_4); + gluEndSurface(theNurb); + + glPopMatrix(); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.5, 0.5, 0.8, 10.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(7.0,4.5,4.0, 4.5,4.5,2.0, 6.0,-3.0,2.0); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/pickdepth.c b/progs/redbook/pickdepth.c new file mode 100644 index 0000000000..c6d50a91d9 --- /dev/null +++ b/progs/redbook/pickdepth.c @@ -0,0 +1,203 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * pickdepth.c + * Picking is demonstrated in this program. In + * rendering mode, three overlapping rectangles are + * drawn. When the left mouse button is pressed, + * selection mode is entered with the picking matrix. + * Rectangles which are drawn under the cursor position + * are "picked." Pay special attention to the depth + * value range, which is returned. + */ +#include +#include +#include + +void +myinit(void) +{ + glClearColor(0.0, 0.0, 0.0, 0.0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_FLAT); + glDepthRange(0.0, 1.0); /* The default z mapping */ +} + +/* The three rectangles are drawn. In selection mode, + * each rectangle is given the same name. Note that + * each rectangle is drawn with a different z value. + */ +void +drawRects(GLenum mode) +{ + if (mode == GL_SELECT) + glLoadName(1); + glBegin(GL_QUADS); + glColor3f(1.0, 1.0, 0.0); + glVertex3i(2, 0, 0); + glVertex3i(2, 6, 0); + glVertex3i(6, 6, 0); + glVertex3i(6, 0, 0); + glEnd(); + if (mode == GL_SELECT) + glLoadName(2); + glBegin(GL_QUADS); + glColor3f(0.0, 1.0, 1.0); + glVertex3i(3, 2, -1); + glVertex3i(3, 8, -1); + glVertex3i(8, 8, -1); + glVertex3i(8, 2, -1); + glEnd(); + if (mode == GL_SELECT) + glLoadName(3); + glBegin(GL_QUADS); + glColor3f(1.0, 0.0, 1.0); + glVertex3i(0, 2, -2); + glVertex3i(0, 7, -2); + glVertex3i(5, 7, -2); + glVertex3i(5, 2, -2); + glEnd(); +} + +/* processHits() prints out the contents of the + * selection array. + */ +void +processHits(GLint hits, GLuint buffer[]) +{ + unsigned int i, j; + GLuint names, *ptr; + + printf("hits = %d\n", hits); + ptr = (GLuint *) buffer; + for (i = 0; i < hits; i++) { /* for each hit */ + names = *ptr; + printf(" number of names for hit = %d\n", names); + ptr++; + printf(" z1 is %g;", (float) *ptr/0xffffffff); + ptr++; + printf(" z2 is %g\n", (float) *ptr/0xffffffff); + ptr++; + printf(" the name is "); + for (j = 0; j < names; j++) { /* for each name */ + printf("%d ", *ptr); + ptr++; + } + printf("\n"); + } +} + +/* pickRects() sets up selection mode, name stack, + * and projection matrix for picking. Then the objects + * are drawn. + */ +#define BUFSIZE 512 + +void +pickRects(int button, int state, int x, int y) +{ + GLuint selectBuf[BUFSIZE]; + GLint hits; + GLint viewport[4]; + + if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) + return; + + glGetIntegerv(GL_VIEWPORT, viewport); + + glSelectBuffer(BUFSIZE, selectBuf); + (void) glRenderMode(GL_SELECT); + + glInitNames(); + glPushName(-1); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); +/* create 5x5 pixel picking region near cursor location */ + gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), + 5.0, 5.0, viewport); + glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); + drawRects(GL_SELECT); + glPopMatrix(); + glFlush(); + + hits = glRenderMode(GL_RENDER); + processHits(hits, selectBuf); +} + +void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + drawRects(GL_RENDER); + glutSwapBuffers(); +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* 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) +{ + glutInitWindowSize(200, 200); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutInit(&argc, argv); + glutCreateWindow(argv[0]); + myinit(); + glutMouseFunc(pickRects); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/picksquare.c b/progs/redbook/picksquare.c new file mode 100644 index 0000000000..0a12aa0fac --- /dev/null +++ b/progs/redbook/picksquare.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * picksquare.c + * Use of multiple names and picking are demonstrated. + * A 3x3 grid of squares is drawn. When the left mouse + * button is pressed, all squares under the cursor position + * have their color changed. + */ +#include +#include +#include + +int board[3][3]; /* amount of color for each square */ + +/* Clear color value for every square on the board */ +void init(void) +{ + int i, j; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j ++) + board[i][j] = 0; + glClearColor (0.0, 0.0, 0.0, 0.0); +} + +/* The nine squares are drawn. In selection mode, each + * square is given two names: one for the row and the + * other for the column on the grid. The color of each + * square is determined by its position on the grid, and + * the value in the board[][] array. + */ +void drawSquares(GLenum mode) +{ + GLuint i, j; + for (i = 0; i < 3; i++) { + if (mode == GL_SELECT) + glLoadName (i); + for (j = 0; j < 3; j ++) { + if (mode == GL_SELECT) + glPushName (j); + glColor3f ((GLfloat) i/3.0, (GLfloat) j/3.0, + (GLfloat) board[i][j]/3.0); + glRecti (i, j, i+1, j+1); + if (mode == GL_SELECT) + glPopName (); + } + } +} + +/* processHits prints out the contents of the + * selection array. + */ +void processHits (GLint hits, GLuint buffer[]) +{ + unsigned int i, j; + GLuint ii, jj, names, *ptr; + + printf ("hits = %d\n", hits); + ptr = (GLuint *) buffer; + for (i = 0; i < hits; i++) { /* for each hit */ + names = *ptr; + printf (" number of names for this hit = %d\n", names); ptr++; + printf(" z1 is %g;", (float) *ptr/0x7fffffff); ptr++; + printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++; + printf (" names are "); + for (j = 0; j < names; j++) { /* for each name */ + printf ("%d ", *ptr); + if (j == 0) /* set row and column */ + ii = *ptr; + else if (j == 1) + jj = *ptr; + ptr++; + } + printf ("\n"); + board[ii][jj] = (board[ii][jj] + 1) % 3; + } +} + +/* pickSquares() sets up selection mode, name stack, + * and projection matrix for picking. Then the + * objects are drawn. + */ +#define BUFSIZE 512 + +void pickSquares(int button, int state, int x, int y) +{ + GLuint selectBuf[BUFSIZE]; + GLint hits; + GLint viewport[4]; + + if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) + return; + + glGetIntegerv (GL_VIEWPORT, viewport); + + glSelectBuffer (BUFSIZE, selectBuf); + (void) glRenderMode (GL_SELECT); + + glInitNames(); + glPushName(0); + + glMatrixMode (GL_PROJECTION); + glPushMatrix (); + glLoadIdentity (); +/* create 5x5 pixel picking region near cursor location */ + gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), + 5.0, 5.0, viewport); + gluOrtho2D (0.0, 3.0, 0.0, 3.0); + drawSquares (GL_SELECT); + + glMatrixMode (GL_PROJECTION); + glPopMatrix (); + glFlush (); + + hits = glRenderMode (GL_RENDER); + processHits (hits, selectBuf); + glutPostRedisplay(); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + drawSquares (GL_RENDER); + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D (0.0, 3.0, 0.0, 3.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* Main Loop */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (100, 100); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutReshapeFunc (reshape); + glutDisplayFunc(display); + glutMouseFunc (pickSquares); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/plane.c b/progs/redbook/plane.c new file mode 100644 index 0000000000..2b0cca06fa --- /dev/null +++ b/progs/redbook/plane.c @@ -0,0 +1,157 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * plane.c + * This program demonstrates the use of local versus + * infinite lighting on a flat plane. + */ +#include +#include + +/* Initialize material property, light source, and lighting model. + */ +void myinit(void) +{ + GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; +/* mat_specular and mat_shininess are NOT default values */ + GLfloat mat_diffuse[] = { 0.4, 0.4, 0.4, 1.0 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 15.0 }; + + GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +void drawPlane(void) +{ + glBegin (GL_QUADS); + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (-1.0, -1.0, 0.0); + glVertex3f (0.0, -1.0, 0.0); + glVertex3f (0.0, 0.0, 0.0); + glVertex3f (-1.0, 0.0, 0.0); + + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (0.0, -1.0, 0.0); + glVertex3f (1.0, -1.0, 0.0); + glVertex3f (1.0, 0.0, 0.0); + glVertex3f (0.0, 0.0, 0.0); + + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (0.0, 0.0, 0.0); + glVertex3f (1.0, 0.0, 0.0); + glVertex3f (1.0, 1.0, 0.0); + glVertex3f (0.0, 1.0, 0.0); + + glNormal3f (0.0, 0.0, 1.0); + glVertex3f (0.0, 0.0, 0.0); + glVertex3f (0.0, 1.0, 0.0); + glVertex3f (-1.0, 1.0, 0.0); + glVertex3f (-1.0, 0.0, 0.0); + glEnd(); +} + +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 }; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glTranslatef (-1.5, 0.0, 0.0); + glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); + drawPlane (); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (1.5, 0.0, 0.0); + glLightfv (GL_LIGHT0, GL_POSITION, local_light); + drawPlane (); + glPopMatrix (); + glFlush (); +} + +void myReshape(int w, int h) +{ + glViewport (0, 0, w, h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (w <= h) + glOrtho (-1.5, 1.5, -1.5*(GLdouble)h/(GLdouble)w, + 1.5*(GLdouble)h/(GLdouble)w, -10.0, 10.0); + else + glOrtho (-1.5*(GLdouble)w/(GLdouble)h, + 1.5*(GLdouble)w/(GLdouble)h, -1.5, 1.5, -10.0, 10.0); + glMatrixMode (GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 200); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/planet.c b/progs/redbook/planet.c new file mode 100644 index 0000000000..e13672d3f6 --- /dev/null +++ b/progs/redbook/planet.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * planet.c + * This program shows how to composite modeling transformations + * to draw translated and rotated models. + * Interaction: pressing the d and y keys (day and year) + * alters the rotation of the planet around the sun. + */ +#include +#include + +static int year = 0, day = 0; + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + + glPushMatrix(); + glutWireSphere(1.0, 20, 16); /* draw sun */ + glRotatef ((GLfloat) year, 0.0, 1.0, 0.0); + glTranslatef (2.0, 0.0, 0.0); + glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); + glutWireSphere(0.2, 10, 8); /* draw smaller planet */ + glPopMatrix(); + glutSwapBuffers(); +} + +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, 20.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 'd': + day = (day + 10) % 360; + glutPostRedisplay(); + break; + case 'D': + day = (day - 10) % 360; + glutPostRedisplay(); + break; + case 'y': + year = (year + 5) % 360; + glutPostRedisplay(); + break; + case 'Y': + year = (year - 5) % 360; + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/polyoff.c b/progs/redbook/polyoff.c new file mode 100644 index 0000000000..42887c9e0c --- /dev/null +++ b/progs/redbook/polyoff.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * polyoff.c + * This program demonstrates polygon offset to draw a shaded + * polygon and its wireframe counterpart without ugly visual + * artifacts ("stitching"). + */ +#include +#include +#include + +#ifdef GL_VERSION_1_1 +GLuint list; +GLint spinx = 0; +GLint spiny = 0; +GLfloat tdist = 0.0; +GLfloat polyfactor = 1.0; +GLfloat polyunits = 1.0; + +/* display() draws two spheres, one with a gray, diffuse material, + * the other sphere with a magenta material with a specular highlight. + */ +void display (void) +{ + GLfloat gray[] = { 0.8, 0.8, 0.8, 1.0 }; + GLfloat black[] = { 0.0, 0.0, 0.0, 1.0 }; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix (); + glTranslatef (0.0, 0.0, tdist); + glRotatef ((GLfloat) spinx, 1.0, 0.0, 0.0); + glRotatef ((GLfloat) spiny, 0.0, 1.0, 0.0); + + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray); + glMaterialfv(GL_FRONT, GL_SPECULAR, black); + glMaterialf(GL_FRONT, GL_SHININESS, 0.0); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(polyfactor, polyunits); + glCallList (list); + glDisable(GL_POLYGON_OFFSET_FILL); + + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glColor3f (1.0, 1.0, 1.0); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glCallList (list); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glPopMatrix (); + glFlush (); +} + +/* specify initial properties + * create display list with sphere + * initialize lighting and depth buffer + */ +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 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + GLfloat global_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + + glClearColor (0.0, 0.0, 0.0, 1.0); + + list = glGenLists(1); + glNewList (list, GL_COMPILE); + glutSolidSphere(1.0, 20, 12); + glEndList (); + + glEnable(GL_DEPTH_TEST); + + glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv (GL_LIGHT0, GL_POSITION, light_position); + glLightModelfv (GL_LIGHT_MODEL_AMBIENT, global_ambient); +} + +/* call when window is resized */ +void reshape(int width, int height) +{ + glViewport (0, 0, width, height); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluPerspective(45.0, (GLdouble)width/(GLdouble)height, + 1.0, 10.0); + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); +} + +/* call when mouse button is pressed */ +/* ARGSUSED2 */ +void mouse(int button, int state, int x, int y) { + switch (button) { + case GLUT_LEFT_BUTTON: + switch (state) { + case GLUT_DOWN: + spinx = (spinx + 5) % 360; + glutPostRedisplay(); + break; + default: + break; + } + break; + case GLUT_MIDDLE_BUTTON: + switch (state) { + case GLUT_DOWN: + spiny = (spiny + 5) % 360; + glutPostRedisplay(); + break; + default: + break; + } + break; + case GLUT_RIGHT_BUTTON: + switch (state) { + case GLUT_UP: + exit(0); + break; + default: + break; + } + break; + default: + break; + } +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 't': + if (tdist < 4.0) { + tdist = (tdist + 0.5); + glutPostRedisplay(); + } + break; + case 'T': + if (tdist > -5.0) { + tdist = (tdist - 0.5); + glutPostRedisplay(); + } + break; + case 'F': + polyfactor = polyfactor + 0.1; + printf ("polyfactor is %f\n", polyfactor); + glutPostRedisplay(); + break; + case 'f': + polyfactor = polyfactor - 0.1; + printf ("polyfactor is %f\n", polyfactor); + glutPostRedisplay(); + break; + case 'U': + polyunits = polyunits + 1.0; + printf ("polyunits is %f\n", polyunits); + glutPostRedisplay(); + break; + case 'u': + polyunits = polyunits - 1.0; + printf ("polyunits is %f\n", polyunits); + glutPostRedisplay(); + break; + 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutMouseFunc(mouse); + glutKeyboardFunc(keyboard); + gfxinit(); + 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/polys.c b/progs/redbook/polys.c new file mode 100644 index 0000000000..2983bc5cc3 --- /dev/null +++ b/progs/redbook/polys.c @@ -0,0 +1,124 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * polys.c + * This program demonstrates polygon stippling. + */ +#include +#include + +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, +0x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20, +0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, +0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, +0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66, +0x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, +0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0, +0x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30, +0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, +0x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08}; + + GLubyte halftone[] = { +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, +0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, +0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, +0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, +0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, +0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; + + glClear (GL_COLOR_BUFFER_BIT); + +/* draw all polygons in white */ + glColor3f (1.0, 1.0, 1.0); + +/* draw one solid, unstippled rectangle, */ +/* then two stippled rectangles */ + glRectf (25.0, 25.0, 125.0, 125.0); + glEnable (GL_POLYGON_STIPPLE); + glPolygonStipple (fly); + glRectf (125.0, 25.0, 225.0, 125.0); + glPolygonStipple (halftone); + glRectf (225.0, 25.0, 325.0, 125.0); + glDisable (GL_POLYGON_STIPPLE); + + glFlush (); +} + +void myinit (void) +{ +/* clear background to black */ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +static void reshape(GLsizei w, GLsizei h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* 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_SINGLE | GLUT_RGB); + glutInitWindowSize (350, 150); + glutCreateWindow (argv[0]); + myinit (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/quadric.c b/progs/redbook/quadric.c new file mode 100644 index 0000000000..4e46c85f82 --- /dev/null +++ b/progs/redbook/quadric.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * quadric.c + * This program demonstrates the use of some of the gluQuadric* + * routines. Quadric objects are created with some quadric + * properties and the callback routine to handle errors. + * Note that the cylinder has no top or bottom and the circle + * has a hole in it. + */ +#include +#include +#include + +/* Win32 calling conventions. */ +#ifndef CALLBACK +#define CALLBACK +#endif + +GLuint startList; + +void CALLBACK errorCallback(GLenum errorCode) +{ + const GLubyte *estring; + + estring = gluErrorString(errorCode); + fprintf(stderr, "Quadric Error: %s\n", estring); + exit(0); +} + +void init(void) +{ + GLUquadricObj *qobj; + GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_shininess[] = { 50.0 }; + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + GLfloat model_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + +/* Create 4 display lists, each with a different quadric object. + * Different drawing styles and surface normal specifications + * are demonstrated. + */ + startList = glGenLists(4); + qobj = gluNewQuadric(); + gluQuadricCallback(qobj, GLU_ERROR, + (GLvoid (CALLBACK*) ()) errorCallback); + + gluQuadricDrawStyle(qobj, GLU_FILL); /* smooth shaded */ + gluQuadricNormals(qobj, GLU_SMOOTH); + glNewList(startList, GL_COMPILE); + gluSphere(qobj, 0.75, 15, 10); + glEndList(); + + gluQuadricDrawStyle(qobj, GLU_FILL); /* flat shaded */ + gluQuadricNormals(qobj, GLU_FLAT); + glNewList(startList+1, GL_COMPILE); + gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5); + glEndList(); + + gluQuadricDrawStyle(qobj, GLU_LINE); /* all polygons wireframe */ + gluQuadricNormals(qobj, GLU_NONE); + glNewList(startList+2, GL_COMPILE); + gluDisk(qobj, 0.25, 1.0, 20, 4); + glEndList(); + + gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); /* boundary only */ + gluQuadricNormals(qobj, GLU_NONE); + glNewList(startList+3, GL_COMPILE); + gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0); + glEndList(); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + + glEnable(GL_LIGHTING); + glShadeModel (GL_SMOOTH); + glTranslatef(-1.0, -1.0, 0.0); + glCallList(startList); + + glShadeModel (GL_FLAT); + glTranslatef(0.0, 2.0, 0.0); + glPushMatrix(); + glRotatef(300.0, 1.0, 0.0, 0.0); + glCallList(startList+1); + glPopMatrix(); + + glDisable(GL_LIGHTING); + glColor3f(0.0, 1.0, 1.0); + glTranslatef(2.0, -2.0, 0.0); + glCallList(startList+2); + + glColor3f(1.0, 1.0, 0.0); + glTranslatef(0.0, 2.0, 0.0); + glCallList(startList+3); + + glPopMatrix(); + glFlush(); +} + +void reshape (int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, + 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho(-2.5*(GLfloat)w/(GLfloat)h, + 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +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(500, 500); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/robot.c b/progs/redbook/robot.c new file mode 100644 index 0000000000..94e20ac71e --- /dev/null +++ b/progs/redbook/robot.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * robot.c + * This program shows how to composite modeling transformations + * to draw translated and rotated hierarchical models. + * Interaction: pressing the s and e keys (shoulder and elbow) + * alters the rotation of the robot arm. + */ +#include +#include + +static int shoulder = 0, elbow = 0; + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glTranslatef (-1.0, 0.0, 0.0); + glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); + glTranslatef (1.0, 0.0, 0.0); + glPushMatrix(); + glScalef (2.0, 0.4, 1.0); + glutWireCube (1.0); + glPopMatrix(); + + glTranslatef (1.0, 0.0, 0.0); + glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); + glTranslatef (1.0, 0.0, 0.0); + glPushMatrix(); + glScalef (2.0, 0.4, 1.0); + glutWireCube (1.0); + glPopMatrix(); + + glPopMatrix(); + glutSwapBuffers(); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef (0.0, 0.0, -5.0); +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 's': + shoulder = (shoulder + 5) % 360; + glutPostRedisplay(); + break; + case 'S': + shoulder = (shoulder - 5) % 360; + glutPostRedisplay(); + break; + case 'e': + elbow = (elbow + 5) % 360; + glutPostRedisplay(); + break; + case 'E': + elbow = (elbow - 5) % 360; + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/sccolorlight.c b/progs/redbook/sccolorlight.c new file mode 100644 index 0000000000..191f266043 --- /dev/null +++ b/progs/redbook/sccolorlight.c @@ -0,0 +1,127 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * sccolorlight.c + * This program demonstrates the use of a colored + * (magenta, in this example) light source. Objects + * are drawn using a grey material characteristic. + * A single light source illuminates the objects. + */ +#include +#include + +/* Initialize material property and light source. + */ +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 }; + GLfloat light_specular[] = { 1.0, 0.0, 1.0, 1.0 }; +/* light_position is NOT default value */ + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix (); + glRotatef (20.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.75, 0.5, 0.0); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 20, 20); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.5, 0.0); + glRotatef (270.0, 1.0, 0.0, 0.0); + glutSolidCone (1.0, 2.0, 20, 20); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.0, -1.0); + glutSolidSphere (1.0, 20, 20); + glPopMatrix (); + + glPopMatrix (); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, + 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-2.5*(GLfloat)w/(GLfloat)h, + 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/scene.c b/progs/redbook/scene.c new file mode 100644 index 0000000000..428e8bd7a1 --- /dev/null +++ b/progs/redbook/scene.c @@ -0,0 +1,127 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * scene.c + * This program demonstrates the use of the GL lighting model. + * Objects are drawn using a grey material characteristic. + * A single light source illuminates the objects. + */ +#include +#include + +/* Initialize material property and light source. + */ +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 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; +/* light_position is NOT default value */ + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv (GL_LIGHT0, GL_POSITION, light_position); + + glEnable (GL_LIGHTING); + glEnable (GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +void display (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glRotatef (20.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.75, 0.5, 0.0); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.5, 0.0); + glRotatef (270.0, 1.0, 0.0, 0.0); + glutSolidCone (1.0, 2.0, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.0, -1.0); + glutSolidSphere (1.0, 15, 15); + glPopMatrix (); + + glPopMatrix (); + glFlush (); +} + +void myReshape(int w, int h) +{ + glViewport (0, 0, w, h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (w <= h) + glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, + 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-2.5*(GLfloat)w/(GLfloat)h, + 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); + glMatrixMode (GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + myinit (); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/scenebamb.c b/progs/redbook/scenebamb.c new file mode 100644 index 0000000000..a3449b5809 --- /dev/null +++ b/progs/redbook/scenebamb.c @@ -0,0 +1,126 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * scenebamb.c + * This program demonstrates use of a blue ambient light + * source. + */ +#include +#include + +/* Initialize light source and lighting. + */ +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 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; +/* light_position is NOT default value */ + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glRotatef (20.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.75, 0.5, 0.0); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.5, 0.0); + glRotatef (270.0, 1.0, 0.0, 0.0); + glutSolidCone (1.0, 2.0, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.0, -1.0); + glutSolidSphere (1.0, 15, 15); + glPopMatrix (); + + glPopMatrix (); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, + 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-2.5*(GLfloat)w/(GLfloat)h, + 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/sceneflat.c b/progs/redbook/sceneflat.c new file mode 100644 index 0000000000..5ab2037e4c --- /dev/null +++ b/progs/redbook/sceneflat.c @@ -0,0 +1,126 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * sceneflat.c + * This program draws lighted objects with flat shading. + */ +#include +#include + +/* Initialize light source and shading model (GL_FLAT). + */ +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 }; + GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; +/* light_position is NOT default value */ + GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glRotatef (20.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.75, 0.5, 0.0); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.5, 0.0); + glRotatef (270.0, 1.0, 0.0, 0.0); + glutSolidCone (1.0, 2.0, 15, 15); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.0, -1.0); + glutSolidSphere (1.0, 15, 15); + glPopMatrix (); + + glPopMatrix (); + glFlush(); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, + 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); + else + glOrtho (-2.5*(GLfloat)w/(GLfloat)h, + 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (500, 500); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/select.c b/progs/redbook/select.c new file mode 100644 index 0000000000..4f413e73ce --- /dev/null +++ b/progs/redbook/select.c @@ -0,0 +1,222 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * select.c + * This is an illustration of the selection mode and + * name stack, which detects whether objects which collide + * with a viewing volume. First, four triangles and a + * rectangular box representing a viewing volume are drawn + * (drawScene routine). The green triangle and yellow + * triangles appear to lie within the viewing volume, but + * the red triangle appears to lie outside it. Then the + * selection mode is entered (selectObjects routine). + * Drawing to the screen ceases. To see if any collisions + * occur, the four triangles are called. In this example, + * the green triangle causes one hit with the name 1, and + * the yellow triangles cause one hit with the name 3. + */ +#include +#include +#include + +/* 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, + GLfloat y2, GLfloat x3, GLfloat y3, GLfloat z) +{ + glBegin (GL_TRIANGLES); + glVertex3f (x1, y1, z); + glVertex3f (x2, y2, z); + glVertex3f (x3, y3, z); + glEnd (); +} + +/* 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) +{ + glColor3f (1.0, 1.0, 1.0); + glBegin (GL_LINE_LOOP); + glVertex3f (x1, y1, -z1); + glVertex3f (x2, y1, -z1); + glVertex3f (x2, y2, -z1); + glVertex3f (x1, y2, -z1); + glEnd (); + + glBegin (GL_LINE_LOOP); + glVertex3f (x1, y1, -z2); + glVertex3f (x2, y1, -z2); + glVertex3f (x2, y2, -z2); + glVertex3f (x1, y2, -z2); + glEnd (); + + glBegin (GL_LINES); /* 4 lines */ + glVertex3f (x1, y1, -z1); + glVertex3f (x1, y1, -z2); + glVertex3f (x1, y2, -z1); + glVertex3f (x1, y2, -z2); + glVertex3f (x2, y1, -z1); + glVertex3f (x2, y1, -z2); + glVertex3f (x2, y2, -z1); + glVertex3f (x2, y2, -z2); + glEnd (); +} + +/* drawScene draws 4 triangles and a wire frame + * which represents the viewing volume. + */ +void drawScene (void) +{ + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + gluPerspective (40.0, 4.0/3.0, 1.0, 100.0); + + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + gluLookAt (7.5, 7.5, 12.5, 2.5, 2.5, -5.0, 0.0, 1.0, 0.0); + glColor3f (0.0, 1.0, 0.0); /* green triangle */ + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0); + glColor3f (1.0, 0.0, 0.0); /* red triangle */ + drawTriangle (2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0); + glColor3f (1.0, 1.0, 0.0); /* yellow triangles */ + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0); + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0); + drawViewVolume (0.0, 5.0, 0.0, 5.0, 0.0, 10.0); +} + +/* processHits prints out the contents of the selection array + */ +void processHits (GLint hits, GLuint buffer[]) +{ + unsigned int i, j; + GLuint names, *ptr; + + printf ("hits = %d\n", hits); + ptr = (GLuint *) buffer; + for (i = 0; i < hits; i++) { /* for each hit */ + names = *ptr; + printf (" number of names for hit = %d\n", names); ptr++; + printf(" z1 is %g;", (float) *ptr/0x7fffffff); ptr++; + printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++; + printf (" the name is "); + for (j = 0; j < names; j++) { /* for each name */ + printf ("%d ", *ptr); ptr++; + } + printf ("\n"); + } +} + +/* selectObjects "draws" the triangles in selection mode, + * assigning names for the triangles. Note that the third + * and fourth triangles share one name, so that if either + * or both triangles intersects the viewing/clipping volume, + * only one hit will be registered. + */ +#define BUFSIZE 512 + +void selectObjects(void) +{ + GLuint selectBuf[BUFSIZE]; + GLint hits; + + glSelectBuffer (BUFSIZE, selectBuf); + (void) glRenderMode (GL_SELECT); + + glInitNames(); + glPushName(0); + + glPushMatrix (); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glOrtho (0.0, 5.0, 0.0, 5.0, 0.0, 10.0); + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + glLoadName(1); + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0); + glLoadName(2); + drawTriangle (2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0); + glLoadName(3); + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0); + drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0); + glPopMatrix (); + glFlush (); + + hits = glRenderMode (GL_RENDER); + processHits (hits, selectBuf); +} + +void init (void) +{ + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_FLAT); +} + +void display(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + drawScene (); + selectObjects (); + glFlush(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* Main Loop */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (200, 200); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init(); + glutDisplayFunc(display); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/smooth.c b/progs/redbook/smooth.c new file mode 100644 index 0000000000..9d22fc9025 --- /dev/null +++ b/progs/redbook/smooth.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * smooth.c + * This program demonstrates smooth shading. + * A smooth shaded polygon is drawn in a 2-D projection. + */ +#include +#include + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); +} + +void triangle(void) +{ + glBegin (GL_TRIANGLES); + glColor3f (1.0, 0.0, 0.0); + glVertex2f (5.0, 5.0); + glColor3f (0.0, 1.0, 0.0); + glVertex2f (25.0, 5.0); + glColor3f (0.0, 0.0, 1.0); + glVertex2f (5.0, 25.0); + glEnd(); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + triangle (); + glFlush (); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (w <= h) + gluOrtho2D (0.0, 30.0, 0.0, 30.0 * (GLfloat) h/(GLfloat) w); + else + gluOrtho2D (0.0, 30.0 * (GLfloat) w/(GLfloat) h, 0.0, 30.0); + glMatrixMode(GL_MODELVIEW); +} + +/* ARGSUSED1 */ +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 (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/stencil.c b/progs/redbook/stencil.c new file mode 100644 index 0000000000..958cf85c8e --- /dev/null +++ b/progs/redbook/stencil.c @@ -0,0 +1,162 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* stencil.c + * This program draws two rotated tori in a window. + * A diamond in the center of the window masks out part + * of the scene. Within this mask, a different model + * (a sphere) is drawn in a different color. + */ +#include +#include + +#define YELLOWMAT 1 +#define BLUEMAT 2 + +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 }; + + GLfloat blue_diffuse[] = { 0.1, 0.1, 0.7, 1.0 }; + GLfloat blue_specular[] = { 0.1, 1.0, 1.0, 1.0 }; + + GLfloat position_one[] = { 1.0, 1.0, 1.0, 0.0 }; + + glNewList(YELLOWMAT, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, yellow_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 64.0); + glEndList(); + + glNewList(BLUEMAT, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_DIFFUSE, blue_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, blue_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 45.0); + glEndList(); + + glLightfv(GL_LIGHT0, GL_POSITION, position_one); + + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + + glClearStencil(0x0); + glEnable(GL_STENCIL_TEST); + +} + +/* Draw a sphere in a diamond-shaped section in the + * middle of a window with 2 tori. + */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + +/* draw blue sphere where the stencil is 1 */ + glStencilFunc (GL_EQUAL, 0x1, 0x1); + glCallList (BLUEMAT); + glutSolidSphere (0.5, 15, 15); + +/* draw the tori where the stencil is not 1 */ + glStencilFunc (GL_NOTEQUAL, 0x1, 0x1); + glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); + glPushMatrix(); + glRotatef (45.0, 0.0, 0.0, 1.0); + glRotatef (45.0, 0.0, 1.0, 0.0); + glCallList (YELLOWMAT); + glutSolidTorus (0.275, 0.85, 15, 15); + glPushMatrix(); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 15, 15); + glPopMatrix(); + glPopMatrix(); + + glFlush(); +} + +/* Whenever the window is reshaped, redefine the + * coordinate system and redraw the stencil area. + */ +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + + glClear(GL_STENCIL_BUFFER_BIT); +/* create a diamond shaped stencil area */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-3.0, 3.0, -3.0, 3.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glStencilFunc (GL_ALWAYS, 0x1, 0x1); + glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); + glBegin(GL_QUADS); + glVertex3f (-1.0, 0.0, 0.0); + glVertex3f (0.0, 1.0, 0.0); + glVertex3f (1.0, 0.0, 0.0); + glVertex3f (0.0, -1.0, 0.0); + glEnd(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, (GLfloat) w/(GLfloat) h, 3.0, 7.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -5.0); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL); + glutInitWindowSize (400, 400); + glutCreateWindow (argv[0]); + myinit (); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/stroke.c b/progs/redbook/stroke.c new file mode 100644 index 0000000000..d8c75c89fe --- /dev/null +++ b/progs/redbook/stroke.c @@ -0,0 +1,181 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * stroke.c + * This program demonstrates some characters of a + * stroke (vector) font. The characters are represented + * by display lists, which are given numbers which + * correspond to the ASCII values of the characters. + * Use of glCallLists() is demonstrated. + */ +#include +#include +#include + +#define PT 1 +#define STROKE 2 +#define END 3 + +typedef struct charpoint { + GLfloat x, y; + int type; +} CP; + +CP Adata[] = { + { 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT}, + {5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END} +}; + +CP Edata[] = { + {5, 0, PT}, {0, 0, PT}, {0, 10, PT}, {5, 10, STROKE}, + {0, 5, PT}, {4, 5, END} +}; + +CP Pdata[] = { + {0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, + {4, 5, PT}, {0, 5, END} +}; + +CP Rdata[] = { + {0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT}, + {4, 5, PT}, {0, 5, STROKE}, {3, 5, PT}, {5, 0, END} +}; + +CP Sdata[] = { + {0, 1, PT}, {1, 0, PT}, {4, 0, PT}, {5, 1, PT}, {5, 4, PT}, + {4, 5, PT}, {1, 5, PT}, {0, 6, PT}, {0, 9, PT}, {1, 10, PT}, + {4, 10, PT}, {5, 9, END} +}; + +/* drawLetter() interprets the instructions from the array + * for that letter and renders the letter with line segments. + */ +void drawLetter(CP *l) +{ + glBegin(GL_LINE_STRIP); + for (;;) { + switch (l->type) { + case PT: + glVertex2fv(&l->x); + break; + case STROKE: + glVertex2fv(&l->x); + glEnd(); + glBegin(GL_LINE_STRIP); + break; + case END: + glVertex2fv(&l->x); + glEnd(); + glTranslatef(8.0, 0.0, 0.0); + return; + } + l++; + } +} + +/* Create a display list for each of 6 characters */ +void myinit (void) +{ + GLuint base; + + glShadeModel (GL_FLAT); + + base = glGenLists (128); + glListBase(base); + glNewList(base+'A', GL_COMPILE); drawLetter(Adata); glEndList(); + glNewList(base+'E', GL_COMPILE); drawLetter(Edata); glEndList(); + glNewList(base+'P', GL_COMPILE); drawLetter(Pdata); glEndList(); + glNewList(base+'R', GL_COMPILE); drawLetter(Rdata); glEndList(); + glNewList(base+'S', GL_COMPILE); drawLetter(Sdata); glEndList(); + glNewList(base+' ', GL_COMPILE); glTranslatef(8.0, 0.0, 0.0); glEndList(); +} + +char *test1 = "A SPARE SERAPE APPEARS AS"; +char *test2 = "APES PREPARE RARE PEPPERS"; + +void printStrokedString(char *s) +{ + GLsizei len = (GLsizei) strlen(s); + glCallLists(len, GL_BYTE, (GLbyte *)s); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 1.0, 1.0); + glPushMatrix(); + glScalef(2.0, 2.0, 2.0); + glTranslatef(10.0, 30.0, 0.0); + printStrokedString(test1); + glPopMatrix(); + glPushMatrix(); + glScalef(2.0, 2.0, 2.0); + glTranslatef(10.0, 13.0, 0.0); + printStrokedString(test2); + glPopMatrix(); + glFlush(); +} + +static void reshape(GLsizei w, GLsizei h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* 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_SINGLE | GLUT_RGB); + glutInitWindowSize (440, 120); + glutCreateWindow (argv[0]); + myinit (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/surface.c b/progs/redbook/surface.c new file mode 100644 index 0000000000..fb2691eb7c --- /dev/null +++ b/progs/redbook/surface.c @@ -0,0 +1,217 @@ +/* aux2glut conversion Copyright (c) Mark J. Kilgard, 1994, 1995 */ + +/** + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/** + * surface.c + * This program draws a NURBS surface in the shape of a + * symmetrical hill. + */ +#include + +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 + */ +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] = 7.0; + else + ctlpoints[u][v][2] = -3.0; + } + } +} + +/* Initialize material property and depth buffer. + */ +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 }; + GLfloat mat_shininess[] = { 100.0 }; + + glClearColor (0.0, 0.0, 0.0, 1.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); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + + init_surface(); + + theNurb = gluNewNurbsRenderer(); + gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef (0.0, 0.0, -5.0); +} + +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.25, 0.25, 0.25); + + 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(); + glutSwapBuffers(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, (GLdouble)w/(GLdouble)h, 3.0, 8.0); + + glMatrixMode(GL_MODELVIEW); +} + +void +menu(int value) +{ + switch (value) { + case 0: + case 1: + showPoints = value; + break; + case 2: + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); + break; + case 3: + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON); + break; + } + glutPostRedisplay(); +} + +int down = 0, lastx; + +/* ARGSUSED1 */ +void +motion(int x, int y) +{ + if (down) { + glRotatef(lastx - x, 0, 1, 0); + lastx = x; + glutPostRedisplay(); + } +} + +/* ARGSUSED3 */ +void +mouse(int button, int state, int x, int y) +{ + if (button == GLUT_LEFT_BUTTON) { + if (state == GLUT_DOWN) { + lastx = x; + down = 1; + } else { + down = 0; + } + } +} + +/* Main Loop */ +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(reshape); + glutDisplayFunc(display); + glutCreateMenu(menu); + glutAddMenuEntry("Show control points", 1); + glutAddMenuEntry("Hide control points", 0); + glutAddMenuEntry("Solid", 2); + glutAddMenuEntry("Wireframe", 3); + glutAttachMenu(GLUT_RIGHT_BUTTON); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/teaambient.c b/progs/redbook/teaambient.c new file mode 100644 index 0000000000..62c091c70a --- /dev/null +++ b/progs/redbook/teaambient.c @@ -0,0 +1,148 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/** + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/** + * teaambient.c + * This program renders three lighted, shaded teapots, with + * different ambient values. + */ +#include +#include + +/* Initialize light source and lighting model. + */ +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}; + GLfloat light_specular[] = + {1.0, 1.0, 1.0, 1.0}; +/* light_position is NOT default value */ + GLfloat light_position[] = + {1.0, 0.0, 0.0, 0.0}; + GLfloat global_ambient[] = + {0.75, 0.75, 0.75, 1.0}; + + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); + + glFrontFace(GL_CW); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); +} + +void +display(void) +{ + GLfloat low_ambient[] = + {0.1, 0.1, 0.1, 1.0}; + GLfloat more_ambient[] = + {0.4, 0.4, 0.4, 1.0}; + GLfloat most_ambient[] = + {1.0, 1.0, 1.0, 1.0}; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* material has small ambient reflection */ + glMaterialfv(GL_FRONT, GL_AMBIENT, low_ambient); + glMaterialf(GL_FRONT, GL_SHININESS, 40.0); + glPushMatrix(); + glTranslatef(0.0, 2.0, 0.0); + glutSolidTeapot(1.0); + glPopMatrix(); + + /* material has moderate ambient reflection */ + glMaterialfv(GL_FRONT, GL_AMBIENT, more_ambient); + glPushMatrix(); + glTranslatef(0.0, 0.0, 0.0); + glutSolidTeapot(1.0); + glPopMatrix(); + + /* material has large ambient reflection */ + glMaterialfv(GL_FRONT, GL_AMBIENT, most_ambient); + glPushMatrix(); + glTranslatef(0.0, -2.0, 0.0); + glutSolidTeapot(1.0); + glPopMatrix(); + glFlush(); +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w, + 4.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); + else + glOrtho(-4.0 * (GLfloat) w / (GLfloat) h, + 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize(500, 500); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/teapots.c b/progs/redbook/teapots.c new file mode 100644 index 0000000000..2431cae735 --- /dev/null +++ b/progs/redbook/teapots.c @@ -0,0 +1,206 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/** + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/** + * teapots.c + * This program demonstrates lots of material properties. + * A single light source illuminates the objects. + */ +#include +#include + +/* + * Initialize depth buffer, projection matrix, light source, and lighting + * model. Do not specify a material property here. + */ +void +myinit(void) +{ + GLfloat ambient[] = + {0.0, 0.0, 0.0, 1.0}; + GLfloat diffuse[] = + {1.0, 1.0, 1.0, 1.0}; + GLfloat position[] = + {0.0, 3.0, 3.0, 0.0}; + + GLfloat lmodel_ambient[] = + {0.2, 0.2, 0.2, 1.0}; + GLfloat local_view[] = + {0.0}; + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); + + glFrontFace(GL_CW); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); +} + +/* + * Move object into position. Use 3rd through 12th parameters to specify the + * material property. Draw a teapot. + */ +void +renderTeapot(GLfloat x, GLfloat y, + GLfloat ambr, GLfloat ambg, GLfloat ambb, + GLfloat difr, GLfloat difg, GLfloat difb, + GLfloat specr, GLfloat specg, GLfloat specb, GLfloat shine) +{ + float mat[4]; + + glPushMatrix(); + glTranslatef(x, y, 0.0); + mat[0] = ambr; + mat[1] = ambg; + mat[2] = ambb; + mat[3] = 1.0; + glMaterialfv(GL_FRONT, GL_AMBIENT, mat); + mat[0] = difr; + mat[1] = difg; + mat[2] = difb; + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat); + mat[0] = specr; + mat[1] = specg; + mat[2] = specb; + glMaterialfv(GL_FRONT, GL_SPECULAR, mat); + glMaterialf(GL_FRONT, GL_SHININESS, shine * 128.0); + glutSolidTeapot(1.0); + glPopMatrix(); +} + +/** + * First column: emerald, jade, obsidian, pearl, ruby, turquoise + * 2nd column: brass, bronze, chrome, copper, gold, silver + * 3rd column: black, cyan, green, red, white, yellow plastic + * 4th column: black, cyan, green, red, white, yellow rubber + */ +void +display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215, + 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6); + renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575, + 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1); + renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625, + 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3); + renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725, + 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088); + renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175, + 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6); + renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745, + 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1); + renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451, + 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843, + 0.21794872); + renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054, + 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2); + renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25, + 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6); + renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225, + 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1); + renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745, + 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4); + renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225, + 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4); + renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01, + 0.50, 0.50, 0.50, .25); + renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392, + 0.50196078, 0.50196078, 0.50196078, .25); + renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0, + 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, .25); + renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, + 0.7, 0.6, 0.6, .25); + renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55, + 0.70, 0.70, 0.70, .25); + renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, + 0.60, 0.60, 0.50, .25); + renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, + 0.4, 0.4, 0.4, .078125); + renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5, + 0.04, 0.7, 0.7, .078125); + renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4, + 0.04, 0.7, 0.04, .078125); + renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4, + 0.7, 0.04, 0.04, .078125); + renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5, + 0.7, 0.7, 0.7, .078125); + renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4, + 0.7, 0.7, 0.04, .078125); + glFlush(); +} + +void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(0.0, 16.0, 0.0, 16.0 * (GLfloat) h / (GLfloat) w, + -10.0, 10.0); + else + glOrtho(0.0, 16.0 * (GLfloat) w / (GLfloat) h, 0.0, 16.0, + -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +/* + * 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_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/tess.c b/progs/redbook/tess.c new file mode 100644 index 0000000000..cef35dbbe9 --- /dev/null +++ b/progs/redbook/tess.c @@ -0,0 +1,241 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * tess.c + * This program demonstrates polygon tessellation. + * Two tesselated objects are drawn. The first is a + * rectangle with a triangular hole. The second is a + * smooth shaded, self-intersecting star. + * + * Note the exterior rectangle is drawn with its vertices + * in counter-clockwise order, but its interior clockwise. + * Note the combineCallback is needed for the self-intersecting + * star. Also note that removing the TessProperty for the + * star will make the interior unshaded (WINDING_ODD). + */ +#include +#include +#include + +#ifdef GLU_VERSION_1_2 + +/* Win32 calling conventions. */ +#ifndef CALLBACK +#define CALLBACK +#endif + +GLuint startList; + +void display (void) { + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 1.0, 1.0); + glCallList(startList); + glCallList(startList + 1); + glFlush(); +} + +void CALLBACK beginCallback(GLenum which) +{ + glBegin(which); +} + +void CALLBACK errorCallback(GLenum errorCode) +{ + const GLubyte *estring; + + estring = gluErrorString(errorCode); + fprintf(stderr, "Tessellation Error: %s\n", estring); + exit(0); +} + +void CALLBACK endCallback(void) +{ + glEnd(); +} + +void CALLBACK vertexCallback(GLvoid *vertex) +{ + const GLdouble *pointer; + + pointer = (GLdouble *) vertex; + glColor3dv(pointer+3); + glVertex3dv(vertex); +} + +/* combineCallback is used to create a new vertex when edges + * intersect. coordinate location is trivial to calculate, + * 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], + GLdouble *vertex_data[4], + GLfloat weight[4], GLdouble **dataOut ) +{ + GLdouble *vertex; + int i; + + vertex = (GLdouble *) malloc(6 * sizeof(GLdouble)); + + vertex[0] = coords[0]; + vertex[1] = coords[1]; + vertex[2] = coords[2]; + for (i = 3; i < 7; i++) + vertex[i] = weight[0] * vertex_data[0][i] + + weight[1] * vertex_data[1][i] + + weight[2] * vertex_data[2][i] + + weight[3] * vertex_data[3][i]; + *dataOut = vertex; +} + +void init (void) +{ + GLUtesselator *tobj; + GLdouble rect[4][3] = {50.0, 50.0, 0.0, + 200.0, 50.0, 0.0, + 200.0, 200.0, 0.0, + 50.0, 200.0, 0.0}; + GLdouble tri[3][3] = {75.0, 75.0, 0.0, + 125.0, 175.0, 0.0, + 175.0, 75.0, 0.0}; + GLdouble star[5][6] = {250.0, 50.0, 0.0, 1.0, 0.0, 1.0, + 325.0, 200.0, 0.0, 1.0, 1.0, 0.0, + 400.0, 50.0, 0.0, 0.0, 1.0, 1.0, + 250.0, 150.0, 0.0, 1.0, 0.0, 0.0, + 400.0, 150.0, 0.0, 0.0, 1.0, 0.0}; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + startList = glGenLists(2); + + tobj = gluNewTess(); + gluTessCallback(tobj, GLU_TESS_VERTEX, + (GLvoid (CALLBACK*) ()) &glVertex3dv); + gluTessCallback(tobj, GLU_TESS_BEGIN, + (GLvoid (CALLBACK*) ()) &beginCallback); + gluTessCallback(tobj, GLU_TESS_END, + (GLvoid (CALLBACK*) ()) &endCallback); + gluTessCallback(tobj, GLU_TESS_ERROR, + (GLvoid (CALLBACK*) ()) &errorCallback); + + /* rectangle with triangular hole inside */ + glNewList(startList, GL_COMPILE); + glShadeModel(GL_FLAT); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + gluTessVertex(tobj, rect[0], rect[0]); + gluTessVertex(tobj, rect[1], rect[1]); + gluTessVertex(tobj, rect[2], rect[2]); + gluTessVertex(tobj, rect[3], rect[3]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + gluTessVertex(tobj, tri[0], tri[0]); + gluTessVertex(tobj, tri[1], tri[1]); + gluTessVertex(tobj, tri[2], tri[2]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); + + gluTessCallback(tobj, GLU_TESS_VERTEX, + (GLvoid (CALLBACK*) ()) &vertexCallback); + gluTessCallback(tobj, GLU_TESS_BEGIN, + (GLvoid (CALLBACK*) ()) &beginCallback); + gluTessCallback(tobj, GLU_TESS_END, + (GLvoid (CALLBACK*) ()) &endCallback); + gluTessCallback(tobj, GLU_TESS_ERROR, + (GLvoid (CALLBACK*) ()) &errorCallback); + gluTessCallback(tobj, GLU_TESS_COMBINE, + (GLvoid (CALLBACK*) ()) &combineCallback); + + /* smooth shaded, self-intersecting star */ + glNewList(startList + 1, GL_COMPILE); + glShadeModel(GL_SMOOTH); + gluTessProperty(tobj, GLU_TESS_WINDING_RULE, + GLU_TESS_WINDING_POSITIVE); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + gluTessVertex(tobj, star[0], star[0]); + gluTessVertex(tobj, star[1], star[1]); + gluTessVertex(tobj, star[2], star[2]); + gluTessVertex(tobj, star[3], star[3]); + gluTessVertex(tobj, star[4], star[4]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); + gluDeleteTess(tobj); +} + +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); +} + +/* ARGSUSED1 */ +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(500, 500); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} + +#else +int main(int argc, char** argv) +{ + fprintf (stderr, "This program demonstrates the new tesselator API in GLU 1.2.\n"); + fprintf (stderr, "Your GLU library does not support this new interface, sorry.\n"); + return 0; +} +#endif diff --git a/progs/redbook/tesswind.c b/progs/redbook/tesswind.c new file mode 100644 index 0000000000..455966a0b0 --- /dev/null +++ b/progs/redbook/tesswind.c @@ -0,0 +1,290 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * tesswind.c + * This program demonstrates the winding rule polygon + * tessellation property. Four tessellated objects are drawn, + * each with very different contours. When the w key is pressed, + * the objects are drawn with a different winding rule. + */ +#include +#include +#include + +#ifdef GLU_VERSION_1_2 + +/* Win32 calling conventions. */ +#ifndef CALLBACK +#define CALLBACK +#endif + +GLdouble currentWinding = GLU_TESS_WINDING_ODD; +int currentShape = 0; +GLUtesselator *tobj; +GLuint list; + +/* Make four display lists, + * each with a different tessellated object. + */ +void makeNewLists (void) { + int i; + static GLdouble rects[12][3] = + {50.0, 50.0, 0.0, 300.0, 50.0, 0.0, + 300.0, 300.0, 0.0, 50.0, 300.0, 0.0, + 100.0, 100.0, 0.0, 250.0, 100.0, 0.0, + 250.0, 250.0, 0.0, 100.0, 250.0, 0.0, + 150.0, 150.0, 0.0, 200.0, 150.0, 0.0, + 200.0, 200.0, 0.0, 150.0, 200.0, 0.0}; + static GLdouble spiral[16][3] = + {400.0, 250.0, 0.0, 400.0, 50.0, 0.0, + 50.0, 50.0, 0.0, 50.0, 400.0, 0.0, + 350.0, 400.0, 0.0, 350.0, 100.0, 0.0, + 100.0, 100.0, 0.0, 100.0, 350.0, 0.0, + 300.0, 350.0, 0.0, 300.0, 150.0, 0.0, + 150.0, 150.0, 0.0, 150.0, 300.0, 0.0, + 250.0, 300.0, 0.0, 250.0, 200.0, 0.0, + 200.0, 200.0, 0.0, 200.0, 250.0, 0.0}; + static GLdouble quad1[4][3] = + {50.0, 150.0, 0.0, 350.0, 150.0, 0.0, + 350.0, 200.0, 0.0, 50.0, 200.0, 0.0}; + static GLdouble quad2[4][3] = + {100.0, 100.0, 0.0, 300.0, 100.0, 0.0, + 300.0, 350.0, 0.0, 100.0, 350.0, 0.0}; + static GLdouble tri[3][3] = + {200.0, 50.0, 0.0, 250.0, 300.0, 0.0, + 150.0, 300.0, 0.0}; + + gluTessProperty(tobj, GLU_TESS_WINDING_RULE, + currentWinding); + + glNewList(list, GL_COMPILE); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + for (i = 0; i < 4; i++) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 4; i < 8; i++) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 8; i < 12; i++) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); + + glNewList(list+1, GL_COMPILE); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + for (i = 0; i < 4; i++) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 7; i >= 4; i--) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 11; i >= 8; i--) + gluTessVertex(tobj, rects[i], rects[i]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); + + glNewList(list+2, GL_COMPILE); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + for (i = 0; i < 16; i++) + gluTessVertex(tobj, spiral[i], spiral[i]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); + + glNewList(list+3, GL_COMPILE); + gluTessBeginPolygon(tobj, NULL); + gluTessBeginContour(tobj); + for (i = 0; i < 4; i++) + gluTessVertex(tobj, quad1[i], quad1[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 0; i < 4; i++) + gluTessVertex(tobj, quad2[i], quad2[i]); + gluTessEndContour(tobj); + gluTessBeginContour(tobj); + for (i = 0; i < 3; i++) + gluTessVertex(tobj, tri[i], tri[i]); + gluTessEndContour(tobj); + gluTessEndPolygon(tobj); + glEndList(); +} + +void display (void) { + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 1.0, 1.0); + glPushMatrix(); + glCallList(list); + glTranslatef(0.0, 500.0, 0.0); + glCallList(list+1); + glTranslatef(500.0, -500.0, 0.0); + glCallList(list+2); + glTranslatef(0.0, 500.0, 0.0); + glCallList(list+3); + glPopMatrix(); + glFlush(); +} + +void CALLBACK beginCallback(GLenum which) +{ + glBegin(which); +} + +void CALLBACK errorCallback(GLenum errorCode) +{ + const GLubyte *estring; + + estring = gluErrorString(errorCode); + fprintf(stderr, "Tessellation Error: %s\n", estring); + exit(0); +} + +void CALLBACK endCallback(void) +{ + glEnd(); +} + +/* combineCallback is used to create a new vertex when edges + * intersect. coordinate location is trivial to calculate, + * but weight[4] may be used to average color, normal, or texture + * coordinate data. + */ +/* ARGSUSED */ +void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4], + GLfloat weight[4], GLdouble **dataOut ) +{ + GLdouble *vertex; + vertex = (GLdouble *) malloc(3 * sizeof(GLdouble)); + + vertex[0] = coords[0]; + vertex[1] = coords[1]; + vertex[2] = coords[2]; + *dataOut = vertex; +} + +void init(void) +{ + glClearColor(0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + + tobj = gluNewTess(); + gluTessCallback(tobj, GLU_TESS_VERTEX, + (GLvoid (CALLBACK*) ()) &glVertex3dv); + gluTessCallback(tobj, GLU_TESS_BEGIN, + (GLvoid (CALLBACK*) ()) &beginCallback); + gluTessCallback(tobj, GLU_TESS_END, + (GLvoid (CALLBACK*) ()) &endCallback); + gluTessCallback(tobj, GLU_TESS_ERROR, + (GLvoid (CALLBACK*) ()) &errorCallback); + gluTessCallback(tobj, GLU_TESS_COMBINE, + (GLvoid (CALLBACK*) ()) &combineCallback); + + list = glGenLists(4); + makeNewLists(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + gluOrtho2D(0.0, 1000.0, 0.0, 1000.0 * (GLdouble)h/(GLdouble)w); + else + gluOrtho2D(0.0, 1000.0 * (GLdouble)w/(GLdouble)h, 0.0, 1000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 'w': + case 'W': + if (currentWinding == GLU_TESS_WINDING_ODD) + currentWinding = GLU_TESS_WINDING_NONZERO; + else if (currentWinding == GLU_TESS_WINDING_NONZERO) + currentWinding = GLU_TESS_WINDING_POSITIVE; + else if (currentWinding == GLU_TESS_WINDING_POSITIVE) + currentWinding = GLU_TESS_WINDING_NEGATIVE; + else if (currentWinding == GLU_TESS_WINDING_NEGATIVE) + currentWinding = GLU_TESS_WINDING_ABS_GEQ_TWO; + else if (currentWinding == GLU_TESS_WINDING_ABS_GEQ_TWO) + currentWinding = GLU_TESS_WINDING_ODD; + makeNewLists(); + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + default: + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(500, 500); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} + +#else +int main(int argc, char** argv) +{ + fprintf (stderr, "This program demonstrates the new tesselator API in GLU 1.2.\n"); + fprintf (stderr, "Your GLU library does not support this new interface, sorry.\n"); + return 0; +} +#endif diff --git a/progs/redbook/texbind.c b/progs/redbook/texbind.c new file mode 100644 index 0000000000..92c226fbdb --- /dev/null +++ b/progs/redbook/texbind.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* texbind.c + * This program demonstrates using glBindTexture() by + * creating and managing two textures. + */ +#include +#include +#include + +#ifdef GL_VERSION_1_1 +/* Create checkerboard texture */ +#define checkImageWidth 64 +#define checkImageHeight 64 +static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; +static GLubyte otherImage[checkImageHeight][checkImageWidth][4]; + +static GLuint texName[2]; + +void makeCheckImages(void) +{ + int i, j, c; + + for (i = 0; i < checkImageHeight; i++) { + for (j = 0; j < checkImageWidth; j++) { + c = ((((i&0x8)==0)^((j&0x8))==0))*255; + checkImage[i][j][0] = (GLubyte) c; + checkImage[i][j][1] = (GLubyte) c; + checkImage[i][j][2] = (GLubyte) c; + checkImage[i][j][3] = (GLubyte) 255; + c = ((((i&0x10)==0)^((j&0x10))==0))*255; + otherImage[i][j][0] = (GLubyte) c; + otherImage[i][j][1] = (GLubyte) 0; + otherImage[i][j][2] = (GLubyte) 0; + otherImage[i][j][3] = (GLubyte) 255; + } + } +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + makeCheckImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glGenTextures(2, texName); + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + 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, checkImageWidth, + checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, + checkImage); + + glBindTexture(GL_TEXTURE_2D, texName[1]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, + checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, + otherImage); + glEnable(GL_TEXTURE_2D); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindTexture(GL_TEXTURE_2D, texName[0]); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); + glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); + glEnd(); + glBindTexture(GL_TEXTURE_2D, texName[1]); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421); + glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); + glEnd(); + glFlush(); +} + +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, -3.6); +} + +/* ARGSUSED1 */ +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]); + 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.\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/texgen.c b/progs/redbook/texgen.c new file mode 100644 index 0000000000..7c1802a3be --- /dev/null +++ b/progs/redbook/texgen.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* texgen.c + * This program draws a texture mapped teapot with + * automatically generated texture coordinates. The + * texture is rendered as stripes on the teapot. + * Initially, the object is drawn with texture coordinates + * based upon the object coordinates of the vertex + * and distance from the plane x = 0. Pressing the 'e' + * key changes the coordinate generation to eye coordinates + * of the vertex. Pressing the 'o' key switches it back + * to the object coordinates. Pressing the 's' key + * changes the plane to a slanted one (x + y + z = 0). + * Pressing the 'x' key switches it back to x = 0. + */ + +#include +#include +#include + +#define stripeImageWidth 32 +GLubyte stripeImage[4*stripeImageWidth]; + +#ifdef GL_VERSION_1_1 +static GLuint texName; +#endif + +void makeStripeImage(void) +{ + int j; + + for (j = 0; j < stripeImageWidth; j++) { + stripeImage[4*j] = (GLubyte) ((j<=4) ? 255 : 0); + stripeImage[4*j+1] = (GLubyte) ((j>4) ? 255 : 0); + stripeImage[4*j+2] = (GLubyte) 0; + stripeImage[4*j+3] = (GLubyte) 255; + } +} + +/* planes for texture coordinate generation */ +static GLfloat xequalzero[] = {1.0, 0.0, 0.0, 0.0}; +static GLfloat slanted[] = {1.0, 1.0, 1.0, 0.0}; +static GLfloat *currentCoeff; +static GLenum currentPlane; +static GLint currentGenMode; + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + + makeStripeImage(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + +#ifdef GL_VERSION_1_1 + glGenTextures(1, &texName); + glBindTexture(GL_TEXTURE_1D, texName); +#endif + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); +#ifdef GL_VERSION_1_1 + glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, stripeImageWidth, 0, + GL_RGBA, GL_UNSIGNED_BYTE, stripeImage); +#else + glTexImage1D(GL_TEXTURE_1D, 0, 4, stripeImageWidth, 0, + GL_RGBA, GL_UNSIGNED_BYTE, stripeImage); +#endif + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + currentCoeff = xequalzero; + currentGenMode = GL_OBJECT_LINEAR; + currentPlane = GL_OBJECT_PLANE; + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode); + glTexGenfv(GL_S, currentPlane, currentCoeff); + + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_1D); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + glEnable(GL_NORMALIZE); + glFrontFace(GL_CW); + glCullFace(GL_BACK); + glMaterialf (GL_FRONT, GL_SHININESS, 64.0); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glRotatef(45.0, 0.0, 0.0, 1.0); +#ifdef GL_VERSION_1_1 + glBindTexture(GL_TEXTURE_1D, texName); +#endif + glutSolidTeapot(2.0); + glPopMatrix (); + glFlush(); +} + +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-3.5, 3.5, -3.5*(GLfloat)h/(GLfloat)w, + 3.5*(GLfloat)h/(GLfloat)w, -3.5, 3.5); + else + glOrtho (-3.5*(GLfloat)w/(GLfloat)h, + 3.5*(GLfloat)w/(GLfloat)h, -3.5, 3.5, -3.5, 3.5); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 'e': + case 'E': + currentGenMode = GL_EYE_LINEAR; + currentPlane = GL_EYE_PLANE; + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode); + glTexGenfv(GL_S, currentPlane, currentCoeff); + glutPostRedisplay(); + break; + case 'o': + case 'O': + currentGenMode = GL_OBJECT_LINEAR; + currentPlane = GL_OBJECT_PLANE; + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode); + glTexGenfv(GL_S, currentPlane, currentCoeff); + glutPostRedisplay(); + break; + case 's': + case 'S': + currentCoeff = slanted; + glTexGenfv(GL_S, currentPlane, currentCoeff); + glutPostRedisplay(); + break; + case 'x': + case 'X': + currentCoeff = xequalzero; + glTexGenfv(GL_S, currentPlane, currentCoeff); + 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(256, 256); + glutInitWindowPosition(100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/texprox.c b/progs/redbook/texprox.c new file mode 100644 index 0000000000..6f1e853fac --- /dev/null +++ b/progs/redbook/texprox.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * texprox.c + * The brief program illustrates use of texture proxies. + * This program only prints out some messages about whether + * certain size textures are supported and then exits. + */ +#include +#include +#include + +#ifdef GL_VERSION_1_1 + +/* Microsoft OpenGL 1.1's forgets to define + GL_TEXTURE_INTERNAL_FORMAT. */ +#ifndef GL_TEXTURE_INTERNAL_FORMAT +#define GL_TEXTURE_INTERNAL_FORMAT GL_TEXTURE_COMPONENTS +#endif + +void init(void) +{ + GLint proxyComponents; + + putchar('\n'); + + glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA8, + 64, 64, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, + GL_TEXTURE_INTERNAL_FORMAT, &proxyComponents); + printf ("Proxying 64x64 level 0 RGBA8 texture (level 0)\n"); + if (proxyComponents == GL_RGBA8) + printf ("proxy allocation succeeded\n"); + else + printf ("proxy allocation failed\n"); + putchar('\n'); + + glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA16, + 2048, 2048, 0, + GL_RGBA, GL_UNSIGNED_SHORT, NULL); + glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, + GL_TEXTURE_INTERNAL_FORMAT, &proxyComponents); + printf ("Proxying 2048x2048 level 0 RGBA16 texture (big so unlikely to be supported)\n"); + if (proxyComponents == GL_RGBA16) + printf ("proxy allocation succeeded\n"); + else + printf ("proxy allocation failed\n"); + putchar('\n'); +} + +void display(void) +{ + exit(0); +} + +void reshape (int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + 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/texsub.c b/progs/redbook/texsub.c new file mode 100644 index 0000000000..5dc36ec4e7 --- /dev/null +++ b/progs/redbook/texsub.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* texsub.c + * This program texture maps a checkerboard image onto + * two rectangles. This program clamps the texture, if + * the texture coordinates fall outside 0.0 and 1.0. + * If the s key is pressed, a texture subimage is used to + * alter the original texture. If the r key is pressed, + * the original texture is restored. + */ +#include +#include +#include + +#ifdef GL_VERSION_1_1 +/* Create checkerboard textures */ +#define checkImageWidth 64 +#define checkImageHeight 64 +#define subImageWidth 16 +#define subImageHeight 16 +static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; +static GLubyte subImage[subImageHeight][subImageWidth][4]; + +static GLuint texName; + +void makeCheckImages(void) +{ + int i, j, c; + + for (i = 0; i < checkImageHeight; i++) { + for (j = 0; j < checkImageWidth; j++) { + c = ((((i&0x8)==0)^((j&0x8))==0))*255; + checkImage[i][j][0] = (GLubyte) c; + checkImage[i][j][1] = (GLubyte) c; + checkImage[i][j][2] = (GLubyte) c; + checkImage[i][j][3] = (GLubyte) 255; + } + } + for (i = 0; i < subImageHeight; i++) { + for (j = 0; j < subImageWidth; j++) { + c = ((((i&0x4)==0)^((j&0x4))==0))*255; + subImage[i][j][0] = (GLubyte) c; + subImage[i][j][1] = (GLubyte) 0; + subImage[i][j][2] = (GLubyte) 0; + subImage[i][j][3] = (GLubyte) 255; + } + } +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + makeCheckImages(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glGenTextures(1, &texName); + glBindTexture(GL_TEXTURE_2D, texName); + + 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, checkImageWidth, checkImageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glBindTexture(GL_TEXTURE_2D, texName); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); + glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); + + glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); + glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0); + glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421); + glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); + glEnd(); + glFlush(); + glDisable(GL_TEXTURE_2D); +} + +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, -3.6); +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 's': + case 'S': + glBindTexture(GL_TEXTURE_2D, texName); + glTexSubImage2D(GL_TEXTURE_2D, 0, 12, 44, subImageWidth, + subImageHeight, GL_RGBA, + GL_UNSIGNED_BYTE, subImage); + glutPostRedisplay(); + break; + case 'r': + case 'R': + glBindTexture(GL_TEXTURE_2D, texName); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, + checkImageHeight, 0, GL_RGBA, + GL_UNSIGNED_BYTE, checkImage); + 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(250, 250); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + 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/texturesurf.c b/progs/redbook/texturesurf.c new file mode 100644 index 0000000000..89cdbcc652 --- /dev/null +++ b/progs/redbook/texturesurf.c @@ -0,0 +1,141 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* texturesurf.c + * This program uses evaluators to generate a curved + * surface and automatically generated texture coordinates. + */ + +#include +#include +#include + +GLfloat ctrlpoints[4][4][3] = { + {{ -1.5, -1.5, 4.0}, { -0.5, -1.5, 2.0}, + {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, + {{ -1.5, -0.5, 1.0}, { -0.5, -0.5, 3.0}, + {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, + {{ -1.5, 0.5, 4.0}, { -0.5, 0.5, 0.0}, + {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, + {{ -1.5, 1.5, -2.0}, { -0.5, 1.5, -2.0}, + {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}} +}; + +GLfloat texpts[2][2][2] = {{{0.0, 0.0}, {0.0, 1.0}}, + {{1.0, 0.0}, {1.0, 1.0}}}; + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glColor3f(1.0, 1.0, 1.0); + glEvalMesh2(GL_FILL, 0, 20, 0, 20); + glFlush(); +} + +#define imageWidth 64 +#define imageHeight 64 +GLubyte image[3*imageWidth*imageHeight]; + +void makeImage(void) +{ + int i, j; + float ti, tj; + + for (i = 0; i < imageWidth; i++) { + ti = 2.0*3.14159265*i/imageWidth; + for (j = 0; j < imageHeight; j++) { + tj = 2.0*3.14159265*j/imageHeight; + + image[3*(imageHeight*i+j)] = (GLubyte) 127*(1.0+sin(ti)); + image[3*(imageHeight*i+j)+1] = (GLubyte) 127*(1.0+cos(2*tj)); + image[3*(imageHeight*i+j)+2] = (GLubyte) 127*(1.0+cos(ti+tj)); + } + } +} + +void myinit(void) +{ + glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, + 0, 1, 12, 4, &ctrlpoints[0][0][0]); + glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, + 0, 1, 4, 2, &texpts[0][0][0]); + glEnable(GL_MAP2_TEXTURE_COORD_2); + glEnable(GL_MAP2_VERTEX_3); + glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); + makeImage(); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, 3, imageWidth, imageHeight, 0, + GL_RGB, GL_UNSIGNED_BYTE, image); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glEnable(GL_NORMALIZE); + glShadeModel (GL_FLAT); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(-4.0, 4.0, -4.0*(GLfloat)h/(GLfloat)w, + 4.0*(GLfloat)h/(GLfloat)w, -4.0, 4.0); + else + glOrtho(-4.0*(GLfloat)w/(GLfloat)h, + 4.0*(GLfloat)w/(GLfloat)h, -4.0, 4.0, -4.0, 4.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glRotatef(85.0, 1.0, 1.0, 1.0); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/redbook/torus.c b/progs/redbook/torus.c new file mode 100644 index 0000000000..7ae4d41e26 --- /dev/null +++ b/progs/redbook/torus.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * torus.c + * This program demonstrates the creation of a display list. + */ + +#include +#include +#include +#include + +/* Some files do not define M_PI... */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +GLuint theTorus; + +/* Draw a torus */ +static void torus(int numc, int numt) +{ + int i, j, k; + double s, t, x, y, z, twopi; + + twopi = 2 * (double)M_PI; + for (i = 0; i < numc; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) { + for (k = 1; k >= 0; k--) { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = (1+.1*cos(s*twopi/numc))*cos(t*twopi/numt); + y = (1+.1*cos(s*twopi/numc))*sin(t*twopi/numt); + z = .1 * sin(s * twopi / numc); + glVertex3f(x, y, z); + } + } + glEnd(); + } +} + +/* Create display list with Torus and initialize state */ +static void init(void) +{ + theTorus = glGenLists (1); + glNewList(theTorus, GL_COMPILE); + torus(8, 25); + glEndList(); + + glShadeModel(GL_FLAT); + glClearColor(0.0, 0.0, 0.0, 0.0); +} + +/* Clear window and draw torus */ +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + glCallList(theTorus); + glFlush(); +} + +/* Handle window resize */ +void reshape(int w, int h) +{ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(30, (GLfloat) w/(GLfloat) h, 1.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); +} + +/* 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) +{ + switch (key) { + case 'x': + case 'X': + glRotatef(30.,1.0,0.0,0.0); + glutPostRedisplay(); + break; + case 'y': + case 'Y': + glRotatef(30.,0.0,1.0,0.0); + glutPostRedisplay(); + break; + case 'i': + case 'I': + glLoadIdentity(); + gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); + glutPostRedisplay(); + break; + case 27: + exit(0); + break; + } +} + +int main(int argc, char **argv) +{ + glutInitWindowSize(200, 200); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutCreateWindow(argv[0]); + init(); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutDisplayFunc(display); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/trim.c b/progs/redbook/trim.c new file mode 100644 index 0000000000..26f474814c --- /dev/null +++ b/progs/redbook/trim.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * trim.c + * This program draws a NURBS surface in the shape of a + * symmetrical hill, using both a NURBS curve and pwl + * (piecewise linear) curve to trim part of the surface. + */ +#include +#include +#include + + +#ifndef CALLBACK +#define CALLBACK +#endif + + +GLfloat ctlpoints[4][4][3]; + +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) +{ + 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; + } + } +} + +void nurbsError(GLenum errorCode) +{ + const GLubyte *estring; + + estring = gluErrorString(errorCode); + fprintf (stderr, "Nurbs Error: %s\n", estring); + exit (0); +} + +/* Initialize material property and depth buffer. + */ +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_SAMPLING_TOLERANCE, 25.0); + gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); + gluNurbsCallback(theNurb, GLU_ERROR, + (GLvoid (CALLBACK*) ()) nurbsError); +} + +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 */ + {{0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {0.0, 1.0}, {0.0, 0.0}}; + GLfloat curvePt[4][2] = /* clockwise */ + {{0.25, 0.5}, {0.25, 0.75}, {0.75, 0.75}, {0.75, 0.5}}; + GLfloat curveKnots[8] = + {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0}; + GLfloat pwlPt[4][2] = /* clockwise */ + {{0.75, 0.5}, {0.5, 0.25}, {0.25, 0.5}}; + + 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); + gluBeginTrim (theNurb); + gluPwlCurve (theNurb, 5, &edgePt[0][0], 2, GLU_MAP1_TRIM_2); + gluEndTrim (theNurb); + gluBeginTrim (theNurb); + gluNurbsCurve (theNurb, 8, curveKnots, 2, + &curvePt[0][0], 4, GLU_MAP1_TRIM_2); + gluPwlCurve (theNurb, 3, &pwlPt[0][0], 2, GLU_MAP1_TRIM_2); + gluEndTrim (theNurb); + gluEndSurface(theNurb); + + glPopMatrix(); + glFlush(); +} + +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); +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* Main Loop + */ +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; +} diff --git a/progs/redbook/unproject.c b/progs/redbook/unproject.c new file mode 100644 index 0000000000..134c361bac --- /dev/null +++ b/progs/redbook/unproject.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * unproject.c + * When the left mouse button is pressed, this program + * reads the mouse position and determines two 3D points + * from which it was transformed. Very little is displayed. + */ +#include +#include +#include + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glFlush(); +} + +/* Change these values for a different transformation */ +void reshape(int w, int h) +{ + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 1.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +void mouse(int button, int state, int x, int y) +{ + GLint viewport[4]; + GLdouble mvmatrix[16], projmatrix[16]; + GLint realy; /* OpenGL y coordinate position */ + GLdouble wx, wy, wz; /* returned world x, y, z coords */ + + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN) { + glGetIntegerv (GL_VIEWPORT, viewport); + glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix); + glGetDoublev (GL_PROJECTION_MATRIX, projmatrix); +/* note viewport[3] is height of window in pixels */ + realy = viewport[3] - (GLint) y - 1; + printf ("Coordinates at cursor are (%4d, %4d)\n", x, realy); + gluUnProject ((GLdouble) x, (GLdouble) realy, 0.0, + mvmatrix, projmatrix, viewport, &wx, &wy, &wz); + printf ("World coords at z=0.0 are (%f, %f, %f)\n", + wx, wy, wz); + gluUnProject ((GLdouble) x, (GLdouble) realy, 1.0, + mvmatrix, projmatrix, viewport, &wx, &wy, &wz); + printf ("World coords at z=1.0 are (%f, %f, %f)\n", + wx, wy, wz); + } + break; + case GLUT_RIGHT_BUTTON: + if (state == GLUT_DOWN) + exit(0); + break; + default: + break; + } +} + +/* ARGSUSED1 */ +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +/* + * Open window, register input callback functions + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMouseFunc(mouse); + glutMainLoop(); + return 0; +} diff --git a/progs/redbook/varray.c b/progs/redbook/varray.c new file mode 100644 index 0000000000..b22e723e0e --- /dev/null +++ b/progs/redbook/varray.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* + * varray.c + * This program demonstrates vertex arrays. + */ +#include +#include +#include + +#ifdef GL_VERSION_1_1 +#define POINTER 1 +#define INTERLEAVED 2 + +#define DRAWARRAY 1 +#define ARRAYELEMENT 2 +#define DRAWELEMENTS 3 + +int setupMethod = POINTER; +int derefMethod = DRAWARRAY; + +void setupPointers(void) +{ + static GLint vertices[] = {25, 25, + 100, 325, + 175, 25, + 175, 325, + 250, 25, + 325, 325}; + static GLfloat colors[] = {1.0, 0.2, 0.2, + 0.2, 0.2, 1.0, + 0.8, 1.0, 0.2, + 0.75, 0.75, 0.75, + 0.35, 0.35, 0.35, + 0.5, 0.5, 0.5}; + + glEnableClientState (GL_VERTEX_ARRAY); + glEnableClientState (GL_COLOR_ARRAY); + + glVertexPointer (2, GL_INT, 0, vertices); + glColorPointer (3, GL_FLOAT, 0, colors); +} + +void setupInterleave(void) +{ + static GLfloat intertwined[] = + {1.0, 0.2, 1.0, 100.0, 100.0, 0.0, + 1.0, 0.2, 0.2, 0.0, 200.0, 0.0, + 1.0, 1.0, 0.2, 100.0, 300.0, 0.0, + 0.2, 1.0, 0.2, 200.0, 300.0, 0.0, + 0.2, 1.0, 1.0, 300.0, 200.0, 0.0, + 0.2, 0.2, 1.0, 200.0, 100.0, 0.0}; + + glInterleavedArrays (GL_C3F_V3F, 0, intertwined); +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + setupPointers (); +} + +void display(void) +{ + glClear (GL_COLOR_BUFFER_BIT); + + if (derefMethod == DRAWARRAY) + glDrawArrays (GL_TRIANGLES, 0, 6); + else if (derefMethod == ARRAYELEMENT) { + glBegin (GL_TRIANGLES); + glArrayElement (2); + glArrayElement (3); + glArrayElement (5); + glEnd (); + } + else if (derefMethod == DRAWELEMENTS) { + GLuint indices[4] = {0, 1, 3, 4}; + + glDrawElements (GL_POLYGON, 4, GL_UNSIGNED_INT, indices); + } + glFlush (); +} + +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); +} + +/* ARGSUSED2 */ +void mouse (int button, int state, int x, int y) +{ + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN) { + if (setupMethod == POINTER) { + setupMethod = INTERLEAVED; + setupInterleave(); + } + else if (setupMethod == INTERLEAVED) { + setupMethod = POINTER; + setupPointers(); + } + glutPostRedisplay(); + } + break; + case GLUT_MIDDLE_BUTTON: + case GLUT_RIGHT_BUTTON: + if (state == GLUT_DOWN) { + if (derefMethod == DRAWARRAY) + derefMethod = ARRAYELEMENT; + else if (derefMethod == ARRAYELEMENT) + derefMethod = DRAWELEMENTS; + else if (derefMethod == DRAWELEMENTS) + derefMethod = DRAWARRAY; + glutPostRedisplay(); + } + break; + default: + break; + } +} + +/* ARGSUSED1 */ +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]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMouseFunc(mouse); + 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/wrap.c b/progs/redbook/wrap.c new file mode 100644 index 0000000000..c67e04a7f3 --- /dev/null +++ b/progs/redbook/wrap.c @@ -0,0 +1,180 @@ +/* + * Copyright (c) 1993-1997, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. + */ + +/* wrap.c + * This program texture maps a checkerboard image onto + * two rectangles. This program demonstrates the wrapping + * modes, if the texture coordinates fall outside 0.0 and 1.0. + * Interaction: Pressing the 's' and 'S' keys switch the + * wrapping between clamping and repeating for the s parameter. + * The 't' and 'T' keys control the wrapping for the t parameter. + * + * If running this program on OpenGL 1.0, texture objects are + * not used. + */ +#include +#include +#include + +/* Create checkerboard texture */ +#define checkImageWidth 64 +#define checkImageHeight 64 +static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; + +#ifdef GL_VERSION_1_1 +static GLuint texName; +#endif + +void makeCheckImage(void) +{ + int i, j, c; + + for (i = 0; i < checkImageHeight; i++) { + for (j = 0; j < checkImageWidth; j++) { + c = ((((i&0x8)==0)^((j&0x8))==0))*255; + checkImage[i][j][0] = (GLubyte) c; + checkImage[i][j][1] = (GLubyte) c; + checkImage[i][j][2] = (GLubyte) c; + checkImage[i][j][3] = (GLubyte) 255; + } + } +} + +void init(void) +{ + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + makeCheckImage(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + +#ifdef GL_VERSION_1_1 + glGenTextures(1, &texName); + glBindTexture(GL_TEXTURE_2D, texName); +#endif + + 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); +#ifdef GL_VERSION_1_1 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); +#else + glTexImage2D(GL_TEXTURE_2D, 0, 4, checkImageWidth, checkImageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); +#endif +} + +void display(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); +#ifdef GL_VERSION_1_1 + glBindTexture(GL_TEXTURE_2D, texName); +#endif + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, 3.0); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(3.0, 3.0); glVertex3f(0.0, 1.0, 0.0); + glTexCoord2f(3.0, 0.0); glVertex3f(0.0, -1.0, 0.0); + + glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); + glTexCoord2f(0.0, 3.0); glVertex3f(1.0, 1.0, 0.0); + glTexCoord2f(3.0, 3.0); glVertex3f(2.41421, 1.0, -1.41421); + glTexCoord2f(3.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421); + glEnd(); + glFlush(); + glDisable(GL_TEXTURE_2D); +} + +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, -3.6); +} + +/* ARGSUSED1 */ +void keyboard (unsigned char key, int x, int y) +{ + switch (key) { + case 's': + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glutPostRedisplay(); + break; + case 'S': + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glutPostRedisplay(); + break; + case 't': + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glutPostRedisplay(); + break; + case 'T': + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + 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(250, 250); + glutInitWindowPosition(100, 100); + glutCreateWindow(argv[0]); + init(); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/Imakefile b/progs/samples/Imakefile new file mode 100644 index 0000000000..457493214b --- /dev/null +++ b/progs/samples/Imakefile @@ -0,0 +1,102 @@ +LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\glut.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a + +INCLUDES = -I$(TOP)\include + +SRCS = accum.c \ + bitmap1.c \ + bitmap2.c \ + blendeq.c \ + blendxor.c \ + copy.c \ + cursor.c \ + depth.c \ + eval.c \ + fog.c \ + font.c \ + line.c \ + logo.c \ + nurb.c \ + oglinfo.c \ + olympic.c \ + overlay.c \ + point.c \ + prim.c \ + quad.c \ + select.c \ + shape.c \ + speed.c \ + sphere.c \ + star.c \ + stencil.c \ + stretch.c \ + texture.c \ + tri.c \ + wave.c + +PROGRAMS = ProgramTargetName(accum) \ + ProgramTargetName(bitmap1) \ + ProgramTargetName(bitmap2) \ + ProgramTargetName(blendeq) \ + ProgramTargetName(blendxor) \ + ProgramTargetName(copy) \ + ProgramTargetName(cursor) \ + ProgramTargetName(depth) \ + ProgramTargetName(eval) \ + ProgramTargetName(fog) \ + ProgramTargetName(font) \ + ProgramTargetName(line) \ + ProgramTargetName(logo) \ + ProgramTargetName(nurb) \ + ProgramTargetName(oglinfo) \ + ProgramTargetName(olympic) \ + ProgramTargetName(overlay) \ + ProgramTargetName(point) \ + ProgramTargetName(prim) \ + ProgramTargetName(quad) \ + ProgramTargetName(select) \ + ProgramTargetName(shape) \ + ProgramTargetName(speed) \ + ProgramTargetName(sphere) \ + ProgramTargetName(star) \ + ProgramTargetName(stencil) \ + ProgramTargetName(stretch) \ + ProgramTargetName(texture) \ + ProgramTargetName(tri) \ + ProgramTargetName(wave) + +AllTarget($(PROGRAMS)) + +NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(bitmap1,bitmap1.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(bitmap2,bitmap2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(blendeq,blendeq.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(blendxor,blendxor.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(copy,copy.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(cursor,cursor.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(depth,depth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(eval,eval.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(line,line.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(logo,logo.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(nurb,nurb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(oglinfo,oglinfo.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(olympic,olympic.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(overlay,overlay.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(point,point.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(prim,prim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(quad,quad.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(shape,shape.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(speed,speed.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(star,star.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(stretch,stretch.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(texture,texture.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(tri,tri.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) +NormalProgramTarget(wave,wave.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) + +DependTarget() + + diff --git a/progs/samples/Makefile.BeOS-R4 b/progs/samples/Makefile.BeOS-R4 new file mode 100644 index 0000000000..2e1e804cca --- /dev/null +++ b/progs/samples/Makefile.BeOS-R4 @@ -0,0 +1,64 @@ +# $Id: Makefile.BeOS-R4,v 1.1 1999/08/19 00:55:41 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1999 Brian Paul +# +# This file is in the public domain. + + +# Makefile for sample programs for BeOS R4 + + + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -L/boot/home/config/lib -Xlinker -rpath $(LIBDIR) -lbe -lglut -lMesaGLU -lMesaGL $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = accum bitmap1 bitmap2 blendeq blendxor copy cursor depth eval fog \ + font line logo olympic overlay point prim select \ + shape sphere star stencil stretch texture tri wave + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config + diff --git a/progs/samples/Makefile.DJ b/progs/samples/Makefile.DJ new file mode 100644 index 0000000000..5c43b7db68 --- /dev/null +++ b/progs/samples/Makefile.DJ @@ -0,0 +1,36 @@ +# $Id: Makefile.DJ,v 1.1 1999/08/19 00:55:41 jtg Exp $ + +# Makefile for sample programs for MS-DOS with DJGPP + +##### MACROS ##### + +INCDIR = ../include + +GL_LIBS = ../lib/dosglut.a ../lib/dosglub.a ../lib/dosmesa.a + +LIB_DEP = $(GL_LIBS) + +PROGS = accum bitmap1 bitmap2 blendeq blendxor copy depth \ + eval fog font line logo nurb olympic \ + point prim quad select shape \ + sphere star stencil stretch texture \ + tri wave + +##### RULES ##### + +.c: $(LIB_DEP) + gcc -I$(INCDIR) $(CFLAGS) $< $(LIB_DEP) -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + +clean: + del *. + +realclean: clean + del *.exe + + + diff --git a/progs/samples/Makefile.X11 b/progs/samples/Makefile.X11 new file mode 100644 index 0000000000..e2393e8a41 --- /dev/null +++ b/progs/samples/Makefile.X11 @@ -0,0 +1,61 @@ +# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:41 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1999 Brian Paul + + +# Makefile for assorted SGI OpenGL demos + + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = accum bitmap1 bitmap2 blendeq blendxor copy cursor depth eval fog \ + font line logo nurb oglinfo olympic overlay point prim quad select \ + shape sphere star stencil stretch texture tri wave + + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + ./$$prog; \ + echo ; \ + done + + +include ../Make-config diff --git a/progs/samples/Makefile.dja b/progs/samples/Makefile.dja new file mode 100644 index 0000000000..f2d5382968 --- /dev/null +++ b/progs/samples/Makefile.dja @@ -0,0 +1,26 @@ +# $Id: Makefile.dja,v 1.1 1999/08/19 00:55:41 jtg Exp $ + +# Makefile for sample programs for MS-DOS with DJGPP and ALLEGRO + + + +INCDIR = ../include +LIBDIR = ../lib +include ../common.dja + + _PROGS = accum bitmap1 bitmap2 blendeq blendxor copy cursor depth \ + eval fog font line logo nurb oglinfo olympic overlay point \ + prim quad select shape sphere star stencil stretch texture \ + tri wave + + PROGS = $(_PROGS:=.exe) + + +default: $(PROGS) + +clean: + del *. + +realclean: clean + del *.exe + diff --git a/progs/samples/README b/progs/samples/README new file mode 100644 index 0000000000..853158873c --- /dev/null +++ b/progs/samples/README @@ -0,0 +1,520 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +accum - Accumulation test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit + 1 Use filled polygon mode. + 2 Use outlined polygon mode. + +bitmap1 - Bitmap test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + +bitmap2 - Bitmap test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + 1 Toggle display list mode. + 2 Toggle color animation mode. + +copy - Pixel copy test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -f RGB image file. + - keys: + ESC Quit. + Z Increase zoom factor. + z Decrease zoom factor. + - mouse input: + Left Copy location. + +cursor - Cursor test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + SPACE switch cursor color. + +depth - Z buffer test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + 1 Toggle anti-aliased mode. + 2 Toggle stipple mode. + +eval - Evaluator test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + UP Rotate. + DOWN Rotate. + 1 Toggle dimensions. + 2 Toggle dimensions. + e Use eval mode. + m Use mesh mode. + f Toggle polygon mode. + p Toggle point mode. + c Toggle color mode. + t Toggle texture mode. + l Toggle lighting mode. + +fog - Fog test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + UP Rotate. + DOWN Rotate. + D Increase fog density. + d Decrease fog density. + +font - font test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + Left Shift left. + Right Shift right. + Up Shift up. + Down Shift down. + n Shift in. + m Shift out. + q Scale up x. + w Scale down x. + a Scale up y. + s Scale down y. + z Scale up z. + x Scale down z. + e Rotate clockwise x. + r Rotate counter-clockwise x. + d Rotate clockwise y. + f Rotate counter-clockwise y. + c Rotate clockwise z. + v Rotate counter-clockwise z. + +line - Line test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + W Increase line width. + w Decrease line width. + 1 Toggle stipple mode. + 2 Toggle anti-aliased mode. + +logo - Demo. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate + UP Move clipping plane. + DOWN Move clipping plane. + Z Translate. + z Translate. + 1 Use GL_POINT polygon mode. + 2 Use GL_LINE polygon mode. + 3 Use GL_FILL polygon mode. + p Toggle polygon fill modes. + 4 Use GL_NICEST for GL_POLYGON_SMOOTH_HINT. + 5 Use anti-aliased polygon mode. + 6 Use aliased polygon mode. + 8 Toggle dither mode. + 9 Toggle stipple polygon mode. + 0 Toggle flat/smooth shading mode. + q Disable cull mode. + w Use front face cull mode. + e Use back face cull mode. + r Use clockwise front face mode. + t Use counter-clockwise front face mode. + y Use MSB first stipple pattern. + u Use LSB first stipple pattern. + a Use brick texture map. + s Use checker texture map. + d Disable texture map. + f Use decal texture environment mode. + g Use modulate texture environment mode. + +nurb - Nurb test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + UP Rotate. + DOWN Rotate. + +olympic - Olymipic rings demo. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + SPACE Restart demo. + +overlay - Overlay plane demo. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + SPACE Toggle star weird movement mode. + t Toggle star turbo mode. + +point - Point test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Translate. + RIGHT Translate. + UP Translate. + DOWN Translate. + W Increase point width. + w Decrease point width. + 1 Toggle anti-aliased mode. + +prim - Primitive test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + 1 Toggle flat/smooth shade mode. + 2 Toggle outlined/filled polygon mode. + 3 Toggle color mask mode. + +quad - Quadric test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -f texture file. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + UP Rotate. + DOWN Rotate. + X Rotate. + x Rotate. + 1 Use GLU_FILL draw style. + 2 Use GLU_POINT draw style. + 3 Use GLU_LINE draw style. + 4 Use GLU_SILHOUETTE draw style. + 0 Toggle flat/smooth shade mode. + f Cylce through quadrics. + d Toggle orientation. + A Increase number of stacks. + a Decrease number of stacks. + S Increase number of slices. + s Decrease number of slices. + G Increase radius1. + g Decrease radius1. + J Increase radius2. + j Decrease radius2. + H Increase height. + h Decrease height. + K Increase angle1. + k Decrease angle1. + L Increase angle2. + l Decrease angle2. + z Toggle texture mode. + q Disable cull mode. + w Use front face cull mode. + e Use back face cull mode. + r Use clockwise front face mode. + t Use counter-clockwise front face mode. + y Toggle dither mode. + +select - Selection test. + - RGBA, SB. + - cmd line options: + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + Z Increase zoom factor. + z Decrease zoom factor. + d Zoom at current mouse location. + f Print feedback information. + l Toggle outlined/filled polygon mode. + - mouse: + Left Recolor selected triangle. + Center Enlarge selected triangle. + Right Delete selected triangle. + +shape - shape test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + Left Shift left. + Right Shift right. + Up Shift up. + Down Shift down. + n Shift in. + m Shift out. + q Scale up x. + w Scale down x. + a Scale up y. + s Scale down y. + z Scale up z. + x Scale down z. + e Rotate clockwise x. + r Rotate counter-clockwise x. + d Rotate clockwise y. + f Rotate counter-clockwise y. + c Rotate clockwise z. + v Rotate counter-clockwise z. + SPACE switch shapes. + +speed - Speed test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + a Toggle anti-aliased mode. + d Toggle z buffering mode. + f Toggle fog mode. + F Toggle fog hint mode. + s Toggle flat/smooth shading mode. + t Toggle texturing mode. + +sphere - Spheremap test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -f texture file. + -3 Use RGB components. + -4 Use RGBA components. + - keys: + ESC Quit. + LEFT Rotate about the y axis. + RIGHT Rotate about the y axis. + UP Rotate about the x axis. + DOWN Rotate about the x axis. + a Toggle auto rotate mode. + c toggle between cylinder or cube object. + t Use torus object. + d Use decal texture mode. + m Use modulate texture mode. + l Toggle lighted mode. + f Toggle fog mode. + 0 Use nearest magification filter. + 1 Use linear magification. + 2 Use nearest minification filter. + 3 Use linear minification filter. + 4 Use nearest-mipmap-nearest minification filter. + 5 Use nearest-mipmap-linear minification filter. + 6 Use linear-mipmap-nearest minification filter. + 7 Use linear-mipmap-linear minification filter. + +star - Demo. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + SPACE Toggle weird movement mode. + t Toggle turbo mode. + +stencil - Stencil test. + - RGBA, SB. + - cmd line options: + +stretch - Texture test. + - RGBA, SB. + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -f texture file. + - keys: + ESC Quit. + SPACE Start animation. + - mouse: + Left Added stretch point. + +texture - Texture test. + - RGBA, SB/DB (SB default). + - cmd line options: + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -f texture file. + - keys: + ESC Quit. + LEFT Rotate. + RIGHT Rotate. + UP Rotate. + DOWN Rotate. + T Translate. + t Translate. + s Toggle sphere map mode. + 0 Use nearest magification filter. + 1 Use linear magification filter. + 2 Use nearest minification filter. + 3 Use linear minification filter. + 4 Use nearest-mipmap-nearest minification filter. + 5 Use nearest-mipmap-linear minification filter. + 6 Use linear-mipmap-nearest minification filter. + 7 Use linear-mipmap-linear minification filter. + +tri - Triangle test. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + - keys: + ESC Quit. + LEFT Translate. + RIGHT Translate. + Z Increase zoom factor. + z Decrease zoom factor. + 1 Use point polygon mode. + 2 Use line polygon mode. + 3 Use filled polygon mode. + 4 Use point primitive. + 5 Use line-loop primitive. + 6 Use polygon primitive. + 7 Toggle cull mode. + 8 Use clockwise/counter-clockwise front face mode. + 9 Toggle front/back face cull mode. + v Toggle show verticies mode. + s Toggle flat/smooth shade mode. + h Toggle hide bottom triangle mode. + o Toggle outline mode. + m Toggle dither mode. + 0 Toggle anti-aliased mode. + +wave - Demo. + - RGBA/CI (RGBA default), SB/DB (SB default). + - cmd line options: + -rgb RGBA mode. + -ci Color index mode. + -sb Single buffer mode. + -db Double buffer mode. + -dr Direct render mode. + -ir Indirect render mode. + -grid Number of grids. + -size Size of grid. + -wave Height of wave (floating point number). + -frames Number of frames. + - keys: + ESC Quit. + c Toggle contouring mode. + s Toggle flat/smooth shade mode. + l Toggle lighting mode. + d Toggle depth checking mode. + SPACE Toggle step/animation mode. + n Single step in step mode. + a Toggle spin mode. diff --git a/progs/samples/accum.c b/progs/samples/accum.c new file mode 100644 index 0000000000..24dfc07d2a --- /dev/null +++ b/progs/samples/accum.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +#include +#include +#include +#include + + +GLenum doubleBuffer; +GLint thing1, thing2; + + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearAccum(0.0, 0.0, 0.0, 0.0); + + thing1 = glGenLists(1); + glNewList(thing1, GL_COMPILE); + glColor3f(1.0, 0.0, 0.0); + glRectf(-1.0, -1.0, 1.0, 0.0); + glEndList(); + + thing2 = glGenLists(1); + glNewList(thing2, GL_COMPILE); + glColor3f(0.0, 1.0, 0.0); + glRectf(0.0, -1.0, 1.0, 1.0); + glEndList(); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(1); + case '1': + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + break; + case '2': + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glPushMatrix(); + + glScalef(0.8, 0.8, 1.0); + + glClear(GL_COLOR_BUFFER_BIT); + glCallList(thing1); + glAccum(GL_LOAD, 0.5); + + glClear(GL_COLOR_BUFFER_BIT); + glCallList(thing2); + glAccum(GL_ACCUM, 0.5); + + glAccum(GL_RETURN, 1.0); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); + glutInitWindowSize( 300, 300); + + type = GLUT_RGB | GLUT_ACCUM; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Accum Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/bitmap1.c b/progs/samples/bitmap1.c new file mode 100644 index 0000000000..517d584e21 --- /dev/null +++ b/progs/samples/bitmap1.c @@ -0,0 +1,250 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define OPENGL_WIDTH 24 +#define OPENGL_HEIGHT 13 + + +GLenum rgb, doubleBuffer, windType; + +float boxA[3] = { + 0, 0, 0 +}; +float boxB[3] = { + -100, 0, 0 +}; +float boxC[3] = { + 100, 0, 0 +}; +float boxD[3] = { + 0, 95, 0 +}; +float boxE[3] = { + 0, -105, 0 +}; +GLubyte OpenGL_bits1[] = { + 0x00, 0x03, 0x00, + 0x7f, 0xfb, 0xff, + 0x7f, 0xfb, 0xff, + 0x00, 0x03, 0x00, + 0x3e, 0x8f, 0xb7, + 0x63, 0xdb, 0xb0, + 0x63, 0xdb, 0xb7, + 0x63, 0xdb, 0xb6, + 0x63, 0x8f, 0xf3, + 0x63, 0x00, 0x00, + 0x63, 0x00, 0x00, + 0x63, 0x00, 0x00, + 0x3e, 0x00, 0x00, +}; +GLubyte OpenGL_bits2[] = { + 0x00, 0x00, 0x00, + 0xff, 0xff, 0x01, + 0xff, 0xff, 0x01, + 0x00, 0x00, 0x00, + 0xf9, 0xfc, 0x01, + 0x8d, 0x0d, 0x00, + 0x8d, 0x0d, 0x00, + 0x8d, 0x0d, 0x00, + 0xcc, 0x0d, 0x00, + 0x0c, 0x4c, 0x0a, + 0x0c, 0x4c, 0x0e, + 0x8c, 0xed, 0x0e, + 0xf8, 0x0c, 0x00, +}; +GLubyte logo_bits[] = { + 0x00, 0x66, 0x66, + 0xff, 0x66, 0x66, + 0x00, 0x00, 0x00, + 0xff, 0x3c, 0x3c, + 0x00, 0x42, 0x40, + 0xff, 0x42, 0x40, + 0x00, 0x41, 0x40, + 0xff, 0x21, 0x20, + 0x00, 0x2f, 0x20, + 0xff, 0x20, 0x20, + 0x00, 0x10, 0x90, + 0xff, 0x10, 0x90, + 0x00, 0x0f, 0x10, + 0xff, 0x00, 0x00, + 0x00, 0x66, 0x66, + 0xff, 0x66, 0x66, +}; + +#include "tkmap.c" + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + } +} + +static void Draw(void) +{ + float mapI[2], mapIA[2], mapIR[2]; + + glClear(GL_COLOR_BUFFER_BIT); + + mapI[0] = 0.0; + mapI[1] = 1.0; + mapIR[0] = 0.0; + mapIR[1] = 0.0; + mapIA[0] = 1.0; + mapIA[1] = 1.0; + + glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR); + glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI); + glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI); + glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA); + glPixelTransferi(GL_MAP_COLOR, GL_TRUE); + + SetColor(COLOR_WHITE); + glRasterPos3fv(boxA); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 24); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 2); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + SetColor(COLOR_WHITE); + glRasterPos3fv(boxB); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits1); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits2); + + SetColor(COLOR_YELLOW); + glRasterPos3fv(boxC); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits1); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits2); + + SetColor(COLOR_CYAN); + glRasterPos3fv(boxD); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits1); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits2); + + SetColor(COLOR_RED); + glRasterPos3fv(boxE); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits1); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0, + OpenGL_bits2); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Bitmap Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/bitmap2.c b/progs/samples/bitmap2.c new file mode 100644 index 0000000000..5faac84162 --- /dev/null +++ b/progs/samples/bitmap2.c @@ -0,0 +1,787 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ +#include +#include +#include +#include + + +#define EXP_WIDTH 80 +#define EXP_HEIGHT 80 + + +GLenum rgb, doubleBuffer, windType; + +#include "tkmap.c" + +GLenum useLists, abuse; +GLubyte exp_bits[7][800] = { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x81, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xbe, 0x7c, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf6, 0x4f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xde, 0x7d, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xea, 0xef, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0x55, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xdd, 0xfd, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xbf, 0xae, 0x22, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xdb, 0xf7, 0x3f, 0x1e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x50, 0xbf, 0xbf, 0x85, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xe5, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xee, 0x7e, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x74, 0x4b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xe8, 0x3e, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x49, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x54, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x91, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0xf1, 0x53, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x97, 0x5c, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xa0, 0x0c, 0x8c, 0x1b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc4, 0x01, 0x00, 0xc8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x88, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x00, 0x02, 0x40, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x70, 0x00, 0x0c, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x70, 0xe0, 0x0d, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x72, 0xc8, 0x07, 0x40, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x02, 0x78, 0x2f, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x02, 0xb0, 0x0a, 0x20, 0x77, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x13, 0x10, 0x33, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x02, 0x78, 0xbb, 0x81, 0x09, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0xdc, 0xe7, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xac, 0x78, 0x00, 0x31, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x03, 0x74, 0x4b, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x02, 0xe8, 0x3e, 0x00, 0x01, 0x10, 0x00, + 0x00, 0x00, 0x80, 0x00, 0xf8, 0x49, 0x80, 0x09, 0x1c, 0x00, + 0x00, 0x00, 0x00, 0x0c, 0x40, 0x07, 0x00, 0x05, 0x1c, 0x00, + 0x00, 0x00, 0x80, 0x09, 0x04, 0x80, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x1d, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xe3, 0x0b, 0x00, 0x22, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x8f, 0x10, 0x00, 0xa0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x4f, 0x20, 0x78, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x80, 0x79, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x7c, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0xc0, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x84, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x60, 0x06, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x07, 0x64, 0x3a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x08, 0x72, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3b, 0x00, 0x00, 0xc0, 0x33, 0x00, 0x00, + 0x00, 0x00, 0xa0, 0x1b, 0x00, 0x00, 0x80, 0x42, 0x00, 0x00, + 0x00, 0x00, 0xd0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, + 0x00, 0x30, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x80, 0x03, 0x03, 0x80, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0xe2, 0x82, 0x03, 0x00, 0x20, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x0e, 0x80, 0x03, 0x00, 0x4c, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x0e, 0x80, 0x03, 0xec, 0x10, 0x00, 0x00, 0x60, 0x00, + 0x00, 0x12, 0x00, 0x00, 0x05, 0x93, 0x01, 0x00, 0x20, 0x00, + 0x00, 0x12, 0x00, 0x00, 0x00, 0x5c, 0x0c, 0x00, 0x60, 0x00, + 0x00, 0x30, 0x00, 0xc0, 0x05, 0x81, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x2c, 0x00, 0x00, 0xcc, 0x06, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x28, 0x20, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x80, 0x80, 0x22, 0x00, 0x02, 0x00, 0x00, 0x02, + 0x00, 0x20, 0x00, 0x80, 0x02, 0x20, 0x08, 0x00, 0x20, 0x02, + 0x00, 0x38, 0x00, 0x00, 0x00, 0x11, 0x28, 0x00, 0x20, 0x06, + 0x00, 0x20, 0x00, 0x80, 0x0e, 0xc0, 0x21, 0x00, 0x5c, 0x00, + 0x00, 0x24, 0x00, 0x90, 0x40, 0x58, 0x04, 0x00, 0x20, 0x01, + 0x00, 0x24, 0x00, 0x10, 0x22, 0x02, 0x05, 0x00, 0x20, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x28, 0xb6, 0x00, 0x00, 0x20, 0x01, + 0x00, 0x70, 0x00, 0x00, 0x18, 0xc1, 0x00, 0x00, 0xc0, 0x01, + 0x00, 0xc0, 0x00, 0x00, 0x40, 0x83, 0x04, 0x00, 0xc0, 0x01, + 0x00, 0x00, 0x01, 0x80, 0xfc, 0x41, 0x02, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x03, 0x30, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x10, 0x02, 0x00, 0x40, 0x1d, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x30, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x81, 0x0f, 0x00, 0x00, 0x2a, 0x00, + 0x00, 0x00, 0xf8, 0x02, 0x80, 0x0f, 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0xf8, 0x02, 0x80, 0x0f, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x06, 0xc0, 0x01, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x14, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x70, 0x00, 0x00, 0x85, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x00, 0x30, 0x00, 0x20, 0x3c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xe0, 0x80, 0x00, 0x0b, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0x79, 0x83, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x19, 0x22, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x28, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0x03, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x02, 0x90, 0x00, 0x00, 0x00, 0x40, + 0x02, 0x02, 0x00, 0x80, 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x20, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30, 0x28, 0x90, 0x05, 0x00, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x48, 0x05, 0x00, 0x21, 0x00, 0x00, 0x0c, + 0x00, 0x00, 0x00, 0x84, 0x00, 0x54, 0x05, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x40, 0x05, 0x80, 0x41, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0e, 0x02, 0x01, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x08, 0x20, 0x20, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x84, 0x82, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x48, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, + 0x04, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x21, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x90, 0x40, 0x40, 0x04, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x41, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x40, 0xa0, 0x00, 0x00, 0x00, 0x50, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x40, + 0x40, 0x00, 0x00, 0x00, 0x40, 0x02, 0x04, 0x00, 0x00, 0x30, + 0x00, 0x00, 0x00, 0x80, 0x84, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc2, 0x20, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0xc0, 0x05, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x02, 0x00, 0x00, 0x10, + 0x08, 0x00, 0x00, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x08, + 0x10, 0x02, 0x00, 0x00, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x08, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3a, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x40, 0x04, + 0x00, 0x60, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x00, 0xb8, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x08, 0x00, 0x00, + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1f, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x01, 0x00, 0x01, 0x10, 0x04, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x02, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1c, 0x20, 0x05, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0xc4, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x40, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x42, 0x00, 0x00, 0x04, 0x20, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x05, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x81, 0x07, 0x01, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x02, 0x80, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x40, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x0d, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, + 0x02, 0x02, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, + 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + } +}; +GLint exp_lists[7]; + + +static void Init(void) +{ + GLint i; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); + + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + for (i = 0; i < 7; i++) { + exp_lists[i] = glGenLists(1); + glNewList(exp_lists[i], GL_COMPILE); + glBitmap(80, 80, 40.0, 40.0, 0.0, 0.0, exp_bits[i]); + glEndList(); + } + + abuse = GL_FALSE; + useLists = GL_TRUE; +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + useLists = !useLists; + break; + case '2': + abuse = !abuse; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + GLint i, j; + + glClear(GL_COLOR_BUFFER_BIT); + + for (i = 0; i < 7; i++) { + for (j = 0; j < 40; j++) { + switch (j % 7) { + case 0: + SetColor(COLOR_YELLOW); + break; + case 1: + SetColor(COLOR_GREEN); + break; + case 2: + SetColor(COLOR_BLUE); + break; + case 3: + SetColor(COLOR_MAGENTA); + break; + case 4: + SetColor(COLOR_CYAN); + break; + case 5: + SetColor(COLOR_WHITE); + break; + case 6: + SetColor(COLOR_RED); + break; + } + glRasterPos3i((j*3)%5, (j*3)%8, 0); + + if (useLists) { + glCallList(exp_lists[i]); + } else { + glBitmap(80, 80, 40.0, 40.0, 0.0, 0.0, exp_bits[i]); + } + if (!abuse) { + break; + } + } + + if (i == 6) { + break; + } + + for (j = 0; j < 40; j++) { + SetColor(COLOR_BLACK); + glRasterPos3i((j*3)%5, (j*3)%8, 0); + if (useLists) { + glCallList(exp_lists[i]); + } else { + glBitmap(80, 80, 40.0, 40.0, 0.0, 0.0, exp_bits[i]); + } + if (!abuse) { + break; + } + } + } + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Bitmap Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/blendeq.c b/progs/samples/blendeq.c new file mode 100644 index 0000000000..7be52073ab --- /dev/null +++ b/progs/samples/blendeq.c @@ -0,0 +1,295 @@ +/* +** blendeq.c - Demonstrates the use of the blend_minmax, blend_subtract, +** and blend_logic_op extensions using glBlendEquationEXT. +** +** Over a two-color backround, draw rectangles using twelve blend +** options. The values are read back as UNSIGNED_BYTE and printed +** in hex over each value. These values are useful for logic +** op comparisons when channels are 8 bits deep. +*/ + +#include +#include +#include +#include + + +GLenum doubleBuffer; +static int dithering = 0; +static int doPrint = 1; +static int deltaY; +GLint windW, windH; + +static void DrawString(const char *string) +{ + int i; + + for (i = 0; string[i]; i++) + glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]); +} + +static void Init(void) +{ + + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glViewport(0, 0, (GLint)width, (GLint)height); + deltaY = windH /16; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, windW, 0, windH); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'd': + dithering = !dithering; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void PrintColorStrings( void ) +{ + GLubyte ubbuf[3]; + int i, xleft, xright; + char colorString[18]; + + xleft = 5 + windW/4; + xright = 5 + windW/2; + + for (i = windH - deltaY + 4; i > 0; i-=deltaY) { + glReadPixels(xleft, i+10, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, ubbuf); + sprintf(colorString, "(0x%x, 0x%x, 0x%x)", + ubbuf[0], ubbuf[1], ubbuf[2]); + glRasterPos2f(xleft, i); + DrawString(colorString); + glReadPixels(xright, i+10, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, ubbuf); + sprintf(colorString, "(0x%x, 0x%x, 0x%x)", + ubbuf[0], ubbuf[1], ubbuf[2]); + glRasterPos2f(xright, i); + DrawString(colorString); + } +} + +static void Draw(void) +{ + int stringOffset = 5, stringx = 8; + int x1, x2, xleft, xright; + int i; + + (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); + glDisable(GL_BLEND); + + glClearColor(0.5, 0.6, 0.1, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* Draw background */ + glColor3f(0.1, 0.1, 1.0); + glRectf(0.0, 0.0, windW/2, windH); + + /* Draw labels */ + glColor3f(0.8, 0.8, 0.0); + i = windH - deltaY + stringOffset; + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("SOURCE"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("DEST"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("min"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("max"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("subtract"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("reverse_subtract"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("clear"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("set"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("copy"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("noop"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("and"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("invert"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("or"); + glRasterPos2f(stringx, i); i -= deltaY; + DrawString("xor"); + + + i = windH - deltaY; + x1 = windW/4; + x2 = 3 * windW/4; + xleft = 5 + windW/4; + xright = 5 + windW/2; + + /* Draw foreground color for comparison */ + glColor3f(0.9, 0.2, 0.8); + glRectf(x1, i, x2, i+deltaY); + + /* Leave one rectangle of background color */ + + /* Begin test cases */ + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + + i -= 2*deltaY; + glBlendEquationEXT(GL_MIN_EXT); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_MAX_EXT); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_FUNC_SUBTRACT_EXT); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT); + glRectf(x1, i, x2, i+deltaY); + + glBlendFunc(GL_ONE, GL_ZERO); + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_CLEAR); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_SET); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_COPY); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_NOOP); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_AND); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_INVERT); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_OR); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_XOR); + glRectf(x1, i, x2, i+deltaY); + glRectf(x1, i+10, x2, i+5); + + if (doPrint) { + glDisable(GL_BLEND); + glColor3f(1.0, 1.0, 1.0); + PrintColorStrings(); + } + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } + +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + char *s; + char *extName1 = "GL_EXT_blend_logic_op"; + char *extName2 = "GL_EXT_blend_minmax"; + char *extName3 = "GL_EXT_blend_subtract"; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Blend Equation") == GL_FALSE) { + exit(1); + } + + /* Make sure blend_logic_op extension is there. */ + s = (char *) glGetString(GL_EXTENSIONS); + if (!s) + exit(1); + if (strstr(s,extName1) == 0) { + printf("Blend_logic_op extension is not present.\n"); + exit(1); + } + if (strstr(s,extName2) == 0) { + printf("Blend_minmax extension is not present.\n"); + exit(1); + } + if (strstr(s,extName3) == 0) { + printf("Blend_subtract extension is not present.\n"); + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/blendxor.c b/progs/samples/blendxor.c new file mode 100644 index 0000000000..a46920d234 --- /dev/null +++ b/progs/samples/blendxor.c @@ -0,0 +1,174 @@ +/* +** blendxor.c - Demonstrates the use of the blend_logic_op +** extension to draw hilights. Using XOR to draw the same +** image twice restores the background to its original value. +*/ + +#include +#include +#ifndef _WIN32 +#include +#endif +#include +#include + + +GLenum doubleBuffer; +int dithering = 0; +GLint windW, windH; + +static void Init(void) +{ + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, 400, 0, 400); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'd': + dithering = !dithering; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + int i; + + glDisable(GL_BLEND); + + (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); + + glClearColor(0.5, 0.6, 0.1, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* Draw background prims */ + glColor3f(0.1, 0.1, 1.0); + glBegin(GL_TRIANGLES); + glVertex2i(5, 5); + glVertex2i(130, 50); + glVertex2i(100, 300); + glEnd(); + glColor3f(0.5, 0.2, 0.9); + glBegin(GL_TRIANGLES); + glVertex2i(200, 100); + glVertex2i(330, 50); + glVertex2i(340, 400); + glEnd(); + + glEnable(GL_BLEND); + glBlendEquationEXT(GL_LOGIC_OP); + glLogicOp(GL_XOR); + + /* Draw a set of rectangles across the window */ + glColor3f(0.9, 0.2, 0.8); + for(i = 0; i < 400; i+=60) { + glBegin(GL_POLYGON); + glVertex2i(i, 100); + glVertex2i(i+50, 100); + glVertex2i(i+50, 200); + glVertex2i(i, 200); + glEnd(); + } + glFlush(); /* Added by Brian Paul */ +#ifndef _WIN32 + sleep(2); +#endif + + /* Redraw the rectangles, which should erase them */ + for(i = 0; i < 400; i+=60) { + glBegin(GL_POLYGON); + glVertex2i(i, 100); + glVertex2i(i+50, 100); + glVertex2i(i+50, 200); + glVertex2i(i, 200); + glEnd(); + } + glFlush(); + + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + char *s; + char *extName = "GL_EXT_blend_logic_op"; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Blend XOR") == GL_FALSE) { + exit(1); + } + + /* Make sure blend_logic_op extension is there. */ + s = (char *) glGetString(GL_EXTENSIONS); + if (!s) + exit(1); + if (strstr(s,extName) == 0) { + printf("Blend_logic_op extension is not present.\n"); + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/copy.c b/progs/samples/copy.c new file mode 100644 index 0000000000..391c637d6f --- /dev/null +++ b/progs/samples/copy.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#include "loadppm.c" + +GLenum doubleBuffer; +GLint windW, windH; + +char *fileName = 0; +PPMImage *image; +float point[3]; +float zoom; +GLint x, y; + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + + x = 0; + y = windH; + zoom = 1.8; +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glViewport(0, 0, windW, windH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, windW, 0, windH); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'Z': + zoom += 0.2; + break; + case 'z': + zoom -= 0.2; + if (zoom < 0.2) { + zoom = 0.2; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Mouse(int button, int state, int mouseX, int mouseY) +{ + if (state != GLUT_DOWN) + return; + x = (GLint)mouseX; + y = (GLint)mouseY; + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + point[0] = (windW / 2) - (image->sizeX / 2); + point[1] = (windH / 2) - (image->sizeY / 2); + point[2] = 0; + glRasterPos3fv(point); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelZoom(1.0, 1.0); + glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, + image->data); + + point[0] = (float)x; + point[1] = windH - (float)y; + point[2] = 0.0; + glRasterPos3fv(point); + + glPixelZoom(zoom, zoom); + glCopyPixels((windW/2)-(image->sizeX/2), + (windH/2)-(image->sizeY/2), + image->sizeX, image->sizeY, GL_COLOR); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-f") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-f (No file name).\n"); + return GL_FALSE; + } else { + fileName = argv[++i]; + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + if (fileName == 0) { + printf("No image file.\n"); + exit(1); + } + + image = LoadPPM(fileName); + + windW = 300; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Copy Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutMouseFunc(Mouse); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/cursor.c b/progs/samples/cursor.c new file mode 100644 index 0000000000..de8fc58556 --- /dev/null +++ b/progs/samples/cursor.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +GLenum rgb, doubleBuffer, windType; +int windX, windY; +int cursor; + + +#include "tkmap.c" + +static void Init(void) +{ + cursor = 0; + glutSetCursor(cursor); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); +} + +static void Reshape(int width, int height) +{ + + windX = width; + windY = height; + glViewport(0, 0, windX, windY); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, windX, 0, windY); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 32: + cursor++; + if (cursor > 19) { + cursor = 0; + } + glutSetCursor(cursor); + } +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_POLYGON); + SetColor(COLOR_BLACK); + glVertex2i(0, 0); + SetColor(COLOR_RED); + glVertex2i(windX, 0); + SetColor(COLOR_GREEN); + glVertex2i(windX, windY); + SetColor(COLOR_BLUE); + glVertex2i(0, windY); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windX = 300; + windY = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windX, windY); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Cursor Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/depth.c b/progs/samples/depth.c new file mode 100644 index 0000000000..afe2ec17a3 --- /dev/null +++ b/progs/samples/depth.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum rgb, doubleBuffer; + +GLenum antiAlias, stipple; +GLubyte stippleBits[32*4] = { + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, + 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, +}; + + +#include "tkmap.c" + +static void Init(void) +{ + GLint i; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); + + if (!rgb) { + for (i = 0; i < 16; i++) { + glutSetColor(i+CI_OFFSET_1, 0.0, 0.0, i/15.0); + glutSetColor(i+CI_OFFSET_2, 0.0, i/15.0, 0.0); + } + } + + glPolygonStipple(stippleBits); + + antiAlias = GL_FALSE; + stipple = GL_FALSE; +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + antiAlias = !antiAlias; + break; + case '2': + stipple = !stipple; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + GLint ci1, ci2; + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + if (antiAlias) { + ci1 = CI_OFFSET_1; + ci2 = CI_OFFSET_2; + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glEnable(GL_BLEND); + glEnable(GL_POLYGON_SMOOTH); + glDisable(GL_DEPTH_TEST); + } else { + ci1 = COLOR_BLUE; + ci2 = COLOR_GREEN; + glDisable(GL_BLEND); + glDisable(GL_POLYGON_SMOOTH); + glEnable(GL_DEPTH_TEST); + } + + if (stipple) { + glEnable(GL_POLYGON_STIPPLE); + } else { + glDisable(GL_POLYGON_STIPPLE); + } + + glBegin(GL_TRIANGLES); + (rgb) ? glColor3fv(RGBMap[COLOR_BLUE]) : glIndexi(ci1); + glVertex3f( 0.9, -0.9, -30.0); + glVertex3f( 0.9, 0.9, -30.0); + glVertex3f(-0.9, 0.0, -30.0); + (rgb) ? glColor3fv(RGBMap[COLOR_GREEN]) : glIndexi(ci2); + glVertex3f(-0.9, -0.9, -40.0); + glVertex3f(-0.9, 0.9, -40.0); + glVertex3f( 0.9, 0.0, -25.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Depth Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/eval.c b/progs/samples/eval.c new file mode 100644 index 0000000000..3ad9c5468f --- /dev/null +++ b/progs/samples/eval.c @@ -0,0 +1,472 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +#define VORDER 10 +#define CORDER 10 +#define TORDER 3 + +#define VMAJOR_ORDER 2 +#define VMINOR_ORDER 3 + +#define CMAJOR_ORDER 2 +#define CMINOR_ORDER 2 + +#define TMAJOR_ORDER 2 +#define TMINOR_ORDER 2 + +#define VDIM 4 +#define CDIM 4 +#define TDIM 2 + +#define ONE_D 1 +#define TWO_D 2 + +#define EVAL 3 +#define MESH 4 + + +GLenum doubleBuffer; + +float rotX = 0.0, rotY = 0.0, translateZ = -1.0; + +GLenum arrayType = ONE_D; +GLenum colorType = GL_FALSE; +GLenum textureType = GL_FALSE; +GLenum polygonFilled = GL_FALSE; +GLenum lighting = GL_FALSE; +GLenum mapPoint = GL_FALSE; +GLenum mapType = EVAL; + +double point1[10*4] = { + -0.5, 0.0, 0.0, 1.0, + -0.4, 0.5, 0.0, 1.0, + -0.3,-0.5, 0.0, 1.0, + -0.2, 0.5, 0.0, 1.0, + -0.1,-0.5, 0.0, 1.0, + 0.0, 0.5, 0.0, 1.0, + 0.1,-0.5, 0.0, 1.0, + 0.2, 0.5, 0.0, 1.0, + 0.3,-0.5, 0.0, 1.0, + 0.4, 0.0, 0.0, 1.0, +}; +double cpoint1[10*4] = { + 0.0, 0.0, 1.0, 1.0, + 0.3, 0.0, 0.7, 1.0, + 0.6, 0.0, 0.3, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.3, 0.0, 1.0, + 1.0, 0.6, 0.0, 1.0, + 1.0, 1.0, 0.0, 1.0, + 1.0, 1.0, 0.5, 1.0, + 1.0, 1.0, 1.0, 1.0, +}; +double tpoint1[11*4] = { + 0.0, 0.0, 0.0, 1.0, + 0.0, 0.1, 0.0, 1.0, + 0.0, 0.2, 0.0, 1.0, + 0.0, 0.3, 0.0, 1.0, + 0.0, 0.4, 0.0, 1.0, + 0.0, 0.5, 0.0, 1.0, + 0.0, 0.6, 0.0, 1.0, + 0.0, 0.7, 0.0, 1.0, + 0.0, 0.8, 0.0, 1.0, + 0.0, 0.9, 0.0, 1.0, +}; +double point2[2*3*4] = { + -0.5, -0.5, 0.5, 1.0, + 0.0, 1.0, 0.5, 1.0, + 0.5, -0.5, 0.5, 1.0, + -0.5, 0.5, -0.5, 1.0, + 0.0, -1.0, -0.5, 1.0, + 0.5, 0.5, -0.5, 1.0, +}; +double cpoint2[2*2*4] = { + 0.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 1.0, 1.0, + 0.0, 1.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 1.0, +}; +double tpoint2[2*2*2] = { + 0.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 1.0, 1.0, +}; +float textureImage[4*2*4] = { + 1.0, 1.0, 1.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 1.0, +}; + + +static void Init(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {1.0, 1.0, 1.0, 1.0}; + static float position[] = {0.0, 0.0, -150.0, 0.0}; + static float front_mat_diffuse[] = {1.0, 0.2, 1.0, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + static float decal[] = {GL_DECAL}; + static float repeat[] = {GL_REPEAT}; + static float nr[] = {GL_NEAREST}; + + glFrontFace(GL_CCW); + + glEnable(GL_DEPTH_TEST); + + glMap1d(GL_MAP1_VERTEX_4, 0.0, 1.0, VDIM, VORDER, point1); + glMap1d(GL_MAP1_COLOR_4, 0.0, 1.0, CDIM, CORDER, cpoint1); + + glMap2d(GL_MAP2_VERTEX_4, 0.0, 1.0, VMINOR_ORDER*VDIM, VMAJOR_ORDER, 0.0, + 1.0, VDIM, VMINOR_ORDER, point2); + glMap2d(GL_MAP2_COLOR_4, 0.0, 1.0, CMINOR_ORDER*CDIM, CMAJOR_ORDER, 0.0, + 1.0, CDIM, CMINOR_ORDER, cpoint2); + glMap2d(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, TMINOR_ORDER*TDIM, + TMAJOR_ORDER, 0.0, 1.0, TDIM, TMINOR_ORDER, tpoint2); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nr); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nr); + glTexImage2D(GL_TEXTURE_2D, 0, 4, 2, 4, 0, GL_RGBA, GL_FLOAT, + (GLvoid *)textureImage); +} + +static void DrawPoints1(void) +{ + GLint i; + + glColor3f(0.0, 1.0, 0.0); + glPointSize(2); + glBegin(GL_POINTS); + for (i = 0; i < VORDER; i++) { + glVertex4dv(&point1[i*4]); + } + glEnd(); +} + +static void DrawPoints2(void) +{ + GLint i, j; + + glColor3f(1.0, 0.0, 1.0); + glPointSize(2); + glBegin(GL_POINTS); + for (i = 0; i < VMAJOR_ORDER; i++) { + for (j = 0; j < VMINOR_ORDER; j++) { + glVertex4dv(&point2[i*4*VMINOR_ORDER+j*4]); + } + } + glEnd(); +} + +static void DrawMapEval1(float du) +{ + float u; + + glColor3f(1.0, 0.0, 0.0); + glBegin(GL_LINE_STRIP); + for (u = 0.0; u < 1.0; u += du) { + glEvalCoord1d(u); + } + glEvalCoord1d(1.0); + glEnd(); +} + +static void DrawMapEval2(float du, float dv) +{ + float u, v, tmp; + + glColor3f(1.0, 0.0, 0.0); + for (v = 0.0; v < 1.0; v += dv) { + glBegin(GL_QUAD_STRIP); + for (u = 0.0; u <= 1.0; u += du) { + glEvalCoord2d(u,v); + tmp = (v + dv < 1.0) ? (v + dv) : 1.0; + glEvalCoord2d(u, tmp); + } + glEvalCoord2d(1.0, v); + glEvalCoord2d(1.0, v+dv); + glEnd(); + } +} + +static void RenderEval(void) +{ + + if (colorType) { + glEnable(GL_MAP1_COLOR_4); + glEnable(GL_MAP2_COLOR_4); + } else { + glDisable(GL_MAP1_COLOR_4); + glDisable(GL_MAP2_COLOR_4); + } + + if (textureType) { + glEnable(GL_TEXTURE_2D); + glEnable(GL_MAP2_TEXTURE_COORD_2); + } else { + glDisable(GL_TEXTURE_2D); + glDisable(GL_MAP2_TEXTURE_COORD_2); + } + + if (polygonFilled) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + + glShadeModel(GL_SMOOTH); + + switch (mapType) { + case EVAL: + switch (arrayType) { + case ONE_D: + glDisable(GL_MAP2_VERTEX_4); + glEnable(GL_MAP1_VERTEX_4); + DrawPoints1(); + DrawMapEval1(0.1/VORDER); + break; + case TWO_D: + glDisable(GL_MAP1_VERTEX_4); + glEnable(GL_MAP2_VERTEX_4); + DrawPoints2(); + DrawMapEval2(0.1/VMAJOR_ORDER,0.1/VMINOR_ORDER); + break; + default: + break; + } + break; + case MESH: + switch (arrayType) { + case ONE_D: + DrawPoints1(); + glDisable(GL_MAP2_VERTEX_4); + glEnable (GL_MAP1_VERTEX_4); + glColor3f(0.0, 0.0, 1.0); + glMapGrid1d(40, 0.0, 1.0); + if (mapPoint) { + glPointSize(2); + glEvalMesh1(GL_POINT, 0, 40); + } else { + glEvalMesh1(GL_LINE, 0, 40); + } + break; + case TWO_D: + DrawPoints2(); + glDisable(GL_MAP1_VERTEX_4); + glEnable(GL_MAP2_VERTEX_4); + glColor3f(0.0, 0.0, 1.0); + glMapGrid2d(20, 0.0, 1.0, 20, 0.0, 1.0); + if (mapPoint) { + glPointSize(2); + glEvalMesh2(GL_POINT, 0, 20, 0, 20); + } else if (polygonFilled) { + glEvalMesh2(GL_FILL, 0, 20, 0, 20); + } else { + glEvalMesh2(GL_LINE, 0, 20, 0, 20); + } + break; + default: + break; + } + break; + default: + break; + } +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + switch (key) { + case GLUT_KEY_LEFT: + rotY -= 30; + break; + case GLUT_KEY_RIGHT: + rotY += 30; + break; + case GLUT_KEY_UP: + rotX -= 30; + break; + case GLUT_KEY_DOWN: + rotX += 30; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(1); + case '1': + arrayType = ONE_D; + break; + case '2': + arrayType = TWO_D; + break; + case 'e': + mapType = EVAL; + break; + case 'm': + mapType = MESH; + break; + case 'f': + polygonFilled = !polygonFilled; + break; + case 'p': + mapPoint = !mapPoint; + break; + case 'c': + colorType = !colorType; + break; + case 't': + textureType = !textureType; + break; + case 'l': + lighting =! lighting; + if (lighting) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_AUTO_NORMAL); + } else { + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_AUTO_NORMAL); + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glTranslatef(0.0, 0.0 , translateZ); + glRotatef(rotX, 1, 0, 0); + glRotatef(rotY, 0, 1, 0); + RenderEval(); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB | GLUT_DEPTH; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Evaluator Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/fog.c b/progs/samples/fog.c new file mode 100644 index 0000000000..96534dddcb --- /dev/null +++ b/progs/samples/fog.c @@ -0,0 +1,311 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +GLenum rgb, doubleBuffer; + +#include "tkmap.c" + +double plane[4] = { + 1.0, 0.0, -1.0, 0.0 +}; +float rotX = 5.0, rotY = -5.0, zTranslate = -65.0; +float fogDensity = 0.02; +GLint cubeList = 1; + +float scp[18][3] = { + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 5.000000 + }, + { + 0.707107, 0.707107, 0.000000 + }, + { + 0.707107, 0.707107, 5.000000 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + 0.000000, 1.000000, 5.000000 + }, + { + -0.707107, 0.707107, 0.000000 + }, + { + -0.707107, 0.707107, 5.000000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -1.000000, 0.000000, 5.000000 + }, + { + -0.707107, -0.707107, 0.000000 + }, + { + -0.707107, -0.707107, 5.000000 + }, + { + 0.000000, -1.000000, 0.000000 + }, + { + 0.000000, -1.000000, 5.000000 + }, + { + 0.707107, -0.707107, 0.000000 + }, + { + 0.707107, -0.707107, 5.000000 + }, + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 5.000000 + }, +}; + + +static void Build_lists(void) +{ + + glNewList(cubeList, GL_COMPILE); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(scp[0]); glVertex3fv(scp[0]); + glNormal3fv(scp[0]); glVertex3fv(scp[1]); + glNormal3fv(scp[2]); glVertex3fv(scp[2]); + glNormal3fv(scp[2]); glVertex3fv(scp[3]); + glNormal3fv(scp[4]); glVertex3fv(scp[4]); + glNormal3fv(scp[4]); glVertex3fv(scp[5]); + glNormal3fv(scp[6]); glVertex3fv(scp[6]); + glNormal3fv(scp[6]); glVertex3fv(scp[7]); + glNormal3fv(scp[8]); glVertex3fv(scp[8]); + glNormal3fv(scp[8]); glVertex3fv(scp[9]); + glNormal3fv(scp[10]); glVertex3fv(scp[10]); + glNormal3fv(scp[10]); glVertex3fv(scp[11]); + glNormal3fv(scp[12]); glVertex3fv(scp[12]); + glNormal3fv(scp[12]); glVertex3fv(scp[13]); + glNormal3fv(scp[14]); glVertex3fv(scp[14]); + glNormal3fv(scp[14]); glVertex3fv(scp[15]); + glNormal3fv(scp[16]); glVertex3fv(scp[16]); + glNormal3fv(scp[16]); glVertex3fv(scp[17]); + glEnd(); + glEndList(); +} + +static void Init(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {1.0, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 0.0, 0.0}; + static float front_mat_shininess[] = {30.0}; + static float front_mat_specular[] = {0.0, 0.0, 0.0, 1.0}; + static float front_mat_diffuse[] = {0.0, 1.0, 0.0, 1.0}; + static float back_mat_shininess[] = {50.0}; + static float back_mat_specular[] = {0.0, 0.0, 1.0, 1.0}; + static float back_mat_diffuse[] = {1.0, 0.0, 0.0, 1.0}; + static float lmodel_ambient[] = {0.0, 0.0, 0.0, 1.0}; + static float fog_color[] = {0.8, 0.8, 0.8, 1.0}; + + glFrontFace(GL_CW); + + glEnable(GL_DEPTH_TEST); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP); + glFogf(GL_FOG_DENSITY, fogDensity); + if (rgb) { + glFogfv(GL_FOG_COLOR, fog_color); + glClearColor(0.8, 0.8, 0.8, 1.0); + } else { + glFogi(GL_FOG_INDEX, 1<<5); + SetFogRamp(5, 3); + glClearIndex(128); + } + + Build_lists(); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, 1.0, 1.0, 200.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_UP: + rotX -= 5; + break; + case GLUT_KEY_DOWN: + rotX += 5; + break; + case GLUT_KEY_LEFT: + rotY -= 5; + break; + case GLUT_KEY_RIGHT: + rotY += 5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'D': + if (rgb) { + fogDensity *= 1.10; + glFogf(GL_FOG_DENSITY, fogDensity); + } + break; + case 'd': + if (rgb) { + fogDensity /= 1.10; + glFogf(GL_FOG_DENSITY, fogDensity); + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glTranslatef(0, 0, zTranslate); + glRotatef(rotY, 0,1,0); + glRotatef(rotX, 1,0,0); + glScalef(1.0, 1.0, 10.0); + + glCallList(cubeList); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Fog Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/font.c b/progs/samples/font.c new file mode 100644 index 0000000000..a0091a65d7 --- /dev/null +++ b/progs/samples/font.c @@ -0,0 +1,273 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define OPENGL_WIDTH 24 +#define OPENGL_HEIGHT 13 + + +char string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"; +GLenum rgb, doubleBuffer, windType; +float angleX = 0.0, angleY = 0.0, angleZ = 0.0; +float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0; +float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0; + + +#include "tkmap.c" + + +static void DrawBitmapString(void *font, const char *string) +{ + int i; + + for (i = 0; string[i]; i++) + glutBitmapCharacter(font, string[i]); +} + +static void DrawStrokeString(void *font, const char *string) +{ + int i; + + for (i = 0; string[i]; i++) + glutStrokeCharacter(font, string[i]); +} + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + shiftX -= 20.0; + break; + case GLUT_KEY_RIGHT: + shiftX += 20.0; + break; + case GLUT_KEY_UP: + shiftY += 20.0; + break; + case GLUT_KEY_DOWN: + shiftY -= 20.0; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + + case 'n': + shiftZ += 20.0; + break; + case 'm': + shiftZ -= 20.0; + break; + + case 'q': + scaleX -= 0.1; + if (scaleX < 0.1) { + scaleX = 0.1; + } + break; + case 'w': + scaleX += 0.1; + break; + case 'a': + scaleY -= 0.1; + if (scaleY < 0.1) { + scaleY = 0.1; + } + break; + case 's': + scaleY += 0.1; + break; + case 'z': + scaleZ -= 0.1; + if (scaleZ < 0.1) { + scaleZ = 0.1; + } + break; + case 'x': + scaleZ += 0.1; + break; + + case 'e': + angleX -= 5.0; + if (angleX < 0.0) { + angleX = 360.0 + angleX; + } + break; + case 'r': + angleX += 5.0; + if (angleX > 360.0) { + angleX = angleX - 360.0; + } + break; + case 'd': + angleY -= 5.0; + if (angleY < 0.0) { + angleY = 360.0 + angleY; + } + break; + case 'f': + angleY += 5.0; + if (angleY > 360.0) { + angleY = angleY - 360.0; + } + break; + case 'c': + angleZ -= 5.0; + if (angleZ < 0.0) { + angleZ = 360.0 + angleZ; + } + break; + case 'v': + angleZ += 5.0; + if (angleZ > 360.0) { + angleZ = angleZ - 360.0; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + SetColor(COLOR_WHITE); + + glPushMatrix(); + + glTranslatef(shiftX, shiftY, shiftZ); + glRotatef(angleX, 1.0, 0.0, 0.0); + glRotatef(angleY, 0.0, 1.0, 0.0); + glRotatef(angleZ, 0.0, 0.0, 1.0); + glScalef(scaleX, scaleY, scaleZ); + + glPushMatrix(); + glRasterPos2f(-390.5, 0.5); + DrawBitmapString(GLUT_BITMAP_9_BY_15, string); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-390.5, -30.5, 0.0); + DrawStrokeString(GLUT_STROKE_ROMAN, string); + glPopMatrix(); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Font Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/line.c b/progs/samples/line.c new file mode 100644 index 0000000000..59e1d62192 --- /dev/null +++ b/progs/samples/line.c @@ -0,0 +1,219 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_OFFSET 16 + + +GLenum rgb, doubleBuffer, windType; + +GLenum mode1, mode2; +GLint size; +float pntA[3] = { + -160.0, 0.0, 0.0 +}; +float pntB[3] = { + -130.0, 0.0, 0.0 +}; +float pntC[3] = { + -40.0, -50.0, 0.0 +}; +float pntD[3] = { + 30.0, 60.0, 0.0 +}; + + +#include "tkmap.c" + +static void Init(void) +{ + GLint i; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glLineStipple(1, 0xF0E0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + if (!rgb) { + for (i = 0; i < 16; i++) { + glutSetColor(i+CI_OFFSET, i/15.0, i/15.0, 0.0); + } + } + + mode1 = GL_FALSE; + mode2 = GL_FALSE; + size = 1; +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + mode1 = !mode1; + break; + case '2': + mode2 = !mode2; + break; + case 'W': + size++; + break; + case 'w': + size--; + if (size < 1) { + size = 1; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + GLint ci, i; + + glClear(GL_COLOR_BUFFER_BIT); + + glLineWidth(size); + + if (mode1) { + glEnable(GL_LINE_STIPPLE); + } else { + glDisable(GL_LINE_STIPPLE); + } + + if (mode2) { + ci = CI_OFFSET; + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + } else { + ci = COLOR_YELLOW; + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glPushMatrix(); + + glShadeModel( GL_FLAT ); + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0,0,1); + + (rgb) ? glColor3f(1.0, 1.0, 0.0) : glIndexi(ci); + glBegin(GL_LINE_STRIP); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glPointSize(1); + + SetColor(COLOR_GREEN); + glBegin(GL_POINTS); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + } + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Line Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/loadppm.c b/progs/samples/loadppm.c new file mode 100644 index 0000000000..bf7c8dd1e8 --- /dev/null +++ b/progs/samples/loadppm.c @@ -0,0 +1,72 @@ + +typedef struct { + int sizeX, sizeY; + GLubyte *data; +} PPMImage; + +static PPMImage *LoadPPM(const char *filename) +{ + char buff[16]; + PPMImage *result; + FILE *fp; + int maxval; + + fp = fopen(filename, "rb"); + if (!fp) + { + fprintf(stderr, "Unable to open file `%s'\n", filename); + exit(1); + } + + if (!fgets(buff, sizeof(buff), fp)) + { + perror(filename); + exit(1); + } + + if (buff[0] != 'P' || buff[1] != '6') + { + fprintf(stderr, "Invalid image format (must be `P6')\n"); + exit(1); + } + + result = malloc(sizeof(PPMImage)); + if (!result) + { + fprintf(stderr, "Unable to allocate memory\n"); + exit(1); + } + + if (fscanf(fp, "%d %d", &result->sizeX, &result->sizeY) != 2) + { + fprintf(stderr, "Error loading image `%s'\n", filename); + exit(1); + } + + if (fscanf(fp, "%d", &maxval) != 1) + { + fprintf(stderr, "Error loading image `%s'\n", filename); + exit(1); + } + + while (fgetc(fp) != '\n') + ; + + result->data = malloc(3 * result->sizeX * result->sizeY); + if (!result) + { + fprintf(stderr, "Unable to allocate memory\n"); + exit(1); + } + + if (fread(result->data, 3 * result->sizeX, result->sizeY, fp) != result->sizeY) + { + fprintf(stderr, "Error loading image `%s'\n", filename); + exit(1); + } + + fclose(fp); + + return result; +} + diff --git a/progs/samples/logo.c b/progs/samples/logo.c new file mode 100644 index 0000000000..8f7de45b00 --- /dev/null +++ b/progs/samples/logo.c @@ -0,0 +1,1630 @@ +/* $Id: logo.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */ + +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define PI 3.141592654 + +#define BLACK 0 +#define GRAY 128 +#define WHITE 255 +#define BL 0x00 +#define WH 0xFF +#define RD 0xA4,0x00,0x00,0xFF +#define WT 0xFF,0xFF,0xFF,0xFF + +#define CHECKIMAGEWIDTH 8 +#define CHECKIMAGEHEIGHT 8 +#define BRICKIMAGEWIDTH 16 +#define BRICKIMAGEHEIGHT 16 + + +GLenum rgb, doubleBuffer; + +#include "tkmap.c" + +float black[3] = {0.0, 0.0, 0.0}; +float white[3] = {1.0, 1.0, 1.0}; +float gray[3] = {0.5, 0.5, 0.5}; +float blue[3] = {0.0, 0.0, 1.0}; +GLint colorIndexes[3] = {0, 200, 255}; + +GLenum polyMode; +GLboolean dithering; +GLboolean shade; +GLboolean doStipple; +GLboolean noDraw = 0; +GLboolean LineSmooth = GL_FALSE; + +double plane[4] = {1.0, 0.0, -1.0, 0.0}; +float xRotation = 30.0, yRotation = 30.0; +float zTranslation = -15.0; + +GLint singleCylinder; +GLint doubleCylinder; +GLint elbow, logo; + +GLubyte checkImage[3*CHECKIMAGEWIDTH*CHECKIMAGEHEIGHT] = { + BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, + WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, + WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, + BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, + WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, + WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, + BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, + WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, + WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, + BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, + WH, WH, BL, BL, BL, WH, WH, WH, WH, WH, WH, BL, BL, BL, WH, WH, + WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, WH, WH, WH, BL, BL, BL, +}; +GLubyte brickImage[4*BRICKIMAGEWIDTH*BRICKIMAGEHEIGHT] = { + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD +}; + +GLubyte *image = checkImage; +GLint imageHeight = CHECKIMAGEHEIGHT; +GLint imageWidth = CHECKIMAGEWIDTH; + +float decal[] = { + GL_DECAL, +}; +float modulate[] = { + GL_MODULATE, +}; +float repeat[] = { + GL_REPEAT, +}; +float nearest[] = { + GL_NEAREST, +}; + +GLubyte stipple[4*32] = { + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + 0x00, 0x0F, 0xF0, 0x00, + + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + +float tscp[18][2] = { + { + 0.0, 0.0 + }, + { + 1.0, 0.0 + }, + { + 0.0, 0.125 + }, + { + 1.0, 0.125 + }, + { + 0.0, 0.250 + }, + { + 1.0, 0.25 + }, + { + 0.0, 0.375 + }, + { + 1.0, 0.375 + }, + { + 0.0, 0.50 + }, + { + 1.0, 0.50 + }, + { + 0.0, 0.625 + }, + { + 1.0, 0.625 + }, + { + 0.0, 0.75 + }, + { + 1.0, 0.75 + }, + { + 0.0, 0.875 + }, + { + 1.0, 0.875 + }, + { + 0.0, 1.0 + }, + { + 1.0, 1.0 + } +}; +float scp[18][3] = { + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 5.000000 + }, + { + 0.707107, 0.707107, 0.000000 + }, + { + 0.707107, 0.707107, 5.000000 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + 0.000000, 1.000000, 5.000000 + }, + { + -0.707107, 0.707107, 0.000000 + }, + { + -0.707107, 0.707107, 5.000000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -1.000000, 0.000000, 5.000000 + }, + { + -0.707107, -0.707107, 0.000000 + }, + { + -0.707107, -0.707107, 5.000000 + }, + { + 0.000000, -1.000000, 0.000000 + }, + { + 0.000000, -1.000000, 5.000000 + }, + { + 0.707107, -0.707107, 0.000000 + }, + { + 0.707107, -0.707107, 5.000000 + }, + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 5.000000 + } +}; +float dcp[18][3] = { + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 7.000000 + }, + { + 0.707107, 0.707107, 0.000000 + }, + { + 0.707107, 0.707107, 7.000000 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + 0.000000, 1.000000, 7.000000 + }, + { + -0.707107, 0.707107, 0.000000 + }, + { + -0.707107, 0.707107, 7.000000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -1.000000, 0.000000, 7.000000 + }, + { + -0.707107, -0.707107, 0.000000 + }, + { + -0.707107, -0.707107, 7.000000 + }, + { + 0.000000, -1.000000, 0.000000 + }, + { + 0.000000, -1.000000, 7.000000 + }, + { + 0.707107, -0.707107, 0.000000 + }, + { + 0.707107, -0.707107, 7.000000 + }, + { + 1.000000, 0.000000, 0.000000 + }, + { + 1.000000, 0.000000, 7.000000 + } +}; +float ep[7][9][3] = { + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.707107, 0.000000 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.707107, 0.000000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.707107, 0.000000 + }, + { + 0.000000, -1.000000, 0.000000 + }, + { + 0.707107, -0.707107, 0.000000 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.034074, 0.258819 + }, + { + 0.707107, 0.717087, 0.075806 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.717087, 0.075806 + }, + { + -1.000000, 0.034074, 0.258819 + }, + { + -0.707107, -0.648939, 0.441832 + }, + { + 0.000000, -0.931852, 0.517638 + }, + { + 0.707107, -0.648939, 0.441832 + }, + { + 1.000000, 0.034074, 0.258819 + } + }, + { + { + 1.000000, 0.133975, 0.500000 + }, + { + 0.707107, 0.746347, 0.146447 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.746347, 0.146447 + }, + { + -1.000000, 0.133975, 0.500000 + }, + { + -0.707107, -0.478398, 0.853553 + }, + { + 0.000000, -0.732051, 1.000000 + }, + { + 0.707107, -0.478398, 0.853553 + }, + { + 1.000000, 0.133975, 0.500000 + } + }, + { + { + 1.000000, 0.292893, 0.707107 + }, + { + 0.707107, 0.792893, 0.207107 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.792893, 0.207107 + }, + { + -1.000000, 0.292893, 0.707107 + }, + { + -0.707107, -0.207107, 1.207107 + }, + { + 0.000000, -0.414214, 1.414214 + }, + { + 0.707107, -0.207107, 1.207107 + }, + { + 1.000000, 0.292893, 0.707107 + } + }, + { + { + 1.000000, 0.500000, 0.866025 + }, + { + 0.707107, 0.853553, 0.253653 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.853553, 0.253653 + }, + { + -1.000000, 0.500000, 0.866025 + }, + { + -0.707107, 0.146447, 1.478398 + }, + { + 0.000000, 0.000000, 1.732051 + }, + { + 0.707107, 0.146447, 1.478398 + }, + { + 1.000000, 0.500000, 0.866025 + } + }, + { + { + 1.000000, 0.741181, 0.965926 + }, + { + 0.707107, 0.924194, 0.282913 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.924194, 0.282913 + }, + { + -1.000000, 0.741181, 0.965926 + }, + { + -0.707107, 0.558168, 1.648939 + }, + { + 0.000000, 0.482362, 1.931852 + }, + { + 0.707107, 0.558168, 1.648939 + }, + { + 1.000000, 0.741181, 0.965926 + } + }, + { + { + 1.000000, 1.000000, 1.000000 + }, + { + 0.707107, 1.000000, 0.292893 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 1.000000, 0.292893 + }, + { + -1.000000, 1.000000, 1.000000 + }, + { + -0.707107, 1.000000, 1.707107 + }, + { + 0.000000, 1.000000, 2.000000 + }, + { + 0.707107, 1.000000, 1.707107 + }, + { + 1.000000, 1.000000, 1.000000 + } + } +}; +float en[7][9][3] = { + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.707107, 0.000000 + }, + { + 0.000000, 1.000000, 0.000000 + }, + { + -0.707107, 0.707107, 0.000000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.707107, 0.000000 + }, + { + 0.000000, -1.000000, 0.000000 + }, + { + 0.707107, -0.707107, 0.000000 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.683013, -0.183013 + }, + { + 0.000000, 0.965926, -0.258819 + }, + { + -0.707107, 0.683013, -0.183013 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.683013, 0.183013 + }, + { + 0.000000, -0.965926, 0.258819 + }, + { + 0.707107, -0.683013, 0.183013 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.612372, -0.353553 + }, + { + 0.000000, 0.866025, -0.500000 + }, + { + -0.707107, 0.612372, -0.353553 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.612372, 0.353553 + }, + { + 0.000000, -0.866025, 0.500000 + }, + { + 0.707107, -0.612372, 0.353553 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + /* These 3 lines added by BEP */ + 0.707107, 0.500000, -0.500000 + }, + { + 0.000000, 0.707107, -0.707107 + }, + { + -0.707107, 0.500000, -0.500000 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.500000, 0.500000 + }, + { + 0.000000, -0.707107, 0.707107 + }, + { + 0.707107, -0.500000, 0.500000 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.353553, -0.612372 + }, + { + 0.000000, 0.500000, -0.866025 + }, + { + -0.707107, 0.353553, -0.612372 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.353553, 0.612372 + }, + { + 0.000000, -0.500000, 0.866025 + }, + { + 0.707107, -0.353553, 0.612372 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.183013, -0.683013 + }, + { + 0.000000, 0.258819, -0.965926 + }, + { + -0.707107, 0.183013, -0.683013 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, -0.183013, 0.683013 + }, + { + 0.000000, -0.258819, 0.965926 + }, + { + 0.707107, -0.183013, 0.683013 + }, + { + 1.000000, 0.000000, 0.000000 + } + }, + { + { + 1.000000, 0.000000, 0.000000 + }, + { + 0.707107, 0.000000, -0.707107 + }, + { + 0.000000, 0.000000, -1.000000 + }, + { + -0.707107, 0.000000, -0.707107 + }, + { + -1.000000, 0.000000, 0.000000 + }, + { + -0.707107, 0.000000, 0.707107 + }, + { + 0.000000, 0.000000, 1.000000 + }, + { + 0.707107, 0.000000, 0.707107 + }, + { + 1.000000, 0.000000, 0.000000 + } + } +}; +float tep[7][9][2] = { + { + { + 0, 0.0 + }, + { + 0.125, 0.0 + }, + { + 0.25, 0.0 + }, + { + 0.375, 0.0 + }, + { + 0.5, 0.0 + }, + { + 0.625, 0.0 + }, + { + 0.75, 0.0 + }, + { + 0.875, 0.0 + }, + { + 1.0, 0.0 + } + }, + { + { + 0, 0.16667 + }, + { + 0.125, 0.16667 + }, + { + 0.25, 0.16667 + }, + { + 0.375, 0.16667 + }, + { + 0.5, 0.16667 + }, + { + 0.625, 0.16667 + }, + { + 0.75, 0.16667 + }, + { + 0.875, 0.16667 + }, + { + 1.0, 0.16667 + } + }, + { + { + 0, 0.33333 + }, + { + 0.125, 0.33333 + }, + { + 0.25, 0.33333 + }, + { + 0.375, 0.33333 + }, + { + 0.5, 0.33333 + }, + { + 0.625, 0.33333 + }, + { + 0.75, 0.33333 + }, + { + 0.875, 0.33333 + }, + { + 1.0, 0.33333 + } + }, + { + { + 0, 0.5 + }, + { + 0.125, 0.5 + }, + { + 0.25, 0.5 + }, + { + 0.375, 0.5 + }, + { + 0.5, 0.5 + }, + { + 0.625, 0.5 + }, + { + 0.75, 0.5 + }, + { + 0.875, 0.5 + }, + { + 1.0, 0.5 + } + }, + { + { + 0, 0.6667 + }, + { + 0.125, 0.6667 + }, + { + 0.25, 0.6667 + }, + { + 0.375, 0.6667 + }, + { + 0.5, 0.6667 + }, + { + 0.625, 0.6667 + }, + { + 0.75, 0.6667 + }, + { + 0.875, 0.6667 + }, + { + 1.0, 0.6667 + } + }, + { + { + 0, 0.83333 + }, + { + 0.125, 0.83333 + }, + { + 0.25, 0.83333 + }, + { + 0.375, 0.83333 + }, + { + 0.5, 0.83333 + }, + { + 0.625, 0.83333 + }, + { + 0.75, 0.83333 + }, + { + 0.875, 0.83333 + }, + { + 1.0, 0.83333 + } + }, + { + { + 0, 1.0 + }, + { + 0.125, 1.0 + }, + { + 0.25, 1.0 + }, + { + 0.375, 1.0 + }, + { + 0.5, 1.0 + }, + { + 0.625, 1.0 + }, + { + 0.75, 1.0 + }, + { + 0.875, 1.0 + }, + { + 1.0, 1.0 + } + } +}; + + +static void SetUpAntiAliasedGrayScale(void) +{ + float color; + GLint i, j; + + for (i = 0; i < 16; i++) { + color = (2 * i + 1) / 32.0; + for (j = 0; j < 16; j++) { + glutSetColor(i*16+j, color*j/15.0, color*j/15.0, color*j/15.0); + } + } +} + +static void BendForward(void) +{ + + glTranslatef(0.0, 1.0, 0.0); + glRotatef(90.0, 1, 0, 0); + glTranslatef(0.0, -1.0, 0.0); +} + +static void BendLeft(void) +{ + + glRotatef(-90.0, 0, 0, 1); + glTranslatef(0.0, 1.0, 0.0); + glRotatef(90.0, 1, 0, 0); + glTranslatef(0.0, -1.0, 0.0); +} + +static void BendRight(void) +{ + + glRotatef(90.0, 0, 0, 1); + glTranslatef(0.0, 1.0, 0.0); + glRotatef(90.0, 1, 0, 0); + glTranslatef(0.0, -1.0, 0.0); +} + +static void BuildSingleCylinder(void) +{ + + glNewList(singleCylinder, GL_COMPILE); + + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(scp[0]); glTexCoord2fv(tscp[0]); glVertex3fv(scp[0]); + glNormal3fv(scp[0]); glTexCoord2fv(tscp[1]); glVertex3fv(scp[1]); + glNormal3fv(scp[2]); glTexCoord2fv(tscp[2]); glVertex3fv(scp[2]); + glNormal3fv(scp[2]); glTexCoord2fv(tscp[3]); glVertex3fv(scp[3]); + glNormal3fv(scp[4]); glTexCoord2fv(tscp[4]); glVertex3fv(scp[4]); + glNormal3fv(scp[4]); glTexCoord2fv(tscp[5]); glVertex3fv(scp[5]); + glNormal3fv(scp[6]); glTexCoord2fv(tscp[6]); glVertex3fv(scp[6]); + glNormal3fv(scp[6]); glTexCoord2fv(tscp[7]); glVertex3fv(scp[7]); + glNormal3fv(scp[8]); glTexCoord2fv(tscp[8]); glVertex3fv(scp[8]); + glNormal3fv(scp[8]); glTexCoord2fv(tscp[9]); glVertex3fv(scp[9]); + glNormal3fv(scp[10]); glTexCoord2fv(tscp[10]); glVertex3fv(scp[10]); + glNormal3fv(scp[10]); glTexCoord2fv(tscp[11]); glVertex3fv(scp[11]); + glNormal3fv(scp[12]); glTexCoord2fv(tscp[12]); glVertex3fv(scp[12]); + glNormal3fv(scp[12]); glTexCoord2fv(tscp[13]); glVertex3fv(scp[13]); + glNormal3fv(scp[14]); glTexCoord2fv(tscp[14]); glVertex3fv(scp[14]); + glNormal3fv(scp[14]); glTexCoord2fv(tscp[15]); glVertex3fv(scp[15]); + glNormal3fv(scp[16]); glTexCoord2fv(tscp[16]); glVertex3fv(scp[16]); + glNormal3fv(scp[16]); glTexCoord2fv(tscp[17]); glVertex3fv(scp[17]); + glEnd(); + + glEndList(); +} + +static void BuildDoubleCylinder(void) +{ + + glNewList(doubleCylinder, GL_COMPILE); + + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(dcp[0]); glTexCoord2fv(tscp[0]); glVertex3fv(dcp[0]); + glNormal3fv(dcp[0]); glTexCoord2fv(tscp[1]); glVertex3fv(dcp[1]); + glNormal3fv(dcp[2]); glTexCoord2fv(tscp[2]); glVertex3fv(dcp[2]); + glNormal3fv(dcp[2]); glTexCoord2fv(tscp[3]); glVertex3fv(dcp[3]); + glNormal3fv(dcp[4]); glTexCoord2fv(tscp[4]); glVertex3fv(dcp[4]); + glNormal3fv(dcp[4]); glTexCoord2fv(tscp[5]); glVertex3fv(dcp[5]); + glNormal3fv(dcp[6]); glTexCoord2fv(tscp[6]); glVertex3fv(dcp[6]); + glNormal3fv(dcp[6]); glTexCoord2fv(tscp[7]); glVertex3fv(dcp[7]); + glNormal3fv(dcp[8]); glTexCoord2fv(tscp[8]); glVertex3fv(dcp[8]); + glNormal3fv(dcp[8]); glTexCoord2fv(tscp[9]); glVertex3fv(dcp[9]); + glNormal3fv(dcp[10]); glTexCoord2fv(tscp[10]); glVertex3fv(dcp[10]); + glNormal3fv(dcp[10]); glTexCoord2fv(tscp[11]); glVertex3fv(dcp[11]); + glNormal3fv(dcp[12]); glTexCoord2fv(tscp[12]); glVertex3fv(dcp[12]); + glNormal3fv(dcp[12]); glTexCoord2fv(tscp[13]); glVertex3fv(dcp[13]); + glNormal3fv(dcp[14]); glTexCoord2fv(tscp[14]); glVertex3fv(dcp[14]); + glNormal3fv(dcp[14]); glTexCoord2fv(tscp[15]); glVertex3fv(dcp[15]); + glNormal3fv(dcp[16]); glTexCoord2fv(tscp[16]); glVertex3fv(dcp[16]); + glNormal3fv(dcp[16]); glTexCoord2fv(tscp[17]); glVertex3fv(dcp[17]); + glEnd(); + + glEndList(); +} + +static void BuildElbow(void) +{ + + glNewList(elbow, GL_COMPILE); + + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[0][0]); glTexCoord2fv(tep[0][0]); glVertex3fv(ep[0][0]); + glNormal3fv(en[1][0]); glTexCoord2fv(tep[1][0]); glVertex3fv(ep[1][0]); + glNormal3fv(en[0][1]); glTexCoord2fv(tep[0][1]); glVertex3fv(ep[0][1]); + glNormal3fv(en[1][1]); glTexCoord2fv(tep[1][1]); glVertex3fv(ep[1][1]); + glNormal3fv(en[0][2]); glTexCoord2fv(tep[0][2]); glVertex3fv(ep[0][2]); + glNormal3fv(en[1][2]); glTexCoord2fv(tep[1][2]); glVertex3fv(ep[1][2]); + glNormal3fv(en[0][3]); glTexCoord2fv(tep[0][3]); glVertex3fv(ep[0][3]); + glNormal3fv(en[1][3]); glTexCoord2fv(tep[1][3]); glVertex3fv(ep[1][3]); + glNormal3fv(en[0][4]); glTexCoord2fv(tep[0][4]); glVertex3fv(ep[0][4]); + glNormal3fv(en[1][4]); glTexCoord2fv(tep[1][4]); glVertex3fv(ep[1][4]); + glNormal3fv(en[0][5]); glTexCoord2fv(tep[0][5]); glVertex3fv(ep[0][5]); + glNormal3fv(en[1][5]); glTexCoord2fv(tep[1][5]); glVertex3fv(ep[1][5]); + glNormal3fv(en[0][6]); glTexCoord2fv(tep[0][6]); glVertex3fv(ep[0][6]); + glNormal3fv(en[1][6]); glTexCoord2fv(tep[1][6]); glVertex3fv(ep[1][6]); + glNormal3fv(en[0][7]); glTexCoord2fv(tep[0][7]); glVertex3fv(ep[0][7]); + glNormal3fv(en[1][7]); glTexCoord2fv(tep[1][7]); glVertex3fv(ep[1][7]); + glNormal3fv(en[0][8]); glTexCoord2fv(tep[0][8]); glVertex3fv(ep[0][8]); + glNormal3fv(en[1][8]); glTexCoord2fv(tep[1][8]); glVertex3fv(ep[1][8]); + glEnd(); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[1][0]); glTexCoord2fv(tep[1][0]); glVertex3fv(ep[1][0]); + glNormal3fv(en[2][0]); glTexCoord2fv(tep[2][0]); glVertex3fv(ep[2][0]); + glNormal3fv(en[1][1]); glTexCoord2fv(tep[1][1]); glVertex3fv(ep[1][1]); + glNormal3fv(en[2][1]); glTexCoord2fv(tep[2][1]); glVertex3fv(ep[2][1]); + glNormal3fv(en[1][2]); glTexCoord2fv(tep[1][2]); glVertex3fv(ep[1][2]); + glNormal3fv(en[2][2]); glTexCoord2fv(tep[2][2]); glVertex3fv(ep[2][2]); + glNormal3fv(en[1][3]); glTexCoord2fv(tep[1][3]); glVertex3fv(ep[1][3]); + glNormal3fv(en[2][3]); glTexCoord2fv(tep[2][3]); glVertex3fv(ep[2][3]); + glNormal3fv(en[1][4]); glTexCoord2fv(tep[1][4]); glVertex3fv(ep[1][4]); + glNormal3fv(en[2][4]); glTexCoord2fv(tep[2][4]); glVertex3fv(ep[2][4]); + glNormal3fv(en[1][5]); glTexCoord2fv(tep[1][5]); glVertex3fv(ep[1][5]); + glNormal3fv(en[2][5]); glTexCoord2fv(tep[2][5]); glVertex3fv(ep[2][5]); + glNormal3fv(en[1][6]); glTexCoord2fv(tep[1][6]); glVertex3fv(ep[1][6]); + glNormal3fv(en[2][6]); glTexCoord2fv(tep[2][6]); glVertex3fv(ep[2][6]); + glNormal3fv(en[1][7]); glTexCoord2fv(tep[1][7]); glVertex3fv(ep[1][7]); + glNormal3fv(en[2][7]); glTexCoord2fv(tep[2][7]); glVertex3fv(ep[2][7]); + glNormal3fv(en[1][8]); glTexCoord2fv(tep[1][8]); glVertex3fv(ep[1][8]); + glNormal3fv(en[2][8]); glTexCoord2fv(tep[2][8]); glVertex3fv(ep[2][8]); + glEnd(); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[2][0]); glTexCoord2fv(tep[2][0]); glVertex3fv(ep[2][0]); + glNormal3fv(en[3][0]); glTexCoord2fv(tep[3][0]); glVertex3fv(ep[3][0]); + glNormal3fv(en[2][1]); glTexCoord2fv(tep[2][1]); glVertex3fv(ep[2][1]); + glNormal3fv(en[3][1]); glTexCoord2fv(tep[3][1]); glVertex3fv(ep[3][1]); + glNormal3fv(en[2][2]); glTexCoord2fv(tep[2][2]); glVertex3fv(ep[2][2]); + glNormal3fv(en[3][2]); glTexCoord2fv(tep[3][2]); glVertex3fv(ep[3][2]); + glNormal3fv(en[2][3]); glTexCoord2fv(tep[2][3]); glVertex3fv(ep[2][3]); + glNormal3fv(en[3][3]); glTexCoord2fv(tep[3][3]); glVertex3fv(ep[3][3]); + glNormal3fv(en[2][4]); glTexCoord2fv(tep[2][4]); glVertex3fv(ep[2][4]); + glNormal3fv(en[3][4]); glTexCoord2fv(tep[3][4]); glVertex3fv(ep[3][4]); + glNormal3fv(en[2][5]); glTexCoord2fv(tep[2][5]); glVertex3fv(ep[2][5]); + glNormal3fv(en[3][5]); glTexCoord2fv(tep[3][5]); glVertex3fv(ep[3][5]); + glNormal3fv(en[2][6]); glTexCoord2fv(tep[2][6]); glVertex3fv(ep[2][6]); + glNormal3fv(en[3][6]); glTexCoord2fv(tep[3][6]); glVertex3fv(ep[3][6]); + glNormal3fv(en[2][7]); glTexCoord2fv(tep[2][7]); glVertex3fv(ep[2][7]); + glNormal3fv(en[3][7]); glTexCoord2fv(tep[3][7]); glVertex3fv(ep[3][7]); + glNormal3fv(en[2][8]); glTexCoord2fv(tep[2][8]); glVertex3fv(ep[2][8]); + glNormal3fv(en[3][8]); glTexCoord2fv(tep[3][8]); glVertex3fv(ep[3][8]); + glEnd(); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[3][0]); glTexCoord2fv(tep[3][0]); glVertex3fv(ep[3][0]); + glNormal3fv(en[4][0]); glTexCoord2fv(tep[4][0]); glVertex3fv(ep[4][0]); + glNormal3fv(en[3][1]); glTexCoord2fv(tep[3][1]); glVertex3fv(ep[3][1]); + glNormal3fv(en[4][1]); glTexCoord2fv(tep[4][1]); glVertex3fv(ep[4][1]); + glNormal3fv(en[3][2]); glTexCoord2fv(tep[3][2]); glVertex3fv(ep[3][2]); + glNormal3fv(en[4][2]); glTexCoord2fv(tep[4][2]); glVertex3fv(ep[4][2]); + glNormal3fv(en[3][3]); glTexCoord2fv(tep[3][3]); glVertex3fv(ep[3][3]); + glNormal3fv(en[4][3]); glTexCoord2fv(tep[4][3]); glVertex3fv(ep[4][3]); + glNormal3fv(en[3][4]); glTexCoord2fv(tep[3][4]); glVertex3fv(ep[3][4]); + glNormal3fv(en[4][4]); glTexCoord2fv(tep[4][4]); glVertex3fv(ep[4][4]); + glNormal3fv(en[3][5]); glTexCoord2fv(tep[3][5]); glVertex3fv(ep[3][5]); + glNormal3fv(en[4][5]); glTexCoord2fv(tep[4][5]); glVertex3fv(ep[4][5]); + glNormal3fv(en[3][6]); glTexCoord2fv(tep[3][6]); glVertex3fv(ep[3][6]); + glNormal3fv(en[4][6]); glTexCoord2fv(tep[4][6]); glVertex3fv(ep[4][6]); + glNormal3fv(en[3][7]); glTexCoord2fv(tep[3][7]); glVertex3fv(ep[3][7]); + glNormal3fv(en[4][7]); glTexCoord2fv(tep[4][7]); glVertex3fv(ep[4][7]); + glNormal3fv(en[3][8]); glTexCoord2fv(tep[3][8]); glVertex3fv(ep[3][8]); + glNormal3fv(en[4][8]); glTexCoord2fv(tep[4][8]); glVertex3fv(ep[4][8]); + glEnd(); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[4][0]); glTexCoord2fv(tep[4][0]); glVertex3fv(ep[4][0]); + glNormal3fv(en[5][0]); glTexCoord2fv(tep[5][0]); glVertex3fv(ep[5][0]); + glNormal3fv(en[4][1]); glTexCoord2fv(tep[4][1]); glVertex3fv(ep[4][1]); + glNormal3fv(en[5][1]); glTexCoord2fv(tep[5][1]); glVertex3fv(ep[5][1]); + glNormal3fv(en[4][2]); glTexCoord2fv(tep[4][2]); glVertex3fv(ep[4][2]); + glNormal3fv(en[5][2]); glTexCoord2fv(tep[5][2]); glVertex3fv(ep[5][2]); + glNormal3fv(en[4][3]); glTexCoord2fv(tep[4][3]); glVertex3fv(ep[4][3]); + glNormal3fv(en[5][3]); glTexCoord2fv(tep[5][3]); glVertex3fv(ep[5][3]); + glNormal3fv(en[4][4]); glTexCoord2fv(tep[4][4]); glVertex3fv(ep[4][4]); + glNormal3fv(en[5][4]); glTexCoord2fv(tep[5][4]); glVertex3fv(ep[5][4]); + glNormal3fv(en[4][5]); glTexCoord2fv(tep[4][5]); glVertex3fv(ep[4][5]); + glNormal3fv(en[5][5]); glTexCoord2fv(tep[5][5]); glVertex3fv(ep[5][5]); + glNormal3fv(en[4][6]); glTexCoord2fv(tep[4][6]); glVertex3fv(ep[4][6]); + glNormal3fv(en[5][6]); glTexCoord2fv(tep[5][6]); glVertex3fv(ep[5][6]); + glNormal3fv(en[4][7]); glTexCoord2fv(tep[4][7]); glVertex3fv(ep[4][7]); + glNormal3fv(en[5][7]); glTexCoord2fv(tep[5][7]); glVertex3fv(ep[5][7]); + glNormal3fv(en[4][8]); glTexCoord2fv(tep[4][8]); glVertex3fv(ep[4][8]); + glNormal3fv(en[5][8]); glTexCoord2fv(tep[5][8]); glVertex3fv(ep[5][8]); + glEnd(); + glBegin(GL_TRIANGLE_STRIP); + glNormal3fv(en[5][0]); glTexCoord2fv(tep[5][0]); glVertex3fv(ep[5][0]); + glNormal3fv(en[6][0]); glTexCoord2fv(tep[6][0]); glVertex3fv(ep[6][0]); + glNormal3fv(en[5][1]); glTexCoord2fv(tep[5][1]); glVertex3fv(ep[5][1]); + glNormal3fv(en[6][1]); glTexCoord2fv(tep[6][1]); glVertex3fv(ep[6][1]); + glNormal3fv(en[5][2]); glTexCoord2fv(tep[5][2]); glVertex3fv(ep[5][2]); + glNormal3fv(en[6][2]); glTexCoord2fv(tep[6][2]); glVertex3fv(ep[6][2]); + glNormal3fv(en[5][3]); glTexCoord2fv(tep[5][3]); glVertex3fv(ep[5][3]); + glNormal3fv(en[6][3]); glTexCoord2fv(tep[6][3]); glVertex3fv(ep[6][3]); + glNormal3fv(en[5][4]); glTexCoord2fv(tep[5][4]); glVertex3fv(ep[5][4]); + glNormal3fv(en[6][4]); glTexCoord2fv(tep[6][4]); glVertex3fv(ep[6][4]); + glNormal3fv(en[5][5]); glTexCoord2fv(tep[5][5]); glVertex3fv(ep[5][5]); + glNormal3fv(en[6][5]); glTexCoord2fv(tep[6][5]); glVertex3fv(ep[6][5]); + glNormal3fv(en[5][6]); glTexCoord2fv(tep[5][6]); glVertex3fv(ep[5][6]); + glNormal3fv(en[6][6]); glTexCoord2fv(tep[6][6]); glVertex3fv(ep[6][6]); + glNormal3fv(en[5][7]); glTexCoord2fv(tep[5][7]); glVertex3fv(ep[5][7]); + glNormal3fv(en[6][7]); glTexCoord2fv(tep[6][7]); glVertex3fv(ep[6][7]); + glNormal3fv(en[5][8]); glTexCoord2fv(tep[5][8]); glVertex3fv(ep[5][8]); + glNormal3fv(en[6][8]); glTexCoord2fv(tep[6][8]); glVertex3fv(ep[6][8]); + glEnd(); + + glEndList(); +} + +static void BuildLogo(void) +{ + + glNewList(logo, GL_COMPILE); + + glTranslatef(5.5, -3.5, 4.5); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendRight(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendLeft(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendRight(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendLeft(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendRight(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -7.0); + glCallList(doubleCylinder); + BendForward(); + glCallList(elbow); + glTranslatef(0.0, 0.0, -5.0); + glCallList(singleCylinder); + BendLeft(); + glCallList(elbow); + + glEndList(); +} + +static void BuildLists(void) +{ + + singleCylinder = glGenLists(1); + doubleCylinder = glGenLists(1); + elbow = glGenLists(1); + logo = glGenLists(1); + + BuildSingleCylinder(); + BuildDoubleCylinder(); + BuildElbow(); + BuildLogo(); +} + +static void Init(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 150.0, 0.0}; + static float front_mat_shininess[] = {30.0}; + static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; + static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; + static float back_mat_shininess[] = {50.0}; + static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glFrontFace(GL_CW); + + glEnable(GL_DEPTH_TEST); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + + glEnable(GL_CLIP_PLANE0); + + if (rgb) { + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); + glTexImage2D(GL_TEXTURE_2D, 0, 3, CHECKIMAGEWIDTH, CHECKIMAGEHEIGHT, 0, + GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)checkImage); + glEnable(GL_TEXTURE_2D); + + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + } else { + SetGreyRamp(); + /* commented out by BrianP because it's the wrong way to handle a 4-bit visual! + if (doubleBuffer) { + colorIndexes[1] = 10; + colorIndexes[2] = 15; + } + */ + glMaterialiv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, colorIndexes); + } + + BuildLists(); + + dithering = GL_TRUE; + shade = GL_TRUE; + doStipple = GL_FALSE; + polyMode = GL_BACK; +} + +static void Reshape(int width, int height) +{ + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(90, 1.0, 1.0, 200.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + yRotation += 0.5; + break; + case GLUT_KEY_RIGHT: + yRotation -= 0.5; + break; + case GLUT_KEY_UP: + plane[3] += 2.0; + break; + case GLUT_KEY_DOWN: + plane[3] -= 2.0; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(1); + + case 'Z': + zTranslation -= 1.0; + break; + case 'z': + zTranslation += 1.0; + break; + + case '1': + glPolygonMode(polyMode, GL_POINT); + break; + case '2': + glPolygonMode(polyMode, GL_LINE); + break; + case '3': + glPolygonMode(polyMode, GL_FILL); + break; + case 'p': + switch (polyMode) { + case GL_BACK: + polyMode = GL_FRONT; + break; + case GL_FRONT: + polyMode = GL_FRONT_AND_BACK; + break; + case GL_FRONT_AND_BACK: + polyMode = GL_BACK; + break; + default: + break; + } + break; + + case '4': + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + break; + case '5': + glEnable(GL_POLYGON_SMOOTH); + if (rgb) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + } else { + SetUpAntiAliasedGrayScale(); + } + break; + case '6': + glDisable(GL_POLYGON_SMOOTH); + if (rgb) { + glBlendFunc(GL_ONE, GL_ZERO); + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + } else { + SetGreyRamp(); + } + break; + + case '8': + dithering = !dithering; + (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); + break; + + case '9': + doStipple = !doStipple; + if (doStipple) { + glPolygonStipple(stipple); + glEnable(GL_POLYGON_STIPPLE); + } else { + glDisable(GL_POLYGON_STIPPLE); + } + break; + + case '0': + shade = !shade; + (shade) ? glShadeModel(GL_SMOOTH) : glShadeModel(GL_FLAT); + break; + + case 'q': + glDisable(GL_CULL_FACE); + break; + case 'w': + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + break; + case 'e': + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + break; + + case 'r': + glFrontFace(GL_CW); + break; + case 't': + glFrontFace(GL_CCW); + break; + case 'y': + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_LSB_FIRST, 0); + glPolygonStipple(stipple); + break; + case 'u': + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_LSB_FIRST, 1); + glPolygonStipple(stipple); + break; + + case 'a': + glEnable(GL_TEXTURE_2D); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); + glTexImage2D(GL_TEXTURE_2D, 0, 4, BRICKIMAGEWIDTH, + BRICKIMAGEHEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, + (GLvoid *)brickImage); + break; + case 's': + glEnable(GL_TEXTURE_2D); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); + glTexImage2D(GL_TEXTURE_2D, 0, 3, CHECKIMAGEWIDTH, + CHECKIMAGEHEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, + (GLvoid *)checkImage); + break; + case 'd': + glDisable(GL_TEXTURE_2D); + break; + + case 'f': + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); + break; + case 'g': + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, modulate); + break; + + case 'n': + /* added by BrianP */ + noDraw = !noDraw; + if (noDraw) { + glDrawBuffer( GL_NONE ); + } + else { + if (doubleBuffer) { + glDrawBuffer( GL_BACK ); + } + else { + glDrawBuffer( GL_FRONT ); + } + } + break; + + case 'l': + /* Line Smooth - added by BrianP */ + LineSmooth = !LineSmooth; + if (LineSmooth) { + glEnable(GL_LINE_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + } + else { + glDisable(GL_LINE_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_BLEND); + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glTranslatef(0, 0, zTranslation); + glRotatef(30.0, 1, 0, 0); + glRotatef(yRotation, 0, 1, 0); + glClipPlane(GL_CLIP_PLANE0, plane); + glCallList(logo); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + unsigned int type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Logo Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/nurb.c b/progs/samples/nurb.c new file mode 100644 index 0000000000..f90c6ee91f --- /dev/null +++ b/progs/samples/nurb.c @@ -0,0 +1,355 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +#ifndef CALLBACK +#define CALLBACK +#endif + + +#define INREAL float + +#define S_NUMPOINTS 13 +#define S_ORDER 3 +#define S_NUMKNOTS (S_NUMPOINTS + S_ORDER) +#define T_NUMPOINTS 3 +#define T_ORDER 3 +#define T_NUMKNOTS (T_NUMPOINTS + T_ORDER) +#define SQRT_TWO 1.41421356237309504880 + + +typedef INREAL Point[4]; + + +GLenum doubleBuffer; + +GLenum expectedError; +GLint rotX = 40, rotY = 40; +INREAL sknots[S_NUMKNOTS] = { + -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, + 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0 +}; +INREAL tknots[T_NUMKNOTS] = { + 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 +}; +Point ctlpoints[S_NUMPOINTS][T_NUMPOINTS] = { + { + { + 4.0, 2.0, 2.0, 1.0 + }, + { + 4.0, 1.6, 2.5, 1.0 + }, + { + 4.0, 2.0, 3.0, 1.0 + } + }, + { + { + 5.0, 4.0, 2.0, 1.0 + }, + { + 5.0, 4.0, 2.5, 1.0 + }, + { + 5.0, 4.0, 3.0, 1.0 + } + }, + { + { + 6.0, 5.0, 2.0, 1.0 + }, + { + 6.0, 5.0, 2.5, 1.0 + }, + { + 6.0, 5.0, 3.0, 1.0 + } + }, + { + { + SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO + }, + { + SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO + }, + { + SQRT_TWO*6.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO + } + }, + { + { + 5.2, 6.7, 2.0, 1.0 + }, + { + 5.2, 6.7, 2.5, 1.0 + }, + { + 5.2, 6.7, 3.0, 1.0 + } + }, + { + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO + }, + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO + }, + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO + } + }, + { + { + 4.0, 5.2, 2.0, 1.0 + }, + { + 4.0, 4.6, 2.5, 1.0 + }, + { + 4.0, 5.2, 3.0, 1.0 + } + }, + { + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO + }, + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO + }, + { + SQRT_TWO*4.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO + } + }, + { + { + 2.8, 6.7, 2.0, 1.0 + }, + { + 2.8, 6.7, 2.5, 1.0 + }, + { + 2.8, 6.7, 3.0, 1.0 + } + }, + { + { + SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*2.0, SQRT_TWO + }, + { + SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*2.5, SQRT_TWO + }, + { + SQRT_TWO*2.0, SQRT_TWO*6.0, SQRT_TWO*3.0, SQRT_TWO + } + }, + { + { + 2.0, 5.0, 2.0, 1.0 + }, + { + 2.0, 5.0, 2.5, 1.0 + }, + { + 2.0, 5.0, 3.0, 1.0 + } + }, + { + { + 3.0, 4.0, 2.0, 1.0 + }, + { + 3.0, 4.0, 2.5, 1.0 + }, + { + 3.0, 4.0, 3.0, 1.0 + } + }, + { + { + 4.0, 2.0, 2.0, 1.0 + }, + { + 4.0, 1.6, 2.5, 1.0 + }, + { + 4.0, 2.0, 3.0, 1.0 + } + } +}; +GLUnurbsObj *theNurbs; + + +static void CALLBACK ErrorCallback(GLenum which) +{ + + if (which != expectedError) { + fprintf(stderr, "Unexpected error occured (%d):\n", which); + fprintf(stderr, " %s\n", (char *) gluErrorString(which)); + } +} + +static void Init(void) +{ + + theNurbs = gluNewNurbsRenderer(); + gluNurbsCallback(theNurbs, GLU_ERROR, ErrorCallback); + + gluNurbsProperty(theNurbs, GLU_SAMPLING_TOLERANCE, 15.0); + gluNurbsProperty(theNurbs, GLU_DISPLAY_MODE, GLU_OUTLINE_PATCH); + + expectedError = GLU_INVALID_ENUM; + gluNurbsProperty(theNurbs, ~0, 15.0); + expectedError = GLU_NURBS_ERROR13; + gluEndSurface(theNurbs); + expectedError = 0; + + glColor3f(1.0, 1.0, 1.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-2.0, 2.0, -2.0, 2.0, 0.8, 10.0); + gluLookAt(7.0, 4.5, 4.0, 4.5, 4.5, 2.5, 6.0, -3.0, 2.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_DOWN: + rotX -= 5; + break; + case GLUT_KEY_UP: + rotX += 5; + break; + case GLUT_KEY_LEFT: + rotY -= 5; + break; + case GLUT_KEY_RIGHT: + rotY += 5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + } +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + + glTranslatef(4.0, 4.5, 2.5); + glRotatef(rotY, 1, 0, 0); + glRotatef(rotX, 0, 1, 0); + glTranslatef(-4.0, -4.5, -2.5); + + gluBeginSurface(theNurbs); + gluNurbsSurface(theNurbs, S_NUMKNOTS, sknots, T_NUMKNOTS, tknots, + 4*T_NUMPOINTS, 4, &ctlpoints[0][0][0], S_ORDER, + T_ORDER, GL_MAP2_VERTEX_4); + gluEndSurface(theNurbs); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("NURBS Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/oglinfo.c b/progs/samples/oglinfo.c new file mode 100644 index 0000000000..4fe51efb3c --- /dev/null +++ b/progs/samples/oglinfo.c @@ -0,0 +1,218 @@ +/* oglinfo.c */ + +/* This demo modified by BrianP to accomodate Mesa and test + * the GLX 1.1 functions. + */ + + + +#include +#include +#include +#include +#include + +int visual_request0[] = { None }; /* don't need much of a visual */ +int visual_request1[] = { GLX_RGBA, None }; /* in case CI failed */ + +int main(int argc, char **argv) +{ + char *display_name = NULL; + char *string; + Display *dpy; + int screen_num; + int major, minor; + XVisualInfo *vis; + GLXContext ctx; + Window root, win; + Colormap cmap; + XSetWindowAttributes swa; + int dontcare; + + /* parse arguments */ + if(argc > 1) { + if(!strcmp(argv[1],"-display")) + display_name = argv[2]; + else { + fprintf(stderr, "Usage: %s [-display ]\n",argv[0]); + return 0; + } + } + + /* get display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr,"Error: XOpenDisplay() failed.\n"); + return 1; + } + + /* does the server know about OpenGL & GLX? */ +#ifndef MESA + if(!XQueryExtension(dpy, "GLX", &dontcare, &dontcare, &dontcare)) { + fprintf(stderr,"This system doesn't appear to support OpenGL\n"); + return 1; + } +#else + (void) dontcare; +#endif + + /* find the glx version */ + if(glXQueryVersion(dpy, &major, &minor)) + printf("GLX Version: %d.%d\n", major, minor); + else { + fprintf(stderr, "Error: glXQueryVersion() failed.\n"); + return 1; + } + + /* get screen number */ + screen_num = DefaultScreen(dpy); + +/* This #ifdef isn't redundant. It keeps the build from breaking +** if you are building on a machine that has an old (1.0) version +** of glx. +** +** This program could still be *run* on a machine that has an old +** version of glx, even if it was *compiled* on a version that has +** a new version. +** +** If compiled on a system with an old version of glx, then it will +** never recognize glx extensions, since that code would have been +** #ifdef'ed out. +*/ +#ifdef GLX_VERSION_1_1 + + /* + ** This test guarantees that glx, on the display you are inquiring, + ** suppports glXQueryExtensionsString(). + */ + if(minor > 0 || major > 1) + string = (char *) glXQueryExtensionsString(dpy, screen_num); + else + string = ""; + + if(string) + printf("GLX Extensions (client & server): %s\n", + string); + else { + fprintf(stderr, "Error: glXQueryExtensionsString() failed.\n"); + return 1; + } + + if (minor>0 || major>1) { + printf("glXGetClientString(GLX_VENDOR): %s\n", glXGetClientString(dpy,GLX_VENDOR)); + printf("glXGetClientString(GLX_VERSION): %s\n", glXGetClientString(dpy,GLX_VERSION)); + printf("glXGetClientString(GLX_EXTENSIONS): %s\n", glXGetClientString(dpy,GLX_EXTENSIONS)); + printf("glXQueryServerString(GLX_VENDOR): %s\n", glXQueryServerString(dpy,screen_num,GLX_VENDOR)); + printf("glXQueryServerString(GLX_VERSION): %s\n", glXQueryServerString(dpy,screen_num,GLX_VERSION)); + printf("glXQueryServerString(GLX_EXTENSIONS): %s\n", glXQueryServerString(dpy,screen_num,GLX_EXTENSIONS)); + } + + +#endif + + /* get any valid OpenGL visual */ + if (!(vis = glXChooseVisual(dpy, screen_num, visual_request0))) { + if (!(vis = glXChooseVisual(dpy, screen_num, visual_request1))) { + fprintf(stderr,"Error: glXChooseVisual() failed.\n"); + return 1; + } + } + + /* get context */ + ctx = glXCreateContext(dpy,vis,0,GL_TRUE); + + /* root window */ + root = RootWindow(dpy,vis->screen); + + /* get RGBA colormap */ + cmap = XCreateColormap(dpy, root, vis->visual, AllocNone); + + /* get window */ + swa.colormap = cmap; + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + win = XCreateWindow(dpy, root, 0, 0, 1, 1, 0, vis->depth, + InputOutput,vis->visual, + CWBorderPixel|CWColormap|CWEventMask, + &swa); + + glXMakeCurrent(dpy,win,ctx); + + string = (char *) glGetString(GL_VERSION); + if(string) +#ifdef MESA + printf("Mesa Version: %s\n", string); +#else + printf("OpenGL Version: %s\n", string); +#endif + else { + fprintf(stderr, "Error: glGetString(GL_VERSION) failed.\n"); + return 1; + } + + string = (char *) glGetString(GL_EXTENSIONS); + + if(string) +#ifdef MESA + printf("Mesa Extensions: %s\n", string); +#else + printf("OpenGL Extensions: %s\n", string); +#endif + else { + fprintf(stderr, "Error: glGetString(GL_EXTENSIONS) failed.\n"); + return 1; + } + + string = (char *) glGetString(GL_RENDERER); + + if(string) +#ifdef MESA + printf("Mesa Renderer: %s\n", string); +#else + printf("OpenGL renderer: %s\n", string); +#endif + else { + fprintf(stderr, "Error: glGetString(GL_RENDERER) failed.\n"); + return 1; + } + +/* +** This #ifdef prevents a build failure if you compile on an a +** machine with an old GLU library. +** +** If you build on a pre GLU 1.1 machine, you will never be able +** to get glu info, even if you run on a GLU 1.1 or latter machine, +** since the code has been #ifdef'ed out. +*/ +#ifdef GLU_VERSION_1_1 + + /* + ** If the glx version is 1.1 or latter, gluGetString() is guaranteed + ** to exist. + */ + if(minor > 0 || major > 1) + string = (char *) gluGetString(GLU_VERSION); + else + string = "1.0"; + + if(string) + printf("GLU Version: %s\n", string); + else { + fprintf(stderr, "Error: gluGetString(GLU_VERSION) failed.\n"); + return 1; + } + + if(minor > 0 || major > 1) + string = (char *) gluGetString(GLU_EXTENSIONS); + else + string = ""; + + if(string) + printf("GLU Extensions: %s\n", string); + else { + fprintf(stderr, "Error: gluGetString(GLU_EXTENSIONS) failed.\n"); + return 1; + } + +#endif + return 0; +} diff --git a/progs/samples/olympic.c b/progs/samples/olympic.c new file mode 100644 index 0000000000..db72002c01 --- /dev/null +++ b/progs/samples/olympic.c @@ -0,0 +1,375 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * Nov 20, 1995 use stdlib's rand()/srand() instead of random()/srand48(), etc. + */ + +/* + * Modified by Li Wei(liwei@aiar.xjtu.edu.cn) to be able to run in Windows + * 6/13 + * + * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97 + */ + + +#define _HPUX_SOURCE + +#include +#include +#include +#include +#include + +#ifndef RAND_MAX +# define RAND_MAX 32767 +#endif + + +#define XSIZE 100 +#define YSIZE 75 + +#define RINGS 5 +#define BLUERING 0 +#define BLACKRING 1 +#define REDRING 2 +#define YELLOWRING 3 +#define GREENRING 4 + +#define BACKGROUND 8 + + +GLenum rgb, doubleBuffer; + +#include "tkmap.c" + +unsigned char rgb_colors[RINGS][3]; +int mapped_colors[RINGS]; +float dests[RINGS][3]; +float offsets[RINGS][3]; +float angs[RINGS]; +float rotAxis[RINGS][3]; +int iters[RINGS]; +GLuint theTorus; + + +void FillTorus(float rc, int numc, float rt, int numt) +{ + int i, j, k; + double s, t; + double x, y, z; + double pi, twopi; + + pi = 3.14159265358979323846; + twopi = 2 * pi; + + for (i = 0; i < numc; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) { + for (k = 1; k >= 0; k--) { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = cos(t*twopi/numt) * cos(s*twopi/numc); + y = sin(t*twopi/numt) * cos(s*twopi/numc); + z = sin(s*twopi/numc); + glNormal3f(x, y, z); + + x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt); + y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt); + z = rc * sin(s*twopi/numc); + glVertex3f(x, y, z); + } + } + glEnd(); + } +} + +float Clamp(int iters_left, float t) +{ + + if (iters_left < 3) { + return 0.0; + } + return (iters_left-2)*t/iters_left; +} + +void DrawScene(void) +{ + int i, j; + GLboolean goIdle; + + goIdle = GL_TRUE; + for (i = 0; i < RINGS; i++) { + if (iters[i]) { + for (j = 0; j < 3; j++) { + offsets[i][j] = Clamp(iters[i], offsets[i][j]); + } + angs[i] = Clamp(iters[i], angs[i]); + iters[i]--; + goIdle = GL_FALSE; + } + } + if (goIdle) { + glutIdleFunc(NULL); + } + + glPushMatrix(); + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + gluLookAt(0,0,10, 0,0,0, 0,1,0); + + for (i = 0; i < RINGS; i++) { + if (rgb) { + glColor3ubv(rgb_colors[i]); + } else { + glIndexi(mapped_colors[i]); + } + glPushMatrix(); + glTranslatef(dests[i][0]+offsets[i][0], dests[i][1]+offsets[i][1], + dests[i][2]+offsets[i][2]); + glRotatef(angs[i], rotAxis[i][0], rotAxis[i][1], rotAxis[i][2]); + glCallList(theTorus); + glPopMatrix(); + } + + glPopMatrix(); + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +float MyRand(void) +{ + return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 ); +} + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + glutPostRedisplay(); +} + +void ReInit(void) +{ + int i; + float deviation; + + deviation = MyRand() / 2; + deviation = deviation * deviation; + for (i = 0; i < RINGS; i++) { + offsets[i][0] = MyRand(); + offsets[i][1] = MyRand(); + offsets[i][2] = MyRand(); + angs[i] = 260.0 * MyRand(); + rotAxis[i][0] = MyRand(); + rotAxis[i][1] = MyRand(); + rotAxis[i][2] = MyRand(); + iters[i] = (deviation * MyRand() + 60.0); + } + glutIdleFunc(glut_post_redisplay_p); +} + +void Init(void) +{ + float base, height; + float aspect, x, y; + int i; + + float top_y = 1.0; + float bottom_y = 0.0; + float top_z = 0.15; + float bottom_z = 0.69; + float spacing = 2.5; + static float lmodel_ambient[] = {0.0, 0.0, 0.0, 0.0}; + static float lmodel_twoside[] = {GL_FALSE}; + static float lmodel_local[] = {GL_FALSE}; + static float light0_ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float light0_diffuse[] = {1.0, 1.0, 1.0, 0.0}; + static float light0_position[] = {0.8660254, 0.5, 1, 0}; + static float light0_specular[] = {1.0, 1.0, 1.0, 0.0}; + static float bevel_mat_ambient[] = {0.0, 0.0, 0.0, 1.0}; + static float bevel_mat_shininess[] = {40.0}; + static float bevel_mat_specular[] = {1.0, 1.0, 1.0, 0.0}; + static float bevel_mat_diffuse[] = {1.0, 0.0, 0.0, 0.0}; + + srand( (unsigned int) glutGet(GLUT_ELAPSED_TIME) ); + + ReInit(); + for (i = 0; i < RINGS; i++) { + rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = 0; + } + rgb_colors[BLUERING][2] = 255; + rgb_colors[REDRING][0] = 255; + rgb_colors[GREENRING][1] = 255; + rgb_colors[YELLOWRING][0] = 255; + rgb_colors[YELLOWRING][1] = 255; + mapped_colors[BLUERING] = COLOR_BLUE; + mapped_colors[REDRING] = COLOR_RED; + mapped_colors[GREENRING] = COLOR_GREEN; + mapped_colors[YELLOWRING] = COLOR_YELLOW; + mapped_colors[BLACKRING] = COLOR_BLACK; + + dests[BLUERING][0] = -spacing; + dests[BLUERING][1] = top_y; + dests[BLUERING][2] = top_z; + + dests[BLACKRING][0] = 0.0; + dests[BLACKRING][1] = top_y; + dests[BLACKRING][2] = top_z; + + dests[REDRING][0] = spacing; + dests[REDRING][1] = top_y; + dests[REDRING][2] = top_z; + + dests[YELLOWRING][0] = -spacing / 2.0; + dests[YELLOWRING][1] = bottom_y; + dests[YELLOWRING][2] = bottom_z; + + dests[GREENRING][0] = spacing / 2.0; + dests[GREENRING][1] = bottom_y; + dests[GREENRING][2] = bottom_z; + + base = 2.0; + height = 2.0; + theTorus = glGenLists(1); + glNewList(theTorus, GL_COMPILE); + FillTorus(0.1, 8, 1.0, 25); + glEndList(); + + x = (float)XSIZE; + y = (float)YSIZE; + aspect = x / y; + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + glClearDepth(1.0); + + if (rgb) { + glClearColor(0.5, 0.5, 0.5, 0.0); + glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light0_position); + glEnable(GL_LIGHT0); + + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glEnable(GL_LIGHTING); + + glMaterialfv(GL_FRONT, GL_AMBIENT, bevel_mat_ambient); + glMaterialfv(GL_FRONT, GL_SHININESS, bevel_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, bevel_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, bevel_mat_diffuse); + + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + glShadeModel(GL_SMOOTH); + } else { + glClearIndex(BACKGROUND); + glShadeModel(GL_FLAT); + } + + glMatrixMode(GL_PROJECTION); + gluPerspective(45, 1.33, 0.1, 100.0); + glMatrixMode(GL_MODELVIEW); +} + +void Reshape(int width, int height) +{ + + glViewport(0, 0, width, height); +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 32: + ReInit(); + break; + } +} + +GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Olympic") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(DrawScene); + glutIdleFunc(glut_post_redisplay_p); + + glutMainLoop(); + return 0; +} diff --git a/progs/samples/overlay.c b/progs/samples/overlay.c new file mode 100644 index 0000000000..41bbc26114 --- /dev/null +++ b/progs/samples/overlay.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + + +#ifndef PI +#define PI 3.141592657 +#endif + + +enum { + NORMAL = 0, + WEIRD = 1 +}; + +enum { + STREAK = 0, + CIRCLE = 1 +}; + +#define MAXSTARS 400 +#define MAXPOS 10000 +#define MAXWARP 10 +#define MAXANGLES 6000 + + +typedef struct _starRec { + GLint type; + float x[2], y[2], z[2]; + float offsetX, offsetY, offsetR, rotation; +} starRec; + + +GLenum doubleBuffer; +GLint windW, windH; + +GLenum flag = NORMAL, overlayInit = GL_FALSE; +GLint starCount = MAXSTARS / 2; +float speed = 1.0; +GLint nitro = 0; +starRec stars[MAXSTARS]; +float sinTable[MAXANGLES]; + + +float Sin(float angle) +{ + + return (sinTable[(GLint)angle]); +} + +float Cos(float angle) +{ + + return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]); +} + +void NewStar(GLint n, GLint d) +{ + + if (rand()%4 == 0) { + stars[n].type = CIRCLE; + } else { + stars[n].type = STREAK; + } + stars[n].x[0] = (float)(rand() % MAXPOS - MAXPOS / 2); + stars[n].y[0] = (float)(rand() % MAXPOS - MAXPOS / 2); + stars[n].z[0] = (float)(rand() % MAXPOS + d); + if (rand()%4 == 0 && flag == WEIRD) { + stars[n].offsetX = (float)(rand() % 100 - 100 / 2); + stars[n].offsetY = (float)(rand() % 100 - 100 / 2); + stars[n].offsetR = (float)(rand() % 25 - 25 / 2); + } else { + stars[n].offsetX = 0.0; + stars[n].offsetY = 0.0; + stars[n].offsetR = 0.0; + } +} + +void RotatePoint(float *x, float *y, float rotation) +{ + float tmpX, tmpY; + + tmpX = *x * Cos(rotation) - *y * Sin(rotation); + tmpY = *y * Cos(rotation) + *x * Sin(rotation); + *x = tmpX; + *y = tmpY; +} + +void MoveStars(void) +{ + float offset; + GLint n; + + offset = speed * 60.0; + + for (n = 0; n < starCount; n++) { + stars[n].x[1] = stars[n].x[0]; + stars[n].y[1] = stars[n].y[0]; + stars[n].z[1] = stars[n].z[0]; + stars[n].x[0] += stars[n].offsetX; + stars[n].y[0] += stars[n].offsetY; + stars[n].z[0] -= offset; + stars[n].rotation += stars[n].offsetR; + if (stars[n].rotation > MAXANGLES) { + stars[n].rotation = 0.0; + } + } +} + +GLenum StarPoint(GLint n) +{ + float x0, y0, x1, y1, width; + GLint i; + + x0 = stars[n].x[0] * windW / stars[n].z[0]; + y0 = stars[n].y[0] * windH / stars[n].z[0]; + RotatePoint(&x0, &y0, stars[n].rotation); + x0 += windW / 2.0; + y0 += windH / 2.0; + + if (x0 >= 0.0 && x0 < windW && y0 >= 0.0 && y0 < windH) { + if (stars[n].type == STREAK) { + x1 = stars[n].x[1] * windW / stars[n].z[1]; + y1 = stars[n].y[1] * windH / stars[n].z[1]; + RotatePoint(&x1, &y1, stars[n].rotation); + x1 += windW / 2.0; + y1 += windH / 2.0; + + glLineWidth(MAXPOS/100.0/stars[n].z[0]+1.0); + glColor3f(1.0, (MAXWARP-speed)/MAXWARP, (MAXWARP-speed)/MAXWARP); + if (fabs(x0-x1) < 1.0 && fabs(y0-y1) < 1.0) { + glBegin(GL_POINTS); + glVertex2f(x0, y0); + glEnd(); + } else { + glBegin(GL_LINES); + glVertex2f(x0, y0); + glVertex2f(x1, y1); + glEnd(); + } + } else { + width = MAXPOS / 10.0 / stars[n].z[0] + 1.0; + glColor3f(1.0, 0.0, 0.0); + glBegin(GL_POLYGON); + for (i = 0; i < 8; i++) { + float x = x0 + width * Cos((float)i*MAXANGLES/8.0); + float y = y0 + width * Sin((float)i*MAXANGLES/8.0); + glVertex2f(x, y); + }; + glEnd(); + } + return GL_TRUE; + } else { + return GL_FALSE; + } +} + +void ShowStars(void) +{ + GLint n; + + glClear(GL_COLOR_BUFFER_BIT); + + for (n = 0; n < starCount; n++) { + if (stars[n].z[0] > speed || (stars[n].z[0] > 0.0 && speed < MAXWARP)) { + if (StarPoint(n) == GL_FALSE) { + NewStar(n, MAXPOS); + } + } else { + NewStar(n, MAXPOS); + } + } +} + +static void Init(void) +{ + float angle; + GLint n; + + srand((unsigned int)time(NULL)); + + for (n = 0; n < MAXSTARS; n++) { + NewStar(n, 100); + } + + angle = 0.0; + for (n = 0; n < MAXANGLES ; n++) { + sinTable[n] = sin(angle); + angle += PI / (MAXANGLES / 2.0); + } + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glDisable(GL_DITHER); +} + +void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glutUseLayer(GLUT_OVERLAY); + + glViewport(0, 0, windW, windH); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, windW+0.5, -0.5, windH+0.5); + glMatrixMode(GL_MODELVIEW); + overlayInit = GL_FALSE; + + glutUseLayer(GLUT_NORMAL); + + glViewport(0, 0, windW, windH); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, windW+0.5, -0.5, windH+0.5); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 32: + flag = (flag == NORMAL) ? WEIRD : NORMAL; + break; + case 't': + nitro = 1; + break; + default: + return; + } +} + +void Idle(void) +{ + + if (overlayInit == GL_FALSE) { + glutUseLayer(GLUT_OVERLAY); + glClear(GL_COLOR_BUFFER_BIT); +/* glColor3f(1.0, 0.0, 0.0);*/ + + glIndexf( 2.0 ); + glBegin(GL_POLYGON); + glVertex2i(windW/4-10, windH/4-10); + glVertex2i(windW/2-10, windH/4-10); + glVertex2i(windW/2-10, windH/2-10); + glVertex2i(windW/4-10, windH/2-10); + glEnd(); + + glIndexf( 0.0 ); + glBegin(GL_POLYGON); + glVertex2i(windW/4, windH/4); + glVertex2i(windW/2, windH/4); + glVertex2i(windW/2, windH/2); + glVertex2i(windW/4, windH/2); + glEnd(); + + glIndexf( 1.0 ); + glBegin(GL_POLYGON); + glVertex2i(windW/4+10, windH/4+10); + glVertex2i(windW/2+10, windH/4+10); + glVertex2i(windW/2+10, windH/2+10); + glVertex2i(windW/4+10, windH/2+10); + glEnd(); + + glutUseLayer(GLUT_NORMAL); + overlayInit = GL_TRUE; + } + + MoveStars(); + ShowStars(); + if (nitro > 0) { + speed = (float)(nitro / 10) + 1.0; + if (speed > MAXWARP) { + speed = MAXWARP; + } + if (++nitro > MAXWARP*10) { + nitro = -nitro; + } + } else if (nitro < 0) { + nitro++; + speed = (float)(-nitro / 10) + 1.0; + if (speed > MAXWARP) { + speed = MAXWARP; + } + } + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (!glutLayerGet(GLUT_OVERLAY_POSSIBLE)) + { + fprintf(stderr, "Overlay not available\n"); + return; + } + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 300; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Overlay Test") == GL_FALSE) { + exit(1); + } + + glutEstablishOverlay(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutIdleFunc(Idle); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/point.c b/progs/samples/point.c new file mode 100644 index 0000000000..4cb6ad7d51 --- /dev/null +++ b/progs/samples/point.c @@ -0,0 +1,234 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_RED COLOR_RED +#define CI_ANTI_ALIAS_GREEN 16 +#define CI_ANTI_ALIAS_YELLOW 32 +#define CI_ANTI_ALIAS_RED 48 + + +GLenum rgb, doubleBuffer, windType; +GLint windW, windH; + +#include "tkmap.c" + +GLenum mode; +GLint size; +float point[3] = { + 1.0, 1.0, 0.0 +}; + + +static void Init(void) +{ + GLint i; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glBlendFunc(GL_SRC_ALPHA, GL_ZERO); + + if (!rgb) { + for (i = 0; i < 16; i++) { + glutSetColor(i+CI_ANTI_ALIAS_RED, i/15.0, 0.0, 0.0); + glutSetColor(i+CI_ANTI_ALIAS_YELLOW, i/15.0, i/15.0, 0.0); + glutSetColor(i+CI_ANTI_ALIAS_GREEN, 0.0, i/15.0, 0.0); + } + } + + mode = GL_FALSE; + size = 1; +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-windW/2, windW/2, -windH/2, windH/2); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + point[0] -= 0.25; + break; + case GLUT_KEY_RIGHT: + point[0] += 0.25; + break; + case GLUT_KEY_UP: + point[1] += 0.25; + break; + case GLUT_KEY_DOWN: + point[1] -= 0.25; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + mode = !mode; + break; + case 'W': + size++; + break; + case 'w': + size--; + if (size < 1) { + size = 1; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + SetColor(COLOR_YELLOW); + glBegin(GL_LINE_STRIP); + glVertex2f(-windW/2, 0); + glVertex2f(windW/2, 0); + glEnd(); + glBegin(GL_LINE_STRIP); + glVertex2f(0, -windH/2); + glVertex2f(0, windH/2); + glEnd(); + + if (mode) { + glEnable(GL_BLEND); + glEnable(GL_POINT_SMOOTH); + } else { + glDisable(GL_BLEND); + glDisable(GL_POINT_SMOOTH); + } + + glPointSize(size); + if (mode) { + (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_ANTI_ALIAS_RED); + } else { + (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_RED); + } + glBegin(GL_POINTS); + glVertex3fv(point); + glEnd(); + + glDisable(GL_POINT_SMOOTH); + glDisable(GL_BLEND); + + glPointSize(1); + SetColor(COLOR_GREEN); + glBegin(GL_POINTS); + glVertex3fv(point); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 300; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Point Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/prim.c b/progs/samples/prim.c new file mode 100644 index 0000000000..388e0153b4 --- /dev/null +++ b/progs/samples/prim.c @@ -0,0 +1,546 @@ +#include +#include +#include +#include + + +#define PIXEL_CENTER(x) ((long)(x) + 0.5) + +#define GAP 10 +#define ROWS 3 +#define COLS 4 + +#define OPENGL_WIDTH 48 +#define OPENGL_HEIGHT 13 + + +GLenum rgb, doubleBuffer, windType; +GLint windW, windH; + +GLenum mode1, mode2; +GLint boxW, boxH; +GLubyte OpenGL_bits[] = { + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01, + 0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00, + 0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00, + 0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a, + 0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e, + 0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e, + 0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00, +}; + + +#include "tkmap.c" + +static void Init(void) +{ + + mode1 = GL_TRUE; + mode2 = GL_TRUE; +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; +} + +static void RotateColorMask(void) +{ + static GLint rotation = 0; + + rotation = (rotation + 1) & 0x3; + switch (rotation) { + case 0: + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask( 0xff ); + break; + case 1: + glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); + glIndexMask(0xFE); + break; + case 2: + glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE); + glIndexMask(0xFD); + break; + case 3: + glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); + glIndexMask(0xFB); + break; + } +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case '1': + mode1 = !mode1; + break; + case '2': + mode2 = !mode2; + break; + case '3': + RotateColorMask(); + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Viewport(GLint row, GLint column) +{ + GLint x, y; + + boxW = (windW - (COLS + 1) * GAP) / COLS; + boxH = (windH - (ROWS + 1) * GAP) / ROWS; + + x = GAP + column * (boxW + GAP); + y = GAP + row * (boxH + GAP); + + glViewport(x, y, boxW, boxH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glEnable(GL_SCISSOR_TEST); + glScissor(x, y, boxW, boxH); +} + +static void Point(void) +{ + GLint i; + + glBegin(GL_POINTS); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 1; i < 8; i++) { + GLint j = i * 2; + SetColor(COLOR_BLACK+i); + glVertex2i(-j, -j); + glVertex2i(-j, 0); + glVertex2i(-j, j); + glVertex2i(0, j); + glVertex2i(j, j); + glVertex2i(j, 0); + glVertex2i(j, -j); + glVertex2i(0, -j); + } + glEnd(); +} + +static void Lines(void) +{ + GLint i; + + glPushMatrix(); + + glTranslatef(-12, 0, 0); + for (i = 1; i < 8; i++) { + SetColor(COLOR_BLACK+i); + glBegin(GL_LINES); + glVertex2i(-boxW/4, -boxH/4); + glVertex2i(boxW/4, boxH/4); + glEnd(); + glTranslatef(4, 0, 0); + } + + glPopMatrix(); + + glBegin(GL_LINES); + glVertex2i(0, 0); + glEnd(); +} + +static void LineStrip(void) +{ + + glBegin(GL_LINE_STRIP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2i(0, 0); + glEnd(); +} + +static void LineLoop(void) +{ + + glBegin(GL_LINE_LOOP); + SetColor(COLOR_RED); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4)); + SetColor(COLOR_GREEN); + glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_BLUE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4)); + SetColor(COLOR_WHITE); + glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4)); + glEnd(); + + glEnable(GL_LOGIC_OP); + glLogicOp(GL_XOR); + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + + SetColor(COLOR_MAGENTA); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8)); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8)); + glEnd(); + glBegin(GL_LINE_LOOP); + glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5)); + glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5)); + glEnd(); + glDisable(GL_LOGIC_OP); + glDisable(GL_BLEND); + + SetColor(COLOR_GREEN); + glBegin(GL_POINTS); + glVertex2i(0, 0); + glEnd(); + + glBegin(GL_LINE_LOOP); + glVertex2i(0, 0); + glEnd(); +} + +static void Bitmap(void) +{ + + glBegin(GL_LINES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/2, 0); + glVertex2i(boxW/2, 0); + glVertex2i(0, -boxH/2); + glVertex2i(0, boxH/2); + SetColor(COLOR_RED); + glVertex2i(0, -3); + glVertex2i(0, -3+OPENGL_HEIGHT); + SetColor(COLOR_BLUE); + glVertex2i(0, -3); + glVertex2i(OPENGL_WIDTH, -3); + glEnd(); + + SetColor(COLOR_GREEN); + + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glRasterPos2i(0, 0); + glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits); +} + +static void Triangles(void) +{ + + glBegin(GL_TRIANGLES); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + glEnd(); + + glBegin(GL_TRIANGLES); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleStrip(void) +{ + + glBegin(GL_TRIANGLE_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void TriangleFan(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_TRIANGLE_FAN); + SetColor(COLOR_WHITE); + glVertex2i(0, 0); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_TRIANGLE_FAN); + glVertex2i(0, 0); + glVertex2i(-100, 100); + glEnd(); +} + +static void Rect(void) +{ + + SetColor(COLOR_GREEN); + glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4); +} + +static void PolygonFunc(void) +{ + GLint vx[8][2]; + GLint x0, y0, x1, y1, x2, y2, x3, y3; + GLint i; + + y0 = -boxH/4; + y1 = y0 + boxH/2/3; + y2 = y1 + boxH/2/3; + y3 = boxH/4; + x0 = -boxW/4; + x1 = x0 + boxW/2/3; + x2 = x1 + boxW/2/3; + x3 = boxW/4; + + vx[0][0] = x0; vx[0][1] = y1; + vx[1][0] = x0; vx[1][1] = y2; + vx[2][0] = x1; vx[2][1] = y3; + vx[3][0] = x2; vx[3][1] = y3; + vx[4][0] = x3; vx[4][1] = y2; + vx[5][0] = x3; vx[5][1] = y1; + vx[6][0] = x2; vx[6][1] = y0; + vx[7][0] = x1; vx[7][1] = y0; + + glBegin(GL_POLYGON); + for (i = 0; i < 8; i++) { + SetColor(COLOR_WHITE-i); + glVertex2iv(vx[i]); + } + glEnd(); + + glBegin(GL_POLYGON); + glVertex2i(0, 0); + glVertex2i(100, 100); + glEnd(); +} + +static void Quads(void) +{ + + glBegin(GL_QUADS); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, -boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, -boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, -boxH/4); + + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/8, boxH/16); + SetColor(COLOR_BLUE); + glVertex2i(boxW/8, boxH/16); + SetColor(COLOR_WHITE); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUADS); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void QuadStrip(void) +{ + + glBegin(GL_QUAD_STRIP); + SetColor(COLOR_GREEN); + glVertex2i(-boxW/4, -boxH/4); + SetColor(COLOR_RED); + glVertex2i(-boxW/4, boxH/4); + SetColor(COLOR_BLUE); + glVertex2i(0, -boxH/4); + SetColor(COLOR_WHITE); + glVertex2i(0, boxH/4); + SetColor(COLOR_CYAN); + glVertex2i(boxW/4, -boxH/4); + SetColor(COLOR_YELLOW); + glVertex2i(boxW/4, boxH/4); + glEnd(); + + glBegin(GL_QUAD_STRIP); + glVertex2i(0, 0); + glVertex2i(100, 100); + glVertex2i(-100, 100); + glEnd(); +} + +static void Draw(void) +{ + + glViewport(0, 0, windW, windH); + glDisable(GL_SCISSOR_TEST); + + glPushAttrib(GL_COLOR_BUFFER_BIT); + + glColorMask(1, 1, 1, 1); + glIndexMask(~0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glPopAttrib(); + + if (mode1) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + + if (mode2) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + + Viewport(0, 0); Point(); + Viewport(0, 1); Lines(); + Viewport(0, 2); LineStrip(); + Viewport(0, 3); LineLoop(); + + Viewport(1, 0); Bitmap(); + + Viewport(1, 1); TriangleFan(); + Viewport(1, 2); Triangles(); + Viewport(1, 3); TriangleStrip(); + + Viewport(2, 0); Rect(); + Viewport(2, 1); PolygonFunc(); + Viewport(2, 2); Quads(); + Viewport(2, 3); QuadStrip(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 600; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Primitive Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/quad.c b/progs/samples/quad.c new file mode 100644 index 0000000000..8dec28b6bb --- /dev/null +++ b/progs/samples/quad.c @@ -0,0 +1,455 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#ifndef CALLBACK +#define CALLBACK +#endif + + +#define PI 3.141592654 +#define BLACK 0 +#define GRAY 128 +#define WHITE 255 +#define RD 0xA4,0x00,0x00,0xFF +#define WT 0xFF,0xFF,0xFF,0xFF +#define brickImageWidth 16 +#define brickImageHeight 16 + + +#include "loadppm.c" + +GLenum rgb, doubleBuffer; + +#include "tkmap.c" + +float black[3] = { + 0.0, 0.0, 0.0 +}; +float blue[3] = { + 0.0, 0.0, 1.0 +}; +float gray[3] = { + 0.5, 0.5, 0.5 +}; +float white[3] = { + 1.0, 1.0, 1.0 +}; + +GLenum doDither = GL_TRUE; +GLenum shade = GL_TRUE; +GLenum texture = GL_TRUE; + +float xRotation = 30.0, yRotation = 30.0, zRotation = 0.0; +GLint radius1, radius2; +GLdouble angle1, angle2; +GLint slices, stacks; +GLint height; +GLint orientation = GLU_OUTSIDE; +GLint whichQuadric=0; +GLUquadricObj *quadObj; + +GLubyte brickImage[4*brickImageWidth*brickImageHeight] = { + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + RD, RD, RD, RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, + WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, WT, + RD, RD, RD, RD, WT, RD, RD, RD, RD, RD, RD, RD, RD, RD, WT, RD +}; +char *texFileName = 0; + + +static void CALLBACK ErrorHandler(GLenum which) +{ + + fprintf(stderr, "Quad Error: %s\n", gluErrorString(which)); +} + +static void Init(void) +{ + static GLint colorIndexes[3] = {0, 200, 255}; + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 150.0, 0.0}; + static float front_mat_shininess[] = {30.0}; + static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; + static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; + static float back_mat_shininess[] = {50.0}; + static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + static float decal[] = {GL_DECAL}; + static float repeat[] = {GL_REPEAT}; + static float nearest[] = {GL_NEAREST}; + static PPMImage *image; + + if (!rgb) { + SetGreyRamp(); + } + glClearColor(0.0, 0.0, 0.0, 0.0); + + glEnable(GL_DEPTH_TEST); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + if (!rgb) { + glMaterialiv( GL_FRONT_AND_BACK, GL_COLOR_INDEXES, colorIndexes); + } + + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nearest); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nearest); + if (texFileName) { + image = LoadPPM(texFileName); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY, + GL_RGB, GL_UNSIGNED_BYTE, image->data); + } else { + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, 4, brickImageWidth, brickImageHeight, + 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)brickImage); + } + + quadObj = gluNewQuadric(); + gluQuadricCallback(quadObj, GLU_ERROR, ErrorHandler); + + radius1 = 10; + radius2 = 5; + angle1 = 90; + angle2 = 180; + slices = 16; + stacks = 10; + height = 20; +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 1, 10); + gluLookAt(2, 2, 2, 0, 0, 0, 0, 0, 1); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + yRotation += 5; + break; + case GLUT_KEY_RIGHT: + yRotation -= 5; + break; + case GLUT_KEY_UP: + xRotation += 5; + break; + case GLUT_KEY_DOWN: + xRotation -= 5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + + case 'X': + zRotation += 5; + break; + case 'x': + zRotation -= 5; + break; + + case '1': + gluQuadricDrawStyle(quadObj, GLU_FILL); + break; + case '2': + gluQuadricDrawStyle(quadObj, GLU_POINT); + break; + case '3': + gluQuadricDrawStyle(quadObj, GLU_LINE); + break; + case '4': + gluQuadricDrawStyle(quadObj, GLU_SILHOUETTE); + break; + + case '0': + shade = !shade; + if (shade) { + glShadeModel(GL_SMOOTH); + gluQuadricNormals(quadObj, GLU_SMOOTH); + } else { + glShadeModel(GL_FLAT); + gluQuadricNormals(quadObj, GLU_FLAT); + } + break; + + case 'A': + stacks++; + break; + case 'a': + stacks--; + break; + + case 'S': + slices++; + break; + case 's': + slices--; + break; + + case 'd': + switch(orientation) { + case GLU_OUTSIDE: + orientation = GLU_INSIDE; + break; + case GLU_INSIDE: + default: + orientation = GLU_OUTSIDE; + break; + } + gluQuadricOrientation(quadObj, orientation); + break; + + case 'f': + whichQuadric = (whichQuadric + 1) % 4; + break; + + case 'G': + radius1 += 1; + break; + case 'g': + radius1 -= 1; + break; + + case 'J': + radius2 += 1; + break; + case 'j': + radius2 -= 1; + break; + + case 'H': + height += 2; + break; + case 'h': + height -= 2; + break; + + case 'K': + angle1 += 5; + break; + case 'k': + angle1 -= 5; + break; + + case 'L': + angle2 += 5; + break; + case 'l': + angle2 -= 5; + break; + + case 'z': + texture = !texture; + if (texture) { + gluQuadricTexture(quadObj, GL_TRUE); + glEnable(GL_TEXTURE_2D); + } else { + gluQuadricTexture(quadObj, GL_FALSE); + glDisable(GL_TEXTURE_2D); + } + break; + + case 'q': + glDisable(GL_CULL_FACE); + break; + case 'w': + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + break; + case 'e': + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + break; + + case 'r': + glFrontFace(GL_CW); + break; + case 't': + glFrontFace(GL_CCW); + break; + + case 'y': + doDither = !doDither; + (doDither) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glLoadIdentity(); + glRotatef(xRotation, 1, 0, 0); + glRotatef(yRotation, 0, 1, 0); + glRotatef(zRotation, 0, 0, 1); + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + glColor3f(1.0, 1.0, 1.0); + switch (whichQuadric) { + case 0: + glTranslatef(0, 0, -height/20.0); + gluCylinder(quadObj, radius1/10.0, radius2/10.0, height/10.0, + slices, stacks); + break; + case 1: + gluSphere(quadObj, radius1/10.0, slices, stacks); + break; + case 2: + gluPartialDisk(quadObj, radius2/10.0, radius1/10.0, slices, + stacks, angle1, angle2); + break; + case 3: + gluDisk(quadObj, radius2/10.0, radius1/10.0, slices, stacks); + break; + } + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-f") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-f (No file name).\n"); + return GL_FALSE; + } else { + texFileName = argv[++i]; + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Quad Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c new file mode 100644 index 0000000000..0bc73487b0 --- /dev/null +++ b/progs/samples/rgbtoppm.c @@ -0,0 +1,273 @@ + +/* texture.c - by David Blythe, SGI */ + +/* texload is a simplistic routine for reading an SGI .rgb image file. */ + +#include +#include +#include + +#include + +typedef struct _ImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short xsize, ysize, zsize; + unsigned int min, max; + unsigned int wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp; + unsigned long rleEnd; + unsigned int *rowStart; + int *rowSize; +} ImageRec; + +void +rgbtorgb(unsigned char *r,unsigned char *g,unsigned char *b,unsigned char *l,int n) { + while(n--) { + l[0] = r[0]; + l[1] = g[0]; + l[2] = b[0]; + l += 3; r++; g++; b++; + } +} + +static void +ConvertShort(unsigned short *array, unsigned int length) { + unsigned short b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (b1 << 8) | (b2); + } +} + +static void +ConvertUint(unsigned *array, unsigned int length) { + unsigned int b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static ImageRec *ImageOpen(char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + ImageRec *image; + int swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = 1; + } else { + swapFlag = 0; + } + + image = (ImageRec *)malloc(sizeof(ImageRec)); + if (image == NULL) { + fprintf(stderr, "Out of memory!\n"); + exit(1); + } + if ((image->file = fopen(fileName, "rb")) == NULL) { + return NULL; + } + + fread(image, 1, 12, image->file); + + if (swapFlag) { + ConvertShort(&image->imagic, 6); + } + + image->tmp = (unsigned char *)malloc(image->xsize*256); + if (image->tmp == NULL) { + fprintf(stderr, "\nOut of memory!\n"); + exit(1); + } + + if ((image->type & 0xFF00) == 0x0100) { + x = image->ysize * image->zsize * (int) sizeof(unsigned); + image->rowStart = (unsigned *)malloc(x); + image->rowSize = (int *)malloc(x); + if (image->rowStart == NULL || image->rowSize == NULL) { + fprintf(stderr, "\nOut of memory!\n"); + exit(1); + } + image->rleEnd = 512 + (2 * x); + fseek(image->file, 512, SEEK_SET); + fread(image->rowStart, 1, x, image->file); + fread(image->rowSize, 1, x, image->file); + if (swapFlag) { + ConvertUint(image->rowStart, x/(int) sizeof(unsigned)); + ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int)); + } + } + return image; +} + +static void +ImageClose(ImageRec *image) { + fclose(image->file); + free(image->tmp); + free(image); +} + +static void +ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) { + unsigned char *iPtr, *oPtr, pixel; + int count; + + if ((image->type & 0xFF00) == 0x0100) { + fseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET); + fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize], + image->file); + + iPtr = image->tmp; + oPtr = buf; + for (;;) { + pixel = *iPtr++; + count = (int)(pixel & 0x7F); + if (!count) { + return; + } + if (pixel & 0x80) { + while (count--) { + *oPtr++ = *iPtr++; + } + } else { + pixel = *iPtr++; + while (count--) { + *oPtr++ = pixel; + } + } + } + } else { + fseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize), + SEEK_SET); + fread(buf, 1, image->xsize, image->file); + } +} + +GLubyte * +read_alpha_texture(char *name, int *width, int *height) +{ + unsigned char *base, *lptr; + ImageRec *image; + int y; + + image = ImageOpen(name); + if(!image) { + return NULL; + } + + (*width)=image->xsize; + (*height)=image->ysize; + if (image->zsize != 1) { + ImageClose(image); + return NULL; + } + + base = (unsigned char *)malloc(image->xsize*image->ysize*sizeof(unsigned char)); + lptr = base; + for(y=0; yysize; y++) { + ImageGetRow(image,lptr,y,0); + lptr += image->xsize; + } + ImageClose(image); + + return (unsigned char *) base; +} + +GLubyte * +read_rgb_texture(char *name, int *width, int *height) +{ + unsigned char *base, *ptr; + unsigned char *rbuf, *gbuf, *bbuf, *abuf; + ImageRec *image; + int y; + + image = ImageOpen(name); + + if(!image) + return NULL; + (*width)=image->xsize; + (*height)=image->ysize; + if (image->zsize != 3 && image->zsize != 4) { + ImageClose(image); + return NULL; + } + + base = (unsigned char*)malloc(image->xsize*image->ysize*sizeof(unsigned int)*3); + rbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); + gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); + bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); + abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); + if(!base || !rbuf || !gbuf || !bbuf || !abuf) { + if (base) free(base); + if (rbuf) free(rbuf); + if (gbuf) free(gbuf); + if (bbuf) free(bbuf); + if (abuf) free(abuf); + return NULL; + } + ptr = base; + for(y=0; yysize; y++) { + if(image->zsize == 4) { + ImageGetRow(image,rbuf,y,0); + ImageGetRow(image,gbuf,y,1); + ImageGetRow(image,bbuf,y,2); + ImageGetRow(image,abuf,y,3); /* Discard. */ + rgbtorgb(rbuf,gbuf,bbuf,ptr,image->xsize); + ptr += (image->xsize * 3); + } else { + ImageGetRow(image,rbuf,y,0); + ImageGetRow(image,gbuf,y,1); + ImageGetRow(image,bbuf,y,2); + rgbtorgb(rbuf,gbuf,bbuf,ptr,image->xsize); + ptr += (image->xsize * 3); + } + } + ImageClose(image); + free(rbuf); + free(gbuf); + free(bbuf); + free(abuf); + + return (GLubyte *) base; +} + +int main(int argc, char **argv) +{ + int width, height; + GLubyte *data; + + if (argc != 2) + { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + data = read_rgb_texture(argv[1], &width, &height); + + printf("P6\n%d %d\n255\n", width, height); + fwrite(data, width * 3, height, stdout); + + return 0; +} + diff --git a/progs/samples/select.c b/progs/samples/select.c new file mode 100644 index 0000000000..5a73a457ab --- /dev/null +++ b/progs/samples/select.c @@ -0,0 +1,456 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + + +#define MAXOBJS 10000 +#define MAXSELECT 100 +#define MAXFEED 300 +#define SOLID 1 +#define LINE 2 +#define POINT 3 + + +GLint windW, windH; + +GLuint selectBuf[MAXSELECT]; +GLfloat feedBuf[MAXFEED]; +GLint vp[4]; +float zRotation = 90.0; +float zoom = 1.0; +GLint objectCount; +GLint numObjects; +struct object { + float v1[2]; + float v2[2]; + float v3[2]; + float color[3]; +} objects[MAXOBJS]; +GLenum linePoly = GL_FALSE; + + +static void InitObjects(GLint num) +{ + GLint i; + float x, y; + + if (num > MAXOBJS) { + num = MAXOBJS; + } + if (num < 1) { + num = 1; + } + objectCount = num; + + srand((unsigned int)time(NULL)); + for (i = 0; i < num; i++) { + x = (rand() % 300) - 150; + y = (rand() % 300) - 150; + + objects[i].v1[0] = x + (rand() % 50) - 25; + objects[i].v2[0] = x + (rand() % 50) - 25; + objects[i].v3[0] = x + (rand() % 50) - 25; + objects[i].v1[1] = y + (rand() % 50) - 25; + objects[i].v2[1] = y + (rand() % 50) - 25; + objects[i].v3[1] = y + (rand() % 50) - 25; + objects[i].color[0] = ((rand() % 100) + 50) / 150.0; + objects[i].color[1] = ((rand() % 100) + 50) / 150.0; + objects[i].color[2] = ((rand() % 100) + 50) / 150.0; + } +} + +static void Init(void) +{ + + numObjects = 10; + InitObjects(numObjects); + glGetIntegerv(GL_VIEWPORT, vp); +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; +} + +static void Render(GLenum mode) +{ + GLint i; + + for (i = 0; i < objectCount; i++) { + if (mode == GL_SELECT) { + glLoadName(i); + } + glColor3fv(objects[i].color); + glBegin(GL_POLYGON); + glVertex2fv(objects[i].v1); + glVertex2fv(objects[i].v2); + glVertex2fv(objects[i].v3); + glEnd(); + } +} + +static GLint DoSelect(GLint x, GLint y) +{ + GLint hits; + + glSelectBuffer(MAXSELECT, selectBuf); + (void)glRenderMode(GL_SELECT); + glInitNames(); + glPushName(~0); + + glPushMatrix(); + + glViewport(0, 0, windW, windH); + glGetIntegerv(GL_VIEWPORT, vp); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPickMatrix(x, windH-y, 4, 4, vp); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0, 0, 1); + + Render(GL_SELECT); + + glPopMatrix(); + + hits = glRenderMode(GL_RENDER); + if (hits <= 0) { + return -1; + } + + return selectBuf[(hits-1)*4+3]; +} + +static void RecolorTri(GLint h) +{ + + objects[h].color[0] = ((rand() % 100) + 50) / 150.0; + objects[h].color[1] = ((rand() % 100) + 50) / 150.0; + objects[h].color[2] = ((rand() % 100) + 50) / 150.0; +} + +static void DeleteTri(GLint h) +{ + + objects[h] = objects[objectCount-1]; + objectCount--; +} + +static void GrowTri(GLint h) +{ + float v[2]; + float *oldV; + GLint i; + + v[0] = objects[h].v1[0] + objects[h].v2[0] + objects[h].v3[0]; + v[1] = objects[h].v1[1] + objects[h].v2[1] + objects[h].v3[1]; + v[0] /= 3; + v[1] /= 3; + + for (i = 0; i < 3; i++) { + switch (i) { + case 0: + oldV = objects[h].v1; + break; + case 1: + oldV = objects[h].v2; + break; + case 2: + oldV = objects[h].v3; + break; + } + oldV[0] = 1.5 * (oldV[0] - v[0]) + v[0]; + oldV[1] = 1.5 * (oldV[1] - v[1]) + v[1]; + } +} + +static void Mouse(int button, int state, int mouseX, int mouseY) +{ + GLint hit; + + if (state != GLUT_DOWN) + return; + + hit = DoSelect((GLint)mouseX, (GLint)mouseY); + if (hit != -1) { + if (button == GLUT_LEFT_BUTTON) { + RecolorTri(hit); + } + if (button == GLUT_MIDDLE_BUTTON) { + GrowTri(hit); + } + if (button == GLUT_RIGHT_BUTTON) { + DeleteTri(hit); + } + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glPushMatrix(); + + glViewport(0, 0, windW, windH); + glGetIntegerv(GL_VIEWPORT, vp); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0, 0, 1); + + Render(GL_RENDER); + + glPopMatrix(); + + glFlush(); +} + +static void DrawZoom(GLint x, GLint y) +{ + + glPushMatrix(); + + glViewport(0, 0, windW, windH); + glGetIntegerv(GL_VIEWPORT, vp); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPickMatrix(x, windH-y, 4, 4, vp); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0, 0, 1); + + Render(GL_RENDER); + + glPopMatrix(); +} + +static void DumpFeedbackVert(GLint *i, GLint n) +{ + GLint index; + + index = *i; + if (index+7 > n) { + *i = n; + printf(" ???\n"); + return; + } + printf(" (%g %g %g), color = (%4.2f %4.2f %4.2f)\n", + feedBuf[index], + feedBuf[index+1], + feedBuf[index+2], + feedBuf[index+3], + feedBuf[index+4], + feedBuf[index+5]); + index += 7; + *i = index; +} + +static void DrawFeedback(GLint n) +{ + GLint i; + GLint verts; + + printf("Feedback results (%d floats):\n", n); + for (i = 0; i < n; i++) { + switch ((GLint)feedBuf[i]) { + case GL_POLYGON_TOKEN: + printf("Polygon"); + i++; + if (i < n) { + verts = (GLint)feedBuf[i]; + i++; + printf(": %d vertices", verts); + } else { + verts = 0; + } + printf("\n"); + while (verts) { + DumpFeedbackVert(&i, n); + verts--; + } + i--; + break; + case GL_LINE_TOKEN: + printf("Line:\n"); + i++; + DumpFeedbackVert(&i, n); + DumpFeedbackVert(&i, n); + i--; + break; + case GL_LINE_RESET_TOKEN: + printf("Line Reset:\n"); + i++; + DumpFeedbackVert(&i, n); + DumpFeedbackVert(&i, n); + i--; + break; + default: + printf("%9.2f\n", feedBuf[i]); + break; + } + } + if (i == MAXFEED) { + printf("...\n"); + } + printf("\n"); +} + +static void DoFeedback(void) +{ + GLint x; + + glFeedbackBuffer(MAXFEED, GL_3D_COLOR, feedBuf); + (void)glRenderMode(GL_FEEDBACK); + + glPushMatrix(); + + glViewport(0, 0, windW, windH); + glGetIntegerv(GL_VIEWPORT, vp); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0, 0, 1); + + Render(GL_FEEDBACK); + + glPopMatrix(); + + x = glRenderMode(GL_RENDER); + if (x == -1) { + x = MAXFEED; + } + + DrawFeedback((GLint)x); +} + +static void Key2(int key, int x, int y) +{ + switch (key) { + case GLUT_KEY_LEFT: + zRotation += 0.5; + break; + case GLUT_KEY_RIGHT: + zRotation -= 0.5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(1); + case 'Z': + zoom /= 0.75; + break; + case 'z': + zoom *= 0.75; + break; + case 'f': + DoFeedback(); + break; + case 'd': + DrawZoom(x, y); + break; + case 'l': + linePoly = !linePoly; + if (linePoly) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + windW = 300; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + type = GLUT_RGB | GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Select Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutMouseFunc(Mouse); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/shape.c b/progs/samples/shape.c new file mode 100644 index 0000000000..d342ee5b07 --- /dev/null +++ b/progs/samples/shape.c @@ -0,0 +1,345 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define OPENGL_WIDTH 24 +#define OPENGL_HEIGHT 13 + + +GLenum rgb, doubleBuffer, windType; +GLint objectIndex = 0; +GLuint bases[20]; +float angleX = 0.0, angleY = 0.0, angleZ = 0.0; +float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0; +float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0; + + +#include "tkmap.c" + +static void Init(void) +{ + + bases[0] = glGenLists(1); + glNewList(bases[0], GL_COMPILE); + glutWireSphere(1.0, 20, 10); + glEndList(); + + bases[1] = glGenLists(1); + glNewList(bases[1], GL_COMPILE); + glutSolidSphere(1.0, 20, 10); + glEndList(); + + bases[2] = glGenLists(1); + glNewList(bases[2], GL_COMPILE); + glutWireCube(1.0); + glEndList(); + + bases[3] = glGenLists(1); + glNewList(bases[3], GL_COMPILE); + glutSolidCube(1.0); + glEndList(); + + bases[4] = glGenLists(1); + glNewList(bases[4], GL_COMPILE); + glutWireTorus(1.0, 1.0, 10, 20); + glEndList(); + + bases[5] = glGenLists(1); + glNewList(bases[5], GL_COMPILE); + glutSolidTorus(1.0, 1.0, 10, 20); + glEndList(); + + bases[6] = glGenLists(1); + glNewList(bases[6], GL_COMPILE); + glutWireIcosahedron(); + glEndList(); + + bases[7] = glGenLists(1); + glNewList(bases[7], GL_COMPILE); + glutSolidIcosahedron(); + glEndList(); + + bases[8] = glGenLists(1); + glNewList(bases[8], GL_COMPILE); + glutWireOctahedron(); + glEndList(); + + bases[9] = glGenLists(1); + glNewList(bases[9], GL_COMPILE); + glutSolidOctahedron(); + glEndList(); + + bases[10] = glGenLists(1); + glNewList(bases[10], GL_COMPILE); + glutWireTetrahedron(); + glEndList(); + + bases[11] = glGenLists(1); + glNewList(bases[11], GL_COMPILE); + glutSolidTetrahedron(); + glEndList(); + + bases[12] = glGenLists(1); + glNewList(bases[12], GL_COMPILE); + glutWireDodecahedron(); + glEndList(); + + bases[13] = glGenLists(1); + glNewList(bases[13], GL_COMPILE); + glutSolidDodecahedron(); + glEndList(); + + bases[14] = glGenLists(1); + glNewList(bases[14], GL_COMPILE); + glutWireCone(5.0, 5.0, 20, 10); + glEndList(); + + bases[15] = glGenLists(1); + glNewList(bases[15], GL_COMPILE); + glutSolidCone(5.0, 5.0, 20, 10); + glEndList(); + + bases[16] = glGenLists(1); + glNewList(bases[16], GL_COMPILE); + glutWireTeapot(1.0); + glEndList(); + + bases[17] = glGenLists(1); + glNewList(bases[17], GL_COMPILE); + glutSolidTeapot(1.0); + glEndList(); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + shiftX -= 20.0; + break; + case GLUT_KEY_RIGHT: + shiftX += 20.0; + break; + case GLUT_KEY_UP: + shiftY += 20.0; + break; + case GLUT_KEY_DOWN: + shiftY -= 20.0; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + + case 32: + objectIndex++; + if (objectIndex > 17) { + objectIndex = 0; + } + break; + + case 'n': + shiftZ += 20.0; + break; + case 'm': + shiftZ -= 20.0; + break; + + case 'q': + scaleX -= 0.1; + if (scaleX < 0.1) { + scaleX = 0.1; + } + break; + case 'w': + scaleX += 0.1; + break; + case 'a': + scaleY -= 0.1; + if (scaleY < 0.1) { + scaleY = 0.1; + } + break; + case 's': + scaleY += 0.1; + break; + case 'z': + scaleZ -= 0.1; + if (scaleZ < 0.1) { + scaleZ = 0.1; + } + break; + case 'x': + scaleZ += 0.1; + break; + + case 'e': + angleX -= 5.0; + if (angleX < 0.0) { + angleX = 360.0 + angleX; + } + break; + case 'r': + angleX += 5.0; + if (angleX > 360.0) { + angleX = angleX - 360.0; + } + break; + case 'd': + angleY -= 5.0; + if (angleY < 0.0) { + angleY = 360.0 + angleY; + } + break; + case 'f': + angleY += 5.0; + if (angleY > 360.0) { + angleY = angleY - 360.0; + } + break; + case 'c': + angleZ -= 5.0; + if (angleZ < 0.0) { + angleZ = 360.0 + angleZ; + } + break; + case 'v': + angleZ += 5.0; + if (angleZ > 360.0) { + angleZ = angleZ - 360.0; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + SetColor(COLOR_WHITE); + + glPushMatrix(); + + glTranslatef(shiftX, shiftY, shiftZ); + glRotatef(angleX, 1.0, 0.0, 0.0); + glRotatef(angleY, 0.0, 1.0, 0.0); + glRotatef(angleZ, 0.0, 0.0, 1.0); + glScalef(scaleX, scaleY, scaleZ); + + glCallList(bases[objectIndex]); + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Font Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/sphere.c b/progs/samples/sphere.c new file mode 100644 index 0000000000..154e85cbec --- /dev/null +++ b/progs/samples/sphere.c @@ -0,0 +1,1034 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* BEP: renamed "nearest" as "nnearest" to avoid math.h collision on AIX */ + +#include +#include +#include +#include +#include + + +#define FALSE 0 +#define TRUE 1 +#ifndef PI +#define PI 3.14159265358979323846 +#endif + + +#include "loadppm.c" + +int rgb; /* unused */ + +#include "tkmap.c" + +GLenum doubleBuffer; +int W = 400, H = 400; + +char *imageFileName = 0; +PPMImage *image; + +int numComponents; + +float *minFilter, *magFilter, *sWrapMode, *tWrapMode; +float decal[] = {GL_DECAL}; +float modulate[] = {GL_MODULATE}; +float repeat[] = {GL_REPEAT}; +float clamp[] = {GL_CLAMP}; +float nnearest[] = {GL_NEAREST}; +float linear[] = {GL_LINEAR}; +float nearest_mipmap_nearest[] = {GL_NEAREST_MIPMAP_NEAREST}; +float nearest_mipmap_linear[] = {GL_NEAREST_MIPMAP_LINEAR}; +float linear_mipmap_nearest[] = {GL_LINEAR_MIPMAP_NEAREST}; +float linear_mipmap_linear[] = {GL_LINEAR_MIPMAP_LINEAR}; +GLint sphereMap[] = {GL_SPHERE_MAP}; + +float xRotation = 0.0, yRotation = 0.0; +float zTranslate = -4.0; +GLenum autoRotate = TRUE; +GLenum deepestColor = COLOR_GREEN; +GLenum isLit = TRUE; +GLenum isFogged = FALSE; +float *textureEnvironment = modulate; + +struct MipMap { + int width, height; + unsigned char *data; +}; + +int cube, cage, cylinder, torus, genericObject; + +float c[6][4][4][3] = { + { + { + { + 1.0, 1.0, -1.0 + }, + { + 0.0, 1.0, -1.0 + }, + { + 0.0, 0.0, -1.0 + }, + { + 1.0, 0.0, -1.0 + }, + }, + { + { + 0.0, 1.0, -1.0 + }, + { + -1.0, 1.0, -1.0 + }, + { + -1.0, 0.0, -1.0 + }, + { + 0.0, 0.0, -1.0 + }, + }, + { + { + 0.0, 0.0, -1.0 + }, + { + -1.0, 0.0, -1.0 + }, + { + -1.0, -1.0, -1.0 + }, + { + 0.0, -1.0, -1.0 + }, + }, + { + { + 1.0, 0.0, -1.0 + }, + { + 0.0, 0.0, -1.0 + }, + { + 0.0, -1.0, -1.0 + }, + { + 1.0, -1.0, -1.0 + }, + }, + }, + { + { + { + 1.0, 1.0, 1.0 + }, + { + 1.0, 1.0, 0.0 + }, + { + 1.0, 0.0, 0.0 + }, + { + 1.0, 0.0, 1.0 + }, + }, + { + { + 1.0, 1.0, 0.0 + }, + { + 1.0, 1.0, -1.0 + }, + { + 1.0, 0.0, -1.0 + }, + { + 1.0, 0.0, 0.0 + }, + }, + { + { + 1.0, 0.0, -1.0 + }, + { + 1.0, -1.0, -1.0 + }, + { + 1.0, -1.0, 0.0 + }, + { + 1.0, 0.0, 0.0 + }, + }, + { + { + 1.0, 0.0, 0.0 + }, + { + 1.0, -1.0, 0.0 + }, + { + 1.0, -1.0, 1.0 + }, + { + 1.0, 0.0, 1.0 + }, + }, + }, + { + { + { + -1.0, 1.0, 1.0 + }, + { + 0.0, 1.0, 1.0 + }, + { + 0.0, 0.0, 1.0 + }, + { + -1.0, 0.0, 1.0 + }, + }, + { + { + 0.0, 1.0, 1.0 + }, + { + 1.0, 1.0, 1.0 + }, + { + 1.0, 0.0, 1.0 + }, + { + 0.0, 0.0, 1.0 + }, + }, + { + { + 1.0, 0.0, 1.0 + }, + { + 1.0, -1.0, 1.0 + }, + { + 0.0, -1.0, 1.0 + }, + { + 0.0, 0.0, 1.0 + }, + }, + { + { + 0.0, -1.0, 1.0 + }, + { + -1.0, -1.0, 1.0 + }, + { + -1.0, 0.0, 1.0 + }, + { + 0.0, 0.0, 1.0 + }, + }, + }, + { + { + { + -1.0, 1.0, -1.0 + }, + { + -1.0, 1.0, 0.0 + }, + { + -1.0, 0.0, 0.0 + }, + { + -1.0, 0.0, -1.0 + }, + }, + { + { + -1.0, 1.0, 0.0 + }, + { + -1.0, 1.0, 1.0 + }, + { + -1.0, 0.0, 1.0 + }, + { + -1.0, 0.0, 0.0 + }, + }, + { + { + -1.0, 0.0, 1.0 + }, + { + -1.0, -1.0, 1.0 + }, + { + -1.0, -1.0, 0.0 + }, + { + -1.0, 0.0, 0.0 + }, + }, + { + { + -1.0, -1.0, 0.0 + }, + { + -1.0, -1.0, -1.0 + }, + { + -1.0, 0.0, -1.0 + }, + { + -1.0, 0.0, 0.0 + }, + }, + }, + { + { + { + -1.0, 1.0, 1.0 + }, + { + -1.0, 1.0, 0.0 + }, + { + 0.0, 1.0, 0.0 + }, + { + 0.0, 1.0, 1.0 + }, + }, + { + { + -1.0, 1.0, 0.0 + }, + { + -1.0, 1.0, -1.0 + }, + { + 0.0, 1.0, -1.0 + }, + { + 0.0, 1.0, 0.0 + }, + }, + { + { + 0.0, 1.0, -1.0 + }, + { + 1.0, 1.0, -1.0 + }, + { + 1.0, 1.0, 0.0 + }, + { + 0.0, 1.0, 0.0 + }, + }, + { + { + 1.0, 1.0, 0.0 + }, + { + 1.0, 1.0, 1.0 + }, + { + 0.0, 1.0, 1.0 + }, + { + 0.0, 1.0, 0.0 + }, + }, + }, + { + { + { + -1.0, -1.0, -1.0 + }, + { + -1.0, -1.0, 0.0 + }, + { + 0.0, -1.0, 0.0 + }, + { + 0.0, -1.0, -1.0 + }, + }, + { + { + -1.0, -1.0, 0.0 + }, + { + -1.0, -1.0, 1.0 + }, + { + 0.0, -1.0, 1.0 + }, + { + 0.0, -1.0, 0.0 + }, + }, + { + { + 0.0, -1.0, 1.0 + }, + { + 1.0, -1.0, 1.0 + }, + { + 1.0, -1.0, 0.0 + }, + { + 0.0, -1.0, 0.0 + }, + }, + { + { + 1.0, -1.0, 0.0 + }, + { + 1.0, -1.0, -1.0 + }, + { + 0.0, -1.0, -1.0 + }, + { + 0.0, -1.0, 0.0 + }, + }, + } +}; + +float n[6][3] = { + { + 0.0, 0.0, -1.0 + }, + { + 1.0, 0.0, 0.0 + }, + { + 0.0, 0.0, 1.0 + }, + { + -1.0, 0.0, 0.0 + }, + { + 0.0, 1.0, 0.0 + }, + { + 0.0, -1.0, 0.0 + } +}; + +GLfloat identity[16] = { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + + +void BuildCylinder(int numEdges) +{ + int i, top = 1.0, bottom = -1.0; + float x[100], y[100], angle; + + for (i = 0; i <= numEdges; i++) { + angle = i * 2.0 * PI / numEdges; + x[i] = cos(angle); /* was cosf() */ + y[i] = sin(angle); /* was sinf() */ + } + + glNewList(cylinder, GL_COMPILE); + glBegin(GL_TRIANGLE_STRIP); + for (i = 0; i <= numEdges; i++) { + glNormal3f(x[i], y[i], 0.0); + glVertex3f(x[i], y[i], bottom); + glVertex3f(x[i], y[i], top); + } + glEnd(); + glBegin(GL_TRIANGLE_FAN); + glNormal3f(0.0, 0.0, 1.0); + glVertex3f(0.0, 0.0, top); + for (i = 0; i <= numEdges; i++) { + glVertex3f(x[i], -y[i], top); + } + glEnd(); + glBegin(GL_TRIANGLE_FAN); + glNormal3f(0.0, 0.0, -1.0); + glVertex3f(0.0, 0.0, bottom); + for (i = 0; i <= numEdges; i++) { + glVertex3f(x[i], y[i], bottom); + } + glEnd(); + glEndList(); +} + +void BuildTorus(float rc, int numc, float rt, int numt) +{ + int i, j, k; + double s, t; + double x, y, z; + double pi, twopi; + + pi = 3.14159265358979323846; + twopi = 2.0 * pi; + + glNewList(torus, GL_COMPILE); + for (i = 0; i < numc; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) { + for (k = 0; k <= 1; k++) { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = cos(t*twopi/numt) * cos(s*twopi/numc); + y = sin(t*twopi/numt) * cos(s*twopi/numc); + z = sin(s*twopi/numc); + glNormal3f(x, y, z); + + x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt); + y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt); + z = rc * sin(s*twopi/numc); + glVertex3f(x, y, z); + } + } + glEnd(); + } + glEndList(); +} + +void BuildCage(void) +{ + int i; + float inc; + float right, left, top, bottom, front, back; + + front = 0.0; + back = -8.0; + + left = -4.0; + bottom = -4.0; + right = 4.0; + top = 4.0; + + inc = 2.0 * 4.0 * 0.1; + + glNewList(cage, GL_COMPILE); + for (i = 0; i < 10; i++) { + + /* + ** Back + */ + glBegin(GL_LINES); + glVertex3f(left+i*inc, top, back); + glVertex3f(left+i*inc, bottom, back); + glEnd(); + glBegin(GL_LINES); + glVertex3f(right, bottom+i*inc, back); + glVertex3f(left, bottom+i*inc, back); + glEnd(); + + /* + ** Front + */ + glBegin(GL_LINES); + glVertex3f(left+i*inc, top, front); + glVertex3f(left+i*inc, bottom, front); + glEnd(); + glBegin(GL_LINES); + glVertex3f(right, bottom+i*inc, front); + glVertex3f(left, bottom+i*inc, front); + glEnd(); + + /* + ** Left + */ + glBegin(GL_LINES); + glVertex3f(left, bottom+i*inc, front); + glVertex3f(left, bottom+i*inc, back); + glEnd(); + glBegin(GL_LINES); + glVertex3f(left, top, back+i*inc); + glVertex3f(left, bottom, back+i*inc); + glEnd(); + + /* + ** Right + */ + glBegin(GL_LINES); + glVertex3f(right, top-i*inc, front); + glVertex3f(right, top-i*inc, back); + glEnd(); + glBegin(GL_LINES); + glVertex3f(right, top, back+i*inc); + glVertex3f(right, bottom, back+i*inc); + glEnd(); + + /* + ** Top + */ + glBegin(GL_LINES); + glVertex3f(left+i*inc, top, front); + glVertex3f(left+i*inc, top, back); + glEnd(); + glBegin(GL_LINES); + glVertex3f(right, top, back+i*inc); + glVertex3f(left, top, back+i*inc); + glEnd(); + + /* + ** Bottom + */ + glBegin(GL_LINES); + glVertex3f(right-i*inc, bottom, front); + glVertex3f(right-i*inc, bottom, back); + glEnd(); + glBegin(GL_LINES); + glVertex3f(right, bottom, back+i*inc); + glVertex3f(left, bottom, back+i*inc); + glEnd(); + } + glEndList(); +} + +void BuildCube(void) +{ + int i, j; + + glNewList(cube, GL_COMPILE); + for (i = 0; i < 6; i++) { + for (j = 0; j < 4; j++) { + glNormal3fv(n[i]); + glBegin(GL_POLYGON); + glVertex3fv(c[i][j][0]); + glVertex3fv(c[i][j][1]); + glVertex3fv(c[i][j][2]); + glVertex3fv(c[i][j][3]); + glEnd(); + } + } + glEndList(); +} + +void BuildLists(void) +{ + + cube = glGenLists(1); + BuildCube(); + + cage = glGenLists(2); + BuildCage(); + + cylinder = glGenLists(3); + BuildCylinder(60); + + torus = glGenLists(4); + BuildTorus(0.65, 20, .85, 65); + + genericObject = torus; +} + +void SetDeepestColor(void) +{ + GLint redBits, greenBits, blueBits; + + glGetIntegerv(GL_RED_BITS, &redBits); + glGetIntegerv(GL_GREEN_BITS, &greenBits); + glGetIntegerv(GL_BLUE_BITS, &blueBits); + + deepestColor = (redBits >= greenBits) ? COLOR_RED : COLOR_GREEN; + deepestColor = (deepestColor >= blueBits) ? deepestColor : COLOR_BLUE; +} + +void SetDefaultSettings(void) +{ + + magFilter = nnearest; + minFilter = nnearest; + sWrapMode = repeat; + tWrapMode = repeat; + textureEnvironment = modulate; + autoRotate = TRUE; +} + +unsigned char *AlphaPadImage(int bufSize, unsigned char *inData, int alpha) +{ + unsigned char *outData, *out_ptr, *in_ptr; + int i; + + outData = (unsigned char *) malloc(bufSize * 4); + out_ptr = outData; + in_ptr = inData; + + for (i = 0; i < bufSize; i++) { + *out_ptr++ = *in_ptr++; + *out_ptr++ = *in_ptr++; + *out_ptr++ = *in_ptr++; + *out_ptr++ = alpha; + } + + free (inData); + return outData; +} + +void Init(void) +{ + float ambient[] = {0.0, 0.0, 0.0, 1.0}; + float diffuse[] = {0.0, 1.0, 0.0, 1.0}; + float specular[] = {1.0, 1.0, 1.0, 1.0}; + float position[] = {2.0, 2.0, 0.0, 1.0}; + float fog_color[] = {0.0, 0.0, 0.0, 1.0}; + float mat_ambient[] = {0.0, 0.0, 0.0, 1.0}; + float mat_shininess[] = {90.0}; + float mat_specular[] = {1.0, 1.0, 1.0, 1.0}; + float mat_diffuse[] = {1.0, 1.0, 1.0, 1.0}; + float lmodel_ambient[] = {0.0, 0.0, 0.0, 1.0}; + float lmodel_twoside[] = {GL_TRUE}; + + SetDeepestColor(); + SetDefaultSettings(); + + if (numComponents == 4) { + image = LoadPPM(imageFileName); + image->data = AlphaPadImage(image->sizeX*image->sizeY, + image->data, 128); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gluBuild2DMipmaps(GL_TEXTURE_2D, numComponents, + image->sizeX, image->sizeY, + GL_RGBA, GL_UNSIGNED_BYTE, image->data); + } else { + image = LoadPPM(imageFileName); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gluBuild2DMipmaps(GL_TEXTURE_2D, numComponents, + image->sizeX, image->sizeY, + GL_RGB, GL_UNSIGNED_BYTE, image->data); + } + + glFogf(GL_FOG_DENSITY, 0.125); + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, 4.0); + glFogf(GL_FOG_END, 9.0); + glFogfv(GL_FOG_COLOR, fog_color); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, specular); + glLightfv(GL_LIGHT0, GL_POSITION, position); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glShadeModel(GL_SMOOTH); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glViewport(0, 0, W, H); + glEnable(GL_DEPTH_TEST); + + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + glEnable(GL_TEXTURE_2D); + glTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, sphereMap); + glTexGeniv(GL_T, GL_TEXTURE_GEN_MODE, sphereMap); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, sWrapMode); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tWrapMode); + + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment); + + BuildLists(); +} + +void ReInit(void) +{ + + if (genericObject == torus) { + glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + } + if (isFogged) { + textureEnvironment = modulate; + } + + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment); +} + +void Draw(void) +{ + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-0.2, 0.2, -0.2, 0.2, 0.15, 9.0); + glMatrixMode(GL_MODELVIEW); + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + if (isFogged) { + glEnable(GL_FOG); + glColor3fv(RGBMap[deepestColor]); + } else { + glColor3fv(RGBMap[COLOR_WHITE]); + } + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_TEXTURE_2D); + glCallList(cage); + + glPushMatrix(); + glTranslatef(0.0, 0.0, zTranslate); + glRotatef(xRotation, 1, 0, 0); + glRotatef(yRotation, 0, 1, 0); + + if (isLit == TRUE) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + } + + glEnable(GL_TEXTURE_2D); + if (isFogged) { + glDisable(GL_FOG); + } + glPolygonMode(GL_FRONT, GL_FILL); + glColor3fv(RGBMap[deepestColor]); + glCallList(genericObject); + + glPopMatrix(); + glFlush(); + + if (autoRotate) { + xRotation += .75; + yRotation += .375; + } + glutSwapBuffers(); +} + +void Reshape(int width, int height) +{ + + W = width; + H = height; + ReInit(); + glViewport( 0, 0, width, height ); /*new*/ +} + +void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + yRotation -= 0.5; + autoRotate = FALSE; + ReInit(); + break; + case GLUT_KEY_RIGHT: + yRotation += 0.5; + autoRotate = FALSE; + ReInit(); + break; + case GLUT_KEY_UP: + xRotation -= 0.5; + autoRotate = FALSE; + ReInit(); + break; + case GLUT_KEY_DOWN: + xRotation += 0.5; + autoRotate = FALSE; + ReInit(); + break; + default: + return; + } +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + free(image->data); + exit(1); + + case 'a': + autoRotate = !autoRotate; + ReInit(); + break; + case 'c': + genericObject = (genericObject == cube) ? cylinder : cube; + ReInit(); + break; + case 'd': + textureEnvironment = decal; + ReInit(); + break; + case 'm': + textureEnvironment = modulate; + ReInit(); + break; + case 'l': + isLit = !isLit; + ReInit(); + break; + case 'f': + isFogged = !isFogged; + ReInit(); + break; + case 't': + genericObject = torus; + ReInit(); + break; + case '0': + magFilter = nnearest; + ReInit(); + break; + case '1': + magFilter = linear; + ReInit(); + break; + case '2': + minFilter = nnearest; + ReInit(); + break; + case '3': + minFilter = linear; + ReInit(); + break; + case '4': + minFilter = nearest_mipmap_nearest; + ReInit(); + break; + case '5': + minFilter = nearest_mipmap_linear; + ReInit(); + break; + case '6': + minFilter = linear_mipmap_nearest; + ReInit(); + break; + case '7': + minFilter = linear_mipmap_linear; + ReInit(); + break; + default: + return; + } +} + +GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + numComponents = 4; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-f") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-f (No file name).\n"); + return GL_FALSE; + } else { + imageFileName = argv[++i]; + } + } else if (strcmp(argv[i], "-4") == 0) { + numComponents = 4; + } else if (strcmp(argv[i], "-3") == 0) { + numComponents = 3; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + glutPostRedisplay(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + if (imageFileName == 0) { + printf("No image file.\n"); + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( W, H); + + type = GLUT_RGB | GLUT_DEPTH; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Texture Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutIdleFunc(glut_post_redisplay_p); + + glutMainLoop(); + return 0; +} diff --git a/progs/samples/star.c b/progs/samples/star.c new file mode 100644 index 0000000000..180585e121 --- /dev/null +++ b/progs/samples/star.c @@ -0,0 +1,331 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +#ifndef PI +#define PI 3.141592657 +#endif + +enum { + NORMAL = 0, + WEIRD = 1 +}; + +enum { + STREAK = 0, + CIRCLE = 1 +}; + +#define MAXSTARS 400 +#define MAXPOS 10000 +#define MAXWARP 10 +#define MAXANGLES 6000 + + +typedef struct _starRec { + GLint type; + float x[2], y[2], z[2]; + float offsetX, offsetY, offsetR, rotation; +} starRec; + + +GLenum doubleBuffer; +GLint windW, windH; + +GLenum flag = NORMAL; +GLint starCount = MAXSTARS / 2; +float speed = 1.0; +GLint nitro = 0; +starRec stars[MAXSTARS]; +float sinTable[MAXANGLES]; + + +float Sin(float angle) +{ + + return (sinTable[(GLint)angle]); +} + +float Cos(float angle) +{ + + return (sinTable[((GLint)angle+(MAXANGLES/4))%MAXANGLES]); +} + +void NewStar(GLint n, GLint d) +{ + + if (rand()%4 == 0) { + stars[n].type = CIRCLE; + } else { + stars[n].type = STREAK; + } + stars[n].x[0] = (float)(rand() % MAXPOS - MAXPOS / 2); + stars[n].y[0] = (float)(rand() % MAXPOS - MAXPOS / 2); + stars[n].z[0] = (float)(rand() % MAXPOS + d); + if (rand()%4 == 0 && flag == WEIRD) { + stars[n].offsetX = (float)(rand() % 100 - 100 / 2); + stars[n].offsetY = (float)(rand() % 100 - 100 / 2); + stars[n].offsetR = (float)(rand() % 25 - 25 / 2); + } else { + stars[n].offsetX = 0.0; + stars[n].offsetY = 0.0; + stars[n].offsetR = 0.0; + } +} + +void RotatePoint(float *x, float *y, float rotation) +{ + float tmpX, tmpY; + + tmpX = *x * Cos(rotation) - *y * Sin(rotation); + tmpY = *y * Cos(rotation) + *x * Sin(rotation); + *x = tmpX; + *y = tmpY; +} + +void MoveStars(void) +{ + float offset; + GLint n; + + offset = speed * 60.0; + + for (n = 0; n < starCount; n++) { + stars[n].x[1] = stars[n].x[0]; + stars[n].y[1] = stars[n].y[0]; + stars[n].z[1] = stars[n].z[0]; + stars[n].x[0] += stars[n].offsetX; + stars[n].y[0] += stars[n].offsetY; + stars[n].z[0] -= offset; + stars[n].rotation += stars[n].offsetR; + if (stars[n].rotation > MAXANGLES) { + stars[n].rotation = 0.0; + } + } +} + +GLenum StarPoint(GLint n) +{ + float x0, y0, x1, y1, width; + GLint i; + + x0 = stars[n].x[0] * windW / stars[n].z[0]; + y0 = stars[n].y[0] * windH / stars[n].z[0]; + RotatePoint(&x0, &y0, stars[n].rotation); + x0 += windW / 2.0; + y0 += windH / 2.0; + + if (x0 >= 0.0 && x0 < windW && y0 >= 0.0 && y0 < windH) { + if (stars[n].type == STREAK) { + x1 = stars[n].x[1] * windW / stars[n].z[1]; + y1 = stars[n].y[1] * windH / stars[n].z[1]; + RotatePoint(&x1, &y1, stars[n].rotation); + x1 += windW / 2.0; + y1 += windH / 2.0; + + glLineWidth(MAXPOS/100.0/stars[n].z[0]+1.0); + glColor3f(1.0, (MAXWARP-speed)/MAXWARP, (MAXWARP-speed)/MAXWARP); + if (fabs(x0-x1) < 1.0 && fabs(y0-y1) < 1.0) { + glBegin(GL_POINTS); + glVertex2f(x0, y0); + glEnd(); + } else { + glBegin(GL_LINES); + glVertex2f(x0, y0); + glVertex2f(x1, y1); + glEnd(); + } + } else { + width = MAXPOS / 10.0 / stars[n].z[0] + 1.0; + glColor3f(1.0, 0.0, 0.0); + glBegin(GL_POLYGON); + for (i = 0; i < 8; i++) { + float x = x0 + width * Cos((float)i*MAXANGLES/8.0); + float y = y0 + width * Sin((float)i*MAXANGLES/8.0); + glVertex2f(x, y); + }; + glEnd(); + } + return GL_TRUE; + } else { + return GL_FALSE; + } +} + +void ShowStars(void) +{ + GLint n; + + glClear(GL_COLOR_BUFFER_BIT); + + for (n = 0; n < starCount; n++) { + if (stars[n].z[0] > speed || (stars[n].z[0] > 0.0 && speed < MAXWARP)) { + if (StarPoint(n) == GL_FALSE) { + NewStar(n, MAXPOS); + } + } else { + NewStar(n, MAXPOS); + } + } +} + +static void Init(void) +{ + float angle; + GLint n; + + srand((unsigned int) glutGet(GLUT_ELAPSED_TIME) ); + + for (n = 0; n < MAXSTARS; n++) { + NewStar(n, 100); + } + + angle = 0.0; + for (n = 0; n < MAXANGLES ; n++) { + sinTable[n] = sin(angle); + angle += PI / (MAXANGLES / 2.0); + } + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glDisable(GL_DITHER); +} + +void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; + + glViewport(0, 0, windW, windH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, windW+0.5, -0.5, windH+0.5); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 32: + flag = (flag == NORMAL) ? WEIRD : NORMAL; + break; + case 't': + nitro = 1; + break; + default: + return; + } +} + +void Draw(void) +{ + + MoveStars(); + ShowStars(); + if (nitro > 0) { + speed = (float)(nitro / 10) + 1.0; + if (speed > MAXWARP) { + speed = MAXWARP; + } + if (++nitro > MAXWARP*10) { + nitro = -nitro; + } + } else if (nitro < 0) { + nitro++; + speed = (float)(-nitro / 10) + 1.0; + if (speed > MAXWARP) { + speed = MAXWARP; + } + } + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } + } + return GL_TRUE; +} + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + glutPostRedisplay(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 300; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Stars") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutIdleFunc(glut_post_redisplay_p); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/stencil.c b/progs/samples/stencil.c new file mode 100644 index 0000000000..e00bbb61b0 --- /dev/null +++ b/progs/samples/stencil.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +static void Init(void) +{ + glShadeModel(GL_FLAT); + glClearColor(0.0, 0.0, 0.0, 0.0); + + glClearStencil(0); + glStencilMask(1); + glEnable(GL_STENCIL_TEST); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + } +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + + glStencilFunc(GL_ALWAYS, 1, 1); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + + glColor3ub(200, 0, 0); + glBegin(GL_POLYGON); + glVertex3i(-4, -4, 0); + glVertex3i( 4, -4, 0); + glVertex3i( 0, 4, 0); + glEnd(); + + glStencilFunc(GL_EQUAL, 1, 1); + glStencilOp(GL_INCR, GL_KEEP, GL_DECR); + + glColor3ub(0, 200, 0); + glBegin(GL_POLYGON); + glVertex3i(3, 3, 0); + glVertex3i(-3, 3, 0); + glVertex3i(-3, -3, 0); + glVertex3i(3, -3, 0); + glEnd(); + + glStencilFunc(GL_EQUAL, 1, 1); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + + glColor3ub(0, 0, 200); + glBegin(GL_POLYGON); + glVertex3i(3, 3, 0); + glVertex3i(-3, 3, 0); + glVertex3i(-3, -3, 0); + glVertex3i(3, -3, 0); + glEnd(); + + glFlush(); +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-dr") == 0) { + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB | GLUT_SINGLE | GLUT_STENCIL; + glutInitDisplayMode(type); + + if (glutCreateWindow("Stencil Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/stretch.c b/progs/samples/stretch.c new file mode 100644 index 0000000000..3f610e77de --- /dev/null +++ b/progs/samples/stretch.c @@ -0,0 +1,375 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +#define STEPCOUNT 40 +#define FALSE 0 +#define TRUE 1 +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + + +enum { + OP_NOOP = 0, + OP_STRETCH, + OP_DRAWPOINT, + OP_DRAWIMAGE +}; + + +typedef struct _cRec { + float x, y; +} cRec; + +typedef struct _vertexRec { + float x, y; + float dX, dY; + float tX, tY; +} vertexRec; + + +#include "loadppm.c" + +GLenum doubleBuffer; +int imageSizeX, imageSizeY; +char *fileName = 0; +PPMImage *image; +cRec cList[50]; +vertexRec vList[5]; +int cCount, cIndex[2], cStep; +GLenum op = OP_NOOP; + + +void DrawImage(void) +{ + + glRasterPos2i(0, 0); + glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, + image->data); + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } + + glRasterPos2i(0, 0); + glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE, + image->data); +} + +void DrawPoint(void) +{ + int i; + + glColor3f(1.0, 0.0, 1.0); + glPointSize(3.0); + glBegin(GL_POINTS); + for (i = 0; i < cCount; i++) { + glVertex2f(cList[i].x, cList[i].y); + } + glEnd(); + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +void InitVList(void) +{ + + vList[0].x = 0.0; + vList[0].y = 0.0; + vList[0].dX = 0.0; + vList[0].dY = 0.0; + vList[0].tX = 0.0; + vList[0].tY = 0.0; + + vList[1].x = (float)imageSizeX; + vList[1].y = 0.0; + vList[1].dX = 0.0; + vList[1].dY = 0.0; + vList[1].tX = 1.0; + vList[1].tY = 0.0; + + vList[2].x = (float)imageSizeX; + vList[2].y = (float)imageSizeY; + vList[2].dX = 0.0; + vList[2].dY = 0.0; + vList[2].tX = 1.0; + vList[2].tY = 1.0; + + vList[3].x = 0.0; + vList[3].y = (float)imageSizeY; + vList[3].dX = 0.0; + vList[3].dY = 0.0; + vList[3].tX = 0.0; + vList[3].tY = 1.0; + + vList[4].x = cList[0].x; + vList[4].y = cList[0].y; + vList[4].dX = (cList[1].x - cList[0].x) / STEPCOUNT; + vList[4].dY = (cList[1].y - cList[0].y) / STEPCOUNT; + vList[4].tX = cList[0].x / (float)imageSizeX; + vList[4].tY = cList[0].y / (float)imageSizeY; +} + +void ScaleImage(int sizeX, int sizeY) +{ + GLubyte *buf; + + buf = (GLubyte *)malloc(3*sizeX*sizeY); + gluScaleImage(GL_RGB, image->sizeX, image->sizeY, GL_UNSIGNED_BYTE, + image->data, sizeX, sizeY, GL_UNSIGNED_BYTE, buf); + free(image->data); + image->data = buf; + image->sizeX = sizeX; + image->sizeY = sizeY; +} + +void SetPoint(int x, int y) +{ + + cList[cCount].x = (float)x; + cList[cCount].y = (float)y; + cCount++; +} + +void Stretch(void) +{ + + glBegin(GL_TRIANGLES); + glTexCoord2f(vList[0].tX, vList[0].tY); + glVertex2f(vList[0].x, vList[0].y); + glTexCoord2f(vList[1].tX, vList[1].tY); + glVertex2f(vList[1].x, vList[1].y); + glTexCoord2f(vList[4].tX, vList[4].tY); + glVertex2f(vList[4].x, vList[4].y); + glEnd(); + + glBegin(GL_TRIANGLES); + glTexCoord2f(vList[1].tX, vList[1].tY); + glVertex2f(vList[1].x, vList[1].y); + glTexCoord2f(vList[2].tX, vList[2].tY); + glVertex2f(vList[2].x, vList[2].y); + glTexCoord2f(vList[4].tX, vList[4].tY); + glVertex2f(vList[4].x, vList[4].y); + glEnd(); + + glBegin(GL_TRIANGLES); + glTexCoord2f(vList[2].tX, vList[2].tY); + glVertex2f(vList[2].x, vList[2].y); + glTexCoord2f(vList[3].tX, vList[3].tY); + glVertex2f(vList[3].x, vList[3].y); + glTexCoord2f(vList[4].tX, vList[4].tY); + glVertex2f(vList[4].x, vList[4].y); + glEnd(); + + glBegin(GL_TRIANGLES); + glTexCoord2f(vList[3].tX, vList[3].tY); + glVertex2f(vList[3].x, vList[3].y); + glTexCoord2f(vList[0].tX, vList[0].tY); + glVertex2f(vList[0].x, vList[0].y); + glTexCoord2f(vList[4].tX, vList[4].tY); + glVertex2f(vList[4].x, vList[4].y); + glEnd(); + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } + + if (++cStep < STEPCOUNT) { + vList[4].x += vList[4].dX; + vList[4].y += vList[4].dY; + } else { + cIndex[0] = cIndex[1]; + cIndex[1] = cIndex[1] + 1; + if (cIndex[1] == cCount) { + cIndex[1] = 0; + } + vList[4].dX = (cList[cIndex[1]].x - cList[cIndex[0]].x) / STEPCOUNT; + vList[4].dY = (cList[cIndex[1]].y - cList[cIndex[0]].y) / STEPCOUNT; + cStep = 0; + } +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + free(image->data); + exit(1); + case 32: + if (cCount > 1) { + InitVList(); + cIndex[0] = 0; + cIndex[1] = 1; + cStep = 0; + glEnable(GL_TEXTURE_2D); + op = OP_STRETCH; + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +void Mouse(int button, int state, int mouseX, int mouseY) +{ + + if (state != GLUT_DOWN) + return; + + if (op == OP_STRETCH) { + glDisable(GL_TEXTURE_2D); + cCount = 0; + op = OP_DRAWIMAGE; + } else { + SetPoint(mouseX, imageSizeY-mouseY); + op = OP_DRAWPOINT; + } + + glutPostRedisplay(); +} + +void Animate(void) +{ + + switch (op) { + case OP_STRETCH: + Stretch(); + break; + case OP_DRAWPOINT: + DrawPoint(); + break; + case OP_DRAWIMAGE: + DrawImage(); + break; + default: + break; + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-f") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-f (No file name).\n"); + return GL_FALSE; + } else { + fileName = argv[++i]; + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + glutPostRedisplay(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + if (fileName == 0) { + printf("No image file.\n"); + exit(1); + } + + image = LoadPPM(fileName); + + /* changed powf and logf to pow and log -Brian */ + imageSizeX = (int)pow(2.0, (float)((int)(log(image->sizeX)/log(2.0)))); + imageSizeY = (int)pow(2.0, (float)((int)(log(image->sizeY)/log(2.0)))); + + glutInitWindowPosition(0, 0); glutInitWindowSize( imageSizeX, imageSizeY); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Stretch") == GL_FALSE) { + exit(1); + } + + glViewport(0, 0, imageSizeX, imageSizeY); + gluOrtho2D(0, imageSizeX, 0, imageSizeY); + glClearColor(0.0, 0.0, 0.0, 0.0); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + ScaleImage(imageSizeX, imageSizeY); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, 3, image->sizeX, image->sizeY, 0, + GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)image->data); + + cCount = 0; + cIndex[0] = 0; + cIndex[1] = 0; + cStep = 0; + op = OP_DRAWIMAGE; + + glutKeyboardFunc(Key); + glutMouseFunc(Mouse); + glutDisplayFunc(Animate); + glutIdleFunc(glut_post_redisplay_p); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/texture.c b/progs/samples/texture.c new file mode 100644 index 0000000000..7ee41eef28 --- /dev/null +++ b/progs/samples/texture.c @@ -0,0 +1,474 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + + +#include "loadppm.c" + +GLenum doubleBuffer; + +char *texFileName = 0; +PPMImage *image; + +float *minFilter, *magFilter, *sWrapMode, *tWrapMode; +float decal[] = {GL_DECAL}; +float modulate[] = {GL_MODULATE}; +float repeat[] = {GL_REPEAT}; +float clamp[] = {GL_CLAMP}; +float nr[] = {GL_NEAREST}; +float ln[] = {GL_LINEAR}; +float nr_mipmap_nr[] = {GL_NEAREST_MIPMAP_NEAREST}; +float nr_mipmap_ln[] = {GL_NEAREST_MIPMAP_LINEAR}; +float ln_mipmap_nr[] = {GL_LINEAR_MIPMAP_NEAREST}; +float ln_mipmap_ln[] = {GL_LINEAR_MIPMAP_LINEAR}; +GLint sphereMap[] = {GL_SPHERE_MAP}; + +GLenum doSphere = GL_FALSE; +float xRotation = 0.0, yRotation = 0.0, zTranslate = -3.125; + +GLint cube; +float c[6][4][3] = { + { + { + 1.0, 1.0, -1.0 + }, + { + -1.0, 1.0, -1.0 + }, + { + -1.0, -1.0, -1.0 + }, + { + 1.0, -1.0, -1.0 + } + }, + { + { + 1.0, 1.0, 1.0 + }, + { + 1.0, 1.0, -1.0 + }, + { + 1.0, -1.0, -1.0 + }, + { + 1.0, -1.0, 1.0 + } + }, + { + { + -1.0, 1.0, 1.0 + }, + { + 1.0, 1.0, 1.0 + }, + { + 1.0, -1.0, 1.0 + }, + { + -1.0, -1.0, 1.0 + } + }, + { + { + -1.0, 1.0, -1.0 + }, + { + -1.0, 1.0, 1.0 + }, + { + -1.0, -1.0, 1.0 + }, + { + -1.0, -1.0, -1.0 + } + }, + { + { + -1.0, 1.0, 1.0 + }, + { + -1.0, 1.0, -1.0 + }, + { + 1.0, 1.0, -1.0 + }, + { + 1.0, 1.0, 1.0 + } + }, + { + { + -1.0, -1.0, -1.0 + }, + { + -1.0, -1.0, 1.0 + }, + { + 1.0, -1.0, 1.0 + }, + { + 1.0, -1.0, -1.0 + } + } +}; +static float n[6][3] = { + { + 0.0, 0.0, -1.0 + }, + { + 1.0, 0.0, 0.0 + }, + { + 0.0, 0.0, 1.0 + }, + { + -1.0, 0.0, 0.0 + }, + { + 0.0, 1.0, 0.0 + }, + { + 0.0, -1.0, 0.0 + } +}; +static float t[6][4][2] = { + { + { + 1.1, 1.1 + }, + { + -0.1, 1.1 + }, + { + -0.1, -0.1 + }, + { + 1.1, -0.1 + } + }, + { + { + 1.1, 1.1 + }, + { + -0.1, 1.1 + }, + { + -0.1, -0.1 + }, + { + 1.1, -0.1 + } + }, + { + { + -0.1, 1.1 + }, + { + 1.1, 1.1 + }, + { + 1.1, -0.1 + }, + { + -0.1, -0.1 + } + }, + { + { + 1.1, 1.1 + }, + { + -0.1, 1.1 + }, + { + -0.1, -0.1 + }, + { + 1.1, -0.1 + } + }, + { + { + 1.1, 1.1 + }, + { + -0.1, 1.1 + }, + { + -0.1, -0.1 + }, + { + 1.1, -0.1 + } + }, + { + { + 1.1, 1.1 + }, + { + -0.1, 1.1 + }, + { + -0.1, -0.1 + }, + { + 1.1, -0.1 + } + }, +}; + +static void BuildCube(void) +{ + GLint i; + + glNewList(cube, GL_COMPILE); + for (i = 0; i < 6; i++) { + glBegin(GL_POLYGON); + glNormal3fv(n[i]); glTexCoord2fv(t[i][0]); glVertex3fv(c[i][0]); + glNormal3fv(n[i]); glTexCoord2fv(t[i][1]); glVertex3fv(c[i][1]); + glNormal3fv(n[i]); glTexCoord2fv(t[i][2]); glVertex3fv(c[i][2]); + glNormal3fv(n[i]); glTexCoord2fv(t[i][3]); glVertex3fv(c[i][3]); + glEnd(); + } + glEndList(); +} + +static void BuildLists(void) +{ + + cube = glGenLists(1); + BuildCube(); +} + +static void Init(void) +{ + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY, + GL_RGB, GL_UNSIGNED_BYTE, image->data); + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal); + glEnable(GL_TEXTURE_2D); + + glFrontFace(GL_CCW); + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + + BuildLists(); + + glClearColor(0.0, 0.0, 0.0, 0.0); + + magFilter = nr; + minFilter = nr; + sWrapMode = repeat; + tWrapMode = repeat; +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(145.0, 1.0, 0.01, 1000); + glMatrixMode(GL_MODELVIEW); +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + yRotation -= 0.5; + break; + case GLUT_KEY_RIGHT: + yRotation += 0.5; + break; + case GLUT_KEY_UP: + xRotation -= 0.5; + break; + case GLUT_KEY_DOWN: + xRotation += 0.5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + + case 'T': + zTranslate += 0.25; + break; + case 't': + zTranslate -= 0.25; + break; + + case 's': + doSphere = !doSphere; + if (doSphere) { + glTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, sphereMap); + glTexGeniv(GL_T, GL_TEXTURE_GEN_MODE, sphereMap); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } else { + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + } + break; + + case '0': + magFilter = nr; + break; + case '1': + magFilter = ln; + break; + case '2': + minFilter = nr; + break; + case '3': + minFilter = ln; + break; + case '4': + minFilter = nr_mipmap_nr; + break; + case '5': + minFilter = nr_mipmap_ln; + break; + case '6': + minFilter = ln_mipmap_nr; + break; + case '7': + minFilter = ln_mipmap_ln; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + + glClear(GL_COLOR_BUFFER_BIT); + + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, sWrapMode); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tWrapMode); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); + + glPushMatrix(); + + glTranslatef(0.0, 0.0, zTranslate); + glRotatef(xRotation, 1, 0, 0); + glRotatef(yRotation, 0, 1, 0); + glCallList(cube); + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-f") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-f (No file name).\n"); + return GL_FALSE; + } else { + texFileName = argv[++i]; + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + if (texFileName == 0) { + printf("No image file.\n"); + exit(1); + } + + image = LoadPPM(texFileName); + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Texture Test") == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/tkmap.c b/progs/samples/tkmap.c new file mode 100644 index 0000000000..3ded79caca --- /dev/null +++ b/progs/samples/tkmap.c @@ -0,0 +1,71 @@ + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +static float RGBMap[9][3] = { + {0, 0, 0}, + {1, 0, 0}, + {0, 1, 0}, + {1, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {0, 1, 1}, + {1, 1, 1}, + {0.5, 0.5, 0.5} +}; + +static void SetColor(int c) +{ + if (glutGet(GLUT_WINDOW_RGBA)) + glColor3fv(RGBMap[c]); + else + glIndexf(c); +} + +static void InitMap(void) +{ + int i; + + if (rgb) + return; + + for (i = 0; i < 9; i++) + glutSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]); +} + +static void SetFogRamp(int density, int startIndex) +{ + int fogValues, colorValues; + int i, j, k; + float intensity; + + fogValues = 1 << density; + colorValues = 1 << startIndex; + for (i = 0; i < colorValues; i++) { + for (j = 0; j < fogValues; j++) { + k = i * fogValues + j; + intensity = (i * fogValues + j * colorValues) / 255.0; + glutSetColor(k, intensity, intensity, intensity); + } + } +} + +static void SetGreyRamp(void) +{ + int i; + float intensity; + + for (i = 0; i < 255; i++) { + intensity = i / 255.0; + glutSetColor(i, intensity, intensity, intensity); + } +} + diff --git a/progs/samples/tri.c b/progs/samples/tri.c new file mode 100644 index 0000000000..700325132e --- /dev/null +++ b/progs/samples/tri.c @@ -0,0 +1,403 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define SOLID 1 +#define LINE 2 +#define POINT 3 + + +GLenum rgb, doubleBuffer, windType; +GLint windW, windH; + +GLenum dithering = GL_TRUE; +GLenum showVerticies = GL_TRUE; +GLenum hideBottomTriangle = GL_FALSE; +GLenum outline = GL_TRUE; +GLenum culling = GL_FALSE; +GLenum winding = GL_FALSE; +GLenum face = GL_FALSE; +GLenum state = SOLID; +GLenum aaMode = GL_FALSE; +GLenum shade = GL_TRUE; + +GLint color1, color2, color3; + +float zRotation = 90.0; +float zoom = 1.0; + +float boxA[3] = {-100, -100, 0}; +float boxB[3] = { 100, -100, 0}; +float boxC[3] = { 100, 100, 0}; +float boxD[3] = {-100, 100, 0}; + +float p0[3] = {-125,-80, 0}; +float p1[3] = {-125, 80, 0}; +float p2[3] = { 172, 0, 0}; + + +#include "tkmap.c" + +static void Init(void) +{ + float r, g, b; + float percent1, percent2; + GLint i, j; + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glLineStipple(1, 0xF0F0); + + glEnable(GL_SCISSOR_TEST); + + if (!rgb) { + for (j = 0; j <= 12; j++) { + if (j <= 6) { + percent1 = j / 6.0; + r = 1.0 - 0.8 * percent1; + g = 0.2 + 0.8 * percent1; + b = 0.2; + } else { + percent1 = (j - 6) / 6.0; + r = 0.2; + g = 1.0 - 0.8 * percent1; + b = 0.2 + 0.8 * percent1; + } + glutSetColor(j+18, r, g, b); + for (i = 0; i < 16; i++) { + percent2 = i / 15.0; + glutSetColor(j*16+1+32, r*percent2, g*percent2, b*percent2); + } + } + color1 = 18; + color2 = 24; + color3 = 30; + } +} + +static void Reshape(int width, int height) +{ + + windW = (GLint)width; + windH = (GLint)height; +} + +static void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + zRotation += 0.5; + break; + case GLUT_KEY_RIGHT: + zRotation -= 0.5; + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'Z': + zoom *= 0.75; + break; + case 'z': + zoom /= 0.75; + if (zoom > 10) { + zoom = 10; + } + break; + case '1': + glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); + break; + case '2': + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + break; + case '3': + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + break; + case '4': + state = POINT; + break; + case '5': + state = LINE; + break; + case '6': + state = SOLID; + break; + case '7': + culling = !culling; + break; + case '8': + winding = !winding; + break; + case '9': + face = !face; + break; + case 'v': + showVerticies = !showVerticies; + break; + case 's': + shade = !shade; + (shade) ? glShadeModel(GL_SMOOTH) : glShadeModel(GL_FLAT); + break; + case 'h': + hideBottomTriangle = !hideBottomTriangle; + break; + case 'o': + outline = !outline; + break; + case 'm': + dithering = !dithering; + break; + case '0': + aaMode = !aaMode; + if (aaMode) { + glEnable(GL_POLYGON_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + if (!rgb) { + color1 = 32; + color2 = 128; + color3 = 224; + } + } else { + glDisable(GL_POLYGON_SMOOTH); + glDisable(GL_BLEND); + if (!rgb) { + color1 = 18; + color2 = 24; + color3 = 30; + } + } + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void BeginPrim(void) +{ + + switch (state) { + case SOLID: + glBegin(GL_POLYGON); + break; + case LINE: + glBegin(GL_LINE_LOOP); + break; + case POINT: + glBegin(GL_POINTS); + break; + default: + break; + } +} + +static void EndPrim(void) +{ + + glEnd(); +} + +static void Draw(void) +{ + float scaleX, scaleY; + + glViewport(0, 0, windW, windH); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-175, 175, -175, 175); + glMatrixMode(GL_MODELVIEW); + + glScissor(0, 0, windW, windH); + + (culling) ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE); + (winding) ? glFrontFace(GL_CCW) : glFrontFace(GL_CW); + (face) ? glCullFace(GL_FRONT) : glCullFace(GL_BACK); + + (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); + + glClear(GL_COLOR_BUFFER_BIT); + + SetColor(COLOR_GREEN); + glBegin(GL_LINE_LOOP); + glVertex3fv(boxA); + glVertex3fv(boxB); + glVertex3fv(boxC); + glVertex3fv(boxD); + glEnd(); + + if (!hideBottomTriangle) { + glPushMatrix(); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0, 0, 1); + + SetColor(COLOR_BLUE); + BeginPrim(); + glVertex3fv(p0); + glVertex3fv(p1); + glVertex3fv(p2); + EndPrim(); + + if (showVerticies) { + (rgb) ? glColor3fv(RGBMap[COLOR_RED]) : glIndexf(color1); + glRectf(p0[0]-2, p0[1]-2, p0[0]+2, p0[1]+2); + (rgb) ? glColor3fv(RGBMap[COLOR_GREEN]) : glIndexf(color2); + glRectf(p1[0]-2, p1[1]-2, p1[0]+2, p1[1]+2); + (rgb) ? glColor3fv(RGBMap[COLOR_BLUE]) : glIndexf(color3); + glRectf(p2[0]-2, p2[1]-2, p2[0]+2, p2[1]+2); + } + + glPopMatrix(); + } + + scaleX = (float)(windW - 20) / 2 / 175 * (175 - 100) + 10; + scaleY = (float)(windH - 20) / 2 / 175 * (175 - 100) + 10; + + glViewport(scaleX, scaleY, windW-2*scaleX, windH-2*scaleY); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-100, 100, -100, 100); + glMatrixMode(GL_MODELVIEW); + + glScissor(scaleX, scaleY, windW-2*scaleX, windH-2*scaleY); + + glPushMatrix(); + + glScalef(zoom, zoom, zoom); + glRotatef(zRotation, 0,0,1); + + glPointSize(10); + glLineWidth(5); + glEnable(GL_POINT_SMOOTH); + glEnable(GL_LINE_STIPPLE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + SetColor(COLOR_RED); + BeginPrim(); + (rgb) ? glColor3fv(RGBMap[COLOR_RED]) : glIndexf(color1); + glVertex3fv(p0); + (rgb) ? glColor3fv(RGBMap[COLOR_GREEN]) : glIndexf(color2); + glVertex3fv(p1); + (rgb) ? glColor3fv(RGBMap[COLOR_BLUE]) : glIndexf(color3); + glVertex3fv(p2); + EndPrim(); + + glPointSize(1); + glLineWidth(1); + glDisable(GL_POINT_SMOOTH); + glDisable(GL_LINE_STIPPLE); + glBlendFunc(GL_ONE, GL_ZERO); + + if (outline) { + SetColor(COLOR_WHITE); + glBegin(GL_LINE_LOOP); + glVertex3fv(p0); + glVertex3fv(p1); + glVertex3fv(p2); + glEnd(); + } + + glPopMatrix(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + windW = 600; + windH = 300; + glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); + + windType = (rgb) ? GLUT_RGB : GLUT_INDEX; + windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(windType); + + if (glutCreateWindow("Triangle Test") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(Key2); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/samples/wave.c b/progs/samples/wave.c new file mode 100644 index 0000000000..187c590000 --- /dev/null +++ b/progs/samples/wave.c @@ -0,0 +1,602 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "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 BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + +#define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)])) +#define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX])) + + +GLenum rgb, doubleBuffer; + +#include "tkmap.c" + +GLint colorIndexes1[3]; +GLint colorIndexes2[3]; +GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; + +GLenum smooth = GL_FALSE; +GLenum lighting = GL_TRUE; +GLenum depth = GL_TRUE; +GLenum stepMode = GL_FALSE; +GLenum spinMode = GL_FALSE; +GLint contouring = 0; + +GLint widthX, widthY; +GLint checkerSize; +float height; + +GLint frames, curFrame = 0, nextFrame = 0; + +struct facet { + float color[3]; + float normal[3]; +}; +struct coord { + float vertex[3]; + float normal[3]; +}; +struct mesh { + GLint widthX, widthY; + GLint numFacets; + GLint numCoords; + GLint frames; + struct coord *coords; + struct facet *facets; +} theMesh; + +GLubyte contourTexture1[] = { + 255, 255, 255, 255, + 255, 255, 255, 255, + 255, 255, 255, 255, + 127, 127, 127, 127, +}; +GLubyte contourTexture2[] = { + 255, 255, 255, 255, + 255, 127, 127, 127, + 255, 127, 127, 127, + 255, 127, 127, 127, +}; + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + glutPostRedisplay(); +} + +static void Animate(void) +{ + struct coord *coord; + struct facet *facet; + float *lastColor; + float *thisColor; + GLint i, j; + + glClear(clearMask); + + if (nextFrame || !stepMode) { + curFrame++; + } + if (curFrame >= theMesh.frames) { + curFrame = 0; + } + + if ((nextFrame || !stepMode) && spinMode) { + glRotatef(5.0, 0.0, 0.0, 1.0); + } + nextFrame = 0; + + for (i = 0; i < theMesh.widthX; i++) { + glBegin(GL_QUAD_STRIP); + lastColor = NULL; + for (j = 0; j < theMesh.widthY; j++) { + facet = GETFACET(curFrame, i, j); + if (!smooth && lighting) { + glNormal3fv(facet->normal); + } + if (lighting) { + if (rgb) { + thisColor = facet->color; + glColor3fv(facet->color); + } else { + thisColor = facet->color; + glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, + facet->color); + } + } else { + if (rgb) { + thisColor = facet->color; + glColor3fv(facet->color); + } else { + thisColor = facet->color; + glIndexf(facet->color[1]); + } + } + + if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) { + if (lastColor) { + glEnd(); + glBegin(GL_QUAD_STRIP); + } + coord = GETCOORD(curFrame, i, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + } + + coord = GETCOORD(curFrame, i, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + lastColor = thisColor; + } + glEnd(); + } + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static void SetColorMap(void) +{ + static float green[3] = {0.2, 1.0, 0.2}; + static float red[3] = {1.0, 0.2, 0.2}; + float *color, percent; + GLint *indexes, entries, i, j; + + entries = glutGet(GLUT_WINDOW_COLORMAP_SIZE); + + colorIndexes1[0] = 1; + colorIndexes1[1] = 1 + (GLint)((entries - 1) * 0.3); + colorIndexes1[2] = (GLint)((entries - 1) * 0.5); + colorIndexes2[0] = 1 + (GLint)((entries - 1) * 0.5); + colorIndexes2[1] = 1 + (GLint)((entries - 1) * 0.8); + colorIndexes2[2] = entries - 1; + + for (i = 0; i < 2; i++) { + switch (i) { + case 0: + color = green; + indexes = colorIndexes1; + break; + case 1: + color = red; + indexes = colorIndexes2; + break; + } + + for (j = indexes[0]; j < indexes[1]; j++) { + percent = 0.2 + 0.8 * (j - indexes[0]) / + (float)(indexes[1] - indexes[0]); + glutSetColor(j, percent*color[0], percent*color[1], + percent*color[2]); + } + for (j=indexes[1]; j<=indexes[2]; j++) { + percent = (j - indexes[1]) / (float)(indexes[2] - indexes[1]); + glutSetColor(j, percent*(1-color[0])+color[0], + percent*(1-color[1])+color[1], + percent*(1-color[2])+color[2]); + } + } +} + +static void InitMesh(void) +{ + struct coord *coord; + struct facet *facet; + float dp1[3], dp2[3]; + float *pt1, *pt2, *pt3; + float angle, d, x, y; + GLint numFacets, numCoords, frameNum, i, j; + + theMesh.widthX = widthX; + theMesh.widthY = widthY; + theMesh.frames = frames; + + numFacets = widthX * widthY; + numCoords = (widthX + 1) * (widthY + 1); + + theMesh.numCoords = numCoords; + theMesh.numFacets = numFacets; + + theMesh.coords = (struct coord *)malloc(frames*numCoords* + sizeof(struct coord)); + theMesh.facets = (struct facet *)malloc(frames*numFacets* + sizeof(struct facet)); + if (theMesh.coords == NULL || theMesh.facets == NULL) { + printf("Out of memory.\n"); + exit(1); + } + + for (frameNum = 0; frameNum < frames; frameNum++) { + for (i = 0; i <= widthX; i++) { + x = i / (float)widthX; + for (j = 0; j <= widthY; j++) { + y = j / (float)widthY; + + d = sqrt(x*x+y*y); + if (d == 0.0) { + d = 0.0001; + } + angle = 2 * PI * d + (2 * PI / frames * frameNum); + + coord = GETCOORD(frameNum, i, j); + + coord->vertex[0] = x - 0.5; + coord->vertex[1] = y - 0.5; + coord->vertex[2] = (height - height * d) * cos(angle); + + coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[2] = -1; + + d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+ + coord->normal[1]*coord->normal[1]+1); + coord->normal[0] *= d; + coord->normal[1] *= d; + coord->normal[2] *= d; + } + } + for (i = 0; i < widthX; i++) { + for (j = 0; j < widthY; j++) { + facet = GETFACET(frameNum, i, j); + if (((i/checkerSize)%2)^(j/checkerSize)%2) { + if (rgb) { + facet->color[0] = 1.0; + facet->color[1] = 0.2; + facet->color[2] = 0.2; + } else { + facet->color[0] = colorIndexes1[0]; + facet->color[1] = colorIndexes1[1]; + facet->color[2] = colorIndexes1[2]; + } + } else { + if (rgb) { + facet->color[0] = 0.2; + facet->color[1] = 1.0; + facet->color[2] = 0.2; + } else { + facet->color[0] = colorIndexes2[0]; + facet->color[1] = colorIndexes2[1]; + facet->color[2] = colorIndexes2[2]; + } + } + pt1 = GETCOORD(frameNum, i, j)->vertex; + pt2 = GETCOORD(frameNum, i, j+1)->vertex; + pt3 = GETCOORD(frameNum, i+1, j+1)->vertex; + + dp1[0] = pt2[0] - pt1[0]; + dp1[1] = pt2[1] - pt1[1]; + dp1[2] = pt2[2] - pt1[2]; + + dp2[0] = pt3[0] - pt2[0]; + dp2[1] = pt3[1] - pt2[1]; + dp2[2] = pt3[2] - pt2[2]; + + facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1]; + facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2]; + facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0]; + + d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+ + facet->normal[1]*facet->normal[1]+ + facet->normal[2]*facet->normal[2]); + + facet->normal[0] *= d; + facet->normal[1] *= d; + facet->normal[2] *= d; + } + } + } +} + +static void InitMaterials(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 150.0, 0.0}; + static float front_mat_shininess[] = {60.0}; + static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; + static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; + static float back_mat_shininess[] = {60.0}; + static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + + glMatrixMode(GL_PROJECTION); + gluPerspective(90.0, 1.0, 0.5, 10.0); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + if (rgb) { + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + } + + if (rgb) { + glEnable(GL_COLOR_MATERIAL); + } else { + SetColorMap(); + } +} + +static void InitTexture(void) +{ + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + + glEnable(GL_DEPTH_TEST); + + InitMaterials(); + InitTexture(); + InitMesh(); + + glMatrixMode(GL_MODELVIEW); + glTranslatef(0.0, 0.4, -1.8); + glScalef(2.0, 2.0, 2.0); + glRotatef(-35.0, 1.0, 0.0, 0.0); + glRotatef(35.0, 0.0, 0.0, 1.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + case 'c': + contouring++; + if (contouring == 1) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE, + GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGenfv(GL_S, GL_OBJECT_PLANE, map); + glTexGenfv(GL_T, GL_OBJECT_PLANE, map); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } else if (contouring == 2) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTexGenfv(GL_S, GL_EYE_PLANE, map); + glTexGenfv(GL_T, GL_EYE_PLANE, map); + glPopMatrix(); + } else { + contouring = 0; + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); + } + break; + case 's': + smooth = !smooth; + if (smooth) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + break; + case 'l': + lighting = !lighting; + if (lighting) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + if (rgb) { + glEnable(GL_COLOR_MATERIAL); + } + } else { + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + if (rgb) { + glDisable(GL_COLOR_MATERIAL); + } + } + break; + case 'd': + depth = !depth; + if (depth) { + glEnable(GL_DEPTH_TEST); + clearMask |= GL_DEPTH_BUFFER_BIT; + } else { + glDisable(GL_DEPTH_TEST); + clearMask &= ~GL_DEPTH_BUFFER_BIT; + } + break; + case 32: + stepMode = !stepMode; + if (stepMode) { + glutIdleFunc(0); + } else { + glutIdleFunc(glut_post_redisplay_p); + } + break; + case 'n': + if (stepMode) { + nextFrame = 1; + } + break; + case 'a': + spinMode = !spinMode; + break; + default: + return; + } + glutPostRedisplay(); +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + rgb = GL_TRUE; + doubleBuffer = GL_FALSE; + frames = 10; + widthX = 10; + widthY = 10; + checkerSize = 2; + height = 0.2; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ci") == 0) { + rgb = GL_FALSE; + } else if (strcmp(argv[i], "-rgb") == 0) { + rgb = GL_TRUE; + } else if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-grid") == 0) { + if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') { + printf("-grid (No numbers).\n"); + return GL_FALSE; + } else { + widthX = atoi(argv[++i]); + widthY = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-size") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-checker (No number).\n"); + return GL_FALSE; + } else { + checkerSize = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-wave") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-wave (No number).\n"); + return GL_FALSE; + } else { + height = atof(argv[++i]); + } + } else if (strcmp(argv[i], "-frames") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-frames (No number).\n"); + return GL_FALSE; + } else { + frames = atoi(argv[++i]); + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); + + type = GLUT_DEPTH; + type |= (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Wave Demo") == GL_FALSE) { + exit(1); + } + + InitMap(); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Animate); + glutIdleFunc(glut_post_redisplay_p); + glutMainLoop(); + return 0; +} diff --git a/progs/util/README b/progs/util/README new file mode 100644 index 0000000000..ca89d34bd3 --- /dev/null +++ b/progs/util/README @@ -0,0 +1,22 @@ + +This directory is a collection of function which may be useful to +OpenGL/Mesa programmers. + + +errcheck.c - an OpenGL error check/report function +glutskel.c - handy skeleton for GLUT programs +idproj.c - setup an identity projection +mwmborder.c - remove Motif window decoration/border +winpos.c - set absolute window raster position +readtex.c - load textures/mipmaps from an .rgb file +showbuffer.[ch] - show depth, alpha, or stencil buffer contents +glstate.[ch] - query/print GL state variables, for debugging, etc. +sampleMakefile - example Makefile for making OpenGL/Mesa apps on Unix +dumpsate.c - dump all OpenGL state, from Stephane Rehel +imagesgi.cpp,.h - read SGI image files + + +more to come... + +---------------------------------------------------------------------- +$Id: README,v 1.1 1999/08/19 00:55:42 jtg Exp $ diff --git a/progs/util/dumpstate.c b/progs/util/dumpstate.c new file mode 100644 index 0000000000..4c039a40f9 --- /dev/null +++ b/progs/util/dumpstate.c @@ -0,0 +1,1959 @@ + +/* + * + * From: Stephane Rehel + * Date: Mon, 31 May 1999 18:40:54 -0400 + * To: Paul Brian + * Subject: OpenGL State Dump Function + * + * Here is a function that dumps the current OpenGL state. I wrote it + * some time ago. + * + * In the attachment: + * + the code itself + * + its output + * + * I think Mesa is wrong on some getBooleanv(). For example, GL_VERTEX_ARRAY + * is queried by IsEnabled() (cf. p. 196 of the spec). But on page 193 + * we can read that all the boolean attribs that can be queried by IsEnabled() + * can also be queried by IsEnabled(). + * + * I had duplicated all the enums (LOCAL_*) so that the code can run on any + * OpenGL version, even if an enum is not recognized. + * + * The code can be shipped in the public domain. + * + * Stephane. + */ + + +/* + * Stephane Rehel + * Creation: February 5 1999 + */ + +#include +#include + +/***************************************************************************/ + +enum { + /* Data types */ + LOCAL_GL_BYTE = 0x1400, + LOCAL_GL_UNSIGNED_BYTE = 0x1401, + LOCAL_GL_SHORT = 0x1402, + LOCAL_GL_UNSIGNED_SHORT = 0x1403, + LOCAL_GL_INT = 0x1404, + LOCAL_GL_UNSIGNED_INT = 0x1405, + LOCAL_GL_FLOAT = 0x1406, + LOCAL_GL_DOUBLE = 0x140A, + LOCAL_GL_2_BYTES = 0x1407, + LOCAL_GL_3_BYTES = 0x1408, + LOCAL_GL_4_BYTES = 0x1409, + + /* Primitives */ + LOCAL_GL_LINES = 0x0001, + LOCAL_GL_POINTS = 0x0000, + LOCAL_GL_LINE_STRIP = 0x0003, + LOCAL_GL_LINE_LOOP = 0x0002, + LOCAL_GL_TRIANGLES = 0x0004, + LOCAL_GL_TRIANGLE_STRIP = 0x0005, + LOCAL_GL_TRIANGLE_FAN = 0x0006, + LOCAL_GL_QUADS = 0x0007, + LOCAL_GL_QUAD_STRIP = 0x0008, + LOCAL_GL_POLYGON = 0x0009, + LOCAL_GL_EDGE_FLAG = 0x0B43, + + /* Vertex Arrays */ + LOCAL_GL_VERTEX_ARRAY = 0x8074, + LOCAL_GL_NORMAL_ARRAY = 0x8075, + LOCAL_GL_COLOR_ARRAY = 0x8076, + LOCAL_GL_INDEX_ARRAY = 0x8077, + LOCAL_GL_TEXTURE_COORD_ARRAY = 0x8078, + LOCAL_GL_EDGE_FLAG_ARRAY = 0x8079, + LOCAL_GL_VERTEX_ARRAY_SIZE = 0x807A, + LOCAL_GL_VERTEX_ARRAY_TYPE = 0x807B, + LOCAL_GL_VERTEX_ARRAY_STRIDE = 0x807C, + LOCAL_GL_NORMAL_ARRAY_TYPE = 0x807E, + LOCAL_GL_NORMAL_ARRAY_STRIDE = 0x807F, + LOCAL_GL_COLOR_ARRAY_SIZE = 0x8081, + LOCAL_GL_COLOR_ARRAY_TYPE = 0x8082, + LOCAL_GL_COLOR_ARRAY_STRIDE = 0x8083, + LOCAL_GL_INDEX_ARRAY_TYPE = 0x8085, + LOCAL_GL_INDEX_ARRAY_STRIDE = 0x8086, + LOCAL_GL_TEXTURE_COORD_ARRAY_SIZE = 0x8088, + LOCAL_GL_TEXTURE_COORD_ARRAY_TYPE = 0x8089, + LOCAL_GL_TEXTURE_COORD_ARRAY_STRIDE = 0x808A, + LOCAL_GL_EDGE_FLAG_ARRAY_STRIDE = 0x808C, + LOCAL_GL_VERTEX_ARRAY_POINTER = 0x808E, + LOCAL_GL_NORMAL_ARRAY_POINTER = 0x808F, + LOCAL_GL_COLOR_ARRAY_POINTER = 0x8090, + LOCAL_GL_INDEX_ARRAY_POINTER = 0x8091, + LOCAL_GL_TEXTURE_COORD_ARRAY_POINTER = 0x8092, + LOCAL_GL_EDGE_FLAG_ARRAY_POINTER = 0x8093, + LOCAL_GL_V2F = 0x2A20, + LOCAL_GL_V3F = 0x2A21, + LOCAL_GL_C4UB_V2F = 0x2A22, + LOCAL_GL_C4UB_V3F = 0x2A23, + LOCAL_GL_C3F_V3F = 0x2A24, + LOCAL_GL_N3F_V3F = 0x2A25, + LOCAL_GL_C4F_N3F_V3F = 0x2A26, + LOCAL_GL_T2F_V3F = 0x2A27, + LOCAL_GL_T4F_V4F = 0x2A28, + LOCAL_GL_T2F_C4UB_V3F = 0x2A29, + LOCAL_GL_T2F_C3F_V3F = 0x2A2A, + LOCAL_GL_T2F_N3F_V3F = 0x2A2B, + LOCAL_GL_T2F_C4F_N3F_V3F = 0x2A2C, + LOCAL_GL_T4F_C4F_N3F_V4F = 0x2A2D, + + /* Matrix Mode */ + LOCAL_GL_MATRIX_MODE = 0x0BA0, + LOCAL_GL_MODELVIEW = 0x1700, + LOCAL_GL_PROJECTION = 0x1701, + LOCAL_GL_TEXTURE = 0x1702, + + /* Points */ + LOCAL_GL_POINT_SMOOTH = 0x0B10, + LOCAL_GL_POINT_SIZE = 0x0B11, + LOCAL_GL_POINT_SIZE_GRANULARITY = 0x0B13, + LOCAL_GL_POINT_SIZE_RANGE = 0x0B12, + + /* Lines */ + LOCAL_GL_LINE_SMOOTH = 0x0B20, + LOCAL_GL_LINE_STIPPLE = 0x0B24, + LOCAL_GL_LINE_STIPPLE_PATTERN = 0x0B25, + LOCAL_GL_LINE_STIPPLE_REPEAT = 0x0B26, + LOCAL_GL_LINE_WIDTH = 0x0B21, + LOCAL_GL_LINE_WIDTH_GRANULARITY = 0x0B23, + LOCAL_GL_LINE_WIDTH_RANGE = 0x0B22, + + /* Polygons */ + LOCAL_GL_POINT = 0x1B00, + LOCAL_GL_LINE = 0x1B01, + LOCAL_GL_FILL = 0x1B02, + LOCAL_GL_CCW = 0x0901, + LOCAL_GL_CW = 0x0900, + LOCAL_GL_FRONT = 0x0404, + LOCAL_GL_BACK = 0x0405, + LOCAL_GL_CULL_FACE = 0x0B44, + LOCAL_GL_CULL_FACE_MODE = 0x0B45, + LOCAL_GL_POLYGON_SMOOTH = 0x0B41, + LOCAL_GL_POLYGON_STIPPLE = 0x0B42, + LOCAL_GL_FRONT_FACE = 0x0B46, + LOCAL_GL_POLYGON_MODE = 0x0B40, + LOCAL_GL_POLYGON_OFFSET_FACTOR = 0x8038, + LOCAL_GL_POLYGON_OFFSET_UNITS = 0x2A00, + LOCAL_GL_POLYGON_OFFSET_POINT = 0x2A01, + LOCAL_GL_POLYGON_OFFSET_LINE = 0x2A02, + LOCAL_GL_POLYGON_OFFSET_FILL = 0x8037, + + /* Display Lists */ + LOCAL_GL_COMPILE = 0x1300, + LOCAL_GL_COMPILE_AND_EXECUTE = 0x1301, + LOCAL_GL_LIST_BASE = 0x0B32, + LOCAL_GL_LIST_INDEX = 0x0B33, + LOCAL_GL_LIST_MODE = 0x0B30, + + /* Depth buffer */ + LOCAL_GL_NEVER = 0x0200, + LOCAL_GL_LESS = 0x0201, + LOCAL_GL_GEQUAL = 0x0206, + LOCAL_GL_LEQUAL = 0x0203, + LOCAL_GL_GREATER = 0x0204, + LOCAL_GL_NOTEQUAL = 0x0205, + LOCAL_GL_EQUAL = 0x0202, + LOCAL_GL_ALWAYS = 0x0207, + LOCAL_GL_DEPTH_TEST = 0x0B71, + LOCAL_GL_DEPTH_BITS = 0x0D56, + LOCAL_GL_DEPTH_CLEAR_VALUE = 0x0B73, + LOCAL_GL_DEPTH_FUNC = 0x0B74, + LOCAL_GL_DEPTH_RANGE = 0x0B70, + LOCAL_GL_DEPTH_WRITEMASK = 0x0B72, + LOCAL_GL_DEPTH_COMPONENT = 0x1902, + + /* Lighting */ + LOCAL_GL_LIGHTING = 0x0B50, + LOCAL_GL_LIGHT0 = 0x4000, + LOCAL_GL_LIGHT1 = 0x4001, + LOCAL_GL_LIGHT2 = 0x4002, + LOCAL_GL_LIGHT3 = 0x4003, + LOCAL_GL_LIGHT4 = 0x4004, + LOCAL_GL_LIGHT5 = 0x4005, + LOCAL_GL_LIGHT6 = 0x4006, + LOCAL_GL_LIGHT7 = 0x4007, + LOCAL_GL_SPOT_EXPONENT = 0x1205, + LOCAL_GL_SPOT_CUTOFF = 0x1206, + LOCAL_GL_CONSTANT_ATTENUATION = 0x1207, + LOCAL_GL_LINEAR_ATTENUATION = 0x1208, + LOCAL_GL_QUADRATIC_ATTENUATION = 0x1209, + LOCAL_GL_AMBIENT = 0x1200, + LOCAL_GL_DIFFUSE = 0x1201, + LOCAL_GL_SPECULAR = 0x1202, + LOCAL_GL_SHININESS = 0x1601, + LOCAL_GL_EMISSION = 0x1600, + LOCAL_GL_POSITION = 0x1203, + LOCAL_GL_SPOT_DIRECTION = 0x1204, + LOCAL_GL_AMBIENT_AND_DIFFUSE = 0x1602, + LOCAL_GL_COLOR_INDEXES = 0x1603, + LOCAL_GL_LIGHT_MODEL_TWO_SIDE = 0x0B52, + LOCAL_GL_LIGHT_MODEL_LOCAL_VIEWER = 0x0B51, + LOCAL_GL_LIGHT_MODEL_AMBIENT = 0x0B53, + LOCAL_GL_FRONT_AND_BACK = 0x0408, + LOCAL_GL_SHADE_MODEL = 0x0B54, + LOCAL_GL_FLAT = 0x1D00, + LOCAL_GL_SMOOTH = 0x1D01, + LOCAL_GL_COLOR_MATERIAL = 0x0B57, + LOCAL_GL_COLOR_MATERIAL_FACE = 0x0B55, + LOCAL_GL_COLOR_MATERIAL_PARAMETER = 0x0B56, + LOCAL_GL_NORMALIZE = 0x0BA1, + + /* User clipping planes */ + LOCAL_GL_CLIP_PLANE0 = 0x3000, + LOCAL_GL_CLIP_PLANE1 = 0x3001, + LOCAL_GL_CLIP_PLANE2 = 0x3002, + LOCAL_GL_CLIP_PLANE3 = 0x3003, + LOCAL_GL_CLIP_PLANE4 = 0x3004, + LOCAL_GL_CLIP_PLANE5 = 0x3005, + + /* Accumulation buffer */ + LOCAL_GL_ACCUM_RED_BITS = 0x0D58, + LOCAL_GL_ACCUM_GREEN_BITS = 0x0D59, + LOCAL_GL_ACCUM_BLUE_BITS = 0x0D5A, + LOCAL_GL_ACCUM_ALPHA_BITS = 0x0D5B, + LOCAL_GL_ACCUM_CLEAR_VALUE = 0x0B80, + LOCAL_GL_ACCUM = 0x0100, + LOCAL_GL_ADD = 0x0104, + LOCAL_GL_LOAD = 0x0101, + LOCAL_GL_MULT = 0x0103, + LOCAL_GL_RETURN = 0x0102, + + /* Alpha testing */ + LOCAL_GL_ALPHA_TEST = 0x0BC0, + LOCAL_GL_ALPHA_TEST_REF = 0x0BC2, + LOCAL_GL_ALPHA_TEST_FUNC = 0x0BC1, + + /* Blending */ + LOCAL_GL_BLEND = 0x0BE2, + LOCAL_GL_BLEND_SRC = 0x0BE1, + LOCAL_GL_BLEND_DST = 0x0BE0, + LOCAL_GL_ZERO = 0, + LOCAL_GL_ONE = 1, + LOCAL_GL_SRC_COLOR = 0x0300, + LOCAL_GL_ONE_MINUS_SRC_COLOR = 0x0301, + LOCAL_GL_DST_COLOR = 0x0306, + LOCAL_GL_ONE_MINUS_DST_COLOR = 0x0307, + LOCAL_GL_SRC_ALPHA = 0x0302, + LOCAL_GL_ONE_MINUS_SRC_ALPHA = 0x0303, + LOCAL_GL_DST_ALPHA = 0x0304, + LOCAL_GL_ONE_MINUS_DST_ALPHA = 0x0305, + LOCAL_GL_SRC_ALPHA_SATURATE = 0x0308, + LOCAL_GL_CONSTANT_COLOR = 0x8001, + LOCAL_GL_ONE_MINUS_CONSTANT_COLOR = 0x8002, + LOCAL_GL_CONSTANT_ALPHA = 0x8003, + LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA = 0x8004, + + /* Render Mode */ + LOCAL_GL_FEEDBACK = 0x1C01, + LOCAL_GL_RENDER = 0x1C00, + LOCAL_GL_SELECT = 0x1C02, + + /* Feedback */ + LOCAL_GL_2D = 0x0600, + LOCAL_GL_3D = 0x0601, + LOCAL_GL_3D_COLOR = 0x0602, + LOCAL_GL_3D_COLOR_TEXTURE = 0x0603, + LOCAL_GL_4D_COLOR_TEXTURE = 0x0604, + LOCAL_GL_POINT_TOKEN = 0x0701, + LOCAL_GL_LINE_TOKEN = 0x0702, + LOCAL_GL_LINE_RESET_TOKEN = 0x0707, + LOCAL_GL_POLYGON_TOKEN = 0x0703, + LOCAL_GL_BITMAP_TOKEN = 0x0704, + LOCAL_GL_DRAW_PIXEL_TOKEN = 0x0705, + LOCAL_GL_COPY_PIXEL_TOKEN = 0x0706, + LOCAL_GL_PASS_THROUGH_TOKEN = 0x0700, + LOCAL_GL_FEEDBACK_BUFFER_POINTER = 0x0DF0, + LOCAL_GL_FEEDBACK_BUFFER_SIZE = 0x0DF1, + LOCAL_GL_FEEDBACK_BUFFER_TYPE = 0x0DF2, + + /* Selection */ + LOCAL_GL_SELECTION_BUFFER_POINTER = 0x0DF3, + LOCAL_GL_SELECTION_BUFFER_SIZE = 0x0DF4, + + /* Fog */ + LOCAL_GL_FOG = 0x0B60, + LOCAL_GL_FOG_MODE = 0x0B65, + LOCAL_GL_FOG_DENSITY = 0x0B62, + LOCAL_GL_FOG_COLOR = 0x0B66, + LOCAL_GL_FOG_INDEX = 0x0B61, + LOCAL_GL_FOG_START = 0x0B63, + LOCAL_GL_FOG_END = 0x0B64, + LOCAL_GL_LINEAR = 0x2601, + LOCAL_GL_EXP = 0x0800, + LOCAL_GL_EXP2 = 0x0801, + + /* Logic Ops */ + LOCAL_GL_LOGIC_OP = 0x0BF1, + LOCAL_GL_INDEX_LOGIC_OP = 0x0BF1, + LOCAL_GL_COLOR_LOGIC_OP = 0x0BF2, + LOCAL_GL_LOGIC_OP_MODE = 0x0BF0, + LOCAL_GL_CLEAR = 0x1500, + LOCAL_GL_SET = 0x150F, + LOCAL_GL_COPY = 0x1503, + LOCAL_GL_COPY_INVERTED = 0x150C, + LOCAL_GL_NOOP = 0x1505, + LOCAL_GL_INVERT = 0x150A, + LOCAL_GL_AND = 0x1501, + LOCAL_GL_NAND = 0x150E, + LOCAL_GL_OR = 0x1507, + LOCAL_GL_NOR = 0x1508, + LOCAL_GL_XOR = 0x1506, + LOCAL_GL_EQUIV = 0x1509, + LOCAL_GL_AND_REVERSE = 0x1502, + LOCAL_GL_AND_INVERTED = 0x1504, + LOCAL_GL_OR_REVERSE = 0x150B, + LOCAL_GL_OR_INVERTED = 0x150D, + + /* Stencil */ + LOCAL_GL_STENCIL_TEST = 0x0B90, + LOCAL_GL_STENCIL_WRITEMASK = 0x0B98, + LOCAL_GL_STENCIL_BITS = 0x0D57, + LOCAL_GL_STENCIL_FUNC = 0x0B92, + LOCAL_GL_STENCIL_VALUE_MASK = 0x0B93, + LOCAL_GL_STENCIL_REF = 0x0B97, + LOCAL_GL_STENCIL_FAIL = 0x0B94, + LOCAL_GL_STENCIL_PASS_DEPTH_PASS = 0x0B96, + LOCAL_GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95, + LOCAL_GL_STENCIL_CLEAR_VALUE = 0x0B91, + LOCAL_GL_STENCIL_INDEX = 0x1901, + LOCAL_GL_KEEP = 0x1E00, + LOCAL_GL_REPLACE = 0x1E01, + LOCAL_GL_INCR = 0x1E02, + LOCAL_GL_DECR = 0x1E03, + + /* Buffers, Pixel Drawing/Reading */ + LOCAL_GL_NONE = 0, + LOCAL_GL_LEFT = 0x0406, + LOCAL_GL_RIGHT = 0x0407, + /*LOCAL_GL_FRONT = 0x0404, */ + /*LOCAL_GL_BACK = 0x0405, */ + /*LOCAL_GL_FRONT_AND_BACK = 0x0408, */ + LOCAL_GL_FRONT_LEFT = 0x0400, + LOCAL_GL_FRONT_RIGHT = 0x0401, + LOCAL_GL_BACK_LEFT = 0x0402, + LOCAL_GL_BACK_RIGHT = 0x0403, + LOCAL_GL_AUX0 = 0x0409, + LOCAL_GL_AUX1 = 0x040A, + LOCAL_GL_AUX2 = 0x040B, + LOCAL_GL_AUX3 = 0x040C, + LOCAL_GL_COLOR_INDEX = 0x1900, + LOCAL_GL_RED = 0x1903, + LOCAL_GL_GREEN = 0x1904, + LOCAL_GL_BLUE = 0x1905, + LOCAL_GL_ALPHA = 0x1906, + LOCAL_GL_LUMINANCE = 0x1909, + LOCAL_GL_LUMINANCE_ALPHA = 0x190A, + LOCAL_GL_ALPHA_BITS = 0x0D55, + LOCAL_GL_RED_BITS = 0x0D52, + LOCAL_GL_GREEN_BITS = 0x0D53, + LOCAL_GL_BLUE_BITS = 0x0D54, + LOCAL_GL_INDEX_BITS = 0x0D51, + LOCAL_GL_SUBPIXEL_BITS = 0x0D50, + LOCAL_GL_AUX_BUFFERS = 0x0C00, + LOCAL_GL_READ_BUFFER = 0x0C02, + LOCAL_GL_DRAW_BUFFER = 0x0C01, + LOCAL_GL_DOUBLEBUFFER = 0x0C32, + LOCAL_GL_STEREO = 0x0C33, + LOCAL_GL_BITMAP = 0x1A00, + LOCAL_GL_COLOR = 0x1800, + LOCAL_GL_DEPTH = 0x1801, + LOCAL_GL_STENCIL = 0x1802, + LOCAL_GL_DITHER = 0x0BD0, + LOCAL_GL_RGB = 0x1907, + LOCAL_GL_RGBA = 0x1908, + + /* Implementation limits */ + LOCAL_GL_MAX_LIST_NESTING = 0x0B31, + LOCAL_GL_MAX_ATTRIB_STACK_DEPTH = 0x0D35, + LOCAL_GL_MAX_MODELVIEW_STACK_DEPTH = 0x0D36, + LOCAL_GL_MAX_NAME_STACK_DEPTH = 0x0D37, + LOCAL_GL_MAX_PROJECTION_STACK_DEPTH = 0x0D38, + LOCAL_GL_MAX_TEXTURE_STACK_DEPTH = 0x0D39, + LOCAL_GL_MAX_EVAL_ORDER = 0x0D30, + LOCAL_GL_MAX_LIGHTS = 0x0D31, + LOCAL_GL_MAX_CLIP_PLANES = 0x0D32, + LOCAL_GL_MAX_TEXTURE_SIZE = 0x0D33, + LOCAL_GL_MAX_PIXEL_MAP_TABLE = 0x0D34, + LOCAL_GL_MAX_VIEWPORT_DIMS = 0x0D3A, + LOCAL_GL_MAX_CLIENT_ATTRIB_STACK_DEPTH= 0x0D3B, + + /* Gets */ + LOCAL_GL_ATTRIB_STACK_DEPTH = 0x0BB0, + LOCAL_GL_CLIENT_ATTRIB_STACK_DEPTH = 0x0BB1, + LOCAL_GL_COLOR_CLEAR_VALUE = 0x0C22, + LOCAL_GL_COLOR_WRITEMASK = 0x0C23, + LOCAL_GL_CURRENT_INDEX = 0x0B01, + LOCAL_GL_CURRENT_COLOR = 0x0B00, + LOCAL_GL_CURRENT_NORMAL = 0x0B02, + LOCAL_GL_CURRENT_RASTER_COLOR = 0x0B04, + LOCAL_GL_CURRENT_RASTER_DISTANCE = 0x0B09, + LOCAL_GL_CURRENT_RASTER_INDEX = 0x0B05, + LOCAL_GL_CURRENT_RASTER_POSITION = 0x0B07, + LOCAL_GL_CURRENT_RASTER_TEXTURE_COORDS = 0x0B06, + LOCAL_GL_CURRENT_RASTER_POSITION_VALID = 0x0B08, + LOCAL_GL_CURRENT_TEXTURE_COORDS = 0x0B03, + LOCAL_GL_INDEX_CLEAR_VALUE = 0x0C20, + LOCAL_GL_INDEX_MODE = 0x0C30, + LOCAL_GL_INDEX_WRITEMASK = 0x0C21, + LOCAL_GL_MODELVIEW_MATRIX = 0x0BA6, + LOCAL_GL_MODELVIEW_STACK_DEPTH = 0x0BA3, + LOCAL_GL_NAME_STACK_DEPTH = 0x0D70, + LOCAL_GL_PROJECTION_MATRIX = 0x0BA7, + LOCAL_GL_PROJECTION_STACK_DEPTH = 0x0BA4, + LOCAL_GL_RENDER_MODE = 0x0C40, + LOCAL_GL_RGBA_MODE = 0x0C31, + LOCAL_GL_TEXTURE_MATRIX = 0x0BA8, + LOCAL_GL_TEXTURE_STACK_DEPTH = 0x0BA5, + LOCAL_GL_VIEWPORT = 0x0BA2, + + + /* Evaluators */ + LOCAL_GL_AUTO_NORMAL = 0x0D80, + LOCAL_GL_MAP1_COLOR_4 = 0x0D90, + LOCAL_GL_MAP1_GRID_DOMAIN = 0x0DD0, + LOCAL_GL_MAP1_GRID_SEGMENTS = 0x0DD1, + LOCAL_GL_MAP1_INDEX = 0x0D91, + LOCAL_GL_MAP1_NORMAL = 0x0D92, + LOCAL_GL_MAP1_TEXTURE_COORD_1 = 0x0D93, + LOCAL_GL_MAP1_TEXTURE_COORD_2 = 0x0D94, + LOCAL_GL_MAP1_TEXTURE_COORD_3 = 0x0D95, + LOCAL_GL_MAP1_TEXTURE_COORD_4 = 0x0D96, + LOCAL_GL_MAP1_VERTEX_3 = 0x0D97, + LOCAL_GL_MAP1_VERTEX_4 = 0x0D98, + LOCAL_GL_MAP2_COLOR_4 = 0x0DB0, + LOCAL_GL_MAP2_GRID_DOMAIN = 0x0DD2, + LOCAL_GL_MAP2_GRID_SEGMENTS = 0x0DD3, + LOCAL_GL_MAP2_INDEX = 0x0DB1, + LOCAL_GL_MAP2_NORMAL = 0x0DB2, + LOCAL_GL_MAP2_TEXTURE_COORD_1 = 0x0DB3, + LOCAL_GL_MAP2_TEXTURE_COORD_2 = 0x0DB4, + LOCAL_GL_MAP2_TEXTURE_COORD_3 = 0x0DB5, + LOCAL_GL_MAP2_TEXTURE_COORD_4 = 0x0DB6, + LOCAL_GL_MAP2_VERTEX_3 = 0x0DB7, + LOCAL_GL_MAP2_VERTEX_4 = 0x0DB8, + LOCAL_GL_COEFF = 0x0A00, + LOCAL_GL_DOMAIN = 0x0A02, + LOCAL_GL_ORDER = 0x0A01, + + /* Hints */ + LOCAL_GL_FOG_HINT = 0x0C54, + LOCAL_GL_LINE_SMOOTH_HINT = 0x0C52, + LOCAL_GL_PERSPECTIVE_CORRECTION_HINT = 0x0C50, + LOCAL_GL_POINT_SMOOTH_HINT = 0x0C51, + LOCAL_GL_POLYGON_SMOOTH_HINT = 0x0C53, + LOCAL_GL_DONT_CARE = 0x1100, + LOCAL_GL_FASTEST = 0x1101, + LOCAL_GL_NICEST = 0x1102, + + /* Scissor box */ + LOCAL_GL_SCISSOR_TEST = 0x0C11, + LOCAL_GL_SCISSOR_BOX = 0x0C10, + + /* Pixel Mode / Transfer */ + LOCAL_GL_MAP_COLOR = 0x0D10, + LOCAL_GL_MAP_STENCIL = 0x0D11, + LOCAL_GL_INDEX_SHIFT = 0x0D12, + LOCAL_GL_INDEX_OFFSET = 0x0D13, + LOCAL_GL_RED_SCALE = 0x0D14, + LOCAL_GL_RED_BIAS = 0x0D15, + LOCAL_GL_GREEN_SCALE = 0x0D18, + LOCAL_GL_GREEN_BIAS = 0x0D19, + LOCAL_GL_BLUE_SCALE = 0x0D1A, + LOCAL_GL_BLUE_BIAS = 0x0D1B, + LOCAL_GL_ALPHA_SCALE = 0x0D1C, + LOCAL_GL_ALPHA_BIAS = 0x0D1D, + LOCAL_GL_DEPTH_SCALE = 0x0D1E, + LOCAL_GL_DEPTH_BIAS = 0x0D1F, + LOCAL_GL_PIXEL_MAP_S_TO_S_SIZE = 0x0CB1, + LOCAL_GL_PIXEL_MAP_I_TO_I_SIZE = 0x0CB0, + LOCAL_GL_PIXEL_MAP_I_TO_R_SIZE = 0x0CB2, + LOCAL_GL_PIXEL_MAP_I_TO_G_SIZE = 0x0CB3, + LOCAL_GL_PIXEL_MAP_I_TO_B_SIZE = 0x0CB4, + LOCAL_GL_PIXEL_MAP_I_TO_A_SIZE = 0x0CB5, + LOCAL_GL_PIXEL_MAP_R_TO_R_SIZE = 0x0CB6, + LOCAL_GL_PIXEL_MAP_G_TO_G_SIZE = 0x0CB7, + LOCAL_GL_PIXEL_MAP_B_TO_B_SIZE = 0x0CB8, + LOCAL_GL_PIXEL_MAP_A_TO_A_SIZE = 0x0CB9, + LOCAL_GL_PIXEL_MAP_S_TO_S = 0x0C71, + LOCAL_GL_PIXEL_MAP_I_TO_I = 0x0C70, + LOCAL_GL_PIXEL_MAP_I_TO_R = 0x0C72, + LOCAL_GL_PIXEL_MAP_I_TO_G = 0x0C73, + LOCAL_GL_PIXEL_MAP_I_TO_B = 0x0C74, + LOCAL_GL_PIXEL_MAP_I_TO_A = 0x0C75, + LOCAL_GL_PIXEL_MAP_R_TO_R = 0x0C76, + LOCAL_GL_PIXEL_MAP_G_TO_G = 0x0C77, + LOCAL_GL_PIXEL_MAP_B_TO_B = 0x0C78, + LOCAL_GL_PIXEL_MAP_A_TO_A = 0x0C79, + LOCAL_GL_PACK_ALIGNMENT = 0x0D05, + LOCAL_GL_PACK_LSB_FIRST = 0x0D01, + LOCAL_GL_PACK_ROW_LENGTH = 0x0D02, + LOCAL_GL_PACK_SKIP_PIXELS = 0x0D04, + LOCAL_GL_PACK_SKIP_ROWS = 0x0D03, + LOCAL_GL_PACK_SWAP_BYTES = 0x0D00, + LOCAL_GL_UNPACK_ALIGNMENT = 0x0CF5, + LOCAL_GL_UNPACK_LSB_FIRST = 0x0CF1, + LOCAL_GL_UNPACK_ROW_LENGTH = 0x0CF2, + LOCAL_GL_UNPACK_SKIP_PIXELS = 0x0CF4, + LOCAL_GL_UNPACK_SKIP_ROWS = 0x0CF3, + LOCAL_GL_UNPACK_SWAP_BYTES = 0x0CF0, + LOCAL_GL_ZOOM_X = 0x0D16, + LOCAL_GL_ZOOM_Y = 0x0D17, + + /* Texture mapping */ + LOCAL_GL_TEXTURE_ENV = 0x2300, + LOCAL_GL_TEXTURE_ENV_MODE = 0x2200, + LOCAL_GL_TEXTURE_1D = 0x0DE0, + LOCAL_GL_TEXTURE_2D = 0x0DE1, + LOCAL_GL_TEXTURE_WRAP_S = 0x2802, + LOCAL_GL_TEXTURE_WRAP_T = 0x2803, + LOCAL_GL_TEXTURE_MAG_FILTER = 0x2800, + LOCAL_GL_TEXTURE_MIN_FILTER = 0x2801, + LOCAL_GL_TEXTURE_ENV_COLOR = 0x2201, + LOCAL_GL_TEXTURE_GEN_S = 0x0C60, + LOCAL_GL_TEXTURE_GEN_T = 0x0C61, + LOCAL_GL_TEXTURE_GEN_MODE = 0x2500, + LOCAL_GL_TEXTURE_BORDER_COLOR = 0x1004, + LOCAL_GL_TEXTURE_WIDTH = 0x1000, + LOCAL_GL_TEXTURE_HEIGHT = 0x1001, + LOCAL_GL_TEXTURE_BORDER = 0x1005, + LOCAL_GL_TEXTURE_COMPONENTS = 0x1003, + LOCAL_GL_TEXTURE_RED_SIZE = 0x805C, + LOCAL_GL_TEXTURE_GREEN_SIZE = 0x805D, + LOCAL_GL_TEXTURE_BLUE_SIZE = 0x805E, + LOCAL_GL_TEXTURE_ALPHA_SIZE = 0x805F, + LOCAL_GL_TEXTURE_LUMINANCE_SIZE = 0x8060, + LOCAL_GL_TEXTURE_INTENSITY_SIZE = 0x8061, + LOCAL_GL_NEAREST_MIPMAP_NEAREST = 0x2700, + LOCAL_GL_NEAREST_MIPMAP_LINEAR = 0x2702, + LOCAL_GL_LINEAR_MIPMAP_NEAREST = 0x2701, + LOCAL_GL_LINEAR_MIPMAP_LINEAR = 0x2703, + LOCAL_GL_OBJECT_LINEAR = 0x2401, + LOCAL_GL_OBJECT_PLANE = 0x2501, + LOCAL_GL_EYE_LINEAR = 0x2400, + LOCAL_GL_EYE_PLANE = 0x2502, + LOCAL_GL_SPHERE_MAP = 0x2402, + LOCAL_GL_DECAL = 0x2101, + LOCAL_GL_MODULATE = 0x2100, + LOCAL_GL_NEAREST = 0x2600, + LOCAL_GL_REPEAT = 0x2901, + LOCAL_GL_CLAMP = 0x2900, + LOCAL_GL_S = 0x2000, + LOCAL_GL_T = 0x2001, + LOCAL_GL_R = 0x2002, + LOCAL_GL_Q = 0x2003, + LOCAL_GL_TEXTURE_GEN_R = 0x0C62, + LOCAL_GL_TEXTURE_GEN_Q = 0x0C63, + + /* GL 1.1 texturing */ + LOCAL_GL_PROXY_TEXTURE_1D = 0x8063, + LOCAL_GL_PROXY_TEXTURE_2D = 0x8064, + LOCAL_GL_TEXTURE_PRIORITY = 0x8066, + LOCAL_GL_TEXTURE_RESIDENT = 0x8067, + LOCAL_GL_TEXTURE_BINDING_1D = 0x8068, + LOCAL_GL_TEXTURE_BINDING_2D = 0x8069, + LOCAL_GL_TEXTURE_INTERNAL_FORMAT = 0x1003, + + /* GL 1.2 texturing */ + LOCAL_GL_PACK_SKIP_IMAGES = 0x806B, + LOCAL_GL_PACK_IMAGE_HEIGHT = 0x806C, + LOCAL_GL_UNPACK_SKIP_IMAGES = 0x806D, + LOCAL_GL_UNPACK_IMAGE_HEIGHT = 0x806E, + LOCAL_GL_TEXTURE_3D = 0x806F, + LOCAL_GL_PROXY_TEXTURE_3D = 0x8070, + LOCAL_GL_TEXTURE_DEPTH = 0x8071, + LOCAL_GL_TEXTURE_WRAP_R = 0x8072, + LOCAL_GL_MAX_3D_TEXTURE_SIZE = 0x8073, + LOCAL_GL_TEXTURE_BINDING_3D = 0x806A, + + /* Internal texture formats (GL 1.1) */ + LOCAL_GL_ALPHA4 = 0x803B, + LOCAL_GL_ALPHA8 = 0x803C, + LOCAL_GL_ALPHA12 = 0x803D, + LOCAL_GL_ALPHA16 = 0x803E, + LOCAL_GL_LUMINANCE4 = 0x803F, + LOCAL_GL_LUMINANCE8 = 0x8040, + LOCAL_GL_LUMINANCE12 = 0x8041, + LOCAL_GL_LUMINANCE16 = 0x8042, + LOCAL_GL_LUMINANCE4_ALPHA4 = 0x8043, + LOCAL_GL_LUMINANCE6_ALPHA2 = 0x8044, + LOCAL_GL_LUMINANCE8_ALPHA8 = 0x8045, + LOCAL_GL_LUMINANCE12_ALPHA4 = 0x8046, + LOCAL_GL_LUMINANCE12_ALPHA12 = 0x8047, + LOCAL_GL_LUMINANCE16_ALPHA16 = 0x8048, + LOCAL_GL_INTENSITY = 0x8049, + LOCAL_GL_INTENSITY4 = 0x804A, + LOCAL_GL_INTENSITY8 = 0x804B, + LOCAL_GL_INTENSITY12 = 0x804C, + LOCAL_GL_INTENSITY16 = 0x804D, + LOCAL_GL_R3_G3_B2 = 0x2A10, + LOCAL_GL_RGB4 = 0x804F, + LOCAL_GL_RGB5 = 0x8050, + LOCAL_GL_RGB8 = 0x8051, + LOCAL_GL_RGB10 = 0x8052, + LOCAL_GL_RGB12 = 0x8053, + LOCAL_GL_RGB16 = 0x8054, + LOCAL_GL_RGBA2 = 0x8055, + LOCAL_GL_RGBA4 = 0x8056, + LOCAL_GL_RGB5_A1 = 0x8057, + LOCAL_GL_RGBA8 = 0x8058, + LOCAL_GL_RGB10_A2 = 0x8059, + LOCAL_GL_RGBA12 = 0x805A, + LOCAL_GL_RGBA16 = 0x805B, + + /* Utility */ + LOCAL_GL_VENDOR = 0x1F00, + LOCAL_GL_RENDERER = 0x1F01, + LOCAL_GL_VERSION = 0x1F02, + LOCAL_GL_EXTENSIONS = 0x1F03, + + /* Errors */ + LOCAL_GL_INVALID_VALUE = 0x0501, + LOCAL_GL_INVALID_ENUM = 0x0500, + LOCAL_GL_INVALID_OPERATION = 0x0502, + LOCAL_GL_STACK_OVERFLOW = 0x0503, + LOCAL_GL_STACK_UNDERFLOW = 0x0504, + LOCAL_GL_OUT_OF_MEMORY = 0x0505, + + /* + * Extensions + */ + + /* LOCAL_GL_EXT_blend_minmax and LOCAL_GL_EXT_blend_color */ + LOCAL_GL_CONSTANT_COLOR_EXT = 0x8001, + LOCAL_GL_ONE_MINUS_CONSTANT_COLOR_EXT = 0x8002, + LOCAL_GL_CONSTANT_ALPHA_EXT = 0x8003, + LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA_EXT = 0x8004, + LOCAL_GL_BLEND_EQUATION_EXT = 0x8009, + LOCAL_GL_MIN_EXT = 0x8007, + LOCAL_GL_MAX_EXT = 0x8008, + LOCAL_GL_FUNC_ADD_EXT = 0x8006, + LOCAL_GL_FUNC_SUBTRACT_EXT = 0x800A, + LOCAL_GL_FUNC_REVERSE_SUBTRACT_EXT = 0x800B, + LOCAL_GL_BLEND_COLOR_EXT = 0x8005, + + /* LOCAL_GL_EXT_polygon_offset */ + LOCAL_GL_POLYGON_OFFSET_EXT = 0x8037, + LOCAL_GL_POLYGON_OFFSET_FACTOR_EXT = 0x8038, + LOCAL_GL_POLYGON_OFFSET_BIAS_EXT = 0x8039, + + /* LOCAL_GL_EXT_vertex_array */ + LOCAL_GL_VERTEX_ARRAY_EXT = 0x8074, + LOCAL_GL_NORMAL_ARRAY_EXT = 0x8075, + LOCAL_GL_COLOR_ARRAY_EXT = 0x8076, + LOCAL_GL_INDEX_ARRAY_EXT = 0x8077, + LOCAL_GL_TEXTURE_COORD_ARRAY_EXT = 0x8078, + LOCAL_GL_EDGE_FLAG_ARRAY_EXT = 0x8079, + LOCAL_GL_VERTEX_ARRAY_SIZE_EXT = 0x807A, + LOCAL_GL_VERTEX_ARRAY_TYPE_EXT = 0x807B, + LOCAL_GL_VERTEX_ARRAY_STRIDE_EXT = 0x807C, + LOCAL_GL_VERTEX_ARRAY_COUNT_EXT = 0x807D, + LOCAL_GL_NORMAL_ARRAY_TYPE_EXT = 0x807E, + LOCAL_GL_NORMAL_ARRAY_STRIDE_EXT = 0x807F, + LOCAL_GL_NORMAL_ARRAY_COUNT_EXT = 0x8080, + LOCAL_GL_COLOR_ARRAY_SIZE_EXT = 0x8081, + LOCAL_GL_COLOR_ARRAY_TYPE_EXT = 0x8082, + LOCAL_GL_COLOR_ARRAY_STRIDE_EXT = 0x8083, + LOCAL_GL_COLOR_ARRAY_COUNT_EXT = 0x8084, + LOCAL_GL_INDEX_ARRAY_TYPE_EXT = 0x8085, + LOCAL_GL_INDEX_ARRAY_STRIDE_EXT = 0x8086, + LOCAL_GL_INDEX_ARRAY_COUNT_EXT = 0x8087, + LOCAL_GL_TEXTURE_COORD_ARRAY_SIZE_EXT = 0x8088, + LOCAL_GL_TEXTURE_COORD_ARRAY_TYPE_EXT = 0x8089, + LOCAL_GL_TEXTURE_COORD_ARRAY_STRIDE_EXT = 0x808A, + LOCAL_GL_TEXTURE_COORD_ARRAY_COUNT_EXT = 0x808B, + LOCAL_GL_EDGE_FLAG_ARRAY_STRIDE_EXT = 0x808C, + LOCAL_GL_EDGE_FLAG_ARRAY_COUNT_EXT = 0x808D, + LOCAL_GL_VERTEX_ARRAY_POINTER_EXT = 0x808E, + LOCAL_GL_NORMAL_ARRAY_POINTER_EXT = 0x808F, + LOCAL_GL_COLOR_ARRAY_POINTER_EXT = 0x8090, + LOCAL_GL_INDEX_ARRAY_POINTER_EXT = 0x8091, + LOCAL_GL_TEXTURE_COORD_ARRAY_POINTER_EXT = 0x8092, + LOCAL_GL_EDGE_FLAG_ARRAY_POINTER_EXT = 0x8093, + + /* LOCAL_GL_EXT_texture_object */ + LOCAL_GL_TEXTURE_PRIORITY_EXT = 0x8066, + LOCAL_GL_TEXTURE_RESIDENT_EXT = 0x8067, + LOCAL_GL_TEXTURE_1D_BINDING_EXT = 0x8068, + LOCAL_GL_TEXTURE_2D_BINDING_EXT = 0x8069, + + /* LOCAL_GL_EXT_texture3D */ + LOCAL_GL_PACK_SKIP_IMAGES_EXT = 0x806B, + LOCAL_GL_PACK_IMAGE_HEIGHT_EXT = 0x806C, + LOCAL_GL_UNPACK_SKIP_IMAGES_EXT = 0x806D, + LOCAL_GL_UNPACK_IMAGE_HEIGHT_EXT = 0x806E, + LOCAL_GL_TEXTURE_3D_EXT = 0x806F, + LOCAL_GL_PROXY_TEXTURE_3D_EXT = 0x8070, + LOCAL_GL_TEXTURE_DEPTH_EXT = 0x8071, + LOCAL_GL_TEXTURE_WRAP_R_EXT = 0x8072, + LOCAL_GL_MAX_3D_TEXTURE_SIZE_EXT = 0x8073, + LOCAL_GL_TEXTURE_3D_BINDING_EXT = 0x806A, + + /* LOCAL_GL_EXT_paletted_texture */ + LOCAL_GL_TABLE_TOO_LARGE_EXT = 0x8031, + LOCAL_GL_COLOR_TABLE_FORMAT_EXT = 0x80D8, + LOCAL_GL_COLOR_TABLE_WIDTH_EXT = 0x80D9, + LOCAL_GL_COLOR_TABLE_RED_SIZE_EXT = 0x80DA, + LOCAL_GL_COLOR_TABLE_GREEN_SIZE_EXT = 0x80DB, + LOCAL_GL_COLOR_TABLE_BLUE_SIZE_EXT = 0x80DC, + LOCAL_GL_COLOR_TABLE_ALPHA_SIZE_EXT = 0x80DD, + LOCAL_GL_COLOR_TABLE_LUMINANCE_SIZE_EXT = 0x80DE, + LOCAL_GL_COLOR_TABLE_INTENSITY_SIZE_EXT = 0x80DF, + LOCAL_GL_TEXTURE_INDEX_SIZE_EXT = 0x80ED, + LOCAL_GL_COLOR_INDEX1_EXT = 0x80E2, + LOCAL_GL_COLOR_INDEX2_EXT = 0x80E3, + LOCAL_GL_COLOR_INDEX4_EXT = 0x80E4, + LOCAL_GL_COLOR_INDEX8_EXT = 0x80E5, + LOCAL_GL_COLOR_INDEX12_EXT = 0x80E6, + LOCAL_GL_COLOR_INDEX16_EXT = 0x80E7, + + /* LOCAL_GL_EXT_shared_texture_palette */ + LOCAL_GL_SHARED_TEXTURE_PALETTE_EXT = 0x81FB, + + /* LOCAL_GL_EXT_point_parameters */ + LOCAL_GL_POINT_SIZE_MIN_EXT = 0x8126, + LOCAL_GL_POINT_SIZE_MAX_EXT = 0x8127, + LOCAL_GL_POINT_FADE_THRESHOLD_SIZE_EXT = 0x8128, + LOCAL_GL_DISTANCE_ATTENUATION_EXT = 0x8129, + + /* LOCAL_GL_EXT_rescale_normal */ + LOCAL_GL_RESCALE_NORMAL_EXT = 0x803A, + + /* LOCAL_GL_EXT_abgr */ + LOCAL_GL_ABGR_EXT = 0x8000, + + /* LOCAL_GL_SGIS_multitexture */ + LOCAL_GL_SELECTED_TEXTURE_SGIS = 0x835C, + LOCAL_GL_SELECTED_TEXTURE_COORD_SET_SGIS = 0x835D, + LOCAL_GL_MAX_TEXTURES_SGIS = 0x835E, + LOCAL_GL_TEXTURE0_SGIS = 0x835F, + LOCAL_GL_TEXTURE1_SGIS = 0x8360, + LOCAL_GL_TEXTURE2_SGIS = 0x8361, + LOCAL_GL_TEXTURE3_SGIS = 0x8362, + LOCAL_GL_TEXTURE_COORD_SET_SOURCE_SGIS = 0x8363, + + /* LOCAL_GL_EXT_multitexture */ + LOCAL_GL_SELECTED_TEXTURE_EXT = 0x83C0, + LOCAL_GL_SELECTED_TEXTURE_COORD_SET_EXT = 0x83C1, + LOCAL_GL_SELECTED_TEXTURE_TRANSFORM_EXT = 0x83C2, + LOCAL_GL_MAX_TEXTURES_EXT = 0x83C3, + LOCAL_GL_MAX_TEXTURE_COORD_SETS_EXT = 0x83C4, + LOCAL_GL_TEXTURE_ENV_COORD_SET_EXT = 0x83C5, + LOCAL_GL_TEXTURE0_EXT = 0x83C6, + LOCAL_GL_TEXTURE1_EXT = 0x83C7, + LOCAL_GL_TEXTURE2_EXT = 0x83C8, + LOCAL_GL_TEXTURE3_EXT = 0x83C9, + + /* LOCAL_GL_SGIS_texture_edge_clamp */ + LOCAL_GL_CLAMP_TO_EDGE_SGIS = 0x812F, + + /* OpenGL 1.2 */ + LOCAL_GL_RESCALE_NORMAL = 0x803A, + LOCAL_GL_CLAMP_TO_EDGE = 0x812F, + LOCAL_GL_MAX_ELEMENTS_VERTICES = 0xF0E8, + LOCAL_GL_MAX_ELEMENTS_INDICES = 0xF0E9, + LOCAL_GL_BGR = 0x80E0, + LOCAL_GL_BGRA = 0x80E1, + LOCAL_GL_UNSIGNED_BYTE_3_3_2 = 0x8032, + LOCAL_GL_UNSIGNED_BYTE_2_3_3_REV = 0x8362, + LOCAL_GL_UNSIGNED_SHORT_5_6_5 = 0x8363, + LOCAL_GL_UNSIGNED_SHORT_5_6_5_REV = 0x8364, + LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 = 0x8033, + LOCAL_GL_UNSIGNED_SHORT_4_4_4_4_REV = 0x8365, + LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034, + LOCAL_GL_UNSIGNED_SHORT_1_5_5_5_REV = 0x8366, + LOCAL_GL_UNSIGNED_INT_8_8_8_8 = 0x8035, + LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV = 0x8367, + LOCAL_GL_UNSIGNED_INT_10_10_10_2 = 0x8036, + LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV = 0x8368, + LOCAL_GL_LIGHT_MODEL_COLOR_CONTROL = 0x81F8, + LOCAL_GL_SINGLE_COLOR = 0x81F9, + LOCAL_GL_SEPARATE_SPECULAR_COLOR = 0x81FA, + LOCAL_GL_TEXTURE_MIN_LOD = 0x813A, + LOCAL_GL_TEXTURE_MAX_LOD = 0x813B, + LOCAL_GL_TEXTURE_BASE_LEVEL = 0x813C, + LOCAL_GL_TEXTURE_MAX_LEVEL = 0x813D +}; + +typedef struct { GLenum e; const char* name; } ENUM; +#define EDEF(VAR) { (GLenum)(LOCAL_GL_##VAR), #VAR } + +static ENUM enums[] = + { + EDEF(BYTE), + EDEF(UNSIGNED_BYTE), + EDEF(SHORT), + EDEF(UNSIGNED_SHORT), + EDEF(INT), + EDEF(UNSIGNED_INT), + EDEF(FLOAT), + EDEF(DOUBLE), + EDEF(2_BYTES), + EDEF(3_BYTES), + EDEF(4_BYTES), +/* + EDEF(LINES), + EDEF(POINTS), + EDEF(LINE_STRIP), + EDEF(LINE_LOOP), + EDEF(TRIANGLES), + EDEF(TRIANGLE_STRIP), + EDEF(TRIANGLE_FAN), + EDEF(QUADS), + EDEF(QUAD_STRIP), + EDEF(POLYGON), + EDEF(EDGE_FLAG), +*/ + EDEF(VERTEX_ARRAY), + EDEF(NORMAL_ARRAY), + EDEF(COLOR_ARRAY), + EDEF(INDEX_ARRAY), + EDEF(TEXTURE_COORD_ARRAY), + EDEF(EDGE_FLAG_ARRAY), + EDEF(VERTEX_ARRAY_SIZE), + EDEF(VERTEX_ARRAY_TYPE), + EDEF(VERTEX_ARRAY_STRIDE), + EDEF(NORMAL_ARRAY_TYPE), + EDEF(NORMAL_ARRAY_STRIDE), + EDEF(COLOR_ARRAY_SIZE), + EDEF(COLOR_ARRAY_TYPE), + EDEF(COLOR_ARRAY_STRIDE), + EDEF(INDEX_ARRAY_TYPE), + EDEF(INDEX_ARRAY_STRIDE), + EDEF(TEXTURE_COORD_ARRAY_SIZE), + EDEF(TEXTURE_COORD_ARRAY_TYPE), + EDEF(TEXTURE_COORD_ARRAY_STRIDE), + EDEF(EDGE_FLAG_ARRAY_STRIDE), + EDEF(VERTEX_ARRAY_POINTER), + EDEF(NORMAL_ARRAY_POINTER), + EDEF(COLOR_ARRAY_POINTER), + EDEF(INDEX_ARRAY_POINTER), + EDEF(TEXTURE_COORD_ARRAY_POINTER), + EDEF(EDGE_FLAG_ARRAY_POINTER), + EDEF(V2F), + EDEF(V3F), + EDEF(C4UB_V2F), + EDEF(C4UB_V3F), + EDEF(C3F_V3F), + EDEF(N3F_V3F), + EDEF(C4F_N3F_V3F), + EDEF(T2F_V3F), + EDEF(T4F_V4F), + EDEF(T2F_C4UB_V3F), + EDEF(T2F_C3F_V3F), + EDEF(T2F_N3F_V3F), + EDEF(T2F_C4F_N3F_V3F), + EDEF(T4F_C4F_N3F_V4F), + EDEF(MATRIX_MODE), + EDEF(MODELVIEW), + EDEF(PROJECTION), + EDEF(TEXTURE), + EDEF(POINT_SMOOTH), + EDEF(POINT_SIZE), + EDEF(POINT_SIZE_GRANULARITY), + EDEF(POINT_SIZE_RANGE), + EDEF(LINE_SMOOTH), + EDEF(LINE_STIPPLE), + EDEF(LINE_STIPPLE_PATTERN), + EDEF(LINE_STIPPLE_REPEAT), + EDEF(LINE_WIDTH), + EDEF(LINE_WIDTH_GRANULARITY), + EDEF(LINE_WIDTH_RANGE), + EDEF(POINT), + EDEF(LINE), + EDEF(FILL), + EDEF(CCW), + EDEF(CW), + EDEF(FRONT), + EDEF(BACK), + EDEF(CULL_FACE), + EDEF(CULL_FACE_MODE), + EDEF(POLYGON_SMOOTH), + EDEF(POLYGON_STIPPLE), + EDEF(FRONT_FACE), + EDEF(POLYGON_MODE), + EDEF(POLYGON_OFFSET_FACTOR), + EDEF(POLYGON_OFFSET_UNITS), + EDEF(POLYGON_OFFSET_POINT), + EDEF(POLYGON_OFFSET_LINE), + EDEF(POLYGON_OFFSET_FILL), + EDEF(COMPILE), + EDEF(COMPILE_AND_EXECUTE), + EDEF(LIST_BASE), + EDEF(LIST_INDEX), + EDEF(LIST_MODE), + EDEF(NEVER), + EDEF(LESS), + EDEF(GEQUAL), + EDEF(LEQUAL), + EDEF(GREATER), + EDEF(NOTEQUAL), + EDEF(EQUAL), + EDEF(ALWAYS), + EDEF(DEPTH_TEST), + EDEF(DEPTH_BITS), + EDEF(DEPTH_CLEAR_VALUE), + EDEF(DEPTH_FUNC), + EDEF(DEPTH_RANGE), + EDEF(DEPTH_WRITEMASK), + EDEF(DEPTH_COMPONENT), + EDEF(LIGHTING), + EDEF(LIGHT0), + EDEF(LIGHT1), + EDEF(LIGHT2), + EDEF(LIGHT3), + EDEF(LIGHT4), + EDEF(LIGHT5), + EDEF(LIGHT6), + EDEF(LIGHT7), + EDEF(SPOT_EXPONENT), + EDEF(SPOT_CUTOFF), + EDEF(CONSTANT_ATTENUATION), + EDEF(LINEAR_ATTENUATION), + EDEF(QUADRATIC_ATTENUATION), + EDEF(AMBIENT), + EDEF(DIFFUSE), + EDEF(SPECULAR), + EDEF(SHININESS), + EDEF(EMISSION), + EDEF(POSITION), + EDEF(SPOT_DIRECTION), + EDEF(AMBIENT_AND_DIFFUSE), + EDEF(COLOR_INDEXES), + EDEF(LIGHT_MODEL_TWO_SIDE), + EDEF(LIGHT_MODEL_LOCAL_VIEWER), + EDEF(LIGHT_MODEL_AMBIENT), + EDEF(FRONT_AND_BACK), + EDEF(SHADE_MODEL), + EDEF(FLAT), + EDEF(SMOOTH), + EDEF(COLOR_MATERIAL), + EDEF(COLOR_MATERIAL_FACE), + EDEF(COLOR_MATERIAL_PARAMETER), + EDEF(NORMALIZE), + EDEF(CLIP_PLANE0), + EDEF(CLIP_PLANE1), + EDEF(CLIP_PLANE2), + EDEF(CLIP_PLANE3), + EDEF(CLIP_PLANE4), + EDEF(CLIP_PLANE5), + EDEF(ACCUM_RED_BITS), + EDEF(ACCUM_GREEN_BITS), + EDEF(ACCUM_BLUE_BITS), + EDEF(ACCUM_ALPHA_BITS), + EDEF(ACCUM_CLEAR_VALUE), + EDEF(ACCUM), + EDEF(ADD), + EDEF(LOAD), + EDEF(MULT), + EDEF(RETURN), + EDEF(ALPHA_TEST), + EDEF(ALPHA_TEST_REF), + EDEF(ALPHA_TEST_FUNC), + EDEF(BLEND), + EDEF(BLEND_SRC), + EDEF(BLEND_DST), + EDEF(ZERO), + EDEF(ONE), + EDEF(SRC_COLOR), + EDEF(ONE_MINUS_SRC_COLOR), + EDEF(DST_COLOR), + EDEF(ONE_MINUS_DST_COLOR), + EDEF(SRC_ALPHA), + EDEF(ONE_MINUS_SRC_ALPHA), + EDEF(DST_ALPHA), + EDEF(ONE_MINUS_DST_ALPHA), + EDEF(SRC_ALPHA_SATURATE), + EDEF(CONSTANT_COLOR), + EDEF(ONE_MINUS_CONSTANT_COLOR), + EDEF(CONSTANT_ALPHA), + EDEF(ONE_MINUS_CONSTANT_ALPHA), + EDEF(FEEDBACK), + EDEF(RENDER), + EDEF(SELECT), + EDEF(2D), + EDEF(3D), + EDEF(3D_COLOR), + EDEF(3D_COLOR_TEXTURE), + EDEF(4D_COLOR_TEXTURE), + EDEF(POINT_TOKEN), + EDEF(LINE_TOKEN), + EDEF(LINE_RESET_TOKEN), + EDEF(POLYGON_TOKEN), + EDEF(BITMAP_TOKEN), + EDEF(DRAW_PIXEL_TOKEN), + EDEF(COPY_PIXEL_TOKEN), + EDEF(PASS_THROUGH_TOKEN), + EDEF(FEEDBACK_BUFFER_POINTER), + EDEF(FEEDBACK_BUFFER_SIZE), + EDEF(FEEDBACK_BUFFER_TYPE), + EDEF(SELECTION_BUFFER_POINTER), + EDEF(SELECTION_BUFFER_SIZE), + EDEF(FOG), + EDEF(FOG_MODE), + EDEF(FOG_DENSITY), + EDEF(FOG_COLOR), + EDEF(FOG_INDEX), + EDEF(FOG_START), + EDEF(FOG_END), + EDEF(LINEAR), + EDEF(EXP), + EDEF(EXP2), + EDEF(LOGIC_OP), + EDEF(INDEX_LOGIC_OP), + EDEF(COLOR_LOGIC_OP), + EDEF(LOGIC_OP_MODE), + EDEF(CLEAR), + EDEF(SET), + EDEF(COPY), + EDEF(COPY_INVERTED), + EDEF(NOOP), + EDEF(INVERT), + EDEF(AND), + EDEF(NAND), + EDEF(OR), + EDEF(NOR), + EDEF(XOR), + EDEF(EQUIV), + EDEF(AND_REVERSE), + EDEF(AND_INVERTED), + EDEF(OR_REVERSE), + EDEF(OR_INVERTED), + EDEF(STENCIL_TEST), + EDEF(STENCIL_WRITEMASK), + EDEF(STENCIL_BITS), + EDEF(STENCIL_FUNC), + EDEF(STENCIL_VALUE_MASK), + EDEF(STENCIL_REF), + EDEF(STENCIL_FAIL), + EDEF(STENCIL_PASS_DEPTH_PASS), + EDEF(STENCIL_PASS_DEPTH_FAIL), + EDEF(STENCIL_CLEAR_VALUE), + EDEF(STENCIL_INDEX), + EDEF(KEEP), + EDEF(REPLACE), + EDEF(INCR), + EDEF(DECR), + EDEF(NONE), + EDEF(LEFT), + EDEF(RIGHT), + EDEF(FRONT_LEFT), + EDEF(FRONT_RIGHT), + EDEF(BACK_LEFT), + EDEF(BACK_RIGHT), + EDEF(AUX0), + EDEF(AUX1), + EDEF(AUX2), + EDEF(AUX3), + EDEF(COLOR_INDEX), + EDEF(RED), + EDEF(GREEN), + EDEF(BLUE), + EDEF(ALPHA), + EDEF(LUMINANCE), + EDEF(LUMINANCE_ALPHA), + EDEF(ALPHA_BITS), + EDEF(RED_BITS), + EDEF(GREEN_BITS), + EDEF(BLUE_BITS), + EDEF(INDEX_BITS), + EDEF(SUBPIXEL_BITS), + EDEF(AUX_BUFFERS), + EDEF(READ_BUFFER), + EDEF(DRAW_BUFFER), + EDEF(DOUBLEBUFFER), + EDEF(STEREO), + EDEF(BITMAP), + EDEF(COLOR), + EDEF(DEPTH), + EDEF(STENCIL), + EDEF(DITHER), + EDEF(RGB), + EDEF(RGBA), + EDEF(MAX_LIST_NESTING), + EDEF(MAX_ATTRIB_STACK_DEPTH), + EDEF(MAX_MODELVIEW_STACK_DEPTH), + EDEF(MAX_NAME_STACK_DEPTH), + EDEF(MAX_PROJECTION_STACK_DEPTH), + EDEF(MAX_TEXTURE_STACK_DEPTH), + EDEF(MAX_EVAL_ORDER), + EDEF(MAX_LIGHTS), + EDEF(MAX_CLIP_PLANES), + EDEF(MAX_TEXTURE_SIZE), + EDEF(MAX_PIXEL_MAP_TABLE), + EDEF(MAX_VIEWPORT_DIMS), + EDEF(MAX_CLIENT_ATTRIB_STACK_DEPTH), + EDEF(ATTRIB_STACK_DEPTH), + EDEF(CLIENT_ATTRIB_STACK_DEPTH), + EDEF(COLOR_CLEAR_VALUE), + EDEF(COLOR_WRITEMASK), + EDEF(CURRENT_INDEX), + EDEF(CURRENT_COLOR), + EDEF(CURRENT_NORMAL), + EDEF(CURRENT_RASTER_COLOR), + EDEF(CURRENT_RASTER_DISTANCE), + EDEF(CURRENT_RASTER_INDEX), + EDEF(CURRENT_RASTER_POSITION), + EDEF(CURRENT_RASTER_TEXTURE_COORDS), + EDEF(CURRENT_RASTER_POSITION_VALID), + EDEF(CURRENT_TEXTURE_COORDS), + EDEF(INDEX_CLEAR_VALUE), + EDEF(INDEX_MODE), + EDEF(INDEX_WRITEMASK), + EDEF(MODELVIEW_MATRIX), + EDEF(MODELVIEW_STACK_DEPTH), + EDEF(NAME_STACK_DEPTH), + EDEF(PROJECTION_MATRIX), + EDEF(PROJECTION_STACK_DEPTH), + EDEF(RENDER_MODE), + EDEF(RGBA_MODE), + EDEF(TEXTURE_MATRIX), + EDEF(TEXTURE_STACK_DEPTH), + EDEF(VIEWPORT), + EDEF(AUTO_NORMAL), + EDEF(MAP1_COLOR_4), + EDEF(MAP1_GRID_DOMAIN), + EDEF(MAP1_GRID_SEGMENTS), + EDEF(MAP1_INDEX), + EDEF(MAP1_NORMAL), + EDEF(MAP1_TEXTURE_COORD_1), + EDEF(MAP1_TEXTURE_COORD_2), + EDEF(MAP1_TEXTURE_COORD_3), + EDEF(MAP1_TEXTURE_COORD_4), + EDEF(MAP1_VERTEX_3), + EDEF(MAP1_VERTEX_4), + EDEF(MAP2_COLOR_4), + EDEF(MAP2_GRID_DOMAIN), + EDEF(MAP2_GRID_SEGMENTS), + EDEF(MAP2_INDEX), + EDEF(MAP2_NORMAL), + EDEF(MAP2_TEXTURE_COORD_1), + EDEF(MAP2_TEXTURE_COORD_2), + EDEF(MAP2_TEXTURE_COORD_3), + EDEF(MAP2_TEXTURE_COORD_4), + EDEF(MAP2_VERTEX_3), + EDEF(MAP2_VERTEX_4), + EDEF(COEFF), + EDEF(DOMAIN), + EDEF(ORDER), + EDEF(FOG_HINT), + EDEF(LINE_SMOOTH_HINT), + EDEF(PERSPECTIVE_CORRECTION_HINT), + EDEF(POINT_SMOOTH_HINT), + EDEF(POLYGON_SMOOTH_HINT), + EDEF(DONT_CARE), + EDEF(FASTEST), + EDEF(NICEST), + EDEF(SCISSOR_TEST), + EDEF(SCISSOR_BOX), + EDEF(MAP_COLOR), + EDEF(MAP_STENCIL), + EDEF(INDEX_SHIFT), + EDEF(INDEX_OFFSET), + EDEF(RED_SCALE), + EDEF(RED_BIAS), + EDEF(GREEN_SCALE), + EDEF(GREEN_BIAS), + EDEF(BLUE_SCALE), + EDEF(BLUE_BIAS), + EDEF(ALPHA_SCALE), + EDEF(ALPHA_BIAS), + EDEF(DEPTH_SCALE), + EDEF(DEPTH_BIAS), + EDEF(PIXEL_MAP_S_TO_S_SIZE), + EDEF(PIXEL_MAP_I_TO_I_SIZE), + EDEF(PIXEL_MAP_I_TO_R_SIZE), + EDEF(PIXEL_MAP_I_TO_G_SIZE), + EDEF(PIXEL_MAP_I_TO_B_SIZE), + EDEF(PIXEL_MAP_I_TO_A_SIZE), + EDEF(PIXEL_MAP_R_TO_R_SIZE), + EDEF(PIXEL_MAP_G_TO_G_SIZE), + EDEF(PIXEL_MAP_B_TO_B_SIZE), + EDEF(PIXEL_MAP_A_TO_A_SIZE), + EDEF(PIXEL_MAP_S_TO_S), + EDEF(PIXEL_MAP_I_TO_I), + EDEF(PIXEL_MAP_I_TO_R), + EDEF(PIXEL_MAP_I_TO_G), + EDEF(PIXEL_MAP_I_TO_B), + EDEF(PIXEL_MAP_I_TO_A), + EDEF(PIXEL_MAP_R_TO_R), + EDEF(PIXEL_MAP_G_TO_G), + EDEF(PIXEL_MAP_B_TO_B), + EDEF(PIXEL_MAP_A_TO_A), + EDEF(PACK_ALIGNMENT), + EDEF(PACK_LSB_FIRST), + EDEF(PACK_ROW_LENGTH), + EDEF(PACK_SKIP_PIXELS), + EDEF(PACK_SKIP_ROWS), + EDEF(PACK_SWAP_BYTES), + EDEF(UNPACK_ALIGNMENT), + EDEF(UNPACK_LSB_FIRST), + EDEF(UNPACK_ROW_LENGTH), + EDEF(UNPACK_SKIP_PIXELS), + EDEF(UNPACK_SKIP_ROWS), + EDEF(UNPACK_SWAP_BYTES), + EDEF(ZOOM_X), + EDEF(ZOOM_Y), + EDEF(TEXTURE_ENV), + EDEF(TEXTURE_ENV_MODE), + EDEF(TEXTURE_1D), + EDEF(TEXTURE_2D), + EDEF(TEXTURE_WRAP_S), + EDEF(TEXTURE_WRAP_T), + EDEF(TEXTURE_MAG_FILTER), + EDEF(TEXTURE_MIN_FILTER), + EDEF(TEXTURE_ENV_COLOR), + EDEF(TEXTURE_GEN_S), + EDEF(TEXTURE_GEN_T), + EDEF(TEXTURE_GEN_MODE), + EDEF(TEXTURE_BORDER_COLOR), + EDEF(TEXTURE_WIDTH), + EDEF(TEXTURE_HEIGHT), + EDEF(TEXTURE_BORDER), + EDEF(TEXTURE_COMPONENTS), + EDEF(TEXTURE_RED_SIZE), + EDEF(TEXTURE_GREEN_SIZE), + EDEF(TEXTURE_BLUE_SIZE), + EDEF(TEXTURE_ALPHA_SIZE), + EDEF(TEXTURE_LUMINANCE_SIZE), + EDEF(TEXTURE_INTENSITY_SIZE), + EDEF(NEAREST_MIPMAP_NEAREST), + EDEF(NEAREST_MIPMAP_LINEAR), + EDEF(LINEAR_MIPMAP_NEAREST), + EDEF(LINEAR_MIPMAP_LINEAR), + EDEF(OBJECT_LINEAR), + EDEF(OBJECT_PLANE), + EDEF(EYE_LINEAR), + EDEF(EYE_PLANE), + EDEF(SPHERE_MAP), + EDEF(DECAL), + EDEF(MODULATE), + EDEF(NEAREST), + EDEF(REPEAT), + EDEF(CLAMP), + EDEF(S), + EDEF(T), + EDEF(R), + EDEF(Q), + EDEF(TEXTURE_GEN_R), + EDEF(TEXTURE_GEN_Q), + EDEF(PROXY_TEXTURE_1D), + EDEF(PROXY_TEXTURE_2D), + EDEF(TEXTURE_PRIORITY), + EDEF(TEXTURE_RESIDENT), + EDEF(TEXTURE_BINDING_1D), + EDEF(TEXTURE_BINDING_2D), + EDEF(TEXTURE_INTERNAL_FORMAT), + EDEF(PACK_SKIP_IMAGES), + EDEF(PACK_IMAGE_HEIGHT), + EDEF(UNPACK_SKIP_IMAGES), + EDEF(UNPACK_IMAGE_HEIGHT), + EDEF(TEXTURE_3D), + EDEF(PROXY_TEXTURE_3D), + EDEF(TEXTURE_DEPTH), + EDEF(TEXTURE_WRAP_R), + EDEF(MAX_3D_TEXTURE_SIZE), + EDEF(TEXTURE_BINDING_3D), + EDEF(ALPHA4), + EDEF(ALPHA8), + EDEF(ALPHA12), + EDEF(ALPHA16), + EDEF(LUMINANCE4), + EDEF(LUMINANCE8), + EDEF(LUMINANCE12), + EDEF(LUMINANCE16), + EDEF(LUMINANCE4_ALPHA4), + EDEF(LUMINANCE6_ALPHA2), + EDEF(LUMINANCE8_ALPHA8), + EDEF(LUMINANCE12_ALPHA4), + EDEF(LUMINANCE12_ALPHA12), + EDEF(LUMINANCE16_ALPHA16), + EDEF(INTENSITY), + EDEF(INTENSITY4), + EDEF(INTENSITY8), + EDEF(INTENSITY12), + EDEF(INTENSITY16), + EDEF(R3_G3_B2), + EDEF(RGB4), + EDEF(RGB5), + EDEF(RGB8), + EDEF(RGB10), + EDEF(RGB12), + EDEF(RGB16), + EDEF(RGBA2), + EDEF(RGBA4), + EDEF(RGB5_A1), + EDEF(RGBA8), + EDEF(RGB10_A2), + EDEF(RGBA12), + EDEF(RGBA16), + EDEF(VENDOR), + EDEF(RENDERER), + EDEF(VERSION), + EDEF(EXTENSIONS), + EDEF(INVALID_VALUE), + EDEF(INVALID_ENUM), + EDEF(INVALID_OPERATION), + EDEF(STACK_OVERFLOW), + EDEF(STACK_UNDERFLOW), + EDEF(OUT_OF_MEMORY), + + /* extensions */ + EDEF(CONSTANT_COLOR_EXT), + EDEF(ONE_MINUS_CONSTANT_COLOR_EXT), + EDEF(CONSTANT_ALPHA_EXT), + EDEF(ONE_MINUS_CONSTANT_ALPHA_EXT), + EDEF(BLEND_EQUATION_EXT), + EDEF(MIN_EXT), + EDEF(MAX_EXT), + EDEF(FUNC_ADD_EXT), + EDEF(FUNC_SUBTRACT_EXT), + EDEF(FUNC_REVERSE_SUBTRACT_EXT), + EDEF(BLEND_COLOR_EXT), + EDEF(POLYGON_OFFSET_EXT), + EDEF(POLYGON_OFFSET_FACTOR_EXT), + EDEF(POLYGON_OFFSET_BIAS_EXT), + EDEF(VERTEX_ARRAY_EXT), + EDEF(NORMAL_ARRAY_EXT), + EDEF(COLOR_ARRAY_EXT), + EDEF(INDEX_ARRAY_EXT), + EDEF(TEXTURE_COORD_ARRAY_EXT), + EDEF(EDGE_FLAG_ARRAY_EXT), + EDEF(VERTEX_ARRAY_SIZE_EXT), + EDEF(VERTEX_ARRAY_TYPE_EXT), + EDEF(VERTEX_ARRAY_STRIDE_EXT), + EDEF(VERTEX_ARRAY_COUNT_EXT), + EDEF(NORMAL_ARRAY_TYPE_EXT), + EDEF(NORMAL_ARRAY_STRIDE_EXT), + EDEF(NORMAL_ARRAY_COUNT_EXT), + EDEF(COLOR_ARRAY_SIZE_EXT), + EDEF(COLOR_ARRAY_TYPE_EXT), + EDEF(COLOR_ARRAY_STRIDE_EXT), + EDEF(COLOR_ARRAY_COUNT_EXT), + EDEF(INDEX_ARRAY_TYPE_EXT), + EDEF(INDEX_ARRAY_STRIDE_EXT), + EDEF(INDEX_ARRAY_COUNT_EXT), + EDEF(TEXTURE_COORD_ARRAY_SIZE_EXT), + EDEF(TEXTURE_COORD_ARRAY_TYPE_EXT), + EDEF(TEXTURE_COORD_ARRAY_STRIDE_EXT), + EDEF(TEXTURE_COORD_ARRAY_COUNT_EXT), + EDEF(EDGE_FLAG_ARRAY_STRIDE_EXT), + EDEF(EDGE_FLAG_ARRAY_COUNT_EXT), + EDEF(VERTEX_ARRAY_POINTER_EXT), + EDEF(NORMAL_ARRAY_POINTER_EXT), + EDEF(COLOR_ARRAY_POINTER_EXT), + EDEF(INDEX_ARRAY_POINTER_EXT), + EDEF(TEXTURE_COORD_ARRAY_POINTER_EXT), + EDEF(EDGE_FLAG_ARRAY_POINTER_EXT), + EDEF(TEXTURE_PRIORITY_EXT), + EDEF(TEXTURE_RESIDENT_EXT), + EDEF(TEXTURE_1D_BINDING_EXT), + EDEF(TEXTURE_2D_BINDING_EXT), + EDEF(PACK_SKIP_IMAGES_EXT), + EDEF(PACK_IMAGE_HEIGHT_EXT), + EDEF(UNPACK_SKIP_IMAGES_EXT), + EDEF(UNPACK_IMAGE_HEIGHT_EXT), + EDEF(TEXTURE_3D_EXT), + EDEF(PROXY_TEXTURE_3D_EXT), + EDEF(TEXTURE_DEPTH_EXT), + EDEF(TEXTURE_WRAP_R_EXT), + EDEF(MAX_3D_TEXTURE_SIZE_EXT), + EDEF(TEXTURE_3D_BINDING_EXT), + EDEF(TABLE_TOO_LARGE_EXT), + EDEF(COLOR_TABLE_FORMAT_EXT), + EDEF(COLOR_TABLE_WIDTH_EXT), + EDEF(COLOR_TABLE_RED_SIZE_EXT), + EDEF(COLOR_TABLE_GREEN_SIZE_EXT), + EDEF(COLOR_TABLE_BLUE_SIZE_EXT), + EDEF(COLOR_TABLE_ALPHA_SIZE_EXT), + EDEF(COLOR_TABLE_LUMINANCE_SIZE_EXT), + EDEF(COLOR_TABLE_INTENSITY_SIZE_EXT), + EDEF(TEXTURE_INDEX_SIZE_EXT), + EDEF(COLOR_INDEX1_EXT), + EDEF(COLOR_INDEX2_EXT), + EDEF(COLOR_INDEX4_EXT), + EDEF(COLOR_INDEX8_EXT), + EDEF(COLOR_INDEX12_EXT), + EDEF(COLOR_INDEX16_EXT), + EDEF(SHARED_TEXTURE_PALETTE_EXT), + EDEF(POINT_SIZE_MIN_EXT), + EDEF(POINT_SIZE_MAX_EXT), + EDEF(POINT_FADE_THRESHOLD_SIZE_EXT), + EDEF(DISTANCE_ATTENUATION_EXT), + EDEF(RESCALE_NORMAL_EXT), + EDEF(ABGR_EXT), + EDEF(SELECTED_TEXTURE_SGIS), + EDEF(SELECTED_TEXTURE_COORD_SET_SGIS), + EDEF(MAX_TEXTURES_SGIS), + EDEF(TEXTURE0_SGIS), + EDEF(TEXTURE1_SGIS), + EDEF(TEXTURE2_SGIS), + EDEF(TEXTURE3_SGIS), + EDEF(TEXTURE_COORD_SET_SOURCE_SGIS), + EDEF(SELECTED_TEXTURE_EXT), + EDEF(SELECTED_TEXTURE_COORD_SET_EXT), + EDEF(SELECTED_TEXTURE_TRANSFORM_EXT), + EDEF(MAX_TEXTURES_EXT), + EDEF(MAX_TEXTURE_COORD_SETS_EXT), + EDEF(TEXTURE_ENV_COORD_SET_EXT), + EDEF(TEXTURE0_EXT), + EDEF(TEXTURE1_EXT), + EDEF(TEXTURE2_EXT), + EDEF(TEXTURE3_EXT), + EDEF(CLAMP_TO_EDGE_SGIS), + EDEF(RESCALE_NORMAL), + EDEF(CLAMP_TO_EDGE), + EDEF(MAX_ELEMENTS_VERTICES), + EDEF(MAX_ELEMENTS_INDICES), + EDEF(BGR), + EDEF(BGRA), + EDEF(UNSIGNED_BYTE_3_3_2), + EDEF(UNSIGNED_BYTE_2_3_3_REV), + EDEF(UNSIGNED_SHORT_5_6_5), + EDEF(UNSIGNED_SHORT_5_6_5_REV), + EDEF(UNSIGNED_SHORT_4_4_4_4), + EDEF(UNSIGNED_SHORT_4_4_4_4_REV), + EDEF(UNSIGNED_SHORT_5_5_5_1), + EDEF(UNSIGNED_SHORT_1_5_5_5_REV), + EDEF(UNSIGNED_INT_8_8_8_8), + EDEF(UNSIGNED_INT_8_8_8_8_REV), + EDEF(UNSIGNED_INT_10_10_10_2), + EDEF(UNSIGNED_INT_2_10_10_10_REV), + EDEF(LIGHT_MODEL_COLOR_CONTROL), + EDEF(SINGLE_COLOR), + EDEF(SEPARATE_SPECULAR_COLOR), + EDEF(TEXTURE_MIN_LOD), + EDEF(TEXTURE_MAX_LOD), + EDEF(TEXTURE_BASE_LEVEL), + EDEF(TEXTURE_MAX_LEVEL) +}; + +#undef EDEF + +#define N_ENUMS (sizeof(enums) / sizeof(ENUM)) + +/***************************************************************************/ + +static void print_enum_name( FILE* OUT, GLenum e ) +{ + int i, found= 0; + for( i= 0; i < N_ENUMS; ++i ) + { + if( enums[i].e == e ) + { + if( found ) + fprintf( OUT, "/" ); + found= 1; + fprintf( OUT, "%s", enums[i].name ); + } + } + if( ! found ) + fprintf( OUT, "*UNKNOWN* [%04x]", (int)e ); + fprintf( OUT, "\n" ); +} + +#define BOOL_STRING(b) (b ? "true" : "false") + +#define VAR_ENUM(VAR) \ + { \ + GLint e= 0; \ + glGetIntegerv(GL_##VAR,&e); \ + fprintf( OUT, "%s: ", #VAR ); \ + print_enum_name( OUT, (GLenum) e ); \ + } + +#define VAR_FLOAT4(VAR) \ + { \ + GLfloat f[4]; \ + f[0]= f[1]= f[2]= f[3]= 0.0; \ + glGetFloatv(GL_##VAR,f); \ + fprintf( OUT, "%s: [%f %f %f %f]\n", \ + #VAR, f[0], f[1], f[2], f[3] ); \ + } + +#define VAR_MAT_FLOAT4(VAR) \ + { \ + GLfloat f[4]; \ + f[0]= f[1]= f[2]= f[3]= 0.0; \ + glGetMaterialfv(GL_FRONT,GL_##VAR,f); \ + fprintf( OUT, "FRONT_%s: [%f %f %f %f]\n", \ + #VAR, f[0], f[1], f[2], f[3] ); \ + glGetMaterialfv(GL_BACK,GL_##VAR,f); \ + fprintf( OUT, " BACK_%s: [%f %f %f %f]\n", \ + #VAR, f[0], f[1], f[2], f[3] ); \ + } + +#define VAR_LIGHT_FLOAT4(LIGHT,VAR) \ + { \ + GLfloat f[4]; \ + f[0]= f[1]= f[2]= f[3]= 0.0; \ + glGetLightfv(GL_LIGHT0+LIGHT,GL_##VAR,f); \ + fprintf( OUT, "LIGHT%d.%s: [%f %f %f %f]\n", \ + LIGHT, #VAR, f[0], f[1], f[2], f[3] ); \ + } + +#define VAR_LIGHT_FLOAT3(LIGHT,VAR) \ + { \ + GLfloat f[3]; \ + f[0]= f[1]= f[2]= 0.0; \ + glGetLightfv(GL_LIGHT0+LIGHT,GL_##VAR,f); \ + fprintf( OUT, "LIGHT%d.%s: [%f %f %f]\n", \ + LIGHT, #VAR, f[0], f[1], f[2] ); \ + } + +#define VAR_FLOAT3(VAR) \ + { \ + GLfloat f[3]; \ + f[0]= f[1]= f[2]= 0.0; \ + glGetFloatv(GL_##VAR,f) ; \ + fprintf( OUT, "%s: [%f %f %f]\n", \ + #VAR, f[0], f[1], f[2] ); \ + } +#define VAR_FLOAT2(VAR) \ + { \ + GLfloat f[2]; \ + f[0]= f[1]= 0.0; \ + glGetFloatv(GL_##VAR,f); \ + fprintf( OUT, "%s: [%f %f]\n", \ + #VAR, f[0], f[1] ); \ + } + +#define VAR_COLOR(VAR) VAR_FLOAT4(VAR) +#define VAR_TEXCOORD(VAR) VAR_FLOAT4(VAR) +#define VAR_NORMAL(VAR) VAR_FLOAT3(VAR) + +#define VAR_MAT_COLOR(VAR) VAR_MAT_FLOAT4(VAR) +#define VAR_LIGHT_COLOR(LIGHT,VAR) VAR_LIGHT_FLOAT4(LIGHT,VAR) + +#define VAR_FLOAT(VAR) \ + { \ + GLfloat f= 0.0; \ + glGetFloatv(GL_##VAR,&f); \ + fprintf( OUT, "%s: %f\n", #VAR, f ); \ + } + +#define VAR_MAT_FLOAT(VAR) \ + { \ + GLfloat f= 0.0; \ + glGetMaterialfv(GL_FRONT,GL_##VAR,&f); \ + fprintf( OUT, "FRONT_%s: %f\n", #VAR, f ); \ + glGetMaterialfv(GL_BACK,GL_##VAR,&f); \ + fprintf( OUT, " BACK_%s: %f\n", #VAR, f ); \ + } + +#define VAR_LIGHT_FLOAT(LIGHT,VAR) \ + { \ + GLfloat f= 0.0; \ + glGetLightfv(GL_LIGHT0+LIGHT,GL_##VAR,&f); \ + fprintf( OUT, "LIGHT%d.%s: %f\n", \ + LIGHT, #VAR, f ); \ + } + +#define VAR_INT(VAR) \ + { \ + GLint i= 0; \ + glGetIntegerv(GL_##VAR,&i); \ + fprintf( OUT, "%s: %d\n", #VAR, (int)i ); \ + } +#define VAR_INTEGER(VAR) VAR_INT(VAR) +#define VAR_INDEX(VAR) VAR_INT(VAR) +#define VAR_HEXINT(VAR) \ + { \ + GLint i= 0; \ + glGetIntegerv(GL_##VAR,&i); \ + fprintf( OUT, "%s: 0x%04x\n", #VAR, (int)i ); \ + } +#define VAR_INT4(VAR) \ + { \ + GLint i[4]; \ + i[0]= i[1]= i[2]= i[3]= 0; \ + glGetIntegerv(GL_##VAR,i); \ + fprintf( OUT, "%s: [%d %d %d %d]\n", \ + #VAR, (int)i[0], (int)i[1], (int)i[2], (int)i[3] ); \ + } +#define VAR_BOOL(VAR) \ + { \ + GLboolean b= 0; \ + glGetBooleanv(GL_##VAR,&b); \ + fprintf( OUT, "%s: %s\n", #VAR, BOOL_STRING(b) ); \ + } +#define VAR_BOOL4(VAR) \ + { \ + GLboolean b[4]; \ + b[0]= b[1]= b[2]= b[3]= 0; \ + glGetBooleanv(GL_##VAR,b); \ + fprintf( OUT, "%s: [%s %s %s %s]\n", \ + #VAR, \ + BOOL_STRING(b[0]), \ + BOOL_STRING(b[1]), \ + BOOL_STRING(b[2]), \ + BOOL_STRING(b[3]) ); \ + } +#define VAR_PTR(VAR) \ + { \ + GLvoid* p= 0; \ + glGetPointerv(GL_##VAR,&p); \ + fprintf( OUT, "%s: %p\n", #VAR, p ); \ + } +#define VAR_MATRIX(VAR) \ + { \ + GLfloat m[16]; \ + int i; \ + for( i= 0; i < 16; ++i ) m[i]= 0.0; \ + glGetFloatv(GL_##VAR,m); \ + fprintf( OUT, \ + "%s:\n\t[%+.6f %+.6f %+.6f %+.6f]\n\t[%+.6f %+.6f %+.6f +%+.6f]\n\t[%+.6f %+.6f %+.6f %+.6f]\n\t[%+.6f %+.6f %+.6f %+.6f]\n", \ + #VAR, \ + m[0+0*4], m[0+1*4], m[0+2*4], m[0+3*4], \ + m[1+0*4], m[1+1*4], m[1+2*4], m[1+3*4], \ + m[2+0*4], m[2+1*4], m[2+2*4], m[2+3*4], \ + m[3+0*4], m[3+1*4], m[3+2*4], m[3+3*4] ); \ + } + +/***************************************************************************/ + +/* +#define OUT stderr +*/ +void dump_opengl_state( FILE* OUT ) +{ + int i; + GLint n_lights= 0; + + glGetIntegerv( GL_MAX_LIGHTS, &n_lights ); + + VAR_COLOR(CURRENT_COLOR) + VAR_INDEX(CURRENT_INDEX) + VAR_TEXCOORD(CURRENT_TEXTURE_COORDS) + VAR_NORMAL(CURRENT_NORMAL) + VAR_FLOAT4(CURRENT_RASTER_POSITION) + VAR_FLOAT(CURRENT_RASTER_DISTANCE) + VAR_COLOR(CURRENT_RASTER_COLOR) + VAR_INDEX(CURRENT_RASTER_INDEX) + VAR_TEXCOORD(CURRENT_RASTER_TEXTURE_COORDS) + VAR_BOOL(CURRENT_RASTER_POSITION_VALID) + VAR_BOOL(EDGE_FLAG) + + VAR_BOOL (VERTEX_ARRAY) + VAR_INTEGER(VERTEX_ARRAY_SIZE) + VAR_ENUM (VERTEX_ARRAY_TYPE) + VAR_INTEGER(VERTEX_ARRAY_STRIDE) + VAR_PTR (VERTEX_ARRAY_POINTER) + + VAR_BOOL (NORMAL_ARRAY) + VAR_ENUM (NORMAL_ARRAY_TYPE) + VAR_INTEGER(NORMAL_ARRAY_STRIDE) + VAR_PTR (NORMAL_ARRAY_POINTER) + + VAR_BOOL (COLOR_ARRAY) + VAR_INTEGER(COLOR_ARRAY_SIZE) + VAR_ENUM (COLOR_ARRAY_TYPE) + VAR_INTEGER(COLOR_ARRAY_STRIDE) + VAR_PTR (COLOR_ARRAY_POINTER) + + VAR_BOOL (INDEX_ARRAY) + VAR_ENUM (INDEX_ARRAY_TYPE) + VAR_INTEGER(INDEX_ARRAY_STRIDE) + VAR_PTR (INDEX_ARRAY_POINTER) + + VAR_BOOL (TEXTURE_COORD_ARRAY) + VAR_INTEGER(TEXTURE_COORD_ARRAY_SIZE) + VAR_ENUM (TEXTURE_COORD_ARRAY_TYPE) + VAR_INTEGER(TEXTURE_COORD_ARRAY_STRIDE) + VAR_PTR (TEXTURE_COORD_ARRAY_POINTER) + + VAR_BOOL (EDGE_FLAG_ARRAY) + VAR_INTEGER(EDGE_FLAG_ARRAY_STRIDE) + VAR_PTR (EDGE_FLAG_ARRAY_POINTER) + + VAR_MATRIX(MODELVIEW_MATRIX) + VAR_MATRIX(PROJECTION_MATRIX) + VAR_MATRIX(TEXTURE_MATRIX) + VAR_INT4(VIEWPORT) + VAR_FLOAT2(DEPTH_RANGE) + VAR_INT(MODELVIEW_STACK_DEPTH) + VAR_INT(PROJECTION_STACK_DEPTH) + VAR_INT(TEXTURE_STACK_DEPTH) + VAR_ENUM(MATRIX_MODE) + VAR_BOOL(NORMALIZE) + VAR_BOOL(RESCALE_NORMAL_EXT) + VAR_BOOL(CLIP_PLANE0) + VAR_BOOL(CLIP_PLANE1) + VAR_BOOL(CLIP_PLANE2) + VAR_BOOL(CLIP_PLANE3) + VAR_BOOL(CLIP_PLANE4) + VAR_BOOL(CLIP_PLANE5) + /* + glGetClipPlane() */ + + VAR_COLOR(FOG_COLOR) + VAR_INDEX(FOG_INDEX) + VAR_FLOAT(FOG_DENSITY) + VAR_FLOAT(FOG_START) + VAR_FLOAT(FOG_END) + VAR_ENUM(FOG_MODE) + VAR_BOOL(FOG) + VAR_ENUM(SHADE_MODEL) + + VAR_BOOL(LIGHTING) + VAR_BOOL(COLOR_MATERIAL) + VAR_ENUM(COLOR_MATERIAL_PARAMETER) + VAR_ENUM(COLOR_MATERIAL_FACE) + + VAR_MAT_COLOR(AMBIENT) + VAR_MAT_COLOR(DIFFUSE) + VAR_MAT_COLOR(SPECULAR) + VAR_MAT_COLOR(EMISSION) + VAR_MAT_FLOAT(SHININESS) + + VAR_COLOR(LIGHT_MODEL_AMBIENT) + VAR_BOOL(LIGHT_MODEL_LOCAL_VIEWER) + VAR_BOOL(LIGHT_MODEL_TWO_SIDE) +/* VAR_ENUM(LIGHT_MODEL_COLOR_CONTROL)*/ + + for( i= 0; i < n_lights; ++i ) + { + GLboolean b= 0; + + glGetBooleanv( GL_LIGHT0 + i, &b ); + fprintf( OUT, "LIGHT%d: %s\n", i, BOOL_STRING(b) ); + + if( ! b ) + continue; + + VAR_LIGHT_COLOR(i,AMBIENT) + VAR_LIGHT_COLOR(i,DIFFUSE) + VAR_LIGHT_COLOR(i,SPECULAR) + VAR_LIGHT_FLOAT4(i,POSITION) + VAR_LIGHT_FLOAT(i,CONSTANT_ATTENUATION) + VAR_LIGHT_FLOAT(i,LINEAR_ATTENUATION) + VAR_LIGHT_FLOAT(i,QUADRATIC_ATTENUATION) + VAR_LIGHT_FLOAT3(i,SPOT_DIRECTION) + VAR_LIGHT_FLOAT(i,SPOT_EXPONENT) + VAR_LIGHT_FLOAT(i,SPOT_CUTOFF) + /* COLOR_INDEXES */ + } + + VAR_FLOAT(POINT_SIZE) + VAR_BOOL(POINT_SMOOTH) + VAR_FLOAT(LINE_WIDTH) + VAR_BOOL(LINE_SMOOTH) + VAR_HEXINT(LINE_STIPPLE_PATTERN) + VAR_INT(LINE_STIPPLE_REPEAT) + VAR_BOOL(LINE_STIPPLE) + VAR_BOOL(CULL_FACE) + VAR_ENUM(CULL_FACE_MODE) + VAR_ENUM(FRONT_FACE) + VAR_BOOL(POLYGON_SMOOTH) + VAR_ENUM(POLYGON_MODE) + VAR_FLOAT(POLYGON_OFFSET_FACTOR) + VAR_FLOAT(POLYGON_OFFSET_UNITS) + VAR_BOOL(POLYGON_OFFSET_POINT) + VAR_BOOL(POLYGON_OFFSET_LINE) + VAR_BOOL(POLYGON_OFFSET_FILL) + /* GetPolygonStipple */ + VAR_BOOL(POLYGON_STIPPLE) + + VAR_BOOL(TEXTURE_1D) + VAR_BOOL(TEXTURE_2D) +/* VAR_BOOL(TEXTURE_3D)*/ + + VAR_INT(TEXTURE_BINDING_1D) + VAR_INT(TEXTURE_BINDING_2D) +/* VAR_INT(TEXTURE_BINDING_3D)*/ + + /* GetTexImage() */ + /* GetTexLevelParameter() */ + /* GetTexEnv() */ + + VAR_BOOL(TEXTURE_GEN_S) + VAR_BOOL(TEXTURE_GEN_T) + VAR_BOOL(TEXTURE_GEN_R) + VAR_BOOL(TEXTURE_GEN_Q) + + /* GetTexGen() */ + + VAR_BOOL(SCISSOR_TEST) + VAR_INT4(SCISSOR_BOX) + VAR_BOOL(ALPHA_TEST) + VAR_ENUM(ALPHA_TEST_FUNC) + VAR_FLOAT(ALPHA_TEST_REF) + VAR_BOOL(STENCIL_TEST) + VAR_ENUM(STENCIL_FUNC) + VAR_HEXINT(STENCIL_VALUE_MASK) + VAR_INT(STENCIL_REF) + VAR_ENUM(STENCIL_FAIL) + VAR_ENUM(STENCIL_PASS_DEPTH_FAIL) + VAR_ENUM(STENCIL_PASS_DEPTH_PASS) + VAR_BOOL(DEPTH_TEST) + VAR_ENUM(DEPTH_FUNC) + VAR_BOOL(BLEND) + VAR_ENUM(BLEND_SRC) + VAR_ENUM(BLEND_DST) + + VAR_BOOL(DITHER) + VAR_BOOL(LOGIC_OP) /* INDEX_LOGIC_OP */ + VAR_BOOL(COLOR_LOGIC_OP) + + VAR_ENUM(DRAW_BUFFER) + VAR_INT(INDEX_WRITEMASK) + VAR_BOOL4(COLOR_WRITEMASK) + VAR_BOOL(DEPTH_WRITEMASK) + VAR_HEXINT(STENCIL_WRITEMASK) + VAR_COLOR(COLOR_CLEAR_VALUE) + VAR_INDEX(INDEX_CLEAR_VALUE) + VAR_FLOAT(DEPTH_CLEAR_VALUE) + VAR_INT(STENCIL_CLEAR_VALUE) + VAR_FLOAT(ACCUM_CLEAR_VALUE) + + VAR_BOOL(UNPACK_SWAP_BYTES) + VAR_BOOL(UNPACK_LSB_FIRST) +#ifdef UNPACK_IMAGE_HEIGHT + VAR_INT(UNPACK_IMAGE_HEIGHT) +#endif +#ifdef UNPACK_SKIP_IMAGES + VAR_INT(UNPACK_SKIP_IMAGES) +#endif + VAR_INT(UNPACK_ROW_LENGTH) + VAR_INT(UNPACK_SKIP_ROWS) + VAR_INT(UNPACK_SKIP_PIXELS) + VAR_INT(UNPACK_ALIGNMENT) + + VAR_BOOL(PACK_SWAP_BYTES) + VAR_BOOL(PACK_LSB_FIRST) +#ifdef PACK_IMAGE_HEIGHT + VAR_INT(PACK_IMAGE_HEIGHT) +#endif +#ifdef PACK_SKIP_IMAGES + VAR_INT(PACK_SKIP_IMAGES) +#endif + VAR_INT(PACK_ROW_LENGTH) + VAR_INT(PACK_SKIP_ROWS) + VAR_INT(PACK_SKIP_PIXELS) + VAR_INT(PACK_ALIGNMENT) + + VAR_BOOL(MAP_COLOR) + VAR_BOOL(MAP_STENCIL) + VAR_INT(INDEX_SHIFT) + VAR_INT(INDEX_OFFSET) + VAR_FLOAT(RED_SCALE) + VAR_FLOAT(GREEN_SCALE) + VAR_FLOAT(BLUE_SCALE) + VAR_FLOAT(ALPHA_SCALE) + VAR_FLOAT(DEPTH_SCALE) + VAR_FLOAT(RED_BIAS) + VAR_FLOAT(GREEN_BIAS) + VAR_FLOAT(BLUE_BIAS) + VAR_FLOAT(ALPHA_BIAS) + VAR_FLOAT(DEPTH_BIAS) + + VAR_FLOAT(ZOOM_X) + VAR_FLOAT(ZOOM_Y) + + VAR_ENUM(READ_BUFFER) + + VAR_BOOL(AUTO_NORMAL) + + VAR_ENUM(PERSPECTIVE_CORRECTION_HINT) + VAR_ENUM(POINT_SMOOTH_HINT) + VAR_ENUM(LINE_SMOOTH_HINT) + VAR_ENUM(POLYGON_SMOOTH_HINT) + VAR_ENUM(FOG_HINT) + + VAR_INT(MAX_LIGHTS) + VAR_INT(MAX_CLIP_PLANES) + VAR_INT(MAX_MODELVIEW_STACK_DEPTH) + VAR_INT(MAX_PROJECTION_STACK_DEPTH) + VAR_INT(MAX_TEXTURE_STACK_DEPTH) + VAR_INT(SUBPIXEL_BITS) +#ifdef GL_MAX_3D_TEXTURE_SIZE + VAR_INT(MAX_3D_TEXTURE_SIZE) +#endif + VAR_INT(MAX_TEXTURE_SIZE) + VAR_INT(MAX_PIXEL_MAP_TABLE) + VAR_INT(MAX_NAME_STACK_DEPTH) + VAR_INT(MAX_LIST_NESTING) + VAR_INT(MAX_EVAL_ORDER) + VAR_INT(MAX_VIEWPORT_DIMS) + VAR_INT(MAX_ATTRIB_STACK_DEPTH) + VAR_INT(MAX_CLIENT_ATTRIB_STACK_DEPTH) + VAR_INT(AUX_BUFFERS) + VAR_BOOL(RGBA_MODE) + VAR_BOOL(INDEX_MODE) + VAR_BOOL(DOUBLEBUFFER) + VAR_BOOL(STEREO) +#ifdef GL_ALIASED_POINT_SIZE_RANGE + VAR_FLOAT2(ALIASED_POINT_SIZE_RANGE) +#endif +#ifdef GL_POINT_SIZE_RANGE + VAR_FLOAT2(POINT_SIZE_RANGE) /* SMOOTH_POINT_SIZE_RANGE */ +#endif + VAR_FLOAT(POINT_SIZE_GRANULARITY) /* SMOOTH_POINT_SIZE_GRANULARITY */ +#ifdef GL_ALIASED_LINE_WIDTH_RANGE + VAR_FLOAT2(ALIASED_LINE_WIDTH_RANGE) +#endif + VAR_FLOAT2(LINE_WIDTH_RANGE) /* SMOOTH_LINE_WIDTH_RANGE */ + VAR_FLOAT(LINE_WIDTH_GRANULARITY) /* SMOOTH_LINE_WIDTH_GRANULARITY */ + +#ifdef GL_MAX_ELEMENTS_INDICES + VAR_INT(MAX_ELEMENTS_INDICES) +#endif +#ifdef GL_MAX_ELEMENTS_VERTICES + VAR_INT(MAX_ELEMENTS_VERTICES) +#endif + VAR_INT(RED_BITS) + VAR_INT(GREEN_BITS) + VAR_INT(BLUE_BITS) + VAR_INT(ALPHA_BITS) + VAR_INT(INDEX_BITS) + VAR_INT(DEPTH_BITS) + VAR_INT(STENCIL_BITS) + VAR_INT(ACCUM_RED_BITS) + VAR_INT(ACCUM_GREEN_BITS) + VAR_INT(ACCUM_BLUE_BITS) + VAR_INT(ACCUM_ALPHA_BITS) + + VAR_INT(LIST_BASE) + VAR_INT(LIST_INDEX) + VAR_ENUM(LIST_MODE) + VAR_INT(ATTRIB_STACK_DEPTH) + VAR_INT(CLIENT_ATTRIB_STACK_DEPTH) + VAR_INT(NAME_STACK_DEPTH) + VAR_ENUM(RENDER_MODE) + VAR_PTR(SELECTION_BUFFER_POINTER) + VAR_INT(SELECTION_BUFFER_SIZE) + VAR_PTR(FEEDBACK_BUFFER_POINTER) + VAR_INT(FEEDBACK_BUFFER_SIZE) + VAR_ENUM(FEEDBACK_BUFFER_TYPE) + + /* glGetError() */ +} + +/***************************************************************************/ + +/*#define TEST*/ +#ifdef TEST + +#include + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 300); + glutInitDisplayMode(GLUT_RGB); + glutCreateWindow(argv[0]); + dump_opengl_state(stdout); + return 0; +} + +#endif + diff --git a/progs/util/errcheck.c b/progs/util/errcheck.c new file mode 100644 index 0000000000..fe9c2973c3 --- /dev/null +++ b/progs/util/errcheck.c @@ -0,0 +1,27 @@ +/* errcheck.c */ + + +/* + * Call this function in your rendering loop to check for GL errors + * during development. Remove from release code. + * + * Written by Brian Paul and in the public domain. + */ + + +#include +#include +#incldue + + + +GLboolean CheckError( const char *message ) +{ + GLenum error = glGetError(); + if (error) { + char *err = (char *) gluErrorString( error ); + fprintf( stderr, "GL Error: %s at %s\n", err, message ); + return GL_TRUE; + } + return GL_FALSE; +} diff --git a/progs/util/glstate.c b/progs/util/glstate.c new file mode 100644 index 0000000000..4c5db13ec7 --- /dev/null +++ b/progs/util/glstate.c @@ -0,0 +1,504 @@ +/* $Id: glstate.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */ + +/* + * Print GL state information (for debugging) + * Copyright (C) 1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * $Log: glstate.c,v $ + * Revision 1.1 1999/08/19 00:55:42 jtg + * Initial revision + * + * Revision 1.4 1999/06/19 01:36:43 brianp + * more features added + * + * Revision 1.3 1999/02/24 05:16:20 brianp + * added still more records to EnumTable + * + * Revision 1.2 1998/11/24 03:47:54 brianp + * added more records to EnumTable + * + * Revision 1.1 1998/11/24 03:41:16 brianp + * Initial revision + * + */ + + + +#include +#include +#include +#include +#include "glstate.h" + + +#define FLOAT 1 +#define INT 2 +#define DOUBLE 3 +#define BOOLEAN 4 +#define ENUM 5 +#define VOID 6 +#define LAST_TOKEN ~0 + + +struct EnumRecord { + GLenum enumerator; /* GLenum constant */ + const char *string; /* string name */ + int getType; /* INT, FLOAT, DOUBLE, BOOLEAN, ENUM, or VOID */ + int getCount; /* number of values returned by the glGet*v() call */ +}; + + +/* XXX Lots more records to add here! Help, anyone? */ + +static struct EnumRecord EnumTable[] = { + { GL_ACCUM_RED_BITS, "GL_ACCUM_RED_BITS", INT, 1 }, + { GL_ACCUM_GREEN_BITS, "GL_ACCUM_GREEN_BITS", INT, 1 }, + { GL_ACCUM_BLUE_BITS, "GL_ACCUM_BLUE_BITS", INT, 1 }, + { GL_ACCUM_ALPHA_BITS, "GL_ACCUM_ALPHA_BITS", INT, 1 }, + { GL_ACCUM_CLEAR_VALUE, "GL_ACCUM_CLEAR_VALUE", FLOAT, 4 }, + { GL_ALPHA_BIAS, "GL_ALPHA_BIAS", FLOAT, 1 }, + { GL_ALPHA_BITS, "GL_ALPHA_BITS", INT, 1 }, + { GL_ALPHA_SCALE, "GL_ALPHA_SCALE", FLOAT, 1 }, + { GL_ALPHA_TEST, "GL_ALPHA_TEST", BOOLEAN, 1 }, + { GL_ALPHA_TEST_FUNC, "GL_ALPHA_TEST_FUNC", ENUM, 1 }, + { GL_ALWAYS, "GL_ALWAYS", ENUM, 0 }, + { GL_ALPHA_TEST_REF, "GL_ALPHA_TEST_REF", FLOAT, 1 }, + { GL_ATTRIB_STACK_DEPTH, "GL_ATTRIB_STACK_DEPTH", INT, 1 }, + { GL_AUTO_NORMAL, "GL_AUTO_NORMAL", BOOLEAN, 1 }, + { GL_AUX_BUFFERS, "GL_AUX_BUFFERS", INT, 1 }, + { GL_BLEND, "GL_BLEND", BOOLEAN, 1 }, + { GL_BLEND_DST, "GL_BLEND_DST", ENUM, 1 }, + { GL_BLEND_SRC, "GL_BLEND_SRC", ENUM, 1 }, + { GL_BLUE_BIAS, "GL_BLUE_BIAS", FLOAT, 1 }, + { GL_BLUE_BITS, "GL_BLUE_BITS", INT, 1 }, + { GL_BLUE_SCALE, "GL_BLUE_SCALE", FLOAT, 1 }, + + { GL_CLAMP_TO_EDGE, "GL_CLAMP_TO_EDGE", ENUM, 0 }, + { GL_CLEAR, "GL_CLEAR", ENUM, 0 }, + { GL_CLIENT_ATTRIB_STACK_DEPTH, "GL_CLIENT_ATTRIB_STACK_DEPTH", INT, 1 }, + { GL_CLIP_PLANE0, "GL_CLIP_PLANE0", BOOLEAN, 1 }, + { GL_CLIP_PLANE1, "GL_CLIP_PLANE1", BOOLEAN, 1 }, + { GL_CLIP_PLANE2, "GL_CLIP_PLANE2", BOOLEAN, 1 }, + { GL_CLIP_PLANE3, "GL_CLIP_PLANE3", BOOLEAN, 1 }, + { GL_CLIP_PLANE4, "GL_CLIP_PLANE4", BOOLEAN, 1 }, + { GL_CLIP_PLANE5, "GL_CLIP_PLANE5", BOOLEAN, 1 }, + { GL_COEFF, "GL_COEEF", ENUM, 0 }, + { GL_COLOR, "GL_COLOR", ENUM, 0 }, + { GL_COLOR_BUFFER_BIT, "GL_COLOR_BUFFER_BIT", ENUM, 0 }, + { GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE", FLOAT, 4 }, + { GL_COLOR_INDEX, "GL_COLOR_INDEX", ENUM, 0 }, + { GL_COLOR_MATERIAL, "GL_COLOR_MATERIAL", BOOLEAN, 1 }, + { GL_COLOR_MATERIAL_FACE, "GL_COLOR_MATERIAL_FACE", ENUM, 1 }, + { GL_COLOR_MATERIAL_PARAMETER, "GL_COLOR_MATERIAL_PARAMETER", ENUM, 1 }, + { GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK", BOOLEAN, 4 }, + { GL_COMPILE, "GL_COMPILE", ENUM, 0 }, + { GL_COMPILE_AND_EXECUTE, "GL_COMPILE_AND_EXECUTE", ENUM, 0 }, + { GL_COPY, "GL_COPY", ENUM, 0 }, + { GL_COPY_INVERTED, "GL_COPY_INVERTED", ENUM, 0 }, + { GL_COPY_PIXEL_TOKEN, "GL_COPY_PIXEL_TOKEN", ENUM, 0 }, + { GL_CULL_FACE, "GL_CULL_FACE", BOOLEAN, 1 }, + { GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE", ENUM, 1 }, + { GL_CURRENT_BIT, "GL_CURRENT_BIT", ENUM, 0 }, + { GL_CURRENT_COLOR, "GL_CURRENT_COLOR", FLOAT, 4 }, + { GL_CURRENT_INDEX, "GL_CURRENT_INDEX", INT, 1 }, + { GL_CURRENT_NORMAL, "GL_CURRENT_NORMAL", FLOAT, 3 }, + { GL_CURRENT_RASTER_COLOR, "GL_CURRENT_RASTER_COLOR", FLOAT, 4 }, + { GL_CURRENT_RASTER_DISTANCE, "GL_CURRENT_RASTER_DISTANCE", FLOAT, 1 }, + { GL_CURRENT_RASTER_INDEX, "GL_CURRENT_RASTER_INDEX", INT, 1 }, + { GL_CURRENT_RASTER_POSITION, "GL_CURRENT_RASTER_POSITION", FLOAT, 4 }, + { GL_CURRENT_RASTER_TEXTURE_COORDS, "GL_CURRENT_RASTER_TEXTURE_COORDS", FLOAT, 4 }, + { GL_CURRENT_RASTER_POSITION_VALID, "GL_CURRENT_RASTER_POSITION_VALID", BOOLEAN, 1 }, + { GL_CURRENT_TEXTURE_COORDS, "GL_CURRENT_TEXTURE_COORDS", FLOAT, 4 }, + { GL_CW, "GL_CW", ENUM, 0 }, + { GL_CCW, "GL_CCW", ENUM, 0 }, + + { GL_DECAL, "GL_DECAL", ENUM, 0 }, + { GL_DECR, "GL_DECR", ENUM, 0 }, + { GL_DEPTH, "GL_DEPTH", ENUM, 0 }, + { GL_DEPTH_BIAS, "GL_DEPTH_BIAS", FLOAT, 1 }, + { GL_DEPTH_BITS, "GL_DEPTH_BITS", INT, 1 }, + { GL_DEPTH_BUFFER_BIT, "GL_DEPTH_BUFFER_BIT", ENUM, 0 }, + { GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE", FLOAT, 1 }, + { GL_DEPTH_COMPONENT, "GL_DEPTH_COMPONENT", ENUM, 0 }, + { GL_DEPTH_FUNC, "GL_DEPTH_FUNC", ENUM, 1 }, + { GL_DEPTH_RANGE, "GL_DEPTH_RANGE", FLOAT, 2 }, + { GL_DEPTH_SCALE, "GL_DEPTH_SCALE", FLOAT, 1 }, + { GL_DEPTH_TEST, "GL_DEPTH_TEST", ENUM, 1 }, + { GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK", BOOLEAN, 1 }, + { GL_DIFFUSE, "GL_DIFFUSE", ENUM, 0 }, /*XXX*/ + { GL_DITHER, "GL_DITHER", BOOLEAN, 1 }, + { GL_DOMAIN, "GL_DOMAIN", ENUM, 0 }, + { GL_DONT_CARE, "GL_DONT_CARE", ENUM, 0 }, + { GL_DOUBLE, "GL_DOUBLE", ENUM, 0 }, + { GL_DOUBLEBUFFER, "GL_DOUBLEBUFFER", BOOLEAN, 1}, + { GL_DRAW_BUFFER, "GL_DRAW_BUFFER", ENUM, 1 }, + { GL_DRAW_PIXEL_TOKEN, "GL_DRAW_PIXEL_TOKEN", ENUM, 0 }, + { GL_DST_ALPHA, "GL_DST_ALPHA", ENUM, 0 }, + { GL_DST_COLOR, "GL_DST_COLOR", ENUM, 0 }, + + { GL_EDGE_FLAG, "GL_EDGE_FLAG", BOOLEAN, 1 }, + /* XXX GL_EDGE_FLAG_ARRAY_* */ + { GL_EMISSION, "GL_EMISSION", ENUM, 0 }, /* XXX */ + { GL_ENABLE_BIT, "GL_ENABLE_BIT", ENUM, 0 }, + { GL_EQUAL, "GL_EQUAL", ENUM, 0 }, + { GL_EQUIV, "GL_EQUIV", ENUM, 0 }, + { GL_EVAL_BIT, "GL_EVAL_BIT", ENUM, 0 }, + { GL_EXP, "GL_EXP", ENUM, 0 }, + { GL_EXP2, "GL_EXP2", ENUM, 0 }, + { GL_EXTENSIONS, "GL_EXTENSIONS", ENUM, 0 }, + { GL_EYE_LINEAR, "GL_EYE_LINEAR", ENUM, 0 }, + { GL_EYE_PLANE, "GL_EYE_PLANE", ENUM, 0 }, + + { GL_FALSE, "GL_FALSE", ENUM, 0 }, + { GL_FASTEST, "GL_FASTEST", ENUM, 0 }, + { GL_FEEDBACK, "GL_FEEDBACK", ENUM, 0 }, + { GL_FEEDBACK_BUFFER_POINTER, "GL_FEEDBACK_BUFFER_POINTER", VOID, 0 }, + { GL_FEEDBACK_BUFFER_SIZE, "GL_FEEDBACK_BUFFER_SIZE", INT, 1 }, + { GL_FEEDBACK_BUFFER_TYPE, "GL_FEEDBACK_BUFFER_TYPE", INT, 1 }, + { GL_FILL, "GL_FILL", ENUM, 0 }, + { GL_FLAT, "GL_FLAT", ENUM, 0 }, + { GL_FLOAT, "GL_FLOAT", ENUM, 0 }, + { GL_FOG, "GL_FOG", BOOLEAN, 1 }, + { GL_FOG_BIT, "GL_FOG_BIT", ENUM, 0 }, + { GL_FOG_COLOR, "GL_FOG_COLOR", FLOAT, 4 }, + { GL_FOG_DENSITY, "GL_FOG_DENSITY", FLOAT, 1 }, + { GL_FOG_END, "GL_FOG_END", FLOAT, 1 }, + { GL_FOG_HINT, "GL_FOG_HINT", ENUM, 1 }, + { GL_FOG_INDEX, "GL_FOG_INDEX", INT, 1 }, + { GL_FOG_MODE, "GL_FOG_MODE", ENUM, 1 }, + { GL_FOG_START, "GL_FOG_START", FLOAT, 1 }, + { GL_FRONT, "GL_FRONT", ENUM, 0 }, + { GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK", ENUM, 0 }, + { GL_FRONT_FACE, "GL_FRONT_FACE", ENUM, 1 }, + { GL_FRONT_LEFT, "GL_FRONT_LEFT", ENUM, 0 }, + { GL_FRONT_RIGHT, "GL_FRONT_RIGHT", ENUM, 0 }, + + { GL_GEQUAL, "GL_GEQUAL", ENUM, 0 }, + { GL_GREATER, "GL_GREATER", ENUM, 0 }, + { GL_GREEN, "GL_GREEN", ENUM, 0 }, + { GL_GREEN_BIAS, "GL_GREEN_BIAS", FLOAT, 1 }, + { GL_GREEN_BITS, "GL_GREEN_BITS", INT, 1 }, + { GL_GREEN_SCALE, "GL_GREEN_SCALE", FLOAT, 1 }, + + + + { GL_LESS, "GL_LESS", ENUM, 0 }, + { GL_LEQUAL, "GL_LEQUAL", ENUM, 0 }, + { GL_LIGHTING, "GL_LIGHTING", BOOLEAN, 1 }, + { GL_LINE_SMOOTH, "GL_LINE_SMOOTH", BOOLEAN, 1 }, + { GL_LINE_STIPPLE, "GL_LINE_STIPPLE", BOOLEAN, 1 }, + { GL_LINE_STIPPLE_PATTERN, "GL_LINE_STIPPLE_PATTERN", INT, 1 }, + { GL_LINE_STIPPLE_REPEAT, "GL_LINE_STIPPLE_REPEAT", INT, 1 }, + { GL_LINE_WIDTH, "GL_LINE_WIDTH", FLOAT, 1 }, + + { GL_MODELVIEW_MATRIX, "GL_MODELVIEW_MATRIX", DOUBLE, 16 }, + + { GL_NEVER, "GL_NEVER", ENUM, 0 }, + { GL_NOTEQUAL, "GL_NOTEQUAL", ENUM, 0 }, + + { GL_PROJECTION_MATRIX, "GL_PROJECTION_MATRIX", FLOAT, 16 }, + + { GL_PACK_SWAP_BYTES, "GL_PACK_SWAP_BYTES", INT, 1 }, + { GL_PACK_LSB_FIRST, "GL_PACK_LSB_FIRST", INT, 1 }, + { GL_PACK_ROW_LENGTH, "GL_PACK_ROW_LENGTH", INT, 1 }, + { GL_PACK_SKIP_PIXELS, "GL_PACK_SKIP_PIXELS", INT, 1 }, + { GL_PACK_SKIP_ROWS, "GL_PACK_SKIP_ROWS", INT, 1 }, + { GL_PACK_ALIGNMENT, "GL_PACK_ALIGNMENT", INT, 1 }, + + { GL_TRUE, "GL_TRUE", ENUM, 0 }, + + { GL_UNPACK_SWAP_BYTES, "GL_UNPACK_SWAP_BYTES", INT, 1 }, + { GL_UNPACK_LSB_FIRST, "GL_UNPACK_LSB_FIRST", INT, 1 }, + { GL_UNPACK_ROW_LENGTH, "GL_UNPACK_ROW_LENGTH", INT, 1 }, + { GL_UNPACK_SKIP_PIXELS, "GL_UNPACK_SKIP_PIXELS", INT, 1 }, + { GL_UNPACK_SKIP_ROWS, "GL_UNPACK_SKIP_ROWS", INT, 1 }, + { GL_UNPACK_ALIGNMENT, "GL_UNPACK_ALIGNMENT", INT, 1 }, + + { GL_VIEWPORT, "GL_VIEWPORT", INT, 4 }, + + + /* + * Extensions + */ + +#if defined(GL_EXT_blend_minmax) + { GL_BLEND_EQUATION_EXT, "GL_BLEND_EQUATION_EXT", ENUM, 1 }, +#endif +#if defined(GL_EXT_blend_color) + { GL_BLEND_COLOR_EXT, "GL_BLEND_COLOR_EXT", FLOAT, 4 }, +#endif +#if defined(GL_EXT_point_parameters) + { GL_DISTANCE_ATTENUATION_EXT, "GL_DISTANCE_ATTENUATION_EXT", FLOAT, 1 }, +#endif +#if defined(GL_INGR_blend_func_separate) + { GL_BLEND_SRC_RGB_INGR, "GL_BLEND_SRC_RGB_INGR", ENUM, 1 }, + { GL_BLEND_DST_RGB_INGR, "GL_BLEND_DST_RGB_INGR", ENUM, 1 }, + { GL_BLEND_SRC_ALPHA_INGR, "GL_BLEND_SRC_ALPHA_INGR", ENUM, 1 }, + { GL_BLEND_DST_ALPHA_INGR, "GL_BLEND_DST_ALPHA_INGR", ENUM, 1 }, +#endif + + + { LAST_TOKEN, "", 0, 0 } +}; + + +static const struct EnumRecord *FindRecord( GLenum var ) +{ + int i; + for (i = 0; EnumTable[i].enumerator != LAST_TOKEN; i++) { + if (EnumTable[i].enumerator == var) { + return &EnumTable[i]; + } + } + return NULL; +} + + + +/* + * Return the string label for the given enum. + */ +const char *GetEnumString( GLenum var ) +{ + const struct EnumRecord *rec = FindRecord(var); + if (rec) + return rec->string; + else + return NULL; +} + + + +/* + * Print current value of the given state variable. + */ +void PrintState( int indent, GLenum var ) +{ + const struct EnumRecord *rec = FindRecord(var); + + while (indent-- > 0) + putchar(' '); + + if (rec) { + if (rec->getCount <= 0) { + assert(rec->getType == ENUM); + printf("%s is not a state variable\n", rec->string); + } + else { + switch (rec->getType) { + case INT: + { + GLint values[100]; + int i; + glGetIntegerv(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) + printf("%d ", values[i]); + printf("\n"); + } + break; + case FLOAT: + { + GLfloat values[100]; + int i; + glGetFloatv(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) + printf("%f ", values[i]); + printf("\n"); + } + break; + case DOUBLE: + { + GLdouble values[100]; + int i; + glGetDoublev(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) + printf("%f ", (float) values[i]); + printf("\n"); + } + break; + case BOOLEAN: + { + GLboolean values[100]; + int i; + glGetBooleanv(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) + printf("%s ", values[i] ? "GL_TRUE" : "GL_FALSE"); + printf("\n"); + } + break; + case ENUM: + { + GLint values[100]; + int i; + glGetIntegerv(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) { + const char *str = GetEnumString((GLenum) values[i]); + if (str) + printf("%s ", str); + else + printf("??? "); + } + printf("\n"); + } + break; + case VOID: + { + GLvoid *values[100]; + int i; + glGetPointerv(rec->enumerator, values); + printf("%s = ", rec->string); + for (i = 0; i < rec->getCount; i++) { + printf("%p ", values[i]); + } + printf("\n"); + } + break; + default: + printf("fatal error in PrintState()\n"); + abort(); + } + } + } + else { + printf("Unknown GLenum passed to PrintState()\n"); + } +} + + + +/* + * Print all glPixelStore-related state. + * NOTE: Should write similar functions for lighting, texturing, etc. + */ +void PrintPixelStoreState( void ) +{ + const GLenum enums[] = { + GL_PACK_SWAP_BYTES, + GL_PACK_LSB_FIRST, + GL_PACK_ROW_LENGTH, + GL_PACK_SKIP_PIXELS, + GL_PACK_SKIP_ROWS, + GL_PACK_ALIGNMENT, + GL_UNPACK_SWAP_BYTES, + GL_UNPACK_LSB_FIRST, + GL_UNPACK_ROW_LENGTH, + GL_UNPACK_SKIP_PIXELS, + GL_UNPACK_SKIP_ROWS, + GL_UNPACK_ALIGNMENT, + 0 + }; + int i; + printf("Pixel pack/unpack state:\n"); + for (i = 0; enums[i]; i++) { + PrintState(3, enums[i]); + } +} + + + + +/* + * Print all state for the given attribute group. + */ +void PrintAttribState( GLbitfield attrib ) +{ + static const GLenum depth_buffer_enums[] = { + GL_DEPTH_FUNC, + GL_DEPTH_CLEAR_VALUE, + GL_DEPTH_TEST, + GL_DEPTH_WRITEMASK, + 0 + }; + static const GLenum fog_enums[] = { + GL_FOG, + GL_FOG_COLOR, + GL_FOG_DENSITY, + GL_FOG_START, + GL_FOG_END, + GL_FOG_INDEX, + GL_FOG_MODE, + 0 + }; + static const GLenum line_enums[] = { + GL_LINE_SMOOTH, + GL_LINE_STIPPLE, + GL_LINE_STIPPLE_PATTERN, + GL_LINE_STIPPLE_REPEAT, + GL_LINE_WIDTH, + 0 + }; + + const GLenum *enumList = NULL; + + switch (attrib) { + case GL_DEPTH_BUFFER_BIT: + enumList = depth_buffer_enums; + printf("GL_DEPTH_BUFFER_BIT state:\n"); + break; + case GL_FOG_BIT: + enumList = fog_enums; + printf("GL_FOG_BIT state:\n"); + break; + case GL_LINE_BIT: + enumList = line_enums; + printf("GL_LINE_BIT state:\n"); + break; + default: + printf("Bad value in PrintAttribState()\n"); + } + + if (enumList) { + int i; + for (i = 0; enumList[i]; i++) + PrintState(3, enumList[i]); + } +} + + +/*#define TEST*/ +#ifdef TEST + +#include + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 300); + glutInitDisplayMode(GLUT_RGB); + glutCreateWindow(argv[0]); + PrintAttribState(GL_DEPTH_BUFFER_BIT); + PrintAttribState(GL_FOG_BIT); + PrintAttribState(GL_LINE_BIT); + PrintState(0, GL_ALPHA_BITS); + PrintState(0, GL_VIEWPORT); + PrintState(0, GL_ALPHA_TEST_FUNC); + PrintState(0, GL_MODELVIEW_MATRIX); + PrintState(0, GL_ALWAYS); + PrintPixelStoreState(); + return 0; +} + +#endif diff --git a/progs/util/glstate.h b/progs/util/glstate.h new file mode 100644 index 0000000000..1aa4d21d8e --- /dev/null +++ b/progs/util/glstate.h @@ -0,0 +1,53 @@ +/* $Id: glstate.h,v 1.1 1999/08/19 00:55:42 jtg Exp $ */ + +/* + * Print GL state information (for debugging) + * Copyright (C) 1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * $Log: glstate.h,v $ + * Revision 1.1 1999/08/19 00:55:42 jtg + * Initial revision + * + * Revision 1.2 1999/06/19 01:36:43 brianp + * more features added + * + * Revision 1.1 1998/11/24 03:41:16 brianp + * Initial revision + * + */ + + +#ifndef GLSTATE_H +#define GLSTATE_H + + +#include + + +extern const char *GetNameString( GLenum var ); + +extern void PrintState( int indent, GLenum var ); + +extern void PrintAttribState( GLbitfield attrib ); + +extern void PrintPixelStoreState( void ); + + +#endif diff --git a/progs/util/glutskel.c b/progs/util/glutskel.c new file mode 100644 index 0000000000..8c283f8497 --- /dev/null +++ b/progs/util/glutskel.c @@ -0,0 +1,145 @@ +/* $Id: glutskel.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */ + +/* + * A skeleton/template GLUT program + * + * Written by Brian Paul and in the public domain. + */ + + +/* + * $Log: glutskel.c,v $ + * Revision 1.1 1999/08/19 00:55:42 jtg + * Initial revision + * + * Revision 1.2 1998/11/07 14:20:14 brianp + * added simple rotation, animation of cube + * + * Revision 1.1 1998/11/07 14:14:37 brianp + * Initial revision + * + */ + + +#include +#include +#include +#include + + +static GLfloat Xrot = 0, Yrot = 0, Zrot = 0; +static GLboolean Anim = GL_FALSE; + + +static void Idle( void ) +{ + Xrot += 3.0; + Yrot += 4.0; + Zrot += 2.0; + glutPostRedisplay(); +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glRotatef(Zrot, 0, 0, 1); + + glutSolidCube(2.0); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + const GLfloat step = 3.0; + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'z': + Zrot -= step; + break; + case 'Z': + Zrot += step; + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const GLfloat step = 3.0; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + Xrot -= step; + break; + case GLUT_KEY_DOWN: + Xrot += step; + break; + case GLUT_KEY_LEFT: + Yrot -= step; + break; + case GLUT_KEY_RIGHT: + Yrot += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + /* setup lighting, etc */ + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 400, 400 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/util/idproj.c b/progs/util/idproj.c new file mode 100644 index 0000000000..d5ee3409f3 --- /dev/null +++ b/progs/util/idproj.c @@ -0,0 +1,26 @@ +/* idproj.c */ + + +/* + * Setup an identity projection such that glVertex(x,y) maps to + * window coordinate (x,y). + * + * Written by Brian Paul and in the public domain. + */ + + + + + +void IdentityProjection( GLint x, GLint y, GLsizei width, GLsizei height ) +{ + glViewport( x, y, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( (GLdouble) x, (GLdouble) y, + (GLdouble) width, (GLdouble) height, + -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); +} + diff --git a/progs/util/imagesgi.cpp b/progs/util/imagesgi.cpp new file mode 100644 index 0000000000..f5128aabec --- /dev/null +++ b/progs/util/imagesgi.cpp @@ -0,0 +1,369 @@ +/****************************************************************************** +** Filename : imageSgi.cpp +** UNCLASSIFIED +** +** Description : Utility to read SGI image format files. This code was +** originally a SGI image loading utility provided with the +** Mesa 3D library @ http://www.mesa3d.org by Brain Paul. +** This has been extended to read all SGI image formats +** (e.g. INT, INTA, RGB, RGBA). +** +** Revision History: +** Date Name Description +** 06/07/99 BRC Initial Release +** +** Note: +** +** The SGI Image Data (if not RLE) +** +** If the image is stored verbatim (without RLE), then image data directly +** follows the 512 byte header. The data for each scanline of the first +** channel is written first. If the image has more than 1 channel, all +** the data for the first channel is written, followed by the remaining +** channels. If the BPC value is 1, then each scanline is written as XSIZE +** bytes. If the BPC value is 2, then each scanline is written as XSIZE +** shorts. These shorts are stored in the byte order described above. +** +******************************************************************************/ +#define __IMAGESGI_CPP + +#include "imagesgi.h" + +#include +#include +#include +#include +#include + +struct sImageSgiRaw +{ + struct sImageSgiHeader header; + unsigned char *chan0; + unsigned char *chan1; + unsigned char *chan2; + unsigned char *chan3; + unsigned int *rowStart; + int *rowSize; +}; + +// Static routines +static struct sImageSgiRaw *ImageSgiRawOpen(char const * const fileName); +static void ImageSgiRawClose(struct sImageSgiRaw *raw); +static void ImageSgiRawGetRow(struct sImageSgiRaw *raw, unsigned char *buf, + int y, int z); +static void ImageSgiRawGetData(struct sImageSgiRaw *raw, struct sImageSgi +*final); +static void *SwitchEndian16(void *value); +static void *SwitchEndian32(void *value); + +// Static variables +FILE *mFp = NULL; +unsigned char *mChanTmp = NULL; + + +/*****************************************************************************/ +struct sImageSgi *ImageSgiOpen(char const * const fileName) +{ + struct sImageSgiRaw *raw = NULL; + struct sImageSgi *final = NULL; + + raw = ImageSgiRawOpen(fileName); + final = new struct sImageSgi; + + assert(final); + if(final) + { + final->header = raw->header; + final->data = NULL; + ImageSgiRawGetData(raw, final); + ImageSgiRawClose(raw); + } + + return final; +} // ImageSgiRawOpen + + +/*****************************************************************************/ +void ImageSgiClose(struct sImageSgi *image) +{ + + if(image) + { + if(image->data) + delete[] image->data; + image->data = NULL; + delete image; + } + image = NULL; + + return; +} // ImageSgiClose + + +/*****************************************************************************/ +static struct sImageSgiRaw *ImageSgiRawOpen(char const * const fileName) +{ + struct sImageSgiRaw *raw = NULL; + int x; + int i; + bool swapFlag = false; + union + { + int testWord; + char testByte[4]; + } endianTest; + endianTest.testWord = 1; + + // Determine endianess of platform. + if(endianTest.testByte[0] == 1) + swapFlag = true; + else + swapFlag = false; + + raw = new struct sImageSgiRaw; + + assert(raw); + if(raw) + { + raw->chan0 = NULL; + raw->chan1 = NULL; + raw->chan2 = NULL; + raw->chan3 = NULL; + raw->rowStart = NULL; + raw->rowSize = NULL; + mFp = fopen(fileName, "rb"); + assert(mFp); + + fread(&raw->header, sizeof(struct sImageSgiHeader), 1, mFp); + if(swapFlag == true) + { + SwitchEndian16(&raw->header.magic); + SwitchEndian16(&raw->header.type); + SwitchEndian16(&raw->header.dim); + SwitchEndian16(&raw->header.xsize); + SwitchEndian16(&raw->header.ysize); + SwitchEndian16(&raw->header.zsize); + } + + mChanTmp = new unsigned char[raw->header.xsize * raw->header.ysize]; + assert(mChanTmp); + switch(raw->header.zsize) + { + case 4: + raw->chan3 = new unsigned char[raw->header.xsize * +raw->header.ysize]; + assert(raw->chan3); + case 3: + raw->chan2 = new unsigned char[raw->header.xsize * +raw->header.ysize]; + assert(raw->chan2); + case 2: + raw->chan1 = new unsigned char[raw->header.xsize * +raw->header.ysize]; + assert(raw->chan1); + case 1: + raw->chan0 = new unsigned char[raw->header.xsize * +raw->header.ysize]; + assert(raw->chan0); + } + + if(raw->header.type == IMAGE_SGI_TYPE_RLE) + { + x = raw->header.ysize * raw->header.zsize * sizeof(unsigned int); + raw->rowStart = new unsigned int[x]; + raw->rowSize = new int[x]; + + fseek(mFp, sizeof(struct sImageSgiHeader), SEEK_SET); + fread(raw->rowStart, 1, x, mFp); + fread(raw->rowSize, 1, x, mFp); + + if(swapFlag == true) + { + for(i=0; irowStart[i]); + for(i=0; irowSize[i]); + } + + } + + } + + return raw; +} // ImageSgiRawOpen + + +/*****************************************************************************/ +static void ImageSgiRawClose(struct sImageSgiRaw *raw) +{ + + fclose(mFp); + mFp = NULL; + + if(mChanTmp) + delete[] mChanTmp; + mChanTmp = NULL; + + if(raw->chan0) + delete[] raw->chan0; + raw->chan0 = NULL; + + if(raw->chan1) + delete[] raw->chan1; + raw->chan1 = NULL; + + if(raw->chan2) + delete[] raw->chan2; + raw->chan2 = NULL; + + if(raw->chan3) + delete[] raw->chan3; + raw->chan3 = NULL; + + if(raw) + delete raw; + raw = NULL; + + return; +} // ImageSgiRawClose + + +/*****************************************************************************/ +static void ImageSgiRawGetRow(struct sImageSgiRaw *raw, unsigned char *buf, + int y, int z) +{ + unsigned char *iPtr = NULL; + unsigned char *oPtr = NULL; + unsigned char pixel; + int count; + + if((raw->header.type & 0xFF00) == 0x0100) + { + fseek(mFp, raw->rowStart[y+z*raw->header.ysize], SEEK_SET); + fread(mChanTmp, 1, (unsigned int)raw->rowSize[y+z*raw->header.ysize], +mFp); + iPtr = mChanTmp; + oPtr = buf; + while(1) + { + pixel = *iPtr++; + count = (int)(pixel & 0x7F); + if(!count) + { + return; + } + if (pixel & 0x80) + { + while (count--) + { + *oPtr++ = *iPtr++; + } + } + else + { + pixel = *iPtr++; + while (count--) + { + *oPtr++ = pixel; + } + } + } + } + else + { + fseek(mFp, + sizeof(struct sImageSgiHeader)+(y*raw->header.xsize) + + (z*raw->header.xsize*raw->header.ysize), + SEEK_SET); + fread(buf, 1, raw->header.xsize, mFp); + } + + return; +} // ImageSgiRawGetRow + + +/*****************************************************************************/ +static void ImageSgiRawGetData(struct sImageSgiRaw *raw, struct sImageSgi +*final) +{ + unsigned char *ptr = NULL; + int i, j; + + final->data = + new unsigned +char[raw->header.xsize*raw->header.ysize*raw->header.zsize]; + assert(final->data); + + ptr = final->data; + for(i=0; iheader.ysize; i++) + { + switch(raw->header.zsize) + { + case 1: + ImageSgiRawGetRow(raw, raw->chan0, i, 0); + for(j=0; jheader.xsize; j++) + *(ptr++) = raw->chan0[j]; + break; + case 2: + ImageSgiRawGetRow(raw, raw->chan0, i, 0); + ImageSgiRawGetRow(raw, raw->chan1, i, 1); + for(j=0; jheader.xsize; j++) + { + *(ptr++) = raw->chan0[j]; + *(ptr++) = raw->chan1[j]; + } + break; + case 3: + ImageSgiRawGetRow(raw, raw->chan0, i, 0); + ImageSgiRawGetRow(raw, raw->chan1, i, 1); + ImageSgiRawGetRow(raw, raw->chan2, i, 2); + for(j=0; jheader.xsize; j++) + { + *(ptr++) = raw->chan0[j]; + *(ptr++) = raw->chan1[j]; + *(ptr++) = raw->chan2[j]; + } + break; + case 4: + ImageSgiRawGetRow(raw, raw->chan0, i, 0); + ImageSgiRawGetRow(raw, raw->chan1, i, 1); + ImageSgiRawGetRow(raw, raw->chan2, i, 2); + ImageSgiRawGetRow(raw, raw->chan3, i, 3); + for(j=0; jheader.xsize; j++) + { + *(ptr++) = raw->chan0[j]; + *(ptr++) = raw->chan1[j]; + *(ptr++) = raw->chan2[j]; + *(ptr++) = raw->chan3[j]; + } + break; + } + } + + return; +} // ImageSgiRawGetData + + +/*****************************************************************************/ +static void *SwitchEndian16(void *value) +{ + short value16 = *(short *) value; + value16 = ((value16 & 0xff00) >> 8L) + + ((value16 & 0x00ff) << 8L); + *(short *)value = value16; + return value; +} // SwitchEndian16 + + +/*****************************************************************************/ +static void *SwitchEndian32(void *value) +{ + int value32 = *(int *) value; + value32 = ((value32 & 0xff000000) >> 24L) + + ((value32 & 0x00ff0000) >> 8) + + ((value32 & 0x0000ff00) << 8) + + ((value32 & 0x000000ff) << 24L); + *(int *)value = value32; + return value; +} // SwitchEndian32 + diff --git a/progs/util/imagesgi.h b/progs/util/imagesgi.h new file mode 100644 index 0000000000..e5ecece49d --- /dev/null +++ b/progs/util/imagesgi.h @@ -0,0 +1,55 @@ +/****************************************************************************** +** Filename : imageSgi.h +** UNCLASSIFIED +** +** Description : Utility to read SGI image format files. This code was +** originally a SGI image loading utility provided with the +** Mesa 3D library @ http://www.mesa3d.org by Brain Paul. +** This has been extended to read all SGI image formats +** (e.g. INT, INTA, RGB, RGBA). +** +** Revision History: +** Date Name Description +** 06/08/99 BRC Initial Release +** +******************************************************************************/ + +#ifndef __IMAGESGI_H +#define __IMAGESGI_H + +#define IMAGE_SGI_TYPE_VERBATIM 0 +#define IMAGE_SGI_TYPE_RLE 1 + +struct sImageSgiHeader // 512 bytes +{ + short magic; // IRIS image file magic number (474) + char type; // Storage format (e.g. RLE or VERBATIM) + char numBytesPerPixelChannel; // Number of bytes per pixel channel + unsigned short dim; // Number of dimensions (1 to 3) + unsigned short xsize; // Width (in pixels) + unsigned short ysize; // Height (in pixels) + unsigned short zsize; // Number of channels (1 to 4) + int minimumPixelValue; // Minimum pixel value (0 to 255) + int maximumPixelValue; // Maximum pixel value (0 to 255) + char padding1[4]; // (ignored) + char imageName[80]; // Image name + int colormap; // colormap ID (0=normal, 0=dithered, + // 2=screen, 3=colormap) + char padding2[404]; // (ignored) +}; + +struct sImageSgi +{ + struct sImageSgiHeader header; + unsigned char *data; +}; + +#ifndef __IMAGESGI_CPP + +// RGB image load utility +extern struct sImageSgi *ImageSgiOpen(char const * const fileName); +extern void ImageSgiClose(struct sImageSgi *image); + +#endif + +#endif /* __IMAGESGI_H */ diff --git a/progs/util/mwmborder.c b/progs/util/mwmborder.c new file mode 100644 index 0000000000..b61ffb50bc --- /dev/null +++ b/progs/util/mwmborder.c @@ -0,0 +1,91 @@ +/* mwmborder.c */ + + +/* + * This function shows how to remove the border, title bar, resize button, + * etc from a Motif window frame from inside an Xlib-based application. + * + * Brian Paul 19 Sep 1995 brianp@ssec.wisc.edu + * + * This code is in the public domain. + */ + + +#include +#include + +#define HAVE_MOTIF +#ifdef HAVE_MOTIF + +#include + +#else + +/* bit definitions for MwmHints.flags */ +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_STATUS (1L << 3) + +/* bit definitions for MwmHints.decorations */ +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) + +typedef struct +{ + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; +} PropMotifWmHints; + +#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 + +#endif + + + +/* + * Specify which Motif window manager border decorations to put on a + * top-level window. For example, you can specify that a window is not + * resizabe, or omit the titlebar, or completely remove all decorations. + * Input: dpy - the X display + * w - the X window + * flags - bitwise-OR of the MWM_DECOR_xxx symbols in X11/Xm/MwmUtil.h + * indicating what decoration elements to enable. Zero would + * be no decoration. + */ +void set_mwm_border( Display *dpy, Window w, unsigned long flags ) +{ + PropMotifWmHints motif_hints; + Atom prop, proptype; + + /* setup the property */ + motif_hints.flags = MWM_HINTS_DECORATIONS; + motif_hints.decorations = flags; + + /* get the atom for the property */ + prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True ); + if (!prop) { + /* something went wrong! */ + return; + } + + /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */ + proptype = prop; + + XChangeProperty( dpy, w, /* display, window */ + prop, proptype, /* property, type */ + 32, /* format: 32-bit datums */ + PropModeReplace, /* mode */ + (unsigned char *) &motif_hints, /* data */ + PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */ + ); +} + diff --git a/progs/util/readtex.c b/progs/util/readtex.c new file mode 100644 index 0000000000..7799416924 --- /dev/null +++ b/progs/util/readtex.c @@ -0,0 +1,353 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + + + +#include +#include +#include +#include +#include + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)malloc(sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + if ((raw->file = fopen(fileName, "rb")) == NULL) { + perror(fileName); + return NULL; + } + + fread(raw, 1, 12, raw->file); + + if (swapFlag) { + ConvertShort(&raw->imagic, 6); + } + + raw->tmp = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpR = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpG = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpB = (unsigned char *)malloc(raw->sizeX*256); + if (raw->sizeZ==4) { + raw->tmpA = (unsigned char *)malloc(raw->sizeX*256); + } + if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || + raw->tmpB == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + + if ((raw->type & 0xFF00) == 0x0100) { + x = raw->sizeY * raw->sizeZ * sizeof(GLuint); + raw->rowStart = (GLuint *)malloc(x); + raw->rowSize = (GLint *)malloc(x); + if (raw->rowStart == NULL || raw->rowSize == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + raw->rleEnd = 512 + (2 * x); + fseek(raw->file, 512, SEEK_SET); + fread(raw->rowStart, 1, x, raw->file); + fread(raw->rowSize, 1, x, raw->file); + if (swapFlag) { + ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); + ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); + } + } + return raw; +} + +static void RawImageClose(rawImageRec *raw) +{ + + fclose(raw->file); + free(raw->tmp); + free(raw->tmpR); + free(raw->tmpG); + free(raw->tmpB); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + if ((raw->type & 0xFF00) == 0x0100) { + fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET); + fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], + raw->file); + + iPtr = raw->tmp; + oPtr = buf; + while (!done) { + pixel = *iPtr++; + count = (int)(pixel & 0x7F); + if (!count) { + done = 1; + return; + } + if (pixel & 0x80) { + while (count--) { + *oPtr++ = *iPtr++; + } + } else { + pixel = *iPtr++; + while (count--) { + *oPtr++ = pixel; + } + } + } + } else { + fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY), + SEEK_SET); + fread(buf, 1, raw->sizeX, raw->file); + } +} + + +static void RawImageGetData(rawImageRec *raw, TK_RGBImageRec *final) +{ + unsigned char *ptr; + int i, j; + + final->data = (unsigned char *)malloc((raw->sizeX+1)*(raw->sizeY+1)*4); + if (final->data == NULL) { + fprintf(stderr, "Out of memory!\n"); + } + + ptr = final->data; + for (i = 0; i < (int)(raw->sizeY); i++) { + RawImageGetRow(raw, raw->tmpR, i, 0); + RawImageGetRow(raw, raw->tmpG, i, 1); + RawImageGetRow(raw, raw->tmpB, i, 2); + if (raw->sizeZ>3) { + RawImageGetRow(raw, raw->tmpA, i, 3); + } + for (j = 0; j < (int)(raw->sizeX); j++) { + *ptr++ = *(raw->tmpR + j); + *ptr++ = *(raw->tmpG + j); + *ptr++ = *(raw->tmpB + j); + if (raw->sizeZ>3) { + *ptr++ = *(raw->tmpA + j); + } + } + } +} + + +static TK_RGBImageRec *tkRGBImageLoad(const char *fileName) +{ + rawImageRec *raw; + TK_RGBImageRec *final; + + raw = RawImageOpen(fileName); + if (!raw) { + fprintf(stderr, "File not found\n"); + return NULL; + } + final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec)); + if (final == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + final->sizeX = raw->sizeX; + final->sizeY = raw->sizeY; + final->components = raw->sizeZ; + RawImageGetData(raw, final); + RawImageClose(raw); + return final; +} + + +static void FreeImage( TK_RGBImageRec *image ) +{ + free(image->data); + free(image); +} + + +/* + * Load an SGI .rgb file and generate a set of 2-D mipmaps from it. + * Input: imageFile - name of .rgb to read + * intFormat - internal texture format to use, or number of components + * Return: GL_TRUE if success, GL_FALSE if error. + */ +GLboolean LoadRGBMipmaps( const char *imageFile, GLint intFormat ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( GL_TEXTURE_2D, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + FreeImage(image); + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + bytes = image->sizeX * image->sizeY * image->components; + buffer = (GLubyte *) malloc(bytes); + if (!buffer) + return NULL; + + memcpy( (void *) buffer, (void *) image->data, bytes ); + + FreeImage(image); + + return buffer; +} + diff --git a/progs/util/sampleMakefile b/progs/util/sampleMakefile new file mode 100644 index 0000000000..ebb57ff3dd --- /dev/null +++ b/progs/util/sampleMakefile @@ -0,0 +1,49 @@ +# $Id: sampleMakefile,v 1.1 1999/08/19 00:55:42 jtg Exp $ + +# Sample makefile for compiling OpenGL/Mesa applications on Unix. +# This example assumes Linux with gcc. + +# This makefile is in the public domain + +# $Log: sampleMakefile,v $ +# Revision 1.1 1999/08/19 00:55:42 jtg +# Initial revision +# +# Revision 1.1 1999/02/24 05:20:45 brianp +# Initial revision +# + + +CC = gcc + +CFLAGS = -c -g -ansi -pedantic -Wall + +INCDIRS = -I. -I../include + +LIBDIRS = -L../lib -L/usr/X11/lib + +LIBS = -lglut -lMesaGLU -lMesaGL -lX11 -lXext -lXmu -lXt -lXi -lSM -lICE -lm + +OBJECTS = main.o \ + file1.o \ + file2.o \ + file3.o + + +PROGRAMS = myprogram + + +.c.o: + $(CC) $(CFLAGS) $(INCDIRS) $< -o $@ + + + +default: $(PROGRAMS) + + +dtenvmap: $(OBJECTS) + $(CC) $(OBJECTS) $(LIBDIRS) $(LIBS) -o $@ + + +clean: + rm -f *.o diff --git a/progs/util/showbuffer.c b/progs/util/showbuffer.c new file mode 100644 index 0000000000..17f84dc62b --- /dev/null +++ b/progs/util/showbuffer.c @@ -0,0 +1,192 @@ +/* showbuffer.c */ + + +/* + * Copy the depth buffer to the color buffer as a grayscale image. + * Useful for inspecting the depth buffer values. + * + * This program is in the public domain. + * + * Brian Paul November 4, 1998 + */ + + +#include +#include +#include +#include "showbuffer.h" + + + +/* + * Copy the depth buffer values into the current color buffer as a + * grayscale image. + * Input: winWidth, winHeight - size of the window + * zBlack - the Z value which should map to black (usually 1) + * zWhite - the Z value which should map to white (usually 0) + */ +void +ShowDepthBuffer( GLsizei winWidth, GLsizei winHeight, + GLfloat zBlack, GLfloat zWhite ) +{ + GLfloat *depthValues; + + assert(zBlack >= 0.0); + assert(zBlack <= 1.0); + assert(zWhite >= 0.0); + assert(zWhite <= 1.0); + assert(zBlack != zWhite); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + /* Read depth values */ + depthValues = (GLfloat *) malloc(winWidth * winHeight * sizeof(GLfloat)); + assert(depthValues); + glReadPixels(0, 0, winWidth, winHeight, GL_DEPTH_COMPONENT, + GL_FLOAT, depthValues); + + /* Map Z values from [zBlack, zWhite] to gray levels in [0, 1] */ + /* Not using glPixelTransfer() because it's broke on some systems! */ + if (zBlack != 0.0 || zWhite != 1.0) { + GLfloat scale = 1.0 / (zWhite - zBlack); + GLfloat bias = -zBlack * scale; + int n = winWidth * winHeight; + int i; + for (i = 0; i < n; i++) + depthValues[i] = depthValues[i] * scale + bias; + } + + /* save GL state */ + glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | + GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); + + /* setup raster pos for glDrawPixels */ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glRasterPos2f(0, 0); + + glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_FLOAT, depthValues); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + free(depthValues); + + glPopAttrib(); +} + + + + +/* + * Copy the alpha channel values into the current color buffer as a + * grayscale image. + * Input: winWidth, winHeight - size of the window + */ +void +ShowAlphaBuffer( GLsizei winWidth, GLsizei winHeight ) +{ + GLubyte *alphaValues; + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + /* Read alpha values */ + alphaValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte)); + assert(alphaValues); + glReadPixels(0, 0, winWidth, winHeight, GL_ALPHA, GL_UNSIGNED_BYTE, alphaValues); + + /* save GL state */ + glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL | + GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); + + /* setup raster pos for glDrawPixels */ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glRasterPos2f(0, 0); + + glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, alphaValues); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + free(alphaValues); + + glPopAttrib(); +} + + + +/* + * Copy the stencil buffer values into the current color buffer as a + * grayscale image. + * Input: winWidth, winHeight - size of the window + * scale, bias - scale and bias to apply to stencil values for display + */ +void +ShowStencilBuffer( GLsizei winWidth, GLsizei winHeight, + GLfloat scale, GLfloat bias ) +{ + GLubyte *stencilValues; + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + /* Read stencil values */ + stencilValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte)); + assert(stencilValues); + glReadPixels(0, 0, winWidth, winHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilValues); + + /* save GL state */ + glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | + GL_PIXEL_MODE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); + + /* setup raster pos for glDrawPixels */ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glRasterPos2f(0, 0); + + glPixelTransferf(GL_RED_SCALE, scale); + glPixelTransferf(GL_RED_BIAS, bias); + glPixelTransferf(GL_GREEN_SCALE, scale); + glPixelTransferf(GL_GREEN_BIAS, bias); + glPixelTransferf(GL_BLUE_SCALE, scale); + glPixelTransferf(GL_BLUE_BIAS, bias); + + glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, stencilValues); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + free(stencilValues); + + glPopAttrib(); +} diff --git a/progs/util/showbuffer.h b/progs/util/showbuffer.h new file mode 100644 index 0000000000..63533d8e9b --- /dev/null +++ b/progs/util/showbuffer.h @@ -0,0 +1,36 @@ +/* showbuffer. h*/ + +/* + * Copy the depth buffer to the color buffer as a grayscale image. + * Useful for inspecting the depth buffer values. + * + * This program is in the public domain. + * + * Brian Paul November 4, 1998 + */ + + +#ifndef SHOWBUFFER_H +#define SHOWBUFFER_H + + +#include + + + +extern void +ShowDepthBuffer( GLsizei winWidth, GLsizei winHeight, + GLfloat zBlack, GLfloat zWhite ); + + +extern void +ShowAlphaBuffer( GLsizei winWidth, GLsizei winHeight ); + + +extern void +ShowStencilBuffer( GLsizei winWidth, GLsizei winHeight, + GLfloat scale, GLfloat bias ); + + + +#endif diff --git a/progs/util/winpos.c b/progs/util/winpos.c new file mode 100644 index 0000000000..5ad98fd270 --- /dev/null +++ b/progs/util/winpos.c @@ -0,0 +1,42 @@ +/* winpos.c */ + + +/* + * Set the current raster position to a specific window + * coordinate. Also see the GL_MESA_window_pos extension. + * + * Written by Brian Paul and in the public domain. + */ + + +void WindowPos( GLfloat x, GLfloat y, GLfloat z ) +{ + GLfloat fx, fy; + + /* Push current matrix mode and viewport attributes */ + glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT ); + + /* Setup projection parameters */ + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + + glDepthRange( z, z ); + glViewport( (int) x - 1, (int) y - 1, 2, 2 ); + + /* set the raster (window) position */ + fx = x - (int) x; + fy = y - (int) y; + glRasterPos3f( fx, fy, 0.0 ); + + /* restore matrices, viewport and matrix mode */ + glPopMatrix(); + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + + glPopAttrib(); +} + diff --git a/progs/xdemos/Makefile.X11 b/progs/xdemos/Makefile.X11 new file mode 100644 index 0000000000..ab5dce418d --- /dev/null +++ b/progs/xdemos/Makefile.X11 @@ -0,0 +1,58 @@ +# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:43 jtg Exp $ + +# Mesa 3-D graphics library +# Version: 3.1 +# Copyright (C) 1995-1999 Brian Paul + +# Makefile for non-GLUT (X11, SVGA, etc) demo programs + + +##### MACROS ##### + +INCDIR = ../include +LIBDIR = ../lib + +GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS) + +LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB) + +PROGS = glxdemo glxpixmap offset xdemo + + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@ + + + +##### TARGETS ##### + +default: + @echo "Specify a target configuration" + +clean: + -rm *.o *~ + +realclean: + -rm $(PROGS) + -rm *.o *~ + +targets: $(PROGS) + +# execute all programs +exec: $(PROGS) + @for prog in $(PROGS) ; \ + do \ + echo -n "Running $$prog ..." ; \ + $$prog ; \ + echo ; \ + done + + +include ../Make-config + diff --git a/progs/xdemos/descrip.mms b/progs/xdemos/descrip.mms new file mode 100644 index 0000000000..aa56c1cec3 --- /dev/null +++ b/progs/xdemos/descrip.mms @@ -0,0 +1,79 @@ +# Makefile for demo programs for VMS +# contributed by Jouk Jansen joukj@crys.chem.uva.nl + + +.first + define gl [-.include.gl] + +.include [-]mms-config. + +##### MACROS ##### + +INCDIR = [-.include] +CFLAGS = /include=$(INCDIR)/define=(FBIND=1) + +GL_LIBS = [-.lib]libMesaaux/l,libMesatk/l,libMesaGLU/l,libMesaGL/l,$(XLIBS) + +LIB_DEP = [-.lib]$(GL_LIB) [-.lib]$(GLU_LIB) [-.lib]$(TK_LIB) [-.lib]$(AUX_LIB) + +PROGS = bounce.exe;,gamma.exe;,gears.exe;,glxdemo.exe;,glxpixmap.exe;,\ + isosurf.exe;,offset.exe;,osdemo.exe;,spin.exe;,test0.exe;,\ + texobj.exe;,xdemo.exe;,reflect.exe;,winpos.exe; + + + +##### RULES ##### + + +##### TARGETS ##### +default : + mms $(PROGS) + +clean : + delete *.obj;* + +realclean : + delete $(PROGS) + delete *.obj;* + +bounce.exe; : bounce.obj $(LIB_DEP) + link bounce,$(GL_LIBS) + +gamma.exe; : gamma.obj $(LIB_DEP) + link gamma,$(GL_LIBS) + +gears.exe; : gears.obj $(LIB_DEP) + link gears,$(GL_LIBS) + +glxdemo.exe; : glxdemo.obj $(LIB_DEP) + link glxdemo,$(GL_LIBS) + +glxpixmap.exe; : glxpixmap.obj $(LIB_DEP) + link glxpixmap,$(GL_LIBS) + +isosurf.exe; : isosurf.obj $(LIB_DEP) + link isosurf,$(GL_LIBS) + +offset.exe; : offset.obj $(LIB_DEP) + link offset,$(GL_LIBS) + +osdemo.exe; : osdemo.obj $(LIB_DEP) + link osdemo,$(GL_LIBS) + +spin.exe; : spin.obj $(LIB_DEP) + link spin,$(GL_LIBS) + +test0.exe; : test0.obj $(LIB_DEP) + link test0,$(GL_LIBS) + +texobj.exe; : texobj.obj $(LIB_DEP) + link texobj,$(GL_LIBS) + +xdemo.exe; : xdemo.obj $(LIB_DEP) + link xdemo,$(GL_LIBS) + +reflect.exe; : reflect.obj $(LIB_DEP) + link reflect,$(GL_LIBS) + +winpos.exe; : winpos.obj $(LIB_DEP) + link winpos,$(GL_LIBS) diff --git a/progs/xdemos/glxdemo.c b/progs/xdemos/glxdemo.c new file mode 100644 index 0000000000..c49cd85140 --- /dev/null +++ b/progs/xdemos/glxdemo.c @@ -0,0 +1,136 @@ +/* $Id: glxdemo.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + + +/* + * A demonstration of using the GLX functions. This program is in the + * public domain. + * + * Brian Paul + */ + + +/* + * $Log: glxdemo.c,v $ + * Revision 1.1 1999/08/19 00:55:43 jtg + * Initial revision + * + * Revision 3.0 1998/02/21 02:16:54 brianp + * initial rev + * + */ + + +#include +#include +#include +#include + + + +static void redraw( Display *dpy, Window w ) +{ + printf("Redraw event\n"); + + glClear( GL_COLOR_BUFFER_BIT ); + + glColor3f( 1.0, 1.0, 0.0 ); + glRectf( -0.8, -0.8, 0.8, 0.8 ); + + glXSwapBuffers( dpy, w ); +} + + + +static void resize( unsigned int width, unsigned int height ) +{ + printf("Resize event\n"); + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); +} + + + +static Window make_rgb_db_window( Display *dpy, + unsigned int width, unsigned int height ) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + GLXContext ctx; + XVisualInfo *visinfo; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + visinfo = glXChooseVisual( dpy, scrnum, attrib ); + if (!visinfo) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + + glXMakeCurrent( dpy, win, ctx ); + + return win; +} + + +static void event_loop( Display *dpy ) +{ + XEvent event; + + while (1) { + XNextEvent( dpy, &event ); + + switch (event.type) { + case Expose: + redraw( dpy, event.xany.window ); + break; + case ConfigureNotify: + resize( event.xconfigure.width, event.xconfigure.height ); + break; + } + } +} + + + +int main( int argc, char *argv[] ) +{ + Display *dpy; + Window win; + + dpy = XOpenDisplay(NULL); + + win = make_rgb_db_window( dpy, 300, 300 ); + + glShadeModel( GL_FLAT ); + glClearColor( 0.5, 0.5, 0.5, 1.0 ); + + XMapWindow( dpy, win ); + + event_loop( dpy ); + return 0; +} diff --git a/progs/xdemos/glxpixmap.c b/progs/xdemos/glxpixmap.c new file mode 100644 index 0000000000..e4a62c72d9 --- /dev/null +++ b/progs/xdemos/glxpixmap.c @@ -0,0 +1,160 @@ +/* $Id: glxpixmap.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + + +/* + * A demonstration of using the GLXPixmap functions. This program is in + * the public domain. + * + * Brian Paul + */ + + +/* + * $Id: glxpixmap.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ + */ + + +#include +#include +#include +#include + + + +static GLXContext ctx; +static XVisualInfo *visinfo; +static GC gc; + + + +static Window make_rgb_window( Display *dpy, + unsigned int width, unsigned int height ) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + visinfo = glXChooseVisual( dpy, scrnum, attrib ); + if (!visinfo) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + /* TODO: share root colormap if possible */ + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* make an X GC so we can do XCopyArea later */ + gc = XCreateGC( dpy, win, 0, NULL ); + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + + return win; +} + + +static GLXPixmap make_pixmap( Display *dpy, Window win, + unsigned int width, unsigned int height ) +{ + Pixmap pm; + GLXPixmap glxpm; + XWindowAttributes attr; + + pm = XCreatePixmap( dpy, win, width, height, visinfo->depth ); + XGetWindowAttributes( dpy, win, &attr ); + + /* + * IMPORTANT: + * Use the glXCreateGLXPixmapMESA funtion when using Mesa because + * Mesa needs to know the colormap associated with a pixmap in order + * to render correctly. This is because Mesa allows RGB rendering + * into any kind of visual, not just TrueColor or DirectColor. + */ +#ifdef GLX_MESA_pixmap_colormap + glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap ); +#else + /* This will work with Mesa too if the visual is TrueColor or DirectColor */ + glxpm = glXCreateGLXPixmap( dpy, visinfo, pm ); +#endif + + return glxpm; +} + + + +static void event_loop( Display *dpy, GLXPixmap pm ) +{ + XEvent event; + + while (1) { + XNextEvent( dpy, &event ); + + switch (event.type) { + case Expose: + printf("Redraw\n"); + /* copy the image from GLXPixmap to window */ + XCopyArea( dpy, pm, event.xany.window, /* src, dest */ + gc, 0, 0, 300, 300, /* gc, src pos, size */ + 0, 0 ); /* dest pos */ + break; + case ConfigureNotify: + /* nothing */ + break; + } + } +} + + + +int main( int argc, char *argv[] ) +{ + Display *dpy; + Window win; + GLXPixmap pm; + + dpy = XOpenDisplay(NULL); + + win = make_rgb_window( dpy, 300, 300 ); + pm = make_pixmap( dpy, win, 300, 300 ); + +#ifdef JUNK + glXMakeCurrent( dpy, win, ctx ); /*to make sure ctx is properly initialized*/ +#endif + + glXMakeCurrent( dpy, pm, ctx ); + + /* Render an image into the pixmap */ + glShadeModel( GL_FLAT ); + glClearColor( 0.5, 0.5, 0.5, 1.0 ); + glClear( GL_COLOR_BUFFER_BIT ); + glViewport( 0, 0, 300, 300 ); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); + glColor3f( 0.0, 1.0, 1.0 ); + glRectf( -0.75, -0.75, 0.75, 0.75 ); + glFlush(); + + /* when a redraw is needed we'll just copy the pixmap image to the window */ + + XMapWindow( dpy, win ); + + event_loop( dpy, pm ); + return 0; +} diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c new file mode 100644 index 0000000000..158e52a97c --- /dev/null +++ b/progs/xdemos/offset.c @@ -0,0 +1,323 @@ +/**************************************************************************** +Copyright 1995 by Silicon Graphics Incorporated, Mountain View, California. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Silicon Graphics not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + +****************************************************************************/ + +/* + * Derived from code written by Kurt Akeley, November 1992 + * + * Uses PolygonOffset to draw hidden-line images. PolygonOffset + * shifts the z values of polygons an amount that is + * proportional to their slope in screen z. This keeps + * the lines, which are drawn without displacement, from + * interacting with their respective polygons, and + * thus eliminates line dropouts. + * + * The left image shows an ordinary antialiased wireframe image. + * The center image shows an antialiased hidden-line image without + * PolygonOffset. + * The right image shows an antialiased hidden-line image using + * PolygonOffset to reduce artifacts. + * + * Drag with a mouse button pressed to rotate the models. + * Press the escape key to exit. + */ + +/* + * Modified for OpenGL 1.1 glPolygonOffset() conventions + */ + + +#include +#include +#include +#include +#include +#include + +/*#undef GL_EXT_polygon_offset uncomment to use new version*/ + + +#ifndef EXIT_FAILURE +# define EXIT_FAILURE 1 +#endif +#ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +#endif + +#define MAXQUAD 6 + +typedef float Vertex[3]; + +typedef Vertex Quad[4]; + +/* data to define the six faces of a unit cube */ +Quad quads[MAXQUAD] = { + { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} }, + { {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} }, + { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} }, + { {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} }, + { {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} }, + { {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} } +}; + +#define WIREFRAME 0 +#define HIDDEN_LINE 1 + +static void error(const char* prog, const char* msg); +static void cubes(int mx, int my, int mode); +static void fill(Quad quad); +static void outline(Quad quad); +static void draw_hidden(Quad quad, int mode); +static void process_input(Display *dpy, Window win); +static int query_extension(char* extName); + +static int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None }; + +static int dimension = 3; + +int main(int argc, char** argv) { + Display *dpy; + XVisualInfo *vi; + XSetWindowAttributes swa; + Window win; + GLXContext cx; + + dpy = XOpenDisplay(0); + if (!dpy) error(argv[0], "can't open display"); + + vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList); + if (!vi) error(argv[0], "no suitable visual"); + + cx = glXCreateContext(dpy, vi, 0, GL_TRUE); + + swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), + vi->visual, AllocNone); + + swa.border_pixel = 0; + swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | + ButtonPressMask | ButtonMotionMask; + win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 900, 300, + 0, vi->depth, InputOutput, vi->visual, + CWBorderPixel|CWColormap|CWEventMask, &swa); + XStoreName(dpy, win, "hiddenline"); + XMapWindow(dpy, win); + + glXMakeCurrent(dpy, win, cx); + + /* check for the polygon offset extension */ +#ifndef GL_VERSION_1_1 + if (!query_extension("GL_EXT_polygon_offset")) + error(argv[0], "polygon_offset extension is not available"); +#else + (void) query_extension; +#endif + + /* set up viewing parameters */ + glMatrixMode(GL_PROJECTION); + gluPerspective(20, 1, 0.1, 20); + glMatrixMode(GL_MODELVIEW); + glTranslatef(0, 0, -15); + + /* set other relevant state information */ + glEnable(GL_DEPTH_TEST); + +#ifdef GL_EXT_polygon_offset + printf("using 1.0 offset extension\n"); + glPolygonOffsetEXT( 1.0, 0.00001 ); +#else + printf("using 1.1 offset\n"); + glPolygonOffset( 1.0, 0.5 ); +#endif + + glShadeModel( GL_FLAT ); + glDisable( GL_DITHER ); + + /* process events until the user presses ESC */ + while (1) process_input(dpy, win); + + return 0; +} + +static void +draw_scene(int mx, int my) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glTranslatef(-1.7, 0.0, 0.0); + cubes(mx, my, WIREFRAME); + glPopMatrix(); + + glPushMatrix(); + cubes(mx, my, HIDDEN_LINE); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(1.7, 0.0, 0.0); +#ifdef GL_EXT_polygon_offset + glEnable(GL_POLYGON_OFFSET_EXT); +#else + glEnable(GL_POLYGON_OFFSET_FILL); +#endif + cubes(mx, my, HIDDEN_LINE); +#ifdef GL_EXT_polygon_offset + glDisable(GL_POLYGON_OFFSET_EXT); +#else + glDisable(GL_POLYGON_OFFSET_FILL); +#endif + glPopMatrix(); +} + + +static void +cubes(int mx, int my, int mode) { + int x, y, z, i; + + /* track the mouse */ + glRotatef(mx / 2.0, 0, 1, 0); + glRotatef(my / 2.0, 1, 0, 0); + + /* draw the lines as hidden polygons */ + glTranslatef(-0.5, -0.5, -0.5); + glScalef(1.0/dimension, 1.0/dimension, 1.0/dimension); + for (z = 0; z < dimension; z++) { + for (y = 0; y < dimension; y++) { + for (x = 0; x < dimension; x++) { + glPushMatrix(); + glTranslatef(x, y, z); + glScalef(0.8, 0.8, 0.8); + for (i = 0; i < MAXQUAD; i++) + draw_hidden(quads[i], mode); + glPopMatrix(); + } + } + } +} + +static void +fill(Quad quad) { + /* draw a filled polygon */ + glBegin(GL_QUADS); + glVertex3fv(quad[0]); + glVertex3fv(quad[1]); + glVertex3fv(quad[2]); + glVertex3fv(quad[3]); + glEnd(); +} + +static void +outline(Quad quad) { + /* draw an outlined polygon */ + glBegin(GL_LINE_LOOP); + glVertex3fv(quad[0]); + glVertex3fv(quad[1]); + glVertex3fv(quad[2]); + glVertex3fv(quad[3]); + glEnd(); +} + +static void +draw_hidden(Quad quad, int mode) { + if (mode == HIDDEN_LINE) { + glColor3f(0, 0, 0); + fill(quad); + } + + /* draw the outline using white, optionally fill the interior with black */ + glColor3f(1, 1, 1); + outline(quad); +} + +static void +process_input(Display *dpy, Window win) { + XEvent event; + static int prevx, prevy; + static int deltax = 90, deltay = 40; + + do { + char buf[31]; + KeySym keysym; + + XNextEvent(dpy, &event); + switch(event.type) { + case Expose: + break; + case ConfigureNotify: { + /* this approach preserves a 1:1 viewport aspect ratio */ + int vX, vY, vW, vH; + int eW = event.xconfigure.width, eH = event.xconfigure.height; + if (eW >= eH) { + vX = 0; + vY = (eH - eW) >> 1; + vW = vH = eW; + } else { + vX = (eW - eH) >> 1; + vY = 0; + vW = vH = eH; + } + glViewport(vX, vY, vW, vH); + } + break; + case KeyPress: + (void) XLookupString(&event.xkey, buf, sizeof(buf), &keysym, NULL); + switch (keysym) { + case XK_Escape: + exit(EXIT_SUCCESS); + default: + break; + } + case ButtonPress: + prevx = event.xbutton.x; + prevy = event.xbutton.y; + break; + case MotionNotify: + deltax += (event.xbutton.x - prevx); prevx = event.xbutton.x; + deltay += (event.xbutton.y - prevy); prevy = event.xbutton.y; + break; + default: + break; + } + } while (XPending(dpy)); + + draw_scene(deltax, deltay); + glXSwapBuffers(dpy, win); +} + +static void +error(const char *prog, const char *msg) { + fprintf(stderr, "%s: %s\n", prog, msg); + exit(EXIT_FAILURE); +} + +static int +query_extension(char* extName) { + char *p = (char *) glGetString(GL_EXTENSIONS); + char *end = p + strlen(p); + while (p < end) { + int n = strcspn(p, " "); + if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0)) + return GL_TRUE; + p += (n + 1); + } + return GL_FALSE; +} + diff --git a/progs/xdemos/shape.c b/progs/xdemos/shape.c new file mode 100644 index 0000000000..94b9b1f26a --- /dev/null +++ b/progs/xdemos/shape.c @@ -0,0 +1,305 @@ +/* $Id: shape.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + +/* + * Example of using the X "shape" extension with OpenGL: render a spinning + * cube inside of a non-rectangular window. + * + * Press ESC to exit. Press up/down to change window shape. + * + * To compile add "shape" to the PROGS list in Makefile. + * + * Brian Paul + * June 16, 1997 + * + * This program is in the public domain. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef PI +#define PI 3.1415926 +#endif + + +static int Width=500, Height=500; + +static float Xangle = 0.0, Yangle = 0.0; +static int Redraw = 0; +static int Sides = 5; +static int MinSides = 3; +static int MaxSides = 20; + + +/* + * Draw the OpenGL stuff and do a SwapBuffers. + */ +static void display(Display *dpy, Window win) +{ + float scale = 1.7; + + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + + glScalef(scale, scale, scale); + glRotatef(Xangle, 1.0, 0.0, 0.0); + glRotatef(Yangle, 0.0, 1.0, 0.0); + + glColor3f(1.0, 1.0, 1.0); + glBegin(GL_LINE_LOOP); + glVertex3f(-1.0, -1.0, -1.0); + glVertex3f( 1.0, -1.0, -1.0); + glVertex3f( 1.0, 1.0, -1.0); + glVertex3f(-1.0, 1.0, -1.0); + glEnd(); + + glBegin(GL_LINE_LOOP); + glVertex3f(-1.0, -1.0, 1.0); + glVertex3f( 1.0, -1.0, 1.0); + glVertex3f( 1.0, 1.0, 1.0); + glVertex3f(-1.0, 1.0, 1.0); + glEnd(); + + glBegin(GL_LINES); + glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, 1.0); + glVertex3f( 1.0, -1.0, -1.0); glVertex3f( 1.0, -1.0, 1.0); + glVertex3f( 1.0, 1.0, -1.0); glVertex3f( 1.0, 1.0, 1.0); + glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 1.0); + glEnd(); + + glPopMatrix(); + + glXSwapBuffers(dpy, win); +} + + +/* + * Called when no events are pending. + */ +static void idle(void) +{ + Xangle += 2.0; + Yangle += 3.3; + Redraw = 1; +} + + +/* + * This is called when we have to recompute the window shape bitmask. + * We just generate an n-sided regular polygon here but any other shape + * would be possible. + */ +static void make_shape_mask(Display *dpy, Window win, int width, int height, + int sides) +{ + Pixmap shapeMask; + XGCValues xgcv; + GC gc; + + /* allocate 1-bit deep pixmap and a GC */ + shapeMask = XCreatePixmap(dpy, win, width, height, 1); + gc = XCreateGC(dpy, shapeMask, 0, &xgcv); + + /* clear shapeMask to zeros */ + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, shapeMask, gc, 0, 0, width, height); + + /* draw mask */ + XSetForeground(dpy, gc, 1); + { + int cx = width / 2; + int cy = height / 2; + float angle = 0.0; + float step = 2.0 * PI / sides; + float radius = width / 2; + int i; + XPoint points[100]; + for (i=0;iMaxSides) Sides = MaxSides; + make_shape_mask(dpy, win, Width, Height, Sides); + break; + case XK_Down: + Sides--; + if (Sidesvisual); + if (!cmap) { + fprintf(stderr, "Couln't create colormap\n"); + return 1; + } + + winAttribs.border_pixel = 0; + winAttribs.colormap = cmap; + winAttribs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + winAttribsMask = CWBorderPixel | CWColormap | CWEventMask; + win = XCreateWindow(dpy, root, 0, 0, Width, Height, 0, + visInfo->depth, InputOutput, + visInfo->visual, + winAttribsMask, &winAttribs); + XMapWindow(dpy, win); + + glXMakeCurrent(dpy, win, glCtx); + + printf("Press ESC to exit.\n"); + printf("Press up/down to change window shape.\n"); + + event_loop(dpy, win); + + return 0; +} diff --git a/progs/xdemos/vgears.c b/progs/xdemos/vgears.c new file mode 100644 index 0000000000..13d030a8be --- /dev/null +++ b/progs/xdemos/vgears.c @@ -0,0 +1,282 @@ +/* $ID$ */ + +/* + * Spinning gears demo for Linux SVGA/Mesa interface in 32K color mode. + * + * Compile with: gcc vgears.c -I../include -L../lib -lMesaGL -lX11 -lXext + * -lvga -lm -o vgears + * + * This program is in the public domain. + * Brian Paul, January 1996 + */ + + +#include +#include +#include "GL/svgamesa.h" +#include "GL/gl.h" + + +int width = 800, height = 600; + +SVGAMesaContext vmc; + + + +/* + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth ) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth/2.0; + r2 = outer_radius + tooth_depth/2.0; + + da = 2.0*M_PI / teeth / 4.0; + + glShadeModel( GL_FLAT ); + + glNormal3f( 0.0, 0.0, 1.0 ); + + /* draw front face */ + glBegin( GL_QUAD_STRIP ); + for (i=0;i<=teeth;i++) { + angle = i * 2.0*M_PI / teeth; + glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); + glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 ); + glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); + glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 ); + } + glEnd(); + + /* draw front sides of teeth */ + glBegin( GL_QUADS ); + da = 2.0*M_PI / teeth / 4.0; + for (i=0;iheight) { + GLfloat w = (GLfloat) width / (GLfloat) height; + glFrustum( -w, w, -1.0, 1.0, 5.0, 60.0 ); + } + else { + GLfloat h = (GLfloat) height / (GLfloat) width; + glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 ); + } + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -40.0 ); +} + +void setup( void ) +{ + vga_init(); + + vga_setmode(G800x600x32K); +/* gl_setcontextvga(G800x600x32K);*/ + + vmc = SVGAMesaCreateContext(GL_TRUE); + SVGAMesaMakeCurrent( vmc ); +} + + +void end( void ) +{ + SVGAMesaDestroyContext( vmc ); + + vga_setmode( TEXT ); +} + + +int main( int argc, char *argv[] ) +{ + int i; + + setup(); + init(); + for (i=0;i<4;i++) { + draw(); /*SVGAMesaSwapBuffers();*/ + } + end(); + return 0; +} diff --git a/progs/xdemos/vindex.c b/progs/xdemos/vindex.c new file mode 100644 index 0000000000..f9e3192f38 --- /dev/null +++ b/progs/xdemos/vindex.c @@ -0,0 +1,66 @@ +/* $Id: vindex.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + +/* + * Test Linux 8-bit SVGA/Mesa color index mode + * + * Compile with: gcc vindex.c -I../include -L../lib -lMesaGL -lX11 -lXext + * -lvga -lm -o vindex + * + * This program is in the public domain. + * Brian Paul, January 1996 + */ + + + +#include +#include "GL/svgamesa.h" +#include "GL/gl.h" + + + +static GLint width = 640, height = 480; + + + +static void display( void ) +{ + int i, j; + int w, h; + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, (GLfloat) width, 0.0, (GLfloat) height, -1.0, 1.0 ); + + glClear( GL_COLOR_BUFFER_BIT ); + + w = width / 16; + h = height / 16; + for (i=0;i<16;i++) { + for (j=0;j<16;j++) { + glIndexi( i*16+j ); + glRecti( i*w, j*h, i*w+w, j*h+h ); + } + } +} + + + +int main( int argc, char *argv[] ) +{ + SVGAMesaContext vmc; + int i; + + vga_init(); + vga_setmode( G640x480x256 ); + + vmc = SVGAMesaCreateContext( GL_FALSE ); + SVGAMesaMakeCurrent( vmc ); + + display(); + sleep(3); + + SVGAMesaDestroyContext( vmc ); + vga_setmode( TEXT ); + return 0; +} diff --git a/progs/xdemos/vtest.c b/progs/xdemos/vtest.c new file mode 100644 index 0000000000..f0900b6ed6 --- /dev/null +++ b/progs/xdemos/vtest.c @@ -0,0 +1,83 @@ +/* $Id: vtest.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + +/* + * Test SVGA/Mesa interface in 32K color mode. + * + * Compile with: gcc vtest.c -I../include -L../lib -lMesaGL -lX11 -lXext + * -lvga -lm -o vtest + * + * This program is in the public domain. + * Brian Paul, January 1996 + */ + + + +#include +#include "GL/svgamesa.h" +#include "GL/gl.h" + + +SVGAMesaContext vmc; + + + +void setup( void ) +{ + vga_init(); + + vga_setmode(G800x600x32K); +/* gl_setcontextvga(G800x600x32K);*/ + + vmc = SVGAMesaCreateContext( GL_FALSE ); /* single buffered */ + SVGAMesaMakeCurrent( vmc ); +} + + +void test( void ) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); + glMatrixMode(GL_MODELVIEW); + + glClear( GL_COLOR_BUFFER_BIT ); + + glBegin( GL_LINES ); + glColor3f( 1.0, 0.0, 0.0 ); + glVertex2f( -0.5, 0.5 ); + glVertex2f( 0.5, 0.5 ); + glColor3f( 0.0, 1.0, 0.0 ); + glVertex2f( -0.5, 0.25 ); + glVertex2f( 0.5, 0.25 ); + glColor3f( 0.0, 0.0, 1.0 ); + glVertex2f( -0.5, 0.0 ); + glVertex2f( 0.5, 0.0 ); + glEnd(); + + glBegin( GL_POLYGON ); + glColor3f( 1.0, 0.0, 0.0 ); + glVertex2f( 0.0, 0.7 ); + glColor3f( 0.0, 1.0, 0.0 ); + glVertex2f( -0.5, -0.5 ); + glColor3f( 0.0, 0.0, 1.0 ); + glVertex2f( 0.5, -0.5 ); + glEnd(); + + sleep(3); +} + +void end( void ) +{ + SVGAMesaDestroyContext( vmc ); + + vga_setmode( TEXT ); +} + + +int main( int argc, char *argv[] ) +{ + setup(); + test(); + end(); + return 0; +} diff --git a/progs/xdemos/xdemo.c b/progs/xdemos/xdemo.c new file mode 100644 index 0000000000..13facba839 --- /dev/null +++ b/progs/xdemos/xdemo.c @@ -0,0 +1,347 @@ +/* $Id: xdemo.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */ + + +/* + * Very simple demo of how to use the Mesa/X11 interface instead of the + * glx, tk or aux toolkits. I highly recommend using the GLX interface + * instead of the X/Mesa interface, however. + * + * This program is in the public domain. + * + * Brian Paul + */ + + +/* + * $Log: xdemo.c,v $ + * Revision 1.1 1999/08/19 00:55:43 jtg + * Initial revision + * + * Revision 3.0 1998/02/21 02:16:54 brianp + * initial rev + * + */ + + + +#include +#include +#include +#include +#include +#include "GL/xmesa.h" +#include "GL/gl.h" + + + +static GLint Black, Red, Green, Blue; + + + +static void make_window( char *title, int color_flag ) +{ + int x = 10, y = 10, width = 400, height = 300; + Display *dpy; + int scr; + Window root, win; + Colormap cmap; + XColor xcolor; + int attr_flags; + XVisualInfo *visinfo; + XSetWindowAttributes attr; + XTextProperty tp; + XSizeHints sh; + XEvent e; + XMesaContext context; + XMesaVisual visual; + XMesaBuffer buffer; + + + /* + * Do the usual X things to make a window. + */ + + dpy = XOpenDisplay(NULL); + if (!dpy) { + printf("Couldn't open default display!\n"); + exit(1); + } + + scr = DefaultScreen(dpy); + root = RootWindow(dpy, scr); + + /* alloc visinfo struct */ + visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) ); + + /* Get a visual and colormap */ + if (color_flag) { + /* Open TrueColor window */ + +/* + if (!XMatchVisualInfo( dpy, scr, 24, TrueColor, visinfo )) { + printf("Couldn't get 24-bit TrueColor visual!\n"); + exit(1); + } +*/ + if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) { + printf("Couldn't get 8-bit PseudoColor visual!\n"); + exit(1); + } + + cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone ); + Black = Red = Green = Blue = 0; + } + else { + /* Open color index window */ + + if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) { + printf("Couldn't get 8-bit PseudoColor visual\n"); + exit(1); + } + + cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone ); + + /* Allocate colors */ + xcolor.red = 0x0; + xcolor.green = 0x0; + xcolor.blue = 0x0; + xcolor.flags = DoRed | DoGreen | DoBlue; + if (!XAllocColor( dpy, cmap, &xcolor )) { + printf("Couldn't allocate black!\n"); + exit(1); + } + Black = xcolor.pixel; + + xcolor.red = 0xffff; + xcolor.green = 0x0; + xcolor.blue = 0x0; + xcolor.flags = DoRed | DoGreen | DoBlue; + if (!XAllocColor( dpy, cmap, &xcolor )) { + printf("Couldn't allocate red!\n"); + exit(1); + } + Red = xcolor.pixel; + + xcolor.red = 0x0; + xcolor.green = 0xffff; + xcolor.blue = 0x0; + xcolor.flags = DoRed | DoGreen | DoBlue; + if (!XAllocColor( dpy, cmap, &xcolor )) { + printf("Couldn't allocate green!\n"); + exit(1); + } + Green = xcolor.pixel; + + xcolor.red = 0x0; + xcolor.green = 0x0; + xcolor.blue = 0xffff; + xcolor.flags = DoRed | DoGreen | DoBlue; + if (!XAllocColor( dpy, cmap, &xcolor )) { + printf("Couldn't allocate blue!\n"); + exit(1); + } + Blue = xcolor.pixel; + } + + /* set window attributes */ + attr.colormap = cmap; + attr.event_mask = ExposureMask | StructureNotifyMask; + attr.border_pixel = BlackPixel( dpy, scr ); + attr.background_pixel = BlackPixel( dpy, scr ); + attr_flags = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel; + + /* Create the window */ + win = XCreateWindow( dpy, root, x,y, width, height, 0, + visinfo->depth, InputOutput, + visinfo->visual, + attr_flags, &attr); + if (!win) { + printf("Couldn't open window!\n"); + exit(1); + } + + XStringListToTextProperty(&title, 1, &tp); + sh.flags = USPosition | USSize; + XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0); + XMapWindow(dpy, win); + while (1) { + XNextEvent( dpy, &e ); + if (e.type == MapNotify && e.xmap.window == win) { + break; + } + } + + + /* + * Now do the special Mesa/Xlib stuff! + */ + + visual = XMesaCreateVisual( dpy, visinfo, + (GLboolean) color_flag, + GL_FALSE, /* alpha_flag */ + GL_FALSE, /* db_flag */ + GL_FALSE, /* stereo flag */ + GL_FALSE, /* ximage_flag */ + 0, /* depth size */ + 0, /* stencil size */ + 0, /* accum_size */ + 0 /* level */ + ); + if (!visual) { + printf("Couldn't create Mesa/X visual!\n"); + exit(1); + } + + /* Create a Mesa rendering context */ + context = XMesaCreateContext( visual, + NULL /* share_list */ + ); + if (!context) { + printf("Couldn't create Mesa/X context!\n"); + exit(1); + } + + buffer = XMesaCreateWindowBuffer( visual, win ); + if (!buffer) { + printf("Couldn't create Mesa/X buffer!\n"); + exit(1); + } + + + XMesaMakeCurrent( context, buffer ); + + /* Ready to render! */ +} + + + +static void draw_cube( void ) +{ + /* X faces */ + glIndexi( Red ); + glColor3f( 1.0, 0.0, 0.0 ); + glBegin( GL_POLYGON ); + glVertex3f( 1.0, 1.0, 1.0 ); + glVertex3f( 1.0, -1.0, 1.0 ); + glVertex3f( 1.0, -1.0, -1.0 ); + glVertex3f( 1.0, 1.0, -1.0 ); + glEnd(); + + glBegin( GL_POLYGON ); + glVertex3f( -1.0, 1.0, 1.0 ); + glVertex3f( -1.0, 1.0, -1.0 ); + glVertex3f( -1.0, -1.0, -1.0 ); + glVertex3f( -1.0, -1.0, 1.0 ); + glEnd(); + + /* Y faces */ + glIndexi( Green ); + glColor3f( 0.0, 1.0, 0.0 ); + glBegin( GL_POLYGON ); + glVertex3f( 1.0, 1.0, 1.0 ); + glVertex3f( 1.0, 1.0, -1.0 ); + glVertex3f( -1.0, 1.0, -1.0 ); + glVertex3f( -1.0, 1.0, 1.0 ); + glEnd(); + + glBegin( GL_POLYGON ); + glVertex3f( 1.0, -1.0, 1.0 ); + glVertex3f( -1.0, -1.0, 1.0 ); + glVertex3f( -1.0, -1.0, -1.0 ); + glVertex3f( 1.0, -1.0, -1.0 ); + glEnd(); + + /* Z faces */ + glIndexi( Blue ); + glColor3f( 0.0, 0.0, 1.0 ); + glBegin( GL_POLYGON ); + glVertex3f( 1.0, 1.0, 1.0 ); + glVertex3f( -1.0, 1.0, 1.0 ); + glVertex3f( -1.0, -1.0, 1.0 ); + glVertex3f( 1.0, -1.0, 1.0 ); + glEnd(); + + glBegin( GL_POLYGON ); + glVertex3f( 1.0, 1.0, -1.0 ); + glVertex3f( 1.0,-1.0, -1.0 ); + glVertex3f( -1.0,-1.0, -1.0 ); + glVertex3f( -1.0, 1.0, -1.0 ); + glEnd(); +} + + + + +static void display_loop( void ) +{ + GLfloat xrot, yrot, zrot; + + xrot = yrot = zrot = 0.0; + + glClearColor( 0.0, 0.0, 0.0, 0.0 ); + glClearIndex( Black ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 10.0 ); + glTranslatef( 0.0, 0.0, -5.0 ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glCullFace( GL_BACK ); + glEnable( GL_CULL_FACE ); + + glShadeModel( GL_FLAT ); + + while (1) { + glClear( GL_COLOR_BUFFER_BIT ); + glPushMatrix(); + glRotatef( xrot, 1.0, 0.0, 0.0 ); + glRotatef( yrot, 0.0, 1.0, 0.0 ); + glRotatef( zrot, 0.0, 0.0, 1.0 ); + + draw_cube(); + + glPopMatrix(); + glFinish(); + + xrot += 10.0; + yrot += 7.0; + zrot -= 3.0; + } + +} + + + + +int main( int argc, char *argv[] ) +{ + int mode = 0; + + if (argc >= 2) + { + if (strcmp(argv[1],"-ci")==0) + mode = 0; + else if (strcmp(argv[1],"-rgb")==0) + mode = 1; + else + { + printf("Bad flag: %s\n", argv[1]); + printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n"); + exit(1); + } + } + else + { + printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n"); + printf("Defaulting to 8-bit color index\n"); + } + + make_window( argv[0], mode ); + + display_loop(); + return 0; +} + diff --git a/progs/xdemos/xfont.c b/progs/xdemos/xfont.c new file mode 100644 index 0000000000..31bfb4bf94 --- /dev/null +++ b/progs/xdemos/xfont.c @@ -0,0 +1,148 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* + * xfont.c + * Draws some text in a bitmapped font. Uses glBitmap() + * and other pixel routines. Also demonstrates use of + * display lists. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "glaux.h" + +GLuint base; + +void makeRasterFont(void) +{ + XFontStruct *fontInfo; + Font id; + unsigned int first, last; + Display *xdisplay; + + xdisplay = auxXDisplay (); + fontInfo = XLoadQueryFont(xdisplay, + "-adobe-helvetica-medium-r-normal--17-120-100-100-p-88-iso8859-1"); + if (fontInfo == NULL) { + printf ("no font found\n"); + exit (0); + } + + id = fontInfo->fid; + first = fontInfo->min_char_or_byte2; + last = fontInfo->max_char_or_byte2; + + base = glGenLists((GLuint) last+1); + if (base == 0) { + printf ("out of display lists\n"); + exit (0); + } + glXUseXFont(id, first, last-first+1, base+first); +/* *height = fontInfo->ascent + fontInfo->descent; + *width = fontInfo->max_bounds.width; */ +} + +void printString(char *s) +{ + glPushAttrib (GL_LIST_BIT); + glListBase(base); + glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s); + glPopAttrib (); +} + +void myinit (void) +{ + makeRasterFont (); + glShadeModel (GL_FLAT); +} + +void display(void) +{ + GLfloat white[3] = { 1.0, 1.0, 1.0 }; + int i, j; + char teststring[33]; + + glClear(GL_COLOR_BUFFER_BIT); + glColor3fv(white); + for (i = 32; i < 127; i += 32) { + glRasterPos2i(20, 200 - 18*(GLint) i/32); + for (j = 0; j < 32; j++) + teststring[j] = (char) (i+j); + teststring[32] = 0; + printString(teststring); + } + glRasterPos2i(20, 100); + printString("The quick brown fox jumps"); + glRasterPos2i(20, 82); + printString("over a lazy dog."); + glFlush (); +} + +void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho (0.0, (GLfloat) w, 0.0, (GLfloat) h, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + auxInitDisplayMode (AUX_SINGLE | AUX_RGB); + auxInitPosition (0, 0, 500, 500); + if (!auxInitWindow (argv[0])) + auxQuit(); + auxReshapeFunc (myReshape); + myinit (); + auxMainLoop(display); + return 0; +} + + + + -- cgit v1.2.3