diff options
Diffstat (limited to 'progs')
265 files changed, 81720 insertions, 0 deletions
diff --git a/progs/Makefile b/progs/Makefile new file mode 100644 index 00000000000..d5ec17d43e5 --- /dev/null +++ b/progs/Makefile @@ -0,0 +1,32 @@ +# progs/Makefile + +TOP = .. + +include $(TOP)/configs/current + +SUBDIRS = $(PROGRAM_DIRS) + + +default: message subdirs + + +message: + @echo "Making programs for" $(CONFIG_NAME) + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir ; $(MAKE)) || exit 1 ; \ + fi \ + done + +# Dummy install target +install: + +clean: + @for dir in $(SUBDIRS) tests ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir ; $(MAKE) clean) ; \ + fi \ + done diff --git a/progs/beos/GLInfo.cpp b/progs/beos/GLInfo.cpp new file mode 100644 index 00000000000..cfa8c83af82 --- /dev/null +++ b/progs/beos/GLInfo.cpp @@ -0,0 +1,151 @@ +// Small app to display GL infos + +#include <stdio.h> +#include <string.h> + +#include <Application.h> +#include <Window.h> +#include <OutlineListView.h> +#include <ScrollView.h> +#include <GLView.h> + +#include <String.h> + +#include <GL/gl.h> +#include <GL/glu.h> + +#define GLUT_INFO 1 +#ifdef GLUT_INFO + #include <GL/glut.h> +#endif + + +class GLInfoWindow : public BWindow +{ +public: + GLInfoWindow(BRect frame); + virtual bool QuitRequested() { be_app->PostMessage(B_QUIT_REQUESTED); return true; } + +private: + BGLView *gl; + BOutlineListView *list; + BScrollView *scroller; +}; + + +class GLInfoApp : public BApplication +{ +public: + GLInfoApp(); +private: + GLInfoWindow *window; +}; + + +GLInfoApp::GLInfoApp() + : BApplication("application/x-vnd.OBOS-GLInfo") +{ + window = new GLInfoWindow(BRect(50, 50, 350, 350)); +} + +GLInfoWindow::GLInfoWindow(BRect frame) + : BWindow(frame, "OpenGL Info", B_TITLED_WINDOW, 0) +{ + BRect r = Bounds(); + char *s; + BString l; + + // Add a outline list view + r.right -= B_V_SCROLL_BAR_WIDTH; + list = new BOutlineListView(r, "GLInfoList", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES); + scroller = new BScrollView("GLInfoListScroller", list, B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_FRAME_EVENTS, false, true); + + gl = new BGLView(r, "opengl", B_FOLLOW_ALL_SIDES, 0, BGL_RGB | BGL_DOUBLE); + gl->Hide(); + AddChild(gl); + AddChild(scroller); + + Show(); + + LockLooper(); + + // gl->LockGL(); + + list->AddItem(new BStringItem("OpenGL", 0)); + + s = (char *) glGetString(GL_VENDOR); + if (s) { + l = ""; l << "Vendor Name: " << s; + list->AddItem(new BStringItem(l.String(), 1)); + } + + s = (char *) glGetString(GL_VERSION); + if (s) { + l = ""; l << "Version: " << s; + list->AddItem(new BStringItem(l.String(), 1)); + } + + s = (char *) glGetString(GL_RENDERER); + if (s) { + l = ""; l << "Renderer Name: " << s; + list->AddItem(new BStringItem(l.String(), 1)); + } + + s = (char *) glGetString(GL_EXTENSIONS); + if (s) { + list->AddItem(new BStringItem("Extensions", 1)); + while (*s) { + char extname[255]; + int n = strcspn(s, " "); + strncpy(extname, s, n); + extname[n] = 0; + list->AddItem(new BStringItem(extname, 2)); + if (! s[n]) + break; + s += (n + 1); // next ! + } + } + + list->AddItem(new BStringItem("GLU", 0)); + s = (char *) gluGetString(GLU_VERSION); + if (s) { + l = ""; l << "Version: " << s; + list->AddItem(new BStringItem(l.String(), 1)); + } + + s = (char *) gluGetString(GLU_EXTENSIONS); + if (s) { + list->AddItem(new BStringItem("Extensions", 1)); + while (*s) { + char extname[255]; + int n = strcspn(s, " "); + strncpy(extname, s, n); + extname[n] = 0; + list->AddItem(new BStringItem(extname, 2)); + if (! s[n]) + break; + s += (n + 1); // next ! + } + } + +#ifdef GLUT_INFO + list->AddItem(new BStringItem("GLUT", 0)); + l = "API version: "; l << GLUT_API_VERSION; + list->AddItem(new BStringItem(l.String(), 1)); +#endif + + // gl->UnlockGL(); + + UnlockLooper(); +} + + + +int main(int argc, char *argv[]) +{ + GLInfoApp *app = new GLInfoApp; + app->Run(); + delete app; + return 0; +} diff --git a/progs/beos/Makefile b/progs/beos/Makefile new file mode 100644 index 00000000000..45782fb3cf7 --- /dev/null +++ b/progs/beos/Makefile @@ -0,0 +1,33 @@ +# progs/beos/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +# Makefile for BeOS demos + +# Written by Brian Paul +# This file is in the public domain. +# +# Modified by Philippe Houdoin + +LDFLAGS += -soname=_APP_ $(APP_LIB_DEPS) + +INCLUDES = -I. -I- -I../../include + +default: demo sample GLInfo + +clean: + rm -f demo sample GLInfo + rm -f *.o + +demo: demo.o + $(LD) demo.o $(LDFLAGS) -o $@ + +sample: sample.o + $(LD) sample.o $(LDFLAGS) -o $@ + +GTLInfo: GLInfo.o + $(LD) GLInfo.o $(INCLUDES) $(LDFLAGS) -o $@ + +.cpp.o: + $(CC) -c $< $(INCLUDES) $(CFLAGS) -o $@ diff --git a/progs/beos/demo.cpp b/progs/beos/demo.cpp new file mode 100644 index 00000000000..6b0b9576d66 --- /dev/null +++ b/progs/beos/demo.cpp @@ -0,0 +1,147 @@ +// $Id: demo.cpp,v 1.2 2004/08/14 09:59:16 phoudoin Exp $ + +// Simple BeOS GLView demo +// Written by Brian Paul +// Changes by Philippe Houdoin +// This file is in the public domain. + + + +#include <stdio.h> +#include <Application.h> +#include <Window.h> +#include <GLView.h> + +class MyGL : public BGLView +{ +public: + MyGL(BRect rect, char *name, ulong options); + + virtual void AttachedToWindow(); + virtual void Pulse(); + virtual void FrameResized(float w, float h); + +private: + void Render(); + void Reshape(float w, float h); + float mAngle; +}; + + +class MyWindow : public BWindow +{ +public: + MyWindow(BRect frame); + virtual bool QuitRequested(); +}; + + +MyWindow::MyWindow(BRect frame) + : BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE) +{ + // Make OpenGL view and put it in the window + BRect r = Bounds(); + r.InsetBy(5, 5); + + MyGL *gl = new MyGL(r, "GL", BGL_RGB | BGL_DOUBLE); + AddChild(gl); + SetPulseRate(1000000 / 30); +} + +bool MyWindow::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + + +MyGL::MyGL(BRect rect, char *name, ulong options) + : BGLView(rect, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED, options) +{ + mAngle = 0.0; +} + + +void MyGL::AttachedToWindow() +{ + BGLView::AttachedToWindow(); + + LockGL(); + glClearColor(0.7, 0.7, 0, 0); + Reshape(Bounds().Width(), Bounds().Height()); + UnlockGL(); +} + + +void MyGL::FrameResized(float w, float h) +{ + BGLView::FrameResized(w, h); + + LockGL(); + Reshape(w, h); + UnlockGL(); + + Render(); +} + + +void MyGL::Pulse() +{ + mAngle += 1.0; + Render(); +} + + +void MyGL::Render() +{ + LockGL(); + + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + + glRotated(mAngle, 0, 0, 1); + glColor3f(0, 0, 1); + + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + + glPopMatrix(); + + SwapBuffers(); + + UnlockGL(); +} + + +void MyGL::Reshape(float w, float 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); +} + + +int main(int argc, char *argv[]) +{ + BApplication *app = new BApplication("application/demo"); + + // make top-level window + MyWindow *win = new MyWindow(BRect(100, 100, 500, 500)); + win->Show(); + + app->Run(); + + delete app; + + return 0; +} diff --git a/progs/beos/sample.cpp b/progs/beos/sample.cpp new file mode 100644 index 00000000000..a86a118747f --- /dev/null +++ b/progs/beos/sample.cpp @@ -0,0 +1,225 @@ +// sample BGLView app from the Be Book + + +#include <stdio.h> +#include <Application.h> +#include <Window.h> +#include <GLView.h> + + +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() { be_app->PostMessage(B_QUIT_REQUESTED); 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) +{ + BGLView::FrameResized(newWidth, newHeight); + + LockGL(); + + 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 = 6; +} + + + +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); + } +*/ + + glDisable(GL_POINT_SMOOTH); + + + glPushMatrix(); + + glPointSize(pointsize); // Set size for point + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0,0,1); // Rotate right 5 degrees + + if (use_smooth_mode) { + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + } else { + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glColor3f(1.0, 1.0, 0.0); // Set color for line + glBegin(GL_LINE_STRIP); // And create the line + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glDisable(GL_POINT_SMOOTH); + glDisable(GL_BLEND); + + 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 b/progs/demos/Makefile new file mode 100644 index 00000000000..43d0f17c85f --- /dev/null +++ b/progs/demos/Makefile @@ -0,0 +1,145 @@ +# progs/demos/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCDIR = $(TOP)/include + +OSMESA_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa -lGLU -lGL $(APP_LIB_DEPS) + +OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa16 -lGLU -lGL $(APP_LIB_DEPS) + +OSMESA32_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa32 -lGLU -lGL $(APP_LIB_DEPS) + +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) + +PROGS = \ + arbfplight \ + arbfslight \ + arbocclude \ + bounce \ + clearspd \ + cubemap \ + drawpix \ + engine \ + fire \ + fogcoord \ + fplight \ + gamma \ + gearbox \ + gears \ + geartrain \ + glinfo \ + gloss \ + glslnoise \ + gltestperf \ + glutfx \ + isosurf \ + ipers \ + lodbias \ + morph3d \ + multiarb \ + paltex \ + pointblast \ + ray \ + readpix \ + reflect \ + renormal \ + shadowtex \ + singlebuffer \ + spectex \ + spriteblast \ + stex3d \ + teapot \ + terrain \ + tessdemo \ + texcyl \ + texdown \ + texenv \ + texobj \ + trispd \ + tunnel \ + tunnel2 \ + vao_demo \ + winpos + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + + +# make executable from .c file: +.c: $(LIB_DEP) readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + +$(PROGS): readtex.o + +readtex.c: $(TOP)/progs/util/readtex.c + cp $< . + +readtex.h: $(TOP)/progs/util/readtex.h + cp $< . + +readtex.o: readtex.c readtex.h + $(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c + + +showbuffer.c: $(TOP)/progs/util/showbuffer.c + cp $< . + +showbuffer.h: $(TOP)/progs/util/showbuffer.h + cp $< . + +showbuffer.o: showbuffer.c showbuffer.h + $(CC) -c -I$(INCDIR) $(CFLAGS) showbuffer.c + + +trackball.c: $(TOP)/progs/util/trackball.c + cp $< . + +trackball.h: $(TOP)/progs/util/trackball.h + cp $< . + +trackball.o: trackball.c trackball.h + $(CC) -c -I$(INCDIR) $(CFLAGS) trackball.c + + +reflect: reflect.o showbuffer.o readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) reflect.o showbuffer.o readtex.o $(APP_LIB_DEPS) -o $@ + +reflect.o: reflect.c showbuffer.h + $(CC) -c -I$(INCDIR) $(CFLAGS) reflect.c + + +shadowtex: shadowtex.o showbuffer.o + $(CC) -I$(INCDIR) $(CFLAGS) shadowtex.o showbuffer.o $(APP_LIB_DEPS) -o $@ + +shadowtex.o: shadowtex.c showbuffer.h + $(CC) -c -I$(INCDIR) $(CFLAGS) shadowtex.c + + +gloss: gloss.o trackball.o readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) gloss.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@ + +gloss.o: gloss.c trackball.h + $(CC) -c -I$(INCDIR) $(CFLAGS) gloss.c + + +engine: engine.o trackball.o readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) engine.o trackball.o readtex.o $(APP_LIB_DEPS) -o $@ + +engine.o: engine.c trackball.h + $(CC) -c -I$(INCDIR) $(CFLAGS) engine.c + + +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + -rm -f readtex.[ch] showbuffer.[ch] diff --git a/progs/demos/Makefile.cygnus b/progs/demos/Makefile.cygnus new file mode 100644 index 00000000000..0efc1ab0c99 --- /dev/null +++ b/progs/demos/Makefile.cygnus @@ -0,0 +1,87 @@ + +# Mesa 3-D graphics library +# Version: 3.3 +# Copyright (C) 1995-2000 Brian Paul + + +# Makefile for demo programs for cygnus +# Stephane Rehel ([email protected]) April 13 1997 + + + +##### 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 = bounce \ + clearspd \ + cubemap \ + drawpix \ + fire \ + gamma \ + gears \ + geartrain \ + glinfo \ + gloss \ + gltestperf \ + glutfx \ + isosurf \ + ipers \ + lodbias \ + morph3d \ + multiarb \ + occlude \ + osdemo \ + paltex \ + pixeltex \ + pointblast \ + ray \ + readpix \ + reflect \ + renormal \ + spectex \ + stex3d \ + teapot \ + terrain \ + tessdemo \ + texcyl \ + texdown \ + texenv \ + texobj \ + trispd \ + tunnel \ + tunnel2 \ + winpos + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) -I../util $(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/Makefile.win b/progs/demos/Makefile.win new file mode 100644 index 00000000000..4ac32361b26 --- /dev/null +++ b/progs/demos/Makefile.win @@ -0,0 +1,118 @@ + +# Mesa 3-D graphics library +# Version: 6.5 +# Copyright (C) 1995-2006 Brian Paul + +# Makefile for GLUT-based demo programs for Windows + +# Build the Mesa and GLUT libraries by using the Visual Studio +# Workspaces in this distribution before running this Makefile. + +# Invocation: nmake -f Makefile.win + +NODEBUG=1 +!include <win32.mak> + +##### MACROS ##### + +TOP = ..\.. +INCDIR = ..\..\include +LIBDIR = ..\..\lib +LIBS = GLUT32.LIB OPENGL32.LIB + +all: OPENGL32.DLL GLU32.DLL GLUT32.DLL \ + readtex.h readtex.c showbuffer.h showbuffer.c \ + arbfplight.exe arbfslight.exe arbocclude.exe bounce.exe \ + clearspd.exe cubemap.exe drawpix.exe fire.exe fogcoord.exe \ + fplight.exe gamma.exe gearbox.exe \ + gears.exe geartrain.exe gloss.exe \ + glinfo.exe glslnoise.exe \ + gltestperf.exe glutfx.exe ipers.exe isosurf.exe lodbias.exe \ + morph3d.exe multiarb.exe occlude.exe paltex.exe pointblast.exe \ + ray.exe readpix.exe reflect.exe renormal.exe \ + shadowtex.exe singlebuffer.exe spectex.exe spriteblast.exe \ + stex3d.exe teapot.exe terrain.exe tessdemo.exe texcyl.exe \ + texdown.exe texenv.exe texobj.exe trispd.exe tunnel.exe tunnel2.exe \ + winpos.exe + +arbfplight.exe: arbfplight.obj +arbfslight.exe: arbfslight.obj +arbocclude.exe: arbocclude.obj +bounce.exe: bounce.obj +clearspd.exe: clearspd.obj +cubemap.exe: cubemap.obj readtex.obj +drawpix.exe: drawpix.obj readtex.obj +fire.exe: fire.obj readtex.obj +fogcoord.exe: fogcoord.obj readtex.obj +fplight.exe: fplight.obj +gamma.exe: gamma.obj +gearbox.exe: gearbox.obj +gears.exe: gears.obj +geartrain.exe: geartrain.obj +gloss.exe: gloss.obj readtex.obj +glinfo.exe: glinfo.obj +glslnoise.exe: glslnoise.obj +gltestperf.exe: gltestperf.obj +glutfx.exe: glutfx.obj +ipers.exe: ipers.obj readtex.obj +isosurf.exe: isosurf.obj readtex.obj +lodbias.exe: lodbias.obj readtex.obj +morph3d.exe: morph3d.obj +multiarb.exe: multiarb.obj readtex.obj +occlude.exe: occlude.obj +paltex.exe: paltex.obj +pointblast.exe: pointblast.obj +ray.exe: ray.obj +readpix.exe: readpix.obj readtex.obj +reflect.exe: reflect.obj readtex.obj showbuffer.obj +renormal.exe: renormal.obj +shadowtex.exe: shadowtex.obj showbuffer.obj +singlebuffer.exe: singlebuffer.obj +spectex.exe: spectex.obj +spriteblast.exe: spriteblast.obj +stex3d.exe: stex3d.obj +teapot.exe: teapot.obj readtex.obj +terrain.exe: terrain.obj +tessdemo.exe: tessdemo.obj +texcyl.exe: texcyl.obj readtex.obj +texdown.exe: texdown.obj +texenv.exe: texenv.obj +texobj.exe: texobj.obj +trispd.exe: trispd.obj +tunnel.exe: tunnel.obj readtex.obj +tunnel2.exe: tunnel2.obj readtex.obj +winpos.exe: winpos.obj readtex.obj + + +OPENGL32.DLL: $(LIBDIR)\OPENGL32.DLL + copy $? . + +GLU32.DLL: $(LIBDIR)\GLU32.DLL + copy $? . + +GLUT32.DLL: $(LIBDIR)\GLUT32.DLL + copy $? . + +readtex.c: $(TOP)\progs\util\readtex.c + copy $** . + +readtex.h: $(TOP)\progs\util\readtex.h + copy $** . + +showbuffer.c: $(TOP)\progs\util\showbuffer.c + copy $** . + +showbuffer.h: $(TOP)\progs\util\showbuffer.h + copy $** . + +.obj.exe: + $(link) $(ldebug) -out:$@ $** /LIBPATH:$(LIBDIR) $(LIBS) + +.c.obj: + $(cc) $(cdebug) $(cflags) $(cvars) /I$(INCDIR) $*.c + +clean:: + del *.obj *.exe readtex.* showbuffer.* + +clobber:: + diff --git a/progs/demos/README b/progs/demos/README new file mode 100644 index 00000000000..a3d0c18bb97 --- /dev/null +++ b/progs/demos/README @@ -0,0 +1,230 @@ +INTRODUCTION +------------ + +This directory is usually included in the Mesa demos distribution or +in the GLUT distribution. + +I have written the demos included in this directory mainly for showing +the capabilities of the Mesa library when using the Voodoo driver. +However all the demos are written using the GLUT and OpenGL so they +work with any GLUT/OpenGL platform (tested: Linux+Mesa+Voodoo driver, +Linux+Mesa+X11 driver, Win95+Mesa+Voodoo driver and SGI Onyx IR thanks +to Mark Kilgard). + +All the demos make an heavy use of texture mapping, blending, etc. so +you _need_ some kind of hardware support for the OpenGL otherwise they +will run at ~1fps. You need also a OpenGL 1.1 compliant library. + +You can find some screenshot of these demos at +http://www-hmw.caribel.pisa.it/fxmesa/fxdemos.hmtl + +Write me if you find some bug in the demos. + +David Bucciarelli ([email protected]) + +Humanware s.r.l. +Via XXIV Maggio 62 +Pisa, Italy +Tel./Fax +39-50-554108 +email: [email protected] +www: www-hmw.caribel.pisa.it + + +A BRIEF DESCRIPTION OF THE DEMOS +-------------------------------- + + +IPERS +----- + +Sources: ipers.c image.c + +A nice spinning fractal object. + + +RAY +--- + +Sources: ray.c + +I'm using ray tracing to dynamically generate texture maps with +specular, diffuse, shadows, and mirror colors. Each frame the texture +maps of the plane and of the sphere are partially updated. With this +technique you can obtain true mirrors, shadows, specular highlights, +bump mapping, etc. in realtime. This demo is really CPU intensive +(~25fps on a PentiumII@300MHz with a Pure3D). Support on-the-fly +switching between fullscreen and in-window rendering under Linux/Mesa +(start your X server in 16 bpp mode and press the spacebar). + + +TUNNEL +------ + +Sources: tunnel.c image.c sources.c +Data: bw.rgb tile.rgb + +The model was designed and prelighted with Alias|Wavefront +PowerAnimator V8. Triangle strips were built with a tool written by me +and then statically included in the sources. This demo doesn't +require the ZBuffer and use antialiased polygons. Support on-the-fly +switching between fullscreen and in-window rendering under Linux/Mesa +(start your X server in 16 bpp mode and press the spacebar). + + +TUNNEL2 +------ + +Sources: tunnel2.c image.c sources.c +Data: bw.rgb tile.rgb + +The some tunnel demo but with two output channels. A nice +example of the Mesa/Voodoo support for multiple boards in +the some PC. + + +TEAPOT +------ + +Sources: teapot.c image.c dteapot.c shadow.c +Data: bw.rgb tile.rgb + +The shadow is drawn projecting the teapot geometry over the plane. All +other light effects are drawn using the standard OpenGL capabilities. +Support on-the-fly switching between fullscreen and in-window +rendering under Linux/Mesa (start your X server in 16 bpp mode and +press the spacebar). + + +FIRE +---- + +Sources: fire.c image.c +Data: s128.rgb tree2.rgb + +The demo use a small particle system to draw some nice visual effect. +You can interactively change many parameters of the particle system +and you can choose the number of particles at the startup ('fire +4000'). This demo should be called fountain. Support on-the-fly +switching between fullscreen and in-window rendering under Linux/Mesa +(start your X server in 16 bpp mode and press the spacebar). + + +TERRAIN +------- + +Sources: mesaland.c + +This demo is base on another demo written by Mikael SkiZoWalker. I +have added the capabilities to freely fly around, view culling and +some nice color. Support on-the-fly switching between fullscreen and +in-window rendering under Linux/Mesa (start your X server in 16 bpp +mode and press the spacebar). + + +GLTEST +------ + +Sources: gltest.c + +This is a simple benchmark suite that I'm using in the development of +the Mesa/Voodoo driver. Type 'gltest >my.res' and you will get some +data about the performances of your OpenGL. Follow the results with my +PC (Linux+Mesa-2.6+PentiumII@300MHz+Pure3D): + +Simple Points +587900.080674 Pnts/sec + +Smooth Lines +SIZE=480 => 39007.426183 Lins/sec +SIZE=250 => 74575.016485 Lins/sec +SIZE=100 => 179734.882409 Lins/sec +SIZE=050 => 183987.795297 Lins/sec +SIZE=025 => 183820.086309 Lins/sec + + +ZSmooth Triangles +SIZE=480 => 784.954997 Tris/sec +SIZE=250 => 2862.325889 Tris/sec +SIZE=100 => 17779.492938 Tris/sec +SIZE=050 => 159339.829844 Tris/sec +SIZE=025 => 428602.984008 Tris/sec + + +ZSmooth Tex Blend Triangles +SIZE=480 => 784.473931 Tris/sec +SIZE=250 => 2853.781513 Tris/sec +SIZE=100 => 17598.252146 Tris/sec +SIZE=050 => 152632.578337 Tris/sec +SIZE=025 => 377584.760048 Tris/sec + + +ZSmooth Tex Blend TMesh Triangles +SIZE=400 => 563.900695 Tris/sec, MPixel Fill/sec: 45.112056 +SIZE=250 => 1449.777225 Tris/sec, MPixel Fill/sec: 45.305538 +SIZE=100 => 8702.869121 Tris/sec, MPixel Fill/sec: 43.514346 +SIZE=050 => 31896.867466 Tris/sec, MPixel Fill/sec: 39.871084 +SIZE=025 => 114037.262894 Tris/sec, MPixel Fill/sec: 35.636645 +SIZE=010 => 220494.235839 Tris/sec, MPixel Fill/sec: 11.024712 +SIZE=005 => 225615.506651 Tris/sec, MPixel Fill/sec: 2.820194 +SIZE=002 => 225607.681439 Tris/sec, MPixel Fill/sec: 0.451215 + + +Color/Depth Buffer Clears +295.042474 Clrs/sec, MPixel Fill/sec: 90.553256 + + +Follow the results with my +PC (Linux+Mesa-3.0beta5+PentiumII@300MHz+Voodoo2): + + +Simple Points +1620113.525130 Pnts/sec + +Smooth Lines +SIZE=480 => 73841.166065 Lins/sec +SIZE=250 => 140794.035316 Lins/sec +SIZE=100 => 344185.242157 Lins/sec +SIZE=050 => 420399.008289 Lins/sec +SIZE=025 => 420261.389773 Lins/sec + + +ZSmooth Triangles +SIZE=480 => 1434.668506 Tris/sec +SIZE=250 => 5228.449614 Tris/sec +SIZE=100 => 46603.815842 Tris/sec +SIZE=050 => 325757.045961 Tris/sec +SIZE=025 => 589022.403336 Tris/sec + + +ZSmooth Tex Blend Triangles +SIZE=480 => 1414.900041 Tris/sec +SIZE=250 => 5006.055235 Tris/sec +SIZE=100 => 43602.252031 Tris/sec +SIZE=050 => 303497.092692 Tris/sec +SIZE=025 => 517087.428669 Tris/sec + + +ZSmooth Tex Blend TMesh Triangles +SIZE=400 => 1023.273112 Tris/sec, MPixel Fill/sec: 81.861849 +SIZE=250 => 2595.692121 Tris/sec, MPixel Fill/sec: 81.115379 +SIZE=100 => 15788.198912 Tris/sec, MPixel Fill/sec: 78.940995 +SIZE=050 => 58784.121300 Tris/sec, MPixel Fill/sec: 73.480152 +SIZE=025 => 244233.873481 Tris/sec, MPixel Fill/sec: 76.323085 +SIZE=010 => 474995.004191 Tris/sec, MPixel Fill/sec: 23.749750 +SIZE=005 => 475124.354163 Tris/sec, MPixel Fill/sec: 5.939054 +SIZE=002 => 474959.089503 Tris/sec, MPixel Fill/sec: 0.949918 + + +Color/Depth Buffer Clears +478.654830 Clrs/sec, MPixel Fill/sec: 146.906826 + + +PALTEX and GLBPALTX +------------------- + +Sources: paltex.c and glbpaltx.c + +The PALTEX example was written by Brian Paul and it shows the +capabilities of the GL_EXT_paletted_texture extension. I have written +the other example in order to show the capabilities of the +gl3DfxSetPaletteEXT() (it used only by GLQuake and Quake2). diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c new file mode 100644 index 00000000000..d9c564fbe56 --- /dev/null +++ b/progs/demos/arbfplight.c @@ -0,0 +1,395 @@ +/* + * Use GL_ARB_fragment_program and GL_ARB_vertex_program to implement + * simple per-pixel lighting. + * + * Brian Paul + * 17 April 2003 + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +static GLfloat Diffuse[4] = { 0.5, 0.5, 1.0, 1.0 }; +static GLfloat Specular[4] = { 0.8, 0.8, 0.8, 1.0 }; +static GLfloat LightPos[4] = { 0.0, 10.0, 20.0, 1.0 }; +static GLfloat Delta = 1.0; + +static GLuint FragProg; +static GLuint VertProg; +static GLboolean Anim = GL_TRUE; +static GLboolean Wire = GL_FALSE; +static GLboolean PixelLight = GL_TRUE; + +static GLint T0 = 0; +static GLint Frames = 0; + +static GLfloat Xrot = 0, Yrot = 0; + +static PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB_func; +static PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB_func; +static PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB_func; +static PFNGLGENPROGRAMSARBPROC glGenProgramsARB_func; +static PFNGLPROGRAMSTRINGARBPROC glProgramStringARB_func; +static PFNGLBINDPROGRAMARBPROC glBindProgramARB_func; +static PFNGLISPROGRAMARBPROC glIsProgramARB_func; +static PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB_func; + +/* These must match the indexes used in the fragment program */ +#define LIGHTPOS 3 + +/* Set to one to test ARB_fog_linear program option */ +#define DO_FRAGMENT_FOG 0 + + +static void Redisplay( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + if (PixelLight) { + glProgramLocalParameter4fvARB_func(GL_FRAGMENT_PROGRAM_ARB, + LIGHTPOS, LightPos); + glEnable(GL_FRAGMENT_PROGRAM_ARB); + glEnable(GL_VERTEX_PROGRAM_ARB); + glDisable(GL_LIGHTING); + } + else { + glLightfv(GL_LIGHT0, GL_POSITION, LightPos); + glDisable(GL_FRAGMENT_PROGRAM_ARB); + glDisable(GL_VERTEX_PROGRAM_ARB); + glEnable(GL_LIGHTING); + } + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glutSolidSphere(2.0, 10, 5); + glPopMatrix(); + + glutSwapBuffers(); + + Frames++; + + if (Anim) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + } + } +} + + +static void Idle(void) +{ + LightPos[0] += Delta; + if (LightPos[0] > 25.0) + Delta = -1.0; + else if (LightPos[0] <- 25.0) + Delta = 1.0; + glutPostRedisplay(); +} + + +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 ' ': + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'x': + LightPos[0] -= 1.0; + break; + case 'X': + LightPos[0] += 1.0; + break; + case 'w': + Wire = !Wire; + if (Wire) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + break; + case 'p': + PixelLight = !PixelLight; + if (PixelLight) { + printf("Per-pixel lighting\n"); + } + else { + printf("Conventional lighting\n"); + } + break; + case 27: + glDeleteProgramsARB_func(1, &VertProg); + glDeleteProgramsARB_func(1, &FragProg); + 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(); +} + + +/* A helper for finding errors in program strings */ +static int FindLine( const char *program, int position ) +{ + int i, line = 1; + for (i = 0; i < position; i++) { + if (program[i] == '\n') + line++; + } + return line; +} + + +static void Init( void ) +{ + GLint errorPos; + + /* Yes, this could be expressed more efficiently */ + static const char *fragProgramText = + "!!ARBfp1.0\n" +#if DO_FRAGMENT_FOG + "OPTION ARB_fog_linear; \n" +#endif + "PARAM Diffuse = state.material.diffuse; \n" + "PARAM Specular = state.material.specular; \n" + "PARAM LightPos = program.local[3]; \n" + "TEMP lightDir, normal, len; \n" + "TEMP dotProd, specAtten; \n" + "TEMP diffuseColor, specularColor; \n" + + "# Compute normalized light direction \n" + "DP3 len.x, LightPos, LightPos; \n" + "RSQ len.y, len.x; \n" + "MUL lightDir, LightPos, len.y; \n" + + "# Compute normalized normal \n" + "DP3 len.x, fragment.texcoord[0], fragment.texcoord[0]; \n" + "RSQ len.y, len.x; \n" + "MUL normal, fragment.texcoord[0], len.y; \n" + + "# Compute dot product of light direction and normal vector\n" + "DP3_SAT dotProd, lightDir, normal; # limited to [0,1]\n" + + "MUL diffuseColor, Diffuse, dotProd; # diffuse attenuation\n" + + "POW specAtten.x, dotProd.x, {20.0}.x; # specular exponent\n" + + "MUL specularColor, Specular, specAtten.x; # specular attenuation\n" + +#if DO_FRAGMENT_FOG + "# need to clamp color to [0,1] before fogging \n" + "ADD_SAT result.color, diffuseColor, specularColor; # add colors\n" +#else + "# clamping will be done after program's finished \n" + "ADD result.color, diffuseColor, specularColor; # add colors\n" +#endif + "END \n" + ; + + static const char *vertProgramText = + "!!ARBvp1.0\n" + "ATTRIB pos = vertex.position; \n" + "ATTRIB norm = vertex.normal; \n" + "PARAM modelview[4] = { state.matrix.modelview }; \n" + "PARAM modelviewProj[4] = { state.matrix.mvp }; \n" + "PARAM invModelview[4] = { state.matrix.modelview.invtrans }; \n" + + "# typical modelview/projection transform \n" + "DP4 result.position.x, pos, modelviewProj[0]; \n" + "DP4 result.position.y, pos, modelviewProj[1]; \n" + "DP4 result.position.z, pos, modelviewProj[2]; \n" + "DP4 result.position.w, pos, modelviewProj[3]; \n" + + "# transform normal by inv transpose of modelview, put in tex0 \n" + "DP3 result.texcoord[0].x, norm, invModelview[0]; \n" + "DP3 result.texcoord[0].y, norm, invModelview[1]; \n" + "DP3 result.texcoord[0].z, norm, invModelview[2]; \n" + "DP3 result.texcoord[0].w, norm, invModelview[3]; \n" + +#if DO_FRAGMENT_FOG + "# compute fog coordinate = vertex eye-space Z coord (negated)\n" + "DP4 result.fogcoord, -pos, modelview[2]; \n" +#endif + "END\n"; + ; + + if (!glutExtensionSupported("GL_ARB_vertex_program")) { + printf("Sorry, this demo requires GL_ARB_vertex_program\n"); + exit(1); + } + if (!glutExtensionSupported("GL_ARB_fragment_program")) { + printf("Sorry, this demo requires GL_ARB_fragment_program\n"); + exit(1); + } + + /* + * Get extension function pointers. + */ + glProgramLocalParameter4fvARB_func = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) glutGetProcAddress("glProgramLocalParameter4fvARB"); + assert(glProgramLocalParameter4fvARB_func); + + glProgramLocalParameter4dARB_func = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) glutGetProcAddress("glProgramLocalParameter4dARB"); + assert(glProgramLocalParameter4dARB_func); + + glGetProgramLocalParameterdvARB_func = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) glutGetProcAddress("glGetProgramLocalParameterdvARB"); + assert(glGetProgramLocalParameterdvARB_func); + + glGenProgramsARB_func = (PFNGLGENPROGRAMSARBPROC) glutGetProcAddress("glGenProgramsARB"); + assert(glGenProgramsARB_func); + + glProgramStringARB_func = (PFNGLPROGRAMSTRINGARBPROC) glutGetProcAddress("glProgramStringARB"); + assert(glProgramStringARB_func); + + glBindProgramARB_func = (PFNGLBINDPROGRAMARBPROC) glutGetProcAddress("glBindProgramARB"); + assert(glBindProgramARB_func); + + glIsProgramARB_func = (PFNGLISPROGRAMARBPROC) glutGetProcAddress("glIsProgramARB"); + assert(glIsProgramARB_func); + + glDeleteProgramsARB_func = (PFNGLDELETEPROGRAMSARBPROC) glutGetProcAddress("glDeleteProgramsARB"); + assert(glDeleteProgramsARB_func); + + /* + * Fragment program + */ + glGenProgramsARB_func(1, &FragProg); + assert(FragProg > 0); + glBindProgramARB_func(GL_FRAGMENT_PROGRAM_ARB, FragProg); + glProgramStringARB_func(GL_FRAGMENT_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(fragProgramText), + (const GLubyte *) fragProgramText); + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); + if (glGetError() != GL_NO_ERROR || errorPos != -1) { + int l = FindLine(fragProgramText, errorPos); + printf("Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l, + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + exit(0); + } + assert(glIsProgramARB_func(FragProg)); + + /* + * Do some sanity tests + */ + { + GLdouble v[4]; + glProgramLocalParameter4dARB_func(GL_FRAGMENT_PROGRAM_ARB, 8, + 10.0, 20.0, 30.0, 40.0); + glGetProgramLocalParameterdvARB_func(GL_FRAGMENT_PROGRAM_ARB, 8, v); + assert(v[0] == 10.0); + assert(v[1] == 20.0); + assert(v[2] == 30.0); + assert(v[3] == 40.0); + } + + /* + * Vertex program + */ + glGenProgramsARB_func(1, &VertProg); + assert(VertProg > 0); + glBindProgramARB_func(GL_VERTEX_PROGRAM_ARB, VertProg); + glProgramStringARB_func(GL_VERTEX_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(vertProgramText), + (const GLubyte *) vertProgramText); + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); + if (glGetError() != GL_NO_ERROR || errorPos != -1) { + int l = FindLine(vertProgramText, errorPos); + printf("Vertex Program Error (pos=%d line=%d): %s\n", errorPos, l, + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + exit(0); + } + assert(glIsProgramARB_func(VertProg)); + + /* + * Misc init + */ + glClearColor(0.3, 0.3, 0.3, 0.0); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0); + +#if DO_FRAGMENT_FOG + { + /* Green-ish fog color */ + static const GLfloat fogColor[4] = {0.5, 1.0, 0.5, 0}; + glFogfv(GL_FOG_COLOR, fogColor); + glFogf(GL_FOG_START, 5.0); + glFogf(GL_FOG_END, 25.0); + } +#endif + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("Press p to toggle between per-pixel and per-vertex lighting\n"); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 200, 200 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Redisplay ); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c new file mode 100644 index 00000000000..374de568872 --- /dev/null +++ b/progs/demos/arbfslight.c @@ -0,0 +1,304 @@ +/* + * Use GL_ARB_fragment_shader and GL_ARB_vertex_shader to implement + * simple per-pixel lighting. + * + * Michal Krol + * 20 February 2006 + * + * Based on the original demo by: + * Brian Paul + * 17 April 2003 + */ + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> + +#ifdef WIN32 +#define GETPROCADDRESS wglGetProcAddress +#else +#define GETPROCADDRESS glutGetProcAddress +#endif + +static GLfloat diffuse[4] = { 0.5f, 0.5f, 1.0f, 1.0f }; +static GLfloat specular[4] = { 0.8f, 0.8f, 0.8f, 1.0f }; +static GLfloat lightPos[4] = { 0.0f, 10.0f, 20.0f, 1.0f }; +static GLfloat delta = 1.0f; + +static GLhandleARB fragShader; +static GLhandleARB vertShader; +static GLhandleARB program; + +static GLint uLightPos; +static GLint uDiffuse; +static GLint uSpecular; + +static GLboolean anim = GL_TRUE; +static GLboolean wire = GL_FALSE; +static GLboolean pixelLight = GL_TRUE; + +static GLint t0 = 0; +static GLint frames = 0; + +static GLfloat xRot = 0.0f, yRot = 0.0f; + +static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; +static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; +static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; +static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; +static PFNGLUNIFORM3FVARBPROC glUniform3fvARB = NULL; +static PFNGLUNIFORM3FVARBPROC glUniform4fvARB = NULL; + +static void normalize (GLfloat *dst, const GLfloat *src) +{ + GLfloat len = sqrtf (src[0] * src[0] + src[1] * src[1] + src[2] * src[2]); + dst[0] = src[0] / len; + dst[1] = src[1] / len; + dst[2] = src[2] / len; +} + +static void Redisplay (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (pixelLight) + { + GLfloat vec[3]; + + glUseProgramObjectARB (program); + normalize (vec, lightPos); + glUniform3fvARB (uLightPos, 1, vec); + glDisable(GL_LIGHTING); + } + else + { + glUseProgramObjectARB (0); + glLightfv (GL_LIGHT0, GL_POSITION, lightPos); + glEnable(GL_LIGHTING); + } + + glPushMatrix (); + glRotatef (xRot, 1.0f, 0.0f, 0.0f); + glRotatef (yRot, 0.0f, 1.0f, 0.0f); + glutSolidSphere (2.0, 10, 5); + glPopMatrix (); + + glutSwapBuffers(); + frames++; + + if (anim) + { + GLint t = glutGet (GLUT_ELAPSED_TIME); + if (t - t0 >= 5000) + { + GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; + GLfloat fps = frames / seconds; + printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + t0 = t; + frames = 0; + } + } +} + +static void Idle (void) +{ + lightPos[0] += delta; + if (lightPos[0] > 25.0f || lightPos[0] < -25.0f) + delta = -delta; + glutPostRedisplay (); +} + +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.0f, 0.0f, -15.0f); +} + +static void Key (unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch (key) + { + case ' ': + case 'a': + anim = !anim; + if (anim) + glutIdleFunc (Idle); + else + glutIdleFunc (NULL); + break; + case 'x': + lightPos[0] -= 1.0f; + break; + case 'X': + lightPos[0] += 1.0f; + break; + case 'w': + wire = !wire; + if (wire) + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + break; + case 'p': + pixelLight = !pixelLight; + if (pixelLight) + printf ("Per-pixel lighting\n"); + else + printf ("Conventional lighting\n"); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay (); +} + +static void SpecialKey (int key, int x, int y) +{ + const GLfloat step = 3.0f; + + (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) +{ + static const char *fragShaderText = + "uniform vec3 lightPos;\n" + "uniform vec4 diffuse;\n" + "uniform vec4 specular;\n" + "varying vec3 normal;\n" + "void main () {\n" + " // Compute dot product of light direction and normal vector\n" + " float dotProd = max (dot (lightPos, normalize (normal)), 0.0);\n" + " // Compute diffuse and specular contributions\n" + " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n" + "}\n" + ; + static const char *vertShaderText = + "varying vec3 normal;\n" + "void main () {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " normal = gl_NormalMatrix * gl_Normal;\n" + "}\n" + ; + + if (!glutExtensionSupported ("GL_ARB_fragment_shader")) + { + printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shader_objects")) + { + printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shading_language_100")) + { + printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_vertex_shader")) + { + printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); + exit(1); + } + + glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB"); + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB"); + glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GETPROCADDRESS ("glUniform3fvARB"); + glUniform4fvARB = (PFNGLUNIFORM3FVARBPROC) GETPROCADDRESS ("glUniform4fvARB"); + + fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); + glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); + glCompileShaderARB (fragShader); + + vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); + glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); + glCompileShaderARB (vertShader); + + program = glCreateProgramObjectARB (); + glAttachObjectARB (program, fragShader); + glAttachObjectARB (program, vertShader); + glLinkProgramARB (program); + glUseProgramObjectARB (program); + + uLightPos = glGetUniformLocationARB (program, "lightPos"); + uDiffuse = glGetUniformLocationARB (program, "diffuse"); + uSpecular = glGetUniformLocationARB (program, "specular"); + + glUniform4fvARB (uDiffuse, 1, diffuse); + glUniform4fvARB (uSpecular, 1, specular); + + glClearColor (0.3f, 0.3f, 0.3f, 0.0f); + glEnable (GL_DEPTH_TEST); + glEnable (GL_LIGHT0); + glEnable (GL_LIGHTING); + glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 20.0f); + + printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER)); + printf ("Press p to toggle between per-pixel and per-vertex lighting\n"); +} + +int main (int argc, char *argv[]) +{ + glutInit (&argc, argv); + glutInitWindowPosition ( 0, 0); + glutInitWindowSize (200, 200); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutCreateWindow (argv[0]); + glutReshapeFunc (Reshape); + glutKeyboardFunc (Key); + glutSpecialFunc (SpecialKey); + glutDisplayFunc (Redisplay); + if (anim) + glutIdleFunc (Idle); + Init (); + glutMainLoop (); + return 0; +} + diff --git a/progs/demos/arbocclude.c b/progs/demos/arbocclude.c new file mode 100644 index 00000000000..ddbb1f1b759 --- /dev/null +++ b/progs/demos/arbocclude.c @@ -0,0 +1,283 @@ +/* + * GL_ARB_occlusion_query demo + * + * Brian Paul + * 12 June 2003 + * + * Copyright (C) 2003 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + +#define TEST_DISPLAY_LISTS 0 + +static GLboolean Anim = GL_TRUE; +static GLfloat Xpos = 0; +static GLuint OccQuery; + + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + + +static void Idle(void) +{ + static int lastTime = 0; + static int sign = +1; + int time = glutGet(GLUT_ELAPSED_TIME); + float step; + + if (lastTime == 0) + lastTime = time; + else if (time - lastTime < 20) /* 50Hz update */ + return; + + step = (time - lastTime) / 1000.0 * sign; + lastTime = time; + + Xpos += step; + + if (Xpos > 2.5) { + Xpos = 2.5; + sign = -1; + } + else if (Xpos < -2.5) { + Xpos = -2.5; + sign = +1; + } + glutPostRedisplay(); +} + + +static void Display( void ) +{ + GLuint passed; + GLint ready; + char s[100]; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + 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 ); + + /* draw the occluding polygons */ + glColor3f(0, 0.6, 0.8); + glBegin(GL_QUADS); + glVertex2f(-1.6, -1.5); + glVertex2f(-0.4, -1.5); + glVertex2f(-0.4, 1.5); + glVertex2f(-1.6, 1.5); + + glVertex2f( 0.4, -1.5); + glVertex2f( 1.6, -1.5); + glVertex2f( 1.6, 1.5); + glVertex2f( 0.4, 1.5); + glEnd(); + + /* draw the test polygon with occlusion testing */ + glPushMatrix(); + glTranslatef(Xpos, 0, -0.5); + glScalef(0.3, 0.3, 1.0); + glRotatef(-90.0 * Xpos, 0, 0, 1); + +#if defined(GL_ARB_occlusion_query) +#if TEST_DISPLAY_LISTS + glNewList(10, GL_COMPILE); + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); + glEndList(); + glCallList(10); +#else + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); +#endif + + glColorMask(0, 0, 0, 0); + glDepthMask(GL_FALSE); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + +#if TEST_DISPLAY_LISTS + glNewList(11, GL_COMPILE); + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + glEndList(); + glCallList(11); +#else + glEndQueryARB(GL_SAMPLES_PASSED_ARB); +#endif + + do { + /* do useful work here, if any */ + glGetQueryObjectivARB(OccQuery, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); + } while (!ready); + glGetQueryObjectuivARB(OccQuery, GL_QUERY_RESULT_ARB, &passed); + + /* turn off occlusion testing */ + glColorMask(1, 1, 1, 1); + glDepthMask(GL_TRUE); +#endif /* GL_ARB_occlusion_query */ + + /* draw the orange rect, so we can see what's going on */ + glColor3f(0.8, 0.5, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + + + /* Print result message */ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glColor3f(1, 1, 1); +#if defined(GL_ARB_occlusion_query) + sprintf(s, " %4d Fragments Visible", passed); + glRasterPos3f(-0.50, -0.7, 0); + PrintString(s); + if (!passed) { + glRasterPos3f(-0.25, -0.8, 0); + PrintString("Fully Occluded"); + } +#else + glRasterPos3f(-0.25, -0.8, 0); + PrintString("GL_ARB_occlusion_query not available at compile time"); +#endif /* GL_ARB_occlusion_query */ + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + case ' ': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const GLfloat step = 0.1; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char *ext = (const char *) glGetString(GL_EXTENSIONS); + GLint bits; + + if (!strstr(ext, "GL_ARB_occlusion_query")) { + printf("Sorry, this demo requires the GL_ARB_occlusion_query extension\n"); + exit(-1); + } + +#if defined(GL_ARB_occlusion_query) + glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bits); + if (!bits) { + printf("Hmmm, GL_QUERY_COUNTER_BITS_ARB is zero!\n"); + exit(-1); + } +#endif /* GL_ARB_occlusion_query */ + + glGetIntegerv(GL_DEPTH_BITS, &bits); + printf("Depthbits: %d\n", bits); + +#if defined(GL_ARB_occlusion_query) + glGenQueriesARB(1, &OccQuery); + assert(OccQuery > 0); +#endif /* GL_ARB_occlusion_query */ + + glEnable(GL_DEPTH_TEST); +} + + +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 ); + glutIdleFunc( Idle ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/bounce.c b/progs/demos/bounce.c new file mode 100644 index 00000000000..436bc7d1fb8 --- /dev/null +++ b/progs/demos/bounce.c @@ -0,0 +1,226 @@ + +/* + * Bouncing ball demo. + * + * This program is in the public domain + * + * Brian Paul + * + * Conversion to GLUT by Mark J. Kilgard + */ + + +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glut.h> + +#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 = 180.0; +GLfloat Xpos = 0.0, Ypos = 1.0; +GLfloat Xvel = 2.0, Yvel = 0.0; +GLfloat Xmin = -4.0, Xmax = 4.0; +GLfloat Ymin = -3.8, Ymax = 4.0; +GLfloat G = -9.8; + +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 = radius * COS(b) * COS(a); + y = radius * SIN(b) * COS(a); + z = radius * 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; + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + t0 = t; + + Zrot += Zstep*dt; + + Xpos += Xvel*dt; + if (Xpos >= Xmax) { + Xpos = Xmax; + Xvel = -Xvel; + Zstep = -Zstep; + } + if (Xpos <= Xmin) { + Xpos = Xmin; + Xvel = -Xvel; + Zstep = -Zstep; + } + Ypos += Yvel*dt; + Yvel += G*dt; + if (Ypos < Ymin) { + Ypos = Ymin; + if (vel0 == -100.0) + vel0 = fabs(Yvel); + Yvel = vel0; + } + glutPostRedisplay(); +} + +static 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 00000000000..42953f6675e --- /dev/null +++ b/progs/demos/clearspd.c @@ -0,0 +1,218 @@ + +/* + * Simple GLUT program to measure glClear() and glutSwapBuffers() speed. + * Brian Paul February 15, 1997 This file in public domain. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + + +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<Loops;i++) { + glClear( BufferMask ); + glutSwapBuffers(); + } + glFinish(); + t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + } + else { + t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + for (i=0;i<Loops;i++) { + glClear( BufferMask ); + } + glFinish(); + t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + glutSwapBuffers(); + } + + /* NOTE: If clearspd doesn't map it's window immediately on + * starting, swaps will be istantaneous, so this will send Loops + * towards infinity. When a window is finally mapped, it may be + * minutes before the first call to glutSwapBuffers, making it look + * like there's a driver bug. + */ + if (t1-t0 < MinPeriod) { + /* Next time do more clears to get longer elapsed time */ + Loops *= 2; + return; + } + + clearRate = Loops / (t1-t0); + pixelRate = clearRate * Width * Height; + if (SwapFlag) { + printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %g pixels/s\n", + Loops, t1-t0, clearRate, pixelRate ); + } + else { + printf("Rate: %d clears in %gs = %g clears/s %g pixels/s\n", + Loops, t1-t0, clearRate, pixelRate); + } +} + + +static void Reshape( int width, int height ) +{ + Width = width; + Height = 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(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void Init( int argc, char *argv[] ) +{ + int i; + for (i=1; i<argc; i++) { + if (strcmp(argv[i],"+rgb")==0) + ColorMode = GLUT_RGB; + else if (strcmp(argv[i],"+ci")==0) + ColorMode = GLUT_INDEX; + else if (strcmp(argv[i],"-color")==0) + BufferMask = 0; + else if (strcmp(argv[i],"+depth")==0) + BufferMask |= GL_DEPTH_BUFFER_BIT; + else if (strcmp(argv[i],"+alpha")==0) + ColorMode = GLUT_RGB | GLUT_ALPHA; + else if (strcmp(argv[i],"+stencil")==0) + BufferMask |= GL_STENCIL_BUFFER_BIT; + else if (strcmp(argv[i],"+accum")==0) + BufferMask |= GL_ACCUM_BUFFER_BIT; + else if (strcmp(argv[i],"-width")==0) { + Width = atoi(argv[i+1]); + i++; + } + else if (strcmp(argv[i],"-height")==0) { + Height = atoi(argv[i+1]); + i++; + } + else if (strcmp(argv[i],"+swap")==0) { + SwapFlag = GL_TRUE; + } + else if (strcmp(argv[i],"-swap")==0) { + SwapFlag = GL_FALSE; + } + else + printf("Unknown option: %s\n", argv[i]); + } + + if (ColorMode & GLUT_ALPHA) + printf("Mode: RGB + Alpha\n"); + else if (ColorMode==GLUT_RGB) + printf("Mode: RGB\n"); + else + printf("Mode: Color Index\n"); + printf("SwapBuffers: %s\n", SwapFlag ? "yes" : "no" ); + printf("Size: %d x %d\n", Width, Height); + printf("Buffers: "); + if (BufferMask & GL_COLOR_BUFFER_BIT) printf("color "); + if (BufferMask & GL_DEPTH_BUFFER_BIT) printf("depth "); + if (BufferMask & GL_STENCIL_BUFFER_BIT) printf("stencil "); + if (BufferMask & GL_ACCUM_BUFFER_BIT) printf("accum "); + printf("\n"); +} + + +static void Help( const char *program ) +{ + printf("%s options:\n", program); + printf(" +rgb RGB mode\n"); + printf(" +ci color index mode\n"); + printf(" -color don't clear color buffer\n"); + printf(" +alpha clear alpha buffer\n"); + printf(" +depth clear depth buffer\n"); + printf(" +stencil clear stencil buffer\n"); + printf(" +accum clear accum buffer\n"); + printf(" +swap also do SwapBuffers\n"); + printf(" -swap don't do SwapBuffers\n"); +} + + +int main( int argc, char *argv[] ) +{ + GLint mode; + + printf("For options: %s -help\n", argv[0]); + + Init( argc, argv ); + + glutInit( &argc, argv ); + glutInitWindowSize( (int) Width, (int) Height ); + glutInitWindowPosition( 0, 0 ); + + mode = ColorMode | GLUT_DOUBLE; + if (BufferMask & GL_STENCIL_BUFFER_BIT) + mode |= GLUT_STENCIL; + if (BufferMask & GL_ACCUM_BUFFER_BIT) + mode |= GLUT_ACCUM; + if (BufferMask & GL_DEPTH_BUFFER_BIT) + mode |= GLUT_DEPTH; + + glutInitDisplayMode(mode); + + glutCreateWindow( argv[0] ); + + if (argc==2 && strcmp(argv[1],"-help")==0) { + Help(argv[0]); + return 0; + } + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c new file mode 100644 index 00000000000..0a59b989835 --- /dev/null +++ b/progs/demos/cubemap.c @@ -0,0 +1,475 @@ +/* + * GL_ARB_texture_cube_map demo + * + * Brian Paul + * May 2000 + * + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * This is a pretty minimalistic demo for now. Eventually, use some + * interesting cube map textures and 3D objects. + * For now, we use 6 checkerboard "walls" and a sphere (good for + * verification purposes). + */ + + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "GL/glut.h" +#include "readtex.h" + + +static GLfloat Xrot = 0, Yrot = 0; +static GLfloat EyeDist = 10; +static GLboolean use_vertex_arrays = GL_FALSE; +static GLboolean anim = GL_TRUE; + +#define eps1 0.99 +#define br 20.0 /* box radius */ + +static const GLfloat tex_coords[] = { + /* +X side */ + 1.0, -eps1, -eps1, + 1.0, -eps1, eps1, + 1.0, eps1, eps1, + 1.0, eps1, -eps1, + + /* -X side */ + -1.0, eps1, -eps1, + -1.0, eps1, eps1, + -1.0, -eps1, eps1, + -1.0, -eps1, -eps1, + + /* +Y side */ + -eps1, 1.0, -eps1, + -eps1, 1.0, eps1, + eps1, 1.0, eps1, + eps1, 1.0, -eps1, + + /* -Y side */ + -eps1, -1.0, -eps1, + -eps1, -1.0, eps1, + eps1, -1.0, eps1, + eps1, -1.0, -eps1, + + /* +Z side */ + eps1, -eps1, 1.0, + -eps1, -eps1, 1.0, + -eps1, eps1, 1.0, + eps1, eps1, 1.0, + + /* -Z side */ + eps1, eps1, -1.0, + -eps1, eps1, -1.0, + -eps1, -eps1, -1.0, + eps1, -eps1, -1.0, +}; + +static const GLfloat vtx_coords[] = { + /* +X side */ + br, -br, -br, + br, -br, br, + br, br, br, + br, br, -br, + + /* -X side */ + -br, br, -br, + -br, br, br, + -br, -br, br, + -br, -br, -br, + + /* +Y side */ + -br, br, -br, + -br, br, br, + br, br, br, + br, br, -br, + + /* -Y side */ + -br, -br, -br, + -br, -br, br, + br, -br, br, + br, -br, -br, + + /* +Z side */ + br, -br, br, + -br, -br, br, + -br, br, br, + br, br, br, + + /* -Z side */ + br, br, -br, + -br, br, -br, + -br, -br, -br, + br, -br, -br, +}; + +static void draw_skybox( void ) +{ + if ( use_vertex_arrays ) { + glTexCoordPointer( 3, GL_FLOAT, 0, tex_coords ); + glVertexPointer( 3, GL_FLOAT, 0, vtx_coords ); + + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); + glEnableClientState( GL_VERTEX_ARRAY ); + + glDrawArrays( GL_QUADS, 0, 24 ); + + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); + } + else { + unsigned i; + + glBegin(GL_QUADS); + for ( i = 0 ; i < 24 ; i++ ) { + glTexCoord3fv( & tex_coords[ i * 3 ] ); + glVertex3fv ( & vtx_coords[ i * 3 ] ); + } + glEnd(); + } +} + + +static void draw( void ) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); /*MODELVIEW*/ + glTranslatef( 0.0, 0.0, -EyeDist ); + + /* skybox */ + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + draw_skybox(); + glPopMatrix(); + + /* sphere */ + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glRotatef(-Yrot, 0, 1, 0); + glRotatef(-Xrot, 1, 0, 0); + + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + glutSolidSphere(2.0, 20, 20); + + glLoadIdentity(); /* texture */ + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void idle(void) +{ + GLfloat t = 0.05 * glutGet(GLUT_ELAPSED_TIME); + Yrot = t; + glutPostRedisplay(); +} + + +static void set_mode(GLuint mode) +{ + if (mode == 0) { + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + printf("GL_REFLECTION_MAP_ARB mode\n"); + } + else if (mode == 1) { + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + printf("GL_NORMAL_MAP_ARB mode\n"); + } +} + + +static void key(unsigned char k, int x, int y) +{ + static GLuint mode = 0; + (void) x; + (void) y; + switch (k) { + case ' ': + anim = !anim; + if (anim) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); + break; + case 'm': + mode = !mode; + set_mode(mode); + break; + case 'v': + use_vertex_arrays = ! use_vertex_arrays; + printf( "Vertex arrays are %sabled\n", + (use_vertex_arrays) ? "en" : "dis" ); + break; + case 'z': + EyeDist -= 0.5; + if (EyeDist < 6.0) + EyeDist = 6.0; + break; + case 'Z': + EyeDist += 0.5; + if (EyeDist > 90.0) + EyeDist = 90; + break; + case 27: + exit(0); + } + glutPostRedisplay(); +} + + +static void specialkey(int key, int x, int y) +{ + GLfloat step = 5; + (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(); +} + + +/* new window size or exposure */ +static void reshape(int width, int height) +{ + GLfloat ar = (float) width / (float) height; + glViewport(0, 0, (GLint)width, (GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -2.0*ar, 2.0*ar, -2.0, 2.0, 4.0, 100.0 ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void init_checkers( void ) +{ +#define CUBE_TEX_SIZE 64 + GLubyte image[CUBE_TEX_SIZE][CUBE_TEX_SIZE][3]; + static const GLubyte colors[6][3] = { + { 255, 0, 0 }, /* face 0 - red */ + { 0, 255, 255 }, /* face 1 - cyan */ + { 0, 255, 0 }, /* face 2 - green */ + { 255, 0, 255 }, /* face 3 - purple */ + { 0, 0, 255 }, /* face 4 - blue */ + { 255, 255, 0 } /* face 5 - yellow */ + }; + static const GLenum targets[6] = { + GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB + }; + + GLint i, j, f; + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + /* make colored checkerboard cube faces */ + for (f = 0; f < 6; f++) { + for (i = 0; i < CUBE_TEX_SIZE; i++) { + for (j = 0; j < CUBE_TEX_SIZE; j++) { + if ((i/4 + j/4) & 1) { + image[i][j][0] = colors[f][0]; + image[i][j][1] = colors[f][1]; + image[i][j][2] = colors[f][2]; + } + else { + image[i][j][0] = 255; + image[i][j][1] = 255; + image[i][j][2] = 255; + } + } + } + + glTexImage2D(targets[f], 0, GL_RGB, CUBE_TEX_SIZE, CUBE_TEX_SIZE, 0, + GL_RGB, GL_UNSIGNED_BYTE, image); + } +} + + +static void load(GLenum target, const char *filename, + GLboolean flipTB, GLboolean flipLR) +{ + GLint w, h; + GLenum format; + GLubyte *img = LoadRGBImage( filename, &w, &h, &format ); + if (!img) { + printf("Error: couldn't load texture image %s\n", filename); + exit(1); + } + assert(format == GL_RGB); + + /* <sigh> the way the texture cube mapping works, we have to flip + * images to make things look right. + */ + if (flipTB) { + const int stride = 3 * w; + GLubyte temp[3*1024]; + int i; + for (i = 0; i < h / 2; i++) { + memcpy(temp, img + i * stride, stride); + memcpy(img + i * stride, img + (h - i - 1) * stride, stride); + memcpy(img + (h - i - 1) * stride, temp, stride); + } + } + if (flipLR) { + const int stride = 3 * w; + GLubyte temp[3]; + GLubyte *row; + int i, j; + for (i = 0; i < h; i++) { + row = img + i * stride; + for (j = 0; j < w / 2; j++) { + int k = w - j - 1; + temp[0] = row[j*3+0]; + temp[1] = row[j*3+1]; + temp[2] = row[j*3+2]; + row[j*3+0] = row[k*3+0]; + row[j*3+1] = row[k*3+1]; + row[j*3+2] = row[k*3+2]; + row[k*3+0] = temp[0]; + row[k*3+1] = temp[1]; + row[k*3+2] = temp[2]; + } + } + } + + gluBuild2DMipmaps(target, GL_RGB, w, h, format, GL_UNSIGNED_BYTE, img); + free(img); +} + + +static void load_envmaps(void) +{ + load(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, "right.rgb", GL_TRUE, GL_FALSE); + load(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, "left.rgb", GL_TRUE, GL_FALSE); + load(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, "top.rgb", GL_FALSE, GL_TRUE); + load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, "bottom.rgb", GL_FALSE, GL_TRUE); + load(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, "front.rgb", GL_TRUE, GL_FALSE); + load(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, "back.rgb", GL_TRUE, GL_FALSE); +} + + +static void init( GLboolean useImageFiles ) +{ + GLenum filter; + + /* check for extension */ + { + char *exten = (char *) glGetString(GL_EXTENSIONS); + if (!strstr(exten, "GL_ARB_texture_cube_map")) { + printf("Sorry, this demo requires GL_ARB_texture_cube_map\n"); + exit(0); + } + } + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); + + if (useImageFiles) { + load_envmaps(); + filter = GL_LINEAR; + } + else { + init_checkers(); + filter = GL_NEAREST; + } + + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glEnable(GL_TEXTURE_CUBE_MAP_ARB); + glEnable(GL_DEPTH_TEST); + + glClearColor(.3, .3, .3, 0); + glColor3f( 1.0, 1.0, 1.0 ); + + set_mode(0); +} + + +static void usage(void) +{ + printf("keys:\n"); + printf(" SPACE - toggle animation\n"); + printf(" CURSOR KEYS - rotation\n"); + printf(" m - toggle texgen reflection mode\n"); + printf(" z/Z - change viewing distance\n"); +} + + +int main( int argc, char *argv[] ) +{ + glutInitWindowPosition(0, 0); + glutInitWindowSize(600, 500); + glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); + glutCreateWindow("Texture Cube Mapping"); + + if (argc > 1 && strcmp(argv[1] , "-i") == 0) + init( 1 ); + else + init( 0 ); + glutReshapeFunc( reshape ); + glutKeyboardFunc( key ); + glutSpecialFunc( specialkey ); + glutDisplayFunc( draw ); + if (anim) + glutIdleFunc(idle); + usage(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/descrip.mms b/progs/demos/descrip.mms new file mode 100644 index 00000000000..a374fdf13d0 --- /dev/null +++ b/progs/demos/descrip.mms @@ -0,0 +1,90 @@ +# Makefile for GLUT-based demo programs for VMS +# contributed by Jouk Jansen [email protected] +# Last update : 20 May 2005 + +.first + define gl [--.include.gl] + +.include [--]mms-config. + +##### MACROS ##### + +INCDIR = ([--.include],[-.util]) +CFLAGS =/include=$(INCDIR)/prefix=all/name=(as_is,short)/float=ieee/ieee=denorm + +.ifdef SHARE +GL_LIBS = $(XLIBS) +LIB_DEP = [--.lib]$(GL_SHAR) [--.lib]$(GLU_SHAR) [--.lib]$(GLUT_SHAR) +.else +GL_LIBS = [--.lib]libGLUT/l,libMesaGLU/l,libMesaGL/l,$(XLIBS) +LIB_DEP = [--.lib]$(GL_LIB) [--.lib]$(GLU_LIB) [--.lib]$(GLUT_LIB) +.endif + + +PROGS = bounce.exe;,clearspd.exe;,drawpix.exe;,gamma.exe;,gears.exe;,\ + glinfo.exe;,glutfx.exe;,isosurf.exe;,morph3d.exe;,\ + paltex.exe;,pointblast.exe;,reflect.exe;,spectex.exe;,stex3d.exe;,\ + tessdemo.exe;,texcyl.exe;,texobj.exe;,trispd.exe;,winpos.exe; + + +##### RULES ##### +.obj.exe : + cxxlink $(MMS$TARGET_NAME),$(GL_LIBS) + +##### TARGETS ##### +default : + $(MMS)$(MMSQUALIFIERS) $(PROGS) + +clean : + delete *.obj;* + +realclean : + delete $(PROGS) + delete *.obj;* + +bounce.exe; : bounce.obj $(LIB_DEP) +clearspd.exe; : clearspd.obj $(LIB_DEP) +drawpix.exe; : drawpix.obj $(LIB_DEP) [-.util]readtex.obj + cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) +gamma.exe; : gamma.obj $(LIB_DEP) +gears.exe; : gears.obj $(LIB_DEP) +glinfo.exe; : glinfo.obj $(LIB_DEP) +glutfx.exe; : glutfx.obj $(LIB_DEP) +isosurf.exe; : isosurf.obj $(LIB_DEP) [-.util]readtex.obj + cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) +morph3d.exe; : morph3d.obj $(LIB_DEP) +paltex.exe; : paltex.obj $(LIB_DEP) +pointblast.exe; : pointblast.obj $(LIB_DEP) +reflect.exe; : reflect.obj [-.util]readtex.obj [-.util]showbuffer.obj\ + $(LIB_DEP) + cxxlink $(MMS$TARGET_NAME),[-.util]readtex,showbuffer,$(GL_LIBS) +spectex.exe; : spectex.obj $(LIB_DEP) +stex3d.exe; : stex3d.obj $(LIB_DEP) +tessdemo.exe; : tessdemo.obj $(LIB_DEP) +texcyl.exe; : texcyl.obj [-.util]readtex.obj $(LIB_DEP) + cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) +texobj.exe; : texobj.obj $(LIB_DEP) +trispd.exe; : trispd.obj $(LIB_DEP) +winpos.exe; : winpos.obj [-.util]readtex.obj $(LIB_DEP) + cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) + + +bounce.obj : bounce.c +clearspd.obj : clearspd.c +drawpix.obj : drawpix.c +gamma.obj : gamma.c +gears.obj : gears.c +glinfo.obj : glinfo.c +glutfx.obj : glutfx.c +isosurf.obj : isosurf.c +morph3d.obj : morph3d.c +paltex.obj : paltex.c +pointblast.obj : pointblast.c +reflect.obj : reflect.c +spectex.obj : spectex.c +stex3d.obj : stex3d.c +tessdemo.obj : tessdemo.c +texcyl.obj : texcyl.c +texobj.obj : texobj.c +trispd.obj : trispd.c +winpos.obj : winpos.c diff --git a/progs/demos/drawpix.c b/progs/demos/drawpix.c new file mode 100644 index 00000000000..d2f57486744 --- /dev/null +++ b/progs/demos/drawpix.c @@ -0,0 +1,358 @@ + +/* + * glDrawPixels demo/test/benchmark + * + * Brian Paul September 25, 1997 This file is in the public domain. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" + +#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 int Fog = 0; +static GLfloat Zpos = -1.0; +static float Xzoom, Yzoom; +static GLboolean DrawFront = GL_FALSE; +static GLboolean Dither = GL_TRUE; + + +static void Reset( void ) +{ + Xpos = Ypos = 20; + DrawWidth = ImgWidth; + DrawHeight = ImgHeight; + SkipPixels = SkipRows = 0; + Scissor = 0; + Fog = 0; + Zpos = -1.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: */ + glRasterPos3f(0, 0, Zpos); + 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); + + if (Fog) + glEnable(GL_FOG); + + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + + glDisable(GL_SCISSOR_TEST); + glDisable(GL_FOG); + + if (DrawFront) + glFinish(); + else + 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); + if (Fog) + glEnable(GL_FOG); + + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + + /* 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); + glDisable(GL_FOG); + + /* 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, 0.0, 2.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 'd': + Dither = !Dither; + if (Dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); + 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 'z': + Zpos -= 0.1; + printf("RasterPos Z = %g\n", Zpos); + break; + case 'Z': + Zpos += 0.1; + printf("RasterPos Z = %g\n", Zpos); + break; + case 'b': + Benchmark(); + break; + case 'F': + Fog = !Fog; + printf("Fog %d\n", Fog); + break; + case 'f': + DrawFront = !DrawFront; + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); + 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, const char *filename ) +{ + static const GLfloat fogColor[4] = {0, 1, 0, 0}; + + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat ); + if (!Image) { + printf("Couldn't read %s\n", filename); + exit(0); + } + + if (ciMode) { + /* Convert RGB image to grayscale */ + GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i<ImgWidth*ImgHeight; i++) { + int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; + indexImage[i] = gray / 3; + } + free(Image); + Image = indexImage; + ImgFormat = GL_COLOR_INDEX; + + for (i=0;i<255;i++) { + float g = i / 255.0; + glutSetColor(i, g, g, g); + } + } + + printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); + + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, 0); + glFogf(GL_FOG_END, 2); + glFogfv(GL_FOG_COLOR, fogColor); + + Reset(); +} + + +static void Usage(void) +{ + printf("Keys:\n"); + printf(" SPACE Reset Parameters\n"); + printf(" Up/Down Move image up/down\n"); + printf(" Left/Right Move image left/right\n"); + printf(" x Decrease X-axis PixelZoom\n"); + printf(" X Increase X-axis PixelZoom\n"); + printf(" y Decrease Y-axis PixelZoom\n"); + printf(" Y Increase Y-axis PixelZoom\n"); + printf(" w Decrease glDrawPixels width*\n"); + printf(" W Increase glDrawPixels width*\n"); + printf(" h Decrease glDrawPixels height*\n"); + printf(" H Increase glDrawPixels height*\n"); + printf(" p Decrease GL_UNPACK_SKIP_PIXELS*\n"); + printf(" P Increase GL_UNPACK_SKIP_PIXELS*\n"); + printf(" r Decrease GL_UNPACK_SKIP_ROWS*\n"); + printf(" R Increase GL_UNPACK_SKIP_ROWS*\n"); + printf(" s Toggle GL_SCISSOR_TEST\n"); + printf(" F Toggle GL_FOG\n"); + printf(" z Decrease RasterPos Z\n"); + printf(" Z Increase RasterPos Z\n"); + + printf(" f Toggle front/back buffer drawing\n"); + printf(" b Benchmark test\n"); + printf(" ESC Exit\n"); + printf("* Warning: no limits are imposed on these parameters so it's\n"); + printf(" possible to cause a segfault if you go too far.\n"); +} + + +int main( int argc, char *argv[] ) +{ + GLboolean ciMode = GL_FALSE; + const char *filename = IMAGE_FILE; + int i = 1; + + if (argc > i && strcmp(argv[i], "-ci")==0) { + ciMode = GL_TRUE; + i++; + } + if (argc > i) { + filename = argv[i]; + } + + 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, filename); + Usage(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/engine.c b/progs/demos/engine.c new file mode 100644 index 00000000000..143b02a8894 --- /dev/null +++ b/progs/demos/engine.c @@ -0,0 +1,1293 @@ +/** + * Simple engine demo (crankshaft, pistons, connecting rods) + * + * Brian Paul + * June 2006 + */ + +#define GL_GLEXT_PROTOTYPES + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> +#include "readtex.h" +#include "trackball.h" + + +#define DEG_TO_RAD(DEG) ((DEG) * M_PI / 180.0) + +#define TEXTURE_FILE "../images/reflect.rgb" + +/* Target engine speed: */ +const int RPM = 100.0; + + +/** + * Engine description. + */ +typedef struct +{ + const char *Name; + int Pistons; + int Cranks; + float V_Angle; + float PistonRadius; + float PistonHeight; + float WristPinRadius; + float Throw; + float CrankPlateThickness; + float CrankPinRadius; + float CrankJournalRadius; + float CrankJournalLength; + float ConnectingRodLength; + float ConnectingRodThickness; + /* display list IDs */ + GLuint CrankList; + GLuint ConnRodList; + GLuint PistonList; + GLuint BlockList; +} Engine; + + +typedef struct +{ + float CurQuat[4]; + float Distance; + /* When mouse is moving: */ + GLboolean Rotating, Translating; + GLint StartX, StartY; + float StartDistance; +} ViewInfo; + + +typedef enum +{ + LIT, + WIREFRAME, + TEXTURED +} RenderMode; + + +typedef struct +{ + RenderMode Mode; + GLboolean Anim; + GLboolean Wireframe; + GLboolean Blend; + GLboolean Antialias; + GLboolean Texture; + GLboolean UseLists; + GLboolean DrawBox; + GLboolean ShowInfo; + GLboolean ShowBlock; +} RenderInfo; + + +static GLUquadric *Q; + +static GLfloat Theta = 0.0; + +static const GLfloat PistonColor[4] = { 1.0, 0.5, 0.5, 1.0 }; +static const GLfloat ConnRodColor[4] = { 0.7, 1.0, 0.7, 1.0 }; +static const GLfloat CrankshaftColor[4] = { 0.7, 0.7, 1.0, 1.0 }; +static const GLfloat BlockColor[4] = {0.8, 0.8, 0.8, 0.75 }; + +static GLuint TextureObj; +static GLint WinWidth = 800, WinHeight = 500; + +static ViewInfo View; +static RenderInfo Render; + +#define NUM_ENGINES 3 +static Engine Engines[NUM_ENGINES] = +{ + { + "V-6", + 6, /* Pistons */ + 3, /* Cranks */ + 90.0, /* V_Angle */ + 0.5, /* PistonRadius */ + 0.6, /* PistonHeight */ + 0.1, /* WristPinRadius */ + 0.5, /* Throw */ + 0.2, /* CrankPlateThickness */ + 0.25, /* CrankPinRadius */ + 0.3, /* CrankJournalRadius */ + 0.4, /* CrankJournalLength */ + 1.5, /* ConnectingRodLength */ + 0.1 /* ConnectingRodThickness */ + }, + { + "Inline-4", + 4, /* Pistons */ + 4, /* Cranks */ + 0.0, /* V_Angle */ + 0.5, /* PistonRadius */ + 0.6, /* PistonHeight */ + 0.1, /* WristPinRadius */ + 0.5, /* Throw */ + 0.2, /* CrankPlateThickness */ + 0.25, /* CrankPinRadius */ + 0.3, /* CrankJournalRadius */ + 0.4, /* CrankJournalLength */ + 1.5, /* ConnectingRodLength */ + 0.1 /* ConnectingRodThickness */ + }, + { + "Boxer-6", + 6, /* Pistons */ + 3, /* Cranks */ + 180.0,/* V_Angle */ + 0.5, /* PistonRadius */ + 0.6, /* PistonHeight */ + 0.1, /* WristPinRadius */ + 0.5, /* Throw */ + 0.2, /* CrankPlateThickness */ + 0.25, /* CrankPinRadius */ + 0.3, /* CrankJournalRadius */ + 0.4, /* CrankJournalLength */ + 1.5, /* ConnectingRodLength */ + 0.1 /* ConnectingRodThickness */ + } +}; + +static int CurEngine = 0; + + + +static void +InitViewInfo(ViewInfo *view) +{ + view->Rotating = GL_FALSE; + view->Translating = GL_FALSE; + view->StartX = view->StartY = 0; + view->Distance = 12.0; + view->StartDistance = 0.0; + view->CurQuat[0] = -0.194143; + view->CurQuat[1] = 0.507848; + view->CurQuat[2] = 0.115245; + view->CurQuat[3] = 0.831335; +} + + +static void +InitRenderInfo(RenderInfo *render) +{ + render->Mode = LIT; + render->Anim = GL_TRUE; + render->Wireframe = GL_FALSE; + render->Blend = GL_FALSE; + render->Antialias = GL_FALSE; + render->Texture = GL_FALSE; + render->DrawBox = GL_FALSE; + render->ShowInfo = GL_TRUE; + render->ShowBlock = GL_FALSE; + render->UseLists = GL_FALSE; +} + + +/** + * Set GL for given rendering mode. + */ +static void +SetRenderState(RenderMode mode) +{ + static const GLfloat gray2[4] = { 0.2, 0.2, 0.2, 1.0 }; + static const GLfloat gray4[4] = { 0.4, 0.4, 0.4, 1.0 }; + + /* defaults */ + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gray2); + + switch (mode) { + case LIT: + glEnable(GL_LIGHTING); + break; + case WIREFRAME: + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + glLineWidth(1.5); + break; + case TEXTURED: + glEnable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gray4); + break; + default: + ; + } +} + + +/** + * Animate the engine parts. + */ +static void +Idle(void) +{ + /* convert degrees per millisecond to RPM: */ + const float m = 360.0 / 1000.0 / 60.0; + GLint t = glutGet(GLUT_ELAPSED_TIME); + Theta = ((int) (t * RPM * m)) % 360; + glutPostRedisplay(); +} + + +/** + * Compute piston's position along its stroke. + */ +static float +PistonStrokePosition(float throwDist, float crankAngle, float connRodLength) +{ + float x = throwDist * cos(DEG_TO_RAD(crankAngle)); + float y = throwDist * sin(DEG_TO_RAD(crankAngle)); + float pos = y + sqrt(connRodLength * connRodLength - x * x); + return pos; +} + + +/** + * Compute position of nth piston along the crankshaft. + */ +static float +PistonShaftPosition(const Engine *eng, int piston) +{ + const int i = piston / (eng->Pistons / eng->Cranks); + float z; + assert(piston < eng->Pistons); + z = 1.5 * eng->CrankJournalLength + eng->CrankPlateThickness + + i * (2.0 * (eng->CrankJournalLength + eng->CrankPlateThickness)); + if (eng->Pistons > eng->Cranks) { + if (piston & 1) + z += eng->ConnectingRodThickness; + else + z -= eng->ConnectingRodThickness; + } + return z; +} + + +/** + * Compute distance between two adjacent pistons + */ +static float +PistonSpacing(const Engine *eng) +{ + const int pistonsPerCrank = eng->Pistons / eng->Cranks; + const float z0 = PistonShaftPosition(eng, 0); + const float z1 = PistonShaftPosition(eng, pistonsPerCrank); + return z1 - z0; +} + + +/** + * (x0, y0) = position of big end on crankshaft + * (x1, y1) = position of small end on piston + */ +static void +ComputeConnectingRodPosition(float throwDist, float crankAngle, + float connRodLength, + float *x0, float *y0, float *x1, float *y1) +{ + *x0 = throwDist * cos(DEG_TO_RAD(crankAngle)); + *y0 = throwDist * sin(DEG_TO_RAD(crankAngle)); + *x1 = 0.0; + *y1 = PistonStrokePosition(throwDist, crankAngle, connRodLength); +} + + +/** + * Compute total length of the crankshaft. + */ +static float +CrankshaftLength(const Engine *eng) +{ + float len = (eng->Cranks * 2 + 1) * eng->CrankJournalLength + + 2 * eng->Cranks * eng->CrankPlateThickness; + return len; +} + + +/** + * Draw a piston. + * Axis of piston = Z axis. Wrist pin is centered on (0, 0, 0). + */ +static void +DrawPiston(const Engine *eng) +{ + const int slices = 30, stacks = 4, loops = 4; + const float innerRadius = 0.9 * eng->PistonRadius; + const float innerHeight = eng->PistonHeight - 0.15; + const float wristPinLength = 1.8 * eng->PistonRadius; + + assert(Q); + + glPushMatrix(); + glTranslatef(0, 0, -1.1 * eng->WristPinRadius); + + gluQuadricOrientation(Q, GLU_INSIDE); + + /* bottom rim */ + gluDisk(Q, innerRadius, eng->PistonRadius, slices, 1/*loops*/); + + /* inner cylinder */ + gluCylinder(Q, innerRadius, innerRadius, innerHeight, slices, stacks); + + /* inside top */ + glPushMatrix(); + glTranslatef(0, 0, innerHeight); + gluDisk(Q, 0, innerRadius, slices, loops); + glPopMatrix(); + + gluQuadricOrientation(Q, GLU_OUTSIDE); + + /* outer cylinder */ + gluCylinder(Q, eng->PistonRadius, eng->PistonRadius, eng->PistonHeight, + slices, stacks); + + /* top */ + glTranslatef(0, 0, eng->PistonHeight); + gluDisk(Q, 0, eng->PistonRadius, slices, loops); + + glPopMatrix(); + + /* wrist pin */ + glPushMatrix(); + glTranslatef(0, 0.5 * wristPinLength, 0.0); + glRotatef(90, 1, 0, 0); + gluCylinder(Q, eng->WristPinRadius, eng->WristPinRadius, wristPinLength, + slices, stacks); + glPopMatrix(); +} + + +/** + * Draw piston at particular position. + */ +static void +DrawPositionedPiston(const Engine *eng, float crankAngle) +{ + const float pos = PistonStrokePosition(eng->Throw, crankAngle, + eng->ConnectingRodLength); + glPushMatrix(); + glRotatef(-90, 1, 0, 0); + glTranslatef(0, 0, pos); + DrawPiston(eng); + glPopMatrix(); +} + + +/** + * Draw connector plate. Used for crankshaft and connecting rods. + */ +static void +DrawConnector(float length, float thickness, + float bigEndRadius, float smallEndRadius) +{ + const float bigRadius = 1.2 * bigEndRadius; + const float smallRadius = 1.2 * smallEndRadius; + const float z0 = -0.5 * thickness, z1 = -z0; + GLfloat points[36][2], normals[36][2]; + int i; + + /* compute vertex locations, normals */ + for (i = 0; i < 36; i++) { + const int angle = i * 10; + float x = cos(DEG_TO_RAD(angle)); + float y = sin(DEG_TO_RAD(angle)); + normals[i][0] = x; + normals[i][1] = y; + if (angle >= 0 && angle <= 180) { + x *= smallRadius; + y = y * smallRadius + length; + } + else { + x *= bigRadius; + y *= bigRadius; + } + points[i][0] = x; + points[i][1] = y; + } + + /* front face */ + glNormal3f(0, 0, 1); + glBegin(GL_POLYGON); + for (i = 0; i < 36; i++) { + glVertex3f(points[i][0], points[i][1], z1); + } + glEnd(); + + /* back face */ + glNormal3f(0, 0, -1); + glBegin(GL_POLYGON); + for (i = 0; i < 36; i++) { + glVertex3f(points[35-i][0], points[35-i][1], z0); + } + glEnd(); + + /* edge */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= 36; i++) { + const int j = i % 36; + glNormal3f(normals[j][0], normals[j][1], 0); + glVertex3f(points[j][0], points[j][1], z0); + glVertex3f(points[j][0], points[j][1], z1); + } + glEnd(); +} + + +/** + * Draw a crankshaft. Shaft lies along +Z axis, starting at zero. + */ +static void +DrawCrankshaft(const Engine *eng) +{ + const int slices = 20, stacks = 2; + const int n = eng->Cranks * 4 + 1; + const float phiStep = 360 / eng->Cranks; + float phi = -90.0; + int i; + float z = 0.0; + + for (i = 0; i < n; i++) { + glPushMatrix(); + glTranslatef(0, 0, z); + if (i & 1) { + /* draw a crank plate */ + glRotatef(phi, 0, 0, 1); + glTranslatef(0, 0, 0.5 * eng->CrankPlateThickness); + DrawConnector(eng->Throw, eng->CrankPlateThickness, + eng->CrankJournalRadius, eng->CrankPinRadius); + z += 0.2; + if (i % 4 == 3) + phi += phiStep; + } + else if (i % 4 == 0) { + /* draw crank journal segment */ + gluCylinder(Q, eng->CrankJournalRadius, eng->CrankJournalRadius, + eng->CrankJournalLength, slices, stacks); + z += eng->CrankJournalLength; + } + else if (i % 4 == 2) { + /* draw crank pin segment */ + glRotatef(phi, 0, 0, 1); + glTranslatef(0, eng->Throw, 0); + gluCylinder(Q, eng->CrankPinRadius, eng->CrankPinRadius, + eng->CrankJournalLength, slices, stacks); + z += eng->CrankJournalLength; + } + glPopMatrix(); + } +} + + +/** + * Draw crankshaft at a particular rotation. + * \param crankAngle current crankshaft rotation, in radians + */ +static void +DrawPositionedCrankshaft(const Engine *eng, float crankAngle) +{ + glPushMatrix(); + glRotatef(crankAngle, 0, 0, 1); + if (eng->CrankList) + glCallList(eng->CrankList); + else + DrawCrankshaft(eng); + glPopMatrix(); +} + + +/** + * Draw a connecting rod at particular position. + * \param eng description of connecting rod to draw + * \param crankAngle current crankshaft rotation, in radians + */ +static void +DrawPositionedConnectingRod(const Engine *eng, float crankAngle) +{ + float x0, y0, x1, y1; + float d, phi; + + ComputeConnectingRodPosition(eng->Throw, crankAngle, + eng->ConnectingRodLength, + &x0, &y0, &x1, &y1); + d = sqrt(eng->ConnectingRodLength * eng->ConnectingRodLength - x0 * x0); + phi = atan(x0 / d) * 180.0 / M_PI; + + glPushMatrix(); + glTranslatef(x0, y0, 0); + glRotatef(phi, 0, 0, 1); + if (eng->ConnRodList) + glCallList(eng->ConnRodList); + else + DrawConnector(eng->ConnectingRodLength, eng->ConnectingRodThickness, + eng->CrankPinRadius, eng->WristPinRadius); + glPopMatrix(); +} + + +/** + * Draw a square with a hole in middle. + */ +static void +SquareWithHole(float squareSize, float holeRadius) +{ + int i; + glBegin(GL_QUAD_STRIP); + glNormal3f(0, 0, 1); + for (i = 0; i <= 360; i += 5) { + const float x1 = holeRadius * cos(DEG_TO_RAD(i)); + const float y1 = holeRadius * sin(DEG_TO_RAD(i)); + float x2, y2; + if (i > 315 || i <= 45) { + x2 = squareSize; + y2 = squareSize * tan(DEG_TO_RAD(i)); + } + else if (i > 45 && i <= 135) { + x2 = -squareSize * tan(DEG_TO_RAD(i - 90)); + y2 = squareSize; + } + else if (i > 135 && i <= 225) { + x2 = -squareSize; + y2 = -squareSize * tan(DEG_TO_RAD(i-180)); + } + else if (i > 225 && i <= 315) { + x2 = squareSize * tan(DEG_TO_RAD(i - 270)); + y2 = -squareSize; + } + glVertex2f(x1, y1); /* inner circle */ + glVertex2f(x2, y2); /* outer square */ + } + glEnd(); +} + + +/** + * Draw block with hole through middle. + * Hole is centered on Z axis. + * Bottom of block is at z=0, top of block is at z = blockHeight. + * index is in [0, count - 1] to determine which block faces are drawn. + */ +static void +DrawBlockWithHole(float blockSize, float blockHeight, float holeRadius, + int index, int count) +{ + const int slices = 30, stacks = 4; + const float x = blockSize; + const float y = blockSize; + const float z0 = 0; + const float z1 = blockHeight; + + assert(index < count); + assert(Q); + gluQuadricOrientation(Q, GLU_INSIDE); + + glBegin(GL_QUADS); + /* +X face */ + glNormal3f(1, 0, 0); + glVertex3f( x, -y, z0); + glVertex3f( x, y, z0); + glVertex3f( x, y, z1); + glVertex3f( x, -y, z1); + /* -X face */ + glNormal3f(-1, 0, 0); + glVertex3f(-x, -y, z1); + glVertex3f(-x, y, z1); + glVertex3f(-x, y, z0); + glVertex3f(-x, -y, z0); + if (index == 0) { + /* +Y face */ + glNormal3f(0, 1, 0); + glVertex3f(-x, y, z1); + glVertex3f( x, y, z1); + glVertex3f( x, y, z0); + glVertex3f(-x, y, z0); + } + if (index == count - 1) { + /* -Y face */ + glNormal3f(0, -1, 0); + glVertex3f(-x, -y, z0); + glVertex3f( x, -y, z0); + glVertex3f( x, -y, z1); + glVertex3f(-x, -y, z1); + } + glEnd(); + + /* cylinder / hole */ + gluCylinder(Q, holeRadius, holeRadius, blockHeight, slices, stacks); + + /* face at z0 */ + glPushMatrix(); + glRotatef(180, 1, 0, 0); + SquareWithHole(blockSize, holeRadius); + glPopMatrix(); + + /* face at z1 */ + glTranslatef(0, 0, z1); + SquareWithHole(blockSize, holeRadius); + + gluQuadricOrientation(Q, GLU_OUTSIDE); +} + + +/** + * Draw the engine block. + */ +static void +DrawEngineBlock(const Engine *eng) +{ + const float blockHeight = eng->Throw + 1.5 * eng->PistonHeight; + const float cylRadius = 1.01 * eng->PistonRadius; + const float blockSize = 0.5 * PistonSpacing(eng); + const int pistonsPerCrank = eng->Pistons / eng->Cranks; + int i; + + for (i = 0; i < eng->Pistons; i++) { + const float z = PistonShaftPosition(eng, i); + const int crank = i / pistonsPerCrank; + int k; + + glPushMatrix(); + glTranslatef(0, 0, z); + + /* additional rotation for kth piston per crank */ + k = i % pistonsPerCrank; + glRotatef(k * -eng->V_Angle, 0, 0, 1); + + /* the block */ + glRotatef(-90, 1, 0, 0); + glTranslatef(0, 0, eng->Throw * 2); + DrawBlockWithHole(blockSize, blockHeight, cylRadius, + crank, eng->Cranks); + glPopMatrix(); + } +} + + +/** + * Generate display lists for engine parts. + */ +static void +GenerateDisplayLists(Engine *eng) +{ + eng->CrankList = glGenLists(1); + glNewList(eng->CrankList, GL_COMPILE); + DrawCrankshaft(eng); + glEndList(); + + eng->ConnRodList = glGenLists(1); + glNewList(eng->ConnRodList, GL_COMPILE); + DrawConnector(eng->ConnectingRodLength, eng->ConnectingRodThickness, + eng->CrankPinRadius, eng->WristPinRadius); + glEndList(); + + eng->PistonList = glGenLists(1); + glNewList(eng->PistonList, GL_COMPILE); + DrawPiston(eng); + glEndList(); + + eng->BlockList = glGenLists(1); + glNewList(eng->BlockList, GL_COMPILE); + DrawEngineBlock(eng); + glEndList(); +} + + +/** + * Free engine display lists (render with immediate mode). + */ +static void +FreeDisplayLists(Engine *eng) +{ + glDeleteLists(eng->CrankList, 1); + eng->CrankList = 0; + glDeleteLists(eng->ConnRodList, 1); + eng->ConnRodList = 0; + glDeleteLists(eng->PistonList, 1); + eng->PistonList = 0; + glDeleteLists(eng->BlockList, 1); + eng->BlockList = 0; +} + + +/** + * Draw complete engine. + * \param eng description of engine to draw + * \param crankAngle current crankshaft angle, in radians + */ +static void +DrawEngine(const Engine *eng, float crankAngle) +{ + const float crankDelta = 360.0 / eng->Cranks; + const float crankLen = CrankshaftLength(eng); + const int pistonsPerCrank = eng->Pistons / eng->Cranks; + int i; + + glPushMatrix(); + glRotatef(eng->V_Angle * 0.5, 0, 0, 1); + glTranslatef(0, 0, -0.5 * crankLen); + + /* crankshaft */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, CrankshaftColor); + glColor4fv(CrankshaftColor); + DrawPositionedCrankshaft(eng, crankAngle); + + for (i = 0; i < eng->Pistons; i++) { + const float z = PistonShaftPosition(eng, i); + const int crank = i / pistonsPerCrank; + float rot = crankAngle + crank * crankDelta; + int k; + + glPushMatrix(); + glTranslatef(0, 0, z); + + /* additional rotation for kth piston per crank */ + k = i % pistonsPerCrank; + glRotatef(k * -eng->V_Angle, 0, 0, 1); + rot += k * eng->V_Angle; + + /* piston */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, PistonColor); + glColor4fv(PistonColor); + DrawPositionedPiston(eng, rot); + + /* connecting rod */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ConnRodColor); + glColor4fv(ConnRodColor); + DrawPositionedConnectingRod(eng, rot); + glPopMatrix(); + } + + if (Render.ShowBlock) { + const GLboolean blend = glIsEnabled(GL_BLEND); + + glDepthMask(GL_FALSE); + if (!blend) { + glEnable(GL_BLEND); + } + glEnable(GL_CULL_FACE); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, BlockColor); + glColor4fv(BlockColor); + if (eng->CrankList) + glCallList(eng->BlockList); + else + DrawEngineBlock(eng); + + glDisable(GL_CULL_FACE); + glDepthMask(GL_TRUE); + if (!blend) { + glDisable(GL_BLEND); + } + } + + glPopMatrix(); +} + + +static void +DrawBox(void) +{ + const float xmin = -3.0, xmax = 3.0; + const float ymin = -1.0, ymax = 3.0; + const float zmin = -4.0, zmax = 4.0; + const float step = 0.5; + const float d = 0.01; + float x, y, z; + GLboolean lit = glIsEnabled(GL_LIGHTING); + GLboolean tex = glIsEnabled(GL_TEXTURE_2D); + + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + + glColor3f(1, 1, 1); + + /* Z min */ + glBegin(GL_LINES); + for (x = xmin; x <= xmax; x += step) { + glVertex3f(x, ymin, zmin); + glVertex3f(x, ymax, zmin); + } + glEnd(); + glBegin(GL_LINES); + for (y = ymin; y <= ymax; y += step) { + glVertex3f(xmin, y, zmin); + glVertex3f(xmax, y, zmin); + } + glEnd(); + + /* Y min */ + glBegin(GL_LINES); + for (x = xmin; x <= xmax; x += step) { + glVertex3f(x, ymin, zmin); + glVertex3f(x, ymin, zmax); + } + glEnd(); + glBegin(GL_LINES); + for (z = zmin; z <= zmax; z += step) { + glVertex3f(xmin, ymin, z); + glVertex3f(xmax, ymin, z); + } + glEnd(); + + /* X min */ + glBegin(GL_LINES); + for (y = ymin; y <= ymax; y += step) { + glVertex3f(xmin, y, zmin); + glVertex3f(xmin, y, zmax); + } + glEnd(); + glBegin(GL_LINES); + for (z = zmin; z <= zmax; z += step) { + glVertex3f(xmin, ymin, z); + glVertex3f(xmin, ymax, z); + } + glEnd(); + + glColor3f(0.4, 0.4, 0.6); + glBegin(GL_QUADS); + /* xmin */ + glVertex3f(xmin-d, ymin, zmin); + glVertex3f(xmin-d, ymax, zmin); + glVertex3f(xmin-d, ymax, zmax); + glVertex3f(xmin-d, ymin, zmax); + /* ymin */ + glVertex3f(xmin, ymin-d, zmin); + glVertex3f(xmax, ymin-d, zmin); + glVertex3f(xmax, ymin-d, zmax); + glVertex3f(xmin, ymin-d, zmax); + /* zmin */ + glVertex3f(xmin, ymin, zmin-d); + glVertex3f(xmax, ymin, zmin-d); + glVertex3f(xmax, ymax, zmin-d); + glVertex3f(xmin, ymax, zmin-d); + glEnd(); + + if (lit) + glEnable(GL_LIGHTING); + if (tex) + glEnable(GL_TEXTURE_2D); +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static int +ComputeFPS(void) +{ + static double t0 = -1.0; + static int frames = 0; + double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + static int fps = 0; + + frames++; + + if (t0 < 0.0) { + t0 = t; + fps = 0; + } + else if (t - t0 >= 1.0) { + fps = (int) (frames / (t - t0) + 0.5); + t0 = t; + frames = 0; + } + + return fps; +} + + +static void +Draw(void) +{ + int fps; + GLfloat rot[4][4]; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glTranslatef(0.0, 0.0, -View.Distance); + build_rotmatrix(rot, View.CurQuat); + glMultMatrixf(&rot[0][0]); + + glPushMatrix(); + glTranslatef(0, -0.75, 0); + if (Render.DrawBox) + DrawBox(); + DrawEngine(Engines + CurEngine, Theta); + glPopMatrix(); + + glPopMatrix(); + + fps = ComputeFPS(); + if (Render.ShowInfo) { + GLboolean lit = glIsEnabled(GL_LIGHTING); + GLboolean tex = glIsEnabled(GL_TEXTURE_2D); + char s[100]; + sprintf(s, "%s %d FPS %s", Engines[CurEngine].Name, fps, + Render.UseLists ? "Display Lists" : "Immediate mode"); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glColor3f(1, 1 , 1); + glWindowPos2iARB(10, 10); + PrintString(s); + if (lit) + glEnable(GL_LIGHTING); + if (tex) + glEnable(GL_TEXTURE_2D); + } + + glutSwapBuffers(); +} + + +/** + * Handle window resize. + */ +static void +Reshape(int width, int height) +{ + float ar = (float) width / height; + float s = 0.5; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar * s, ar * s, -s, s, 2.0, 50.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + WinWidth = width; + WinHeight = height; +} + + +/** + * Handle mouse button. + */ +static void +Mouse(int button, int state, int x, int y) +{ + if (button == GLUT_LEFT_BUTTON) { + if (state == GLUT_DOWN) { + View.StartX = x; + View.StartY = y; + View.Rotating = GL_TRUE; + } + else if (state == GLUT_UP) { + View.Rotating = GL_FALSE; + } + } + else if (button == GLUT_MIDDLE_BUTTON) { + if (state == GLUT_DOWN) { + View.StartX = x; + View.StartY = y; + View.StartDistance = View.Distance; + View.Translating = GL_TRUE; + } + else if (state == GLUT_UP) { + View.Translating = GL_FALSE; + } + } +} + + +/** + * Handle mouse motion + */ +static void +Motion(int x, int y) +{ + int i; + if (View.Rotating) { + float x0 = (2.0 * View.StartX - WinWidth) / WinWidth; + float y0 = (WinHeight - 2.0 * View.StartY) / WinHeight; + float x1 = (2.0 * x - WinWidth) / WinWidth; + float y1 = (WinHeight - 2.0 * y) / WinHeight; + float q[4]; + + trackball(q, x0, y0, x1, y1); + View.StartX = x; + View.StartY = y; + for (i = 0; i < 1; i++) + add_quats(q, View.CurQuat, View.CurQuat); + + glutPostRedisplay(); + } + else if (View.Translating) { + float dz = 0.01 * (y - View.StartY); + View.Distance = View.StartDistance + dz; + glutPostRedisplay(); + } +} + + +/** + ** Menu Callbacks + **/ + +static void +OptAnimation(void) +{ + Render.Anim = !Render.Anim; + if (Render.Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); +} + +static void +OptChangeEngine(void) +{ + CurEngine = (CurEngine + 1) % NUM_ENGINES; +} + +static void +OptRenderMode(void) +{ + Render.Mode++; + if (Render.Mode > TEXTURED) + Render.Mode = 0; + SetRenderState(Render.Mode); +} + +static void +OptDisplayLists(void) +{ + int i; + Render.UseLists = !Render.UseLists; + if (Render.UseLists) { + for (i = 0; i < NUM_ENGINES; i++) { + GenerateDisplayLists(Engines + i); + } + } + else { + for (i = 0; i < NUM_ENGINES; i++) { + FreeDisplayLists(Engines + i); + } + } +} + +static void +OptShowBlock(void) +{ + Render.ShowBlock = !Render.ShowBlock; +} + +static void +OptShowInfo(void) +{ + Render.ShowInfo = !Render.ShowInfo; +} + +static void +OptShowBox(void) +{ + Render.DrawBox = !Render.DrawBox; +} + +static void +OptRotate(void) +{ + Theta += 5.0; +} + +static void +OptExit(void) +{ + exit(0); +} + + +/** + * Define menu entries (w/ keyboard shortcuts) + */ + +typedef struct +{ + const char *Text; + const char Key; + void (*Function)(void); +} MenuInfo; + +static const MenuInfo MenuItems[] = { + { "Animation", 'a', OptAnimation }, + { "Change Engine", 'e', OptChangeEngine }, + { "Rendering Style", 'm', OptRenderMode }, + { "Display Lists", 'd', OptDisplayLists }, + { "Show Block", 'b', OptShowBlock }, + { "Show Info", 'i', OptShowInfo }, + { "Show Box", 'x', OptShowBox }, + { "Exit", 27, OptExit }, + { NULL, 'r', OptRotate }, + { NULL, 0, NULL } +}; + + +/** + * Handle menu selection. + */ +static void +MenuHandler(int entry) +{ + MenuItems[entry].Function(); + glutPostRedisplay(); +} + + +/** + * Make pop-up menu. + */ +static void +MakeMenu(void) +{ + int i; + glutCreateMenu(MenuHandler); + for (i = 0; MenuItems[i].Text; i++) { + glutAddMenuEntry(MenuItems[i].Text, i); + } + glutAttachMenu(GLUT_RIGHT_BUTTON); +} + + +/** + * Handle keyboard event. + */ +static void +Key(unsigned char key, int x, int y) +{ + int i; + (void) x; (void) y; + for (i = 0; MenuItems[i].Key; i++) { + if (MenuItems[i].Key == key) { + MenuItems[i].Function(); + glutPostRedisplay(); + break; + } + } +} + + +static +void LoadTexture(void) +{ + GLboolean convolve = GL_FALSE; + + glGenTextures(1, &TextureObj); + glBindTexture(GL_TEXTURE_2D, TextureObj); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + + if (convolve) { +#define FILTER_SIZE 7 + /* use convolution to blur the texture to simulate a dull finish + * on the object. + */ + GLubyte *img; + GLenum format; + GLint w, h; + GLfloat filter[FILTER_SIZE][FILTER_SIZE][4]; + + for (h = 0; h < FILTER_SIZE; h++) { + for (w = 0; w < FILTER_SIZE; w++) { + const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE); + filter[h][w][0] = k; + filter[h][w][1] = k; + filter[h][w][2] = k; + filter[h][w][3] = k; + } + } + + glEnable(GL_CONVOLUTION_2D); + glConvolutionParameteri(GL_CONVOLUTION_2D, + GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA, + FILTER_SIZE, FILTER_SIZE, + GL_RGBA, GL_FLOAT, filter); + + img = LoadRGBImage(TEXTURE_FILE, &w, &h, &format); + if (!img) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, + format, GL_UNSIGNED_BYTE, img); + free(img); + } + else { + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + } +} + + +static void +Init(void) +{ + const GLfloat lightColor[4] = { 0.7, 0.7, 0.7, 1.0 }; + const GLfloat specular[4] = { 0.8, 0.8, 0.8, 1.0 }; + + Q = gluNewQuadric(); + gluQuadricNormals(Q, GLU_SMOOTH); + + LoadTexture(); + + glClearColor(0.3, 0.3, 0.3, 0.0); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glEnable(GL_NORMALIZE); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + InitViewInfo(&View); + InitRenderInfo(&Render); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutCreateWindow("OpenGL Engine Demo"); + glutReshapeFunc(Reshape); + glutMouseFunc(Mouse); + glutMotionFunc(Motion); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + MakeMenu(); + Init(); + if (Render.Anim) + glutIdleFunc(Idle); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/fire.c b/progs/demos/fire.c new file mode 100644 index 00000000000..dd70f6141db --- /dev/null +++ b/progs/demos/fire.c @@ -0,0 +1,777 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> +#include <string.h> + +#ifdef WIN32 +#include <windows.h> +#include <mmsystem.h> +#endif + +#include <GL/glut.h> +#include "readtex.h" + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +#define vinit(a,i,j,k) {\ + (a)[0]=i;\ + (a)[1]=j;\ + (a)[2]=k;\ +} + +#define vinit4(a,i,j,k,w) {\ + (a)[0]=i;\ + (a)[1]=j;\ + (a)[2]=k;\ + (a)[3]=w;\ +} + + +#define vadds(a,dt,b) {\ + (a)[0]+=(dt)*(b)[0];\ + (a)[1]+=(dt)*(b)[1];\ + (a)[2]+=(dt)*(b)[2];\ +} + +#define vequ(a,b) {\ + (a)[0]=(b)[0];\ + (a)[1]=(b)[1];\ + (a)[2]=(b)[2];\ +} + +#define vinter(a,dt,b,c) {\ + (a)[0]=(dt)*(b)[0]+(1.0-dt)*(c)[0];\ + (a)[1]=(dt)*(b)[1]+(1.0-dt)*(c)[1];\ + (a)[2]=(dt)*(b)[2]+(1.0-dt)*(c)[2];\ +} + +#define clamp(a) ((a) < 0.0 ? 0.0 : ((a) < 1.0 ? (a) : 1.0)) + +#define vclamp(v) {\ + (v)[0]=clamp((v)[0]);\ + (v)[1]=clamp((v)[1]);\ + (v)[2]=clamp((v)[2]);\ +} + +static int WIDTH = 640; +static int HEIGHT = 480; + +static GLint T0 = 0; +static GLint Frames = 0; +static GLint NiceFog = 1; + +#define DIMP 20.0 +#define DIMTP 16.0 + +#define RIDCOL 0.4 + +#define NUMTREE 50 +#define TREEINR 2.5 +#define TREEOUTR 8.0 + +#define AGRAV -9.8 + +typedef struct +{ + int age; + float p[3][3]; + float v[3]; + float c[3][4]; +} +part; + +static float treepos[NUMTREE][3]; + +static float black[3] = { 0.0, 0.0, 0.0 }; +static float blu[3] = { 1.0, 0.2, 0.0 }; +static float blu2[3] = { 1.0, 1.0, 0.0 }; + +static float fogcolor[4] = { 1.0, 1.0, 1.0, 1.0 }; + +static float q[4][3] = { + {-DIMP, 0.0, -DIMP}, + {DIMP, 0.0, -DIMP}, + {DIMP, 0.0, DIMP}, + {-DIMP, 0.0, DIMP} +}; + +static float qt[4][2] = { + {-DIMTP, -DIMTP}, + {DIMTP, -DIMTP}, + {DIMTP, DIMTP}, + {-DIMTP, DIMTP} +}; + +static int win = 0; + +static int np; +static float eject_r, dt, maxage, eject_vy, eject_vl; +static short shadows; +static float ridtri; +static int fog = 1; +static int help = 1; +static int joyavailable = 0; +static int joyactive = 0; + +static part *p; + +static GLuint groundid; +static GLuint treeid; + +static float obs[3] = { 2.0, 1.0, 0.0 }; +static float dir[3]; +static float v = 0.0; +static float alpha = -84.0; +static float beta = 90.0; + +static float +vrnd(void) +{ + return (((float) rand()) / RAND_MAX); +} + +static void +setnewpart(part * p) +{ + float a, v[3], *c; + + p->age = 0; + + a = vrnd() * 3.14159265359 * 2.0; + + vinit(v, sin(a) * eject_r * vrnd(), 0.15, cos(a) * eject_r * vrnd()); + vinit(p->p[0], v[0] + vrnd() * ridtri, v[1] + vrnd() * ridtri, + v[2] + vrnd() * ridtri); + vinit(p->p[1], v[0] + vrnd() * ridtri, v[1] + vrnd() * ridtri, + v[2] + vrnd() * ridtri); + vinit(p->p[2], v[0] + vrnd() * ridtri, v[1] + vrnd() * ridtri, + v[2] + vrnd() * ridtri); + + vinit(p->v, v[0] * eject_vl / (eject_r / 2), + vrnd() * eject_vy + eject_vy / 2, v[2] * eject_vl / (eject_r / 2)); + + c = blu; + + vinit4(p->c[0], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); + vinit4(p->c[1], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); + vinit4(p->c[2], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), + c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); +} + +static void +setpart(part * p) +{ + float fact; + + if (p->p[0][1] < 0.1) { + setnewpart(p); + return; + } + + p->v[1] += AGRAV * dt; + + vadds(p->p[0], dt, p->v); + vadds(p->p[1], dt, p->v); + vadds(p->p[2], dt, p->v); + + p->age++; + + if ((p->age) > maxage) { + vequ(p->c[0], blu2); + vequ(p->c[1], blu2); + vequ(p->c[2], blu2); + } + else { + fact = 1.0 / maxage; + vadds(p->c[0], fact, blu2); + vclamp(p->c[0]); + p->c[0][3] = fact * (maxage - p->age); + + vadds(p->c[1], fact, blu2); + vclamp(p->c[1]); + p->c[1][3] = fact * (maxage - p->age); + + vadds(p->c[2], fact, blu2); + vclamp(p->c[2]); + p->c[2][3] = fact * (maxage - p->age); + } +} + +static void +drawtree(float x, float y, float z) +{ + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex3f(x - 1.5, y + 0.0, z); + + glTexCoord2f(1.0, 0.0); + glVertex3f(x + 1.5, y + 0.0, z); + + glTexCoord2f(1.0, 1.0); + glVertex3f(x + 1.5, y + 3.0, z); + + glTexCoord2f(0.0, 1.0); + glVertex3f(x - 1.5, y + 3.0, z); + + + glTexCoord2f(0.0, 0.0); + glVertex3f(x, y + 0.0, z - 1.5); + + glTexCoord2f(1.0, 0.0); + glVertex3f(x, y + 0.0, z + 1.5); + + glTexCoord2f(1.0, 1.0); + glVertex3f(x, y + 3.0, z + 1.5); + + glTexCoord2f(0.0, 1.0); + glVertex3f(x, y + 3.0, z - 1.5); + + glEnd(); + +} + +static void +calcposobs(void) +{ + dir[0] = sin(alpha * M_PI / 180.0); + dir[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[1] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + obs[0] += v * dir[0]; + obs[1] += v * dir[1]; + obs[2] += v * dir[2]; +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +reshape(int width, int height) +{ + WIDTH = width; + HEIGHT = height; + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(70.0, width / (float) height, 0.1, 30.0); + + glMatrixMode(GL_MODELVIEW); +} + +static void +printhelp(void) +{ + glColor4f(0.0, 0.0, 0.0, 0.5); + glRecti(40, 40, 600, 440); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); + + glRasterPos2i(60, 360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Increase particle size"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "T - Decrease particle size"); + + glRasterPos2i(60, 300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "r - Increase emission radius"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "R - Decrease emission radius"); + + glRasterPos2i(60, 240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "s - Toggle shadows"); + glRasterPos2i(60, 180); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); + glRasterPos2i(60, 150); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); + glRasterPos2i(60, 120); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); + + glRasterPos2i(60, 90); + if (joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "(No Joystick control available)"); +} + +static void +dojoy(void) +{ +#ifdef WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha += + 2.5 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.5 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.01; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.01; + } + } + else + joyavailable = 0; +#endif +} + +static void +drawfire(void) +{ + static char frbuf[80] = ""; + int j; + static double t0 = -1.; + double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = (t - t0) * 1.0; + t0 = t; + + dojoy(); + + if (NiceFog) + glHint(GL_FOG_HINT, GL_NICEST); + else + glHint(GL_FOG_HINT, GL_DONT_CARE); + + glEnable(GL_DEPTH_TEST); + + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glDepthMask(GL_TRUE); + glClearColor(1.0, 1.0, 1.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + calcposobs(); + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 1.0, 0.0); + + glColor4f(1.0, 1.0, 1.0, 1.0); + + glEnable(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, groundid); +#if 1 + glBegin(GL_QUADS); + glTexCoord2fv(qt[0]); + glVertex3fv(q[0]); + glTexCoord2fv(qt[1]); + glVertex3fv(q[1]); + glTexCoord2fv(qt[2]); + glVertex3fv(q[2]); + glTexCoord2fv(qt[3]); + glVertex3fv(q[3]); + glEnd(); +#else + /* Subdivide the ground into a bunch of quads. This improves fog + * if GL_FOG_HINT != GL_NICEST + */ + { + float x, y; + float dx = 1.0, dy = 1.0; + glBegin(GL_QUADS); + for (y = -DIMP; y < DIMP; y += 1.0) { + for (x = -DIMP; x < DIMP; x += 1.0) { + glTexCoord2f(0, 0); glVertex3f(x, 0, y); + glTexCoord2f(1, 0); glVertex3f(x+dx, 0, y); + glTexCoord2f(1, 1); glVertex3f(x+dx, 0, y+dy); + glTexCoord2f(0, 1); glVertex3f(x, 0, y+dy); + } + } + glEnd(); + } +#endif + + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GEQUAL, 0.9); + + glBindTexture(GL_TEXTURE_2D, treeid); + for (j = 0; j < NUMTREE; j++) + drawtree(treepos[j][0], treepos[j][1], treepos[j][2]); + + glDisable(GL_TEXTURE_2D); + glDepthMask(GL_FALSE); + glDisable(GL_ALPHA_TEST); + + if (shadows) { + glBegin(GL_TRIANGLES); + for (j = 0; j < np; j++) { + glColor4f(black[0], black[1], black[2], p[j].c[0][3]); + glVertex3f(p[j].p[0][0], 0.1, p[j].p[0][2]); + + glColor4f(black[0], black[1], black[2], p[j].c[1][3]); + glVertex3f(p[j].p[1][0], 0.1, p[j].p[1][2]); + + glColor4f(black[0], black[1], black[2], p[j].c[2][3]); + glVertex3f(p[j].p[2][0], 0.1, p[j].p[2][2]); + } + glEnd(); + } + + glBegin(GL_TRIANGLES); + for (j = 0; j < np; j++) { + glColor4fv(p[j].c[0]); + glVertex3fv(p[j].p[0]); + + glColor4fv(p[j].c[1]); + glVertex3fv(p[j].p[1]); + + glColor4fv(p[j].c[2]); + glVertex3fv(p[j].p[2]); + + setpart(&p[j]); + } + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_ALPHA_TEST); + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(370, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "Fire V1.5 Written by David Bucciarelli ([email protected])"); + + if (help) + printhelp(); + + reshape(WIDTH, HEIGHT); + glPopMatrix(); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + + +static void +idle(void) +{ + glutPostRedisplay(); +} + + +static void +special(int key, int x, int y) +{ + switch (key) { + case GLUT_KEY_LEFT: + alpha += 2.0; + break; + case GLUT_KEY_RIGHT: + alpha -= 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } + glutPostRedisplay(); +} + +static void +key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + + case 'a': + v += 0.0005; + break; + case 'z': + v -= 0.0005; + break; + + case 'j': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + case 's': + shadows = !shadows; + break; + case 'R': + eject_r -= 0.03; + break; + case 'r': + eject_r += 0.03; + break; + case 't': + ridtri += 0.005; + break; + case 'T': + ridtri -= 0.005; + break; +#ifdef XMESA + case ' ': + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + fullscreen = (!fullscreen); + break; +#endif + case 'n': + NiceFog = !NiceFog; + printf("NiceFog %d\n", NiceFog); + break; + } + glutPostRedisplay(); +} + +static void +inittextures(void) +{ + GLenum gluerr; + GLubyte tex[128][128][4]; + + glGenTextures(1, &groundid); + glBindTexture(GL_TEXTURE_2D, groundid); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + if (!LoadRGBMipmaps("../images/s128.rgb", GL_RGB)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + glGenTextures(1, &treeid); + glBindTexture(GL_TEXTURE_2D, treeid); + + if (1) + { + int w, h; + GLenum format; + int x, y; + GLubyte *image = LoadRGBImage("../images/tree3.rgb", &w, &h, &format); + + if (!image) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + for (y = 0; y < 128; y++) + for (x = 0; x < 128; x++) { + tex[x][y][0] = image[(y + x * 128) * 3]; + tex[x][y][1] = image[(y + x * 128) * 3 + 1]; + tex[x][y][2] = image[(y + x * 128) * 3 + 2]; + if ((tex[x][y][0] == tex[x][y][1]) && + (tex[x][y][1] == tex[x][y][2]) && (tex[x][y][2] == 255)) + tex[x][y][3] = 0; + else + tex[x][y][3] = 255; + } + + if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA, + GL_UNSIGNED_BYTE, (GLvoid *) (tex)))) { + fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); + exit(-1); + } + } + else { + if (!LoadRGBMipmaps("../images/tree2.rgba", GL_RGBA)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +static void +inittree(void) +{ + int i; + float dist; + + for (i = 0; i < NUMTREE; i++) + do { + treepos[i][0] = vrnd() * TREEOUTR * 2.0 - TREEOUTR; + treepos[i][1] = 0.0; + treepos[i][2] = vrnd() * TREEOUTR * 2.0 - TREEOUTR; + dist = + sqrt(treepos[i][0] * treepos[i][0] + + treepos[i][2] * treepos[i][2]); + } while ((dist < TREEINR) || (dist > TREEOUTR)); +} + +int +main(int ac, char **av) +{ + int i; + + fprintf(stderr, + "Fire V1.5\nWritten by David Bucciarelli ([email protected])\n"); + + /* Default settings */ + + np = 800; + eject_r = -0.65; + dt = 0.015; + eject_vy = 4; + eject_vl = 1; + shadows = 1; + ridtri = 0.25; + + maxage = 1.0 / dt; + + if (ac == 2) + np = atoi(av[1]); + + if (ac == 4) { + WIDTH = atoi(av[2]); + HEIGHT = atoi(av[3]); + } + + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + if (!(win = glutCreateWindow("Fire"))) { + fprintf(stderr, "Error opening a window.\n"); + exit(-1); + } + + reshape(WIDTH, HEIGHT); + + inittextures(); + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP); + glFogfv(GL_FOG_COLOR, fogcolor); + glFogf(GL_FOG_DENSITY, 0.1); + + p = (part *) malloc(sizeof(part) * np); + + for (i = 0; i < np; i++) + setnewpart(&p[i]); + + inittree(); + + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutDisplayFunc(drawfire); + glutIdleFunc(idle); + glutReshapeFunc(reshape); + glutMainLoop(); + + return (0); +} diff --git a/progs/demos/fogcoord.c b/progs/demos/fogcoord.c new file mode 100644 index 00000000000..19a15f05b87 --- /dev/null +++ b/progs/demos/fogcoord.c @@ -0,0 +1,420 @@ +/* + * EXT_fog_coord. + * + * Based on glutskel.c by Brian Paul + * and NeHe's Volumetric fog tutorial! + * + * Daniel Borca + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define TEXTURE_FILE "../images/bw.rgb" + +#define ARRAYS 0 /* use glDrawElements */ + +#define VERBOSE 1 /* tell me what happens */ + +#define DEPTH 15.0f + +#if !defined(GLAPIENTRYP) +# define GLAPIENTRYP * +#endif + +typedef void (GLAPIENTRYP GLFOGCOORDFEXTPROC) (GLfloat f); +typedef void (GLAPIENTRYP GLFOGCOORDPOINTEREXTPROC) (GLenum, GLsizei, const GLvoid *); + +static GLFOGCOORDFEXTPROC glFogCoordf_ext; +#if ARRAYS +static GLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ext; +#endif +static GLboolean have_fog_coord; + +static GLfloat camz; +static GLuint texture[1]; + +static GLint fogMode; +static GLboolean fogCoord; +static GLfloat fogDensity = 0.75; +static GLfloat fogStart = 1.0, fogEnd = 40.0; +static GLfloat fogColor[4] = {0.6f, 0.3f, 0.0f, 1.0f}; + + +static void APIENTRY glFogCoordf_nop (GLfloat f) +{ + (void)f; +} + + +static int BuildTexture (const char *filename, GLuint texid[]) +{ + GLubyte *tex_data; + GLenum tex_format; + GLint tex_width, tex_height; + + tex_data = LoadRGBImage(filename, &tex_width, &tex_height, &tex_format); + if (tex_data == NULL) { + return -1; + } + + { + GLint tex_max; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tex_max); + if ((tex_width > tex_max) || (tex_height > tex_max)) { + return -1; + } + } + + glGenTextures(1, texid); + + glBindTexture(GL_TEXTURE_2D, texid[0]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, tex_format, tex_width, tex_height, 0, + tex_format, GL_UNSIGNED_BYTE, tex_data); + + return 0; +} + + +static int SetFogMode (GLint fogMode) +{ + fogMode &= 3; + switch (fogMode) { + case 0: + glDisable(GL_FOG); +#if VERBOSE + printf("fog(disable)\n"); +#endif + break; + case 1: + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, fogStart); + glFogf(GL_FOG_END, fogEnd); +#if VERBOSE + printf("fog(GL_LINEAR, %.2f, %.2f)\n", fogStart, fogEnd); +#endif + break; + case 2: + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP); + glFogf(GL_FOG_DENSITY, fogDensity); +#if VERBOSE + printf("fog(GL_EXP, %.2f)\n", fogDensity); +#endif + break; + case 3: + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogf(GL_FOG_DENSITY, fogDensity); +#if VERBOSE + printf("fog(GL_EXP2, %.2f)\n", fogDensity); +#endif + break; + } + return fogMode; +} + + +static GLboolean SetFogCoord (GLboolean fogCoord) +{ + glFogCoordf_ext = glFogCoordf_nop; + + if (!have_fog_coord) { +#if VERBOSE + printf("fog(GL_FRAGMENT_DEPTH_EXT)%s\n", fogCoord ? " EXT_fog_coord not available!" : ""); +#endif + return GL_FALSE; + } + + if (fogCoord) { + glFogCoordf_ext = (GLFOGCOORDFEXTPROC)glutGetProcAddress("glFogCoordfEXT"); + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); +#if VERBOSE + printf("fog(GL_FOG_COORDINATE_EXT)\n"); +#endif + } else { + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); +#if VERBOSE + printf("fog(GL_FRAGMENT_DEPTH_EXT)\n"); +#endif + } + return fogCoord; +} + + +#if ARRAYS +/* could reuse vertices */ +static GLuint vertex_index[] = { + /* Back */ + 0, 1, 2, 3, + + /* Floor */ + 4, 5, 6, 7, + + /* Roof */ + 8, 9, 10, 11, + + /* Right */ + 12, 13, 14, 15, + + /* Left */ + 16, 17, 18, 19 +}; + +static GLfloat vertex_pointer[][3] = { + /* Back */ + {-2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH}, { 2.5f, 2.5f,-DEPTH}, {-2.5f, 2.5f,-DEPTH}, + + /* Floor */ + {-2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f, DEPTH}, {-2.5f,-2.5f, DEPTH}, + + /* Roof */ + {-2.5f, 2.5f,-DEPTH}, { 2.5f, 2.5f,-DEPTH}, { 2.5f, 2.5f, DEPTH}, {-2.5f, 2.5f, DEPTH}, + + /* Right */ + { 2.5f,-2.5f, DEPTH}, { 2.5f, 2.5f, DEPTH}, { 2.5f, 2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH}, + + /* Left */ + {-2.5f,-2.5f, DEPTH}, {-2.5f, 2.5f, DEPTH}, {-2.5f, 2.5f,-DEPTH}, {-2.5f,-2.5f,-DEPTH} +}; + +static GLfloat texcoord_pointer[][2] = { + /* Back */ + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, + + /* Floor */ + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, + + /* Roof */ + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, + + /* Right */ + {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, + + /* Left */ + {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f} +}; + +static GLfloat fogcoord_pointer[][1] = { + /* Back */ + {1.0f}, {1.0f}, {1.0f}, {1.0f}, + + /* Floor */ + {1.0f}, {1.0f}, {0.0f}, {0.0f}, + + /* Roof */ + {1.0f}, {1.0f}, {0.0f}, {0.0f}, + + /* Right */ + {0.0f}, {0.0f}, {1.0f}, {1.0f}, + + /* Left */ + {0.0f}, {0.0f}, {1.0f}, {1.0f} +}; +#endif + + +static void Display( void ) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity (); + + glTranslatef(0.0f, 0.0f, camz); + +#if ARRAYS + glDrawElements(GL_QUADS, sizeof(vertex_index) / sizeof(vertex_index[0]), GL_UNSIGNED_INT, vertex_index); +#else + /* Back */ + glBegin(GL_QUADS); + glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f,-DEPTH); + glEnd(); + + /* Floor */ + glBegin(GL_QUADS); + glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f,-2.5f, DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f,-2.5f, DEPTH); + glEnd(); + + /* Roof */ + glBegin(GL_QUADS); + glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f, 2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f, 2.5f,-DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f, DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f, DEPTH); + glEnd(); + + /* Right */ + glBegin(GL_QUADS); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 2.5f,-2.5f, DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 2.5f, 2.5f, DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH); + glEnd(); + + /* Left */ + glBegin(GL_QUADS); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f, DEPTH); + glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f, DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-2.5f, 2.5f,-DEPTH); + glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH); + glEnd(); +#endif + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0f, (GLfloat)(width)/(GLfloat)(height), 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 'f': + fogMode = SetFogMode(fogMode + 1); + break; + case '+': + if (fogDensity < 1.0) { + fogDensity += 0.05; + } + SetFogMode(fogMode); + break; + case '-': + if (fogDensity > 0.0) { + fogDensity -= 0.05; + } + SetFogMode(fogMode); + break; + case 's': + if (fogStart > 0.0) { + fogStart -= 1.0; + } + SetFogMode(fogMode); + break; + case 'S': + if (fogStart < fogEnd) { + fogStart += 1.0; + } + SetFogMode(fogMode); + break; + case 'e': + if (fogEnd > fogStart) { + fogEnd -= 1.0; + } + SetFogMode(fogMode); + break; + case 'E': + if (fogEnd < 100.0) { + fogEnd += 1.0; + } + SetFogMode(fogMode); + break; + case 'c': + fogCoord = SetFogCoord(fogCoord ^ GL_TRUE); + 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: + if (camz < (DEPTH - 1.0)) { + camz += 1.0f; + } + break; + case GLUT_KEY_DOWN: + if (camz > -19.0) { + camz -= 1.0f; + } + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + have_fog_coord = glutExtensionSupported("GL_EXT_fog_coord"); + + if (BuildTexture(TEXTURE_FILE, texture) == -1) { + exit(1); + } + + glEnable(GL_TEXTURE_2D); + glClearColor(0.0f, 0.0f, 0.0f, 0.5f); + glClearDepth(1.0f); + glDepthFunc(GL_LEQUAL); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + glFogfv(GL_FOG_COLOR, fogColor); + glHint(GL_FOG_HINT, GL_NICEST); + fogCoord = SetFogCoord(GL_TRUE); /* try to enable fog_coord */ + fogMode = SetFogMode(2); /* GL_EXP */ + + camz = -19.0f; + +#if ARRAYS + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, vertex_pointer); + + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, texcoord_pointer); + + if (have_fog_coord) { + glFogCoordPointer_ext = (GLFOGCOORDPOINTEREXTPROC)glutGetProcAddress("glFogCoordPointerEXT"); + glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT); + glFogCoordPointer_ext(GL_FLOAT, 0, fogcoord_pointer); + } +#endif +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 640, 480 ); + 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/demos/fplight.c b/progs/demos/fplight.c new file mode 100644 index 00000000000..c7a38248d38 --- /dev/null +++ b/progs/demos/fplight.c @@ -0,0 +1,285 @@ +/* + * Use GL_NV_fragment_program to implement per-pixel lighting. + * + * Brian Paul + * 7 April 2003 + */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + + +static GLfloat Diffuse[4] = { 0.5, 0.5, 1.0, 1.0 }; +static GLfloat Specular[4] = { 0.8, 0.8, 0.8, 1.0 }; +static GLfloat LightPos[4] = { 0.0, 10.0, 20.0, 1.0 }; +static GLfloat Delta = 1.0; + +static GLuint FragProg; +static GLuint VertProg; +static GLboolean Anim = GL_TRUE; +static GLboolean Wire = GL_FALSE; +static GLboolean PixelLight = GL_TRUE; + +static GLfloat Xrot = 0, Yrot = 0; + + +#define NAMED_PARAMETER4FV(prog, name, v) \ + glProgramNamedParameter4fvNV(prog, strlen(name), (const GLubyte *) name, v) + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + if (PixelLight) { +#if defined(GL_NV_fragment_program) + NAMED_PARAMETER4FV(FragProg, "LightPos", LightPos); + glEnable(GL_FRAGMENT_PROGRAM_NV); + glEnable(GL_VERTEX_PROGRAM_NV); +#endif + glDisable(GL_LIGHTING); + } + else { + glLightfv(GL_LIGHT0, GL_POSITION, LightPos); +#if defined(GL_NV_fragment_program) + glDisable(GL_FRAGMENT_PROGRAM_NV); + glDisable(GL_VERTEX_PROGRAM_NV); +#endif + glEnable(GL_LIGHTING); + } + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + +#if 1 + glutSolidSphere(2.0, 10, 5); +#else + { + GLUquadricObj *q = gluNewQuadric(); + gluQuadricNormals(q, GL_SMOOTH); + gluQuadricTexture(q, GL_TRUE); + glRotatef(90, 1, 0, 0); + glTranslatef(0, 0, -1); + gluCylinder(q, 1.0, 1.0, 2.0, 24, 1); + gluDeleteQuadric(q); + } +#endif + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Idle(void) +{ + LightPos[0] += Delta; + if (LightPos[0] > 25.0) + Delta = -1.0; + else if (LightPos[0] <- 25.0) + Delta = 1.0; + glutPostRedisplay(); +} + + +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 ); + /*glOrtho( -2.0, 2.0, -2.0, 2.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 ' ': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'x': + LightPos[0] -= 1.0; + break; + case 'X': + LightPos[0] += 1.0; + break; + case 'w': + Wire = !Wire; + if (Wire) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + break; + case 'p': + PixelLight = !PixelLight; + if (PixelLight) { + printf("Per-pixel lighting\n"); + } + else { + printf("Conventional lighting\n"); + } + 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 ) +{ + static const char *fragProgramText = + "!!FP1.0\n" + "DECLARE Diffuse; \n" + "DECLARE Specular; \n" + "DECLARE LightPos; \n" + + "# Compute normalized LightPos, put it in R0\n" + "DP3 R0.x, LightPos, LightPos;\n" + "RSQ R0.y, R0.x;\n" + "MUL R0, LightPos, R0.y;\n" + + "# Compute normalized normal, put it in R1\n" + "DP3 R1, f[TEX0], f[TEX0]; \n" + "RSQ R1.y, R1.x;\n" + "MUL R1, f[TEX0], R1.y;\n" + + "# Compute dot product of light direction and normal vector\n" + "DP3_SAT R2, R0, R1;" + + "MUL R3, Diffuse, R2; # diffuse attenuation\n" + + "POW R4, R2.x, {20.0}.x; # specular exponent\n" + + "MUL R5, Specular, R4; # specular attenuation\n" + + "ADD o[COLR], R3, R5; # add diffuse and specular colors\n" + "END \n" + ; + + static const char *vertProgramText = + "!!VP1.0\n" + "# typical modelview/projection transform\n" + "DP4 o[HPOS].x, c[0], v[OPOS] ;\n" + "DP4 o[HPOS].y, c[1], v[OPOS] ;\n" + "DP4 o[HPOS].z, c[2], v[OPOS] ;\n" + "DP4 o[HPOS].w, c[3], v[OPOS] ;\n" + "# transform normal by inv transpose of modelview, put in tex0\n" + "DP3 o[TEX0].x, c[4], v[NRML] ;\n" + "DP3 o[TEX0].y, c[5], v[NRML] ;\n" + "DP3 o[TEX0].z, c[6], v[NRML] ;\n" + "DP3 o[TEX0].w, c[7], v[NRML] ;\n" + "END\n"; + ; + + if (!glutExtensionSupported("GL_NV_vertex_program")) { + printf("Sorry, this demo requires GL_NV_vertex_program\n"); + exit(1); + } + if (!glutExtensionSupported("GL_NV_fragment_program")) { + printf("Sorry, this demo requires GL_NV_fragment_program\n"); + exit(1); + } + +#if defined(GL_NV_fragment_program) + glGenProgramsNV(1, &FragProg); + assert(FragProg > 0); + glGenProgramsNV(1, &VertProg); + assert(VertProg > 0); + + /* + * Fragment program + */ + glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, FragProg, + strlen(fragProgramText), + (const GLubyte *) fragProgramText); + assert(glIsProgramNV(FragProg)); + glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, FragProg); + + NAMED_PARAMETER4FV(FragProg, "Diffuse", Diffuse); + NAMED_PARAMETER4FV(FragProg, "Specular", Specular); + + /* + * Vertex program + */ + glLoadProgramNV(GL_VERTEX_PROGRAM_NV, VertProg, + strlen(vertProgramText), + (const GLubyte *) vertProgramText); + assert(glIsProgramNV(VertProg)); + glBindProgramNV(GL_VERTEX_PROGRAM_NV, VertProg); + glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV); + glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4, GL_MODELVIEW, GL_INVERSE_TRANSPOSE_NV); +#endif + + /* + * Misc init + */ + glClearColor(0.3, 0.3, 0.3, 0.0); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("Press p to toggle between per-pixel and per-vertex lighting\n"); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 200, 200 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/gamma.c b/progs/demos/gamma.c new file mode 100644 index 00000000000..9b2c3e1052b --- /dev/null +++ b/progs/demos/gamma.c @@ -0,0 +1,162 @@ + +/* 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 */ + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +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); + GLfloat t = d * 0.25; + + glColor3f(r*t, g*t, b*t); /* 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/gearbox.c b/progs/demos/gearbox.c new file mode 100644 index 00000000000..3a1662cd625 --- /dev/null +++ b/progs/demos/gearbox.c @@ -0,0 +1,485 @@ +/* + * Use glCopyTexSubImage2D to draw animated gears on the sides of a box. + * + * Brian Paul + * 27 January 2006 + */ + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <GL/glut.h> + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +static GLint WinWidth = 800, WinHeight = 500; +static GLint TexWidth, TexHeight; +static GLuint TexObj = 1; +static GLenum IntFormat = GL_RGB; + +static GLboolean WireFrame = GL_FALSE; + +static GLint T0 = 0; +static GLint Frames = 0; +static GLint Win = 0; + +static GLfloat ViewRotX = 20.0, ViewRotY = 30.0, ViewRotZ = 0.0; +static GLint Gear1, Gear2, Gear3; +static GLfloat GearRot = 0.0; +static GLfloat CubeRot = 0.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 void +cleanup(void) +{ + glDeleteTextures(1, &TexObj); + glDeleteLists(Gear1, 1); + glDeleteLists(Gear2, 1); + glDeleteLists(Gear3, 1); + glutDestroyWindow(Win); +} + + +static void +DrawGears(void) +{ + if (WireFrame) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + + glPushMatrix(); + glRotatef(20/*ViewRotX*/, 1.0, 0.0, 0.0); + glRotatef(ViewRotY, 0.0, 1.0, 0.0); + glRotatef(ViewRotZ, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(GearRot, 0.0, 0.0, 1.0); + glCallList(Gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * GearRot - 9.0, 0.0, 0.0, 1.0); + glCallList(Gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * GearRot - 25.0, 0.0, 0.0, 1.0); + glCallList(Gear3); + glPopMatrix(); + + glPopMatrix(); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +} + + +static void +DrawCube(void) +{ + static const GLfloat texcoords[4][2] = { + { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } + }; + static const GLfloat vertices[4][2] = { + { -1, -1 }, { 1, -1 }, { 1, 1 }, { -1, 1 } + }; + static const GLfloat xforms[6][4] = { + { 0, 0, 1, 0 }, + { 90, 0, 1, 0 }, + { 180, 0, 1, 0 }, + { 270, 0, 1, 0 }, + { 90, 1, 0, 0 }, + { -90, 1, 0, 0 } + }; + static const GLfloat mat[4] = { 1.0, 1.0, 0.5, 1.0 }; + GLint i, j; + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat); + glEnable(GL_TEXTURE_2D); + + glPushMatrix(); + glRotatef(ViewRotX, 1.0, 0.0, 0.0); + glRotatef(15, 1, 0, 0); + glRotatef(CubeRot, 0, 1, 0); + glScalef(4, 4, 4); + + for (i = 0; i < 6; i++) { + glPushMatrix(); + glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]); + glTranslatef(0, 0, 1.1); + glBegin(GL_POLYGON); + glNormal3f(0, 0, 1); + for (j = 0; j < 4; j++) { + glTexCoord2fv(texcoords[j]); + glVertex2fv(vertices[j]); + } + glEnd(); + glPopMatrix(); + } + glPopMatrix(); + + glDisable(GL_TEXTURE_2D); +} + + +static void +draw(void) +{ + float ar; + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); + + glDisable(GL_SCISSOR_TEST); + glClear(GL_DEPTH_BUFFER_BIT); + glEnable(GL_SCISSOR_TEST); + + /* draw gears */ + glViewport(0, 0, TexWidth, TexHeight); + glScissor(0, 0, TexWidth, TexHeight); + glClearColor(0.5, 0.5, 0.8, 0.0); + glClearColor(1, 1, 1, 0); + glClear(GL_COLOR_BUFFER_BIT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + + DrawGears(); + + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TexWidth, TexHeight); + + /* draw textured cube */ + glViewport(TexWidth, 0, WinWidth - TexWidth, WinHeight); + glScissor(TexWidth, 0, WinWidth - TexWidth, WinHeight); + glClearColor(0.5, 0.5, 0.8, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + ar = (float) (WinWidth - TexWidth) / WinHeight; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + + DrawCube(); + + /* finish up */ + 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 %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + } + } +} + + +static void +idle(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + /* fmod to prevent overflow */ + GearRot = fmod(GearRot + 70.0 * dt, 360.0); /* 70 deg/sec */ + CubeRot = fmod(CubeRot + 15.0 * dt, 360.0); /* 15 deg/sec */ + + glutPostRedisplay(); +} + + +/* change view angle, exit upon ESC */ +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 'w': + WireFrame = !WireFrame; + break; + case 'z': + ViewRotZ += 5.0; + break; + case 'Z': + ViewRotZ -= 5.0; + break; + case 27: /* Escape */ + cleanup(); + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* change view angle */ +static void +special(int k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case GLUT_KEY_UP: + ViewRotX += 5.0; + break; + case GLUT_KEY_DOWN: + ViewRotX -= 5.0; + break; + case GLUT_KEY_LEFT: + ViewRotY += 5.0; + break; + case GLUT_KEY_RIGHT: + ViewRotY -= 5.0; + break; + default: + return; + } + glutPostRedisplay(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + WinWidth = width; + WinHeight = height; +} + + +static void +init(int argc, char *argv[]) +{ + 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}; + GLint i; + + glLightfv(GL_LIGHT0, GL_POSITION, pos); +#if 0 + glEnable(GL_CULL_FACE); +#endif + 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); + + /* xxx make size dynamic */ + TexWidth = 256; + TexHeight = 256; + + glBindTexture(GL_TEXTURE_2D, TexObj); + glTexImage2D(GL_TEXTURE_2D, 0, IntFormat, TexWidth, TexHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + for ( i=1; i<argc; i++ ) { + if (strcmp(argv[i], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + } +} + + +static 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); + + glutInitWindowSize(WinWidth, WinHeight); + Win = glutCreateWindow("gearbox"); + init(argc, argv); + + 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/gears.c b/progs/demos/gears.c new file mode 100644 index 00000000000..ab9bc007421 --- /dev/null +++ b/progs/demos/gears.c @@ -0,0 +1,381 @@ +/* + * 3-D gear wheels. This program is in the public domain. + * + * Command line options: + * -info print GL implementation information + * -exit automatically exit after 30 seconds + * + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <GL/glut.h> + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +static GLint T0 = 0; +static GLint Frames = 0; +static GLint autoexit = 0; +static GLint win = 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 +cleanup(void) +{ + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + glutDestroyWindow(win); +} + +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 %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + if ((t >= 999.0 * autoexit) && (autoexit)) { + cleanup(); + exit(0); + } + } + } +} + + +static void +idle(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + angle += 70.0 * dt; /* 70 degrees per second */ + angle = fmod(angle, 360.0); /* prevents eventual overflow */ + + 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 */ + cleanup(); + 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(int argc, char *argv[]) +{ + 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}; + GLint i; + + 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); + + for ( i=1; i<argc; i++ ) { + if (strcmp(argv[i], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + else if ( strcmp(argv[i], "-exit")==0) { + autoexit = 30; + printf("Auto Exit after %i seconds.\n", autoexit ); + } + } +} + +static 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); + win = glutCreateWindow("Gears"); + init(argc, argv); + + 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/geartrain.c b/progs/demos/geartrain.c new file mode 100644 index 00000000000..3feb2a0524b --- /dev/null +++ b/progs/demos/geartrain.c @@ -0,0 +1,1073 @@ + +/* + * GearTrain Simulator * Version: 1.00 + * + * Copyright (C) 1999 Shobhan Kumar Dutta All Rights Reserved. + * <[email protected]> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SHOBHAN KUMAR DUTTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT + * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#include <math.h> +#include <stdlib.h> +#include <GL/glut.h> +#include <string.h> +#include <stdio.h> + +#ifndef min +#define min(x, y) ( x < y ? x : y ) +#endif + +#ifndef M_PI +#define M_PI 3.14159265 +#endif /* */ +typedef GLfloat TDA[4]; + +TDA background; + + +struct AXLE + { + char name[20]; + GLint id; + GLfloat radius; + GLint axis; + TDA color; + TDA position; + GLfloat length; + GLint motored; + GLfloat angular_velocity; + GLint direction; + }; + + +struct GEAR + { + char name[20]; + char type[7]; + GLint face; + GLint id; + GLfloat radius; + GLfloat width; + GLint teeth; + GLfloat tooth_depth; + GLfloat angle; + GLfloat angular_velocity; + TDA color; + GLint relative_position; + TDA position; + char axle_name[20]; + GLint axis; + GLint direction; + GLint motored; + }; + + +struct BELT + { + char name[20]; + GLint id; + char gear1_name[20]; + char gear2_name[20]; + }; + + +FILE * mainfile; +struct GEAR g[10]; +struct AXLE a[10]; +struct BELT b[10]; +int number_of_gears; +int number_of_axles; +int number_of_belts; + + +char Buf1[256], Buf2[256], Buf3[256], Buf4[256], Buf5[256]; + +static GLint T0 = 0; +static GLint Frames = 0; + + +#ifndef _WIN32 +static void +strset (char buf[], char ch) +{ + int i; + for (i = 0; i < strlen (buf); i++) + buf[i] = ch; +} +#endif + + +static void +Clear_Buffers () +{ + strset (Buf1, 0); + strset (Buf2, 0); + strset (Buf3, 0); + strset (Buf4, 0); + strset (Buf5, 0); +} + + +static void +LoadTriplet (TDA A) +{ + Clear_Buffers (); + fscanf (mainfile, "%s %s %s %s", Buf1, Buf2, Buf3, Buf4); + A[0] = atof (Buf2); + A[1] = atof (Buf3); + A[2] = atof (Buf4); +} + + +static void +LoadReal (float *a) +{ + Clear_Buffers (); + fscanf (mainfile, "%s %s", Buf1, Buf2); + *a = atof (Buf2); +} + + +static void +LoadInteger (int *a) +{ + Clear_Buffers (); + fscanf (mainfile, "%s %s", Buf1, Buf2); + *a = atoi (Buf2); +} + + +static void +LoadText (char *a) +{ + Clear_Buffers (); + fscanf (mainfile, "%s %s", Buf1, Buf2); + strcpy (a, Buf2); +} + + +static void +getdata (char filename[]) +{ + int gear_count = 0, axle_count = 0, belt_count = 0, i; + + mainfile = fopen (filename, "r"); + if (!mainfile) { + printf("Error: couldn't open %s\n", filename); + exit(-1); + } + + do + { + Clear_Buffers (); + fscanf (mainfile, "%s", Buf1); + if (ferror (mainfile)) + { + printf ("\nError opening file !\n"); + exit (1); + } + + if (!(strcmp (Buf1, "BACKGROUND"))) + LoadTriplet (background); + + if (!(strcmp (Buf1, "ANAME"))) + { + LoadText (a[axle_count].name); + axle_count++; + } + + if (!(strcmp (Buf1, "ARADIUS"))) + LoadReal (&a[axle_count - 1].radius); + + if (!(strcmp (Buf1, "AAXIS"))) + LoadInteger (&a[axle_count - 1].axis); + + if (!(strcmp (Buf1, "ACOLOR"))) + LoadTriplet (a[axle_count - 1].color); + + if (!(strcmp (Buf1, "APOSITION"))) + LoadTriplet (a[axle_count - 1].position); + + if (!(strcmp (Buf1, "ALENGTH"))) + LoadReal (&a[axle_count - 1].length); + + if (!(strcmp (Buf1, "AMOTORED"))) + LoadInteger (&a[axle_count - 1].motored); + + if (!(strcmp (Buf1, "AANGULARVELOCITY"))) + LoadReal (&a[axle_count - 1].angular_velocity); + + if (!(strcmp (Buf1, "ADIRECTION"))) + LoadInteger (&a[axle_count - 1].direction); + + if (!(strcmp (Buf1, "GNAME"))) + { + LoadText (g[gear_count].name); + gear_count++; + } + + if (!(strcmp (Buf1, "GTYPE"))) + LoadText (g[gear_count - 1].type); + + if (!(strcmp (Buf1, "GFACE"))) + LoadInteger (&g[gear_count - 1].face); + + if (!(strcmp (Buf1, "GRADIUS"))) + LoadReal (&g[gear_count - 1].radius); + + if (!(strcmp (Buf1, "GWIDTH"))) + LoadReal (&g[gear_count - 1].width); + + if (!(strcmp (Buf1, "GTEETH"))) + LoadInteger (&g[gear_count - 1].teeth); + + if (!(strcmp (Buf1, "GTOOTHDEPTH"))) + LoadReal (&g[gear_count - 1].tooth_depth); + + if (!(strcmp (Buf1, "GCOLOR"))) + LoadTriplet (g[gear_count - 1].color); + + if (!(strcmp (Buf1, "GAXLE"))) + LoadText (g[gear_count - 1].axle_name); + + if (!(strcmp (Buf1, "GPOSITION"))) + LoadInteger (&g[gear_count - 1].relative_position); + + if (!(strcmp (Buf1, "BELTNAME"))) + { + LoadText (b[belt_count].name); + belt_count++; + } + + if (!(strcmp (Buf1, "GEAR1NAME"))) + LoadText (b[belt_count - 1].gear1_name); + + if (!(strcmp (Buf1, "GEAR2NAME"))) + LoadText (b[belt_count - 1].gear2_name); + } + + while (Buf1[0] != 0); + + for (i = 0; i < number_of_gears; i++) + { + g[i].axis = -1; + g[i].direction = 0; + g[i].angular_velocity = 0.0; + } + + number_of_gears = gear_count; + number_of_axles = axle_count; + number_of_belts = belt_count; + fclose (mainfile); +} + + +static void +axle (GLint j, GLfloat radius, GLfloat length) +{ + GLfloat angle, rad, incr = 10.0 * M_PI / 180.0; + + /* draw main cylinder */ + glBegin (GL_QUADS); + for (angle = 0.0; angle < 360.0; angle += 5.0) + { + rad = angle * M_PI / 180.0; + glNormal3f (cos (rad), sin (rad), 0.0); + glVertex3f (radius * cos (rad), radius * sin (rad), length / 2); + glVertex3f (radius * cos (rad), radius * sin (rad), -length / 2); + glVertex3f (radius * cos (rad + incr), radius * sin (rad + incr), -length / 2); + glVertex3f (radius * cos (rad + incr), radius * sin (rad + incr), length / 2); + } + glEnd (); + + /* draw front face */ + glNormal3f (0.0, 0.0, 1.0); + glBegin (GL_TRIANGLES); + for (angle = 0.0; angle < 360.0; angle += 5.0) + { + rad = angle * M_PI / 180.0; + glVertex3f (0.0, 0.0, length / 2); + glVertex3f (radius * cos (rad), radius * sin (rad), length / 2); + glVertex3f (radius * cos (rad + incr), radius * sin (rad + incr), length / 2); + glVertex3f (0.0, 0.0, length / 2); + } + glEnd (); + + /* draw back face */ + glNormal3f (0.0, 0.0, -1.0); + glBegin (GL_TRIANGLES); + for (angle = 0.0; angle <= 360.0; angle += 5.0) + { + rad = angle * M_PI / 180.0; + glVertex3f (0.0, 0.0, -length / 2); + glVertex3f (radius * cos (rad), radius * sin (rad), -length / 2); + glVertex3f (radius * cos (rad + incr), radius * sin (rad + incr), -length / 2); + glVertex3f (0.0, 0.0, -length / 2); + } + glEnd (); +} + + + +static void +gear (GLint j, char type[], GLfloat radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r1, r2; + GLfloat angle, da; + GLfloat u, v, len, fraction = 0.5; + GLfloat n = 1.0; + + r1 = radius - tooth_depth; + r2 = radius; + + da = 2.0 * M_PI / teeth / 4.0; + if (!g[j].face) + { + fraction = -0.5; + n = -1.0; + } + if (!(strcmp (type, "NORMAL"))) + { + fraction = 0.5; + n = 1.0; + } + + /* draw front face */ + if (!(strcmp (type, "NORMAL"))) + { + glNormal3f (0.0, 0.0, 1.0 * n); + glBegin (GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0 * M_PI / teeth; + glVertex3f (0.0, 0.0, width * fraction); + glVertex3f (r1 * cos (angle), r1 * sin (angle), width * fraction); + glVertex3f (0.0, 0.0, width * fraction); + glVertex3f (r1 * cos (angle + 3 * da), r1 * sin (angle + 3 * da), width * fraction); + } + glEnd (); + } + else + { + glNormal3f (0.0, 0.0, 1.0 * n); + glBegin (GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0 * M_PI / teeth; + glVertex3f (0.0, 0.0, width * fraction); + glVertex3f ((r2 - width) * cos (angle), (r2 - width) * sin (angle), width * fraction); + glVertex3f (0.0, 0.0, width * fraction); + glVertex3f ((r2 - width) * cos (angle + 3 * da), (r2 - width) * sin (angle + 3 * da), width * fraction); + } + glEnd (); + } + + /* draw front sides of teeth */ + if (!(strcmp (type, "NORMAL"))) + { + glNormal3f (0.0, 0.0, 1.0 * n); + 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 * fraction); + glVertex3f (r2 * cos (angle + da), r2 * sin (angle + da), width * fraction); + glVertex3f (r2 * cos (angle + 2 * da), r2 * sin (angle + 2 * da), width * fraction); + glVertex3f (r1 * cos (angle + 3 * da), r1 * sin (angle + 3 * da), width * fraction); + } + glEnd (); + } + + glNormal3f (0.0, 0.0, -1.0 * n); + + /* 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 * fraction); + glVertex3f (0.0, 0.0, -width * fraction); + glVertex3f (r1 * cos (angle + 3 * da), r1 * sin (angle + 3 * da), -width * fraction); + glVertex3f (0.0, 0.0, -width * fraction); + } + glEnd (); + + /* draw back sides of teeth */ + glNormal3f (0.0, 0.0, -1.0 * n); + 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 * fraction); + glVertex3f (r2 * cos (angle + 2 * da), r2 * sin (angle + 2 * da), -width * fraction); + glVertex3f (r2 * cos (angle + da), r2 * sin (angle + da), -width * fraction); + glVertex3f (r1 * cos (angle), r1 * sin (angle), -width * fraction); + } + glEnd (); + + + /* draw outward faces of teeth */ + if (!(strcmp (type, "NORMAL"))) + { + 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 * fraction); + glVertex3f (r1 * cos (angle), r1 * sin (angle), -width * fraction); + 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 * fraction); + glVertex3f (r2 * cos (angle + da), r2 * sin (angle + da), -width * fraction); + glNormal3f (cos (angle), sin (angle), 0.0); + glVertex3f (r2 * cos (angle + 2 * da), r2 * sin (angle + 2 * da), width * fraction); + glVertex3f (r2 * cos (angle + 2 * da), r2 * sin (angle + 2 * da), -width * fraction); + 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 * fraction); + glVertex3f (r1 * cos (angle + 3 * da), r1 * sin (angle + 3 * da), -width * fraction); + glNormal3f (cos (angle), sin (angle), 0.0); + } + } + else + { + 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 * fraction); + glVertex3f (r1 * cos (angle), r1 * sin (angle), -width * fraction); + 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 - width) * cos (angle + da), (r2 - width) * sin (angle + da), width * fraction); + glVertex3f (r2 * cos (angle + da), r2 * sin (angle + da), -width * fraction); + glNormal3f (cos (angle), sin (angle), n); + glVertex3f ((r2 - width) * cos (angle + 2 * da), (r2 - width) * sin (angle + 2 * da), width * fraction); + glVertex3f (r2 * cos (angle + 2 * da), r2 * sin (angle + 2 * da), -width * fraction); + 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 * fraction); + glVertex3f (r1 * cos (angle + 3 * da), r1 * sin (angle + 3 * da), -width * fraction); + glNormal3f (cos (angle), sin (angle), n); + } + } + + glVertex3f (r1 * cos (0), r1 * sin (0), width * fraction); + glVertex3f (r1 * cos (0), r1 * sin (0), -width * fraction); + glEnd (); +} + + +static void +belt (struct GEAR g1, struct GEAR g2) +{ + GLfloat D, alpha, phi, angle, incr, width; + GLint indexes[3] = + { + 0, 0, 0 + }; + + GLfloat col[3] = + { + 0.0, 0.0, 0.0 + }; + + width = min (g1.width, g2.width); + D = sqrt (pow (g1.position[0] - g2.position[0], 2) + pow (g1.position[1] - g2.position[1], 2) + pow (g1.position[2] - g2.position[2], 2)); + alpha = acos ((g2.position[0] - g1.position[0]) / D); + phi = acos ((g1.radius - g2.radius) / D); + glBegin (GL_QUADS); + glColor3fv (col); + glMaterialiv (GL_FRONT, GL_COLOR_INDEXES, indexes); + incr = 1.2 * 360.0 / g1.teeth * M_PI / 180.00; + for (angle = alpha + phi; angle <= 2 * M_PI - phi + alpha; angle += 360.0 / g1.teeth * M_PI / 180.00) + { + glNormal3f (cos (angle), sin (angle), 0.0); + glVertex3f (g1.radius * cos (angle), g1.radius * sin (angle), width * 0.5); + glVertex3f (g1.radius * cos (angle), g1.radius * sin (angle), -width * 0.5); + glVertex3f (g1.radius * cos (angle + incr), g1.radius * sin (angle + incr), -width * 0.5); + glVertex3f (g1.radius * cos (angle + incr), g1.radius * sin (angle + incr), width * 0.5); + } + glEnd (); + glBegin (GL_QUADS); + glColor3fv (col); + glMaterialiv (GL_FRONT, GL_COLOR_INDEXES, indexes); + incr = 1.2 * 360.0 / g2.teeth * M_PI / 180.00; + for (angle = -phi + alpha; angle <= phi + alpha; angle += 360.0 / g1.teeth * M_PI / 180.0) + { + glNormal3f (cos (angle), sin (angle), 0.0); + glVertex3f (g2.radius * cos (angle) + g2.position[0] - g1.position[0], g2.radius * sin (angle) + g2.position[1] - g1.position[1], width * 0.5); + glVertex3f (g2.radius * cos (angle) + g2.position[0] - g1.position[0], g2.radius * sin (angle) + g2.position[1] - g1.position[1], width * -0.5); + glVertex3f (g2.radius * cos (angle + incr) + g2.position[0] - g1.position[0], g2.radius * sin (angle + incr) + g2.position[1] - g1.position[1], width * -0.5); + glVertex3f (g2.radius * cos (angle + incr) + g2.position[0] - g1.position[0], g2.radius * sin (angle + incr) + g2.position[1] - g1.position[1], width * 0.5); + } + glEnd (); + + glBegin (GL_QUADS); + glColor3fv (col); + glMaterialiv (GL_FRONT, GL_COLOR_INDEXES, indexes); + glVertex3f (g1.radius * cos (alpha + phi), g1.radius * sin (alpha + phi), width * 0.5); + glVertex3f (g1.radius * cos (alpha + phi), g1.radius * sin (alpha + phi), width * -0.5); + glVertex3f (g2.radius * cos (alpha + phi) + g2.position[0] - g1.position[0], g2.radius * sin (alpha + phi) + g2.position[1] - g1.position[1], width * -0.5); + glVertex3f (g2.radius * cos (alpha + phi) + g2.position[0] - g1.position[0], g2.radius * sin (alpha + phi) + g2.position[1] - g1.position[1], width * 0.5); + glVertex3f (g1.radius * cos (alpha - phi), g1.radius * sin (alpha - phi), width * 0.5); + glVertex3f (g1.radius * cos (alpha - phi), g1.radius * sin (alpha - phi), width * -0.5); + glVertex3f (g2.radius * cos (alpha - phi) + g2.position[0] - g1.position[0], g2.radius * sin (alpha - phi) + g2.position[1] - g1.position[1], width * -0.5); + glVertex3f (g2.radius * cos (alpha - phi) + g2.position[0] - g1.position[0], g2.radius * sin (alpha - phi) + g2.position[1] - g1.position[1], width * 0.5); + glEnd (); +} + + +static int +axle_find (char axle_name[]) +{ + int i; + + for (i = 0; i < number_of_axles; i++) + { + if (!(strcmp (axle_name, a[i].name))) + break; + } + return i; +} + + +static int +gear_find (char gear_name[]) +{ + int i; + + for (i = 0; i < number_of_gears; i++) + { + if (!(strcmp (gear_name, g[i].name))) + break; + } + return i; +} + + +static void +process () +{ + GLfloat x, y, z, D, dist; + GLint axle_index, i, j, g1, g2, k; + char error[80]; + + for (i = 0; i < number_of_gears; i++) + { + x = 0.0; + y = 0.0; + z = 0.0; + axle_index = axle_find (g[i].axle_name); + g[i].axis = a[axle_index].axis; + g[i].motored = a[axle_index].motored; + if (a[axle_index].motored) + { + g[i].direction = a[axle_index].direction; + g[i].angular_velocity = a[axle_index].angular_velocity; + } + if (g[i].axis == 0) + x = 1.0; + else if (g[i].axis == 1) + y = 1.0; + else + z = 1.0; + + g[i].position[0] = a[axle_index].position[0] + x * g[i].relative_position; + g[i].position[1] = a[axle_index].position[1] + y * g[i].relative_position; + g[i].position[2] = a[axle_index].position[2] + z * g[i].relative_position; + } + + for (k = 0; k < number_of_axles; k++) + { + for (i = 0; i < number_of_gears - 1; i++) + { + for (j = 0; j < number_of_gears; j++) + { + if (!(strcmp (g[i].type, g[j].type)) && (!(strcmp (g[i].type, "NORMAL"))) && ((strcmp (g[i].axle_name, g[j].axle_name) != 0)) && (g[i].axis == g[j].axis)) + { + D = sqrt (pow (g[i].position[0] - g[j].position[0], 2) + pow (g[i].position[1] - g[j].position[1], 2) + pow (g[i].position[2] - g[j].position[2], 2)); + if (D < 1.1 * (g[i].radius - g[i].tooth_depth + g[j].radius - g[j].tooth_depth)) + { + printf (error, "Gear %s and %s are too close to each other.", g[i].name, g[j].name); + + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + if (g[i].axis == 0) + { + dist = g[i].position[0] - g[j].position[0]; + } + else if (g[i].axis == 1) + { + dist = g[i].position[1] - g[j].position[1]; + } + else + dist = g[i].position[2] - g[j].position[2]; + + dist = fabs (dist); + + if (dist < (g[i].width / 2 + g[j].width / 2)) + { + if ((g[i].motored) && (!(g[j].motored)) && (D < 0.95 * (g[i].radius + g[j].radius))) + { + axle_index = axle_find (g[j].axle_name); + if ((a[axle_index].direction != 0) && (g[j].angular_velocity != g[i].angular_velocity * g[i].teeth / g[j].teeth * g[i].radius / g[j].radius)) + { + printf (error, "Error in tooth linkage of gears %s and %s.", g[i].name, g[j].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + g[j].motored = (a[axle_index].motored = 1); + g[j].direction = (a[axle_index].direction = -g[i].direction); + a[axle_index].angular_velocity = g[i].angular_velocity * g[i].teeth / g[j].teeth; + g[j].angular_velocity = (a[axle_index].angular_velocity *= g[i].radius / g[j].radius); + } + + if ((!(g[i].motored)) && (g[j].motored) && (D < 0.95 * (g[i].radius + g[j].radius))) + { + axle_index = axle_find (g[i].axle_name); + if ((a[axle_index].direction != 0) && (g[i].angular_velocity != g[j].angular_velocity * g[j].teeth / g[i].teeth * g[j].radius / g[i].radius)) + { + printf (error, "Error in tooth linkage of gears %s and %s.", g[i].name, g[j].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + g[i].motored = (a[axle_index].motored = 1); + g[i].direction = (a[axle_index].direction = -g[j].direction); + a[axle_index].angular_velocity = g[j].angular_velocity * g[j].teeth / g[i].teeth; + g[i].angular_velocity = (a[axle_index].angular_velocity *= g[j].radius / g[i].radius); + + } + } + } + + if (!(strcmp (g[i].type, g[j].type)) && (!(strcmp (g[i].type, "BEVEL"))) && ((strcmp (g[i].axle_name, g[j].axle_name) != 0)) && (g[i].axis != g[j].axis)) + { + D = sqrt (pow (g[i].position[0] - g[j].position[0], 2) + pow (g[i].position[1] - g[j].position[1], 2) + pow (g[i].position[2] - g[j].position[2], 2)); + if ((g[i].motored) && (!(g[j].motored)) && (D < 0.95 * sqrt (g[i].radius * g[i].radius + g[j].radius * g[j].radius))) + { + axle_index = axle_find (g[j].axle_name); + if ((a[axle_index].direction != 0) && (g[j].angular_velocity != g[i].angular_velocity * g[i].teeth / g[j].teeth * g[i].radius / g[j].radius)) + { + printf (error, "Error in tooth linkage of gears %s and %s.", g[i].name, g[j].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + g[j].motored = (a[axle_index].motored = 1); + g[j].direction = (a[axle_index].direction = -g[i].direction); + a[axle_index].angular_velocity = g[i].angular_velocity * g[i].teeth / g[j].teeth; + g[j].angular_velocity = (a[axle_index].angular_velocity *= g[i].radius / g[j].radius); + } + + + if ((!(g[i].motored)) && (g[j].motored) && (D < 0.95 * sqrt (g[i].radius * g[i].radius + g[j].radius * g[j].radius))) + { + axle_index = axle_find (g[i].axle_name); + if ((a[axle_index].direction != 0) && (g[i].angular_velocity != g[j].angular_velocity * g[j].teeth / g[i].teeth * g[j].radius / g[i].radius)) + { + printf (error, "Error in tooth linkage of gears %s and %s.", g[i].name, g[j].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + g[i].motored = (a[axle_index].motored = 1); + g[i].direction = (a[axle_index].direction = -g[j].direction); + a[axle_index].angular_velocity = g[j].angular_velocity * g[j].teeth / g[i].teeth; + g[i].angular_velocity = (a[axle_index].angular_velocity *= g[j].radius / g[i].radius); + } + } + } + } + + for (i = 0; i < number_of_gears; i++) + { + axle_index = axle_find (g[i].axle_name); + g[i].motored = a[axle_index].motored; + if (a[axle_index].motored) + { + g[i].direction = a[axle_index].direction; + g[i].angular_velocity = a[axle_index].angular_velocity; + } + } + + for (i = 0; i < number_of_belts; i++) + { + g1 = gear_find (b[i].gear1_name); + g2 = gear_find (b[i].gear2_name); + D = sqrt (pow (g[g1].position[0] - g[g2].position[0], 2) + pow (g[g1].position[1] - g[g2].position[1], 2) + pow (g[g1].position[2] - g[g2].position[2], 2)); + if (!((g[g1].axis == g[g2].axis) && (!strcmp (g[g1].type, g[g2].type)) && (!strcmp (g[g1].type, "NORMAL")))) + { + printf (error, "Belt %s invalid.", b[i].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + if ((g[g1].axis == g[g2].axis) && (!strcmp (g[g1].type, g[g2].type)) && (!strcmp (g[g1].type, "NORMAL"))) + { + /* + if((g[g1].motored)&&(g[g2].motored)) + if(g[g2].angular_velocity!=(g[g1].angular_velocity*g[g1].radius/g[g2].radius)) + { + printf(error,"Error in belt linkage of gears %s and %s".,g[g1].name,g[g2].name); + MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK); + exit(1); + } + */ + if (g[g1].axis == 0) + { + dist = g[g1].position[0] - g[g2].position[0]; + } + else if (g[i].axis == 1) + { + dist = g[g1].position[1] - g[g2].position[1]; + } + else + dist = g[g1].position[2] - g[g2].position[2]; + + dist = fabs (dist); + + if (dist > (g[g1].width / 2 + g[g2].width / 2)) + { + printf (error, "Belt %s invalid.", b[i].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + if (dist < (g[g1].width / 2 + g[g2].width / 2)) + { + if (D < g[g1].radius + g[g2].radius) + { + printf (error, "Gears %s and %s too close to be linked with belts", g[g1].name, g[g2].name); + /*MessageBox(NULL,error,windowName,MB_ICONEXCLAMATION|MB_OK);*/ + exit (1); + } + + if ((g[g1].motored) && (!(g[g2].motored))) + { + axle_index = axle_find (g[g2].axle_name); + g[g2].motored = (a[axle_index].motored = 1); + g[g2].direction = (a[axle_index].direction = g[g1].direction); + g[g2].angular_velocity = (a[axle_index].angular_velocity = g[g1].angular_velocity * g[g1].radius / g[g2].radius); + } + + if ((!(g[g1].motored)) && (g[g2].motored)) + { + axle_index = axle_find (g[g1].axle_name); + g[g1].motored = (a[axle_index].motored = 1); + g[g1].direction = (a[axle_index].direction = g[g2].direction); + g[g1].angular_velocity = (a[axle_index].angular_velocity = g[g2].angular_velocity * g[g2].radius / g[g1].radius); + } + } + } + } + + for (i = 0; i < number_of_gears; i++) + { + axle_index = axle_find (g[i].axle_name); + g[i].motored = a[axle_index].motored; + if (a[axle_index].motored) + { + g[i].direction = a[axle_index].direction; + g[i].angular_velocity = a[axle_index].angular_velocity; + } + } + } +} + + + +GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 10.0; + + +static void +draw (void) +{ + int i; + GLfloat x, y, z; + int index; + + 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); + + for (i = 0; i < number_of_gears; i++) + { + x = 0.0; + y = 0.0; + z = 0.0; + glPushMatrix (); +/*glTranslatef( -3.0, -2.0, 0.0 );*/ + glTranslatef (g[i].position[0], g[i].position[1], g[i].position[2]); + if (g[i].axis == 0) + y = 1.0; + else if (g[i].axis == 1) + x = 1.0; + else + z = 1.0; + + if (z != 1.0) + glRotatef (90.0, x, y, z); + + glRotatef (g[i].direction * g[i].angle, 0.0, 0.0, 1.0); + glCallList (g[i].id); + glPopMatrix (); + } + + for (i = 0; i < number_of_axles; i++) + { + x = 0.0; + y = 0.0; + z = 0.0; + glPushMatrix (); + glTranslatef (a[i].position[0], a[i].position[1], a[i].position[2]); + if (a[i].axis == 0) + y = 1.0; + else if (a[i].axis == 1) + x = 1.0; + else + z = 1.0; + + if (z != 1.0) + glRotatef (90.0, x, y, z); + + glCallList (a[i].id); + glPopMatrix (); + } + + for (i = 0; i < number_of_belts; i++) + { + x = 0.0; + y = 0.0; + z = 0.0; + glPushMatrix (); + index = gear_find (b[i].gear1_name); + glTranslatef (g[index].position[0], g[index].position[1], g[index].position[2]); + if (g[index].axis == 0) + y = 1.0; + else if (g[index].axis == 1) + x = 1.0; + else + z = 1.0; + + if (z != 1.0) + glRotatef (90.0, x, y, z); + + glCallList (b[i].id); + glPopMatrix (); + } + + glPopMatrix (); + glutSwapBuffers (); + + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + Frames++; + 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) +{ + int i; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + for (i = 0; i < number_of_gears; i++) + g[i].angle += g[i].angular_velocity * dt; + glutPostRedisplay(); +} + + + + +/* change view angle, exit upon ESC */ +static void +key (unsigned char k, int x, int y) +{ + switch (k) + { + case 'x': + view_rotx += 5.0; + break; + case 'X': + view_rotx -= 5.0; + break; + case 'y': + view_roty += 5.0; + break; + case 'Y': + view_roty -= 5.0; + break; + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case 0x1B: + 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 (); + if (width > height) + { + 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); + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + + + +static void +init (void) +{ + GLfloat matShine = 20.00F; + GLfloat light0Pos[4] = + { + 0.70F, 0.70F, 1.25F, 0.50F + }; + int i; + + glClearColor (background[0], background[1], background[2], 1.0F); + glClearIndex ((GLfloat) 0.0); + + glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, matShine); + glLightfv (GL_LIGHT0, GL_POSITION, light0Pos); + glEnable (GL_LIGHT0); + + glEnable (GL_LIGHTING); + glEnable (GL_DEPTH_TEST); + for (i = 0; i < number_of_gears; i++) + g[i].angle = 0.0; + + for (i = 0; i < number_of_gears; i++) + { + g[i].id = glGenLists (1); + glNewList (g[i].id, GL_COMPILE); + glColor3fv (g[i].color); + glMaterialfv (GL_FRONT, GL_SPECULAR, g[i].color); + gear (i, g[i].type, g[i].radius, g[i].width, g[i].teeth, g[i].tooth_depth); + glEndList (); + } + + for (i = 0; i < number_of_axles; i++) + { + a[i].id = glGenLists (1); + glNewList (a[i].id, GL_COMPILE); + glColor3fv (a[i].color); + glMaterialfv (GL_FRONT, GL_SPECULAR, a[i].color); + axle (i, a[i].radius, a[i].length); + glEndList (); + } + + for (i = 0; i < number_of_belts; i++) + { + b[i].id = glGenLists (1); + glNewList (b[i].id, GL_COMPILE); + belt (g[gear_find (b[i].gear1_name)], g[gear_find (b[i].gear2_name)]); + glEndList (); + } + + glEnable (GL_COLOR_MATERIAL); +} + + + +int +main (int argc, char *argv[]) +{ + char *file; + + if (argc < 2) + file = "geartrain.dat"; + else + file = argv[1]; + + glutInitWindowPosition (0, 0); + glutInitWindowSize(640,480); + glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); + + if (glutCreateWindow ("Gear Train Simulation") == GL_FALSE) + exit (1); + + getdata (file); + process (); + init (); + + glutDisplayFunc (draw); + glutReshapeFunc (reshape); + glutKeyboardFunc (key); + glutIdleFunc (idle); + glutMainLoop (); + return 0; +} diff --git a/progs/demos/geartrain.dat b/progs/demos/geartrain.dat new file mode 100644 index 00000000000..374de48bd5e --- /dev/null +++ b/progs/demos/geartrain.dat @@ -0,0 +1,119 @@ +BACKGROUND = 0.000 0.500 0.700
+
+ANAME = AXLE1
+ARADIUS = 1.000
+AAXIS = 2
+APOSITION = -7.000 0.000 0.000
+ACOLOR = 0.800 0.500 0.200
+ALENGTH = 6.000
+AMOTORED = 1
+AANGULARVELOCITY = 90.000
+ADIRECTION = 1
+
+ANAME = AXLE2
+ARADIUS = 1.000
+AAXIS = 2
+APOSITION = -3.000 0.000 0.000
+ACOLOR = 0.800 0.500 0.200
+ALENGTH = 12.000
+AMOTORED = 0
+
+ANAME = AXLE3
+ARADIUS = 1.000
+AAXIS = 2
+APOSITION = 1.000 0.000 0.000
+ACOLOR = 0.800 0.500 0.200
+ALENGTH = 6.000
+AMOTORED = 0
+
+ANAME = AXLE4
+ARADIUS = 1.000
+AAXIS = 2
+APOSITION = 8.000 0.000 0.000
+ACOLOR = 0.800 0.500 0.200
+ALENGTH = 18.000
+AMOTORED = 0
+
+ANAME = AXLE5
+ARADIUS = 1.000
+AAXIS = 1
+APOSITION = 8.000 -8.200 -7.400
+ACOLOR = 0.800 0.500 0.200
+ALENGTH = 12.000
+AMOTORED = 0
+
+GNAME = GEAR1
+GTYPE = NORMAL
+GRADIUS = 2.200
+GWIDTH = 3.000
+GTEETH = 40
+GTOOTHDEPTH = 0.500
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE1
+GPOSITION = 0.000
+
+GNAME = GEAR2
+GTYPE = NORMAL
+GRADIUS = 2.200
+GWIDTH = 3.000
+GTEETH = 30
+GTOOTHDEPTH = 0.500
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE2
+GPOSITION = 0.000
+
+GNAME = GEAR3
+GTYPE = NORMAL
+GRADIUS = 2.200
+GWIDTH = 3.000
+GTEETH = 20
+GTOOTHDEPTH = 0.500
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE3
+GPOSITION = 0.000
+
+GNAME = GEAR4
+GTYPE = NORMAL
+GRADIUS = 1.700
+GWIDTH = 1.000
+GTEETH = 20
+GTOOTHDEPTH = 0.500
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE2
+GPOSITION = 5.000
+
+GNAME = GEAR5
+GTYPE = NORMAL
+GRADIUS = 3.000
+GWIDTH = 1.000
+GTEETH = 20
+GTOOTHDEPTH = 0.500
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE4
+GPOSITION = 5.000
+
+GNAME = GEAR6
+GTYPE = BEVEL
+GFACE = 0
+GRADIUS = 4.000
+GWIDTH = 1.000
+GTEETH = 20
+GTOOTHDEPTH = 1.700
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE4
+GPOSITION = -4.000
+
+GNAME = GEAR7
+GTYPE = BEVEL
+GFACE = 0
+GRADIUS = 4.000
+GWIDTH = 1.000
+GTEETH = 20
+GTOOTHDEPTH = 1.700
+GCOLOR = 0.500 0.500 0.500
+GAXLE = AXLE5
+GPOSITION = 5.000
+
+BELTNAME = BELT1
+GEAR1NAME = GEAR5
+GEAR2NAME = GEAR4
diff --git a/progs/demos/glinfo.c b/progs/demos/glinfo.c new file mode 100644 index 00000000000..a6a7478288e --- /dev/null +++ b/progs/demos/glinfo.c @@ -0,0 +1,32 @@ + +/* + * Print GL, GLU and GLUT version and extension info + * + * Brian Paul This file in public domain. + * October 3, 1997 + */ + + +#include <stdio.h> +#include <GL/glut.h> + + +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/gloss.c b/progs/demos/gloss.c new file mode 100644 index 00000000000..9974f0dab2e --- /dev/null +++ b/progs/demos/gloss.c @@ -0,0 +1,460 @@ + +/* + * Specular reflection demo. The specular highlight is modulated by + * a sphere-mapped texture. The result is a high-gloss surface. + * NOTE: you really need hardware acceleration for this. + * Also note, this technique can't be implemented with multi-texture + * and separate specular color interpolation because there's no way + * to indicate that the second texture unit (the reflection map) + * should modulate the specular color and not the base color. + * A future multi-texture extension could fix that. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul October 22, 1999 This program is in the public domain. + */ + + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" +#include "trackball.h" + + +#define SPECULAR_TEXTURE_FILE "../images/reflect.rgb" +#define BASE_TEXTURE_FILE "../images/tile.rgb" + +/* Menu items */ +#define DO_SPEC_TEXTURE 1 +#define OBJECT 2 +#define ANIMATE 3 +#define QUIT 100 + +/* for convolution */ +#define FILTER_SIZE 7 + +static GLint WinWidth = 500, WinHeight = 500; +static GLuint CylinderObj = 0; +static GLuint TeapotObj = 0; +static GLuint Object = 0; +static GLboolean Animate = GL_TRUE; + +static float CurQuat[4] = { 0, 0, 0, 1 }; + +static GLfloat Black[4] = { 0, 0, 0, 0 }; +static GLfloat White[4] = { 1, 1, 1, 1 }; +static GLfloat Diffuse[4] = { .3, .3, 1.0, 1.0 }; /* blue */ +static GLfloat Shininess = 6; + +static GLuint BaseTexture, SpecularTexture; +static GLboolean DoSpecTexture = GL_TRUE; + +static GLboolean ButtonDown = GL_FALSE; +static GLint ButtonX, ButtonY; + + +/* performance info */ +static GLint T0 = 0; +static GLint Frames = 0; + + +static void Idle( void ) +{ + static const float yAxis[3] = {0, 1, 0}; + static double t0 = -1.; + float quat[4]; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + axis_to_quat(yAxis, 2.0 * dt, quat); + add_quats(quat, CurQuat, CurQuat); + + glutPostRedisplay(); +} + + +static void Display( void ) +{ + GLfloat rot[4][4]; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + build_rotmatrix(rot, CurQuat); + glMultMatrixf(&rot[0][0]); + + /* First pass: diffuse lighting with base texture */ + glMaterialfv(GL_FRONT, GL_DIFFUSE, Diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, Black); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, BaseTexture); + glCallList(Object); + + /* Second pass: specular lighting with reflection texture */ + glEnable(GL_POLYGON_OFFSET_FILL); + glBlendFunc(GL_ONE, GL_ONE); /* add */ + glEnable(GL_BLEND); + glMaterialfv(GL_FRONT, GL_DIFFUSE, Black); + glMaterialfv(GL_FRONT, GL_SPECULAR, White); + if (DoSpecTexture) { + glBindTexture(GL_TEXTURE_2D, SpecularTexture); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } + else { + glDisable(GL_TEXTURE_2D); + } + glCallList(Object); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_BLEND); + glDisable(GL_POLYGON_OFFSET_FILL); + + glPopMatrix(); + + glutSwapBuffers(); + + if (Animate) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + Frames++; + 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 Reshape( int width, int height ) +{ + GLfloat h = 30.0; + GLfloat w = h * width / height; + WinWidth = width; + WinHeight = height; + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -w, w, -h, h, 150.0, 500.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -380.0 ); +} + + +static void ToggleAnimate(void) +{ + Animate = !Animate; + if (Animate) { + glutIdleFunc( Idle ); + T0 = glutGet(GLUT_ELAPSED_TIME); + Frames = 0; + } + else { + glutIdleFunc( NULL ); + } +} + + +static void ModeMenu(int entry) +{ + if (entry==ANIMATE) { + ToggleAnimate(); + } + else if (entry==DO_SPEC_TEXTURE) { + DoSpecTexture = !DoSpecTexture; + } + else if (entry==OBJECT) { + if (Object == TeapotObj) + Object = CylinderObj; + else + Object = TeapotObj; + } + else if (entry==QUIT) { + exit(0); + } + glutPostRedisplay(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 's': + Shininess--; + if (Shininess < 0.0) + Shininess = 0.0; + glMaterialf(GL_FRONT, GL_SHININESS, Shininess); + printf("Shininess = %g\n", Shininess); + break; + case 'S': + Shininess++; + if (Shininess > 128.0) + Shininess = 128.0; + glMaterialf(GL_FRONT, GL_SHININESS, Shininess); + printf("Shininess = %g\n", Shininess); + break; + case 'a': + case ' ': + ToggleAnimate(); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +MouseMotion(int x, int y) +{ + if (ButtonDown) { + float x0 = (2.0 * ButtonX - WinWidth) / WinWidth; + float y0 = (WinHeight - 2.0 * ButtonY) / WinHeight; + float x1 = (2.0 * x - WinWidth) / WinWidth; + float y1 = (WinHeight - 2.0 * y) / WinHeight; + float q[4]; + + trackball(q, x0, y0, x1, y1); + ButtonX = x; + ButtonY = y; + add_quats(q, CurQuat, CurQuat); + + glutPostRedisplay(); + } +} + + +static void +MouseButton(int button, int state, int x, int y) +{ + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { + ButtonDown = GL_TRUE; + ButtonX = x; + ButtonY = y; + } + else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { + ButtonDown = GL_FALSE; + } +} + + +static void Init( int argc, char *argv[] ) +{ + GLboolean convolve = GL_FALSE; + GLboolean fullscreen = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + else if (strcmp(argv[i], "-c")==0) { + convolve = GL_TRUE; + } + else if (strcmp(argv[i], "-f")==0) { + fullscreen = GL_TRUE; + } + } + + if (fullscreen) + glutFullScreen(); + + /* Cylinder object */ + { + static GLfloat height = 100.0; + static GLfloat radius = 40.0; + static GLint slices = 24; /* pie slices around Z axis */ + static GLint stacks = 10; /* subdivisions along length of cylinder */ + static GLint rings = 4; /* rings in the end disks */ + GLUquadricObj *q = gluNewQuadric(); + assert(q); + gluQuadricTexture(q, GL_TRUE); + + CylinderObj = glGenLists(1); + glNewList(CylinderObj, GL_COMPILE); + + glPushMatrix(); + glTranslatef(0.0, 0.0, -0.5 * height); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + /*glScalef(8.0, 4.0, 2.0);*/ + glMatrixMode(GL_MODELVIEW); + + /* cylinder */ + gluQuadricNormals(q, GL_SMOOTH); + gluQuadricTexture(q, GL_TRUE); + gluCylinder(q, radius, radius, height, slices, stacks); + + /* end cap */ + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glScalef(3.0, 3.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glTranslatef(0.0, 0.0, height); + gluDisk(q, 0.0, radius, slices, rings); + + /* other end cap */ + glTranslatef(0.0, 0.0, -height); + gluQuadricOrientation(q, GLU_INSIDE); + gluDisk(q, 0.0, radius, slices, rings); + + glPopMatrix(); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + + glEndList(); + gluDeleteQuadric(q); + } + + /* Teapot */ + { + TeapotObj = glGenLists(1); + glNewList(TeapotObj, GL_COMPILE); + + glFrontFace(GL_CW); + glutSolidTeapot(40.0); + glFrontFace(GL_CCW); + + glEndList(); + } + + /* show cylinder by default */ + Object = CylinderObj; + + + /* lighting */ + glEnable(GL_LIGHTING); + { + GLfloat pos[4] = { 3, 3, 3, 1 }; + glLightfv(GL_LIGHT0, GL_AMBIENT, Black); + glLightfv(GL_LIGHT0, GL_DIFFUSE, White); + glLightfv(GL_LIGHT0, GL_SPECULAR, White); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_LIGHT0); + glMaterialfv(GL_FRONT, GL_AMBIENT, Black); + glMaterialf(GL_FRONT, GL_SHININESS, Shininess); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + } + + /* Base texture */ + glGenTextures(1, &BaseTexture); + glBindTexture(GL_TEXTURE_2D, BaseTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (!LoadRGBMipmaps(BASE_TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", BASE_TEXTURE_FILE); + exit(1); + } + + /* Specular texture */ + glGenTextures(1, &SpecularTexture); + glBindTexture(GL_TEXTURE_2D, SpecularTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + if (convolve) { + /* use convolution to blur the texture to simulate a dull finish + * on the object. + */ + GLubyte *img; + GLenum format; + GLint w, h; + GLfloat filter[FILTER_SIZE][FILTER_SIZE][4]; + + for (h = 0; h < FILTER_SIZE; h++) { + for (w = 0; w < FILTER_SIZE; w++) { + const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE); + filter[h][w][0] = k; + filter[h][w][1] = k; + filter[h][w][2] = k; + filter[h][w][3] = k; + } + } + + glEnable(GL_CONVOLUTION_2D); + glConvolutionParameteri(GL_CONVOLUTION_2D, + GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); + glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA, + FILTER_SIZE, FILTER_SIZE, + GL_RGBA, GL_FLOAT, filter); + + img = LoadRGBImage(SPECULAR_TEXTURE_FILE, &w, &h, &format); + if (!img) { + printf("Error: couldn't load texture image file %s\n", + SPECULAR_TEXTURE_FILE); + exit(1); + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, + format, GL_UNSIGNED_BYTE, img); + free(img); + } + else { + /* regular path */ + if (!LoadRGBMipmaps(SPECULAR_TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", + SPECULAR_TEXTURE_FILE); + exit(1); + } + } + + /* misc */ + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glEnable(GL_NORMALIZE); + + glPolygonOffset( -1, -1 ); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0] ); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + glutMotionFunc(MouseMotion); + glutMouseFunc(MouseButton); + if (Animate) + glutIdleFunc( Idle ); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("Toggle Highlight", DO_SPEC_TEXTURE); + glutAddMenuEntry("Toggle Object", OBJECT); + glutAddMenuEntry("Toggle Animate", ANIMATE); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + Init(argc, argv); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c new file mode 100755 index 00000000000..4ee12928164 --- /dev/null +++ b/progs/demos/glslnoise.c @@ -0,0 +1,200 @@ +/* + * GLSL noise demo. + * + * Michal Krol + * 20 February 2006 + * + * Based on the original demo by: + * Stefan Gustavson ([email protected]) 2004, 2005 + */ + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> + +#ifdef WIN32 +#define GETPROCADDRESS(F) wglGetProcAddress(F) +#else +#define GETPROCADDRESS(F) glutGetProcAddress(F) +#endif + +static GLhandleARB fragShader; +static GLhandleARB vertShader; +static GLhandleARB program; + +static GLint uTime; + +static GLint t0 = 0; +static GLint frames = 0; + +static GLfloat u_time = 0.0f; + +static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; +static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; +static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; +static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; +static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; + +static void Redisplay (void) +{ + GLint t; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glUniform1fARB (uTime, 0.5f * u_time); + + glPushMatrix (); + glutSolidSphere (2.0, 20, 10); + glPopMatrix (); + + glutSwapBuffers(); + frames++; + + t = glutGet (GLUT_ELAPSED_TIME); + if (t - t0 >= 5000) { + GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; + GLfloat fps = frames / seconds; + printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + t0 = t; + frames = 0; + } +} + +static void Idle (void) +{ + u_time += 0.1f; + glutPostRedisplay (); +} + +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.0f, 0.0f, -15.0f); +} + +static void Key (unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch (key) + { + case 27: + exit(0); + break; + } + glutPostRedisplay (); +} + +static void Init (void) +{ + static const char *fragShaderText = + "uniform float time;\n" + "varying vec3 position;\n" + "void main () {\n" + " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n" + "}\n" + ; + static const char *vertShaderText = + "varying vec3 position;\n" + "void main () {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " position = 4.0 * gl_Vertex.xyz;\n" + "}\n" + ; + + if (!glutExtensionSupported ("GL_ARB_fragment_shader")) + { + printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shader_objects")) + { + printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shading_language_100")) + { + printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_vertex_shader")) + { + printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); + exit(1); + } + + glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) + GETPROCADDRESS("glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) + GETPROCADDRESS("glShaderSourceARB"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) + GETPROCADDRESS("glCompileShaderARB"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) + GETPROCADDRESS("glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) + GETPROCADDRESS("glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) + GETPROCADDRESS ("glLinkProgramARB"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) + GETPROCADDRESS("glUseProgramObjectARB"); + + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) + GETPROCADDRESS("glGetUniformLocationARB"); + glUniform1fARB = (PFNGLUNIFORM1FARBPROC) + GETPROCADDRESS("glUniform1fARB"); + + fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); + glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); + glCompileShaderARB (fragShader); + + vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); + glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); + glCompileShaderARB (vertShader); + + program = glCreateProgramObjectARB (); + glAttachObjectARB (program, fragShader); + glAttachObjectARB (program, vertShader); + glLinkProgramARB (program); + glUseProgramObjectARB (program); + + uTime = glGetUniformLocationARB (program, "time"); + + glClearColor (0.0f, 0.1f, 0.3f, 1.0f); + glEnable (GL_CULL_FACE); + glEnable (GL_DEPTH_TEST); + + printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER)); +} + +int main (int argc, char *argv[]) +{ + glutInit (&argc, argv); + glutInitWindowPosition ( 0, 0); + glutInitWindowSize (200, 200); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutCreateWindow (argv[0]); + glutReshapeFunc (Reshape); + glutKeyboardFunc (Key); + glutDisplayFunc (Redisplay); + glutIdleFunc (Idle); + Init (); + glutMainLoop (); + return 0; +} + diff --git a/progs/demos/gltestperf.c b/progs/demos/gltestperf.c new file mode 100644 index 00000000000..be953901014 --- /dev/null +++ b/progs/demos/gltestperf.c @@ -0,0 +1,580 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + +typedef struct +{ + char *name; + char *unit; + void (*init) (void); + int (*run) (int, int); + int type; + int numsize; + int size[10]; +} +benchmark; + +static int frontbuffer = 1; + +/***************************************************************************/ + +static void +init_test01(void) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, 639.5, -0.5, 479.5); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_FLAT); + glDisable(GL_DEPTH_TEST); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 0.0, 0.0); +} + +static int +test01(int size, int num) +{ + int x, y; + + glBegin(GL_POINTS); + for (y = 0; y < num; y++) + for (x = 0; x < 480; x++) + glVertex2i(x, x); + glEnd(); + + return 480 * num; +} + +/***************************************************************************/ + +static void +init_test02(void) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, 639.5, -0.5, 479.5); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glDisable(GL_DEPTH_TEST); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); +} + +static int +test02(int size, int num) +{ + int x, y; + + glBegin(GL_LINES); + for (y = 0; y < num; y++) + for (x = 0; x < size; x++) { + glColor3f(0.0, 1.0, y / (float) num); + glVertex2i(0, size - 1); + glColor3f(1.0, 0.0, x / (float) size); + glVertex2i(x, x); + } + glEnd(); + + return num * size; +} + +/***************************************************************************/ + +static void +init_test03(void) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +static int +test03(int size, int num) +{ + int x, y, z; + + glBegin(GL_TRIANGLES); + for (y = 0; y < num; y++) + for (x = 0; x < size; x += 5) { + z = num * size - (y * size + x); + glColor3f(0.0, 1.0, 0.0); + glVertex3i(0, x, z); + + glColor3f(1.0, 0.0, x / (float) size); + glVertex3i(size - 1 - x, 0, z); + + glColor3f(1.0, x / (float) size, 0.0); + glVertex3i(x, size - 1 - x, z); + } + glEnd(); + + return size * num / 5; +} + +/***************************************************************************/ + +static void +init_test04(void) +{ + int x, y; + GLubyte tex[128 * 128 * 3]; + GLenum gluerr; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, 1.0, -1000.0 * 480.0); + + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + for (y = 0; y < 128; y++) + for (x = 0; x < 128; x++) { + tex[(x + y * 128) * 3 + 0] = ((x % (128 / 4)) < (128 / 8)) ? 255 : 0; + tex[(x + y * 128) * 3 + 1] = ((y % (128 / 4)) < (128 / 8)) ? 255 : 0; + tex[(x + y * 128) * 3 + 2] = x; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB, + GL_UNSIGNED_BYTE, (GLvoid *) (&tex[0])))) { + fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable(GL_TEXTURE_2D); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +static int +test04(int size, int num) +{ + int x, y, z; + + glBegin(GL_TRIANGLES); + for (y = 0; y < num; y++) + for (x = 0; x < size; x += 5) { + z = num * size - (y * size + x); + glTexCoord2f(1.0, 1.0); + glColor3f(1.0, 0.0, 0.0); + glVertex3i(0, x, z); + + glTexCoord2f(0.0, 1.0); + glColor3f(0.0, 1.0, 0.0); + glVertex3i(size - 1 - x, 0, z); + + glTexCoord2f(1.0, 0.0); + glColor3f(0.0, 0.0, 1.0); + glVertex3i(x, size - 1 - x, z); + } + glEnd(); + + return num * size / 5; +} + +/***************************************************************************/ + +static void +init_test05(void) +{ + int x, y; + GLubyte tex[128 * 128 * 3]; + GLenum gluerr; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + for (y = 0; y < 128; y++) + for (x = 0; x < 128; x++) { + tex[(x + y * 128) * 3 + 0] = ((x % (128 / 4)) < (128 / 8)) ? 255 : 0; + tex[(x + y * 128) * 3 + 1] = ((y % (128 / 4)) < (128 / 8)) ? 255 : 0; + tex[(x + y * 128) * 3 + 2] = x; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB, + GL_UNSIGNED_BYTE, (GLvoid *) (&tex[0])))) { + fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable(GL_TEXTURE_2D); + + glDepthFunc(GL_ALWAYS); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +static int +test05(int size, int num) +{ + int y; + float v0[3], v1[3], v2[3], v3[3]; + float cv0[3], cv1[3], cv2[3], cv3[3]; + float tv0[3], tv1[3], tv2[3], tv3[3]; + + v0[0] = 320 - size / 2; + v0[1] = 240 - size / 2; + v0[2] = 0.0; + v1[0] = 320 + size / 2; + v1[1] = 240 - size / 2; + v1[2] = 0.0; + v2[0] = 320 - size / 2; + v2[1] = 240 + size / 2; + v2[2] = 0.0; + v3[0] = 320 + size / 2; + v3[1] = 240 + size / 2; + v3[2] = 0.0; + cv0[0] = 1.0; + cv0[1] = 0.0; + cv0[2] = 0.0; + cv1[0] = 1.0; + cv1[1] = 1.0; + cv1[2] = 0.0; + cv2[0] = 1.0; + cv2[1] = 0.0; + cv2[2] = 1.0; + cv3[0] = 1.0; + cv3[1] = 1.0; + cv3[2] = 1.0; + tv0[0] = 0.0; + tv0[1] = 0.0; + tv0[2] = 0.0; + tv1[0] = 1.0; + tv1[1] = 0.0; + tv1[2] = 0.0; + tv2[0] = 0.0; + tv2[1] = 1.0; + tv2[2] = 0.0; + tv3[0] = 1.0; + tv3[1] = 1.0; + tv3[2] = 0.0; + + glBegin(GL_TRIANGLE_STRIP); + for (y = 0; y < num; y++) { + glColor3fv(cv0); + glTexCoord2fv(tv0); + glVertex3fv(v0); + + glColor3fv(cv1); + glTexCoord2fv(tv1); + glVertex3fv(v1); + + glColor3fv(cv2); + glTexCoord2fv(tv2); + glVertex3fv(v2); + + glColor3fv(cv3); + glTexCoord2fv(tv3); + glVertex3fv(v3); + } + glEnd(); + + return 4 * num - 2; +} + +/***************************************************************************/ + +static void +init_test06(void) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(-0.5, 639.5, -0.5, 479.5); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + + glClearColor(0.0, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +static int +test06(int size, int num) +{ + int y; + + for (y = 0; y < num; y++) { + glClearColor(y / (float) num, 0.1, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + return num; +} + +/***************************************************************************/ + +#define BMARKS_TIME 5.0 + +#define NUM_BMARKS 6 + +/* 554 ~= sqrt(640*480) */ + +static benchmark bmarks[NUM_BMARKS] = { + {"Simple Points", "Pnts", init_test01, test01, 0, 0, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, + {"Smooth Lines", "Lins", init_test02, test02, 1, 5, + {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}}, + {"ZSmooth Triangles", "Tris", init_test03, test03, 1, 5, + {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}}, + {"ZSmooth Tex Blend Triangles", "Tris", init_test04, test04, 1, 5, + {480, 250, 100, 50, 25, 0, 0, 0, 0, 0}}, + {"ZSmooth Tex Blend TMesh Triangles", "Tris", init_test05, test05, 2, 8, + {400, 250, 100, 50, 25, 10, 5, 2, 0, 0}}, + {"Color/Depth Buffer Clears", "Clrs", init_test06, test06, 3, 0, + {554, 0, 0, 0, 0, 0, 0, 0, 0, 0}} +}; + +/***************************************************************************/ + +static void +dotest0param(benchmark * bmark) +{ + float stime, etime, dtime, tottime, maxtime, mintime; + int num, numelem, calibnum, j; + + glPushAttrib(GL_ALL_ATTRIB_BITS); + bmark->init(); + + stime = glutGet(GLUT_ELAPSED_TIME); + + dtime = 0.0; + calibnum = 0; + while (dtime < 2.0) { + bmark->run(0, 1); + glFinish(); + etime = glutGet(GLUT_ELAPSED_TIME); + dtime = (etime - stime) / 1000.0; + calibnum++; + } + glPopAttrib(); + + fprintf(stderr, "Elapsed time for the calibration test (%d): %f\n", + calibnum, dtime); + + num = (int) ((BMARKS_TIME / dtime) * calibnum); + + if (num < 1) + num = 1; + + fprintf(stderr, "Selected number of benchmark iterations: %d\n", num); + + mintime = HUGE_VAL; + maxtime = -HUGE_VAL; + + for (tottime = 0.0, j = 0; j < 5; j++) { + glPushAttrib(GL_ALL_ATTRIB_BITS); + bmark->init(); + + stime = glutGet(GLUT_ELAPSED_TIME); + numelem = bmark->run(0, num); + glFinish(); + etime = glutGet(GLUT_ELAPSED_TIME); + + glPopAttrib(); + + dtime = (etime - stime) / 1000.0; + tottime += dtime; + + fprintf(stderr, "Elapsed time for run %d: %f\n", j, dtime); + + if (dtime < mintime) + mintime = dtime; + if (dtime > maxtime) + maxtime = dtime; + } + + tottime -= mintime + maxtime; + + fprintf(stdout, "%s\n%f %s/sec", bmark->name, numelem / (tottime / 3.0), + bmark->unit); + + if (bmark->type == 3) + fprintf(stdout, ", MPixel Fill/sec: %f\n\n", + (numelem * bmark->size[0] * (float) bmark->size[0]) / + (1000000.0 * tottime / 3.0)); + else + fprintf(stdout, "\n\n"); +} + +/***************************************************************************/ + +static void +dotest1param(benchmark * bmark) +{ + float stime, etime, dtime, tottime, maxtime, mintime; + int num, numelem, calibnum, j, k; + + fprintf(stdout, "%s\n", bmark->name); + + for (j = 0; j < bmark->numsize; j++) { + fprintf(stderr, "Current size: %d\n", bmark->size[j]); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + bmark->init(); + + stime = glutGet(GLUT_ELAPSED_TIME); + + dtime = 0.0; + calibnum = 0; + while (dtime < 2.0) { + bmark->run(bmark->size[j], 1); + glFinish(); + etime = glutGet(GLUT_ELAPSED_TIME); + dtime = (etime - stime) / 1000.0; + calibnum++; + } + glPopAttrib(); + + fprintf(stderr, "Elapsed time for the calibration test (%d): %f\n", + calibnum, dtime); + + num = (int) ((BMARKS_TIME / dtime) * calibnum); + + if (num < 1) + num = 1; + + fprintf(stderr, "Selected number of benchmark iterations: %d\n", num); + + mintime = HUGE_VAL; + maxtime = -HUGE_VAL; + + for (numelem = 1, tottime = 0.0, k = 0; k < 5; k++) { + glPushAttrib(GL_ALL_ATTRIB_BITS); + bmark->init(); + + stime = glutGet(GLUT_ELAPSED_TIME); + numelem = bmark->run(bmark->size[j], num); + glFinish(); + etime = glutGet(GLUT_ELAPSED_TIME); + + glPopAttrib(); + + dtime = (etime - stime) / 1000.0; + tottime += dtime; + + fprintf(stderr, "Elapsed time for run %d: %f\n", k, dtime); + + if (dtime < mintime) + mintime = dtime; + if (dtime > maxtime) + maxtime = dtime; + } + + tottime -= mintime + maxtime; + + fprintf(stdout, "SIZE=%03d => %f %s/sec", bmark->size[j], + numelem / (tottime / 3.0), bmark->unit); + if (bmark->type == 2) + fprintf(stdout, ", MPixel Fill/sec: %f\n", + (numelem * bmark->size[j] * bmark->size[j] / 2) / + (1000000.0 * tottime / 3.0)); + else + fprintf(stdout, "\n"); + } + + fprintf(stdout, "\n\n"); +} + +/***************************************************************************/ + +static void +display(void) +{ + int i; + + if (frontbuffer) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + + for (i = 0; i < NUM_BMARKS; i++) { + fprintf(stderr, "Benchmark: %d\n", i); + + switch (bmarks[i].type) { + case 0: + case 3: + dotest0param(&bmarks[i]); + break; + case 1: + case 2: + dotest1param(&bmarks[i]); + break; + } + } + + exit(0); +} + +int +main(int ac, char **av) +{ + fprintf(stderr, "GLTest v1.0\nWritten by David Bucciarelli\n"); + + if (ac == 2) + frontbuffer = 0; + + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowPosition(0, 0); + glutInitWindowSize(640, 480); + glutCreateWindow("OpenGL/Mesa Performances"); + glutDisplayFunc(display); + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/glutfx.c b/progs/demos/glutfx.c new file mode 100644 index 00000000000..8bf55823897 --- /dev/null +++ b/progs/demos/glutfx.c @@ -0,0 +1,189 @@ + +/* + * 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. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +#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"); +#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/ipers.c b/progs/demos/ipers.c new file mode 100644 index 00000000000..6e153c04e15 --- /dev/null +++ b/progs/demos/ipers.c @@ -0,0 +1,712 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> + +#if defined (WIN32)|| defined(_WIN32) +#include <windows.h> +#include <mmsystem.h> +#endif + +#include <GL/glut.h> + +#include "readtex.h" + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +static int WIDTH = 640; +static int HEIGHT = 480; + +static GLint T0; +static GLint Frames; + +#define MAX_LOD 9 + +#define TEX_SKY_WIDTH 256 +#define TEX_SKY_HEIGHT TEX_SKY_WIDTH + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +#define FROM_NONE 0 +#define FROM_DOWN 1 +#define FROM_UP 2 +#define FROM_LEFT 3 +#define FROM_RIGHT 4 +#define FROM_FRONT 5 +#define FROM_BACK 6 + +static int win = 0; + +static float obs[3] = { 3.8, 0.0, 0.0 }; +static float dir[3]; +static float v = 0.0; +static float alpha = -90.0; +static float beta = 90.0; + +static int fog = 1; +static int bfcull = 1; +static int usetex = 1; +static int help = 1; +static int poutline = 0; +static int normext = 1; +static int joyavailable = 0; +static int joyactive = 0; +static int LODbias = 3; +static int maxdepth = MAX_LOD; + +static unsigned int totpoly = 0; + +static GLuint t1id, t2id; +static GLuint skydlist, LODdlist[MAX_LOD], LODnumpoly[MAX_LOD]; + +static void +initlight(void) +{ + GLfloat lspec[4] = { 1.0, 1.0, 1.0, 1.0 }; + static GLfloat lightpos[4] = { 30, 15.0, 30.0, 1.0 }; + + glLightfv(GL_LIGHT0, GL_POSITION, lightpos); + glLightfv(GL_LIGHT0, GL_SPECULAR, lspec); + + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 32.0); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, lspec); +} + +static void +initdlists(void) +{ + static int slicetable[MAX_LOD][2] = { + {21, 10}, + {18, 9}, + {15, 8}, + {12, 7}, + {9, 6}, + {7, 5}, + {5, 4}, + {4, 3}, + {3, 2} + }; + GLUquadricObj *obj; + int i, xslices, yslices; + + obj = gluNewQuadric(); + + skydlist = glGenLists(1); + glNewList(skydlist, GL_COMPILE); + glBindTexture(GL_TEXTURE_2D, t2id); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glColor3f(1.0f, 1.0f, 1.0f); + + gluQuadricDrawStyle(obj, GLU_FILL); + gluQuadricNormals(obj, GLU_NONE); + gluQuadricTexture(obj, GL_TRUE); + gluQuadricOrientation(obj, GLU_INSIDE); + gluSphere(obj, 40.0f, 18, 9); + + glEndList(); + + for (i = 0; i < MAX_LOD; i++) { + LODdlist[i] = glGenLists(1); + glNewList(LODdlist[i], GL_COMPILE); + + gluQuadricDrawStyle(obj, GLU_FILL); + gluQuadricNormals(obj, GLU_SMOOTH); + gluQuadricTexture(obj, GL_TRUE); + gluQuadricOrientation(obj, GLU_OUTSIDE); + xslices = slicetable[i][0]; + yslices = slicetable[i][1]; + gluSphere(obj, 1.0f, xslices, yslices); + LODnumpoly[i] = xslices * (yslices - 2) + 2 * (xslices - 1); + + glEndList(); + } +} + +static void +inittextures(void) +{ + GLubyte tsky[TEX_SKY_HEIGHT][TEX_SKY_WIDTH][3]; + GLuint x, y; + GLfloat fact; + GLenum gluerr; + + /* Brick */ + + glGenTextures(1, &t1id); + glBindTexture(GL_TEXTURE_2D, t1id); + + if (!LoadRGBMipmaps("../images/bw.rgb", 3)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + /* Sky */ + + glGenTextures(1, &t2id); + glBindTexture(GL_TEXTURE_2D, t2id); + + for (y = 0; y < TEX_SKY_HEIGHT; y++) + for (x = 0; x < TEX_SKY_WIDTH; x++) + if (y < TEX_SKY_HEIGHT / 2) { + fact = y / (GLfloat) (TEX_SKY_HEIGHT / 2); + tsky[y][x][0] = + (GLubyte) (255.0f * (0.1f * fact + 0.3f * (1.0f - fact))); + tsky[y][x][1] = + (GLubyte) (255.0f * (0.2f * fact + 1.0f * (1.0f - fact))); + tsky[y][x][2] = 255; + } + else { + tsky[y][x][0] = tsky[TEX_SKY_HEIGHT - y - 1][x][0]; + tsky[y][x][1] = tsky[TEX_SKY_HEIGHT - y - 1][x][1]; + tsky[y][x][2] = 255; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if ( + (gluerr = + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TEX_SKY_WIDTH, TEX_SKY_HEIGHT, + GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *) (tsky)))) { + fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +} + +static void +calcposobs(void) +{ + dir[0] = sin(alpha * M_PI / 180.0); + dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[2] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + obs[0] += v * dir[0]; + obs[1] += v * dir[1]; + obs[2] += v * dir[2]; +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_LEFT: + alpha -= 2.0; + break; + case GLUT_KEY_RIGHT: + alpha += 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: + exit(0); + break; + + case 'a': + v += 0.01; + break; + case 'z': + v -= 0.01; + break; + +#ifdef XMESA + case ' ': + fullscreen = (!fullscreen); + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + break; +#endif + + case '+': + LODbias--; + break; + case '-': + LODbias++; + break; + case 'j': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + case 't': + usetex = (!usetex); + break; + case 'n': + normext = (!normext); + break; + case 'b': + if (bfcull) { + glDisable(GL_CULL_FACE); + bfcull = 0; + } + else { + glEnable(GL_CULL_FACE); + bfcull = 1; + } + break; + case 'p': + if (poutline) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + poutline = 0; + usetex = 1; + } + else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + poutline = 1; + usetex = 0; + } + break; + } +} + +static void +reshape(int w, int h) +{ + WIDTH = w; + HEIGHT = h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(90.0, w / (float) h, 0.8, 100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, w, h); +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +printhelp(void) +{ + glEnable(GL_BLEND); + glColor4f(0.5, 0.5, 0.5, 0.5); + glRecti(40, 40, 600, 440); + glDisable(GL_BLEND); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); + glRasterPos2i(60, 360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); + glRasterPos2i(60, 300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); + glRasterPos2i(60, 240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); + glRasterPos2i(60, 180); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "p - Toggle Wire frame"); + glRasterPos2i(60, 150); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "n - Toggle GL_EXT_rescale_normal extension"); + glRasterPos2i(60, 120); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "+/- - Increase/decrease the Object maximum LOD"); + + glRasterPos2i(60, 90); + if (joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "(No Joystick control available)"); +} + +static void +dojoy(void) +{ +#ifdef _WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha -= + 2.0 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.0 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.01; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.01; + } + } + else + joyavailable = 0; +#endif +} + +static void +drawipers(int depth, int from) +{ + int lod; + + if (depth == maxdepth) + return; + + lod = depth + LODbias; + if (lod < 0) + lod = 0; + if (lod >= MAX_LOD) + return; + + switch (from) { + case FROM_NONE: + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_UP); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_LEFT); + drawipers(depth, FROM_RIGHT); + break; + case FROM_FRONT: + glPushMatrix(); + glTranslatef(0.0f, -1.5f, 0.0f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_UP); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_LEFT); + drawipers(depth, FROM_RIGHT); + glPopMatrix(); + break; + case FROM_BACK: + glPushMatrix(); + glTranslatef(0.0f, 1.5f, 0.0f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_UP); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_LEFT); + drawipers(depth, FROM_RIGHT); + glPopMatrix(); + break; + case FROM_LEFT: + glPushMatrix(); + glTranslatef(-1.5f, 0.0f, 0.0f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_UP); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_LEFT); + glPopMatrix(); + break; + case FROM_RIGHT: + glPushMatrix(); + glTranslatef(1.5f, 0.0f, 0.0f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_UP); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_RIGHT); + glPopMatrix(); + break; + case FROM_DOWN: + glPushMatrix(); + glTranslatef(0.0f, 0.0f, 1.5f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_DOWN); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_LEFT); + drawipers(depth, FROM_RIGHT); + glPopMatrix(); + break; + case FROM_UP: + glPushMatrix(); + glTranslatef(0.0f, 0.0f, -1.5f); + glScalef(0.5f, 0.5f, 0.5f); + + glCallList(LODdlist[lod]); + + depth++; + drawipers(depth, FROM_UP); + drawipers(depth, FROM_FRONT); + drawipers(depth, FROM_BACK); + drawipers(depth, FROM_LEFT); + drawipers(depth, FROM_RIGHT); + glPopMatrix(); + break; + } + + totpoly += LODnumpoly[lod]; +} + +static void +draw(void) +{ + static char frbuf[80] = ""; + static GLfloat alpha = 0.0f; + static GLfloat beta = 0.0f; + static float fr = 0.0; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + dojoy(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (usetex) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glPushMatrix(); + calcposobs(); + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 0.0, 1.0); + + /* Scene */ + glEnable(GL_DEPTH_TEST); + + glShadeModel(GL_SMOOTH); + glBindTexture(GL_TEXTURE_2D, t1id); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glColor3f(1.0f, 1.0f, 1.0f); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + + if (normext) + glEnable(GL_RESCALE_NORMAL_EXT); + else + glEnable(GL_NORMALIZE); + + glPushMatrix(); + glRotatef(alpha, 0.0f, 0.0f, 1.0f); + glRotatef(beta, 1.0f, 0.0f, 0.0f); + totpoly = 0; + drawipers(0, FROM_NONE); + glPopMatrix(); + + alpha += 4.f * dt; + beta += 2.4f * dt; + + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glShadeModel(GL_FLAT); + + if (normext) + glDisable(GL_RESCALE_NORMAL_EXT); + else + glDisable(GL_NORMALIZE); + + glCallList(skydlist); + + glPopMatrix(); + + /* Help Screen */ + + sprintf(frbuf, + "Frame rate: %0.2f LOD: %d Tot. poly.: %d Poly/sec: %.1f", + fr, LODbias, totpoly, totpoly * fr); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + glDisable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(350, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "IperS V1.0 Written by David Bucciarelli ([email protected])"); + + if (help) + printhelp(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + fr = Frames / seconds; + T0 = t; + Frames = 0; + } + } +} + +int +main(int ac, char **av) +{ + float fogcolor[4] = { 0.7, 0.7, 0.7, 1.0 }; + + fprintf(stderr, + "IperS V1.0\nWritten by David Bucciarelli ([email protected])\n"); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + if (!(win = glutCreateWindow("IperS"))) { + fprintf(stderr, "Error, couldn't open window\n"); + exit(-1); + } + + reshape(WIDTH, HEIGHT); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogfv(GL_FOG_COLOR, fogcolor); + + glFogf(GL_FOG_DENSITY, 0.006); + + glHint(GL_FOG_HINT, GL_NICEST); + + inittextures(); + initdlists(); + initlight(); + + glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); + glClear(GL_COLOR_BUFFER_BIT); + + calcposobs(); + + glutReshapeFunc(reshape); + glutDisplayFunc(draw); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutIdleFunc(draw); + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c new file mode 100644 index 00000000000..0710bc6047b --- /dev/null +++ b/progs/demos/isosurf.c @@ -0,0 +1,1125 @@ + +/* + * Display an isosurface of 3-D wind speed volume. + * + * Command line options: + * -info print GL implementation information + * + * Brian Paul This file in public domain. + */ + + +/* Keys: + * ===== + * + * - Arrow keys to rotate + * - 's' toggles smooth shading + * - 'l' toggles lighting + * - 'f' toggles fog + * - 'I' and 'i' zoom in and out + * - 'c' toggles a user clip plane + * - 'm' toggles colorful materials in GL_TRIANGLES modes. + * - '+' and '-' move the user clip plane + * + * Other options are available via the popup menu. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#ifdef _WIN32 +#include <windows.h> +#undef CLIP_MASK +#endif +#define GL_GLEXT_PROTOTYPES +#include "GL/glut.h" + +#include "readtex.h" +#define TEXTURE_FILE "../images/reflect.rgb" + +#define LIT 0x00000001 +#define UNLIT 0x00000002 +#define REFLECT 0x00000004 +#define POINT_FILTER 0x00000008 +#define LINEAR_FILTER 0x00000010 +#define GLVERTEX 0x00000020 +#define DRAW_ELTS 0x00000040 +#define DRAW_ARRAYS 0x00000080 +#define ARRAY_ELT 0x00000100 +#define LOCKED 0x00000200 +#define UNLOCKED 0x00000400 +#define IMMEDIATE 0x00000800 +#define DISPLAYLIST 0x00001000 +#define SHADE_SMOOTH 0x00002000 +#define SHADE_FLAT 0x00004000 +#define TRIANGLES 0x00008000 +#define STRIPS 0x00010000 +#define POINTS 0x00020000 +#define USER_CLIP 0x00040000 +#define NO_USER_CLIP 0x00080000 +#define MATERIALS 0x00100000 +#define NO_MATERIALS 0x00200000 +#define FOG 0x00400000 +#define NO_FOG 0x00800000 +#define QUIT 0x01000000 +#define GLINFO 0x02000000 +#define STIPPLE 0x04000000 +#define NO_STIPPLE 0x08000000 +#define POLYGON_FILL 0x10000000 +#define POLYGON_LINE 0x20000000 + +#define LIGHT_MASK (LIT|UNLIT|REFLECT) +#define FILTER_MASK (POINT_FILTER|LINEAR_FILTER) +#define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT) +#define DLIST_MASK (IMMEDIATE|DISPLAYLIST) +#define LOCK_MASK (LOCKED|UNLOCKED) +#define MATERIAL_MASK (MATERIALS|NO_MATERIALS) +#define PRIMITIVE_MASK (TRIANGLES|STRIPS|POINTS) +#define CLIP_MASK (USER_CLIP|NO_USER_CLIP) +#define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT) +#define FOG_MASK (FOG|NO_FOG) +#define STIPPLE_MASK (STIPPLE|NO_STIPPLE) +#define POLYGON_MASK (POLYGON_FILL|POLYGON_LINE) + +#define MAXVERTS 10000 +static GLint maxverts = MAXVERTS; +static float data[MAXVERTS][6]; +static float compressed_data[MAXVERTS][6]; +static float expanded_data[MAXVERTS*3][6]; +static GLuint indices[MAXVERTS]; +static GLuint tri_indices[MAXVERTS*3]; +static GLuint strip_indices[MAXVERTS]; +static GLfloat col[100][4]; +static GLint numverts, num_tri_verts, numuniq; + +static GLfloat xrot; +static GLfloat yrot; +static GLfloat dist; +static GLint state, allowed = ~0; +static GLboolean doubleBuffer = GL_TRUE; +static GLdouble plane[4]; +static GLuint surf1, dlist_state; + +static GLboolean PrintInfo = GL_FALSE; + + +static 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}; + + +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<maxverts) { + fscanf( f, "%f %f %f %f %f %f", + &data[numverts][0], &data[numverts][1], &data[numverts][2], + &data[numverts][3], &data[numverts][4], &data[numverts][5] ); + numverts++; + } + numverts--; + + printf("%d vertices, %d triangles\n", numverts, numverts-2); + fclose(f); +} + + + +static void print_flags( const char *msg, GLuint flags ) +{ + fprintf(stderr, + "%s (0x%x): %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + msg, flags, + (flags & GLVERTEX) ? "glVertex, " : "", + (flags & DRAW_ARRAYS) ? "glDrawArrays, " : "", + (flags & DRAW_ELTS) ? "glDrawElements, " : "", + (flags & ARRAY_ELT) ? "glArrayElement, " : "", + (flags & LOCKED) ? "locked arrays, " : "", + (flags & TRIANGLES) ? "GL_TRIANGLES, " : "", + (flags & STRIPS) ? "GL_TRIANGLE_STRIP, " : "", + (flags & POINTS) ? "GL_POINTS, " : "", + (flags & DISPLAYLIST) ? "as a displaylist, " : "", + (flags & LIT) ? "lit, " : "", + (flags & UNLIT) ? "unlit, " : "", + (flags & REFLECT) ? "reflect, " : "", + (flags & SHADE_FLAT) ? "flat-shaded, " : "", + (flags & USER_CLIP) ? "user_clip, " : "", + (flags & MATERIALS) ? "materials, " : "", + (flags & FOG) ? "fog, " : "", + (flags & STIPPLE) ? "stipple, " : "", + (flags & POLYGON_LINE) ? "polygon mode line, " : ""); +} + + + +struct data_idx { + float *data; + int idx; + int uniq_idx; +}; + + +#define COMPARE_FUNC( AXIS ) \ +static int compare_axis_##AXIS( const void *a, const void *b ) \ +{ \ + float t = ( (*(struct data_idx *)a).data[AXIS] - \ + (*(struct data_idx *)b).data[AXIS] ); \ + \ + if (t < 0) return -1; \ + if (t > 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(void) +{ + 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 void expand_arrays(void) +{ + int i; + int parity = 0; + for (i = 2 ; i < numverts ; i++, parity ^= 1) { + int v0 = i-2+parity; + int v1 = i-1-parity; + int v2 = i; + memcpy( expanded_data[(i-2)*3+0], data[v0], sizeof(data[0]) ); + memcpy( expanded_data[(i-2)*3+1], data[v1], sizeof(data[0]) ); + memcpy( expanded_data[(i-2)*3+2], data[v2], sizeof(data[0]) ); + } +} + +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; + int i, j; + + for (j=2;j<numverts;j++,parity^=1) { + if (parity) { + *v++ = indices[j-1]; + *v++ = indices[j-2]; + *v++ = indices[j]; + } else { + *v++ = indices[j-2]; + *v++ = indices[j-1]; + *v++ = indices[j]; + } + } + + num_tri_verts = v - tri_indices; + printf("num_tri_verts: %d\n", num_tri_verts); + + for (i = j = 0 ; i < num_tri_verts ; i += 600, j++) { + col[j][3] = 1; + col[j][2] = myrand(1); + col[j][1] = myrand(1); + col[j][0] = myrand(1); + } + + for (i = 0; i < numverts ; i++) + strip_indices[i] = i; +} + +#define MIN(x,y) (x < y) ? x : y + +static void draw_surface( unsigned int with_state ) +{ + GLint i, j; + + if (with_state & DISPLAYLIST) { + if ((with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|MATERIAL_MASK)) != + dlist_state) { + /* + */ + fprintf(stderr, "rebuilding displaylist\n"); + + if (dlist_state) + glDeleteLists( surf1, 1 ); + + dlist_state = with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK| + MATERIAL_MASK); + surf1 = glGenLists(1); + glNewList(surf1, GL_COMPILE); + draw_surface( dlist_state ); + glEndList(); + } + + glCallList( surf1 ); + return; + } + + switch (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) { +#ifdef GL_EXT_vertex_array + + case (DRAW_ELTS|TRIANGLES): + if (with_state & MATERIALS) { + for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { + GLuint nr = MIN(num_tri_verts-i, 600); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); + glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i ); + } + } else { + glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT, + tri_indices ); + } + break; + + case (DRAW_ARRAYS|TRIANGLES): + glDrawArraysEXT( GL_TRIANGLES, 0, (numverts-2)*3 ); + break; + + case (ARRAY_ELT|TRIANGLES): + if (with_state & MATERIALS) { + for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { + GLuint nr = MIN(num_tri_verts-i, 600); + GLuint k; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); + glBegin( GL_TRIANGLES ); + for (k = 0 ; k < nr ; k++) + glArrayElement( tri_indices[i+k] ); + glEnd(); + } + } else { + glBegin( GL_TRIANGLES ); + for (i = 0 ; i < num_tri_verts ; i++) + glArrayElement( tri_indices[i] ); + + glEnd(); + } + break; + + + /* Uses the original arrays (including duplicate elements): + */ + case (DRAW_ARRAYS|STRIPS): + glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts ); + break; + case (DRAW_ELTS|STRIPS): + glDrawElements( GL_TRIANGLE_STRIP, numverts, + GL_UNSIGNED_INT, strip_indices ); + break; + + /* Uses the original arrays (including duplicate elements): + */ + case (ARRAY_ELT|STRIPS): + glBegin( GL_TRIANGLE_STRIP ); + for (i = 0 ; i < numverts ; i++) + glArrayElement( i ); + glEnd(); + break; + + case (DRAW_ARRAYS|POINTS): + glDrawArraysEXT( GL_POINTS, 0, numuniq ); + break; + case (DRAW_ELTS|POINTS): + /* can use numuniq with strip_indices as strip_indices[i] == i. + */ + glDrawElements( GL_POINTS, numuniq, + GL_UNSIGNED_INT, strip_indices ); + break; + case (ARRAY_ELT|POINTS): + /* just emit each unique element once: + */ + glBegin( GL_POINTS ); + for (i = 0 ; i < numuniq ; i++) + glArrayElement( i ); + glEnd(); + break; +#endif + + case (GLVERTEX|TRIANGLES): + if (with_state & MATERIALS) { + for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { + GLuint nr = MIN(num_tri_verts-i, 600); + GLuint k; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]); + glBegin( GL_TRIANGLES ); + for (k = 0 ; k < nr ; k++) { + glNormal3fv( &compressed_data[tri_indices[i+k]][3] ); + glVertex3fv( &compressed_data[tri_indices[i+k]][0] ); + } + glEnd(); + } + } else { + glBegin( GL_TRIANGLES ); + for (i = 0 ; i < num_tri_verts ; i++) { + glNormal3fv( &compressed_data[tri_indices[i]][3] ); + glVertex3fv( &compressed_data[tri_indices[i]][0] ); + } + glEnd(); + } + break; + + case (GLVERTEX|POINTS): + /* Renders all points, but not in strip order... Shouldn't be a + * problem, but people may be confused as to why points are so + * much faster in this demo... And why cva doesn't help them... + */ + glBegin( GL_POINTS ); + for ( i = 0 ; i < numuniq ; i++ ) { + glNormal3fv( &compressed_data[i][3] ); + glVertex3fv( &compressed_data[i][0] ); + } + glEnd(); + break; + + case (GLVERTEX|STRIPS): + glBegin( GL_TRIANGLE_STRIP ); + for (i=0;i<numverts;i++) { + glNormal3fv( &data[i][3] ); + glVertex3fv( &data[i][0] ); + } + glEnd(); + break; + + default: + fprintf(stderr, "unimplemented mode %x...\n", + (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK))); + break; + } +} + + + +static void Display(void) +{ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + draw_surface( state ); + glFlush(); + if (doubleBuffer) glutSwapBuffers(); +} + + +/* KW: only do this when necessary, so CVA can re-use results. + */ +static void set_matrix( void ) +{ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, dist ); + glRotatef( yrot, 0.0, 1.0, 0.0 ); + glRotatef( xrot, 1.0, 0.0, 0.0 ); +} + +static void Benchmark( float xdiff, float ydiff ) +{ + int startTime, endTime; + int draws; + double seconds, fps, triPerSecond; + + printf("Benchmarking...\n"); + + draws = 0; + startTime = glutGet(GLUT_ELAPSED_TIME); + xrot = 0.0; + do { + xrot += xdiff; + yrot += ydiff; + set_matrix(); + Display(); + draws++; + endTime = glutGet(GLUT_ELAPSED_TIME); + } while (endTime - startTime < 5000); /* 5 seconds */ + + /* Results */ + seconds = (double) (endTime - startTime) / 1000.0; + triPerSecond = (numverts - 2) * draws / seconds; + fps = draws / seconds; + printf("Result: triangles/sec: %g fps: %g\n", triPerSecond, fps); +} + + +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 position0[] = {0.0, 0.0, 20.0, 0.0}; + static float position1[] = {0.0, 0.0, -20.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_FALSE}; + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position0); + glEnable(GL_LIGHT0); + + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT1, GL_POSITION, position1); + glEnable(GL_LIGHT1); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse); + + glPolygonStipple (halftone); +} + + + +#define UPDATE(o,n,mask) (o&=~mask, o|=n&mask) +#define CHANGED(o,n,mask) ((n&mask) && (n&mask) != (o&mask) ) + +static void ModeMenu(int m) +{ + m &= allowed; + + if (!m) return; + + if (m==QUIT) + exit(0); + + if (m==GLINFO) { + 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)); + return; + } + + if (CHANGED(state, m, FILTER_MASK)) { + UPDATE(state, m, FILTER_MASK); + if (m & LINEAR_FILTER) { + 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); + } + } + + if (CHANGED(state, m, LIGHT_MASK)) { + UPDATE(state, m, LIGHT_MASK); + if (m & LIT) { + glEnable(GL_LIGHTING); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); + } + else if (m & UNLIT) { + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); + } + else if (m & REFLECT) { + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_2D); + } + } + + if (CHANGED(state, m, SHADE_MASK)) { + UPDATE(state, m, SHADE_MASK); + if (m & SHADE_SMOOTH) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + } + + + if (CHANGED(state, m, CLIP_MASK)) { + UPDATE(state, m, CLIP_MASK); + if (m & USER_CLIP) { + glEnable(GL_CLIP_PLANE0); + } else { + glDisable(GL_CLIP_PLANE0); + } + } + + if (CHANGED(state, m, FOG_MASK)) { + UPDATE(state, m, FOG_MASK); + if (m & FOG) { + glEnable(GL_FOG); + } + else { + glDisable(GL_FOG); + } + } + + if (CHANGED(state, m, STIPPLE_MASK)) { + UPDATE(state, m, STIPPLE_MASK); + if (m & STIPPLE) { + glEnable(GL_POLYGON_STIPPLE); + } + else { + glDisable(GL_POLYGON_STIPPLE); + } + } + + if (CHANGED(state, m, POLYGON_MASK)) { + UPDATE(state, m, POLYGON_MASK); + if (m & POLYGON_FILL) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + } + } + +#ifdef GL_EXT_vertex_array + if (CHANGED(state, m, (LOCK_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK))) + { + if (m & (PRIMITIVE_MASK)) { + UPDATE(state, m, (PRIMITIVE_MASK)); + } + + if (m & (RENDER_STYLE_MASK)) { + UPDATE(state, m, (RENDER_STYLE_MASK)); + } + + if (m & LOCK_MASK) { + UPDATE(state, m, (LOCK_MASK)); + } + + + print_flags("primitive", state & PRIMITIVE_MASK); + print_flags("render style", state & RENDER_STYLE_MASK); + + if ((state & PRIMITIVE_MASK) != STRIPS && + ((state & RENDER_STYLE_MASK) == DRAW_ELTS || + (state & RENDER_STYLE_MASK) == ARRAY_ELT || + (state & PRIMITIVE_MASK) == POINTS)) + { + fprintf(stderr, "enabling small arrays\n"); + /* Rendering any primitive with draw-element/array-element + * --> Can't do strips here as ordering has been lost in + * compaction process... + */ + glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq, + compressed_data ); + glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq, + &compressed_data[0][3]); +#ifdef GL_EXT_compiled_vertex_array + if (allowed & LOCKED) { + if (state & LOCKED) { + glLockArraysEXT( 0, numuniq ); + } else { + glUnlockArraysEXT(); + } + } +#endif + } + else if ((state & PRIMITIVE_MASK) == TRIANGLES && + (state & RENDER_STYLE_MASK) == DRAW_ARRAYS) { + fprintf(stderr, "enabling big arrays\n"); + /* Only get here for TRIANGLES and drawarrays + */ + glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), (numverts-2) * 3, + expanded_data ); + glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), (numverts-2) * 3, + &expanded_data[0][3]); + +#ifdef GL_EXT_compiled_vertex_array + if (allowed & LOCKED) { + if (state & LOCKED) { + glLockArraysEXT( 0, (numverts-2)*3 ); + } else { + glUnlockArraysEXT(); + } + } +#endif + } + else { + fprintf(stderr, "enabling normal arrays\n"); + glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numverts, data ); + glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numverts, &data[0][3]); +#ifdef GL_EXT_compiled_vertex_array + if (allowed & LOCKED) { + if (state & LOCKED) { + glLockArraysEXT( 0, numverts ); + } else { + glUnlockArraysEXT(); + } + } +#endif + } + + } +#endif + + + if (m & DLIST_MASK) { + UPDATE(state, m, DLIST_MASK); + } + + if (m & MATERIAL_MASK) { + UPDATE(state, m, MATERIAL_MASK); + } + + print_flags("new flags", state); + + glutPostRedisplay(); +} + + + +static void Init(int argc, char *argv[]) +{ + GLfloat fogColor[4] = {0.5,1.0,0.5,1.0}; + + xrot = 0; + yrot = 0; + dist = -6; + plane[0] = 1.0; + plane[1] = 0.0; + plane[2] = -1.0; + plane[3] = 0.0; + + glClearColor(0.0, 0.0, 1.0, 0.0); + glEnable( GL_DEPTH_TEST ); + glEnable( GL_VERTEX_ARRAY_EXT ); + glEnable( GL_NORMAL_ARRAY_EXT ); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 ); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClipPlane(GL_CLIP_PLANE0, plane); + + InitMaterials(); + + set_matrix(); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + 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); + + + /* Green fog is easy to see */ + glFogi(GL_FOG_MODE,GL_EXP2); + glFogfv(GL_FOG_COLOR,fogColor); + glFogf(GL_FOG_DENSITY,0.15); + glHint(GL_FOG_HINT,GL_DONT_CARE); + + { + static int firsttime = 1; + if (firsttime) { + firsttime = 0; + compactify_arrays(); + expand_arrays(); + make_tri_indices(); + + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + } + } + + ModeMenu(SHADE_SMOOTH| + LIT| + POINT_FILTER| + NO_USER_CLIP| + NO_MATERIALS| + NO_FOG| + NO_STIPPLE| + IMMEDIATE| + STRIPS| + UNLOCKED| + GLVERTEX); + + if (PrintInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } +} + + + +static void Reshape(int width, int height) +{ + glViewport(0, 0, (GLint)width, (GLint)height); +} + + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + case 'f': + ModeMenu((state ^ FOG_MASK) & FOG_MASK); + break; + case 's': + ModeMenu((state ^ SHADE_MASK) & SHADE_MASK); + break; + case 't': + ModeMenu((state ^ STIPPLE_MASK) & STIPPLE_MASK); + break; + case 'l': + ModeMenu((state ^ LIGHT_MASK) & (LIT|UNLIT)); + break; + case 'm': + ModeMenu((state ^ MATERIAL_MASK) & MATERIAL_MASK); + break; + case 'c': + ModeMenu((state ^ CLIP_MASK) & CLIP_MASK); + break; + case 'v': + ModeMenu((LOCKED|IMMEDIATE|DRAW_ELTS|TRIANGLES) & allowed); + break; + case 'V': + ModeMenu(UNLOCKED|IMMEDIATE|GLVERTEX|STRIPS); + break; + case 'b': + Benchmark(5.0, 0); + break; + case 'B': + Benchmark(0, 5.0); + break; + case 'i': + dist += .25; + set_matrix(); + glutPostRedisplay(); + break; + case 'I': + dist -= .25; + set_matrix(); + glutPostRedisplay(); + break; + case '-': + case '_': + plane[3] += 2.0; + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClipPlane(GL_CLIP_PLANE0, plane); + set_matrix(); + glutPostRedisplay(); + break; + case '+': + case '=': + plane[3] -= 2.0; + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClipPlane(GL_CLIP_PLANE0, plane); + set_matrix(); + glutPostRedisplay(); + break; + case ' ': + Init(0,0); + break; + } +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + yrot -= 15.0; + break; + case GLUT_KEY_RIGHT: + yrot += 15.0; + break; + case GLUT_KEY_UP: + xrot += 15.0; + break; + case GLUT_KEY_DOWN: + xrot -= 15.0; + break; + default: + return; + } + set_matrix(); + glutPostRedisplay(); +} + + + +static GLint Args(int argc, char **argv) +{ + GLint i; + GLint mode = 0; + + 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], "-info") == 0) { + PrintInfo = GL_TRUE; + } + else if (strcmp(argv[i], "-10") == 0) { + maxverts = 10; + } + else if (strcmp(argv[i], "-100") == 0) { + maxverts = 100; + } + else if (strcmp(argv[i], "-1000") == 0) { + maxverts = 1000; + } + else { + printf("%s (Bad option).\n", argv[i]); + return QUIT; + } + } + + return mode; +} + +int main(int argc, char **argv) +{ + GLenum type; + char *extensions; + + GLuint arg_mode = Args(argc, argv); + + if (arg_mode & QUIT) + exit(0); + + read_surface( "isosurf.dat" ); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + + type = GLUT_DEPTH; + type |= GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow("Isosurface") <= 0) { + exit(0); + } + + /* Make sure server supports the vertex array extension */ + extensions = (char *) glGetString( GL_EXTENSIONS ); + + if (!strstr( extensions, "GL_EXT_vertex_array" )) + { + printf("Vertex arrays not supported by this renderer\n"); + allowed &= ~(LOCKED|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT); + } + else if (!strstr( extensions, "GL_EXT_compiled_vertex_array" )) + { + printf("Compiled vertex arrays not supported by this renderer\n"); + allowed &= ~LOCKED; + } + + Init(argc, argv); + ModeMenu(arg_mode); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("GL info", GLINFO); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Lit", LIT); + glutAddMenuEntry("Unlit", UNLIT); + glutAddMenuEntry("Reflect", REFLECT); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Smooth", SHADE_SMOOTH); + glutAddMenuEntry("Flat", SHADE_FLAT); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Fog", FOG); + glutAddMenuEntry("No Fog", NO_FOG); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Stipple", STIPPLE); + glutAddMenuEntry("No Stipple", NO_STIPPLE); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Polygon Mode Fill", POLYGON_FILL); + glutAddMenuEntry("Polygon Mode Line", POLYGON_LINE); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Point Filtered", POINT_FILTER); + glutAddMenuEntry("Linear Filtered", LINEAR_FILTER); + glutAddMenuEntry("", 0); + glutAddMenuEntry("GL_TRIANGLES", TRIANGLES); + glutAddMenuEntry("GL_TRIANGLE_STRIPS", STRIPS); + glutAddMenuEntry("GL_POINTS", POINTS); + glutAddMenuEntry("", 0); + glutAddMenuEntry("Displaylist", DISPLAYLIST); + glutAddMenuEntry("Immediate", IMMEDIATE); + glutAddMenuEntry("", 0); + if (allowed & LOCKED) { + glutAddMenuEntry("Locked Arrays (CVA)", LOCKED); + glutAddMenuEntry("Unlocked Arrays", UNLOCKED); + glutAddMenuEntry("", 0); + } + glutAddMenuEntry("glVertex", GLVERTEX); + if (allowed & DRAW_ARRAYS) { + glutAddMenuEntry("glDrawElements", DRAW_ELTS); + glutAddMenuEntry("glDrawArrays", DRAW_ARRAYS); + glutAddMenuEntry("glArrayElement", ARRAY_ELT); + } + glutAddMenuEntry("", 0); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Display); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/isosurf.dat b/progs/demos/isosurf.dat new file mode 100644 index 00000000000..5cadecdb430 --- /dev/null +++ b/progs/demos/isosurf.dat @@ -0,0 +1,7179 @@ +-1.000000 0.050200 0.254800 0.280000 0.504000 0.808000 +-1.000000 0.061400 0.243900 0.248000 0.608000 0.744000 +-0.973900 0.050200 0.243900 0.312000 0.448000 0.832000 +-1.000000 0.100400 0.207000 0.040000 0.608000 0.784000 +-0.950000 0.050200 0.232900 0.312000 0.424000 0.840000 +-0.950000 0.100400 0.204500 0.176000 0.504000 0.840000 +-0.900000 0.050200 0.202100 0.368000 0.256000 0.888000 +-0.900000 0.100400 0.184100 0.296000 0.408000 0.856000 +-0.865600 0.050200 0.182900 0.480000 0.256000 0.832000 +-0.897500 0.100400 0.182900 0.392000 0.408000 0.816000 +-0.850000 0.050200 0.170400 0.488000 0.296000 0.816000 +-0.850000 0.100400 0.150400 0.488000 0.512000 0.696000 +-0.800000 0.050200 0.139800 0.504000 0.392000 0.760000 +-0.820700 0.100400 0.121900 0.496000 0.488000 0.704000 +-0.800000 0.077200 0.121900 0.512000 0.416000 0.744000 +-0.800000 0.100400 0.105500 0.480000 0.456000 0.736000 +-0.781300 0.050200 0.121900 0.536000 0.400000 0.736000 +-0.750000 0.100400 0.065100 0.488000 0.448000 0.736000 +-0.750000 0.050200 0.097600 0.464000 0.408000 0.776000 +-0.744800 0.100400 0.060900 0.496000 0.456000 0.728000 +-0.700000 0.050200 0.061900 0.536000 0.368000 0.752000 +-0.700000 0.051600 0.060900 0.528000 0.416000 0.728000 +-0.699000 0.050200 0.060900 0.608000 0.360000 0.696000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.650000 0.050200 0.008200 0.568000 0.384000 0.720000 +-0.680200 0.100400 0.000000 0.600000 0.440000 0.656000 +-0.650000 0.063100 0.000000 0.592000 0.392000 0.696000 +-0.650000 0.100400 -0.043200 0.600000 0.608000 0.496000 +-0.641800 0.050200 0.000000 0.616000 0.400000 0.664000 +-0.638000 0.100400 -0.060900 0.672000 0.632000 0.368000 +-0.600000 0.050200 -0.054100 0.640000 0.448000 0.616000 +-0.600000 0.057600 -0.060900 0.728000 0.536000 0.408000 +-0.594700 0.050200 -0.060900 0.744000 0.504000 0.416000 +-0.600000 0.050200 -0.083400 0.800000 0.528000 -0.248000 +-0.573200 0.000000 -0.060900 0.920000 0.296000 -0.248000 +-0.600000 0.000000 -0.117700 0.848000 0.200000 -0.488000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.600000 -0.008200 -0.121900 0.848000 0.208000 -0.472000 +-0.586600 -0.050200 -0.121900 0.872000 0.224000 -0.424000 +-0.600000 -0.050200 -0.162700 0.904000 0.232000 -0.344000 +-0.578300 -0.100400 -0.121900 0.848000 0.312000 -0.424000 +-0.600000 -0.077900 -0.182900 0.856000 0.208000 -0.464000 +-0.594100 -0.100400 -0.182900 0.816000 0.296000 -0.480000 +-0.600000 -0.100400 -0.193800 0.776000 0.296000 -0.544000 +-0.561800 -0.150600 -0.182900 0.544000 0.784000 -0.280000 +-0.600000 -0.150600 -0.229400 0.416000 0.744000 -0.512000 +-0.550000 -0.155500 -0.182900 0.296000 0.920000 -0.232000 +-0.600000 -0.160400 -0.243900 0.432000 0.688000 -0.576000 +-0.550000 -0.172700 -0.243900 0.008000 0.856000 -0.512000 +-0.600000 -0.200800 -0.299500 0.000000 0.872000 -0.480000 +-0.550000 -0.200800 -0.303600 -0.040000 0.880000 -0.464000 +-0.600000 -0.203400 -0.304800 0.008000 0.768000 -0.632000 +-0.550000 -0.201300 -0.304800 -0.032000 0.864000 -0.488000 +-0.600000 -0.251000 -0.360600 -0.120000 0.624000 -0.760000 +-0.550000 -0.245600 -0.365800 -0.104000 0.680000 -0.720000 +-0.576800 -0.251000 -0.365800 -0.136000 0.624000 -0.760000 +-0.550000 -0.251000 -0.371400 -0.120000 0.616000 -0.768000 +-0.600000 -0.256300 -0.365800 -0.112000 0.608000 -0.776000 +-0.550000 -0.301200 -0.401000 0.000000 0.424000 -0.904000 +-0.600000 -0.301200 -0.399100 0.008000 0.480000 -0.872000 +-0.550000 -0.349500 -0.426800 0.056000 0.416000 -0.904000 +-0.600000 -0.340300 -0.426800 0.032000 0.512000 -0.848000 +-0.600000 -0.301200 -0.399100 0.008000 0.480000 -0.872000 +-0.650000 -0.337200 -0.426800 0.016000 0.520000 -0.848000 +-0.650000 -0.301200 -0.398600 0.000000 0.528000 -0.840000 +-0.700000 -0.338200 -0.426800 -0.192000 0.592000 -0.776000 +-0.700000 -0.301200 -0.401600 0.016000 0.504000 -0.856000 +-0.736800 -0.351500 -0.426800 -0.240000 0.480000 -0.832000 +-0.750000 -0.301200 -0.392900 -0.104000 0.352000 -0.928000 +-0.750000 -0.351500 -0.422100 -0.312000 0.448000 -0.824000 +-0.800000 -0.301200 -0.380800 -0.264000 0.104000 -0.952000 +-0.800000 -0.351500 -0.388300 -0.664000 -0.152000 -0.728000 +-0.826000 -0.301200 -0.365800 -0.648000 -0.448000 -0.600000 +-0.812200 -0.351500 -0.365800 -0.856000 -0.296000 -0.408000 +-0.850000 -0.301200 -0.321900 -0.728000 -0.616000 -0.280000 +-0.821000 -0.351500 -0.304800 -0.824000 -0.504000 0.232000 +-0.850000 -0.306900 -0.304800 -0.768000 -0.624000 0.072000 +-0.807300 -0.351500 -0.243900 -0.864000 -0.472000 0.152000 +-0.850000 -0.301200 -0.293400 -0.744000 -0.560000 0.336000 +-0.834700 -0.301200 -0.243900 -0.840000 -0.504000 0.184000 +-0.850000 -0.276800 -0.243900 -0.792000 -0.552000 0.248000 +-0.831100 -0.301200 -0.182900 -0.848000 -0.520000 0.016000 +-0.850000 -0.271300 -0.182900 -0.816000 -0.568000 0.032000 +-0.832400 -0.301200 -0.121900 -0.840000 -0.528000 0.048000 +-0.850000 -0.274400 -0.121900 -0.816000 -0.568000 0.008000 +-0.826600 -0.301200 -0.060900 -0.824000 -0.544000 0.120000 +-0.850000 -0.265600 -0.060900 -0.808000 -0.568000 0.104000 +-0.817700 -0.301200 0.000000 -0.808000 -0.560000 0.168000 +-0.850000 -0.254700 0.000000 -0.800000 -0.568000 0.168000 +-0.805900 -0.301200 0.060900 -0.800000 -0.536000 0.232000 +-0.850000 -0.251000 0.014600 -0.800000 -0.560000 0.176000 +-0.838400 -0.251000 0.060900 -0.808000 -0.528000 0.248000 +-0.850000 -0.233200 0.060900 -0.816000 -0.512000 0.248000 +-0.819200 -0.251000 0.121900 -0.760000 -0.496000 0.400000 +-0.850000 -0.203500 0.121900 -0.792000 -0.528000 0.288000 +-0.800000 -0.251000 0.157900 -0.576000 -0.400000 0.696000 +-0.850000 -0.200800 0.125700 -0.776000 -0.360000 0.504000 +-0.800000 -0.206500 0.182900 -0.304000 -0.264000 0.912000 +-0.803100 -0.200800 0.182900 -0.456000 -0.168000 0.864000 +-0.800000 -0.200800 0.184500 -0.256000 -0.128000 0.952000 +-0.836800 -0.150600 0.182900 -0.304000 -0.304000 0.896000 +-0.800000 -0.150600 0.189500 -0.240000 -0.056000 0.960000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.800000 -0.100400 0.186900 0.104000 0.048000 0.992000 +-0.850000 -0.100400 0.192600 -0.136000 -0.312000 0.936000 +-0.800000 -0.063400 0.182900 0.240000 0.160000 0.952000 +-0.850000 -0.050200 0.193400 0.200000 0.072000 0.968000 +-0.809300 -0.050200 0.182900 0.232000 0.160000 0.952000 +-0.850000 0.000000 0.186200 0.256000 0.144000 0.952000 +-0.839600 0.000000 0.182900 0.264000 0.152000 0.944000 +-0.850000 0.016800 0.182900 0.328000 0.184000 0.920000 +-0.800000 0.000000 0.163200 0.400000 0.288000 0.864000 +-0.850000 0.050200 0.170400 0.488000 0.296000 0.816000 +-0.800000 0.050200 0.139800 0.504000 0.392000 0.760000 +-0.800000 0.000000 0.163200 0.400000 0.288000 0.864000 +-0.781300 0.050200 0.121900 0.536000 0.400000 0.736000 +-0.750000 0.000000 0.129400 0.496000 0.360000 0.776000 +-0.750000 0.012900 0.121900 0.496000 0.384000 0.768000 +-0.740500 0.000000 0.121900 0.504000 0.352000 0.784000 +-0.750000 0.050200 0.097600 0.464000 0.408000 0.776000 +-0.700000 0.000000 0.089700 0.584000 0.336000 0.736000 +-0.700000 0.050200 0.061900 0.536000 0.368000 0.752000 +-0.666100 0.000000 0.060900 0.560000 0.376000 0.728000 +-0.699000 0.050200 0.060900 0.608000 0.360000 0.696000 +-0.650000 0.000000 0.045200 0.576000 0.400000 0.704000 +-0.650000 0.050200 0.008200 0.568000 0.384000 0.720000 +-0.609800 0.000000 0.000000 0.696000 0.384000 0.592000 +-0.641800 0.050200 0.000000 0.616000 0.400000 0.664000 +-0.600000 0.000000 -0.017800 0.736000 0.384000 0.544000 +-0.600000 0.050200 -0.054100 0.640000 0.448000 0.616000 +-0.573200 0.000000 -0.060900 0.920000 0.296000 -0.248000 +-0.594700 0.050200 -0.060900 0.744000 0.504000 0.416000 +-0.594700 0.050200 -0.060900 0.744000 0.504000 0.416000 +-1.000000 0.050200 0.254800 0.280000 0.504000 0.808000 +-1.000000 0.050200 0.254800 0.280000 0.504000 0.808000 +-1.000000 0.000000 0.260200 0.424000 -0.312000 0.840000 +-0.973900 0.050200 0.243900 0.312000 0.448000 0.832000 +-0.976100 0.000000 0.243900 0.464000 -0.432000 0.768000 +-0.950000 0.050200 0.232900 0.312000 0.424000 0.840000 +-0.950000 0.000000 0.224500 0.344000 -0.144000 0.920000 +-0.900000 0.050200 0.202100 0.368000 0.256000 0.888000 +-0.900000 0.000000 0.204000 0.296000 0.088000 0.944000 +-0.865600 0.050200 0.182900 0.480000 0.256000 0.832000 +-0.850000 0.000000 0.186200 0.256000 0.144000 0.952000 +-0.850000 0.016800 0.182900 0.328000 0.184000 0.920000 +-0.865600 0.050200 0.182900 0.480000 0.256000 0.832000 +-0.850000 0.050200 0.170400 0.488000 0.296000 0.816000 +-0.850000 0.050200 0.170400 0.488000 0.296000 0.816000 +-1.000000 0.000000 0.260200 0.424000 -0.312000 0.840000 +-1.000000 0.000000 0.260200 0.424000 -0.312000 0.840000 +-0.976100 0.000000 0.243900 0.464000 -0.432000 0.768000 +-1.000000 -0.016700 0.243900 0.424000 -0.608000 0.656000 +-0.950000 0.000000 0.224500 0.344000 -0.144000 0.920000 +-1.000000 -0.050200 0.185900 -0.256000 -0.768000 0.576000 +-0.950000 -0.050200 0.212200 0.160000 -0.384000 0.904000 +-1.000000 -0.052000 0.182900 -0.336000 -0.760000 0.544000 +-0.950000 -0.074300 0.182900 -0.344000 -0.776000 0.520000 +-1.000000 -0.075600 0.121900 -0.328000 -0.896000 0.264000 +-0.950000 -0.095300 0.121900 -0.400000 -0.864000 0.280000 +-1.000000 -0.090800 0.060900 -0.320000 -0.912000 0.248000 +-0.950000 -0.100400 0.101700 -0.400000 -0.872000 0.264000 +-0.973400 -0.100400 0.060900 -0.344000 -0.904000 0.240000 +-0.950000 -0.110600 0.060900 -0.432000 -0.856000 0.248000 +-1.000000 -0.100400 0.014600 -0.304000 -0.920000 0.208000 +-0.950000 -0.123700 0.000000 -0.488000 -0.840000 0.216000 +-1.000000 -0.103100 0.000000 -0.304000 -0.920000 0.208000 +-0.950000 -0.136200 -0.060900 -0.528000 -0.832000 0.152000 +-1.000000 -0.112800 -0.060900 -0.376000 -0.912000 0.144000 +-0.950000 -0.144800 -0.121900 -0.536000 -0.832000 0.120000 +-1.000000 -0.120900 -0.121900 -0.400000 -0.904000 0.136000 +-0.950000 -0.150600 -0.169000 -0.584000 -0.792000 0.136000 +-1.000000 -0.129600 -0.182900 -0.400000 -0.904000 0.136000 +-0.952800 -0.150600 -0.182900 -0.568000 -0.808000 0.136000 +-1.000000 -0.135800 -0.243900 -0.400000 -0.904000 0.096000 +-0.966700 -0.150600 -0.243900 -0.472000 -0.864000 0.152000 +-1.000000 -0.142300 -0.304800 -0.328000 -0.456000 -0.824000 +-0.989000 -0.150600 -0.304800 -0.440000 -0.624000 -0.640000 +-1.000000 -0.100400 -0.332000 -0.256000 -0.392000 -0.880000 +-0.950000 -0.150600 -0.330800 -0.416000 -0.432000 -0.792000 +-0.950000 -0.100400 -0.349400 -0.088000 -0.160000 -0.976000 +-0.900000 -0.150600 -0.338300 -0.216000 -0.104000 -0.968000 +-0.900000 -0.100400 -0.346700 0.112000 -0.048000 -0.984000 +-0.850000 -0.150600 -0.349400 0.072000 0.056000 -0.992000 +-0.850000 -0.100400 -0.332400 0.280000 0.112000 -0.952000 +-0.800000 -0.150600 -0.340500 0.312000 0.288000 -0.896000 +-0.800000 -0.100400 -0.313000 0.368000 0.216000 -0.896000 +-0.750000 -0.150600 -0.317800 0.416000 0.384000 -0.816000 +-0.785000 -0.100400 -0.304800 0.328000 0.224000 -0.912000 +-0.750000 -0.129200 -0.304800 0.392000 0.376000 -0.832000 +-0.750000 -0.100400 -0.291100 0.336000 0.256000 -0.896000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.700000 -0.100400 -0.274700 0.392000 0.112000 -0.904000 +-0.700000 -0.150600 -0.284500 0.376000 0.392000 -0.832000 +-0.650000 -0.100400 -0.251900 0.448000 0.224000 -0.856000 +-0.650000 -0.150600 -0.267500 0.376000 0.464000 -0.792000 +-0.638400 -0.100400 -0.243900 0.560000 0.160000 -0.808000 +-0.612700 -0.150600 -0.243900 0.496000 0.576000 -0.640000 +-0.600000 -0.100400 -0.193800 0.776000 0.296000 -0.544000 +-0.600000 -0.150600 -0.229400 0.416000 0.744000 -0.512000 +-0.612700 -0.150600 -0.243900 0.496000 0.576000 -0.640000 +-0.600000 -0.160400 -0.243900 0.432000 0.688000 -0.576000 +-0.650000 -0.150600 -0.267500 0.376000 0.464000 -0.792000 +-0.600000 -0.200800 -0.299500 0.000000 0.872000 -0.480000 +-0.650000 -0.200800 -0.303800 0.136000 0.680000 -0.712000 +-0.600000 -0.203400 -0.304800 0.008000 0.768000 -0.632000 +-0.650000 -0.201600 -0.304800 0.104000 0.688000 -0.704000 +-0.600000 -0.251000 -0.360600 -0.120000 0.624000 -0.760000 +-0.650000 -0.251000 -0.354800 0.152000 0.632000 -0.752000 +-0.600000 -0.256300 -0.365800 -0.112000 0.608000 -0.776000 +-0.650000 -0.261300 -0.365800 0.088000 0.568000 -0.808000 +-0.600000 -0.301200 -0.399100 0.008000 0.480000 -0.872000 +-0.650000 -0.301200 -0.398600 0.000000 0.528000 -0.840000 +-0.650000 -0.261300 -0.365800 0.088000 0.568000 -0.808000 +-0.700000 -0.301200 -0.401600 0.016000 0.504000 -0.856000 +-0.700000 -0.252100 -0.365800 0.096000 0.552000 -0.824000 +-0.750000 -0.301200 -0.392900 -0.104000 0.352000 -0.928000 +-0.707800 -0.251000 -0.365800 0.064000 0.432000 -0.896000 +-0.750000 -0.251000 -0.369800 0.056000 0.280000 -0.952000 +-0.750000 -0.240500 -0.365800 0.056000 0.272000 -0.952000 +-0.800000 -0.251000 -0.370300 -0.064000 0.200000 -0.976000 +-0.800000 -0.234100 -0.365800 -0.112000 0.264000 -0.952000 +-0.828000 -0.251000 -0.365800 -0.248000 0.216000 -0.936000 +-0.800000 -0.200800 -0.355700 0.080000 0.256000 -0.960000 +-0.850000 -0.251000 -0.359600 -0.320000 0.248000 -0.912000 +-0.850000 -0.200800 -0.351200 -0.168000 0.112000 -0.976000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-0.900000 -0.200800 -0.331500 -0.576000 -0.328000 -0.736000 +-0.900000 -0.236500 -0.304800 -0.680000 -0.456000 -0.560000 +-0.931500 -0.200800 -0.304800 -0.648000 -0.520000 -0.544000 +-0.900000 -0.212400 -0.243900 -0.672000 -0.712000 0.176000 +-0.914100 -0.200800 -0.243900 -0.664000 -0.728000 0.128000 +-0.900000 -0.206900 -0.182900 -0.648000 -0.752000 0.056000 +-0.907400 -0.200800 -0.182900 -0.688000 -0.712000 0.072000 +-0.900000 -0.204500 -0.121900 -0.688000 -0.712000 0.104000 +-0.903800 -0.200800 -0.121900 -0.696000 -0.704000 0.120000 +-0.900000 -0.200800 -0.096200 -0.752000 -0.632000 0.128000 +-0.943100 -0.150600 -0.121900 -0.672000 -0.720000 0.120000 +-0.900000 -0.192500 -0.060900 -0.856000 -0.488000 0.144000 +-0.932400 -0.150600 -0.060900 -0.688000 -0.696000 0.176000 +-0.900000 -0.169600 0.000000 -0.800000 -0.552000 0.224000 +-0.915700 -0.150600 0.000000 -0.696000 -0.672000 0.232000 +-0.900000 -0.150600 0.057700 -0.744000 -0.616000 0.232000 +-0.950000 -0.123700 0.000000 -0.488000 -0.840000 0.216000 +-0.900000 -0.149700 0.060900 -0.696000 -0.664000 0.232000 +-0.950000 -0.110600 0.060900 -0.432000 -0.856000 0.248000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.950000 -0.100400 0.101700 -0.400000 -0.872000 0.264000 +-0.939400 -0.100400 0.121900 -0.456000 -0.816000 0.336000 +-0.950000 -0.095300 0.121900 -0.400000 -0.864000 0.280000 +-0.900000 -0.100400 0.174900 -0.400000 -0.624000 0.656000 +-0.950000 -0.074300 0.182900 -0.344000 -0.776000 0.520000 +-0.900000 -0.094400 0.182900 -0.312000 -0.608000 0.720000 +-0.950000 -0.050200 0.212200 0.160000 -0.384000 0.904000 +-0.900000 -0.050200 0.208600 0.200000 -0.168000 0.960000 +-0.950000 0.000000 0.224500 0.344000 -0.144000 0.920000 +-0.900000 0.000000 0.204000 0.296000 0.088000 0.944000 +-0.900000 -0.050200 0.208600 0.200000 -0.168000 0.960000 +-0.850000 0.000000 0.186200 0.256000 0.144000 0.952000 +-0.850000 -0.050200 0.193400 0.200000 0.072000 0.968000 +-0.900000 -0.050200 0.208600 0.200000 -0.168000 0.960000 +-0.850000 -0.100400 0.192600 -0.136000 -0.312000 0.936000 +-0.900000 -0.094400 0.182900 -0.312000 -0.608000 0.720000 +-0.886800 -0.100400 0.182900 -0.288000 -0.576000 0.752000 +-0.900000 -0.100400 0.174900 -0.400000 -0.624000 0.656000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.850000 -0.150600 0.175600 -0.632000 -0.392000 0.664000 +-0.878400 -0.150600 0.121900 -0.736000 -0.560000 0.368000 +-0.850000 -0.200800 0.125700 -0.776000 -0.360000 0.504000 +-0.851500 -0.200800 0.121900 -0.832000 -0.360000 0.408000 +-0.850000 -0.203500 0.121900 -0.792000 -0.528000 0.288000 +-0.869300 -0.200800 0.060900 -0.824000 -0.496000 0.248000 +-0.850000 -0.233200 0.060900 -0.816000 -0.512000 0.248000 +-0.882700 -0.200800 0.000000 -0.840000 -0.496000 0.192000 +-0.850000 -0.251000 0.014600 -0.800000 -0.560000 0.176000 +-0.852600 -0.251000 0.000000 -0.800000 -0.568000 0.168000 +-0.850000 -0.254700 0.000000 -0.800000 -0.568000 0.168000 +-0.860100 -0.251000 -0.060900 -0.808000 -0.568000 0.112000 +-0.850000 -0.265600 -0.060900 -0.808000 -0.568000 0.104000 +-0.866600 -0.251000 -0.121900 -0.808000 -0.576000 0.072000 +-0.850000 -0.274400 -0.121900 -0.816000 -0.568000 0.008000 +-0.864200 -0.251000 -0.182900 -0.800000 -0.592000 0.000000 +-0.850000 -0.271300 -0.182900 -0.816000 -0.568000 0.032000 +-0.869200 -0.251000 -0.243900 -0.768000 -0.600000 0.200000 +-0.850000 -0.276800 -0.243900 -0.792000 -0.552000 0.248000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-0.850000 -0.301200 -0.293400 -0.744000 -0.560000 0.336000 +-0.854400 -0.301200 -0.304800 -0.776000 -0.608000 0.112000 +-0.850000 -0.306900 -0.304800 -0.768000 -0.624000 0.072000 +-0.850000 -0.301200 -0.321900 -0.728000 -0.616000 -0.280000 +-0.854400 -0.301200 -0.304800 -0.776000 -0.608000 0.112000 +-0.850000 -0.251000 -0.359600 -0.320000 0.248000 -0.912000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-1.000000 0.100400 0.207000 0.040000 0.608000 0.784000 +-1.000000 0.100400 0.207000 0.040000 0.608000 0.784000 +-0.950000 0.100400 0.204500 0.176000 0.504000 0.840000 +-1.000000 0.136100 0.182900 0.152000 0.600000 0.776000 +-0.950000 0.127100 0.182900 0.248000 0.536000 0.800000 +-1.000000 0.150600 0.170300 0.208000 0.568000 0.792000 +-0.950000 0.150600 0.154300 0.208000 0.640000 0.736000 +-1.000000 0.192500 0.121900 0.192000 0.664000 0.720000 +-0.950000 0.178500 0.121900 0.272000 0.648000 0.704000 +-1.000000 0.200800 0.112700 0.192000 0.656000 0.720000 +-0.950000 0.200800 0.096100 0.208000 0.672000 0.704000 +-1.000000 0.241600 0.060900 0.248000 0.768000 0.584000 +-0.950000 0.226300 0.060900 0.264000 0.760000 0.584000 +-1.000000 0.251000 0.045400 0.264000 0.768000 0.568000 +-0.950000 0.251000 0.016800 0.288000 0.808000 0.504000 +-1.000000 0.274600 0.000000 0.264000 0.848000 0.448000 +-0.950000 0.258900 0.000000 0.296000 0.848000 0.432000 +-1.000000 0.294800 -0.060900 0.312000 0.944000 0.080000 +-0.950000 0.277400 -0.060900 0.336000 0.928000 0.080000 +-1.000000 0.286500 -0.121900 0.328000 0.872000 -0.344000 +-0.950000 0.267200 -0.121900 0.344000 0.864000 -0.336000 +-1.000000 0.256900 -0.182900 0.288000 0.752000 -0.584000 +-0.950000 0.251000 -0.157200 0.320000 0.808000 -0.480000 +-0.985000 0.251000 -0.182900 0.288000 0.752000 -0.576000 +-0.950000 0.237800 -0.182900 0.296000 0.760000 -0.568000 +-1.000000 0.251000 -0.191500 0.280000 0.728000 -0.616000 +-0.950000 0.200800 -0.231900 0.272000 0.640000 -0.704000 +-1.000000 0.207900 -0.243900 0.232000 0.640000 -0.728000 +-0.980800 0.200800 -0.243900 0.232000 0.632000 -0.736000 +-1.000000 0.200800 -0.251300 0.232000 0.624000 -0.736000 +-0.950000 0.189400 -0.243900 0.264000 0.616000 -0.728000 +-1.000000 0.150600 -0.296000 0.168000 0.544000 -0.816000 +-0.950000 0.150600 -0.281200 0.240000 0.600000 -0.752000 +-1.000000 0.137800 -0.304800 0.104000 0.472000 -0.872000 +-0.950000 0.126000 -0.304800 0.168000 0.528000 -0.824000 +-1.000000 0.100400 -0.326700 0.072000 0.384000 -0.912000 +-0.950000 0.100400 -0.325900 0.192000 0.384000 -0.896000 +-1.000000 0.050200 -0.349300 0.080000 0.216000 -0.968000 +-0.950000 0.050200 -0.340200 0.184000 0.072000 -0.976000 +-1.000000 0.000000 -0.357700 0.216000 -0.064000 -0.968000 +-0.950000 0.000000 -0.337100 0.184000 -0.088000 -0.976000 +-1.000000 -0.050200 -0.339100 0.152000 -0.176000 -0.968000 +-0.950000 -0.050200 -0.337400 0.088000 0.008000 -0.992000 +-1.000000 -0.100400 -0.332000 -0.256000 -0.392000 -0.880000 +-0.950000 -0.100400 -0.349400 -0.088000 -0.160000 -0.976000 +-0.950000 -0.050200 -0.337400 0.088000 0.008000 -0.992000 +-0.900000 -0.100400 -0.346700 0.112000 -0.048000 -0.984000 +-0.900000 -0.050200 -0.330000 0.160000 0.128000 -0.976000 +-0.850000 -0.100400 -0.332400 0.280000 0.112000 -0.952000 +-0.850000 -0.050200 -0.323400 0.248000 0.176000 -0.944000 +-0.800000 -0.100400 -0.313000 0.368000 0.216000 -0.896000 +-0.808200 -0.050200 -0.304800 0.280000 0.136000 -0.944000 +-0.800000 -0.066700 -0.304800 0.296000 0.144000 -0.936000 +-0.800000 -0.050200 -0.302200 0.264000 0.120000 -0.952000 +-0.785000 -0.100400 -0.304800 0.328000 0.224000 -0.912000 +-0.750000 -0.050200 -0.287100 0.288000 0.040000 -0.952000 +-0.750000 -0.100400 -0.291100 0.336000 0.256000 -0.896000 +-0.700000 -0.050200 -0.272000 0.360000 0.104000 -0.920000 +-0.700000 -0.100400 -0.274700 0.392000 0.112000 -0.904000 +-0.650000 -0.050200 -0.249300 0.496000 0.208000 -0.840000 +-0.650000 -0.100400 -0.251900 0.448000 0.224000 -0.856000 +-0.642900 -0.050200 -0.243900 0.560000 0.208000 -0.792000 +-0.638400 -0.100400 -0.243900 0.560000 0.160000 -0.808000 +-0.606100 -0.050200 -0.182900 0.864000 0.248000 -0.424000 +-0.600000 -0.100400 -0.193800 0.776000 0.296000 -0.544000 +-0.600000 -0.077900 -0.182900 0.856000 0.208000 -0.464000 +-0.606100 -0.050200 -0.182900 0.864000 0.248000 -0.424000 +-0.600000 -0.050200 -0.162700 0.904000 0.232000 -0.344000 +-0.621400 0.000000 -0.182900 0.848000 0.280000 -0.440000 +-0.600000 -0.008200 -0.121900 0.848000 0.208000 -0.472000 +-0.601900 0.000000 -0.121900 0.848000 0.208000 -0.472000 +-0.600000 0.000000 -0.117700 0.848000 0.200000 -0.488000 +-0.614300 0.050200 -0.121900 0.720000 0.480000 -0.480000 +-0.600000 0.050200 -0.083400 0.800000 0.528000 -0.248000 +-0.650000 0.089500 -0.121900 0.728000 0.552000 -0.384000 +-0.600000 0.057600 -0.060900 0.728000 0.536000 0.408000 +-0.650000 0.100400 -0.098000 0.720000 0.624000 -0.288000 +-0.638000 0.100400 -0.060900 0.672000 0.632000 0.368000 +-0.650000 0.112000 -0.060900 0.672000 0.704000 0.200000 +-0.650000 0.100400 -0.043200 0.600000 0.608000 0.496000 +-0.689800 0.150600 -0.060900 0.640000 0.736000 0.192000 +-0.680200 0.100400 0.000000 0.600000 0.440000 0.656000 +-0.700000 0.150600 -0.043600 0.552000 0.712000 0.424000 +-0.700000 0.121800 0.000000 0.536000 0.544000 0.632000 +-0.734000 0.150600 0.000000 0.496000 0.640000 0.576000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.750000 0.150600 0.014500 0.472000 0.624000 0.608000 +-0.744800 0.100400 0.060900 0.496000 0.456000 0.728000 +-0.750000 0.106000 0.060900 0.496000 0.464000 0.728000 +-0.750000 0.100400 0.065100 0.488000 0.448000 0.736000 +-0.796300 0.150600 0.060900 0.512000 0.584000 0.616000 +-0.800000 0.100400 0.105500 0.480000 0.456000 0.736000 +-0.800000 0.150600 0.064100 0.424000 0.560000 0.704000 +-0.820700 0.100400 0.121900 0.496000 0.488000 0.704000 +-0.850000 0.150600 0.098600 0.360000 0.600000 0.704000 +-0.850000 0.127100 0.121900 0.424000 0.560000 0.704000 +-0.892900 0.150600 0.121900 0.360000 0.624000 0.680000 +-0.850000 0.100400 0.150400 0.488000 0.512000 0.696000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.897500 0.100400 0.182900 0.392000 0.408000 0.816000 +-0.900000 0.101900 0.182900 0.304000 0.552000 0.768000 +-0.900000 0.100400 0.184100 0.296000 0.408000 0.856000 +-0.950000 0.127100 0.182900 0.248000 0.536000 0.800000 +-0.950000 0.100400 0.204500 0.176000 0.504000 0.840000 +-0.950000 0.100400 0.204500 0.176000 0.504000 0.840000 +-0.886800 -0.100400 0.182900 -0.288000 -0.576000 0.752000 +-0.886800 -0.100400 0.182900 -0.288000 -0.576000 0.752000 +-0.850000 -0.100400 0.192600 -0.136000 -0.312000 0.936000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.800000 -0.100400 0.186900 0.104000 0.048000 0.992000 +-0.800000 -0.100400 0.186900 0.104000 0.048000 0.992000 +-0.800000 -0.063400 0.182900 0.240000 0.160000 0.952000 +-0.776900 -0.100400 0.182900 0.184000 0.120000 0.968000 +-0.800000 -0.050200 0.179900 0.264000 0.176000 0.944000 +-0.750000 -0.100400 0.174700 0.320000 0.192000 0.920000 +-0.750000 -0.050200 0.155100 0.464000 0.288000 0.832000 +-0.700000 -0.100400 0.138900 0.488000 0.288000 0.816000 +-0.708600 -0.050200 0.121900 0.496000 0.344000 0.784000 +-0.700000 -0.062200 0.121900 0.504000 0.344000 0.784000 +-0.700000 -0.050200 0.115300 0.496000 0.344000 0.792000 +-0.677900 -0.100400 0.121900 0.528000 0.328000 0.776000 +-0.650000 -0.050200 0.076400 0.576000 0.320000 0.744000 +-0.650000 -0.100400 0.096100 0.592000 0.288000 0.744000 +-0.635700 -0.050200 0.060900 0.640000 0.304000 0.696000 +-0.612900 -0.100400 0.060900 0.624000 0.376000 0.672000 +-0.600000 -0.050200 0.018400 0.648000 0.320000 0.688000 +-0.600000 -0.100400 0.044600 0.672000 0.336000 0.656000 +-0.584800 -0.050200 0.000000 0.744000 0.336000 0.568000 +-0.565600 -0.100400 0.000000 0.744000 0.440000 0.496000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.550000 -0.100400 -0.036900 0.792000 0.376000 0.464000 +-0.550000 -0.066800 -0.060900 0.944000 0.320000 -0.008000 +-0.533200 -0.100400 -0.060900 0.712000 0.696000 -0.024000 +-0.550000 -0.100400 -0.079500 0.552000 0.552000 -0.616000 +-0.500000 -0.119500 -0.060900 -0.160000 0.976000 0.112000 +-0.550000 -0.145600 -0.121900 0.512000 0.792000 -0.312000 +-0.500000 -0.144400 -0.121900 -0.376000 0.880000 -0.280000 +-0.550000 -0.150600 -0.142400 0.376000 0.896000 -0.200000 +-0.500000 -0.150600 -0.154000 -0.424000 0.880000 -0.160000 +-0.550000 -0.155500 -0.182900 0.296000 0.920000 -0.232000 +-0.500000 -0.154300 -0.182900 -0.320000 0.920000 -0.176000 +-0.550000 -0.172700 -0.243900 0.008000 0.856000 -0.512000 +-0.500000 -0.169200 -0.243900 -0.328000 0.880000 -0.312000 +-0.550000 -0.200800 -0.303600 -0.040000 0.880000 -0.464000 +-0.500000 -0.196700 -0.304800 -0.120000 0.848000 -0.504000 +-0.544700 -0.200800 -0.304800 -0.080000 0.824000 -0.552000 +-0.500000 -0.200800 -0.313000 -0.112000 0.824000 -0.544000 +-0.550000 -0.201300 -0.304800 -0.032000 0.864000 -0.488000 +-0.500000 -0.238600 -0.365800 -0.072000 0.656000 -0.744000 +-0.550000 -0.245600 -0.365800 -0.104000 0.680000 -0.720000 +-0.500000 -0.251000 -0.377000 -0.032000 0.528000 -0.840000 +-0.550000 -0.251000 -0.371400 -0.120000 0.616000 -0.768000 +-0.500000 -0.301200 -0.402500 0.040000 0.344000 -0.936000 +-0.550000 -0.301200 -0.401000 0.000000 0.424000 -0.904000 +-0.500000 -0.351500 -0.423900 0.056000 0.504000 -0.856000 +-0.550000 -0.349500 -0.426800 0.056000 0.416000 -0.904000 +-0.538500 -0.351500 -0.426800 0.048000 0.480000 -0.872000 +-0.500000 -0.351500 -0.423900 0.056000 0.504000 -0.856000 +-0.500000 -0.355300 -0.426800 0.056000 0.520000 -0.848000 +-0.450000 -0.351500 -0.418600 0.080000 0.512000 -0.848000 +-0.450000 -0.362400 -0.426800 0.064000 0.520000 -0.848000 +-0.400000 -0.351500 -0.411400 0.000000 0.616000 -0.784000 +-0.400000 -0.368700 -0.426800 0.024000 0.560000 -0.824000 +-0.350000 -0.351500 -0.416300 -0.176000 0.600000 -0.768000 +-0.350000 -0.360100 -0.426800 -0.128000 0.680000 -0.712000 +-0.319100 -0.351500 -0.426800 -0.216000 0.568000 -0.784000 +-0.350000 -0.351500 -0.416300 -0.176000 0.600000 -0.768000 +-0.300000 -0.341100 -0.426800 -0.128000 0.536000 -0.832000 +-0.350000 -0.301200 -0.377400 0.232000 0.208000 -0.944000 +-0.300000 -0.301200 -0.369600 0.320000 0.544000 -0.768000 +-0.350000 -0.251000 -0.367200 0.240000 0.168000 -0.952000 +-0.300000 -0.296900 -0.365800 0.296000 0.528000 -0.784000 +-0.345700 -0.251000 -0.365800 0.320000 0.336000 -0.880000 +-0.300000 -0.251000 -0.348000 0.192000 0.248000 -0.944000 +-0.350000 -0.248400 -0.365800 0.184000 0.424000 -0.880000 +-0.300000 -0.200800 -0.340600 0.016000 0.280000 -0.952000 +-0.350000 -0.200800 -0.339000 0.200000 0.416000 -0.880000 +-0.300000 -0.150600 -0.319300 -0.256000 0.480000 -0.832000 +-0.350000 -0.159400 -0.304800 -0.248000 0.528000 -0.808000 +-0.331500 -0.150600 -0.304800 -0.256000 0.464000 -0.840000 +-0.350000 -0.150600 -0.298700 -0.264000 0.464000 -0.840000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.350000 -0.100400 -0.248500 -0.576000 0.440000 -0.680000 +-0.300000 -0.100400 -0.298100 -0.480000 0.288000 -0.824000 +-0.350000 -0.093900 -0.243900 -0.600000 0.408000 -0.680000 +-0.300000 -0.050200 -0.270300 -0.824000 0.232000 -0.512000 +-0.321700 -0.050200 -0.243900 -0.656000 0.344000 -0.656000 +-0.300000 0.000000 -0.248500 -0.656000 0.560000 -0.488000 +-0.301700 0.000000 -0.243900 -0.744000 0.392000 -0.536000 +-0.300000 0.001800 -0.243900 -0.496000 0.680000 -0.520000 +-0.340600 0.000000 -0.182900 -0.696000 0.480000 -0.520000 +-0.300000 0.050200 -0.185100 -0.648000 0.560000 -0.504000 +-0.301000 0.050200 -0.182900 -0.704000 0.472000 -0.512000 +-0.300000 0.052000 -0.182900 -0.664000 0.464000 -0.568000 +-0.335400 0.050200 -0.121900 -0.752000 0.472000 -0.456000 +-0.300000 0.100400 -0.141500 -0.560000 0.512000 -0.640000 +-0.317300 0.100400 -0.121900 -0.712000 0.264000 -0.640000 +-0.300000 0.144000 -0.121900 -0.728000 0.496000 -0.456000 +-0.350000 0.100400 -0.076700 -0.736000 0.256000 -0.616000 +-0.300000 0.150600 -0.105900 -0.768000 0.536000 -0.320000 +-0.350000 0.148000 -0.060900 -0.504000 0.552000 0.656000 +-0.346000 0.150600 -0.060900 -0.768000 -0.144000 0.616000 +-0.350000 0.100400 -0.017600 -0.744000 0.352000 0.552000 +-0.300000 0.150600 -0.036000 -0.360000 0.064000 0.920000 +-0.321000 0.100400 0.000000 -0.264000 0.416000 0.864000 +-0.300000 0.112500 0.000000 -0.064000 0.472000 0.872000 +-0.300000 0.100400 0.006400 -0.200000 0.408000 0.880000 +-0.250000 0.104200 0.000000 0.144000 0.480000 0.856000 +-0.250000 0.100400 0.002600 0.144000 0.496000 0.848000 +-0.238500 0.100400 0.000000 0.152000 0.496000 0.848000 +-0.250000 0.050200 0.048300 0.000000 0.552000 0.832000 +-0.200000 0.089800 0.000000 0.216000 0.544000 0.800000 +-0.200000 0.050200 0.037800 0.512000 0.448000 0.720000 +-0.163800 0.050200 0.000000 0.704000 0.216000 0.664000 +-0.200000 0.020500 0.060900 0.664000 0.440000 0.600000 +-0.150800 0.000000 0.000000 0.744000 0.072000 0.656000 +-0.190300 0.000000 0.060900 0.816000 0.200000 0.536000 +-0.152800 -0.050200 0.000000 0.848000 0.032000 0.520000 +-0.193200 -0.050200 0.060900 0.808000 0.008000 0.584000 +-0.150600 -0.100400 0.000000 0.800000 0.040000 0.592000 +-0.190200 -0.100400 0.060900 0.752000 -0.248000 0.600000 +-0.150000 -0.104300 0.000000 0.496000 0.120000 0.848000 +-0.200000 -0.121800 0.060900 0.728000 -0.328000 0.592000 +-0.150000 -0.150600 0.010200 0.376000 0.208000 0.896000 +-0.200000 -0.150600 0.042600 0.640000 -0.096000 0.752000 +-0.150000 -0.200800 0.013600 0.104000 0.200000 0.968000 +-0.200000 -0.200800 0.045500 0.568000 -0.152000 0.808000 +-0.150000 -0.251000 0.002400 -0.056000 -0.176000 0.976000 +-0.200000 -0.251000 0.018200 0.408000 -0.392000 0.816000 +-0.150000 -0.301200 0.010200 -0.304000 -0.280000 0.904000 +-0.200000 -0.279600 0.000000 -0.016000 -0.496000 0.864000 +-0.169100 -0.301200 0.000000 -0.376000 -0.392000 0.832000 +-0.200000 -0.301200 -0.017500 -0.064000 -0.432000 0.896000 +-0.150000 -0.346200 0.000000 -0.392000 -0.160000 0.904000 +-0.200000 -0.351500 -0.031500 -0.320000 -0.128000 0.936000 +-0.150000 -0.351500 -0.001100 -0.192000 -0.352000 0.912000 +-0.200000 -0.401700 -0.023400 -0.056000 -0.008000 0.992000 +-0.150000 -0.401700 -0.019000 0.408000 -0.232000 0.880000 +-0.200000 -0.451900 -0.018000 0.376000 -0.112000 0.912000 +-0.150000 -0.451900 -0.041900 0.560000 -0.440000 0.696000 +-0.200000 -0.502100 -0.039000 0.512000 -0.608000 0.592000 +-0.150000 -0.470000 -0.060900 0.568000 -0.552000 0.600000 +-0.181900 -0.502100 -0.060900 0.504000 -0.680000 0.520000 +-0.150000 -0.502100 -0.111600 0.592000 -0.752000 0.280000 +-0.200000 -0.511900 -0.060900 0.416000 -0.800000 0.424000 +-0.150000 -0.505100 -0.121900 0.584000 -0.768000 0.240000 +-0.200000 -0.534300 -0.121900 0.456000 -0.832000 0.296000 +-0.150000 -0.510100 -0.182900 0.616000 -0.760000 0.168000 +-0.200000 -0.549300 -0.182900 0.504000 -0.784000 0.344000 +-0.150000 -0.530700 -0.243900 0.632000 -0.664000 0.392000 +-0.200000 -0.552300 -0.190900 0.520000 -0.768000 0.360000 +-0.172800 -0.552300 -0.243900 0.592000 -0.568000 0.560000 +-0.200000 -0.579600 -0.243900 0.568000 -0.648000 0.496000 +-0.150000 -0.552300 -0.270100 0.544000 -0.504000 0.656000 +-0.200000 -0.602500 -0.268600 0.488000 -0.432000 0.752000 +-0.150000 -0.602500 -0.302600 0.392000 -0.240000 0.880000 +-0.200000 -0.652700 -0.286600 0.488000 -0.272000 0.824000 +-0.150000 -0.609400 -0.304800 0.840000 -0.512000 0.152000 +-0.171500 -0.652700 -0.304800 0.576000 -0.304000 0.752000 +-0.150000 -0.602500 -0.307600 0.456000 -0.280000 -0.840000 +-0.200000 -0.652700 -0.326500 0.488000 -0.272000 -0.824000 +-0.200000 -0.602500 -0.345500 0.488000 -0.272000 -0.824000 +-0.250000 -0.652700 -0.361600 0.240000 -0.216000 -0.944000 +-0.229500 -0.602500 -0.365800 0.408000 -0.240000 -0.872000 +-0.250000 -0.639500 -0.365800 0.216000 -0.224000 -0.944000 +-0.250000 -0.602500 -0.376000 0.360000 -0.328000 -0.872000 +-0.282800 -0.652700 -0.365800 0.080000 -0.160000 -0.976000 +-0.300000 -0.602500 -0.397300 -0.248000 -0.488000 -0.832000 +-0.300000 -0.652700 -0.367500 0.064000 -0.112000 -0.984000 +-0.328400 -0.602500 -0.365800 -0.832000 -0.248000 -0.488000 +-0.350000 -0.652700 -0.376000 0.560000 0.160000 -0.808000 +-0.350000 -0.629600 -0.365800 0.056000 0.640000 -0.760000 +-0.400000 -0.652700 -0.368100 -0.128000 -0.872000 -0.456000 +-0.357100 -0.602500 -0.365800 0.904000 0.256000 -0.312000 +-0.400000 -0.621700 -0.426800 0.392000 -0.856000 -0.304000 +-0.370300 -0.602500 -0.426800 0.624000 -0.760000 -0.160000 +-0.357100 -0.602500 -0.365800 0.904000 0.256000 -0.312000 +-0.350000 -0.582100 -0.426800 0.344000 -0.808000 -0.456000 +-0.350000 -0.585900 -0.365800 0.168000 -0.792000 -0.576000 +-0.300000 -0.582000 -0.426800 0.336000 -0.608000 -0.712000 +-0.328400 -0.602500 -0.365800 -0.832000 -0.248000 -0.488000 +-0.300000 -0.602500 -0.397300 -0.248000 -0.488000 -0.832000 +-0.300000 -0.582000 -0.426800 0.336000 -0.608000 -0.712000 +-0.250000 -0.602500 -0.376000 0.360000 -0.328000 -0.872000 +-0.275900 -0.552300 -0.426800 0.528000 -0.480000 -0.696000 +-0.250000 -0.552300 -0.402600 0.504000 -0.312000 -0.792000 +-0.250000 -0.526200 -0.426800 0.576000 -0.448000 -0.672000 +-0.200000 -0.552300 -0.367100 0.360000 -0.232000 -0.896000 +-0.235700 -0.502100 -0.426800 0.696000 -0.464000 -0.536000 +-0.200000 -0.502100 -0.370700 0.184000 -0.352000 -0.912000 +-0.200000 -0.459900 -0.426800 0.560000 -0.592000 -0.576000 +-0.150000 -0.502100 -0.367300 0.088000 -0.320000 -0.936000 +-0.191200 -0.451900 -0.426800 0.664000 -0.480000 -0.560000 +-0.150000 -0.451900 -0.368100 0.456000 -0.056000 -0.880000 +-0.194300 -0.401700 -0.426800 0.792000 0.416000 -0.432000 +-0.150000 -0.417500 -0.365800 0.544000 0.056000 -0.832000 +-0.151700 -0.401700 -0.365800 0.568000 0.104000 -0.808000 +-0.150000 -0.401700 -0.364300 0.552000 0.080000 -0.824000 +-0.200000 -0.365300 -0.365800 0.504000 0.768000 -0.376000 +-0.150000 -0.351500 -0.350300 0.512000 0.192000 -0.832000 +-0.200000 -0.351500 -0.343300 0.312000 0.640000 -0.696000 +-0.150000 -0.301200 -0.318500 -0.024000 0.504000 -0.856000 +-0.200000 -0.301200 -0.313400 0.328000 0.152000 -0.928000 +-0.150000 -0.286300 -0.304800 -0.184000 0.480000 -0.848000 +-0.200000 -0.251000 -0.307600 0.408000 0.096000 -0.904000 +-0.195100 -0.251000 -0.304800 0.376000 0.112000 -0.912000 +-0.200000 -0.200800 -0.306700 0.368000 -0.184000 -0.904000 +-0.196100 -0.200800 -0.304800 0.360000 -0.200000 -0.904000 +-0.200000 -0.150600 -0.333300 0.216000 -0.272000 -0.936000 +-0.150000 -0.159100 -0.304800 0.152000 -0.400000 -0.896000 +-0.150000 -0.150600 -0.309500 -0.032000 -0.400000 -0.912000 +-0.108400 -0.200800 -0.304800 -0.496000 -0.048000 -0.856000 +-0.100000 -0.150600 -0.315000 -0.456000 -0.064000 -0.880000 +-0.100000 -0.200800 -0.311700 -0.496000 0.128000 -0.856000 +-0.050000 -0.150600 -0.332400 0.016000 -0.080000 -0.992000 +-0.050000 -0.200800 -0.320900 -0.056000 0.280000 -0.952000 +0.000000 -0.150600 -0.318000 0.160000 0.016000 -0.984000 +0.000000 -0.200800 -0.332000 -0.296000 0.528000 -0.784000 +0.050000 -0.150600 -0.318000 0.352000 0.312000 -0.872000 +0.050000 -0.200800 -0.360800 -0.016000 0.576000 -0.808000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +0.100000 -0.200800 -0.352600 0.240000 0.528000 -0.800000 +0.100000 -0.151600 -0.304800 -0.176000 0.536000 -0.816000 +0.150000 -0.200800 -0.325200 0.160000 0.176000 -0.968000 +0.101900 -0.150600 -0.304800 -0.296000 0.368000 -0.872000 +0.150000 -0.150600 -0.323600 -0.232000 0.464000 -0.848000 +0.114400 -0.100400 -0.304800 -0.344000 0.128000 -0.928000 +0.150000 -0.100400 -0.322200 0.000000 0.224000 -0.968000 +0.150000 -0.064700 -0.304800 -0.200000 0.328000 -0.912000 +0.185500 -0.100400 -0.304800 0.296000 0.104000 -0.944000 +0.150000 -0.050200 -0.298400 -0.176000 0.328000 -0.920000 +0.200000 -0.100400 -0.298900 0.088000 0.040000 -0.992000 +0.188500 -0.050200 -0.304800 -0.128000 0.184000 -0.968000 +0.200000 -0.061600 -0.304800 0.000000 -0.144000 -0.984000 +0.200000 -0.050200 -0.307000 0.000000 0.192000 -0.976000 +0.211400 -0.050200 -0.304800 0.152000 0.184000 -0.968000 +0.200000 -0.045300 -0.304800 -0.008000 0.344000 -0.936000 +0.250000 -0.050200 -0.297000 0.000000 0.040000 -0.992000 +0.200000 0.000000 -0.277300 0.080000 0.528000 -0.840000 +0.250000 0.000000 -0.271900 -0.336000 0.528000 -0.776000 +0.200000 0.025700 -0.243900 0.016000 0.752000 -0.648000 +0.250000 0.018500 -0.243900 -0.144000 0.856000 -0.480000 +0.200000 0.019700 -0.182900 0.160000 0.648000 0.736000 +0.250000 0.002800 -0.182900 0.128000 0.640000 0.752000 +0.200000 0.000000 -0.161400 0.032000 0.656000 0.752000 +0.250000 0.000000 -0.180400 0.176000 0.568000 0.792000 +0.200000 -0.041200 -0.121900 0.160000 0.488000 0.856000 +0.250000 -0.050200 -0.132500 0.192000 0.528000 0.816000 +0.222300 -0.050200 -0.121900 0.200000 0.432000 0.872000 +0.250000 -0.068700 -0.121900 0.096000 0.400000 0.904000 +0.200000 -0.050200 -0.116900 0.136000 0.368000 0.912000 +0.250000 -0.100400 -0.106800 0.080000 0.336000 0.936000 +0.200000 -0.100400 -0.095800 0.064000 0.272000 0.952000 +0.250000 -0.150600 -0.087200 0.040000 0.104000 0.992000 +0.200000 -0.150600 -0.099300 0.040000 0.104000 0.992000 +0.250000 -0.200800 -0.084100 0.120000 -0.168000 0.976000 +0.200000 -0.200800 -0.086600 0.112000 -0.336000 0.928000 +0.250000 -0.237200 -0.121900 0.048000 -0.656000 0.744000 +0.200000 -0.240500 -0.121900 0.152000 -0.656000 0.728000 +0.250000 -0.251000 -0.140300 -0.072000 -0.512000 0.848000 +0.200000 -0.251000 -0.134700 0.128000 -0.784000 0.600000 +0.250000 -0.301200 -0.149400 -0.376000 -0.584000 0.712000 +0.200000 -0.290700 -0.182900 -0.520000 -0.680000 0.512000 +0.211500 -0.301200 -0.182900 -0.568000 -0.672000 0.464000 +0.200000 -0.301200 -0.206400 -0.600000 -0.688000 0.384000 +0.250000 -0.319600 -0.182900 -0.280000 -0.832000 0.472000 +0.200000 -0.319700 -0.243900 -0.624000 -0.696000 0.328000 +0.250000 -0.343100 -0.243900 -0.320000 -0.920000 0.208000 +0.200000 -0.340400 -0.304800 -0.480000 -0.448000 -0.744000 +0.250000 -0.348300 -0.304800 -0.128000 -0.736000 -0.656000 +0.200000 -0.301200 -0.321600 -0.488000 -0.368000 -0.784000 +0.250000 -0.313600 -0.365800 -0.336000 -0.640000 -0.680000 +0.236200 -0.301200 -0.365800 -0.608000 -0.320000 -0.712000 +0.250000 -0.301200 -0.379400 -0.536000 -0.264000 -0.792000 +0.250000 -0.271800 -0.365800 -0.320000 0.360000 -0.872000 +0.300000 -0.301200 -0.372900 0.128000 -0.472000 -0.864000 +0.300000 -0.284400 -0.365800 0.136000 0.360000 -0.920000 +0.333500 -0.301200 -0.365800 0.208000 -0.080000 -0.968000 +0.300000 -0.251000 -0.347800 0.304000 0.384000 -0.864000 +0.350000 -0.301200 -0.360500 0.376000 0.184000 -0.904000 +0.350000 -0.251000 -0.329500 0.536000 0.472000 -0.688000 +0.400000 -0.301200 -0.307300 0.704000 0.496000 -0.496000 +0.366700 -0.251000 -0.304800 0.704000 0.488000 -0.496000 +0.400000 -0.299100 -0.304800 0.736000 0.472000 -0.472000 +0.399000 -0.251000 -0.243900 0.912000 -0.008000 -0.392000 +0.400000 -0.252300 -0.243900 0.744000 0.488000 -0.440000 +0.398900 -0.251000 -0.182900 0.896000 -0.160000 0.400000 +0.400000 -0.252800 -0.182900 0.760000 0.464000 0.440000 +0.354900 -0.251000 -0.121900 0.704000 -0.304000 0.632000 +0.400000 -0.301200 -0.149800 0.528000 0.376000 0.752000 +0.350000 -0.260400 -0.121900 0.448000 -0.472000 0.752000 +0.350000 -0.301200 -0.148100 0.392000 -0.048000 0.912000 +0.328900 -0.251000 -0.121900 -0.264000 -0.304000 0.912000 +0.300000 -0.301200 -0.149800 -0.024000 -0.480000 0.872000 +0.300000 -0.251000 -0.132800 -0.224000 -0.464000 0.856000 +0.250000 -0.301200 -0.149400 -0.376000 -0.584000 0.712000 +0.250000 -0.251000 -0.140300 -0.072000 -0.512000 0.848000 +0.300000 -0.251000 -0.132800 -0.224000 -0.464000 0.856000 +0.250000 -0.237200 -0.121900 0.048000 -0.656000 0.744000 +0.300000 -0.234400 -0.121900 0.104000 -0.472000 0.872000 +0.250000 -0.200800 -0.084100 0.120000 -0.168000 0.976000 +0.300000 -0.200800 -0.101500 0.424000 -0.216000 0.872000 +0.250000 -0.150600 -0.087200 0.040000 0.104000 0.992000 +0.300000 -0.150600 -0.090800 0.240000 -0.024000 0.968000 +0.250000 -0.100400 -0.106800 0.080000 0.336000 0.936000 +0.300000 -0.100400 -0.098900 -0.360000 0.344000 0.856000 +0.250000 -0.068700 -0.121900 0.096000 0.400000 0.904000 +0.300000 -0.060700 -0.121900 -0.512000 0.456000 0.720000 +0.250000 -0.050200 -0.132500 0.192000 0.528000 0.816000 +0.300000 -0.050200 -0.130700 -0.504000 0.472000 0.720000 +0.250000 0.000000 -0.180400 0.176000 0.568000 0.792000 +0.300000 0.000000 -0.166100 -0.488000 0.464000 0.728000 +0.250000 0.002800 -0.182900 0.128000 0.640000 0.752000 +0.300000 0.018000 -0.182900 -0.296000 0.768000 0.552000 +0.250000 0.018500 -0.243900 -0.144000 0.856000 -0.480000 +0.300000 0.032100 -0.243900 -0.576000 0.680000 -0.432000 +0.250000 0.000000 -0.271900 -0.336000 0.528000 -0.776000 +0.300000 0.000000 -0.302400 -0.544000 0.608000 -0.568000 +0.250000 -0.050200 -0.297000 0.000000 0.040000 -0.992000 +0.300000 -0.003100 -0.304800 -0.376000 0.424000 -0.816000 +0.266500 -0.050200 -0.304800 -0.280000 0.064000 -0.952000 +0.300000 -0.050200 -0.319900 -0.536000 0.224000 -0.808000 +0.278900 -0.100400 -0.304800 -0.176000 0.256000 -0.944000 +0.300000 -0.100400 -0.310000 -0.248000 0.072000 -0.960000 +0.250000 -0.114900 -0.304800 -0.104000 0.280000 -0.952000 +0.300000 -0.150600 -0.312600 0.312000 -0.200000 -0.920000 +0.250000 -0.150600 -0.317700 0.024000 0.336000 -0.936000 +0.300000 -0.200800 -0.324200 0.480000 0.248000 -0.832000 +0.250000 -0.200800 -0.343100 0.104000 0.232000 -0.960000 +0.300000 -0.251000 -0.347800 0.304000 0.384000 -0.864000 +0.250000 -0.251000 -0.353900 0.064000 0.384000 -0.920000 +0.300000 -0.284400 -0.365800 0.136000 0.360000 -0.920000 +0.250000 -0.271800 -0.365800 -0.320000 0.360000 -0.872000 +0.250000 -0.251000 -0.353900 0.064000 0.384000 -0.920000 +0.236200 -0.301200 -0.365800 -0.608000 -0.320000 -0.712000 +0.200000 -0.251000 -0.346500 -0.184000 0.088000 -0.976000 +0.200000 -0.301200 -0.321600 -0.488000 -0.368000 -0.784000 +0.150000 -0.251000 -0.336000 0.080000 -0.336000 -0.928000 +0.170700 -0.301200 -0.304800 -0.520000 -0.608000 -0.592000 +0.150000 -0.287400 -0.304800 0.000000 -0.712000 -0.688000 +0.176900 -0.301200 -0.243900 -0.504000 -0.800000 0.304000 +0.150000 -0.287700 -0.243900 -0.208000 -0.968000 0.064000 +0.200000 -0.301200 -0.206400 -0.600000 -0.688000 0.384000 +0.150000 -0.278000 -0.182900 -0.064000 -0.936000 0.328000 +0.200000 -0.290700 -0.182900 -0.520000 -0.680000 0.512000 +0.150000 -0.253200 -0.121900 0.192000 -0.808000 0.552000 +0.200000 -0.251000 -0.134700 0.128000 -0.784000 0.600000 +0.161400 -0.251000 -0.121900 0.152000 -0.792000 0.576000 +0.200000 -0.240500 -0.121900 0.152000 -0.656000 0.728000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +0.200000 -0.200800 -0.086600 0.112000 -0.336000 0.928000 +0.150000 -0.200800 -0.071800 0.312000 -0.208000 0.920000 +0.200000 -0.150600 -0.099300 0.040000 0.104000 0.992000 +0.150000 -0.150600 -0.071000 0.136000 0.176000 0.968000 +0.200000 -0.100400 -0.095800 0.064000 0.272000 0.952000 +0.150000 -0.100400 -0.080500 0.184000 0.336000 0.920000 +0.200000 -0.050200 -0.116900 0.136000 0.368000 0.912000 +0.150000 -0.050200 -0.113700 0.032000 0.448000 0.888000 +0.200000 -0.041200 -0.121900 0.160000 0.488000 0.856000 +0.150000 -0.036300 -0.121900 0.008000 0.488000 0.864000 +0.200000 0.000000 -0.161400 0.032000 0.656000 0.752000 +0.150000 0.000000 -0.166100 -0.096000 0.688000 0.712000 +0.200000 0.019700 -0.182900 0.160000 0.648000 0.736000 +0.150000 0.016800 -0.182900 -0.152000 0.840000 0.520000 +0.200000 0.025700 -0.243900 0.016000 0.752000 -0.648000 +0.150000 0.015400 -0.243900 -0.208000 0.728000 -0.640000 +0.200000 0.000000 -0.277300 0.080000 0.528000 -0.840000 +0.150000 0.000000 -0.257100 -0.208000 0.552000 -0.800000 +0.200000 -0.045300 -0.304800 -0.008000 0.344000 -0.936000 +0.150000 -0.050200 -0.298400 -0.176000 0.328000 -0.920000 +0.188500 -0.050200 -0.304800 -0.128000 0.184000 -0.968000 +0.200000 -0.045300 -0.304800 -0.008000 0.344000 -0.936000 +0.200000 -0.050200 -0.307000 0.000000 0.192000 -0.976000 +0.200000 -0.050200 -0.307000 0.000000 0.192000 -0.976000 +-0.800000 -0.100400 0.186900 0.104000 0.048000 0.992000 +-0.800000 -0.100400 0.186900 0.104000 0.048000 0.992000 +-0.776900 -0.100400 0.182900 0.184000 0.120000 0.968000 +-0.800000 -0.150600 0.189500 -0.240000 -0.056000 0.960000 +-0.750000 -0.136500 0.182900 0.216000 0.112000 0.968000 +-0.750000 -0.150600 0.184600 0.192000 0.080000 0.976000 +-0.743500 -0.150600 0.182900 0.192000 0.096000 0.968000 +-0.750000 -0.200800 0.187200 0.064000 -0.048000 0.992000 +-0.703900 -0.200800 0.182900 0.128000 0.064000 0.984000 +-0.750000 -0.251000 0.186100 -0.160000 -0.136000 0.976000 +-0.700000 -0.208700 0.182900 0.176000 0.120000 0.968000 +-0.700000 -0.251000 0.184700 0.008000 -0.024000 0.992000 +-0.650000 -0.249200 0.182900 0.176000 0.464000 0.864000 +-0.650000 -0.251000 0.183700 0.152000 0.272000 0.944000 +-0.638500 -0.251000 0.182900 0.072000 0.424000 0.896000 +-0.650000 -0.301200 0.185200 -0.152000 0.008000 0.984000 +-0.600000 -0.260000 0.182900 0.056000 0.320000 0.944000 +-0.600000 -0.301200 0.196400 -0.152000 0.176000 0.968000 +-0.550000 -0.264400 0.182900 -0.072000 0.456000 0.880000 +-0.550000 -0.301200 0.200100 -0.040000 0.312000 0.944000 +-0.512000 -0.251000 0.182900 -0.112000 0.632000 0.760000 +-0.500000 -0.301200 0.199600 -0.128000 0.216000 0.960000 +-0.500000 -0.251000 0.185100 -0.112000 0.632000 0.760000 +-0.450000 -0.301200 0.203900 0.032000 0.168000 0.984000 +-0.450000 -0.251000 0.195400 -0.152000 0.392000 0.904000 +-0.400000 -0.301200 0.211000 0.416000 0.000000 0.904000 +-0.400000 -0.251000 0.203200 0.024000 0.208000 0.976000 +-0.369700 -0.301200 0.182900 0.552000 -0.328000 0.752000 +-0.350000 -0.251000 0.206900 0.584000 -0.272000 0.760000 +-0.350000 -0.276800 0.182900 0.600000 -0.432000 0.664000 +-0.334800 -0.251000 0.182900 0.672000 -0.480000 0.552000 +-0.350000 -0.301200 0.167500 0.592000 -0.368000 0.712000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.327200 -0.301200 0.121900 0.792000 -0.368000 0.472000 +-0.300000 -0.256400 0.121900 0.624000 -0.624000 0.456000 +-0.300000 -0.301200 0.065200 0.504000 -0.568000 0.640000 +-0.294600 -0.251000 0.121900 0.616000 -0.600000 0.488000 +-0.295000 -0.301200 0.060900 0.472000 -0.584000 0.648000 +-0.250000 -0.251000 0.071500 0.528000 -0.408000 0.736000 +-0.250000 -0.262800 0.060900 0.496000 -0.520000 0.688000 +-0.236900 -0.251000 0.060900 0.464000 -0.480000 0.728000 +-0.250000 -0.301200 0.006000 0.344000 -0.608000 0.704000 +-0.200000 -0.251000 0.018200 0.408000 -0.392000 0.816000 +-0.235900 -0.301200 0.000000 0.272000 -0.568000 0.768000 +-0.200000 -0.279600 0.000000 -0.016000 -0.496000 0.864000 +-0.200000 -0.301200 -0.017500 -0.064000 -0.432000 0.896000 +-0.235900 -0.301200 0.000000 0.272000 -0.568000 0.768000 +-0.200000 -0.351500 -0.031500 -0.320000 -0.128000 0.936000 +-0.250000 -0.307700 0.000000 0.288000 -0.576000 0.760000 +-0.250000 -0.351500 -0.038300 0.104000 -0.504000 0.848000 +-0.300000 -0.343500 0.000000 0.832000 -0.408000 0.360000 +-0.300000 -0.351500 -0.012600 0.872000 -0.352000 0.320000 +-0.303300 -0.351500 0.000000 0.888000 -0.344000 0.288000 +-0.300000 -0.401700 -0.045100 0.792000 -0.248000 0.544000 +-0.319500 -0.401700 0.000000 0.536000 -0.584000 0.592000 +-0.300000 -0.435300 -0.060900 -0.192000 -0.360000 0.912000 +-0.350000 -0.427600 0.000000 0.560000 -0.752000 0.336000 +-0.338500 -0.451900 -0.060900 0.112000 -0.632000 0.760000 +-0.350000 -0.451900 -0.058800 0.248000 -0.624000 0.728000 +-0.350000 -0.453900 -0.060900 0.248000 -0.624000 0.728000 +-0.400000 -0.451900 -0.009600 0.744000 -0.536000 0.376000 +-0.380200 -0.502100 -0.060900 0.648000 -0.616000 0.432000 +-0.400000 -0.502100 -0.024700 0.848000 -0.224000 0.464000 +-0.400000 -0.527700 -0.060900 0.080000 -0.768000 0.624000 +-0.450000 -0.502100 -0.045100 0.560000 -0.696000 0.432000 +-0.450000 -0.512800 -0.060900 0.208000 -0.760000 0.608000 +-0.466200 -0.502100 0.000000 0.712000 -0.616000 0.320000 +-0.478800 -0.552300 -0.060900 0.704000 -0.592000 0.376000 +-0.500000 -0.548400 0.000000 0.368000 -0.816000 0.432000 +-0.500000 -0.552300 -0.009400 0.352000 -0.840000 0.400000 +-0.509600 -0.552300 0.000000 0.320000 -0.840000 0.424000 +-0.500000 -0.570000 -0.060900 0.480000 -0.800000 0.328000 +-0.550000 -0.565800 0.000000 0.224000 -0.872000 0.424000 +-0.550000 -0.588500 -0.060900 0.224000 -0.888000 0.384000 +-0.600000 -0.566300 0.000000 -0.184000 -0.816000 0.544000 +-0.600000 -0.601900 -0.060900 -0.072000 -0.808000 0.568000 +-0.633400 -0.552300 0.000000 -0.384000 -0.672000 0.624000 +-0.650000 -0.594800 -0.060900 -0.368000 -0.640000 0.664000 +-0.650000 -0.552300 -0.012600 -0.496000 -0.592000 0.624000 +-0.685200 -0.552300 -0.060900 -0.696000 -0.384000 0.592000 +-0.650000 -0.541900 0.000000 -0.528000 -0.600000 0.592000 +-0.700000 -0.507800 -0.060900 -0.864000 -0.200000 0.448000 +-0.674300 -0.502100 0.000000 -0.656000 -0.632000 0.384000 +-0.700000 -0.502100 -0.057900 -0.752000 -0.512000 0.400000 +-0.700000 -0.478200 0.000000 -0.704000 -0.632000 0.312000 +-0.701200 -0.502100 -0.060900 -0.816000 -0.416000 0.392000 +-0.719800 -0.451900 0.000000 -0.816000 -0.520000 0.240000 +-0.735400 -0.451900 -0.060900 -0.768000 -0.512000 0.360000 +-0.750000 -0.403200 0.000000 -0.832000 -0.504000 0.216000 +-0.750000 -0.426100 -0.060900 -0.864000 -0.448000 0.200000 +-0.750800 -0.401700 0.000000 -0.816000 -0.520000 0.208000 +-0.762700 -0.401700 -0.060900 -0.840000 -0.496000 0.168000 +-0.782800 -0.351500 0.000000 -0.816000 -0.536000 0.208000 +-0.794800 -0.351500 -0.060900 -0.816000 -0.552000 0.144000 +-0.800000 -0.327900 0.000000 -0.800000 -0.560000 0.176000 +-0.800000 -0.343900 -0.060900 -0.816000 -0.552000 0.128000 +-0.817700 -0.301200 0.000000 -0.808000 -0.560000 0.168000 +-0.826600 -0.301200 -0.060900 -0.824000 -0.544000 0.120000 +-0.800000 -0.343900 -0.060900 -0.816000 -0.552000 0.128000 +-0.832400 -0.301200 -0.121900 -0.840000 -0.528000 0.048000 +-0.800000 -0.351500 -0.101400 -0.840000 -0.528000 0.104000 +-0.802000 -0.351500 -0.121900 -0.840000 -0.520000 0.096000 +-0.800000 -0.354700 -0.121900 -0.848000 -0.512000 0.080000 +-0.802200 -0.351500 -0.182900 -0.872000 -0.480000 0.016000 +-0.800000 -0.355500 -0.182900 -0.872000 -0.472000 0.032000 +-0.807300 -0.351500 -0.243900 -0.864000 -0.472000 0.152000 +-0.800000 -0.365300 -0.243900 -0.880000 -0.440000 0.160000 +-0.821000 -0.351500 -0.304800 -0.824000 -0.504000 0.232000 +-0.800000 -0.395700 -0.304800 -0.920000 -0.376000 0.000000 +-0.812200 -0.351500 -0.365800 -0.856000 -0.296000 -0.408000 +-0.800000 -0.388500 -0.365800 -0.864000 -0.288000 -0.400000 +-0.800000 -0.351500 -0.388300 -0.664000 -0.152000 -0.728000 +-0.796500 -0.401700 -0.365800 -0.952000 -0.168000 -0.232000 +-0.750000 -0.351500 -0.422100 -0.312000 0.448000 -0.824000 +-0.777800 -0.401700 -0.426800 -0.928000 0.040000 -0.360000 +-0.750000 -0.359700 -0.426800 -0.368000 0.408000 -0.832000 +-0.750000 -0.351500 -0.422100 -0.312000 0.448000 -0.824000 +-0.736800 -0.351500 -0.426800 -0.240000 0.480000 -0.832000 +-0.736800 -0.351500 -0.426800 -0.240000 0.480000 -0.832000 +-0.750000 -0.150600 0.184600 0.192000 0.080000 0.976000 +-0.750000 -0.150600 0.184600 0.192000 0.080000 0.976000 +-0.800000 -0.150600 0.189500 -0.240000 -0.056000 0.960000 +-0.750000 -0.200800 0.187200 0.064000 -0.048000 0.992000 +-0.800000 -0.200800 0.184500 -0.256000 -0.128000 0.952000 +-0.750000 -0.251000 0.186100 -0.160000 -0.136000 0.976000 +-0.800000 -0.206500 0.182900 -0.304000 -0.264000 0.912000 +-0.762000 -0.251000 0.182900 -0.256000 -0.192000 0.936000 +-0.800000 -0.251000 0.157900 -0.576000 -0.400000 0.696000 +-0.750000 -0.267900 0.182900 -0.232000 -0.192000 0.944000 +-0.800000 -0.280700 0.121900 -0.736000 -0.528000 0.408000 +-0.750000 -0.301200 0.168400 -0.360000 -0.432000 0.816000 +-0.783300 -0.301200 0.121900 -0.688000 -0.568000 0.440000 +-0.750000 -0.342500 0.121900 -0.536000 -0.592000 0.592000 +-0.800000 -0.301200 0.085900 -0.768000 -0.544000 0.304000 +-0.750000 -0.351500 0.110100 -0.600000 -0.584000 0.536000 +-0.800000 -0.310100 0.060900 -0.800000 -0.544000 0.224000 +-0.767900 -0.351500 0.060900 -0.760000 -0.568000 0.296000 +-0.800000 -0.327900 0.000000 -0.800000 -0.560000 0.176000 +-0.782800 -0.351500 0.000000 -0.816000 -0.536000 0.208000 +-0.767900 -0.351500 0.060900 -0.760000 -0.568000 0.296000 +-0.750800 -0.401700 0.000000 -0.816000 -0.520000 0.208000 +-0.750000 -0.377100 0.060900 -0.760000 -0.552000 0.320000 +-0.750000 -0.401700 0.004100 -0.816000 -0.520000 0.232000 +-0.731300 -0.401700 0.060900 -0.784000 -0.496000 0.344000 +-0.750000 -0.403200 0.000000 -0.832000 -0.504000 0.216000 +-0.701000 -0.451900 0.060900 -0.792000 -0.480000 0.344000 +-0.719800 -0.451900 0.000000 -0.816000 -0.520000 0.240000 +-0.700000 -0.453200 0.060900 -0.560000 -0.720000 0.392000 +-0.700000 -0.478200 0.000000 -0.704000 -0.632000 0.312000 +-0.650000 -0.495900 0.060900 -0.528000 -0.720000 0.432000 +-0.674300 -0.502100 0.000000 -0.656000 -0.632000 0.384000 +-0.650000 -0.502100 0.048300 -0.536000 -0.712000 0.440000 +-0.650000 -0.541900 0.000000 -0.528000 -0.600000 0.592000 +-0.640700 -0.502100 0.060900 -0.496000 -0.728000 0.456000 +-0.633400 -0.552300 0.000000 -0.384000 -0.672000 0.624000 +-0.600000 -0.531600 0.060900 -0.448000 -0.736000 0.496000 +-0.600000 -0.552300 0.023900 -0.224000 -0.776000 0.584000 +-0.550000 -0.532000 0.060900 0.080000 -0.776000 0.624000 +-0.550000 -0.552300 0.031000 0.256000 -0.800000 0.528000 +-0.500000 -0.517700 0.060900 0.632000 -0.632000 0.440000 +-0.509600 -0.552300 0.000000 0.320000 -0.840000 0.424000 +-0.500000 -0.548400 0.000000 0.368000 -0.816000 0.432000 +-0.500000 -0.517700 0.060900 0.632000 -0.632000 0.440000 +-0.466200 -0.502100 0.000000 0.712000 -0.616000 0.320000 +-0.489100 -0.502100 0.060900 0.704000 -0.616000 0.328000 +-0.450000 -0.489500 0.000000 0.584000 -0.760000 0.264000 +-0.450000 -0.471900 0.060900 0.592000 -0.752000 0.272000 +-0.403800 -0.451900 0.000000 0.744000 -0.560000 0.352000 +-0.425300 -0.451900 0.060900 0.696000 -0.640000 0.304000 +-0.400000 -0.447100 0.000000 0.720000 -0.584000 0.344000 +-0.400000 -0.423000 0.060900 0.616000 -0.696000 0.360000 +-0.350000 -0.427600 0.000000 0.560000 -0.752000 0.336000 +-0.350000 -0.406300 0.060900 0.592000 -0.728000 0.320000 +-0.319500 -0.401700 0.000000 0.536000 -0.584000 0.592000 +-0.344500 -0.401700 0.060900 0.632000 -0.688000 0.328000 +-0.303300 -0.351500 0.000000 0.888000 -0.344000 0.288000 +-0.319700 -0.351500 0.060900 0.864000 -0.376000 0.328000 +-0.300000 -0.343500 0.000000 0.832000 -0.408000 0.360000 +-0.300000 -0.305300 0.060900 0.512000 -0.568000 0.632000 +-0.250000 -0.307700 0.000000 0.288000 -0.576000 0.760000 +-0.295000 -0.301200 0.060900 0.472000 -0.584000 0.648000 +-0.250000 -0.301200 0.006000 0.344000 -0.608000 0.704000 +-0.250000 -0.262800 0.060900 0.496000 -0.520000 0.688000 +-0.250000 -0.262800 0.060900 0.496000 -0.520000 0.688000 +-0.762000 -0.251000 0.182900 -0.256000 -0.192000 0.936000 +-0.762000 -0.251000 0.182900 -0.256000 -0.192000 0.936000 +-0.750000 -0.251000 0.186100 -0.160000 -0.136000 0.976000 +-0.750000 -0.267900 0.182900 -0.232000 -0.192000 0.944000 +-0.700000 -0.251000 0.184700 0.008000 -0.024000 0.992000 +-0.700000 -0.272200 0.182900 -0.072000 -0.128000 0.984000 +-0.650000 -0.251000 0.183700 0.152000 0.272000 0.944000 +-0.671000 -0.301200 0.182900 -0.120000 -0.104000 0.984000 +-0.650000 -0.301200 0.185200 -0.152000 0.008000 0.984000 +-0.663400 -0.351500 0.182900 -0.304000 -0.080000 0.944000 +-0.650000 -0.351500 0.187800 -0.272000 -0.048000 0.952000 +-0.650000 -0.385200 0.182900 -0.496000 -0.152000 0.848000 +-0.600000 -0.351500 0.201700 -0.216000 0.016000 0.968000 +-0.644900 -0.401700 0.182900 -0.528000 -0.240000 0.808000 +-0.600000 -0.401700 0.205900 -0.320000 -0.144000 0.928000 +-0.600000 -0.446800 0.182900 -0.240000 -0.464000 0.848000 +-0.550000 -0.401700 0.218500 0.000000 -0.272000 0.960000 +-0.583500 -0.451900 0.182900 -0.128000 -0.544000 0.824000 +-0.550000 -0.451900 0.188900 -0.024000 -0.624000 0.776000 +-0.550000 -0.456500 0.182900 0.056000 -0.736000 0.672000 +-0.523100 -0.451900 0.182900 0.136000 -0.648000 0.744000 +-0.550000 -0.494000 0.121900 0.024000 -0.832000 0.536000 +-0.500000 -0.451900 0.177400 0.160000 -0.648000 0.736000 +-0.500000 -0.486900 0.121900 0.296000 -0.800000 0.504000 +-0.450000 -0.451900 0.126400 0.752000 -0.472000 0.448000 +-0.450000 -0.453600 0.121900 0.584000 -0.744000 0.288000 +-0.447800 -0.451900 0.121900 0.672000 -0.648000 0.344000 +-0.450000 -0.471900 0.060900 0.592000 -0.752000 0.272000 +-0.425300 -0.451900 0.060900 0.696000 -0.640000 0.304000 +-0.447800 -0.451900 0.121900 0.672000 -0.648000 0.344000 +-0.400000 -0.423000 0.060900 0.616000 -0.696000 0.360000 +-0.404400 -0.401700 0.121900 0.648000 -0.656000 0.368000 +-0.400000 -0.401700 0.111300 0.640000 -0.680000 0.336000 +-0.400000 -0.397400 0.121900 0.632000 -0.672000 0.368000 +-0.350000 -0.401700 0.073400 0.632000 -0.688000 0.344000 +-0.350000 -0.369000 0.121900 0.736000 -0.464000 0.480000 +-0.344500 -0.401700 0.060900 0.632000 -0.688000 0.328000 +-0.341600 -0.351500 0.121900 0.808000 -0.352000 0.456000 +-0.319700 -0.351500 0.060900 0.864000 -0.376000 0.328000 +-0.327200 -0.301200 0.121900 0.792000 -0.368000 0.472000 +-0.300000 -0.305300 0.060900 0.512000 -0.568000 0.632000 +-0.300000 -0.301200 0.065200 0.504000 -0.568000 0.640000 +-0.295000 -0.301200 0.060900 0.472000 -0.584000 0.648000 +-0.295000 -0.301200 0.060900 0.472000 -0.584000 0.648000 +-0.650000 -0.301200 0.185200 -0.152000 0.008000 0.984000 +-0.650000 -0.301200 0.185200 -0.152000 0.008000 0.984000 +-0.650000 -0.351500 0.187800 -0.272000 -0.048000 0.952000 +-0.600000 -0.301200 0.196400 -0.152000 0.176000 0.968000 +-0.600000 -0.351500 0.201700 -0.216000 0.016000 0.968000 +-0.550000 -0.301200 0.200100 -0.040000 0.312000 0.944000 +-0.550000 -0.351500 0.211500 0.000000 0.128000 0.984000 +-0.500000 -0.301200 0.199600 -0.128000 0.216000 0.960000 +-0.500000 -0.351500 0.209200 0.072000 0.104000 0.984000 +-0.450000 -0.301200 0.203900 0.032000 0.168000 0.984000 +-0.450000 -0.351500 0.215900 0.592000 -0.216000 0.768000 +-0.400000 -0.301200 0.211000 0.416000 0.000000 0.904000 +-0.400000 -0.351500 0.196700 0.560000 -0.576000 0.584000 +-0.369700 -0.301200 0.182900 0.552000 -0.328000 0.752000 +-0.389000 -0.351500 0.182900 0.544000 -0.632000 0.536000 +-0.350000 -0.301200 0.167500 0.592000 -0.368000 0.712000 +-0.350000 -0.351500 0.138600 0.680000 -0.440000 0.568000 +-0.327200 -0.301200 0.121900 0.792000 -0.368000 0.472000 +-0.341600 -0.351500 0.121900 0.808000 -0.352000 0.456000 +-0.350000 -0.351500 0.138600 0.680000 -0.440000 0.568000 +-0.350000 -0.369000 0.121900 0.736000 -0.464000 0.480000 +-0.389000 -0.351500 0.182900 0.544000 -0.632000 0.536000 +-0.400000 -0.397400 0.121900 0.632000 -0.672000 0.368000 +-0.400000 -0.359600 0.182900 0.520000 -0.680000 0.496000 +-0.404400 -0.401700 0.121900 0.648000 -0.656000 0.368000 +-0.445800 -0.401700 0.182900 0.648000 -0.488000 0.568000 +-0.447800 -0.451900 0.121900 0.672000 -0.648000 0.344000 +-0.450000 -0.407300 0.182900 0.664000 -0.488000 0.552000 +-0.450000 -0.451900 0.126400 0.752000 -0.472000 0.448000 +-0.500000 -0.444100 0.182900 0.168000 -0.480000 0.848000 +-0.500000 -0.451900 0.177400 0.160000 -0.648000 0.736000 +-0.523100 -0.451900 0.182900 0.136000 -0.648000 0.744000 +-0.500000 -0.444100 0.182900 0.168000 -0.480000 0.848000 +-0.550000 -0.451900 0.188900 -0.024000 -0.624000 0.776000 +-0.500000 -0.401700 0.210500 0.208000 -0.296000 0.928000 +-0.550000 -0.401700 0.218500 0.000000 -0.272000 0.960000 +-0.500000 -0.351500 0.209200 0.072000 0.104000 0.984000 +-0.550000 -0.351500 0.211500 0.000000 0.128000 0.984000 +-0.550000 -0.401700 0.218500 0.000000 -0.272000 0.960000 +-0.600000 -0.351500 0.201700 -0.216000 0.016000 0.968000 +-0.600000 -0.401700 0.205900 -0.320000 -0.144000 0.928000 +-0.600000 -0.401700 0.205900 -0.320000 -0.144000 0.928000 +-0.512000 -0.251000 0.182900 -0.112000 0.632000 0.760000 +-0.512000 -0.251000 0.182900 -0.112000 0.632000 0.760000 +-0.500000 -0.249000 0.182900 -0.112000 0.656000 0.744000 +-0.500000 -0.251000 0.185100 -0.112000 0.632000 0.760000 +-0.450000 -0.233700 0.182900 -0.216000 0.472000 0.848000 +-0.450000 -0.251000 0.195400 -0.152000 0.392000 0.904000 +-0.400000 -0.206800 0.182900 -0.168000 0.424000 0.880000 +-0.400000 -0.251000 0.203200 0.024000 0.208000 0.976000 +-0.383500 -0.200800 0.182900 -0.152000 0.448000 0.872000 +-0.350000 -0.251000 0.206900 0.584000 -0.272000 0.760000 +-0.350000 -0.200800 0.190300 -0.112000 0.384000 0.912000 +-0.334800 -0.251000 0.182900 0.672000 -0.480000 0.552000 +-0.300000 -0.200800 0.189700 0.744000 -0.432000 0.496000 +-0.300000 -0.205800 0.182900 0.768000 -0.472000 0.416000 +-0.296900 -0.200800 0.182900 0.792000 -0.440000 0.408000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.278100 -0.200800 0.121900 0.816000 -0.432000 0.368000 +-0.294600 -0.251000 0.121900 0.616000 -0.600000 0.488000 +-0.250000 -0.200800 0.078600 0.664000 -0.312000 0.672000 +-0.250000 -0.251000 0.071500 0.528000 -0.408000 0.736000 +-0.222100 -0.200800 0.060900 0.488000 -0.184000 0.848000 +-0.236900 -0.251000 0.060900 0.464000 -0.480000 0.728000 +-0.200000 -0.200800 0.045500 0.568000 -0.152000 0.808000 +-0.200000 -0.251000 0.018200 0.408000 -0.392000 0.816000 +-0.200000 -0.251000 0.018200 0.408000 -0.392000 0.816000 +-0.450000 -0.351500 0.215900 0.592000 -0.216000 0.768000 +-0.450000 -0.351500 0.215900 0.592000 -0.216000 0.768000 +-0.500000 -0.351500 0.209200 0.072000 0.104000 0.984000 +-0.450000 -0.401700 0.188700 0.656000 -0.464000 0.584000 +-0.500000 -0.401700 0.210500 0.208000 -0.296000 0.928000 +-0.450000 -0.407300 0.182900 0.664000 -0.488000 0.552000 +-0.500000 -0.444100 0.182900 0.168000 -0.480000 0.848000 +-0.500000 -0.444100 0.182900 0.168000 -0.480000 0.848000 +-0.400000 -0.351500 0.196700 0.560000 -0.576000 0.584000 +-0.400000 -0.351500 0.196700 0.560000 -0.576000 0.584000 +-0.400000 -0.359600 0.182900 0.520000 -0.680000 0.496000 +-0.450000 -0.351500 0.215900 0.592000 -0.216000 0.768000 +-0.445800 -0.401700 0.182900 0.648000 -0.488000 0.568000 +-0.450000 -0.401700 0.188700 0.656000 -0.464000 0.584000 +-0.450000 -0.407300 0.182900 0.664000 -0.488000 0.552000 +-0.450000 -0.407300 0.182900 0.664000 -0.488000 0.552000 +-0.383500 -0.200800 0.182900 -0.152000 0.448000 0.872000 +-0.383500 -0.200800 0.182900 -0.152000 0.448000 0.872000 +-0.350000 -0.189600 0.182900 -0.288000 0.472000 0.824000 +-0.350000 -0.200800 0.190300 -0.112000 0.384000 0.912000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.300000 -0.200800 0.189700 0.744000 -0.432000 0.496000 +-0.300000 -0.150600 0.190700 0.000000 0.520000 0.848000 +-0.296900 -0.200800 0.182900 0.792000 -0.440000 0.408000 +-0.288800 -0.150600 0.182900 0.600000 0.360000 0.712000 +-0.278100 -0.200800 0.121900 0.816000 -0.432000 0.368000 +-0.252800 -0.150600 0.121900 0.720000 -0.296000 0.616000 +-0.250000 -0.200800 0.078600 0.664000 -0.312000 0.672000 +-0.250000 -0.150600 0.117900 0.712000 -0.320000 0.616000 +-0.222100 -0.200800 0.060900 0.488000 -0.184000 0.848000 +-0.212600 -0.150600 0.060900 0.712000 -0.216000 0.664000 +-0.200000 -0.200800 0.045500 0.568000 -0.152000 0.808000 +-0.200000 -0.150600 0.042600 0.640000 -0.096000 0.752000 +-0.212600 -0.150600 0.060900 0.712000 -0.216000 0.664000 +-0.200000 -0.121800 0.060900 0.728000 -0.328000 0.592000 +-0.250000 -0.150600 0.117900 0.712000 -0.320000 0.616000 +-0.200000 -0.100400 0.076800 0.784000 -0.136000 0.600000 +-0.250000 -0.144000 0.121900 0.720000 -0.312000 0.608000 +-0.230200 -0.100400 0.121900 0.776000 -0.176000 0.600000 +-0.250000 -0.100400 0.155000 0.480000 0.160000 0.856000 +-0.247100 -0.050200 0.121900 0.488000 0.512000 0.696000 +-0.250000 -0.050200 0.123600 0.200000 0.440000 0.864000 +-0.250000 -0.048000 0.121900 0.272000 0.640000 0.704000 +-0.255700 -0.050200 0.121900 -0.192000 0.512000 0.832000 +-0.250000 0.000000 0.079500 -0.144000 0.552000 0.816000 +-0.300000 -0.050200 0.104800 -0.312000 0.512000 0.792000 +-0.300000 0.000000 0.088800 -0.240000 0.432000 0.864000 +-0.350000 -0.050200 0.083200 -0.416000 0.344000 0.832000 +-0.348200 0.000000 0.060900 -0.376000 0.448000 0.800000 +-0.350000 -0.001900 0.060900 -0.656000 0.280000 0.688000 +-0.350000 0.000000 0.059800 -0.688000 0.400000 0.592000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.373100 0.000000 0.000000 -0.880000 0.240000 0.392000 +-0.399300 -0.050200 0.000000 -0.696000 0.680000 0.184000 +-0.377800 0.000000 -0.060900 -0.864000 0.424000 -0.248000 +-0.400000 -0.050200 -0.003200 -0.712000 0.672000 0.168000 +-0.400000 -0.037800 -0.060900 -0.728000 0.664000 0.152000 +-0.406900 -0.050200 -0.060900 -0.848000 0.520000 0.000000 +-0.400000 -0.050200 -0.118700 -0.832000 0.528000 -0.160000 +-0.450000 -0.099400 -0.060900 -0.760000 0.616000 0.160000 +-0.400000 -0.050900 -0.121900 -0.736000 0.536000 -0.408000 +-0.450000 -0.100400 -0.065100 -0.512000 0.824000 -0.200000 +-0.434900 -0.100400 -0.121900 -0.608000 0.744000 -0.256000 +-0.450000 -0.111500 -0.121900 -0.376000 0.896000 -0.224000 +-0.403600 -0.100400 -0.182900 -0.616000 0.592000 -0.512000 +-0.450000 -0.128500 -0.182900 -0.504000 0.800000 -0.296000 +-0.400000 -0.100400 -0.188300 -0.616000 0.576000 -0.520000 +-0.450000 -0.150600 -0.239400 -0.408000 0.792000 -0.448000 +-0.400000 -0.131400 -0.243900 -0.384000 0.744000 -0.536000 +-0.444500 -0.150600 -0.243900 -0.312000 0.784000 -0.528000 +-0.400000 -0.150600 -0.272200 -0.312000 0.624000 -0.704000 +-0.450000 -0.152500 -0.243900 -0.384000 0.800000 -0.448000 +-0.400000 -0.174400 -0.304800 -0.224000 0.736000 -0.632000 +-0.450000 -0.186700 -0.304800 -0.216000 0.808000 -0.528000 +-0.400000 -0.200800 -0.333600 -0.064000 0.568000 -0.816000 +-0.450000 -0.200800 -0.327900 -0.112000 0.704000 -0.696000 +-0.400000 -0.239300 -0.365800 0.048000 0.512000 -0.848000 +-0.450000 -0.235000 -0.365800 -0.016000 0.592000 -0.800000 +-0.400000 -0.251000 -0.373300 0.080000 0.400000 -0.904000 +-0.450000 -0.251000 -0.376500 0.032000 0.432000 -0.896000 +-0.400000 -0.301200 -0.390900 0.144000 0.296000 -0.936000 +-0.450000 -0.301200 -0.399100 0.080000 0.320000 -0.936000 +-0.400000 -0.351500 -0.411400 0.000000 0.616000 -0.784000 +-0.450000 -0.351500 -0.418600 0.080000 0.512000 -0.848000 +-0.450000 -0.301200 -0.399100 0.080000 0.320000 -0.936000 +-0.500000 -0.351500 -0.423900 0.056000 0.504000 -0.856000 +-0.500000 -0.301200 -0.402500 0.040000 0.344000 -0.936000 +-0.450000 -0.301200 -0.399100 0.080000 0.320000 -0.936000 +-0.500000 -0.251000 -0.377000 -0.032000 0.528000 -0.840000 +-0.450000 -0.251000 -0.376500 0.032000 0.432000 -0.896000 +-0.500000 -0.238600 -0.365800 -0.072000 0.656000 -0.744000 +-0.450000 -0.235000 -0.365800 -0.016000 0.592000 -0.800000 +-0.500000 -0.200800 -0.313000 -0.112000 0.824000 -0.544000 +-0.450000 -0.200800 -0.327900 -0.112000 0.704000 -0.696000 +-0.500000 -0.196700 -0.304800 -0.120000 0.848000 -0.504000 +-0.450000 -0.186700 -0.304800 -0.216000 0.808000 -0.528000 +-0.500000 -0.169200 -0.243900 -0.328000 0.880000 -0.312000 +-0.450000 -0.152500 -0.243900 -0.384000 0.800000 -0.448000 +-0.500000 -0.154300 -0.182900 -0.320000 0.920000 -0.176000 +-0.450000 -0.150600 -0.239400 -0.408000 0.792000 -0.448000 +-0.491700 -0.150600 -0.182900 -0.448000 0.848000 -0.264000 +-0.450000 -0.128500 -0.182900 -0.504000 0.800000 -0.296000 +-0.500000 -0.150600 -0.154000 -0.424000 0.880000 -0.160000 +-0.450000 -0.111500 -0.121900 -0.376000 0.896000 -0.224000 +-0.500000 -0.144400 -0.121900 -0.376000 0.880000 -0.280000 +-0.450000 -0.100400 -0.065100 -0.512000 0.824000 -0.200000 +-0.500000 -0.119500 -0.060900 -0.160000 0.976000 0.112000 +-0.452400 -0.100400 -0.060900 -0.344000 0.936000 -0.016000 +-0.500000 -0.141000 0.000000 -0.040000 0.880000 0.456000 +-0.450000 -0.100400 -0.057100 -0.400000 0.872000 0.264000 +-0.450000 -0.112700 0.000000 -0.520000 0.784000 0.320000 +-0.434300 -0.100400 0.000000 -0.648000 0.720000 0.208000 +-0.450000 -0.136300 0.060900 -0.512000 0.720000 0.448000 +-0.405500 -0.100400 0.060900 -0.712000 0.456000 0.520000 +-0.450000 -0.150600 0.089400 -0.440000 0.744000 0.496000 +-0.400000 -0.100400 0.069600 -0.688000 0.456000 0.552000 +-0.414900 -0.150600 0.121900 -0.424000 0.616000 0.648000 +-0.400000 -0.140400 0.121900 -0.448000 0.624000 0.632000 +-0.400000 -0.150600 0.133500 -0.392000 0.600000 0.688000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.350000 -0.150600 0.151300 -0.584000 0.352000 0.720000 +-0.350000 -0.100400 0.123500 -0.608000 0.328000 0.712000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.300000 -0.100400 0.149000 -0.304000 0.432000 0.840000 +-0.300000 -0.142200 0.182900 0.000000 0.616000 0.776000 +-0.250000 -0.100400 0.155000 0.480000 0.160000 0.856000 +-0.288800 -0.150600 0.182900 0.600000 0.360000 0.712000 +-0.250000 -0.144000 0.121900 0.720000 -0.312000 0.608000 +-0.252800 -0.150600 0.121900 0.720000 -0.296000 0.616000 +-0.250000 -0.150600 0.117900 0.712000 -0.320000 0.616000 +-0.250000 -0.150600 0.117900 0.712000 -0.320000 0.616000 +-0.400000 -0.351500 0.196700 0.560000 -0.576000 0.584000 +-0.400000 -0.351500 0.196700 0.560000 -0.576000 0.584000 +-0.389000 -0.351500 0.182900 0.544000 -0.632000 0.536000 +-0.400000 -0.359600 0.182900 0.520000 -0.680000 0.496000 +-0.400000 -0.359600 0.182900 0.520000 -0.680000 0.496000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.300000 -0.142200 0.182900 0.000000 0.616000 0.776000 +-0.300000 -0.150600 0.190700 0.000000 0.520000 0.848000 +-0.288800 -0.150600 0.182900 0.600000 0.360000 0.712000 +-0.288800 -0.150600 0.182900 0.600000 0.360000 0.712000 +0.577700 0.301200 0.182900 -0.536000 0.272000 0.792000 +0.577700 0.301200 0.182900 -0.536000 0.272000 0.792000 +0.600000 0.327100 0.182900 -0.144000 0.552000 0.816000 +0.600000 0.301200 0.199900 -0.528000 0.136000 0.832000 +0.650000 0.311500 0.182900 0.424000 0.496000 0.752000 +0.650000 0.301200 0.190400 0.408000 0.464000 0.776000 +0.660200 0.301200 0.182900 0.480000 0.488000 0.720000 +0.650000 0.251000 0.217300 -0.016000 0.232000 0.968000 +0.700000 0.263400 0.182900 0.512000 0.536000 0.664000 +0.700000 0.251000 0.193900 0.488000 0.504000 0.704000 +0.711700 0.251000 0.182900 0.560000 0.528000 0.624000 +0.700000 0.200800 0.226400 0.328000 0.432000 0.832000 +0.750000 0.208300 0.182900 0.448000 0.624000 0.632000 +0.750000 0.200800 0.191100 0.424000 0.552000 0.712000 +0.761100 0.200800 0.182900 0.432000 0.472000 0.760000 +0.750000 0.150600 0.201100 0.320000 0.240000 0.912000 +0.797300 0.150600 0.182900 0.336000 0.288000 0.888000 +0.750000 0.100400 0.207000 0.032000 -0.192000 0.976000 +0.800000 0.148000 0.182900 0.424000 0.336000 0.832000 +0.800000 0.100400 0.199400 -0.032000 0.024000 0.992000 +0.850000 0.129700 0.182900 0.408000 0.752000 0.504000 +0.850000 0.100400 0.222500 0.440000 0.584000 0.672000 +0.891700 0.100400 0.182900 0.576000 0.688000 0.424000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.900000 0.093100 0.182900 0.568000 0.672000 0.464000 +0.900000 0.050200 0.226800 0.488000 0.496000 0.712000 +0.940200 0.050200 0.182900 0.624000 0.528000 0.568000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +0.950000 0.037400 0.182900 0.520000 0.504000 0.680000 +0.950000 0.000000 0.206500 0.400000 0.008000 0.912000 +1.000000 0.004900 0.182900 0.336000 0.520000 0.776000 +1.000000 0.000000 0.186800 0.376000 0.128000 0.912000 +0.950000 0.000000 0.206500 0.400000 0.008000 0.912000 +1.000000 -0.012000 0.182900 0.384000 -0.248000 0.880000 +0.950000 -0.050200 0.197900 0.336000 -0.192000 0.920000 +0.975800 -0.050200 0.182900 0.464000 -0.232000 0.848000 +0.950000 -0.100400 0.196500 0.208000 -0.704000 0.672000 +0.959000 -0.100400 0.182900 0.616000 -0.584000 0.520000 +0.950000 -0.108800 0.182900 0.232000 -0.768000 0.584000 +1.000000 -0.100400 0.134700 0.432000 -0.528000 0.720000 +0.950000 -0.142500 0.121900 -0.608000 -0.672000 0.392000 +1.000000 -0.126300 0.121900 0.016000 -0.480000 0.872000 +0.950000 -0.150600 0.094900 -0.648000 -0.696000 0.272000 +1.000000 -0.150600 0.101600 -0.080000 -0.576000 0.808000 +0.950000 -0.158100 0.060900 -0.608000 -0.760000 0.200000 +1.000000 -0.176100 0.060900 -0.688000 -0.632000 0.336000 +0.950000 -0.168100 0.000000 -0.640000 -0.744000 0.184000 +1.000000 -0.200800 0.012500 -0.656000 -0.696000 0.264000 +0.995800 -0.200800 0.000000 -0.648000 -0.704000 0.264000 +1.000000 -0.204500 0.000000 -0.624000 -0.728000 0.256000 +0.973000 -0.200800 -0.060900 -0.584000 -0.760000 0.264000 +1.000000 -0.224100 -0.060900 -0.616000 -0.728000 0.280000 +0.950500 -0.200800 -0.121900 -0.632000 -0.744000 0.192000 +1.000000 -0.243600 -0.121900 -0.640000 -0.736000 0.184000 +0.950000 -0.200800 -0.124000 -0.680000 -0.712000 0.160000 +1.000000 -0.251000 -0.154300 -0.728000 -0.648000 0.200000 +0.950000 -0.211700 -0.182900 -0.704000 -0.680000 0.176000 +0.993400 -0.251000 -0.182900 -0.736000 -0.640000 0.200000 +0.950000 -0.224400 -0.243900 -0.688000 -0.640000 0.328000 +0.978600 -0.251000 -0.243900 -0.696000 -0.616000 0.352000 +0.950000 -0.251000 -0.295200 -0.640000 -0.496000 0.576000 +1.000000 -0.277900 -0.243900 -0.712000 -0.592000 0.360000 +0.950000 -0.261400 -0.304800 -0.752000 -0.584000 0.288000 +1.000000 -0.301200 -0.291200 -0.640000 -0.488000 0.576000 +0.989600 -0.301200 -0.304800 -0.816000 -0.560000 0.128000 +1.000000 -0.316200 -0.304800 -0.800000 -0.552000 0.224000 +1.000000 -0.301200 -0.328200 -0.784000 -0.440000 -0.424000 +0.989600 -0.301200 -0.304800 -0.816000 -0.560000 0.128000 +1.000000 -0.251000 -0.355700 -0.816000 -0.248000 -0.504000 +0.950000 -0.261400 -0.304800 -0.752000 -0.584000 0.288000 +0.950000 -0.251000 -0.328200 -0.712000 -0.568000 -0.392000 +0.942100 -0.251000 -0.304800 -0.752000 -0.552000 0.344000 +0.950000 -0.200800 -0.357000 -0.272000 -0.104000 -0.952000 +0.911900 -0.200800 -0.304800 -0.864000 -0.480000 -0.128000 +0.950000 -0.150600 -0.345500 -0.032000 0.064000 -0.992000 +0.900000 -0.181100 -0.304800 -0.768000 -0.440000 -0.448000 +0.900000 -0.150600 -0.332000 -0.672000 -0.328000 -0.656000 +0.883200 -0.150600 -0.304800 -0.864000 -0.368000 -0.320000 +0.900000 -0.100400 -0.341700 -0.464000 -0.104000 -0.872000 +0.869700 -0.100400 -0.304800 -0.880000 -0.248000 -0.400000 +0.900000 -0.050200 -0.348300 -0.256000 0.192000 -0.944000 +0.867300 -0.050200 -0.304800 -0.784000 -0.136000 -0.600000 +0.900000 0.000000 -0.329500 -0.080000 0.648000 -0.744000 +0.877300 0.000000 -0.304800 -0.592000 0.480000 -0.632000 +0.900000 0.016700 -0.304800 -0.152000 0.720000 -0.664000 +0.850000 0.000000 -0.279000 -0.536000 0.488000 -0.680000 +0.900000 0.050200 -0.268900 0.208000 0.672000 -0.696000 +0.850000 0.042400 -0.243900 -0.408000 0.528000 -0.736000 +0.858900 0.050200 -0.243900 -0.424000 0.568000 -0.696000 +0.850000 0.050200 -0.237100 -0.376000 0.576000 -0.720000 +0.900000 0.070800 -0.243900 -0.096000 0.744000 -0.656000 +0.850000 0.100400 -0.218500 0.128000 0.592000 -0.784000 +0.900000 0.100400 -0.203200 0.536000 0.688000 -0.472000 +0.850000 0.127100 -0.182900 0.192000 0.744000 -0.632000 +0.900000 0.111100 -0.182900 0.552000 0.712000 -0.416000 +0.850000 0.150600 -0.140900 0.432000 0.840000 -0.304000 +0.900000 0.127900 -0.121900 0.560000 0.776000 -0.264000 +0.859300 0.150600 -0.121900 0.456000 0.840000 -0.272000 +0.900000 0.143500 -0.060900 0.528000 0.808000 -0.240000 +0.888500 0.150600 -0.060900 0.504000 0.856000 -0.040000 +0.900000 0.131100 0.000000 0.480000 0.848000 0.192000 +0.867700 0.150600 0.000000 0.552000 0.816000 0.152000 +0.900000 0.118900 0.060900 0.472000 0.856000 0.184000 +0.855400 0.150600 0.060900 0.680000 0.720000 0.072000 +0.900000 0.107300 0.121900 0.512000 0.832000 0.184000 +0.850900 0.150600 0.121900 0.704000 0.704000 0.080000 +0.900000 0.100400 0.165200 0.584000 0.744000 0.296000 +0.850000 0.150600 0.126500 0.640000 0.560000 0.512000 +0.891700 0.100400 0.182900 0.576000 0.688000 0.424000 +0.850000 0.129700 0.182900 0.408000 0.752000 0.504000 +0.850000 0.150600 0.126500 0.640000 0.560000 0.512000 +0.800000 0.148000 0.182900 0.424000 0.336000 0.832000 +0.800000 0.150600 0.181400 0.520000 0.336000 0.776000 +0.797300 0.150600 0.182900 0.336000 0.288000 0.888000 +0.800000 0.190400 0.121900 0.624000 0.752000 0.168000 +0.761100 0.200800 0.182900 0.432000 0.472000 0.760000 +0.788900 0.200800 0.121900 0.632000 0.744000 0.184000 +0.750000 0.208300 0.182900 0.448000 0.624000 0.632000 +0.750000 0.233400 0.121900 0.720000 0.680000 -0.080000 +0.711700 0.251000 0.182900 0.560000 0.528000 0.624000 +0.736800 0.251000 0.121900 0.752000 0.632000 0.144000 +0.700000 0.263400 0.182900 0.512000 0.536000 0.664000 +0.700000 0.297800 0.121900 0.728000 0.680000 -0.032000 +0.660200 0.301200 0.182900 0.480000 0.488000 0.720000 +0.696500 0.301200 0.121900 0.712000 0.672000 0.168000 +0.650000 0.311500 0.182900 0.424000 0.496000 0.752000 +0.653800 0.351500 0.121900 0.656000 0.616000 0.424000 +0.650000 0.351500 0.128300 0.616000 0.616000 0.480000 +0.650000 0.355500 0.121900 0.632000 0.632000 0.432000 +0.600000 0.351500 0.157200 -0.376000 0.584000 0.704000 +0.600000 0.382600 0.121900 0.272000 0.776000 0.560000 +0.566500 0.351500 0.121900 -0.632000 0.576000 0.496000 +0.600000 0.401700 0.085900 0.096000 0.928000 0.336000 +0.550000 0.351500 0.078000 -0.616000 0.672000 0.392000 +0.584600 0.401700 0.060900 -0.416000 0.872000 0.248000 +0.550000 0.359900 0.060900 -0.592000 0.640000 0.480000 +0.568400 0.401700 0.000000 -0.472000 0.832000 -0.264000 +0.550000 0.388900 0.000000 -0.392000 0.856000 0.320000 +0.600000 0.401700 -0.057700 0.168000 0.920000 -0.344000 +0.550000 0.398000 -0.060900 0.000000 0.968000 -0.216000 +0.600000 0.400600 -0.060900 -0.072000 0.912000 -0.384000 +0.550000 0.362300 -0.121900 0.400000 0.656000 -0.632000 +0.600000 0.351500 -0.101600 0.448000 0.496000 -0.736000 +0.566700 0.351500 -0.121900 0.448000 0.536000 -0.704000 +0.600000 0.310600 -0.121900 0.480000 0.424000 -0.760000 +0.550000 0.351500 -0.135900 0.456000 0.632000 -0.616000 +0.600000 0.301200 -0.128700 0.472000 0.520000 -0.704000 +0.550000 0.301200 -0.167400 0.408000 0.504000 -0.752000 +0.600000 0.256700 -0.182900 0.328000 0.496000 -0.792000 +0.550000 0.283200 -0.182900 0.320000 0.472000 -0.816000 +0.600000 0.251000 -0.187000 0.320000 0.456000 -0.816000 +0.550000 0.251000 -0.199600 0.176000 0.288000 -0.936000 +0.600000 0.200800 -0.209200 0.248000 0.288000 -0.920000 +0.550000 0.200800 -0.211100 0.016000 0.048000 -0.992000 +0.600000 0.150600 -0.225200 0.008000 0.128000 -0.984000 +0.550000 0.150600 -0.215400 -0.144000 0.080000 -0.984000 +0.600000 0.100400 -0.237100 -0.096000 0.168000 -0.976000 +0.550000 0.100400 -0.212600 -0.200000 0.352000 -0.904000 +0.600000 0.076600 -0.243900 -0.096000 0.360000 -0.920000 +0.550000 0.067800 -0.243900 0.024000 0.672000 -0.728000 +0.600000 0.050200 -0.251100 0.248000 0.344000 -0.896000 +0.550000 0.050200 -0.258400 0.160000 0.632000 -0.752000 +0.600000 0.000000 -0.284600 0.512000 0.112000 -0.840000 +0.550000 0.015600 -0.304800 0.472000 0.712000 -0.512000 +0.578400 0.000000 -0.304800 0.536000 0.480000 -0.688000 +0.550000 0.000000 -0.335900 0.576000 0.464000 -0.664000 +0.587300 -0.050200 -0.304800 0.688000 0.056000 -0.712000 +0.550000 -0.050200 -0.345500 0.192000 -0.560000 -0.792000 +0.550000 -0.083700 -0.304800 0.088000 -0.736000 -0.664000 +0.500000 -0.050200 -0.339600 -0.136000 -0.672000 -0.720000 +0.500000 -0.082600 -0.304800 0.216000 -0.680000 -0.688000 +0.450000 -0.050200 -0.325200 -0.120000 -0.568000 -0.808000 +0.475800 -0.100400 -0.304800 0.512000 -0.104000 -0.848000 +0.450000 -0.100400 -0.322200 0.392000 -0.360000 -0.840000 +0.500000 -0.127100 -0.304800 0.480000 0.456000 -0.744000 +0.450000 -0.150600 -0.321300 -0.008000 0.120000 -0.992000 +0.500000 -0.150600 -0.319100 0.336000 0.504000 -0.792000 +0.450000 -0.200800 -0.331300 -0.472000 -0.400000 -0.776000 +0.500000 -0.200800 -0.334200 -0.376000 -0.448000 -0.800000 +0.450000 -0.217600 -0.304800 -0.352000 -0.736000 -0.560000 +0.500000 -0.222600 -0.304800 -0.320000 -0.704000 -0.624000 +0.450000 -0.248400 -0.243900 -0.224000 -0.888000 -0.384000 +0.500000 -0.251000 -0.264200 -0.272000 -0.744000 -0.600000 +0.459300 -0.251000 -0.243900 -0.280000 -0.864000 -0.400000 +0.500000 -0.282700 -0.243900 -0.568000 -0.592000 -0.560000 +0.450000 -0.251000 -0.203800 -0.216000 -0.960000 -0.144000 +0.500000 -0.288400 -0.182900 -0.520000 -0.656000 0.528000 +0.450000 -0.255300 -0.182900 -0.208000 -0.656000 0.712000 +0.500000 -0.251000 -0.123800 -0.544000 -0.688000 0.456000 +0.450000 -0.251000 -0.179900 -0.288000 -0.680000 0.664000 +0.500000 -0.250100 -0.121900 -0.432000 -0.712000 0.536000 +0.450000 -0.227100 -0.121900 -0.296000 -0.712000 0.624000 +0.500000 -0.203100 -0.060900 -0.256000 -0.616000 0.736000 +0.450000 -0.200800 -0.072200 -0.256000 -0.536000 0.800000 +0.491400 -0.200800 -0.060900 -0.168000 -0.584000 0.784000 +0.450000 -0.150600 -0.064700 -0.192000 0.128000 0.968000 +0.463100 -0.150600 -0.060900 -0.168000 0.352000 0.912000 +0.450000 -0.100400 -0.078400 -0.088000 0.200000 0.968000 +0.500000 -0.139000 -0.060900 0.080000 0.536000 0.832000 +0.500000 -0.100400 -0.086800 -0.048000 0.256000 0.960000 +0.530700 -0.150600 -0.060900 0.208000 0.504000 0.832000 +0.550000 -0.100400 -0.076900 0.056000 0.056000 0.992000 +0.550000 -0.150600 -0.067100 0.240000 0.480000 0.840000 +0.600000 -0.100400 -0.077400 0.584000 0.048000 0.800000 +0.600000 -0.150600 -0.093600 0.304000 0.568000 0.752000 +0.626600 -0.100400 -0.121900 0.848000 0.208000 0.472000 +0.650000 -0.150600 -0.116200 0.720000 0.480000 0.488000 +0.650000 -0.146100 -0.121900 0.720000 0.504000 0.464000 +0.652900 -0.150600 -0.121900 0.752000 0.456000 0.464000 +0.650000 -0.117900 -0.182900 0.792000 0.600000 0.024000 +0.675300 -0.150600 -0.182900 0.768000 0.552000 0.296000 +0.650000 -0.120200 -0.243900 0.704000 0.520000 -0.472000 +0.674200 -0.150600 -0.243900 0.696000 0.600000 -0.384000 +0.650000 -0.150600 -0.274900 0.544000 0.464000 -0.688000 +0.700000 -0.175300 -0.243900 0.752000 0.600000 -0.240000 +0.650000 -0.200800 -0.297000 0.088000 0.616000 -0.776000 +0.700000 -0.200800 -0.294000 0.576000 0.608000 -0.536000 +0.650000 -0.208600 -0.304800 0.024000 0.680000 -0.728000 +0.700000 -0.211400 -0.304800 0.288000 0.624000 -0.720000 +0.650000 -0.245700 -0.365800 0.168000 0.856000 -0.480000 +0.700000 -0.251000 -0.357800 0.296000 0.496000 -0.808000 +0.678000 -0.251000 -0.365800 0.264000 0.520000 -0.808000 +0.700000 -0.301200 -0.354900 0.160000 -0.240000 -0.952000 +0.650000 -0.267900 -0.365800 0.280000 -0.440000 -0.848000 +0.650000 -0.301200 -0.350300 0.016000 -0.440000 -0.888000 +0.600000 -0.288400 -0.365800 -0.376000 -0.712000 -0.584000 +0.600000 -0.301200 -0.352300 -0.528000 -0.312000 -0.776000 +0.573000 -0.251000 -0.365800 -0.696000 0.544000 -0.464000 +0.567500 -0.301200 -0.304800 -0.696000 0.400000 -0.584000 +0.550000 -0.251000 -0.326800 -0.648000 -0.504000 -0.560000 +0.550000 -0.272400 -0.304800 -0.680000 -0.440000 -0.576000 +0.535300 -0.251000 -0.304800 -0.648000 -0.480000 -0.576000 +0.550000 -0.301200 -0.279200 -0.712000 0.120000 -0.680000 +0.500000 -0.251000 -0.264200 -0.272000 -0.744000 -0.600000 +0.513800 -0.301200 -0.243900 -0.728000 0.592000 -0.328000 +0.500000 -0.282700 -0.243900 -0.568000 -0.592000 -0.560000 +0.511800 -0.301200 -0.182900 -0.912000 0.352000 0.176000 +0.500000 -0.288400 -0.182900 -0.520000 -0.656000 0.528000 +0.550000 -0.301200 -0.123600 -0.624000 -0.440000 0.632000 +0.500000 -0.251000 -0.123800 -0.544000 -0.688000 0.456000 +0.550000 -0.300100 -0.121900 -0.624000 -0.616000 0.472000 +0.501100 -0.251000 -0.121900 -0.552000 -0.624000 0.544000 +0.550000 -0.251000 -0.069700 -0.416000 -0.584000 0.688000 +0.500000 -0.250100 -0.121900 -0.432000 -0.712000 0.536000 +0.550000 -0.242100 -0.060900 -0.400000 -0.536000 0.736000 +0.500000 -0.203100 -0.060900 -0.256000 -0.616000 0.736000 +0.550000 -0.200800 -0.034900 0.016000 -0.040000 0.992000 +0.500000 -0.200800 -0.058700 -0.200000 -0.576000 0.784000 +0.550000 -0.159500 -0.060900 0.248000 0.472000 0.840000 +0.500000 -0.150600 -0.051600 0.024000 0.352000 0.928000 +0.530700 -0.150600 -0.060900 0.208000 0.504000 0.832000 +0.500000 -0.139000 -0.060900 0.080000 0.536000 0.832000 +0.500000 -0.150600 -0.051600 0.024000 0.352000 0.928000 +0.463100 -0.150600 -0.060900 -0.168000 0.352000 0.912000 +0.500000 -0.200800 -0.058700 -0.200000 -0.576000 0.784000 +0.491400 -0.200800 -0.060900 -0.168000 -0.584000 0.784000 +0.500000 -0.203100 -0.060900 -0.256000 -0.616000 0.736000 +0.500000 -0.203100 -0.060900 -0.256000 -0.616000 0.736000 +0.600000 0.251000 0.198700 -0.584000 -0.144000 0.792000 +0.600000 0.251000 0.198700 -0.584000 -0.144000 0.792000 +0.600000 0.301200 0.199900 -0.528000 0.136000 0.832000 +0.586200 0.251000 0.182900 -0.672000 -0.144000 0.720000 +0.577700 0.301200 0.182900 -0.536000 0.272000 0.792000 +0.550000 0.251000 0.125100 -0.872000 -0.184000 0.440000 +0.550000 0.301200 0.149100 -0.896000 -0.096000 0.416000 +0.548800 0.251000 0.121900 -0.912000 -0.176000 0.360000 +0.538800 0.301200 0.121900 -0.912000 0.128000 0.376000 +0.533200 0.251000 0.060900 -0.856000 0.032000 0.512000 +0.526500 0.301200 0.060900 -0.896000 0.008000 0.432000 +0.500800 0.251000 0.000000 -0.792000 -0.016000 0.608000 +0.500000 0.301200 0.002700 -0.768000 -0.080000 0.624000 +0.500000 0.266900 0.000000 -0.760000 -0.040000 0.640000 +0.497900 0.301200 0.000000 -0.728000 -0.144000 0.664000 +0.500000 0.251000 -0.000900 -0.496000 0.112000 0.856000 +0.450000 0.301200 -0.039700 -0.448000 -0.256000 0.848000 +0.450000 0.251000 -0.039600 -0.400000 -0.080000 0.904000 +0.400000 0.301200 -0.051900 -0.168000 -0.472000 0.856000 +0.400000 0.251000 -0.058700 -0.328000 -0.176000 0.920000 +0.353900 0.301200 -0.060900 -0.128000 -0.544000 0.824000 +0.395100 0.251000 -0.060900 -0.344000 -0.184000 0.912000 +0.350000 0.301200 -0.062100 -0.176000 -0.704000 0.680000 +0.350000 0.251000 -0.088400 -0.448000 -0.320000 0.824000 +0.300000 0.301200 -0.077400 -0.160000 -0.712000 0.680000 +0.300000 0.251000 -0.114600 -0.168000 -0.536000 0.824000 +0.250000 0.301200 -0.083600 -0.096000 -0.744000 0.648000 +0.271900 0.251000 -0.121900 -0.240000 -0.760000 0.592000 +0.250000 0.256500 -0.121900 -0.200000 -0.800000 0.552000 +0.300000 0.251000 -0.156100 -0.368000 -0.808000 -0.448000 +0.250000 0.284000 -0.182900 -0.096000 -0.256000 -0.952000 +0.300000 0.284000 -0.182900 -0.168000 -0.184000 -0.960000 +0.250000 0.301200 -0.184400 -0.080000 -0.056000 -0.992000 +0.300000 0.301200 -0.184400 -0.064000 -0.072000 -0.992000 +0.250000 0.351500 -0.189100 -0.160000 0.168000 -0.968000 +0.300000 0.351500 -0.193900 -0.008000 0.064000 -0.992000 +0.250000 0.370000 -0.182900 -0.184000 0.304000 -0.928000 +0.300000 0.379400 -0.182900 -0.016000 0.272000 -0.960000 +0.250000 0.401700 -0.172700 -0.016000 0.288000 -0.952000 +0.300000 0.401700 -0.174800 0.040000 0.368000 -0.920000 +0.250000 0.451900 -0.137900 0.128000 0.536000 -0.824000 +0.300000 0.451900 -0.131100 0.200000 0.712000 -0.664000 +0.250000 0.466900 -0.121900 0.232000 0.968000 0.016000 +0.300000 0.458100 -0.121900 0.224000 0.952000 -0.176000 +0.250000 0.451900 -0.094000 0.248000 0.784000 0.552000 +0.300000 0.451900 -0.106900 0.184000 0.864000 0.456000 +0.250000 0.432000 -0.060900 0.224000 0.624000 0.736000 +0.300000 0.430700 -0.060900 0.128000 0.808000 0.568000 +0.250000 0.401700 -0.026800 -0.216000 0.176000 0.952000 +0.300000 0.401700 -0.022200 0.096000 0.472000 0.864000 +0.250000 0.351500 -0.020200 -0.488000 -0.416000 0.760000 +0.300000 0.351500 -0.009100 -0.016000 -0.144000 0.984000 +0.250000 0.317900 -0.060900 -0.432000 -0.680000 0.584000 +0.300000 0.310700 -0.060900 -0.072000 -0.760000 0.640000 +0.250000 0.301200 -0.083600 -0.096000 -0.744000 0.648000 +0.300000 0.301200 -0.077400 -0.160000 -0.712000 0.680000 +0.300000 0.310700 -0.060900 -0.072000 -0.760000 0.640000 +0.350000 0.301200 -0.062100 -0.176000 -0.704000 0.680000 +0.350000 0.302200 -0.060900 -0.144000 -0.624000 0.760000 +0.353900 0.301200 -0.060900 -0.128000 -0.544000 0.824000 +0.350000 0.351500 -0.021800 0.032000 -0.048000 0.992000 +0.400000 0.301200 -0.051900 -0.168000 -0.472000 0.856000 +0.400000 0.351500 -0.018700 -0.136000 -0.208000 0.960000 +0.450000 0.301200 -0.039700 -0.448000 -0.256000 0.848000 +0.450000 0.351500 -0.003200 -0.296000 0.344000 0.888000 +0.497900 0.301200 0.000000 -0.728000 -0.144000 0.664000 +0.458200 0.351500 0.000000 -0.280000 0.520000 0.800000 +0.500000 0.301200 0.002700 -0.768000 -0.080000 0.624000 +0.500000 0.351500 0.029100 -0.680000 0.048000 0.728000 +0.526500 0.301200 0.060900 -0.896000 0.008000 0.432000 +0.540600 0.351500 0.060900 -0.584000 0.632000 0.496000 +0.538800 0.301200 0.121900 -0.912000 0.128000 0.376000 +0.550000 0.351500 0.078000 -0.616000 0.672000 0.392000 +0.550000 0.331800 0.121900 -0.696000 0.536000 0.456000 +0.566500 0.351500 0.121900 -0.632000 0.576000 0.496000 +0.550000 0.301200 0.149100 -0.896000 -0.096000 0.416000 +0.600000 0.351500 0.157200 -0.376000 0.584000 0.704000 +0.577700 0.301200 0.182900 -0.536000 0.272000 0.792000 +0.600000 0.327100 0.182900 -0.144000 0.552000 0.816000 +0.600000 0.351500 0.157200 -0.376000 0.584000 0.704000 +0.650000 0.311500 0.182900 0.424000 0.496000 0.752000 +0.650000 0.351500 0.128300 0.616000 0.616000 0.480000 +0.650000 0.351500 0.128300 0.616000 0.616000 0.480000 +0.586200 0.251000 0.182900 -0.672000 -0.144000 0.720000 +0.586200 0.251000 0.182900 -0.672000 -0.144000 0.720000 +0.600000 0.251000 0.198700 -0.584000 -0.144000 0.792000 +0.600000 0.211800 0.182900 -0.672000 -0.280000 0.672000 +0.650000 0.251000 0.217300 -0.016000 0.232000 0.968000 +0.604600 0.200800 0.182900 -0.672000 -0.288000 0.664000 +0.650000 0.200800 0.219700 -0.496000 -0.256000 0.824000 +0.641000 0.150600 0.182900 -0.528000 -0.464000 0.696000 +0.650000 0.150600 0.191100 -0.504000 -0.472000 0.720000 +0.650000 0.141000 0.182900 -0.512000 -0.488000 0.704000 +0.700000 0.150600 0.220800 -0.264000 -0.416000 0.864000 +0.685300 0.100400 0.182900 -0.504000 -0.560000 0.648000 +0.700000 0.100400 0.197200 -0.456000 -0.560000 0.680000 +0.700000 0.088000 0.182900 -0.464000 -0.608000 0.640000 +0.750000 0.100400 0.207000 0.032000 -0.192000 0.976000 +0.750000 0.062100 0.182900 -0.416000 -0.632000 0.648000 +0.800000 0.100400 0.199400 -0.032000 0.024000 0.992000 +0.762700 0.050200 0.182900 -0.512000 -0.672000 0.520000 +0.800000 0.050200 0.211000 -0.336000 -0.552000 0.752000 +0.800000 0.035400 0.182900 -0.432000 -0.808000 0.384000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.846600 0.000000 0.182900 -0.736000 -0.616000 0.264000 +0.850000 0.000000 0.194300 -0.704000 -0.640000 0.296000 +0.850000 -0.004200 0.182900 -0.720000 -0.616000 0.288000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +0.880500 -0.050200 0.182900 -0.744000 -0.528000 0.384000 +0.900000 -0.050200 0.230400 -0.448000 -0.568000 0.680000 +0.900000 -0.076800 0.182900 -0.504000 -0.624000 0.592000 +0.950000 -0.050200 0.197900 0.336000 -0.192000 0.920000 +0.934300 -0.100400 0.182900 -0.392000 -0.752000 0.520000 +0.950000 -0.100400 0.196500 0.208000 -0.704000 0.672000 +0.950000 -0.108800 0.182900 0.232000 -0.768000 0.584000 +0.934300 -0.100400 0.182900 -0.392000 -0.752000 0.520000 +0.950000 -0.142500 0.121900 -0.608000 -0.672000 0.392000 +0.900000 -0.100400 0.145900 -0.608000 -0.728000 0.304000 +0.900000 -0.107100 0.121900 -0.584000 -0.768000 0.240000 +0.892500 -0.100400 0.121900 -0.688000 -0.680000 0.240000 +0.900000 -0.117100 0.060900 -0.656000 -0.736000 0.136000 +0.881900 -0.100400 0.060900 -0.752000 -0.632000 0.152000 +0.900000 -0.125700 0.000000 -0.664000 -0.728000 0.136000 +0.873300 -0.100400 0.000000 -0.752000 -0.632000 0.120000 +0.900000 -0.135500 -0.060900 -0.672000 -0.712000 0.168000 +0.865600 -0.100400 -0.060900 -0.776000 -0.616000 0.120000 +0.900000 -0.148200 -0.121900 -0.664000 -0.728000 0.088000 +0.858300 -0.100400 -0.121900 -0.792000 -0.600000 0.056000 +0.900000 -0.150600 -0.145400 -0.696000 -0.704000 0.104000 +0.858100 -0.100400 -0.182900 -0.824000 -0.552000 0.000000 +0.895100 -0.150600 -0.182900 -0.744000 -0.648000 0.104000 +0.860900 -0.100400 -0.243900 -0.856000 -0.496000 -0.072000 +0.890800 -0.150600 -0.243900 -0.848000 -0.512000 0.064000 +0.869700 -0.100400 -0.304800 -0.880000 -0.248000 -0.400000 +0.883200 -0.150600 -0.304800 -0.864000 -0.368000 -0.320000 +0.890800 -0.150600 -0.243900 -0.848000 -0.512000 0.064000 +0.900000 -0.181100 -0.304800 -0.768000 -0.440000 -0.448000 +0.900000 -0.163000 -0.243900 -0.816000 -0.552000 0.128000 +0.911900 -0.200800 -0.304800 -0.864000 -0.480000 -0.128000 +0.928800 -0.200800 -0.243900 -0.736000 -0.616000 0.240000 +0.942100 -0.251000 -0.304800 -0.752000 -0.552000 0.344000 +0.950000 -0.224400 -0.243900 -0.688000 -0.640000 0.328000 +0.950000 -0.251000 -0.295200 -0.640000 -0.496000 0.576000 +0.942100 -0.251000 -0.304800 -0.752000 -0.552000 0.344000 +0.950000 -0.261400 -0.304800 -0.752000 -0.584000 0.288000 +0.950000 -0.261400 -0.304800 -0.752000 -0.584000 0.288000 +0.650000 0.251000 0.217300 -0.016000 0.232000 0.968000 +0.650000 0.251000 0.217300 -0.016000 0.232000 0.968000 +0.600000 0.251000 0.198700 -0.584000 -0.144000 0.792000 +0.650000 0.301200 0.190400 0.408000 0.464000 0.776000 +0.600000 0.301200 0.199900 -0.528000 0.136000 0.832000 +0.600000 0.301200 0.199900 -0.528000 0.136000 0.832000 +0.700000 0.251000 0.193900 0.488000 0.504000 0.704000 +0.700000 0.251000 0.193900 0.488000 0.504000 0.704000 +0.650000 0.251000 0.217300 -0.016000 0.232000 0.968000 +0.700000 0.200800 0.226400 0.328000 0.432000 0.832000 +0.650000 0.200800 0.219700 -0.496000 -0.256000 0.824000 +0.700000 0.150600 0.220800 -0.264000 -0.416000 0.864000 +0.650000 0.150600 0.191100 -0.504000 -0.472000 0.720000 +0.650000 0.150600 0.191100 -0.504000 -0.472000 0.720000 +0.750000 0.200800 0.191100 0.424000 0.552000 0.712000 +0.750000 0.200800 0.191100 0.424000 0.552000 0.712000 +0.700000 0.200800 0.226400 0.328000 0.432000 0.832000 +0.750000 0.150600 0.201100 0.320000 0.240000 0.912000 +0.700000 0.150600 0.220800 -0.264000 -0.416000 0.864000 +0.750000 0.100400 0.207000 0.032000 -0.192000 0.976000 +0.700000 0.100400 0.197200 -0.456000 -0.560000 0.680000 +0.700000 0.100400 0.197200 -0.456000 -0.560000 0.680000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.800000 0.050200 0.211000 -0.336000 -0.552000 0.752000 +0.850000 0.100400 0.222500 0.440000 0.584000 0.672000 +0.800000 0.100400 0.199400 -0.032000 0.024000 0.992000 +0.800000 0.100400 0.199400 -0.032000 0.024000 0.992000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +0.850000 0.000000 0.194300 -0.704000 -0.640000 0.296000 +0.900000 0.050200 0.226800 0.488000 0.496000 0.712000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.850000 0.050200 0.216300 -0.184000 -0.272000 0.936000 +0.950000 -0.050200 0.197900 0.336000 -0.192000 0.920000 +0.950000 -0.050200 0.197900 0.336000 -0.192000 0.920000 +0.900000 -0.050200 0.230400 -0.448000 -0.568000 0.680000 +0.950000 0.000000 0.206500 0.400000 0.008000 0.912000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +0.900000 0.000000 0.237100 -0.176000 -0.616000 0.760000 +-0.950000 0.150600 0.154300 0.208000 0.640000 0.736000 +-0.950000 0.150600 0.154300 0.208000 0.640000 0.736000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.950000 0.178500 0.121900 0.272000 0.648000 0.704000 +-0.900000 0.154600 0.121900 0.352000 0.624000 0.688000 +-0.950000 0.200800 0.096100 0.208000 0.672000 0.704000 +-0.900000 0.200800 0.074800 0.296000 0.712000 0.624000 +-0.950000 0.226300 0.060900 0.264000 0.760000 0.584000 +-0.900000 0.210300 0.060900 0.312000 0.744000 0.576000 +-0.950000 0.251000 0.016800 0.288000 0.808000 0.504000 +-0.900000 0.240500 0.000000 0.368000 0.840000 0.376000 +-0.928700 0.251000 0.000000 0.312000 0.848000 0.408000 +-0.900000 0.251000 -0.035000 0.384000 0.864000 0.312000 +-0.950000 0.258900 0.000000 0.296000 0.848000 0.432000 +-0.900000 0.258900 -0.060900 0.400000 0.896000 0.144000 +-0.950000 0.277400 -0.060900 0.336000 0.928000 0.080000 +-0.900000 0.251000 -0.101700 0.376000 0.896000 -0.216000 +-0.950000 0.267200 -0.121900 0.344000 0.864000 -0.336000 +-0.910500 0.251000 -0.121900 0.344000 0.880000 -0.304000 +-0.950000 0.251000 -0.157200 0.320000 0.808000 -0.480000 +-0.900000 0.246900 -0.121900 0.360000 0.872000 -0.304000 +-0.950000 0.237800 -0.182900 0.296000 0.760000 -0.568000 +-0.900000 0.214200 -0.182900 0.360000 0.720000 -0.576000 +-0.950000 0.200800 -0.231900 0.272000 0.640000 -0.704000 +-0.900000 0.200800 -0.201400 0.352000 0.680000 -0.640000 +-0.950000 0.189400 -0.243900 0.264000 0.616000 -0.728000 +-0.900000 0.162400 -0.243900 0.336000 0.616000 -0.704000 +-0.950000 0.150600 -0.281200 0.240000 0.600000 -0.752000 +-0.900000 0.150600 -0.256300 0.328000 0.616000 -0.704000 +-0.950000 0.126000 -0.304800 0.168000 0.528000 -0.824000 +-0.900000 0.104600 -0.304800 0.304000 0.568000 -0.760000 +-0.950000 0.100400 -0.325900 0.192000 0.384000 -0.896000 +-0.900000 0.100400 -0.308600 0.312000 0.536000 -0.776000 +-0.950000 0.050200 -0.340200 0.184000 0.072000 -0.976000 +-0.900000 0.050200 -0.331200 0.320000 0.232000 -0.912000 +-0.950000 0.000000 -0.337100 0.184000 -0.088000 -0.976000 +-0.900000 0.000000 -0.328400 0.216000 0.000000 -0.968000 +-0.950000 -0.050200 -0.337400 0.088000 0.008000 -0.992000 +-0.900000 -0.050200 -0.330000 0.160000 0.128000 -0.976000 +-0.900000 0.000000 -0.328400 0.216000 0.000000 -0.968000 +-0.850000 -0.050200 -0.323400 0.248000 0.176000 -0.944000 +-0.850000 0.000000 -0.313800 0.264000 0.064000 -0.960000 +-0.808200 -0.050200 -0.304800 0.280000 0.136000 -0.944000 +-0.823600 0.000000 -0.304800 0.296000 0.080000 -0.944000 +-0.800000 -0.050200 -0.302200 0.264000 0.120000 -0.952000 +-0.800000 0.000000 -0.298500 0.248000 0.080000 -0.960000 +-0.750000 -0.050200 -0.287100 0.288000 0.040000 -0.952000 +-0.750000 0.000000 -0.285200 0.328000 0.160000 -0.920000 +-0.700000 -0.050200 -0.272000 0.360000 0.104000 -0.920000 +-0.700000 0.000000 -0.262900 0.392000 0.288000 -0.864000 +-0.650000 -0.050200 -0.249300 0.496000 0.208000 -0.840000 +-0.669700 0.000000 -0.243900 0.480000 0.312000 -0.808000 +-0.650000 -0.035200 -0.243900 0.544000 0.264000 -0.792000 +-0.650000 0.000000 -0.224600 0.632000 0.368000 -0.672000 +-0.642900 -0.050200 -0.243900 0.560000 0.208000 -0.792000 +-0.621400 0.000000 -0.182900 0.848000 0.280000 -0.440000 +-0.606100 -0.050200 -0.182900 0.864000 0.248000 -0.424000 +-0.606100 -0.050200 -0.182900 0.864000 0.248000 -0.424000 +-0.950000 0.127100 0.182900 0.248000 0.536000 0.800000 +-0.950000 0.127100 0.182900 0.248000 0.536000 0.800000 +-0.950000 0.150600 0.154300 0.208000 0.640000 0.736000 +-0.900000 0.101900 0.182900 0.304000 0.552000 0.768000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.939400 -0.100400 0.121900 -0.456000 -0.816000 0.336000 +-0.939400 -0.100400 0.121900 -0.456000 -0.816000 0.336000 +-0.900000 -0.100400 0.174900 -0.400000 -0.624000 0.656000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.900000 0.150600 0.126400 0.344000 0.632000 0.688000 +-0.900000 0.154600 0.121900 0.352000 0.624000 0.688000 +-0.892900 0.150600 0.121900 0.360000 0.624000 0.680000 +-0.900000 0.200800 0.074800 0.296000 0.712000 0.624000 +-0.850000 0.150600 0.098600 0.360000 0.600000 0.704000 +-0.879600 0.200800 0.060900 0.352000 0.712000 0.600000 +-0.850000 0.184100 0.060900 0.376000 0.632000 0.664000 +-0.850000 0.200800 0.035600 0.384000 0.744000 0.536000 +-0.800000 0.153700 0.060900 0.432000 0.632000 0.632000 +-0.811000 0.200800 0.000000 0.408000 0.816000 0.392000 +-0.800000 0.195100 0.000000 0.456000 0.768000 0.432000 +-0.800000 0.200800 -0.016800 0.416000 0.840000 0.336000 +-0.750000 0.162200 0.000000 0.464000 0.672000 0.560000 +-0.768900 0.200800 -0.060900 0.424000 0.888000 0.160000 +-0.750000 0.191300 -0.060900 0.496000 0.856000 0.072000 +-0.800000 0.200800 -0.113900 0.392000 0.880000 -0.256000 +-0.750000 0.174400 -0.121900 0.448000 0.824000 -0.336000 +-0.800000 0.198900 -0.121900 0.384000 0.872000 -0.288000 +-0.750000 0.150600 -0.159200 0.432000 0.664000 -0.600000 +-0.800000 0.163000 -0.182900 0.392000 0.688000 -0.600000 +-0.779100 0.150600 -0.182900 0.400000 0.664000 -0.616000 +-0.800000 0.150600 -0.199200 0.384000 0.648000 -0.648000 +-0.750000 0.132600 -0.182900 0.408000 0.656000 -0.624000 +-0.800000 0.108800 -0.243900 0.352000 0.608000 -0.704000 +-0.750000 0.100400 -0.222000 0.432000 0.576000 -0.680000 +-0.785800 0.100400 -0.243900 0.360000 0.584000 -0.720000 +-0.750000 0.077000 -0.243900 0.368000 0.552000 -0.744000 +-0.800000 0.100400 -0.252800 0.360000 0.584000 -0.720000 +-0.750000 0.050200 -0.267100 0.368000 0.432000 -0.816000 +-0.800000 0.050200 -0.288900 0.352000 0.360000 -0.856000 +-0.750000 0.000000 -0.285200 0.328000 0.160000 -0.920000 +-0.800000 0.000000 -0.298500 0.248000 0.080000 -0.960000 +-0.800000 0.050200 -0.288900 0.352000 0.360000 -0.856000 +-0.823600 0.000000 -0.304800 0.296000 0.080000 -0.944000 +-0.836500 0.050200 -0.304800 0.336000 0.344000 -0.872000 +-0.850000 0.000000 -0.313800 0.264000 0.064000 -0.960000 +-0.850000 0.050200 -0.311100 0.336000 0.328000 -0.872000 +-0.900000 0.000000 -0.328400 0.216000 0.000000 -0.968000 +-0.900000 0.050200 -0.331200 0.320000 0.232000 -0.912000 +-0.850000 0.050200 -0.311100 0.336000 0.328000 -0.872000 +-0.900000 0.100400 -0.308600 0.312000 0.536000 -0.776000 +-0.850000 0.061400 -0.304800 0.336000 0.392000 -0.848000 +-0.892300 0.100400 -0.304800 0.320000 0.536000 -0.776000 +-0.850000 0.100400 -0.281200 0.344000 0.488000 -0.792000 +-0.900000 0.104600 -0.304800 0.304000 0.568000 -0.760000 +-0.850000 0.135500 -0.243900 0.320000 0.608000 -0.712000 +-0.900000 0.150600 -0.256300 0.328000 0.616000 -0.704000 +-0.878700 0.150600 -0.243900 0.328000 0.616000 -0.704000 +-0.900000 0.162400 -0.243900 0.336000 0.616000 -0.704000 +-0.850000 0.150600 -0.229000 0.320000 0.608000 -0.720000 +-0.900000 0.200800 -0.201400 0.352000 0.680000 -0.640000 +-0.850000 0.188600 -0.182900 0.360000 0.712000 -0.592000 +-0.874200 0.200800 -0.182900 0.360000 0.712000 -0.584000 +-0.850000 0.200800 -0.163600 0.360000 0.768000 -0.512000 +-0.900000 0.214200 -0.182900 0.360000 0.720000 -0.576000 +-0.850000 0.222300 -0.121900 0.408000 0.856000 -0.296000 +-0.900000 0.246900 -0.121900 0.360000 0.872000 -0.304000 +-0.850000 0.235300 -0.060900 0.408000 0.904000 0.008000 +-0.900000 0.251000 -0.101700 0.376000 0.896000 -0.216000 +-0.884300 0.251000 -0.060900 0.432000 0.880000 0.144000 +-0.900000 0.258900 -0.060900 0.400000 0.896000 0.144000 +-0.900000 0.251000 -0.035000 0.384000 0.864000 0.312000 +-0.884300 0.251000 -0.060900 0.432000 0.880000 0.144000 +-0.900000 0.240500 0.000000 0.368000 0.840000 0.376000 +-0.850000 0.235300 -0.060900 0.408000 0.904000 0.008000 +-0.850000 0.219100 0.000000 0.368000 0.824000 0.424000 +-0.800000 0.214400 -0.060900 0.400000 0.896000 0.176000 +-0.811000 0.200800 0.000000 0.408000 0.816000 0.392000 +-0.800000 0.200800 -0.016800 0.416000 0.840000 0.336000 +-0.800000 0.214400 -0.060900 0.400000 0.896000 0.176000 +-0.768900 0.200800 -0.060900 0.424000 0.888000 0.160000 +-0.800000 0.200800 -0.113900 0.392000 0.880000 -0.256000 +-0.800000 0.214400 -0.060900 0.400000 0.896000 0.176000 +-0.804300 0.200800 -0.121900 0.384000 0.872000 -0.288000 +-0.850000 0.235300 -0.060900 0.408000 0.904000 0.008000 +-0.850000 0.222300 -0.121900 0.408000 0.856000 -0.296000 +-0.804300 0.200800 -0.121900 0.384000 0.872000 -0.288000 +-0.850000 0.200800 -0.163600 0.360000 0.768000 -0.512000 +-0.800000 0.198900 -0.121900 0.384000 0.872000 -0.288000 +-0.850000 0.188600 -0.182900 0.360000 0.712000 -0.592000 +-0.800000 0.163000 -0.182900 0.392000 0.688000 -0.600000 +-0.850000 0.150600 -0.229000 0.320000 0.608000 -0.720000 +-0.800000 0.150600 -0.199200 0.384000 0.648000 -0.648000 +-0.850000 0.135500 -0.243900 0.320000 0.608000 -0.712000 +-0.800000 0.108800 -0.243900 0.352000 0.608000 -0.704000 +-0.850000 0.100400 -0.281200 0.344000 0.488000 -0.792000 +-0.800000 0.100400 -0.252800 0.360000 0.584000 -0.720000 +-0.850000 0.061400 -0.304800 0.336000 0.392000 -0.848000 +-0.800000 0.050200 -0.288900 0.352000 0.360000 -0.856000 +-0.836500 0.050200 -0.304800 0.336000 0.344000 -0.872000 +-0.850000 0.061400 -0.304800 0.336000 0.392000 -0.848000 +-0.850000 0.050200 -0.311100 0.336000 0.328000 -0.872000 +-0.850000 0.050200 -0.311100 0.336000 0.328000 -0.872000 +-0.850000 0.127100 0.121900 0.424000 0.560000 0.704000 +-0.850000 0.127100 0.121900 0.424000 0.560000 0.704000 +-0.820700 0.100400 0.121900 0.496000 0.488000 0.704000 +-0.850000 0.100400 0.150400 0.488000 0.512000 0.696000 +-0.850000 0.100400 0.150400 0.488000 0.512000 0.696000 +-0.839600 0.000000 0.182900 0.264000 0.152000 0.944000 +-0.839600 0.000000 0.182900 0.264000 0.152000 0.944000 +-0.809300 -0.050200 0.182900 0.232000 0.160000 0.952000 +-0.800000 0.000000 0.163200 0.400000 0.288000 0.864000 +-0.800000 -0.050200 0.179900 0.264000 0.176000 0.944000 +-0.750000 0.000000 0.129400 0.496000 0.360000 0.776000 +-0.750000 -0.050200 0.155100 0.464000 0.288000 0.832000 +-0.740500 0.000000 0.121900 0.504000 0.352000 0.784000 +-0.708600 -0.050200 0.121900 0.496000 0.344000 0.784000 +-0.700000 0.000000 0.089700 0.584000 0.336000 0.736000 +-0.700000 -0.050200 0.115300 0.496000 0.344000 0.792000 +-0.666100 0.000000 0.060900 0.560000 0.376000 0.728000 +-0.650000 -0.050200 0.076400 0.576000 0.320000 0.744000 +-0.650000 -0.023500 0.060900 0.576000 0.360000 0.720000 +-0.635700 -0.050200 0.060900 0.640000 0.304000 0.696000 +-0.650000 0.000000 0.045200 0.576000 0.400000 0.704000 +-0.600000 -0.050200 0.018400 0.648000 0.320000 0.688000 +-0.609800 0.000000 0.000000 0.696000 0.384000 0.592000 +-0.600000 -0.018300 0.000000 0.712000 0.368000 0.584000 +-0.600000 0.000000 -0.017800 0.736000 0.384000 0.544000 +-0.584800 -0.050200 0.000000 0.744000 0.336000 0.568000 +-0.573200 0.000000 -0.060900 0.920000 0.296000 -0.248000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.800000 -0.063400 0.182900 0.240000 0.160000 0.952000 +-0.800000 -0.063400 0.182900 0.240000 0.160000 0.952000 +-0.809300 -0.050200 0.182900 0.232000 0.160000 0.952000 +-0.800000 -0.050200 0.179900 0.264000 0.176000 0.944000 +-0.800000 -0.050200 0.179900 0.264000 0.176000 0.944000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.850000 -0.137400 0.182900 -0.304000 -0.312000 0.896000 +-0.836800 -0.150600 0.182900 -0.304000 -0.304000 0.896000 +-0.850000 -0.150600 0.175600 -0.632000 -0.392000 0.664000 +-0.803100 -0.200800 0.182900 -0.456000 -0.168000 0.864000 +-0.850000 -0.200800 0.125700 -0.776000 -0.360000 0.504000 +-0.850000 -0.200800 0.125700 -0.776000 -0.360000 0.504000 +-0.800000 -0.251000 0.157900 -0.576000 -0.400000 0.696000 +-0.800000 -0.251000 0.157900 -0.576000 -0.400000 0.696000 +-0.800000 -0.280700 0.121900 -0.736000 -0.528000 0.408000 +-0.819200 -0.251000 0.121900 -0.760000 -0.496000 0.400000 +-0.800000 -0.301200 0.085900 -0.768000 -0.544000 0.304000 +-0.838400 -0.251000 0.060900 -0.808000 -0.528000 0.248000 +-0.805900 -0.301200 0.060900 -0.800000 -0.536000 0.232000 +-0.800000 -0.301200 0.085900 -0.768000 -0.544000 0.304000 +-0.800000 -0.310100 0.060900 -0.800000 -0.544000 0.224000 +-0.805900 -0.301200 0.060900 -0.800000 -0.536000 0.232000 +-0.800000 -0.327900 0.000000 -0.800000 -0.560000 0.176000 +-0.817700 -0.301200 0.000000 -0.808000 -0.560000 0.168000 +-0.817700 -0.301200 0.000000 -0.808000 -0.560000 0.168000 +-0.800000 0.077200 0.121900 0.512000 0.416000 0.744000 +-0.800000 0.077200 0.121900 0.512000 0.416000 0.744000 +-0.781300 0.050200 0.121900 0.536000 0.400000 0.736000 +-0.800000 0.050200 0.139800 0.504000 0.392000 0.760000 +-0.800000 0.050200 0.139800 0.504000 0.392000 0.760000 +-0.776900 -0.100400 0.182900 0.184000 0.120000 0.968000 +-0.776900 -0.100400 0.182900 0.184000 0.120000 0.968000 +-0.750000 -0.100400 0.174700 0.320000 0.192000 0.920000 +-0.750000 -0.136500 0.182900 0.216000 0.112000 0.968000 +-0.700000 -0.100400 0.138900 0.488000 0.288000 0.816000 +-0.743500 -0.150600 0.182900 0.192000 0.096000 0.968000 +-0.700000 -0.150600 0.164200 0.408000 0.248000 0.872000 +-0.703900 -0.200800 0.182900 0.128000 0.064000 0.984000 +-0.700000 -0.200800 0.182200 0.152000 0.072000 0.984000 +-0.700000 -0.208700 0.182900 0.176000 0.120000 0.968000 +-0.650000 -0.200800 0.153500 0.376000 0.280000 0.872000 +-0.650000 -0.249200 0.182900 0.176000 0.464000 0.864000 +-0.600000 -0.200800 0.130000 0.152000 0.560000 0.808000 +-0.638500 -0.251000 0.182900 0.072000 0.424000 0.896000 +-0.600000 -0.251000 0.177800 0.080000 0.520000 0.840000 +-0.600000 -0.260000 0.182900 0.056000 0.320000 0.944000 +-0.550000 -0.251000 0.173600 -0.016000 0.472000 0.872000 +-0.550000 -0.264400 0.182900 -0.072000 0.456000 0.880000 +-0.512000 -0.251000 0.182900 -0.112000 0.632000 0.760000 +-0.550000 -0.251000 0.173600 -0.016000 0.472000 0.872000 +-0.500000 -0.249000 0.182900 -0.112000 0.656000 0.744000 +-0.550000 -0.202900 0.121900 0.032000 0.728000 0.680000 +-0.500000 -0.200800 0.127000 -0.088000 0.600000 0.784000 +-0.536800 -0.200800 0.121900 -0.104000 0.736000 0.664000 +-0.500000 -0.196200 0.121900 -0.112000 0.784000 0.600000 +-0.550000 -0.200800 0.118700 0.032000 0.784000 0.608000 +-0.500000 -0.166600 0.060900 -0.304000 0.832000 0.448000 +-0.550000 -0.166800 0.060900 0.264000 0.816000 0.504000 +-0.500000 -0.150600 0.019400 -0.216000 0.856000 0.464000 +-0.550000 -0.150600 0.029600 0.504000 0.688000 0.512000 +-0.500000 -0.141000 0.000000 -0.040000 0.880000 0.456000 +-0.550000 -0.125000 0.000000 0.608000 0.616000 0.488000 +-0.500000 -0.119500 -0.060900 -0.160000 0.976000 0.112000 +-0.550000 -0.100400 -0.036900 0.792000 0.376000 0.464000 +-0.533200 -0.100400 -0.060900 0.712000 0.696000 -0.024000 +-0.533200 -0.100400 -0.060900 0.712000 0.696000 -0.024000 +-0.750000 -0.267900 0.182900 -0.232000 -0.192000 0.944000 +-0.750000 -0.267900 0.182900 -0.232000 -0.192000 0.944000 +-0.750000 -0.301200 0.168400 -0.360000 -0.432000 0.816000 +-0.700000 -0.272200 0.182900 -0.072000 -0.128000 0.984000 +-0.700000 -0.301200 0.175400 -0.248000 -0.280000 0.920000 +-0.671000 -0.301200 0.182900 -0.120000 -0.104000 0.984000 +-0.700000 -0.351500 0.155000 -0.664000 -0.344000 0.656000 +-0.663400 -0.351500 0.182900 -0.304000 -0.080000 0.944000 +-0.700000 -0.401700 0.124500 -0.664000 -0.408000 0.616000 +-0.650000 -0.385200 0.182900 -0.496000 -0.152000 0.848000 +-0.650000 -0.401700 0.178700 -0.552000 -0.344000 0.752000 +-0.644900 -0.401700 0.182900 -0.528000 -0.240000 0.808000 +-0.650000 -0.451900 0.140100 -0.528000 -0.568000 0.624000 +-0.600000 -0.446800 0.182900 -0.240000 -0.464000 0.848000 +-0.600000 -0.451900 0.179400 -0.216000 -0.496000 0.832000 +-0.583500 -0.451900 0.182900 -0.128000 -0.544000 0.824000 +-0.600000 -0.495400 0.121900 -0.392000 -0.720000 0.560000 +-0.550000 -0.456500 0.182900 0.056000 -0.736000 0.672000 +-0.550000 -0.494000 0.121900 0.024000 -0.832000 0.536000 +-0.600000 -0.495400 0.121900 -0.392000 -0.720000 0.560000 +-0.550000 -0.502100 0.104800 0.104000 -0.840000 0.520000 +-0.600000 -0.502100 0.110700 -0.280000 -0.792000 0.528000 +-0.550000 -0.532000 0.060900 0.080000 -0.776000 0.624000 +-0.600000 -0.531600 0.060900 -0.448000 -0.736000 0.496000 +-0.600000 -0.502100 0.110700 -0.280000 -0.792000 0.528000 +-0.640700 -0.502100 0.060900 -0.496000 -0.728000 0.456000 +-0.600000 -0.495400 0.121900 -0.392000 -0.720000 0.560000 +-0.650000 -0.495900 0.060900 -0.528000 -0.720000 0.432000 +-0.650000 -0.463300 0.121900 -0.512000 -0.696000 0.496000 +-0.700000 -0.453200 0.060900 -0.560000 -0.720000 0.392000 +-0.664200 -0.451900 0.121900 -0.552000 -0.696000 0.448000 +-0.700000 -0.451900 0.063700 -0.672000 -0.600000 0.424000 +-0.700000 -0.404000 0.121900 -0.624000 -0.536000 0.560000 +-0.701000 -0.451900 0.060900 -0.792000 -0.480000 0.344000 +-0.701700 -0.401700 0.121900 -0.704000 -0.408000 0.568000 +-0.731300 -0.401700 0.060900 -0.784000 -0.496000 0.344000 +-0.739400 -0.351500 0.121900 -0.528000 -0.576000 0.616000 +-0.750000 -0.377100 0.060900 -0.760000 -0.552000 0.320000 +-0.750000 -0.351500 0.110100 -0.600000 -0.584000 0.536000 +-0.767900 -0.351500 0.060900 -0.760000 -0.568000 0.296000 +-0.767900 -0.351500 0.060900 -0.760000 -0.568000 0.296000 +-0.750000 -0.301200 0.168400 -0.360000 -0.432000 0.816000 +-0.750000 -0.301200 0.168400 -0.360000 -0.432000 0.816000 +-0.700000 -0.301200 0.175400 -0.248000 -0.280000 0.920000 +-0.750000 -0.342500 0.121900 -0.536000 -0.592000 0.592000 +-0.700000 -0.351500 0.155000 -0.664000 -0.344000 0.656000 +-0.739400 -0.351500 0.121900 -0.528000 -0.576000 0.616000 +-0.700000 -0.401700 0.124500 -0.664000 -0.408000 0.616000 +-0.701700 -0.401700 0.121900 -0.704000 -0.408000 0.568000 +-0.700000 -0.404000 0.121900 -0.624000 -0.536000 0.560000 +-0.700000 -0.401700 0.124500 -0.664000 -0.408000 0.616000 +-0.664200 -0.451900 0.121900 -0.552000 -0.696000 0.448000 +-0.650000 -0.401700 0.178700 -0.552000 -0.344000 0.752000 +-0.650000 -0.451900 0.140100 -0.528000 -0.568000 0.624000 +-0.664200 -0.451900 0.121900 -0.552000 -0.696000 0.448000 +-0.650000 -0.463300 0.121900 -0.512000 -0.696000 0.496000 +-0.650000 -0.451900 0.140100 -0.528000 -0.568000 0.624000 +-0.600000 -0.495400 0.121900 -0.392000 -0.720000 0.560000 +-0.600000 -0.451900 0.179400 -0.216000 -0.496000 0.832000 +-0.600000 -0.451900 0.179400 -0.216000 -0.496000 0.832000 +-0.700000 -0.062200 0.121900 0.504000 0.344000 0.784000 +-0.700000 -0.062200 0.121900 0.504000 0.344000 0.784000 +-0.677900 -0.100400 0.121900 0.528000 0.328000 0.776000 +-0.700000 -0.100400 0.138900 0.488000 0.288000 0.816000 +-0.650000 -0.141800 0.121900 0.432000 0.328000 0.832000 +-0.700000 -0.150600 0.164200 0.408000 0.248000 0.872000 +-0.650000 -0.150600 0.126000 0.408000 0.336000 0.840000 +-0.700000 -0.200800 0.182200 0.152000 0.072000 0.984000 +-0.650000 -0.200800 0.153500 0.376000 0.280000 0.872000 +-0.650000 -0.150600 0.126000 0.408000 0.336000 0.840000 +-0.600000 -0.200800 0.130000 0.152000 0.560000 0.808000 +-0.642900 -0.150600 0.121900 0.408000 0.352000 0.832000 +-0.600000 -0.190600 0.121900 0.296000 0.496000 0.808000 +-0.600000 -0.150600 0.080700 0.576000 0.424000 0.688000 +-0.559300 -0.200800 0.121900 0.160000 0.720000 0.672000 +-0.575700 -0.150600 0.060900 0.384000 0.664000 0.632000 +-0.550000 -0.200800 0.118700 0.032000 0.784000 0.608000 +-0.550000 -0.166800 0.060900 0.264000 0.816000 0.504000 +-0.575700 -0.150600 0.060900 0.384000 0.664000 0.632000 +-0.550000 -0.150600 0.029600 0.504000 0.688000 0.512000 +-0.600000 -0.122400 0.060900 0.616000 0.400000 0.664000 +-0.550000 -0.125000 0.000000 0.608000 0.616000 0.488000 +-0.600000 -0.100400 0.044600 0.672000 0.336000 0.656000 +-0.565600 -0.100400 0.000000 0.744000 0.440000 0.496000 +-0.550000 -0.125000 0.000000 0.608000 0.616000 0.488000 +-0.550000 -0.100400 -0.036900 0.792000 0.376000 0.464000 +-0.550000 -0.100400 -0.036900 0.792000 0.376000 0.464000 +-0.650000 -0.150600 0.126000 0.408000 0.336000 0.840000 +-0.650000 -0.150600 0.126000 0.408000 0.336000 0.840000 +-0.650000 -0.141800 0.121900 0.432000 0.328000 0.832000 +-0.642900 -0.150600 0.121900 0.408000 0.352000 0.832000 +-0.650000 -0.100400 0.096100 0.592000 0.288000 0.744000 +-0.600000 -0.150600 0.080700 0.576000 0.424000 0.688000 +-0.612900 -0.100400 0.060900 0.624000 0.376000 0.672000 +-0.600000 -0.122400 0.060900 0.616000 0.400000 0.664000 +-0.600000 -0.100400 0.044600 0.672000 0.336000 0.656000 +-0.600000 -0.100400 0.044600 0.672000 0.336000 0.656000 +-0.600000 -0.190600 0.121900 0.296000 0.496000 0.808000 +-0.600000 -0.190600 0.121900 0.296000 0.496000 0.808000 +-0.559300 -0.200800 0.121900 0.160000 0.720000 0.672000 +-0.600000 -0.200800 0.130000 0.152000 0.560000 0.808000 +-0.550000 -0.202900 0.121900 0.032000 0.728000 0.680000 +-0.600000 -0.251000 0.177800 0.080000 0.520000 0.840000 +-0.550000 -0.251000 0.173600 -0.016000 0.472000 0.872000 +-0.550000 -0.251000 0.173600 -0.016000 0.472000 0.872000 +-0.500000 -0.200800 0.127000 -0.088000 0.600000 0.784000 +-0.500000 -0.200800 0.127000 -0.088000 0.600000 0.784000 +-0.450000 -0.200800 0.150000 -0.304000 0.608000 0.720000 +-0.500000 -0.196200 0.121900 -0.112000 0.784000 0.600000 +-0.450000 -0.173700 0.121900 -0.368000 0.648000 0.656000 +-0.500000 -0.166600 0.060900 -0.304000 0.832000 0.448000 +-0.450000 -0.150600 0.089400 -0.440000 0.744000 0.496000 +-0.472400 -0.150600 0.060900 -0.464000 0.768000 0.416000 +-0.450000 -0.136300 0.060900 -0.512000 0.720000 0.448000 +-0.500000 -0.150600 0.019400 -0.216000 0.856000 0.464000 +-0.450000 -0.112700 0.000000 -0.520000 0.784000 0.320000 +-0.500000 -0.141000 0.000000 -0.040000 0.880000 0.456000 +-0.500000 -0.141000 0.000000 -0.040000 0.880000 0.456000 +-0.500000 -0.200800 0.127000 -0.088000 0.600000 0.784000 +-0.500000 -0.200800 0.127000 -0.088000 0.600000 0.784000 +-0.500000 -0.249000 0.182900 -0.112000 0.656000 0.744000 +-0.450000 -0.200800 0.150000 -0.304000 0.608000 0.720000 +-0.450000 -0.233700 0.182900 -0.216000 0.472000 0.848000 +-0.400000 -0.200800 0.179200 -0.200000 0.464000 0.856000 +-0.400000 -0.206800 0.182900 -0.168000 0.424000 0.880000 +-0.383500 -0.200800 0.182900 -0.152000 0.448000 0.872000 +-0.400000 -0.200800 0.179200 -0.200000 0.464000 0.856000 +-0.350000 -0.189600 0.182900 -0.288000 0.472000 0.824000 +-0.400000 -0.150600 0.133500 -0.392000 0.600000 0.688000 +-0.350000 -0.150600 0.151300 -0.584000 0.352000 0.720000 +-0.350000 -0.189600 0.182900 -0.288000 0.472000 0.824000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.311100 -0.150600 0.182900 -0.424000 0.464000 0.768000 +-0.400000 -0.200800 0.179200 -0.200000 0.464000 0.856000 +-0.400000 -0.200800 0.179200 -0.200000 0.464000 0.856000 +-0.450000 -0.200800 0.150000 -0.304000 0.608000 0.720000 +-0.400000 -0.150600 0.133500 -0.392000 0.600000 0.688000 +-0.450000 -0.173700 0.121900 -0.368000 0.648000 0.656000 +-0.414900 -0.150600 0.121900 -0.424000 0.616000 0.648000 +-0.450000 -0.150600 0.089400 -0.440000 0.744000 0.496000 +-0.450000 -0.150600 0.089400 -0.440000 0.744000 0.496000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.350000 -0.097900 0.121900 -0.560000 0.424000 0.704000 +-0.350000 -0.100400 0.123500 -0.608000 0.328000 0.712000 +-0.300000 -0.066800 0.121900 -0.280000 0.584000 0.752000 +-0.300000 -0.100400 0.149000 -0.304000 0.432000 0.840000 +-0.255700 -0.050200 0.121900 -0.192000 0.512000 0.832000 +-0.250000 -0.100400 0.155000 0.480000 0.160000 0.856000 +-0.250000 -0.050200 0.123600 0.200000 0.440000 0.864000 +-0.250000 -0.050200 0.123600 0.200000 0.440000 0.864000 +-0.369700 -0.301200 0.182900 0.552000 -0.328000 0.752000 +-0.369700 -0.301200 0.182900 0.552000 -0.328000 0.752000 +-0.350000 -0.276800 0.182900 0.600000 -0.432000 0.664000 +-0.350000 -0.301200 0.167500 0.592000 -0.368000 0.712000 +-0.350000 -0.301200 0.167500 0.592000 -0.368000 0.712000 +-0.334800 -0.251000 0.182900 0.672000 -0.480000 0.552000 +-0.334800 -0.251000 0.182900 0.672000 -0.480000 0.552000 +-0.300000 -0.205800 0.182900 0.768000 -0.472000 0.416000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.300000 -0.251000 0.131000 0.632000 -0.616000 0.464000 +-0.294600 -0.251000 0.121900 0.616000 -0.600000 0.488000 +-0.300000 -0.256400 0.121900 0.624000 -0.624000 0.456000 +-0.300000 -0.256400 0.121900 0.624000 -0.624000 0.456000 +0.550000 0.331800 0.121900 -0.696000 0.536000 0.456000 +0.550000 0.331800 0.121900 -0.696000 0.536000 0.456000 +0.550000 0.301200 0.149100 -0.896000 -0.096000 0.416000 +0.538800 0.301200 0.121900 -0.912000 0.128000 0.376000 +0.538800 0.301200 0.121900 -0.912000 0.128000 0.376000 +0.548800 0.251000 0.121900 -0.912000 -0.176000 0.360000 +0.548800 0.251000 0.121900 -0.912000 -0.176000 0.360000 +0.550000 0.251000 0.125100 -0.872000 -0.184000 0.440000 +0.550000 0.246100 0.121900 -0.904000 -0.224000 0.352000 +0.586200 0.251000 0.182900 -0.672000 -0.144000 0.720000 +0.567500 0.200800 0.121900 -0.784000 -0.344000 0.504000 +0.600000 0.211800 0.182900 -0.672000 -0.280000 0.672000 +0.600000 0.200800 0.176700 -0.712000 -0.296000 0.624000 +0.604600 0.200800 0.182900 -0.672000 -0.288000 0.664000 +0.600000 0.150600 0.141200 -0.712000 -0.440000 0.536000 +0.641000 0.150600 0.182900 -0.528000 -0.464000 0.696000 +0.600000 0.134700 0.121900 -0.776000 -0.456000 0.424000 +0.650000 0.141000 0.182900 -0.512000 -0.488000 0.704000 +0.627900 0.100400 0.121900 -0.608000 -0.608000 0.504000 +0.650000 0.100400 0.150000 -0.536000 -0.592000 0.592000 +0.650000 0.080100 0.121900 -0.576000 -0.640000 0.496000 +0.685300 0.100400 0.182900 -0.504000 -0.560000 0.648000 +0.692100 0.050200 0.121900 -0.432000 -0.784000 0.424000 +0.700000 0.088000 0.182900 -0.464000 -0.608000 0.640000 +0.700000 0.050200 0.131500 -0.112000 -0.824000 0.544000 +0.750000 0.062100 0.182900 -0.416000 -0.632000 0.648000 +0.744700 0.050200 0.121900 0.096000 -0.864000 0.480000 +0.750000 0.050900 0.121900 0.096000 -0.792000 0.600000 +0.750000 0.050200 0.120200 -0.160000 -0.904000 0.376000 +0.751700 0.050200 0.121900 -0.392000 -0.816000 0.416000 +0.750000 0.031700 0.060900 -0.136000 -0.928000 0.336000 +0.800000 0.028400 0.121900 -0.376000 -0.808000 0.432000 +0.798100 0.000000 0.060900 -0.504000 -0.792000 0.312000 +0.800000 0.000000 0.064400 -0.576000 -0.736000 0.344000 +0.800000 -0.001000 0.060900 -0.584000 -0.776000 0.216000 +0.829700 0.000000 0.121900 -0.704000 -0.616000 0.344000 +0.843600 -0.050200 0.060900 -0.704000 -0.672000 0.184000 +0.850000 -0.029600 0.121900 -0.840000 -0.432000 0.312000 +0.850000 -0.050200 0.089500 -0.768000 -0.592000 0.216000 +0.857500 -0.050200 0.121900 -0.848000 -0.448000 0.272000 +0.850000 -0.056700 0.060900 -0.720000 -0.664000 0.176000 +0.892500 -0.100400 0.121900 -0.688000 -0.680000 0.240000 +0.881900 -0.100400 0.060900 -0.752000 -0.632000 0.152000 +0.850000 -0.056700 0.060900 -0.720000 -0.664000 0.176000 +0.873300 -0.100400 0.000000 -0.752000 -0.632000 0.120000 +0.850000 -0.068700 0.000000 -0.752000 -0.640000 0.136000 +0.865600 -0.100400 -0.060900 -0.776000 -0.616000 0.120000 +0.850000 -0.079400 -0.060900 -0.768000 -0.616000 0.120000 +0.858300 -0.100400 -0.121900 -0.792000 -0.600000 0.056000 +0.850000 -0.088400 -0.121900 -0.808000 -0.584000 0.016000 +0.858100 -0.100400 -0.182900 -0.824000 -0.552000 0.000000 +0.850000 -0.086900 -0.182900 -0.848000 -0.512000 -0.048000 +0.860900 -0.100400 -0.243900 -0.856000 -0.496000 -0.072000 +0.850000 -0.077200 -0.243900 -0.824000 -0.432000 -0.344000 +0.869700 -0.100400 -0.304800 -0.880000 -0.248000 -0.400000 +0.850000 -0.050200 -0.276700 -0.784000 -0.280000 -0.544000 +0.867300 -0.050200 -0.304800 -0.784000 -0.136000 -0.600000 +0.850000 0.000000 -0.279000 -0.536000 0.488000 -0.680000 +0.877300 0.000000 -0.304800 -0.592000 0.480000 -0.632000 +0.877300 0.000000 -0.304800 -0.592000 0.480000 -0.632000 +0.600000 0.150600 0.141200 -0.712000 -0.440000 0.536000 +0.600000 0.150600 0.141200 -0.712000 -0.440000 0.536000 +0.600000 0.200800 0.176700 -0.712000 -0.296000 0.624000 +0.591100 0.150600 0.121900 -0.792000 -0.400000 0.440000 +0.567500 0.200800 0.121900 -0.784000 -0.344000 0.504000 +0.560700 0.150600 0.060900 -0.704000 -0.368000 0.592000 +0.550000 0.200800 0.086900 -0.880000 -0.256000 0.392000 +0.550000 0.174700 0.060900 -0.744000 -0.320000 0.576000 +0.538800 0.200800 0.060900 -0.824000 -0.216000 0.520000 +0.550000 0.150600 0.048400 -0.632000 -0.416000 0.640000 +0.500000 0.200800 0.008600 -0.576000 -0.176000 0.792000 +0.510200 0.150600 0.000000 -0.752000 -0.384000 0.520000 +0.500000 0.181600 0.000000 -0.600000 -0.304000 0.728000 +0.500000 0.150600 -0.020200 -0.704000 -0.472000 0.520000 +0.488800 0.200800 0.000000 -0.512000 0.024000 0.856000 +0.460500 0.150600 -0.060900 -0.624000 -0.512000 0.584000 +0.450000 0.200800 -0.035500 -0.536000 -0.264000 0.792000 +0.450000 0.163500 -0.060900 -0.600000 -0.504000 0.608000 +0.416500 0.200800 -0.060900 -0.560000 -0.352000 0.744000 +0.450000 0.150600 -0.075000 -0.616000 -0.488000 0.608000 +0.400000 0.200800 -0.077800 -0.600000 -0.432000 0.664000 +0.401900 0.150600 -0.121900 -0.864000 -0.496000 -0.024000 +0.400000 0.152400 -0.121900 -0.688000 -0.712000 -0.048000 +0.407800 0.150600 -0.182900 -0.544000 -0.240000 -0.800000 +0.400000 0.155900 -0.182900 -0.216000 -0.144000 -0.960000 +0.450000 0.150600 -0.187200 -0.088000 0.168000 -0.976000 +0.400000 0.200800 -0.189400 -0.152000 -0.072000 -0.984000 +0.450000 0.200800 -0.192400 -0.128000 -0.040000 -0.984000 +0.400000 0.251000 -0.186400 -0.152000 0.040000 -0.984000 +0.450000 0.251000 -0.188200 -0.104000 0.040000 -0.992000 +0.400000 0.301200 -0.184200 -0.016000 -0.016000 -0.992000 +0.450000 0.301200 -0.186200 0.000000 -0.016000 -0.992000 +0.400000 0.351500 -0.194500 0.000000 0.072000 -0.992000 +0.450000 0.351500 -0.196000 0.120000 0.128000 -0.976000 +0.400000 0.377300 -0.182900 0.016000 0.320000 -0.944000 +0.450000 0.373800 -0.182900 0.104000 0.432000 -0.888000 +0.400000 0.401700 -0.171200 0.088000 0.472000 -0.872000 +0.450000 0.401700 -0.160800 0.376000 0.656000 -0.640000 +0.400000 0.432800 -0.121900 0.160000 0.904000 -0.384000 +0.450000 0.422200 -0.121900 0.368000 0.832000 -0.392000 +0.400000 0.419800 -0.060900 0.080000 0.848000 0.520000 +0.450000 0.414500 -0.060900 0.192000 0.928000 0.304000 +0.400000 0.401700 -0.034800 -0.040000 0.584000 0.808000 +0.450000 0.401700 -0.038900 -0.120000 0.592000 0.784000 +0.400000 0.351500 -0.018700 -0.136000 -0.208000 0.960000 +0.450000 0.351500 -0.003200 -0.296000 0.344000 0.888000 +0.450000 0.401700 -0.038900 -0.120000 0.592000 0.784000 +0.458200 0.351500 0.000000 -0.280000 0.520000 0.800000 +0.500000 0.401700 -0.057700 0.096000 0.864000 0.480000 +0.500000 0.369100 0.000000 -0.184000 0.800000 0.552000 +0.517100 0.401700 -0.060900 0.080000 0.968000 0.224000 +0.550000 0.388900 0.000000 -0.392000 0.856000 0.320000 +0.550000 0.398000 -0.060900 0.000000 0.968000 -0.216000 +0.517100 0.401700 -0.060900 0.080000 0.968000 0.224000 +0.550000 0.362300 -0.121900 0.400000 0.656000 -0.632000 +0.500000 0.401700 -0.069300 0.168000 0.952000 -0.216000 +0.500000 0.393600 -0.121900 0.504000 0.744000 -0.432000 +0.488600 0.401700 -0.121900 0.504000 0.776000 -0.368000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.450000 0.401700 -0.160800 0.376000 0.656000 -0.640000 +0.450000 0.373800 -0.182900 0.104000 0.432000 -0.888000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.450000 0.351500 -0.196000 0.120000 0.128000 -0.976000 +0.500000 0.351500 -0.187300 0.416000 0.568000 -0.696000 +0.450000 0.301200 -0.186200 0.000000 -0.016000 -0.992000 +0.500000 0.301200 -0.193500 0.168000 0.072000 -0.976000 +0.450000 0.251000 -0.188200 -0.104000 0.040000 -0.992000 +0.500000 0.251000 -0.199400 0.072000 0.096000 -0.984000 +0.450000 0.200800 -0.192400 -0.128000 -0.040000 -0.984000 +0.500000 0.200800 -0.200200 -0.104000 -0.048000 -0.992000 +0.450000 0.150600 -0.187200 -0.088000 0.168000 -0.976000 +0.500000 0.150600 -0.194400 -0.208000 0.240000 -0.944000 +0.450000 0.100400 -0.233000 -0.008000 0.816000 -0.568000 +0.500000 0.100400 -0.210700 0.048000 0.704000 -0.704000 +0.450000 0.095300 -0.243900 -0.008000 0.856000 -0.512000 +0.500000 0.082500 -0.243900 0.216000 0.832000 -0.504000 +0.450000 0.055500 -0.304800 0.064000 0.864000 -0.496000 +0.500000 0.050200 -0.303800 0.264000 0.816000 -0.504000 +0.496000 0.050200 -0.304800 0.104000 0.800000 -0.576000 +0.500000 0.049600 -0.304800 0.264000 0.736000 -0.616000 +0.450000 0.050200 -0.314200 0.064000 0.744000 -0.656000 +0.500000 0.014000 -0.365800 0.216000 0.784000 -0.568000 +0.450000 0.007700 -0.365800 -0.264000 0.744000 -0.600000 +0.500000 0.000000 -0.393700 0.528000 0.072000 -0.840000 +0.450000 0.000000 -0.377000 -0.360000 0.400000 -0.840000 +0.500000 -0.027200 -0.365800 0.264000 -0.576000 -0.768000 +0.450000 -0.014200 -0.365800 -0.336000 -0.568000 -0.744000 +0.500000 -0.050200 -0.339600 -0.136000 -0.672000 -0.720000 +0.450000 -0.050200 -0.325200 -0.120000 -0.568000 -0.808000 +0.450000 -0.014200 -0.365800 -0.336000 -0.568000 -0.744000 +0.400000 -0.050200 -0.360800 0.184000 -0.432000 -0.872000 +0.431500 0.000000 -0.365800 -0.424000 0.312000 -0.840000 +0.400000 0.000000 -0.343200 -0.216000 0.592000 -0.768000 +0.450000 0.007700 -0.365800 -0.264000 0.744000 -0.600000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.450000 0.050200 -0.314200 0.064000 0.744000 -0.656000 +0.419200 0.050200 -0.304800 -0.224000 0.736000 -0.632000 +0.450000 0.055500 -0.304800 0.064000 0.864000 -0.496000 +0.400000 0.050200 -0.294000 -0.352000 0.672000 -0.640000 +0.450000 0.095300 -0.243900 -0.008000 0.856000 -0.512000 +0.400000 0.083700 -0.243900 -0.328000 0.768000 -0.536000 +0.450000 0.100400 -0.233000 -0.008000 0.816000 -0.568000 +0.400000 0.100400 -0.207800 -0.424000 0.688000 -0.576000 +0.450000 0.150600 -0.187200 -0.088000 0.168000 -0.976000 +0.400000 0.146600 -0.182900 -0.440000 0.464000 -0.760000 +0.407800 0.150600 -0.182900 -0.544000 -0.240000 -0.800000 +0.400000 0.100400 -0.150800 -0.768000 0.376000 0.512000 +0.401900 0.150600 -0.121900 -0.864000 -0.496000 -0.024000 +0.415000 0.100400 -0.121900 -0.640000 0.192000 0.736000 +0.450000 0.150600 -0.075000 -0.616000 -0.488000 0.608000 +0.450000 0.100400 -0.090700 -0.384000 -0.320000 0.856000 +0.460500 0.150600 -0.060900 -0.624000 -0.512000 0.584000 +0.500000 0.100400 -0.067100 -0.632000 -0.296000 0.704000 +0.500000 0.107000 -0.060900 -0.608000 -0.480000 0.616000 +0.504600 0.100400 -0.060900 -0.704000 -0.248000 0.656000 +0.500000 0.150600 -0.020200 -0.704000 -0.472000 0.520000 +0.550000 0.100400 -0.005700 -0.672000 -0.576000 0.448000 +0.510200 0.150600 0.000000 -0.752000 -0.384000 0.520000 +0.550000 0.104000 0.000000 -0.664000 -0.568000 0.464000 +0.550000 0.150600 0.048400 -0.632000 -0.416000 0.640000 +0.553100 0.100400 0.000000 -0.664000 -0.576000 0.464000 +0.560700 0.150600 0.060900 -0.704000 -0.368000 0.592000 +0.593200 0.100400 0.060900 -0.640000 -0.584000 0.496000 +0.591100 0.150600 0.121900 -0.792000 -0.400000 0.440000 +0.600000 0.100400 0.071800 -0.648000 -0.592000 0.472000 +0.600000 0.134700 0.121900 -0.776000 -0.456000 0.424000 +0.627900 0.100400 0.121900 -0.608000 -0.608000 0.504000 +0.600000 0.100400 0.071800 -0.648000 -0.592000 0.472000 +0.650000 0.080100 0.121900 -0.576000 -0.640000 0.496000 +0.600000 0.093600 0.060900 -0.624000 -0.616000 0.464000 +0.650000 0.050200 0.073400 -0.576000 -0.624000 0.512000 +0.641200 0.050200 0.060900 -0.600000 -0.608000 0.512000 +0.650000 0.041800 0.060900 -0.568000 -0.648000 0.504000 +0.602900 0.050200 0.000000 -0.576000 -0.704000 0.400000 +0.650000 0.013100 0.000000 -0.448000 -0.792000 0.392000 +0.600000 0.050200 -0.005300 -0.440000 -0.752000 0.480000 +0.650000 0.000000 -0.040500 0.104000 -0.944000 0.296000 +0.600000 0.000000 -0.044900 -0.016000 -0.720000 0.688000 +0.650000 -0.010200 -0.060900 0.168000 -0.784000 0.592000 +0.600000 -0.012300 -0.060900 0.104000 -0.576000 0.800000 +0.650000 -0.033500 -0.121900 0.512000 -0.672000 0.520000 +0.600000 -0.050200 -0.088500 0.448000 -0.400000 0.792000 +0.638000 -0.050200 -0.121900 0.800000 -0.536000 0.256000 +0.600000 -0.100400 -0.077400 0.584000 0.048000 0.800000 +0.626600 -0.100400 -0.121900 0.848000 0.208000 0.472000 +0.638000 -0.050200 -0.121900 0.800000 -0.536000 0.256000 +0.638900 -0.100400 -0.182900 0.920000 0.368000 0.072000 +0.649100 -0.050200 -0.182900 0.816000 -0.544000 0.144000 +0.637300 -0.100400 -0.243900 0.848000 0.016000 -0.520000 +0.637200 -0.050200 -0.243900 0.840000 -0.080000 -0.528000 +0.604900 -0.100400 -0.304800 0.744000 -0.360000 -0.552000 +0.600000 -0.050200 -0.286000 0.712000 0.144000 -0.680000 +0.600000 -0.086300 -0.304800 0.440000 0.312000 -0.832000 +0.587300 -0.050200 -0.304800 0.688000 0.056000 -0.712000 +0.589400 -0.100400 -0.304800 -0.440000 -0.424000 -0.784000 +0.550000 -0.083700 -0.304800 0.088000 -0.736000 -0.664000 +0.550000 -0.100400 -0.280800 -0.008000 -0.528000 -0.840000 +0.500000 -0.082600 -0.304800 0.216000 -0.680000 -0.688000 +0.500000 -0.100400 -0.277800 0.560000 -0.104000 -0.816000 +0.475800 -0.100400 -0.304800 0.512000 -0.104000 -0.848000 +0.500000 -0.127100 -0.304800 0.480000 0.456000 -0.744000 +0.500000 -0.100400 -0.277800 0.560000 -0.104000 -0.816000 +0.523400 -0.150600 -0.304800 0.376000 0.592000 -0.704000 +0.550000 -0.100400 -0.280800 -0.008000 -0.528000 -0.840000 +0.550000 -0.150600 -0.287800 0.352000 0.528000 -0.768000 +0.589400 -0.100400 -0.304800 -0.440000 -0.424000 -0.784000 +0.600000 -0.150600 -0.265200 0.248000 0.032000 -0.960000 +0.600000 -0.105700 -0.304800 0.312000 -0.728000 -0.600000 +0.650000 -0.150600 -0.274900 0.544000 0.464000 -0.688000 +0.604900 -0.100400 -0.304800 0.744000 -0.360000 -0.552000 +0.650000 -0.120200 -0.243900 0.704000 0.520000 -0.472000 +0.637300 -0.100400 -0.243900 0.848000 0.016000 -0.520000 +0.650000 -0.117900 -0.182900 0.792000 0.600000 0.024000 +0.638900 -0.100400 -0.182900 0.920000 0.368000 0.072000 +0.650000 -0.146100 -0.121900 0.720000 0.504000 0.464000 +0.626600 -0.100400 -0.121900 0.848000 0.208000 0.472000 +0.626600 -0.100400 -0.121900 0.848000 0.208000 0.472000 +0.591100 0.150600 0.121900 -0.792000 -0.400000 0.440000 +0.591100 0.150600 0.121900 -0.792000 -0.400000 0.440000 +0.600000 0.150600 0.141200 -0.712000 -0.440000 0.536000 +0.600000 0.134700 0.121900 -0.776000 -0.456000 0.424000 +0.600000 0.134700 0.121900 -0.776000 -0.456000 0.424000 +0.650000 0.141000 0.182900 -0.512000 -0.488000 0.704000 +0.650000 0.141000 0.182900 -0.512000 -0.488000 0.704000 +0.685300 0.100400 0.182900 -0.504000 -0.560000 0.648000 +0.650000 0.100400 0.150000 -0.536000 -0.592000 0.592000 +0.650000 0.100400 0.150000 -0.536000 -0.592000 0.592000 +0.692100 0.050200 0.121900 -0.432000 -0.784000 0.424000 +0.692100 0.050200 0.121900 -0.432000 -0.784000 0.424000 +0.700000 0.050200 0.131500 -0.112000 -0.824000 0.544000 +0.700000 0.046100 0.121900 -0.152000 -0.904000 0.376000 +0.744700 0.050200 0.121900 0.096000 -0.864000 0.480000 +0.700000 0.026800 0.060900 -0.288000 -0.896000 0.328000 +0.750000 0.050200 0.120200 -0.160000 -0.904000 0.376000 +0.750000 0.031700 0.060900 -0.136000 -0.928000 0.336000 +0.700000 0.026800 0.060900 -0.288000 -0.896000 0.328000 +0.750000 0.013300 0.000000 -0.240000 -0.936000 0.240000 +0.700000 0.012000 0.000000 -0.032000 -0.960000 0.272000 +0.750000 0.001600 -0.060900 -0.416000 -0.904000 -0.016000 +0.700000 0.001400 -0.060900 0.088000 -0.968000 0.192000 +0.750000 0.004300 -0.121900 -0.408000 -0.880000 -0.216000 +0.700000 0.000400 -0.121900 0.224000 -0.968000 0.032000 +0.750000 0.019900 -0.182900 -0.176000 -0.792000 -0.576000 +0.700000 0.009000 -0.182900 0.456000 -0.744000 -0.472000 +0.750000 0.050200 -0.223600 -0.168000 -0.552000 -0.808000 +0.700000 0.050200 -0.225700 0.368000 -0.368000 -0.848000 +0.750000 0.100400 -0.218500 0.200000 0.232000 -0.944000 +0.700000 0.100400 -0.234000 0.272000 0.000000 -0.960000 +0.750000 0.150600 -0.191500 0.256000 0.656000 -0.704000 +0.700000 0.150600 -0.210500 0.296000 0.424000 -0.848000 +0.750000 0.157000 -0.182900 0.280000 0.720000 -0.624000 +0.700000 0.190400 -0.182900 0.432000 0.560000 -0.696000 +0.750000 0.186400 -0.121900 0.504000 0.648000 -0.560000 +0.700000 0.200800 -0.171600 0.480000 0.608000 -0.616000 +0.734900 0.200800 -0.121900 0.552000 0.608000 -0.552000 +0.700000 0.229200 -0.121900 0.528000 0.656000 -0.528000 +0.750000 0.200800 -0.104400 0.480000 0.680000 -0.544000 +0.700000 0.251000 -0.093200 0.552000 0.600000 -0.568000 +0.750000 0.228900 -0.060900 0.576000 0.696000 -0.416000 +0.725300 0.251000 -0.060900 0.696000 0.648000 -0.288000 +0.750000 0.219200 0.000000 0.672000 0.728000 0.080000 +0.721000 0.251000 0.000000 0.784000 0.608000 -0.040000 +0.750000 0.222200 0.060900 0.704000 0.696000 -0.080000 +0.727500 0.251000 0.060900 0.792000 0.584000 -0.112000 +0.750000 0.233400 0.121900 0.720000 0.680000 -0.080000 +0.736800 0.251000 0.121900 0.752000 0.632000 0.144000 +0.727500 0.251000 0.060900 0.792000 0.584000 -0.112000 +0.700000 0.297800 0.121900 0.728000 0.680000 -0.032000 +0.700000 0.290800 0.060900 0.800000 0.576000 -0.104000 +0.696500 0.301200 0.121900 0.712000 0.672000 0.168000 +0.692400 0.301200 0.060900 0.752000 0.648000 -0.056000 +0.653800 0.351500 0.121900 0.656000 0.616000 0.424000 +0.663900 0.351500 0.060900 0.768000 0.624000 0.096000 +0.650000 0.355500 0.121900 0.632000 0.632000 0.432000 +0.650000 0.370100 0.060900 0.776000 0.624000 0.048000 +0.600000 0.382600 0.121900 0.272000 0.776000 0.560000 +0.612200 0.401700 0.060900 0.488000 0.832000 0.224000 +0.600000 0.401700 0.085900 0.096000 0.928000 0.336000 +0.600000 0.407100 0.060900 0.120000 0.968000 0.184000 +0.584600 0.401700 0.060900 -0.416000 0.872000 0.248000 +0.600000 0.410900 0.000000 0.104000 0.992000 -0.032000 +0.568400 0.401700 0.000000 -0.472000 0.832000 -0.264000 +0.600000 0.401700 -0.057700 0.168000 0.920000 -0.344000 +0.600000 0.410900 0.000000 0.104000 0.992000 -0.032000 +0.616700 0.401700 0.000000 0.496000 0.864000 -0.032000 +0.600000 0.407100 0.060900 0.120000 0.968000 0.184000 +0.612200 0.401700 0.060900 0.488000 0.832000 0.224000 +0.616700 0.401700 0.000000 0.496000 0.864000 -0.032000 +0.650000 0.370100 0.060900 0.776000 0.624000 0.048000 +0.650000 0.368200 0.000000 0.792000 0.584000 -0.144000 +0.663900 0.351500 0.060900 0.768000 0.624000 0.096000 +0.660900 0.351500 0.000000 0.832000 0.512000 -0.176000 +0.692400 0.301200 0.060900 0.752000 0.648000 -0.056000 +0.685300 0.301200 0.000000 0.832000 0.536000 -0.104000 +0.700000 0.290800 0.060900 0.800000 0.576000 -0.104000 +0.700000 0.279600 0.000000 0.792000 0.600000 -0.048000 +0.727500 0.251000 0.060900 0.792000 0.584000 -0.112000 +0.721000 0.251000 0.000000 0.784000 0.608000 -0.040000 +0.700000 0.279600 0.000000 0.792000 0.600000 -0.048000 +0.725300 0.251000 -0.060900 0.696000 0.648000 -0.288000 +0.700000 0.278700 -0.060900 0.648000 0.584000 -0.472000 +0.700000 0.251000 -0.093200 0.552000 0.600000 -0.568000 +0.680100 0.301200 -0.060900 0.752000 0.544000 -0.368000 +0.673000 0.251000 -0.121900 0.568000 0.576000 -0.584000 +0.650000 0.301200 -0.100800 0.528000 0.504000 -0.672000 +0.650000 0.278000 -0.121900 0.448000 0.624000 -0.624000 +0.608400 0.301200 -0.121900 0.448000 0.488000 -0.744000 +0.650000 0.251000 -0.154700 0.488000 0.640000 -0.584000 +0.600000 0.301200 -0.128700 0.472000 0.520000 -0.704000 +0.608400 0.251000 -0.182900 0.328000 0.488000 -0.800000 +0.600000 0.256700 -0.182900 0.328000 0.496000 -0.792000 +0.600000 0.251000 -0.187000 0.320000 0.456000 -0.816000 +0.608400 0.251000 -0.182900 0.328000 0.488000 -0.800000 +0.600000 0.200800 -0.209200 0.248000 0.288000 -0.920000 +0.650000 0.227800 -0.182900 0.368000 0.576000 -0.720000 +0.650000 0.200800 -0.204000 0.272000 0.408000 -0.864000 +0.687200 0.200800 -0.182900 0.432000 0.544000 -0.712000 +0.650000 0.150600 -0.219600 0.200000 0.280000 -0.928000 +0.700000 0.190400 -0.182900 0.432000 0.560000 -0.696000 +0.700000 0.150600 -0.210500 0.296000 0.424000 -0.848000 +0.650000 0.150600 -0.219600 0.200000 0.280000 -0.928000 +0.700000 0.100400 -0.234000 0.272000 0.000000 -0.960000 +0.650000 0.100400 -0.241400 0.232000 0.064000 -0.968000 +0.700000 0.050200 -0.225700 0.368000 -0.368000 -0.848000 +0.650000 0.067400 -0.243900 0.208000 0.056000 -0.968000 +0.653800 0.050200 -0.243900 0.232000 0.032000 -0.968000 +0.650000 0.050200 -0.244900 0.216000 0.040000 -0.968000 +0.653800 0.000000 -0.243900 0.576000 -0.112000 -0.808000 +0.650000 0.000000 -0.248500 0.680000 -0.160000 -0.712000 +0.650000 -0.016900 -0.243900 0.704000 -0.184000 -0.672000 +0.600000 0.000000 -0.284600 0.512000 0.112000 -0.840000 +0.637200 -0.050200 -0.243900 0.840000 -0.080000 -0.528000 +0.600000 -0.050200 -0.286000 0.712000 0.144000 -0.680000 +0.600000 0.000000 -0.284600 0.512000 0.112000 -0.840000 +0.587300 -0.050200 -0.304800 0.688000 0.056000 -0.712000 +0.578400 0.000000 -0.304800 0.536000 0.480000 -0.688000 +0.578400 0.000000 -0.304800 0.536000 0.480000 -0.688000 +0.750000 0.062100 0.182900 -0.416000 -0.632000 0.648000 +0.750000 0.062100 0.182900 -0.416000 -0.632000 0.648000 +0.750000 0.050900 0.121900 0.096000 -0.792000 0.600000 +0.762700 0.050200 0.182900 -0.512000 -0.672000 0.520000 +0.751700 0.050200 0.121900 -0.392000 -0.816000 0.416000 +0.800000 0.035400 0.182900 -0.432000 -0.808000 0.384000 +0.800000 0.028400 0.121900 -0.376000 -0.808000 0.432000 +0.846600 0.000000 0.182900 -0.736000 -0.616000 0.264000 +0.829700 0.000000 0.121900 -0.704000 -0.616000 0.344000 +0.850000 -0.004200 0.182900 -0.720000 -0.616000 0.288000 +0.850000 -0.029600 0.121900 -0.840000 -0.432000 0.312000 +0.880500 -0.050200 0.182900 -0.744000 -0.528000 0.384000 +0.857500 -0.050200 0.121900 -0.848000 -0.448000 0.272000 +0.900000 -0.076800 0.182900 -0.504000 -0.624000 0.592000 +0.892500 -0.100400 0.121900 -0.688000 -0.680000 0.240000 +0.900000 -0.100400 0.145900 -0.608000 -0.728000 0.304000 +0.900000 -0.076800 0.182900 -0.504000 -0.624000 0.592000 +0.934300 -0.100400 0.182900 -0.392000 -0.752000 0.520000 +0.934300 -0.100400 0.182900 -0.392000 -0.752000 0.520000 +0.800000 0.150600 0.181400 0.520000 0.336000 0.776000 +0.800000 0.150600 0.181400 0.520000 0.336000 0.776000 +0.850000 0.150600 0.126500 0.640000 0.560000 0.512000 +0.800000 0.190400 0.121900 0.624000 0.752000 0.168000 +0.850000 0.151600 0.121900 0.680000 0.720000 0.080000 +0.800000 0.182100 0.060900 0.560000 0.824000 -0.024000 +0.850000 0.154700 0.060900 0.576000 0.800000 0.096000 +0.800000 0.184600 0.000000 0.464000 0.872000 0.120000 +0.850000 0.161100 0.000000 0.480000 0.856000 0.160000 +0.800000 0.194300 -0.060900 0.416000 0.824000 -0.360000 +0.850000 0.171300 -0.060900 0.448000 0.864000 -0.216000 +0.800000 0.164900 -0.121900 0.312000 0.800000 -0.504000 +0.850000 0.155600 -0.121900 0.432000 0.856000 -0.272000 +0.800000 0.150600 -0.164100 0.256000 0.800000 -0.528000 +0.850000 0.150600 -0.140900 0.432000 0.840000 -0.304000 +0.800000 0.138600 -0.182900 0.232000 0.712000 -0.656000 +0.850000 0.127100 -0.182900 0.192000 0.744000 -0.632000 +0.800000 0.100400 -0.216300 0.104000 0.416000 -0.896000 +0.850000 0.100400 -0.218500 0.128000 0.592000 -0.784000 +0.800000 0.050200 -0.233400 -0.176000 0.416000 -0.880000 +0.850000 0.050200 -0.237100 -0.376000 0.576000 -0.720000 +0.800000 0.000000 -0.217200 -0.656000 -0.464000 -0.584000 +0.850000 0.042400 -0.243900 -0.408000 0.528000 -0.736000 +0.819700 0.000000 -0.243900 -0.752000 -0.192000 -0.616000 +0.850000 0.000000 -0.279000 -0.536000 0.488000 -0.680000 +0.835300 -0.050200 -0.243900 -0.840000 -0.416000 -0.336000 +0.850000 -0.050200 -0.276700 -0.784000 -0.280000 -0.544000 +0.850000 -0.077200 -0.243900 -0.824000 -0.432000 -0.344000 +0.835300 -0.050200 -0.243900 -0.840000 -0.416000 -0.336000 +0.850000 -0.086900 -0.182900 -0.848000 -0.512000 -0.048000 +0.822900 -0.050200 -0.182900 -0.792000 -0.592000 -0.088000 +0.850000 -0.088400 -0.121900 -0.808000 -0.584000 0.016000 +0.818400 -0.050200 -0.121900 -0.760000 -0.640000 0.016000 +0.850000 -0.079400 -0.060900 -0.768000 -0.616000 0.120000 +0.823600 -0.050200 -0.060900 -0.736000 -0.664000 0.112000 +0.850000 -0.068700 0.000000 -0.752000 -0.640000 0.136000 +0.832800 -0.050200 0.000000 -0.728000 -0.656000 0.144000 +0.850000 -0.056700 0.060900 -0.720000 -0.664000 0.176000 +0.843600 -0.050200 0.060900 -0.704000 -0.672000 0.184000 +0.850000 -0.050200 0.089500 -0.768000 -0.592000 0.216000 +0.850000 -0.050200 0.089500 -0.768000 -0.592000 0.216000 +0.850000 0.150600 0.126500 0.640000 0.560000 0.512000 +0.850000 0.150600 0.126500 0.640000 0.560000 0.512000 +0.850000 0.151600 0.121900 0.680000 0.720000 0.080000 +0.850900 0.150600 0.121900 0.704000 0.704000 0.080000 +0.850000 0.154700 0.060900 0.576000 0.800000 0.096000 +0.855400 0.150600 0.060900 0.680000 0.720000 0.072000 +0.850000 0.161100 0.000000 0.480000 0.856000 0.160000 +0.867700 0.150600 0.000000 0.552000 0.816000 0.152000 +0.850000 0.171300 -0.060900 0.448000 0.864000 -0.216000 +0.888500 0.150600 -0.060900 0.504000 0.856000 -0.040000 +0.850000 0.155600 -0.121900 0.432000 0.856000 -0.272000 +0.859300 0.150600 -0.121900 0.456000 0.840000 -0.272000 +0.850000 0.150600 -0.140900 0.432000 0.840000 -0.304000 +0.850000 0.150600 -0.140900 0.432000 0.840000 -0.304000 +0.891700 0.100400 0.182900 0.576000 0.688000 0.424000 +0.891700 0.100400 0.182900 0.576000 0.688000 0.424000 +0.900000 0.100400 0.165200 0.584000 0.744000 0.296000 +0.900000 0.093100 0.182900 0.568000 0.672000 0.464000 +0.911800 0.100400 0.121900 0.528000 0.800000 0.264000 +0.940200 0.050200 0.182900 0.624000 0.528000 0.568000 +0.950000 0.069700 0.121900 0.360000 0.840000 0.384000 +0.950000 0.050200 0.169400 0.600000 0.560000 0.560000 +1.000000 0.053600 0.121900 0.280000 0.872000 0.392000 +1.000000 0.050200 0.131000 0.336000 0.784000 0.512000 +0.950000 0.050200 0.169400 0.600000 0.560000 0.560000 +1.000000 0.004900 0.182900 0.336000 0.520000 0.776000 +0.950000 0.037400 0.182900 0.520000 0.504000 0.680000 +0.950000 0.050200 0.169400 0.600000 0.560000 0.560000 +0.940200 0.050200 0.182900 0.624000 0.528000 0.568000 +0.940200 0.050200 0.182900 0.624000 0.528000 0.568000 +0.900000 0.100400 0.165200 0.584000 0.744000 0.296000 +0.900000 0.100400 0.165200 0.584000 0.744000 0.296000 +0.900000 0.107300 0.121900 0.512000 0.832000 0.184000 +0.911800 0.100400 0.121900 0.528000 0.800000 0.264000 +0.900000 0.118900 0.060900 0.472000 0.856000 0.184000 +0.936800 0.100400 0.060900 0.456000 0.872000 0.168000 +0.900000 0.131100 0.000000 0.480000 0.848000 0.192000 +0.950000 0.100400 0.012800 0.496000 0.848000 0.136000 +0.950000 0.102000 0.000000 0.472000 0.864000 0.120000 +0.952900 0.100400 0.000000 0.504000 0.848000 0.120000 +0.950000 0.106300 -0.060900 0.576000 0.776000 -0.240000 +0.957800 0.100400 -0.060900 0.544000 0.824000 -0.120000 +0.950000 0.100400 -0.078300 0.560000 0.768000 -0.304000 +1.000000 0.074600 -0.060900 0.496000 0.816000 -0.280000 +0.950000 0.086300 -0.121900 0.544000 0.784000 -0.280000 +1.000000 0.056100 -0.121900 0.488000 0.808000 -0.304000 +0.950000 0.069900 -0.182900 0.544000 0.736000 -0.392000 +1.000000 0.050200 -0.141200 0.512000 0.792000 -0.320000 +0.978000 0.050200 -0.182900 0.512000 0.768000 -0.376000 +1.000000 0.035800 -0.182900 0.504000 0.768000 -0.376000 +0.950000 0.050200 -0.224500 0.472000 0.712000 -0.504000 +1.000000 0.004200 -0.243900 0.464000 0.680000 -0.552000 +0.950000 0.037500 -0.243900 0.432000 0.688000 -0.576000 +1.000000 0.000000 -0.249700 0.512000 0.464000 -0.720000 +0.950000 0.000000 -0.291100 0.424000 0.536000 -0.720000 +1.000000 -0.050200 -0.288900 0.520000 0.432000 -0.728000 +0.950000 -0.016600 -0.304800 0.448000 0.520000 -0.720000 +0.981700 -0.050200 -0.304800 0.528000 0.432000 -0.720000 +0.950000 -0.050200 -0.338500 0.440000 0.400000 -0.800000 +1.000000 -0.073100 -0.304800 0.536000 0.424000 -0.720000 +0.950000 -0.100400 -0.351000 0.336000 0.064000 -0.936000 +1.000000 -0.100400 -0.325200 0.488000 0.344000 -0.792000 +0.950000 -0.150600 -0.345500 -0.032000 0.064000 -0.992000 +1.000000 -0.150600 -0.335800 0.136000 0.136000 -0.976000 +0.950000 -0.200800 -0.357000 -0.272000 -0.104000 -0.952000 +1.000000 -0.200800 -0.338800 0.136000 -0.384000 -0.904000 +0.950000 -0.251000 -0.328200 -0.712000 -0.568000 -0.392000 +1.000000 -0.251000 -0.355700 -0.816000 -0.248000 -0.504000 +1.000000 -0.251000 -0.355700 -0.816000 -0.248000 -0.504000 +1.000000 -0.012000 0.182900 0.384000 -0.248000 0.880000 +1.000000 -0.012000 0.182900 0.384000 -0.248000 0.880000 +1.000000 -0.050200 0.168100 0.416000 -0.344000 0.832000 +0.975800 -0.050200 0.182900 0.464000 -0.232000 0.848000 +1.000000 -0.100400 0.134700 0.432000 -0.528000 0.720000 +0.959000 -0.100400 0.182900 0.616000 -0.584000 0.520000 +0.959000 -0.100400 0.182900 0.616000 -0.584000 0.520000 +-0.900000 0.200800 0.074800 0.296000 0.712000 0.624000 +-0.900000 0.200800 0.074800 0.296000 0.712000 0.624000 +-0.900000 0.210300 0.060900 0.312000 0.744000 0.576000 +-0.879600 0.200800 0.060900 0.352000 0.712000 0.600000 +-0.900000 0.240500 0.000000 0.368000 0.840000 0.376000 +-0.850000 0.200800 0.035600 0.384000 0.744000 0.536000 +-0.850000 0.219100 0.000000 0.368000 0.824000 0.424000 +-0.811000 0.200800 0.000000 0.408000 0.816000 0.392000 +-0.811000 0.200800 0.000000 0.408000 0.816000 0.392000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.900000 -0.127600 0.121900 -0.608000 -0.704000 0.344000 +-0.900000 -0.149700 0.060900 -0.696000 -0.664000 0.232000 +-0.878400 -0.150600 0.121900 -0.736000 -0.560000 0.368000 +-0.899200 -0.150600 0.060900 -0.816000 -0.504000 0.256000 +-0.851500 -0.200800 0.121900 -0.832000 -0.360000 0.408000 +-0.869300 -0.200800 0.060900 -0.824000 -0.496000 0.248000 +-0.899200 -0.150600 0.060900 -0.816000 -0.504000 0.256000 +-0.882700 -0.200800 0.000000 -0.840000 -0.496000 0.192000 +-0.900000 -0.150600 0.057700 -0.744000 -0.616000 0.232000 +-0.900000 -0.169600 0.000000 -0.800000 -0.552000 0.224000 +-0.882700 -0.200800 0.000000 -0.840000 -0.496000 0.192000 +-0.900000 -0.192500 -0.060900 -0.856000 -0.488000 0.144000 +-0.895700 -0.200800 -0.060900 -0.864000 -0.480000 0.136000 +-0.900000 -0.200800 -0.096200 -0.752000 -0.632000 0.128000 +-0.860100 -0.251000 -0.060900 -0.808000 -0.568000 0.112000 +-0.900000 -0.204500 -0.121900 -0.688000 -0.712000 0.104000 +-0.866600 -0.251000 -0.121900 -0.808000 -0.576000 0.072000 +-0.900000 -0.206900 -0.182900 -0.648000 -0.752000 0.056000 +-0.864200 -0.251000 -0.182900 -0.800000 -0.592000 0.000000 +-0.900000 -0.212400 -0.243900 -0.672000 -0.712000 0.176000 +-0.869200 -0.251000 -0.243900 -0.768000 -0.600000 0.200000 +-0.900000 -0.236500 -0.304800 -0.680000 -0.456000 -0.560000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-0.891700 -0.251000 -0.304800 -0.808000 -0.512000 -0.264000 +-0.850000 0.184100 0.060900 0.376000 0.632000 0.664000 +-0.850000 0.184100 0.060900 0.376000 0.632000 0.664000 +-0.850000 0.150600 0.098600 0.360000 0.600000 0.704000 +-0.800000 0.153700 0.060900 0.432000 0.632000 0.632000 +-0.800000 0.150600 0.064100 0.424000 0.560000 0.704000 +-0.796300 0.150600 0.060900 0.512000 0.584000 0.616000 +-0.800000 0.153700 0.060900 0.432000 0.632000 0.632000 +-0.750000 0.150600 0.014500 0.472000 0.624000 0.608000 +-0.800000 0.195100 0.000000 0.456000 0.768000 0.432000 +-0.750000 0.162200 0.000000 0.464000 0.672000 0.560000 +-0.750000 0.150600 0.014500 0.472000 0.624000 0.608000 +-0.734000 0.150600 0.000000 0.496000 0.640000 0.576000 +-0.750000 0.162200 0.000000 0.464000 0.672000 0.560000 +-0.700000 0.150600 -0.043600 0.552000 0.712000 0.424000 +-0.750000 0.191300 -0.060900 0.496000 0.856000 0.072000 +-0.700000 0.159000 -0.060900 0.600000 0.776000 0.184000 +-0.750000 0.174400 -0.121900 0.448000 0.824000 -0.336000 +-0.700000 0.150600 -0.089800 0.592000 0.744000 -0.280000 +-0.715000 0.150600 -0.121900 0.512000 0.744000 -0.408000 +-0.700000 0.140000 -0.121900 0.536000 0.728000 -0.408000 +-0.750000 0.150600 -0.159200 0.432000 0.664000 -0.600000 +-0.700000 0.100400 -0.182100 0.536000 0.592000 -0.592000 +-0.750000 0.132600 -0.182900 0.408000 0.656000 -0.624000 +-0.700900 0.100400 -0.182900 0.440000 0.608000 -0.648000 +-0.750000 0.100400 -0.222000 0.432000 0.576000 -0.680000 +-0.700000 0.099700 -0.182900 0.504000 0.560000 -0.640000 +-0.750000 0.077000 -0.243900 0.368000 0.552000 -0.744000 +-0.700000 0.050200 -0.235800 0.504000 0.432000 -0.744000 +-0.711800 0.050200 -0.243900 0.416000 0.432000 -0.792000 +-0.700000 0.037400 -0.243900 0.440000 0.392000 -0.800000 +-0.750000 0.050200 -0.267100 0.368000 0.432000 -0.816000 +-0.700000 0.000000 -0.262900 0.392000 0.288000 -0.864000 +-0.750000 0.000000 -0.285200 0.328000 0.160000 -0.920000 +-0.750000 0.000000 -0.285200 0.328000 0.160000 -0.920000 +-0.750000 0.012900 0.121900 0.496000 0.384000 0.768000 +-0.750000 0.012900 0.121900 0.496000 0.384000 0.768000 +-0.781300 0.050200 0.121900 0.536000 0.400000 0.736000 +-0.750000 0.050200 0.097600 0.464000 0.408000 0.776000 +-0.750000 0.050200 0.097600 0.464000 0.408000 0.776000 +-0.800000 -0.280700 0.121900 -0.736000 -0.528000 0.408000 +-0.800000 -0.280700 0.121900 -0.736000 -0.528000 0.408000 +-0.783300 -0.301200 0.121900 -0.688000 -0.568000 0.440000 +-0.800000 -0.301200 0.085900 -0.768000 -0.544000 0.304000 +-0.800000 -0.301200 0.085900 -0.768000 -0.544000 0.304000 +-0.750000 -0.342500 0.121900 -0.536000 -0.592000 0.592000 +-0.750000 -0.342500 0.121900 -0.536000 -0.592000 0.592000 +-0.739400 -0.351500 0.121900 -0.528000 -0.576000 0.616000 +-0.750000 -0.351500 0.110100 -0.600000 -0.584000 0.536000 +-0.750000 -0.351500 0.110100 -0.600000 -0.584000 0.536000 +-0.701000 -0.451900 0.060900 -0.792000 -0.480000 0.344000 +-0.701000 -0.451900 0.060900 -0.792000 -0.480000 0.344000 +-0.700000 -0.451900 0.063700 -0.672000 -0.600000 0.424000 +-0.700000 -0.453200 0.060900 -0.560000 -0.720000 0.392000 +-0.700000 -0.453200 0.060900 -0.560000 -0.720000 0.392000 +-0.650000 -0.141800 0.121900 0.432000 0.328000 0.832000 +-0.650000 -0.141800 0.121900 0.432000 0.328000 0.832000 +-0.677900 -0.100400 0.121900 0.528000 0.328000 0.776000 +-0.650000 -0.100400 0.096100 0.592000 0.288000 0.744000 +-0.650000 -0.100400 0.096100 0.592000 0.288000 0.744000 +-0.600000 -0.122400 0.060900 0.616000 0.400000 0.664000 +-0.600000 -0.122400 0.060900 0.616000 0.400000 0.664000 +-0.575700 -0.150600 0.060900 0.384000 0.664000 0.632000 +-0.600000 -0.150600 0.080700 0.576000 0.424000 0.688000 +-0.600000 -0.150600 0.080700 0.576000 0.424000 0.688000 +-0.559300 -0.200800 0.121900 0.160000 0.720000 0.672000 +-0.559300 -0.200800 0.121900 0.160000 0.720000 0.672000 +-0.550000 -0.200800 0.118700 0.032000 0.784000 0.608000 +-0.550000 -0.202900 0.121900 0.032000 0.728000 0.680000 +-0.536800 -0.200800 0.121900 -0.104000 0.736000 0.664000 +-0.536800 -0.200800 0.121900 -0.104000 0.736000 0.664000 +-0.550000 -0.494000 0.121900 0.024000 -0.832000 0.536000 +-0.550000 -0.494000 0.121900 0.024000 -0.832000 0.536000 +-0.550000 -0.502100 0.104800 0.104000 -0.840000 0.520000 +-0.500000 -0.486900 0.121900 0.296000 -0.800000 0.504000 +-0.500000 -0.502100 0.088800 0.616000 -0.688000 0.376000 +-0.450000 -0.453600 0.121900 0.584000 -0.744000 0.288000 +-0.489100 -0.502100 0.060900 0.704000 -0.616000 0.328000 +-0.450000 -0.471900 0.060900 0.592000 -0.752000 0.272000 +-0.450000 -0.471900 0.060900 0.592000 -0.752000 0.272000 +-0.550000 -0.502100 0.104800 0.104000 -0.840000 0.520000 +-0.550000 -0.502100 0.104800 0.104000 -0.840000 0.520000 +-0.550000 -0.532000 0.060900 0.080000 -0.776000 0.624000 +-0.500000 -0.502100 0.088800 0.616000 -0.688000 0.376000 +-0.500000 -0.517700 0.060900 0.632000 -0.632000 0.440000 +-0.489100 -0.502100 0.060900 0.704000 -0.616000 0.328000 +-0.489100 -0.502100 0.060900 0.704000 -0.616000 0.328000 +-0.405500 -0.100400 0.060900 -0.712000 0.456000 0.520000 +-0.405500 -0.100400 0.060900 -0.712000 0.456000 0.520000 +-0.400000 -0.090100 0.060900 -0.696000 0.400000 0.584000 +-0.400000 -0.100400 0.069600 -0.688000 0.456000 0.552000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.350000 -0.050200 0.083200 -0.416000 0.344000 0.832000 +-0.350000 -0.097900 0.121900 -0.560000 0.424000 0.704000 +-0.300000 -0.050200 0.104800 -0.312000 0.512000 0.792000 +-0.300000 -0.066800 0.121900 -0.280000 0.584000 0.752000 +-0.255700 -0.050200 0.121900 -0.192000 0.512000 0.832000 +-0.255700 -0.050200 0.121900 -0.192000 0.512000 0.832000 +-0.350000 -0.001900 0.060900 -0.656000 0.280000 0.688000 +-0.350000 -0.001900 0.060900 -0.656000 0.280000 0.688000 +-0.350000 -0.050200 0.083200 -0.416000 0.344000 0.832000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.351400 -0.100400 0.121900 -0.608000 0.368000 0.696000 +-0.400000 -0.140400 0.121900 -0.448000 0.624000 0.632000 +-0.400000 -0.100400 0.069600 -0.688000 0.456000 0.552000 +-0.400000 -0.100400 0.069600 -0.688000 0.456000 0.552000 +-0.400000 -0.401700 0.111300 0.640000 -0.680000 0.336000 +-0.400000 -0.401700 0.111300 0.640000 -0.680000 0.336000 +-0.400000 -0.423000 0.060900 0.616000 -0.696000 0.360000 +-0.350000 -0.401700 0.073400 0.632000 -0.688000 0.344000 +-0.350000 -0.406300 0.060900 0.592000 -0.728000 0.320000 +-0.344500 -0.401700 0.060900 0.632000 -0.688000 0.328000 +-0.344500 -0.401700 0.060900 0.632000 -0.688000 0.328000 +-0.348200 0.000000 0.060900 -0.376000 0.448000 0.800000 +-0.348200 0.000000 0.060900 -0.376000 0.448000 0.800000 +-0.300000 0.027200 0.060900 -0.160000 0.552000 0.808000 +-0.300000 0.000000 0.088800 -0.240000 0.432000 0.864000 +-0.250000 0.033500 0.060900 0.056000 0.528000 0.840000 +-0.250000 0.000000 0.079500 -0.144000 0.552000 0.816000 +-0.200000 0.020500 0.060900 0.664000 0.440000 0.600000 +-0.200000 0.000000 0.081400 0.696000 0.336000 0.624000 +-0.190300 0.000000 0.060900 0.816000 0.200000 0.536000 +-0.200000 -0.050200 0.072600 0.688000 0.360000 0.624000 +-0.193200 -0.050200 0.060900 0.808000 0.008000 0.584000 +-0.200000 -0.100400 0.076800 0.784000 -0.136000 0.600000 +-0.190200 -0.100400 0.060900 0.752000 -0.248000 0.600000 +-0.200000 -0.121800 0.060900 0.728000 -0.328000 0.592000 +-0.200000 -0.121800 0.060900 0.728000 -0.328000 0.592000 +-0.250000 0.000000 0.079500 -0.144000 0.552000 0.816000 +-0.250000 0.000000 0.079500 -0.144000 0.552000 0.816000 +-0.200000 0.000000 0.081400 0.696000 0.336000 0.624000 +-0.250000 -0.048000 0.121900 0.272000 0.640000 0.704000 +-0.200000 -0.050200 0.072600 0.688000 0.360000 0.624000 +-0.247100 -0.050200 0.121900 0.488000 0.512000 0.696000 +-0.200000 -0.100400 0.076800 0.784000 -0.136000 0.600000 +-0.230200 -0.100400 0.121900 0.776000 -0.176000 0.600000 +-0.230200 -0.100400 0.121900 0.776000 -0.176000 0.600000 +0.550000 0.351500 0.078000 -0.616000 0.672000 0.392000 +0.550000 0.351500 0.078000 -0.616000 0.672000 0.392000 +0.540600 0.351500 0.060900 -0.584000 0.632000 0.496000 +0.550000 0.359900 0.060900 -0.592000 0.640000 0.480000 +0.500000 0.351500 0.029100 -0.680000 0.048000 0.728000 +0.550000 0.388900 0.000000 -0.392000 0.856000 0.320000 +0.500000 0.369100 0.000000 -0.184000 0.800000 0.552000 +0.500000 0.351500 0.029100 -0.680000 0.048000 0.728000 +0.458200 0.351500 0.000000 -0.280000 0.520000 0.800000 +0.458200 0.351500 0.000000 -0.280000 0.520000 0.800000 +0.550000 0.246100 0.121900 -0.904000 -0.224000 0.352000 +0.550000 0.246100 0.121900 -0.904000 -0.224000 0.352000 +0.550000 0.200800 0.086900 -0.880000 -0.256000 0.392000 +0.548800 0.251000 0.121900 -0.912000 -0.176000 0.360000 +0.538800 0.200800 0.060900 -0.824000 -0.216000 0.520000 +0.533200 0.251000 0.060900 -0.856000 0.032000 0.512000 +0.500000 0.200800 0.008600 -0.576000 -0.176000 0.792000 +0.500800 0.251000 0.000000 -0.792000 -0.016000 0.608000 +0.500000 0.245700 0.000000 -0.568000 0.120000 0.808000 +0.500000 0.251000 -0.000900 -0.496000 0.112000 0.856000 +0.488800 0.200800 0.000000 -0.512000 0.024000 0.856000 +0.450000 0.251000 -0.039600 -0.400000 -0.080000 0.904000 +0.450000 0.200800 -0.035500 -0.536000 -0.264000 0.792000 +0.400000 0.251000 -0.058700 -0.328000 -0.176000 0.920000 +0.416500 0.200800 -0.060900 -0.560000 -0.352000 0.744000 +0.400000 0.242400 -0.060900 -0.352000 -0.192000 0.904000 +0.400000 0.200800 -0.077800 -0.600000 -0.432000 0.664000 +0.395100 0.251000 -0.060900 -0.344000 -0.184000 0.912000 +0.366500 0.200800 -0.121900 -0.760000 -0.624000 0.168000 +0.350000 0.251000 -0.088400 -0.448000 -0.320000 0.824000 +0.350000 0.218900 -0.121900 -0.504000 -0.816000 0.264000 +0.300000 0.251000 -0.114600 -0.168000 -0.536000 0.824000 +0.300000 0.236900 -0.121900 -0.304000 -0.688000 0.640000 +0.271900 0.251000 -0.121900 -0.240000 -0.760000 0.592000 +0.300000 0.251000 -0.156100 -0.368000 -0.808000 -0.448000 +0.300000 0.236900 -0.121900 -0.304000 -0.688000 0.640000 +0.321900 0.251000 -0.182900 -0.240000 -0.296000 -0.920000 +0.350000 0.218900 -0.121900 -0.504000 -0.816000 0.264000 +0.350000 0.236900 -0.182900 -0.272000 -0.424000 -0.856000 +0.366500 0.200800 -0.121900 -0.760000 -0.624000 0.168000 +0.380800 0.200800 -0.182900 -0.440000 -0.264000 -0.856000 +0.400000 0.152400 -0.121900 -0.688000 -0.712000 -0.048000 +0.400000 0.155900 -0.182900 -0.216000 -0.144000 -0.960000 +0.380800 0.200800 -0.182900 -0.440000 -0.264000 -0.856000 +0.400000 0.200800 -0.189400 -0.152000 -0.072000 -0.984000 +0.350000 0.236900 -0.182900 -0.272000 -0.424000 -0.856000 +0.400000 0.251000 -0.186400 -0.152000 0.040000 -0.984000 +0.350000 0.251000 -0.187300 -0.168000 -0.184000 -0.960000 +0.400000 0.301200 -0.184200 -0.016000 -0.016000 -0.992000 +0.350000 0.301200 -0.184400 -0.056000 0.000000 -0.992000 +0.400000 0.351500 -0.194500 0.000000 0.072000 -0.992000 +0.350000 0.351500 -0.192800 0.000000 0.056000 -0.992000 +0.400000 0.377300 -0.182900 0.016000 0.320000 -0.944000 +0.350000 0.377400 -0.182900 0.000000 0.280000 -0.952000 +0.400000 0.401700 -0.171200 0.088000 0.472000 -0.872000 +0.350000 0.401700 -0.174600 0.056000 0.440000 -0.888000 +0.400000 0.432800 -0.121900 0.160000 0.904000 -0.384000 +0.350000 0.445000 -0.121900 0.208000 0.960000 -0.152000 +0.400000 0.419800 -0.060900 0.080000 0.848000 0.520000 +0.350000 0.424300 -0.060900 0.120000 0.824000 0.544000 +0.400000 0.401700 -0.034800 -0.040000 0.584000 0.808000 +0.350000 0.401700 -0.031000 0.032000 0.488000 0.864000 +0.400000 0.351500 -0.018700 -0.136000 -0.208000 0.960000 +0.350000 0.351500 -0.021800 0.032000 -0.048000 0.992000 +0.350000 0.401700 -0.031000 0.032000 0.488000 0.864000 +0.300000 0.351500 -0.009100 -0.016000 -0.144000 0.984000 +0.300000 0.401700 -0.022200 0.096000 0.472000 0.864000 +0.350000 0.401700 -0.031000 0.032000 0.488000 0.864000 +0.300000 0.430700 -0.060900 0.128000 0.808000 0.568000 +0.350000 0.424300 -0.060900 0.120000 0.824000 0.544000 +0.300000 0.451900 -0.106900 0.184000 0.864000 0.456000 +0.350000 0.445000 -0.121900 0.208000 0.960000 -0.152000 +0.323400 0.451900 -0.121900 0.248000 0.944000 -0.200000 +0.350000 0.401700 -0.174600 0.056000 0.440000 -0.888000 +0.300000 0.451900 -0.131100 0.200000 0.712000 -0.664000 +0.300000 0.401700 -0.174800 0.040000 0.368000 -0.920000 +0.350000 0.401700 -0.174600 0.056000 0.440000 -0.888000 +0.300000 0.379400 -0.182900 -0.016000 0.272000 -0.960000 +0.350000 0.377400 -0.182900 0.000000 0.280000 -0.952000 +0.300000 0.351500 -0.193900 -0.008000 0.064000 -0.992000 +0.350000 0.351500 -0.192800 0.000000 0.056000 -0.992000 +0.300000 0.301200 -0.184400 -0.064000 -0.072000 -0.992000 +0.350000 0.301200 -0.184400 -0.056000 0.000000 -0.992000 +0.300000 0.284000 -0.182900 -0.168000 -0.184000 -0.960000 +0.350000 0.251000 -0.187300 -0.168000 -0.184000 -0.960000 +0.321900 0.251000 -0.182900 -0.240000 -0.296000 -0.920000 +0.350000 0.236900 -0.182900 -0.272000 -0.424000 -0.856000 +0.350000 0.236900 -0.182900 -0.272000 -0.424000 -0.856000 +0.550000 0.246100 0.121900 -0.904000 -0.224000 0.352000 +0.550000 0.246100 0.121900 -0.904000 -0.224000 0.352000 +0.567500 0.200800 0.121900 -0.784000 -0.344000 0.504000 +0.550000 0.200800 0.086900 -0.880000 -0.256000 0.392000 +0.550000 0.200800 0.086900 -0.880000 -0.256000 0.392000 +0.600000 0.100400 0.071800 -0.648000 -0.592000 0.472000 +0.600000 0.100400 0.071800 -0.648000 -0.592000 0.472000 +0.600000 0.093600 0.060900 -0.624000 -0.616000 0.464000 +0.593200 0.100400 0.060900 -0.640000 -0.584000 0.496000 +0.600000 0.053300 0.000000 -0.472000 -0.712000 0.512000 +0.553100 0.100400 0.000000 -0.664000 -0.576000 0.464000 +0.600000 0.050200 -0.005300 -0.440000 -0.752000 0.480000 +0.550000 0.100400 -0.005700 -0.672000 -0.576000 0.448000 +0.550000 0.050200 -0.037800 -0.320000 -0.688000 0.640000 +0.504600 0.100400 -0.060900 -0.704000 -0.248000 0.656000 +0.500000 0.050200 -0.057700 -0.560000 0.128000 0.816000 +0.500000 0.067400 -0.060900 -0.592000 0.120000 0.792000 +0.495100 0.050200 -0.060900 -0.456000 0.136000 0.872000 +0.500000 0.100400 -0.067100 -0.632000 -0.296000 0.704000 +0.450000 0.050200 -0.077000 -0.360000 0.120000 0.920000 +0.450000 0.100400 -0.090700 -0.384000 -0.320000 0.856000 +0.400000 0.050200 -0.114800 -0.552000 0.256000 0.784000 +0.415000 0.100400 -0.121900 -0.640000 0.192000 0.736000 +0.400000 0.072600 -0.121900 -0.632000 0.256000 0.720000 +0.400000 0.100400 -0.150800 -0.768000 0.376000 0.512000 +0.393200 0.050200 -0.121900 -0.648000 0.352000 0.664000 +0.381500 0.100400 -0.182900 -0.896000 0.440000 -0.008000 +0.357200 0.050200 -0.182900 -0.736000 0.640000 0.184000 +0.400000 0.100400 -0.207800 -0.424000 0.688000 -0.576000 +0.351400 0.050200 -0.243900 -0.480000 0.768000 -0.416000 +0.400000 0.083700 -0.243900 -0.328000 0.768000 -0.536000 +0.400000 0.050200 -0.294000 -0.352000 0.672000 -0.640000 +0.351400 0.050200 -0.243900 -0.480000 0.768000 -0.416000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.350000 0.049300 -0.243900 -0.512000 0.784000 -0.320000 +0.350000 0.024300 -0.304800 -0.456000 0.784000 -0.408000 +0.300000 0.032100 -0.243900 -0.576000 0.680000 -0.432000 +0.301400 0.000000 -0.304800 -0.584000 0.656000 -0.464000 +0.300000 0.000000 -0.302400 -0.544000 0.608000 -0.568000 +0.300000 -0.003100 -0.304800 -0.376000 0.424000 -0.816000 +0.301400 0.000000 -0.304800 -0.584000 0.656000 -0.464000 +0.300000 -0.050200 -0.319900 -0.536000 0.224000 -0.808000 +0.350000 0.000000 -0.339100 -0.264000 0.552000 -0.784000 +0.342100 -0.050200 -0.365800 -0.640000 -0.104000 -0.752000 +0.350000 -0.037900 -0.365800 -0.440000 0.432000 -0.776000 +0.350000 -0.050200 -0.374000 -0.496000 -0.096000 -0.856000 +0.383500 -0.050200 -0.365800 0.200000 -0.288000 -0.928000 +0.350000 -0.059800 -0.365800 -0.280000 -0.560000 -0.768000 +0.400000 -0.050200 -0.360800 0.184000 -0.432000 -0.872000 +0.350000 -0.100400 -0.331300 -0.432000 -0.520000 -0.728000 +0.400000 -0.100400 -0.340000 -0.040000 -0.360000 -0.928000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.400000 -0.150600 -0.318400 -0.432000 -0.416000 -0.792000 +0.380400 -0.150600 -0.304800 -0.424000 -0.456000 -0.776000 +0.400000 -0.168700 -0.304800 -0.504000 -0.464000 -0.720000 +0.350000 -0.150600 -0.283600 -0.064000 -0.424000 -0.896000 +0.400000 -0.200800 -0.276700 0.448000 -0.472000 -0.752000 +0.350000 -0.200800 -0.271400 0.216000 0.224000 -0.944000 +0.400000 -0.249400 -0.243900 0.760000 -0.472000 -0.424000 +0.350000 -0.228300 -0.304800 0.616000 0.528000 -0.576000 +0.399000 -0.251000 -0.243900 0.912000 -0.008000 -0.392000 +0.366700 -0.251000 -0.304800 0.704000 0.488000 -0.496000 +0.350000 -0.228300 -0.304800 0.616000 0.528000 -0.576000 +0.350000 -0.251000 -0.329500 0.536000 0.472000 -0.688000 +0.320800 -0.200800 -0.304800 0.496000 0.328000 -0.800000 +0.300000 -0.251000 -0.347800 0.304000 0.384000 -0.864000 +0.300000 -0.200800 -0.324200 0.480000 0.248000 -0.832000 +0.320800 -0.200800 -0.304800 0.496000 0.328000 -0.800000 +0.300000 -0.150600 -0.312600 0.312000 -0.200000 -0.920000 +0.313400 -0.150600 -0.304800 0.400000 -0.360000 -0.840000 +0.300000 -0.100400 -0.310000 -0.248000 0.072000 -0.960000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.350000 -0.100400 -0.331300 -0.432000 -0.520000 -0.728000 +0.300000 -0.100400 -0.310000 -0.248000 0.072000 -0.960000 +0.350000 -0.059800 -0.365800 -0.280000 -0.560000 -0.768000 +0.300000 -0.050200 -0.319900 -0.536000 0.224000 -0.808000 +0.342100 -0.050200 -0.365800 -0.640000 -0.104000 -0.752000 +0.350000 -0.059800 -0.365800 -0.280000 -0.560000 -0.768000 +0.350000 -0.050200 -0.374000 -0.496000 -0.096000 -0.856000 +0.350000 -0.050200 -0.374000 -0.496000 -0.096000 -0.856000 +0.650000 0.080100 0.121900 -0.576000 -0.640000 0.496000 +0.650000 0.080100 0.121900 -0.576000 -0.640000 0.496000 +0.692100 0.050200 0.121900 -0.432000 -0.784000 0.424000 +0.650000 0.050200 0.073400 -0.576000 -0.624000 0.512000 +0.700000 0.046100 0.121900 -0.152000 -0.904000 0.376000 +0.650000 0.041800 0.060900 -0.568000 -0.648000 0.504000 +0.700000 0.026800 0.060900 -0.288000 -0.896000 0.328000 +0.650000 0.013100 0.000000 -0.448000 -0.792000 0.392000 +0.700000 0.012000 0.000000 -0.032000 -0.960000 0.272000 +0.650000 0.000000 -0.040500 0.104000 -0.944000 0.296000 +0.700000 0.001400 -0.060900 0.088000 -0.968000 0.192000 +0.686800 0.000000 -0.060900 0.208000 -0.960000 0.144000 +0.700000 0.000400 -0.121900 0.224000 -0.968000 0.032000 +0.698200 0.000000 -0.121900 0.296000 -0.952000 0.032000 +0.700000 0.009000 -0.182900 0.456000 -0.744000 -0.472000 +0.687300 0.000000 -0.182900 0.648000 -0.600000 -0.456000 +0.700000 0.050200 -0.225700 0.368000 -0.368000 -0.848000 +0.653800 0.000000 -0.243900 0.576000 -0.112000 -0.808000 +0.653800 0.050200 -0.243900 0.232000 0.032000 -0.968000 +0.653800 0.050200 -0.243900 0.232000 0.032000 -0.968000 +0.750000 0.233400 0.121900 0.720000 0.680000 -0.080000 +0.750000 0.233400 0.121900 0.720000 0.680000 -0.080000 +0.788900 0.200800 0.121900 0.632000 0.744000 0.184000 +0.750000 0.222200 0.060900 0.704000 0.696000 -0.080000 +0.772600 0.200800 0.060900 0.648000 0.736000 -0.136000 +0.750000 0.219200 0.000000 0.672000 0.728000 0.080000 +0.770200 0.200800 0.000000 0.616000 0.776000 0.056000 +0.750000 0.228900 -0.060900 0.576000 0.696000 -0.416000 +0.787300 0.200800 -0.060900 0.520000 0.824000 -0.184000 +0.750000 0.200800 -0.104400 0.480000 0.680000 -0.544000 +0.800000 0.194300 -0.060900 0.416000 0.824000 -0.360000 +0.750000 0.186400 -0.121900 0.504000 0.648000 -0.560000 +0.800000 0.164900 -0.121900 0.312000 0.800000 -0.504000 +0.750000 0.157000 -0.182900 0.280000 0.720000 -0.624000 +0.800000 0.150600 -0.164100 0.256000 0.800000 -0.528000 +0.769100 0.150600 -0.182900 0.248000 0.704000 -0.648000 +0.800000 0.138600 -0.182900 0.232000 0.712000 -0.656000 +0.750000 0.150600 -0.191500 0.256000 0.656000 -0.704000 +0.800000 0.100400 -0.216300 0.104000 0.416000 -0.896000 +0.750000 0.100400 -0.218500 0.200000 0.232000 -0.944000 +0.800000 0.050200 -0.233400 -0.176000 0.416000 -0.880000 +0.750000 0.050200 -0.223600 -0.168000 -0.552000 -0.808000 +0.800000 0.000000 -0.217200 -0.656000 -0.464000 -0.584000 +0.750000 0.019900 -0.182900 -0.176000 -0.792000 -0.576000 +0.776700 0.000000 -0.182900 -0.576000 -0.728000 -0.360000 +0.750000 0.004300 -0.121900 -0.408000 -0.880000 -0.216000 +0.756600 0.000000 -0.121900 -0.496000 -0.856000 -0.080000 +0.750000 0.001600 -0.060900 -0.416000 -0.904000 -0.016000 +0.753100 0.000000 -0.060900 -0.472000 -0.872000 0.000000 +0.750000 0.013300 0.000000 -0.240000 -0.936000 0.240000 +0.772100 0.000000 0.000000 -0.504000 -0.832000 0.224000 +0.750000 0.031700 0.060900 -0.136000 -0.928000 0.336000 +0.798100 0.000000 0.060900 -0.504000 -0.792000 0.312000 +0.772100 0.000000 0.000000 -0.504000 -0.832000 0.224000 +0.800000 -0.001000 0.060900 -0.584000 -0.776000 0.216000 +0.800000 -0.015400 0.000000 -0.560000 -0.800000 0.184000 +0.843600 -0.050200 0.060900 -0.704000 -0.672000 0.184000 +0.832800 -0.050200 0.000000 -0.728000 -0.656000 0.144000 +0.800000 -0.015400 0.000000 -0.560000 -0.800000 0.184000 +0.823600 -0.050200 -0.060900 -0.736000 -0.664000 0.112000 +0.800000 -0.024700 -0.060900 -0.616000 -0.776000 0.088000 +0.818400 -0.050200 -0.121900 -0.760000 -0.640000 0.016000 +0.800000 -0.027900 -0.121900 -0.664000 -0.736000 -0.072000 +0.822900 -0.050200 -0.182900 -0.792000 -0.592000 -0.088000 +0.800000 -0.017800 -0.182900 -0.616000 -0.680000 -0.376000 +0.835300 -0.050200 -0.243900 -0.840000 -0.416000 -0.336000 +0.800000 0.000000 -0.217200 -0.656000 -0.464000 -0.584000 +0.819700 0.000000 -0.243900 -0.752000 -0.192000 -0.616000 +0.819700 0.000000 -0.243900 -0.752000 -0.192000 -0.616000 +0.788900 0.200800 0.121900 0.632000 0.744000 0.184000 +0.788900 0.200800 0.121900 0.632000 0.744000 0.184000 +0.800000 0.190400 0.121900 0.624000 0.752000 0.168000 +0.772600 0.200800 0.060900 0.648000 0.736000 -0.136000 +0.800000 0.182100 0.060900 0.560000 0.824000 -0.024000 +0.770200 0.200800 0.000000 0.616000 0.776000 0.056000 +0.800000 0.184600 0.000000 0.464000 0.872000 0.120000 +0.787300 0.200800 -0.060900 0.520000 0.824000 -0.184000 +0.800000 0.194300 -0.060900 0.416000 0.824000 -0.360000 +0.800000 0.194300 -0.060900 0.416000 0.824000 -0.360000 +0.800000 0.028400 0.121900 -0.376000 -0.808000 0.432000 +0.800000 0.028400 0.121900 -0.376000 -0.808000 0.432000 +0.829700 0.000000 0.121900 -0.704000 -0.616000 0.344000 +0.800000 0.000000 0.064400 -0.576000 -0.736000 0.344000 +0.800000 0.000000 0.064400 -0.576000 -0.736000 0.344000 +0.911800 0.100400 0.121900 0.528000 0.800000 0.264000 +0.911800 0.100400 0.121900 0.528000 0.800000 0.264000 +0.950000 0.069700 0.121900 0.360000 0.840000 0.384000 +0.936800 0.100400 0.060900 0.456000 0.872000 0.168000 +0.950000 0.091300 0.060900 0.600000 0.776000 0.176000 +0.950000 0.100400 0.012800 0.496000 0.848000 0.136000 +1.000000 0.068400 0.060900 0.464000 0.872000 0.104000 +0.952900 0.100400 0.000000 0.504000 0.848000 0.120000 +1.000000 0.075000 0.000000 0.472000 0.872000 0.072000 +0.957800 0.100400 -0.060900 0.544000 0.824000 -0.120000 +1.000000 0.074600 -0.060900 0.496000 0.816000 -0.280000 +1.000000 0.074600 -0.060900 0.496000 0.816000 -0.280000 +0.950000 -0.142500 0.121900 -0.608000 -0.672000 0.392000 +0.950000 -0.142500 0.121900 -0.608000 -0.672000 0.392000 +0.950000 -0.150600 0.094900 -0.648000 -0.696000 0.272000 +0.900000 -0.107100 0.121900 -0.584000 -0.768000 0.240000 +0.942000 -0.150600 0.060900 -0.704000 -0.672000 0.200000 +0.900000 -0.117100 0.060900 -0.656000 -0.736000 0.136000 +0.931300 -0.150600 0.000000 -0.640000 -0.744000 0.144000 +0.900000 -0.125700 0.000000 -0.664000 -0.728000 0.136000 +0.917800 -0.150600 -0.060900 -0.640000 -0.736000 0.184000 +0.900000 -0.135500 -0.060900 -0.672000 -0.712000 0.168000 +0.902600 -0.150600 -0.121900 -0.664000 -0.736000 0.096000 +0.900000 -0.148200 -0.121900 -0.664000 -0.728000 0.088000 +0.900000 -0.150600 -0.145400 -0.696000 -0.704000 0.104000 +0.902600 -0.150600 -0.121900 -0.664000 -0.736000 0.096000 +0.900000 -0.155900 -0.182900 -0.744000 -0.648000 0.112000 +0.950000 -0.200400 -0.121900 -0.720000 -0.672000 0.136000 +0.939100 -0.200800 -0.182900 -0.712000 -0.672000 0.160000 +0.950000 -0.200800 -0.124000 -0.680000 -0.712000 0.160000 +0.950000 -0.211700 -0.182900 -0.704000 -0.680000 0.176000 +0.939100 -0.200800 -0.182900 -0.712000 -0.672000 0.160000 +0.950000 -0.224400 -0.243900 -0.688000 -0.640000 0.328000 +0.928800 -0.200800 -0.243900 -0.736000 -0.616000 0.240000 +0.939100 -0.200800 -0.182900 -0.712000 -0.672000 0.160000 +0.900000 -0.163000 -0.243900 -0.816000 -0.552000 0.128000 +0.900000 -0.155900 -0.182900 -0.744000 -0.648000 0.112000 +0.890800 -0.150600 -0.243900 -0.848000 -0.512000 0.064000 +0.895100 -0.150600 -0.182900 -0.744000 -0.648000 0.104000 +0.900000 -0.155900 -0.182900 -0.744000 -0.648000 0.112000 +0.900000 -0.150600 -0.145400 -0.696000 -0.704000 0.104000 +0.900000 -0.150600 -0.145400 -0.696000 -0.704000 0.104000 +0.950000 -0.150600 0.094900 -0.648000 -0.696000 0.272000 +0.950000 -0.150600 0.094900 -0.648000 -0.696000 0.272000 +0.950000 -0.158100 0.060900 -0.608000 -0.760000 0.200000 +0.942000 -0.150600 0.060900 -0.704000 -0.672000 0.200000 +0.950000 -0.168100 0.000000 -0.640000 -0.744000 0.184000 +0.931300 -0.150600 0.000000 -0.640000 -0.744000 0.144000 +0.950000 -0.183700 -0.060900 -0.632000 -0.728000 0.232000 +0.917800 -0.150600 -0.060900 -0.640000 -0.736000 0.184000 +0.950000 -0.200400 -0.121900 -0.720000 -0.672000 0.136000 +0.902600 -0.150600 -0.121900 -0.664000 -0.736000 0.096000 +0.902600 -0.150600 -0.121900 -0.664000 -0.736000 0.096000 +1.000000 0.053600 0.121900 0.280000 0.872000 0.392000 +1.000000 0.053600 0.121900 0.280000 0.872000 0.392000 +0.950000 0.069700 0.121900 0.360000 0.840000 0.384000 +1.000000 0.068400 0.060900 0.464000 0.872000 0.104000 +0.950000 0.091300 0.060900 0.600000 0.776000 0.176000 +0.950000 0.091300 0.060900 0.600000 0.776000 0.176000 +-1.000000 -0.090800 0.060900 -0.320000 -0.912000 0.248000 +-1.000000 -0.090800 0.060900 -0.320000 -0.912000 0.248000 +-0.973400 -0.100400 0.060900 -0.344000 -0.904000 0.240000 +-1.000000 -0.100400 0.014600 -0.304000 -0.920000 0.208000 +-1.000000 -0.100400 0.014600 -0.304000 -0.920000 0.208000 +-0.950000 0.258900 0.000000 0.296000 0.848000 0.432000 +-0.950000 0.258900 0.000000 0.296000 0.848000 0.432000 +-0.928700 0.251000 0.000000 0.312000 0.848000 0.408000 +-0.950000 0.251000 0.016800 0.288000 0.808000 0.504000 +-0.950000 0.251000 0.016800 0.288000 0.808000 0.504000 +-0.900000 -0.149700 0.060900 -0.696000 -0.664000 0.232000 +-0.900000 -0.149700 0.060900 -0.696000 -0.664000 0.232000 +-0.899200 -0.150600 0.060900 -0.816000 -0.504000 0.256000 +-0.900000 -0.150600 0.057700 -0.744000 -0.616000 0.232000 +-0.900000 -0.150600 0.057700 -0.744000 -0.616000 0.232000 +-0.750000 0.106000 0.060900 0.496000 0.464000 0.728000 +-0.750000 0.106000 0.060900 0.496000 0.464000 0.728000 +-0.796300 0.150600 0.060900 0.512000 0.584000 0.616000 +-0.750000 0.150600 0.014500 0.472000 0.624000 0.608000 +-0.750000 0.150600 0.014500 0.472000 0.624000 0.608000 +-0.750800 -0.401700 0.000000 -0.816000 -0.520000 0.208000 +-0.750800 -0.401700 0.000000 -0.816000 -0.520000 0.208000 +-0.750000 -0.401700 0.004100 -0.816000 -0.520000 0.232000 +-0.750000 -0.403200 0.000000 -0.832000 -0.504000 0.216000 +-0.750000 -0.403200 0.000000 -0.832000 -0.504000 0.216000 +-0.700000 0.051600 0.060900 0.528000 0.416000 0.728000 +-0.700000 0.051600 0.060900 0.528000 0.416000 0.728000 +-0.744800 0.100400 0.060900 0.496000 0.456000 0.728000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.700000 0.121800 0.000000 0.536000 0.544000 0.632000 +-0.700000 0.121800 0.000000 0.536000 0.544000 0.632000 +-0.680200 0.100400 0.000000 0.600000 0.440000 0.656000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.700000 0.100400 0.019100 0.504000 0.504000 0.688000 +-0.650000 -0.023500 0.060900 0.576000 0.360000 0.720000 +-0.650000 -0.023500 0.060900 0.576000 0.360000 0.720000 +-0.666100 0.000000 0.060900 0.560000 0.376000 0.728000 +-0.650000 0.000000 0.045200 0.576000 0.400000 0.704000 +-0.650000 0.000000 0.045200 0.576000 0.400000 0.704000 +-0.650000 0.063100 0.000000 0.592000 0.392000 0.696000 +-0.650000 0.063100 0.000000 0.592000 0.392000 0.696000 +-0.641800 0.050200 0.000000 0.616000 0.400000 0.664000 +-0.650000 0.050200 0.008200 0.568000 0.384000 0.720000 +-0.650000 0.050200 0.008200 0.568000 0.384000 0.720000 +-0.650000 -0.495900 0.060900 -0.528000 -0.720000 0.432000 +-0.650000 -0.495900 0.060900 -0.528000 -0.720000 0.432000 +-0.640700 -0.502100 0.060900 -0.496000 -0.728000 0.456000 +-0.650000 -0.502100 0.048300 -0.536000 -0.712000 0.440000 +-0.650000 -0.502100 0.048300 -0.536000 -0.712000 0.440000 +-0.633400 -0.552300 0.000000 -0.384000 -0.672000 0.624000 +-0.633400 -0.552300 0.000000 -0.384000 -0.672000 0.624000 +-0.600000 -0.552300 0.023900 -0.224000 -0.776000 0.584000 +-0.600000 -0.566300 0.000000 -0.184000 -0.816000 0.544000 +-0.550000 -0.552300 0.031000 0.256000 -0.800000 0.528000 +-0.550000 -0.565800 0.000000 0.224000 -0.872000 0.424000 +-0.509600 -0.552300 0.000000 0.320000 -0.840000 0.424000 +-0.509600 -0.552300 0.000000 0.320000 -0.840000 0.424000 +-0.600000 -0.018300 0.000000 0.712000 0.368000 0.584000 +-0.600000 -0.018300 0.000000 0.712000 0.368000 0.584000 +-0.584800 -0.050200 0.000000 0.744000 0.336000 0.568000 +-0.600000 -0.050200 0.018400 0.648000 0.320000 0.688000 +-0.600000 -0.050200 0.018400 0.648000 0.320000 0.688000 +-0.472400 -0.150600 0.060900 -0.464000 0.768000 0.416000 +-0.472400 -0.150600 0.060900 -0.464000 0.768000 0.416000 +-0.500000 -0.166600 0.060900 -0.304000 0.832000 0.448000 +-0.500000 -0.150600 0.019400 -0.216000 0.856000 0.464000 +-0.500000 -0.150600 0.019400 -0.216000 0.856000 0.464000 +-0.434300 -0.100400 0.000000 -0.648000 0.720000 0.208000 +-0.434300 -0.100400 0.000000 -0.648000 0.720000 0.208000 +-0.405500 -0.100400 0.060900 -0.712000 0.456000 0.520000 +-0.400000 -0.050900 0.000000 -0.776000 0.576000 0.224000 +-0.400000 -0.090100 0.060900 -0.696000 0.400000 0.584000 +-0.399300 -0.050200 0.000000 -0.696000 0.680000 0.184000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.367400 -0.050200 0.060900 -0.696000 0.408000 0.584000 +-0.355100 0.050200 0.000000 -0.872000 0.216000 0.416000 +-0.355100 0.050200 0.000000 -0.872000 0.216000 0.416000 +-0.350000 0.077100 0.000000 -0.776000 0.256000 0.568000 +-0.350000 0.050200 0.010900 -0.568000 0.448000 0.680000 +-0.321000 0.100400 0.000000 -0.264000 0.416000 0.864000 +-0.300000 0.050200 0.038600 -0.224000 0.544000 0.800000 +-0.300000 0.100400 0.006400 -0.200000 0.408000 0.880000 +-0.250000 0.050200 0.048300 0.000000 0.552000 0.832000 +-0.250000 0.100400 0.002600 0.144000 0.496000 0.848000 +-0.250000 0.100400 0.002600 0.144000 0.496000 0.848000 +-0.350000 0.000000 0.059800 -0.688000 0.400000 0.592000 +-0.350000 0.000000 0.059800 -0.688000 0.400000 0.592000 +-0.350000 0.050200 0.010900 -0.568000 0.448000 0.680000 +-0.373100 0.000000 0.000000 -0.880000 0.240000 0.392000 +-0.355100 0.050200 0.000000 -0.872000 0.216000 0.416000 +-0.377800 0.000000 -0.060900 -0.864000 0.424000 -0.248000 +-0.358600 0.050200 -0.060900 -0.920000 0.168000 -0.328000 +-0.372200 0.000000 -0.121900 -0.848000 0.480000 -0.200000 +-0.350000 0.050200 -0.078800 -0.832000 0.272000 -0.472000 +-0.350000 0.031200 -0.121900 -0.744000 0.552000 -0.352000 +-0.335400 0.050200 -0.121900 -0.752000 0.472000 -0.456000 +-0.350000 0.000000 -0.171400 -0.688000 0.416000 -0.584000 +-0.301000 0.050200 -0.182900 -0.704000 0.472000 -0.512000 +-0.340600 0.000000 -0.182900 -0.696000 0.480000 -0.520000 +-0.350000 0.000000 -0.171400 -0.688000 0.416000 -0.584000 +-0.350000 -0.016600 -0.182900 -0.688000 0.360000 -0.616000 +-0.372200 0.000000 -0.121900 -0.848000 0.480000 -0.200000 +-0.365500 -0.050200 -0.182900 -0.728000 0.384000 -0.560000 +-0.399400 -0.050200 -0.121900 -0.760000 0.504000 -0.392000 +-0.400000 -0.096400 -0.182900 -0.664000 0.552000 -0.496000 +-0.400000 -0.050900 -0.121900 -0.736000 0.536000 -0.408000 +-0.403600 -0.100400 -0.182900 -0.616000 0.592000 -0.512000 +-0.434900 -0.100400 -0.121900 -0.608000 0.744000 -0.256000 +-0.434900 -0.100400 -0.121900 -0.608000 0.744000 -0.256000 +-0.350000 0.000000 0.059800 -0.688000 0.400000 0.592000 +-0.350000 0.000000 0.059800 -0.688000 0.400000 0.592000 +-0.350000 0.050200 0.010900 -0.568000 0.448000 0.680000 +-0.348200 0.000000 0.060900 -0.376000 0.448000 0.800000 +-0.300000 0.050200 0.038600 -0.224000 0.544000 0.800000 +-0.300000 0.027200 0.060900 -0.160000 0.552000 0.808000 +-0.250000 0.050200 0.048300 0.000000 0.552000 0.832000 +-0.250000 0.033500 0.060900 0.056000 0.528000 0.840000 +-0.200000 0.050200 0.037800 0.512000 0.448000 0.720000 +-0.200000 0.020500 0.060900 0.664000 0.440000 0.600000 +-0.200000 0.020500 0.060900 0.664000 0.440000 0.600000 +-0.208400 0.401700 0.000000 -0.424000 0.248000 0.864000 +-0.208400 0.401700 0.000000 -0.424000 0.248000 0.864000 +-0.200000 0.408700 0.000000 -0.112000 0.496000 0.856000 +-0.200000 0.401700 0.005100 -0.168000 0.288000 0.936000 +-0.185900 0.401700 0.000000 0.264000 0.248000 0.928000 +-0.200000 0.384800 0.000000 -0.112000 -0.232000 0.960000 +-0.150000 0.401700 -0.011900 0.240000 0.256000 0.928000 +-0.200000 0.351500 -0.009600 0.208000 -0.208000 0.952000 +-0.150000 0.351500 -0.029900 0.096000 -0.168000 0.976000 +-0.200000 0.301200 -0.022600 0.056000 -0.176000 0.976000 +-0.150000 0.301200 -0.033800 0.040000 -0.024000 0.992000 +-0.200000 0.251000 -0.048300 -0.120000 -0.296000 0.944000 +-0.150000 0.251000 -0.027500 -0.136000 -0.104000 0.984000 +-0.200000 0.206100 -0.060900 -0.448000 -0.184000 0.872000 +-0.150000 0.200800 -0.027500 -0.320000 -0.168000 0.928000 +-0.198000 0.200800 -0.060900 -0.464000 0.288000 0.832000 +-0.150000 0.150600 -0.037800 0.256000 -0.016000 0.960000 +-0.200000 0.199100 -0.060900 -0.320000 0.504000 0.792000 +-0.200000 0.150600 -0.023100 -0.360000 0.472000 0.792000 +-0.250000 0.177000 -0.060900 -0.096000 0.568000 0.808000 +-0.250000 0.150600 -0.042200 0.008000 0.568000 0.816000 +-0.277600 0.200800 -0.060900 0.584000 -0.072000 0.800000 +-0.300000 0.150600 -0.036000 -0.360000 0.064000 0.920000 +-0.300000 0.200800 -0.040500 0.440000 0.208000 0.864000 +-0.346000 0.150600 -0.060900 -0.768000 -0.144000 0.616000 +-0.350000 0.200800 -0.003200 -0.528000 -0.104000 0.832000 +-0.350000 0.153200 -0.060900 -0.608000 -0.784000 0.016000 +-0.368900 0.200800 -0.060900 -0.952000 0.040000 -0.280000 +-0.350000 0.200800 -0.076700 -0.368000 -0.104000 -0.920000 +-0.356100 0.251000 -0.060900 -0.936000 0.104000 -0.312000 +-0.350000 0.251000 -0.067500 -0.624000 0.048000 -0.768000 +-0.353500 0.301200 -0.060900 -0.872000 0.080000 -0.464000 +-0.350000 0.301200 -0.064600 -0.624000 0.064000 -0.768000 +-0.350000 0.329400 -0.060900 -0.960000 0.152000 -0.224000 +-0.300000 0.301200 -0.089300 -0.344000 0.056000 -0.936000 +-0.344500 0.351500 -0.060900 -0.776000 0.288000 0.552000 +-0.300000 0.351500 -0.083400 -0.432000 0.176000 -0.880000 +-0.307400 0.401700 -0.060900 -0.696000 0.688000 -0.152000 +-0.300000 0.401700 -0.066400 -0.448000 0.440000 -0.768000 +-0.300000 0.408800 -0.060900 -0.664000 0.712000 -0.184000 +-0.250000 0.401700 -0.091800 -0.416000 0.456000 -0.776000 +-0.250000 0.447500 -0.060900 -0.512000 0.744000 0.408000 +-0.208300 0.401700 -0.121900 -0.432000 0.432000 -0.784000 +-0.242600 0.451900 -0.060900 -0.440000 0.728000 0.512000 +-0.200000 0.409200 -0.121900 -0.400000 0.464000 -0.776000 +-0.200000 0.451900 -0.081300 -0.400000 0.504000 -0.752000 +-0.152100 0.451900 -0.121900 -0.424000 0.536000 -0.720000 +-0.200000 0.477600 -0.060900 -0.544000 0.808000 -0.208000 +-0.150000 0.453400 -0.121900 -0.320000 0.624000 -0.704000 +-0.150000 0.501300 -0.060900 -0.376000 0.880000 -0.280000 +-0.100000 0.479800 -0.121900 -0.288000 0.584000 -0.752000 +-0.146800 0.502100 -0.060900 -0.272000 0.960000 0.016000 +-0.100000 0.502100 -0.081300 -0.184000 0.840000 -0.488000 +-0.100000 0.517800 -0.060900 -0.120000 0.976000 0.136000 +-0.050000 0.502100 -0.117100 -0.040000 0.912000 -0.392000 +-0.050000 0.515300 -0.060900 0.432000 0.792000 0.408000 +-0.033200 0.502100 -0.060900 0.616000 0.496000 0.600000 +-0.050000 0.502100 -0.046900 0.400000 0.496000 0.760000 +-0.023600 0.451900 -0.060900 0.376000 0.152000 0.904000 +-0.050000 0.451900 -0.049700 0.432000 0.024000 0.896000 +-0.005200 0.401700 -0.060900 0.264000 0.168000 0.944000 +-0.050000 0.401700 -0.052300 0.176000 0.040000 0.976000 +0.000000 0.393800 -0.060900 0.224000 0.176000 0.952000 +-0.050000 0.351500 -0.043600 0.248000 0.032000 0.960000 +0.000000 0.351500 -0.051600 0.280000 -0.248000 0.920000 +-0.050000 0.301200 -0.044600 0.440000 -0.008000 0.896000 +0.000000 0.334500 -0.060900 0.312000 -0.368000 0.864000 +-0.027600 0.301200 -0.060900 0.456000 -0.208000 0.856000 +0.000000 0.301200 -0.076500 0.296000 -0.272000 0.904000 +-0.035000 0.251000 -0.060900 0.512000 -0.448000 0.728000 +0.000000 0.251000 -0.086600 0.344000 -0.360000 0.864000 +-0.050000 0.236000 -0.060900 0.536000 -0.496000 0.672000 +0.000000 0.211400 -0.121900 0.496000 -0.712000 0.480000 +-0.050000 0.200800 -0.090500 0.520000 -0.520000 0.672000 +-0.012800 0.200800 -0.121900 0.688000 -0.616000 0.376000 +-0.050000 0.170300 -0.121900 0.584000 -0.576000 0.560000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +0.000000 0.195100 -0.182900 0.504000 -0.656000 -0.544000 +-0.033200 0.150600 -0.182900 0.832000 -0.552000 -0.016000 +0.000000 0.200800 -0.186400 0.272000 -0.456000 -0.840000 +-0.050000 0.150600 -0.210200 0.840000 -0.208000 -0.496000 +-0.050000 0.200800 -0.204500 0.304000 -0.328000 -0.888000 +-0.077600 0.150600 -0.243900 0.320000 0.328000 -0.880000 +-0.100000 0.200800 -0.221500 0.056000 0.392000 -0.912000 +-0.100000 0.164100 -0.243900 -0.032000 0.432000 -0.896000 +-0.150000 0.200800 -0.199200 -0.328000 0.272000 -0.896000 +-0.126800 0.150600 -0.243900 -0.208000 0.496000 -0.832000 +-0.150000 0.150600 -0.235500 -0.296000 0.536000 -0.784000 +-0.150000 0.141700 -0.243900 -0.352000 0.528000 -0.768000 +-0.200000 0.150600 -0.197300 -0.488000 0.464000 -0.728000 +-0.198500 0.100400 -0.243900 -0.376000 0.480000 -0.784000 +-0.200000 0.100400 -0.242800 -0.520000 0.512000 -0.672000 +-0.200000 0.099300 -0.243900 -0.456000 0.488000 -0.736000 +-0.249100 0.100400 -0.182900 -0.576000 0.496000 -0.640000 +-0.250000 0.055800 -0.243900 -0.560000 0.648000 -0.504000 +-0.250000 0.099600 -0.182900 -0.488000 0.616000 -0.608000 +-0.256300 0.050200 -0.243900 -0.592000 0.624000 -0.488000 +-0.300000 0.052000 -0.182900 -0.664000 0.464000 -0.568000 +-0.300000 0.050200 -0.185100 -0.648000 0.560000 -0.504000 +-0.256300 0.050200 -0.243900 -0.592000 0.624000 -0.488000 +-0.300000 0.001800 -0.243900 -0.496000 0.680000 -0.520000 +-0.250000 0.050200 -0.254100 -0.584000 0.656000 -0.464000 +-0.300000 0.000000 -0.248500 -0.656000 0.560000 -0.488000 +-0.250000 0.000000 -0.286200 -0.320000 0.712000 -0.616000 +-0.300000 -0.050200 -0.270300 -0.824000 0.232000 -0.512000 +-0.250000 -0.028200 -0.304800 -0.400000 0.416000 -0.808000 +-0.266700 -0.050200 -0.304800 -0.504000 0.288000 -0.808000 +-0.250000 -0.050200 -0.318700 -0.440000 0.320000 -0.832000 +-0.288100 -0.100400 -0.304800 -0.408000 0.240000 -0.872000 +-0.250000 -0.100400 -0.327300 -0.384000 0.152000 -0.904000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.250000 -0.150600 -0.327500 -0.120000 0.152000 -0.976000 +-0.300000 -0.150600 -0.319300 -0.256000 0.480000 -0.832000 +-0.250000 -0.200800 -0.333200 0.168000 0.080000 -0.976000 +-0.300000 -0.200800 -0.340600 0.016000 0.280000 -0.952000 +-0.250000 -0.251000 -0.337900 0.384000 0.112000 -0.912000 +-0.300000 -0.251000 -0.348000 0.192000 0.248000 -0.944000 +-0.250000 -0.301200 -0.349000 0.296000 0.272000 -0.912000 +-0.300000 -0.296900 -0.365800 0.296000 0.528000 -0.784000 +-0.291400 -0.301200 -0.365800 0.272000 0.504000 -0.808000 +-0.300000 -0.301200 -0.369600 0.320000 0.544000 -0.768000 +-0.250000 -0.342900 -0.365800 0.504000 0.512000 -0.680000 +-0.300000 -0.341100 -0.426800 -0.128000 0.536000 -0.832000 +-0.250000 -0.351500 -0.379700 0.552000 0.712000 -0.416000 +-0.273100 -0.351500 -0.426800 0.480000 0.752000 -0.440000 +-0.250000 -0.368100 -0.426800 0.504000 0.792000 -0.336000 +-0.250000 -0.351500 -0.379700 0.552000 0.712000 -0.416000 +-0.200000 -0.393200 -0.426800 0.696000 0.632000 -0.328000 +-0.241400 -0.351500 -0.365800 0.488000 0.640000 -0.576000 +-0.200000 -0.365300 -0.365800 0.504000 0.768000 -0.376000 +-0.200000 -0.351500 -0.343300 0.312000 0.640000 -0.696000 +-0.241400 -0.351500 -0.365800 0.488000 0.640000 -0.576000 +-0.200000 -0.301200 -0.313400 0.328000 0.152000 -0.928000 +-0.250000 -0.342900 -0.365800 0.504000 0.512000 -0.680000 +-0.250000 -0.301200 -0.349000 0.296000 0.272000 -0.912000 +-0.291400 -0.301200 -0.365800 0.272000 0.504000 -0.808000 +-0.291400 -0.301200 -0.365800 0.272000 0.504000 -0.808000 +-0.200000 0.401700 0.005100 -0.168000 0.288000 0.936000 +-0.200000 0.401700 0.005100 -0.168000 0.288000 0.936000 +-0.200000 0.384800 0.000000 -0.112000 -0.232000 0.960000 +-0.208400 0.401700 0.000000 -0.424000 0.248000 0.864000 +-0.200000 0.351500 -0.009600 0.208000 -0.208000 0.952000 +-0.250000 0.401700 -0.023000 -0.400000 -0.016000 0.912000 +-0.250000 0.351500 -0.004200 0.040000 0.000000 0.992000 +-0.300000 0.401700 -0.053800 -0.512000 0.520000 0.672000 +-0.300000 0.351500 -0.024700 -0.384000 0.216000 0.896000 +-0.307400 0.401700 -0.060900 -0.696000 0.688000 -0.152000 +-0.344500 0.351500 -0.060900 -0.776000 0.288000 0.552000 +-0.300000 0.351500 -0.024700 -0.384000 0.216000 0.896000 +-0.350000 0.329400 -0.060900 -0.960000 0.152000 -0.224000 +-0.300000 0.301200 -0.020200 -0.184000 0.032000 0.976000 +-0.350000 0.301200 -0.051600 -0.832000 0.120000 0.528000 +-0.300000 0.251000 -0.020200 0.208000 -0.160000 0.960000 +-0.350000 0.251000 -0.040500 -0.808000 0.200000 0.544000 +-0.300000 0.200800 -0.040500 0.440000 0.208000 0.864000 +-0.350000 0.200800 -0.003200 -0.528000 -0.104000 0.832000 +-0.350000 0.251000 -0.040500 -0.808000 0.200000 0.544000 +-0.368900 0.200800 -0.060900 -0.952000 0.040000 -0.280000 +-0.356100 0.251000 -0.060900 -0.936000 0.104000 -0.312000 +-0.350000 0.251000 -0.040500 -0.808000 0.200000 0.544000 +-0.353500 0.301200 -0.060900 -0.872000 0.080000 -0.464000 +-0.350000 0.301200 -0.051600 -0.832000 0.120000 0.528000 +-0.350000 0.329400 -0.060900 -0.960000 0.152000 -0.224000 +-0.350000 0.329400 -0.060900 -0.960000 0.152000 -0.224000 +-0.250000 -0.301200 0.006000 0.344000 -0.608000 0.704000 +-0.250000 -0.301200 0.006000 0.344000 -0.608000 0.704000 +-0.235900 -0.301200 0.000000 0.272000 -0.568000 0.768000 +-0.250000 -0.307700 0.000000 0.288000 -0.576000 0.760000 +-0.250000 -0.307700 0.000000 0.288000 -0.576000 0.760000 +-0.169100 -0.301200 0.000000 -0.376000 -0.392000 0.832000 +-0.169100 -0.301200 0.000000 -0.376000 -0.392000 0.832000 +-0.150000 -0.301200 0.010200 -0.304000 -0.280000 0.904000 +-0.150000 -0.346200 0.000000 -0.392000 -0.160000 0.904000 +-0.100000 -0.301200 0.037800 -0.016000 -0.152000 0.984000 +-0.100000 -0.344900 0.000000 0.072000 -0.528000 0.840000 +-0.050000 -0.301200 0.029100 0.312000 -0.280000 0.904000 +-0.050000 -0.329200 0.000000 0.264000 -0.624000 0.720000 +-0.002200 -0.301200 0.000000 0.384000 -0.648000 0.648000 +-0.050000 -0.351500 -0.027000 0.488000 -0.688000 0.528000 +0.000000 -0.301200 -0.001900 0.408000 -0.704000 0.568000 +-0.029100 -0.351500 -0.060900 0.584000 -0.680000 0.424000 +0.000000 -0.326800 -0.060900 0.344000 -0.824000 0.432000 +0.000000 -0.351500 -0.112600 0.544000 -0.704000 0.448000 +0.032200 -0.301200 -0.060900 0.552000 -0.696000 0.448000 +0.006400 -0.351500 -0.121900 0.552000 -0.776000 0.288000 +0.050000 -0.301200 -0.085900 0.528000 -0.704000 0.464000 +0.050000 -0.321600 -0.121900 0.584000 -0.712000 0.376000 +0.074000 -0.301200 -0.121900 0.536000 -0.792000 0.264000 +0.050000 -0.327900 -0.182900 0.552000 -0.824000 0.048000 +0.088900 -0.301200 -0.182900 0.488000 -0.864000 0.072000 +0.050000 -0.327900 -0.243900 0.480000 -0.872000 0.000000 +0.091700 -0.301200 -0.243900 0.488000 -0.864000 -0.008000 +0.050000 -0.326800 -0.304800 0.424000 -0.880000 -0.184000 +0.085600 -0.301200 -0.304800 0.544000 -0.768000 -0.320000 +0.050000 -0.303000 -0.365800 0.400000 -0.792000 -0.448000 +0.052200 -0.301200 -0.365800 0.552000 -0.720000 -0.416000 +0.050000 -0.301200 -0.369000 0.376000 -0.768000 -0.512000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +0.050000 -0.251000 -0.406500 0.232000 -0.312000 -0.912000 +0.100000 -0.251000 -0.380100 0.472000 -0.384000 -0.784000 +0.050000 -0.206300 -0.365800 -0.112000 0.608000 -0.776000 +0.100000 -0.224900 -0.365800 0.352000 0.456000 -0.808000 +0.050000 -0.200800 -0.360800 -0.016000 0.576000 -0.808000 +0.100000 -0.200800 -0.352600 0.240000 0.528000 -0.800000 +0.100000 -0.224900 -0.365800 0.352000 0.456000 -0.808000 +0.150000 -0.200800 -0.325200 0.160000 0.176000 -0.968000 +0.118000 -0.251000 -0.365800 0.536000 -0.224000 -0.808000 +0.150000 -0.251000 -0.336000 0.080000 -0.336000 -0.928000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +0.150000 -0.287400 -0.304800 0.000000 -0.712000 -0.688000 +0.100000 -0.292600 -0.304800 0.432000 -0.840000 -0.304000 +0.150000 -0.287700 -0.243900 -0.208000 -0.968000 0.064000 +0.100000 -0.296900 -0.243900 0.408000 -0.912000 0.000000 +0.150000 -0.278000 -0.182900 -0.064000 -0.936000 0.328000 +0.100000 -0.295100 -0.182900 0.440000 -0.880000 0.144000 +0.150000 -0.253200 -0.121900 0.192000 -0.808000 0.552000 +0.100000 -0.284500 -0.121900 0.464000 -0.744000 0.472000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +0.100000 -0.256900 -0.060900 0.456000 -0.800000 0.368000 +0.110300 -0.251000 -0.060900 0.504000 -0.760000 0.392000 +0.100000 -0.251000 -0.044600 0.544000 -0.608000 0.568000 +0.130700 -0.200800 -0.060900 0.504000 0.008000 0.856000 +0.100000 -0.200800 -0.044900 0.416000 0.232000 0.872000 +0.100000 -0.170000 -0.060900 0.256000 0.296000 0.912000 +0.050000 -0.200800 -0.016400 0.232000 0.648000 0.720000 +0.076800 -0.150600 -0.060900 0.208000 0.432000 0.872000 +0.050000 -0.150600 -0.053500 0.160000 0.448000 0.872000 +0.050000 -0.140200 -0.060900 0.152000 0.504000 0.848000 +0.000000 -0.150600 -0.047300 0.168000 0.600000 0.768000 +0.000000 -0.136800 -0.060900 0.088000 0.520000 0.840000 +-0.050000 -0.150600 -0.033100 0.152000 0.512000 0.840000 +-0.050000 -0.119400 -0.060900 0.168000 0.528000 0.824000 +-0.100000 -0.150600 -0.019000 0.512000 0.456000 0.720000 +-0.100000 -0.105500 -0.060900 0.480000 0.464000 0.736000 +-0.129500 -0.150600 0.000000 0.416000 0.264000 0.864000 +-0.104300 -0.100400 -0.060900 0.528000 0.416000 0.728000 +-0.150000 -0.104300 0.000000 0.496000 0.120000 0.848000 +-0.150000 -0.100400 -0.001300 0.848000 0.032000 0.520000 +-0.150600 -0.100400 0.000000 0.800000 0.040000 0.592000 +-0.150000 -0.050200 -0.005700 0.768000 -0.024000 0.632000 +-0.152800 -0.050200 0.000000 0.848000 0.032000 0.520000 +-0.150000 0.000000 -0.001200 0.744000 0.064000 0.656000 +-0.150800 0.000000 0.000000 0.744000 0.072000 0.656000 +-0.150000 0.050200 -0.012600 0.624000 0.240000 0.728000 +-0.163800 0.050200 0.000000 0.704000 0.216000 0.664000 +-0.150000 0.100400 -0.027500 0.432000 0.296000 0.848000 +-0.200000 0.089800 0.000000 0.216000 0.544000 0.800000 +-0.200000 0.100400 -0.008800 0.176000 0.488000 0.848000 +-0.238500 0.100400 0.000000 0.152000 0.496000 0.848000 +-0.200000 0.150600 -0.023100 -0.360000 0.472000 0.792000 +-0.250000 0.104200 0.000000 0.144000 0.480000 0.856000 +-0.250000 0.150600 -0.042200 0.008000 0.568000 0.816000 +-0.300000 0.112500 0.000000 -0.064000 0.472000 0.872000 +-0.300000 0.150600 -0.036000 -0.360000 0.064000 0.920000 +-0.300000 0.150600 -0.036000 -0.360000 0.064000 0.920000 +-0.150000 -0.104300 0.000000 0.496000 0.120000 0.848000 +-0.150000 -0.104300 0.000000 0.496000 0.120000 0.848000 +-0.129500 -0.150600 0.000000 0.416000 0.264000 0.864000 +-0.150000 -0.150600 0.010200 0.376000 0.208000 0.896000 +-0.100000 -0.188700 0.000000 0.176000 0.408000 0.888000 +-0.150000 -0.200800 0.013600 0.104000 0.200000 0.968000 +-0.100000 -0.200800 0.005100 0.056000 0.344000 0.936000 +-0.150000 -0.251000 0.002400 -0.056000 -0.176000 0.976000 +-0.100000 -0.251000 0.029400 -0.128000 0.120000 0.976000 +-0.150000 -0.301200 0.010200 -0.304000 -0.280000 0.904000 +-0.100000 -0.301200 0.037800 -0.016000 -0.152000 0.984000 +-0.100000 -0.251000 0.029400 -0.128000 0.120000 0.976000 +-0.050000 -0.301200 0.029100 0.312000 -0.280000 0.904000 +-0.050000 -0.251000 0.040700 0.136000 0.064000 0.984000 +-0.002200 -0.301200 0.000000 0.384000 -0.648000 0.648000 +0.000000 -0.251000 0.031300 0.424000 -0.232000 0.872000 +0.000000 -0.299000 0.000000 0.440000 -0.464000 0.760000 +0.050000 -0.251000 0.003400 0.512000 0.320000 0.792000 +0.050000 -0.253500 0.000000 0.448000 -0.608000 0.648000 +0.054200 -0.251000 0.000000 0.552000 0.192000 0.800000 +0.050000 -0.286400 -0.060900 0.528000 -0.720000 0.440000 +0.100000 -0.251000 -0.044600 0.544000 -0.608000 0.568000 +0.100000 -0.256900 -0.060900 0.456000 -0.800000 0.368000 +0.050000 -0.286400 -0.060900 0.528000 -0.720000 0.440000 +0.100000 -0.284500 -0.121900 0.464000 -0.744000 0.472000 +0.050000 -0.301200 -0.085900 0.528000 -0.704000 0.464000 +0.074000 -0.301200 -0.121900 0.536000 -0.792000 0.264000 +0.100000 -0.284500 -0.121900 0.464000 -0.744000 0.472000 +0.088900 -0.301200 -0.182900 0.488000 -0.864000 0.072000 +0.100000 -0.295100 -0.182900 0.440000 -0.880000 0.144000 +0.091700 -0.301200 -0.243900 0.488000 -0.864000 -0.008000 +0.100000 -0.296900 -0.243900 0.408000 -0.912000 0.000000 +0.085600 -0.301200 -0.304800 0.544000 -0.768000 -0.320000 +0.100000 -0.292600 -0.304800 0.432000 -0.840000 -0.304000 +0.052200 -0.301200 -0.365800 0.552000 -0.720000 -0.416000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +-0.100000 -0.200800 0.005100 0.056000 0.344000 0.936000 +-0.100000 -0.200800 0.005100 0.056000 0.344000 0.936000 +-0.050000 -0.200800 0.008600 0.032000 0.536000 0.840000 +-0.100000 -0.188700 0.000000 0.176000 0.408000 0.888000 +-0.050000 -0.190400 0.000000 0.096000 0.648000 0.744000 +-0.100000 -0.150600 -0.019000 0.512000 0.456000 0.720000 +-0.050000 -0.150600 -0.033100 0.152000 0.512000 0.840000 +-0.050000 -0.190400 0.000000 0.096000 0.648000 0.744000 +0.000000 -0.150600 -0.047300 0.168000 0.600000 0.768000 +0.000000 -0.198800 0.000000 0.160000 0.688000 0.704000 +0.050000 -0.150600 -0.053500 0.160000 0.448000 0.872000 +0.006800 -0.200800 0.000000 0.232000 0.576000 0.776000 +0.050000 -0.200800 -0.016400 0.232000 0.648000 0.720000 +0.050000 -0.244100 0.000000 0.488000 0.320000 0.800000 +0.100000 -0.200800 -0.044900 0.416000 0.232000 0.872000 +0.054200 -0.251000 0.000000 0.552000 0.192000 0.800000 +0.100000 -0.251000 -0.044600 0.544000 -0.608000 0.568000 +0.100000 -0.251000 -0.044600 0.544000 -0.608000 0.568000 +-0.100000 -0.200800 0.005100 0.056000 0.344000 0.936000 +-0.100000 -0.200800 0.005100 0.056000 0.344000 0.936000 +-0.100000 -0.251000 0.029400 -0.128000 0.120000 0.976000 +-0.050000 -0.200800 0.008600 0.032000 0.536000 0.840000 +-0.050000 -0.251000 0.040700 0.136000 0.064000 0.984000 +0.000000 -0.200800 0.002300 0.160000 0.560000 0.808000 +0.000000 -0.251000 0.031300 0.424000 -0.232000 0.872000 +0.006800 -0.200800 0.000000 0.232000 0.576000 0.776000 +0.050000 -0.251000 0.003400 0.512000 0.320000 0.792000 +0.050000 -0.244100 0.000000 0.488000 0.320000 0.800000 +0.054200 -0.251000 0.000000 0.552000 0.192000 0.800000 +0.054200 -0.251000 0.000000 0.552000 0.192000 0.800000 +-0.050000 -0.190400 0.000000 0.096000 0.648000 0.744000 +-0.050000 -0.190400 0.000000 0.096000 0.648000 0.744000 +-0.050000 -0.200800 0.008600 0.032000 0.536000 0.840000 +0.000000 -0.198800 0.000000 0.160000 0.688000 0.704000 +0.000000 -0.200800 0.002300 0.160000 0.560000 0.808000 +0.006800 -0.200800 0.000000 0.232000 0.576000 0.776000 +0.006800 -0.200800 0.000000 0.232000 0.576000 0.776000 +0.500000 0.245700 0.000000 -0.568000 0.120000 0.808000 +0.500000 0.245700 0.000000 -0.568000 0.120000 0.808000 +0.500000 0.200800 0.008600 -0.576000 -0.176000 0.792000 +0.488800 0.200800 0.000000 -0.512000 0.024000 0.856000 +0.500000 0.181600 0.000000 -0.600000 -0.304000 0.728000 +0.500000 0.181600 0.000000 -0.600000 -0.304000 0.728000 +0.550000 0.174700 0.060900 -0.744000 -0.320000 0.576000 +0.550000 0.174700 0.060900 -0.744000 -0.320000 0.576000 +0.560700 0.150600 0.060900 -0.704000 -0.368000 0.592000 +0.550000 0.150600 0.048400 -0.632000 -0.416000 0.640000 +0.550000 0.150600 0.048400 -0.632000 -0.416000 0.640000 +0.641200 0.050200 0.060900 -0.600000 -0.608000 0.512000 +0.641200 0.050200 0.060900 -0.600000 -0.608000 0.512000 +0.600000 0.093600 0.060900 -0.624000 -0.616000 0.464000 +0.602900 0.050200 0.000000 -0.576000 -0.704000 0.400000 +0.600000 0.053300 0.000000 -0.472000 -0.712000 0.512000 +0.600000 0.050200 -0.005300 -0.440000 -0.752000 0.480000 +0.600000 0.050200 -0.005300 -0.440000 -0.752000 0.480000 +-0.915700 -0.150600 0.000000 -0.696000 -0.672000 0.232000 +-0.915700 -0.150600 0.000000 -0.696000 -0.672000 0.232000 +-0.950000 -0.123700 0.000000 -0.488000 -0.840000 0.216000 +-0.932400 -0.150600 -0.060900 -0.688000 -0.696000 0.176000 +-0.950000 -0.136200 -0.060900 -0.528000 -0.832000 0.152000 +-0.943100 -0.150600 -0.121900 -0.672000 -0.720000 0.120000 +-0.950000 -0.144800 -0.121900 -0.536000 -0.832000 0.120000 +-0.950000 -0.150600 -0.169000 -0.584000 -0.792000 0.136000 +-0.943100 -0.150600 -0.121900 -0.672000 -0.720000 0.120000 +-0.950000 -0.152700 -0.182900 -0.600000 -0.784000 0.144000 +-0.903800 -0.200800 -0.121900 -0.696000 -0.704000 0.120000 +-0.907400 -0.200800 -0.182900 -0.688000 -0.712000 0.072000 +-0.950000 -0.152700 -0.182900 -0.600000 -0.784000 0.144000 +-0.914100 -0.200800 -0.243900 -0.664000 -0.728000 0.128000 +-0.950000 -0.161800 -0.243900 -0.584000 -0.784000 0.176000 +-0.931500 -0.200800 -0.304800 -0.648000 -0.520000 -0.544000 +-0.950000 -0.180000 -0.304800 -0.552000 -0.600000 -0.568000 +-0.900000 -0.200800 -0.331500 -0.576000 -0.328000 -0.736000 +-0.950000 -0.150600 -0.330800 -0.416000 -0.432000 -0.792000 +-0.900000 -0.150600 -0.338300 -0.216000 -0.104000 -0.968000 +-0.900000 -0.200800 -0.331500 -0.576000 -0.328000 -0.736000 +-0.850000 -0.150600 -0.349400 0.072000 0.056000 -0.992000 +-0.850000 -0.200800 -0.351200 -0.168000 0.112000 -0.976000 +-0.800000 -0.150600 -0.340500 0.312000 0.288000 -0.896000 +-0.800000 -0.200800 -0.355700 0.080000 0.256000 -0.960000 +-0.750000 -0.150600 -0.317800 0.416000 0.384000 -0.816000 +-0.750000 -0.200800 -0.348300 0.272000 0.384000 -0.872000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.700000 -0.200800 -0.326900 0.208000 0.528000 -0.816000 +-0.700000 -0.175200 -0.304800 0.352000 0.528000 -0.768000 +-0.651700 -0.200800 -0.304800 0.320000 0.544000 -0.768000 +-0.700000 -0.150600 -0.284500 0.376000 0.392000 -0.832000 +-0.650000 -0.200800 -0.303800 0.136000 0.680000 -0.712000 +-0.650000 -0.150600 -0.267500 0.376000 0.464000 -0.792000 +-0.650000 -0.150600 -0.267500 0.376000 0.464000 -0.792000 +-0.895700 -0.200800 -0.060900 -0.864000 -0.480000 0.136000 +-0.895700 -0.200800 -0.060900 -0.864000 -0.480000 0.136000 +-0.882700 -0.200800 0.000000 -0.840000 -0.496000 0.192000 +-0.860100 -0.251000 -0.060900 -0.808000 -0.568000 0.112000 +-0.852600 -0.251000 0.000000 -0.800000 -0.568000 0.168000 +-0.852600 -0.251000 0.000000 -0.800000 -0.568000 0.168000 +-0.700000 -0.502100 -0.057900 -0.752000 -0.512000 0.400000 +-0.700000 -0.502100 -0.057900 -0.752000 -0.512000 0.400000 +-0.700000 -0.507800 -0.060900 -0.864000 -0.200000 0.448000 +-0.701200 -0.502100 -0.060900 -0.816000 -0.416000 0.392000 +-0.700000 -0.552300 -0.082500 -0.736000 -0.280000 0.608000 +-0.723300 -0.502100 -0.121900 -0.896000 -0.224000 0.368000 +-0.750000 -0.552300 -0.119400 0.072000 0.512000 0.848000 +-0.750000 -0.549900 -0.121900 0.080000 0.648000 0.752000 +-0.800000 -0.552300 -0.095900 0.424000 0.264000 0.864000 +-0.800000 -0.539500 -0.121900 0.176000 0.680000 0.704000 +-0.850000 -0.552300 -0.082300 -0.704000 -0.480000 0.504000 +-0.850000 -0.519700 -0.121900 0.200000 0.624000 0.752000 +-0.868200 -0.552300 -0.121900 -0.520000 -0.224000 0.816000 +-0.850000 -0.502100 -0.144600 0.400000 0.776000 0.480000 +-0.900000 -0.511500 -0.121900 -0.520000 -0.664000 0.528000 +-0.878700 -0.502100 -0.121900 0.408000 0.368000 0.832000 +-0.900000 -0.502100 -0.104000 -0.752000 0.000000 0.656000 +-0.900000 -0.492700 -0.121900 -0.520000 0.712000 0.448000 +-0.906100 -0.502100 -0.121900 -0.920000 0.072000 0.376000 +-0.900000 -0.462200 -0.182900 0.320000 0.888000 0.304000 +-0.925200 -0.502100 -0.182900 -0.976000 -0.008000 0.208000 +-0.900000 -0.451900 -0.229200 0.512000 0.832000 0.168000 +-0.929300 -0.502100 -0.243900 -0.992000 0.064000 -0.008000 +-0.921000 -0.451900 -0.243900 -0.184000 0.968000 0.160000 +-0.920600 -0.502100 -0.304800 -0.888000 -0.288000 -0.344000 +-0.912200 -0.451900 -0.304800 -0.496000 0.720000 -0.464000 +-0.900000 -0.502100 -0.352600 -0.672000 0.128000 -0.720000 +-0.900000 -0.451900 -0.318500 0.104000 0.872000 -0.464000 +-0.864000 -0.502100 -0.365800 -0.304000 0.480000 -0.816000 +-0.891000 -0.451900 -0.304800 0.528000 0.824000 -0.192000 +-0.850000 -0.496800 -0.365800 -0.176000 0.616000 -0.760000 +-0.850000 -0.473200 -0.304800 0.272000 0.896000 -0.336000 +-0.800000 -0.496400 -0.365800 -0.664000 0.416000 -0.608000 +-0.800000 -0.473000 -0.304800 -0.736000 0.648000 -0.168000 +-0.786000 -0.451900 -0.365800 -0.872000 0.080000 -0.472000 +-0.787800 -0.451900 -0.304800 -0.984000 0.136000 -0.040000 +-0.796500 -0.401700 -0.365800 -0.952000 -0.168000 -0.232000 +-0.797400 -0.401700 -0.304800 -0.928000 -0.344000 0.056000 +-0.800000 -0.388500 -0.365800 -0.864000 -0.288000 -0.400000 +-0.800000 -0.395700 -0.304800 -0.920000 -0.376000 0.000000 +-0.797400 -0.401700 -0.304800 -0.928000 -0.344000 0.056000 +-0.800000 -0.365300 -0.243900 -0.880000 -0.440000 0.160000 +-0.781800 -0.401700 -0.243900 -0.912000 -0.336000 0.208000 +-0.800000 -0.355500 -0.182900 -0.872000 -0.472000 0.032000 +-0.775200 -0.401700 -0.182900 -0.904000 -0.400000 0.120000 +-0.800000 -0.354700 -0.121900 -0.848000 -0.512000 0.080000 +-0.771000 -0.401700 -0.121900 -0.872000 -0.456000 0.128000 +-0.800000 -0.351500 -0.101400 -0.840000 -0.528000 0.104000 +-0.762700 -0.401700 -0.060900 -0.840000 -0.496000 0.168000 +-0.794800 -0.351500 -0.060900 -0.816000 -0.552000 0.144000 +-0.800000 -0.351500 -0.101400 -0.840000 -0.528000 0.104000 +-0.800000 -0.343900 -0.060900 -0.816000 -0.552000 0.128000 +-0.800000 -0.343900 -0.060900 -0.816000 -0.552000 0.128000 +-0.700000 0.150600 -0.043600 0.552000 0.712000 0.424000 +-0.700000 0.150600 -0.043600 0.552000 0.712000 0.424000 +-0.700000 0.159000 -0.060900 0.600000 0.776000 0.184000 +-0.689800 0.150600 -0.060900 0.640000 0.736000 0.192000 +-0.700000 0.150600 -0.089800 0.592000 0.744000 -0.280000 +-0.650000 0.112000 -0.060900 0.672000 0.704000 0.200000 +-0.700000 0.140000 -0.121900 0.536000 0.728000 -0.408000 +-0.650000 0.100400 -0.098000 0.720000 0.624000 -0.288000 +-0.657700 0.100400 -0.121900 0.728000 0.576000 -0.360000 +-0.650000 0.089500 -0.121900 0.728000 0.552000 -0.384000 +-0.700000 0.100400 -0.182100 0.536000 0.592000 -0.592000 +-0.650000 0.050200 -0.178200 0.664000 0.544000 -0.504000 +-0.700000 0.099700 -0.182900 0.504000 0.560000 -0.640000 +-0.652800 0.050200 -0.182900 0.592000 0.536000 -0.592000 +-0.700000 0.050200 -0.235800 0.504000 0.432000 -0.744000 +-0.650000 0.045800 -0.182900 0.672000 0.432000 -0.592000 +-0.700000 0.037400 -0.243900 0.440000 0.392000 -0.800000 +-0.650000 0.000000 -0.224600 0.632000 0.368000 -0.672000 +-0.669700 0.000000 -0.243900 0.480000 0.312000 -0.808000 +-0.700000 0.037400 -0.243900 0.440000 0.392000 -0.800000 +-0.700000 0.000000 -0.262900 0.392000 0.288000 -0.864000 +-0.700000 0.000000 -0.262900 0.392000 0.288000 -0.864000 +-0.650000 -0.541900 0.000000 -0.528000 -0.600000 0.592000 +-0.650000 -0.541900 0.000000 -0.528000 -0.600000 0.592000 +-0.633400 -0.552300 0.000000 -0.384000 -0.672000 0.624000 +-0.650000 -0.552300 -0.012600 -0.496000 -0.592000 0.624000 +-0.650000 -0.552300 -0.012600 -0.496000 -0.592000 0.624000 +-0.452400 -0.100400 -0.060900 -0.344000 0.936000 -0.016000 +-0.452400 -0.100400 -0.060900 -0.344000 0.936000 -0.016000 +-0.450000 -0.099400 -0.060900 -0.760000 0.616000 0.160000 +-0.450000 -0.100400 -0.057100 -0.400000 0.872000 0.264000 +-0.406900 -0.050200 -0.060900 -0.848000 0.520000 0.000000 +-0.434300 -0.100400 0.000000 -0.648000 0.720000 0.208000 +-0.400000 -0.050200 -0.003200 -0.712000 0.672000 0.168000 +-0.400000 -0.050900 0.000000 -0.776000 0.576000 0.224000 +-0.399300 -0.050200 0.000000 -0.696000 0.680000 0.184000 +-0.399300 -0.050200 0.000000 -0.696000 0.680000 0.184000 +-0.466200 -0.502100 0.000000 0.712000 -0.616000 0.320000 +-0.466200 -0.502100 0.000000 0.712000 -0.616000 0.320000 +-0.450000 -0.489500 0.000000 0.584000 -0.760000 0.264000 +-0.450000 -0.502100 -0.045100 0.560000 -0.696000 0.432000 +-0.403800 -0.451900 0.000000 0.744000 -0.560000 0.352000 +-0.400000 -0.502100 -0.024700 0.848000 -0.224000 0.464000 +-0.400000 -0.451900 -0.009600 0.744000 -0.536000 0.376000 +-0.403800 -0.451900 0.000000 0.744000 -0.560000 0.352000 +-0.400000 -0.447100 0.000000 0.720000 -0.584000 0.344000 +-0.400000 -0.451900 -0.009600 0.744000 -0.536000 0.376000 +-0.350000 -0.427600 0.000000 0.560000 -0.752000 0.336000 +-0.350000 -0.451900 -0.058800 0.248000 -0.624000 0.728000 +-0.350000 -0.451900 -0.058800 0.248000 -0.624000 0.728000 +-0.500000 -0.552300 -0.009400 0.352000 -0.840000 0.400000 +-0.500000 -0.552300 -0.009400 0.352000 -0.840000 0.400000 +-0.478800 -0.552300 -0.060900 0.704000 -0.592000 0.376000 +-0.500000 -0.570000 -0.060900 0.480000 -0.800000 0.328000 +-0.452200 -0.552300 -0.121900 0.864000 0.184000 0.464000 +-0.500000 -0.589900 -0.121900 0.408000 -0.832000 0.352000 +-0.450000 -0.552300 -0.127200 0.616000 -0.144000 0.768000 +-0.500000 -0.602500 -0.155300 0.000000 -0.920000 0.376000 +-0.450000 -0.558900 -0.121900 0.808000 0.320000 0.488000 +-0.474100 -0.602500 -0.121900 -0.520000 -0.712000 0.456000 +-0.450000 -0.602500 -0.084100 -0.232000 -0.736000 0.624000 +-0.450000 -0.612400 -0.121900 0.032000 -0.944000 0.312000 +-0.410500 -0.602500 -0.121900 0.456000 -0.632000 0.616000 +-0.450000 -0.629600 -0.182900 -0.344000 -0.872000 0.320000 +-0.400000 -0.602500 -0.131300 0.560000 -0.576000 0.584000 +-0.400000 -0.651500 -0.182900 -0.552000 -0.472000 0.672000 +-0.386500 -0.602500 -0.182900 0.376000 -0.032000 0.920000 +-0.400000 -0.652700 -0.184800 -0.640000 -0.536000 0.536000 +-0.350000 -0.647900 -0.182900 0.008000 0.768000 0.624000 +-0.396000 -0.652700 -0.182900 -0.176000 0.000000 0.984000 +-0.350000 -0.652700 -0.168800 -0.864000 0.056000 0.488000 +-0.350700 -0.703000 -0.182900 -0.792000 -0.176000 0.576000 +-0.350000 -0.703000 -0.180700 -0.616000 -0.504000 0.592000 +-0.350000 -0.704300 -0.182900 -0.112000 -0.808000 0.576000 +-0.300000 -0.703000 -0.173800 0.616000 -0.544000 0.552000 +-0.300000 -0.708000 -0.182900 0.360000 -0.768000 0.520000 +-0.293800 -0.703000 -0.182900 0.608000 -0.624000 0.488000 +-0.300000 -0.736500 -0.243900 0.320000 -0.832000 0.440000 +-0.256000 -0.703000 -0.243900 0.696000 -0.392000 0.584000 +-0.300000 -0.753200 -0.286100 0.088000 -0.928000 0.352000 +-0.250000 -0.703000 -0.252700 0.704000 -0.368000 0.600000 +-0.281500 -0.753200 -0.304800 0.312000 -0.920000 -0.216000 +-0.250000 -0.737300 -0.304800 0.568000 -0.808000 -0.112000 +-0.300000 -0.753200 -0.317300 0.136000 -0.840000 -0.512000 +-0.250000 -0.703000 -0.346500 0.432000 -0.280000 -0.848000 +-0.300000 -0.703000 -0.365100 0.056000 -0.232000 -0.968000 +-0.250000 -0.652700 -0.361600 0.240000 -0.216000 -0.944000 +-0.300000 -0.687100 -0.365800 0.104000 -0.048000 -0.992000 +-0.282800 -0.652700 -0.365800 0.080000 -0.160000 -0.976000 +-0.300000 -0.652700 -0.367500 0.064000 -0.112000 -0.984000 +-0.300000 -0.687100 -0.365800 0.104000 -0.048000 -0.992000 +-0.350000 -0.652700 -0.376000 0.560000 0.160000 -0.808000 +-0.350000 -0.679200 -0.365800 -0.072000 -0.176000 -0.976000 +-0.400000 -0.652700 -0.368100 -0.128000 -0.872000 -0.456000 +-0.400000 -0.653700 -0.365800 -0.176000 -0.888000 -0.416000 +-0.405700 -0.652700 -0.365800 -0.144000 -0.920000 -0.344000 +-0.400000 -0.672200 -0.304800 -0.400000 -0.904000 -0.128000 +-0.450000 -0.652700 -0.319500 -0.256000 -0.952000 -0.136000 +-0.450000 -0.654300 -0.304800 -0.272000 -0.952000 0.040000 +-0.455200 -0.652700 -0.304800 -0.280000 -0.952000 0.040000 +-0.450000 -0.652700 -0.293400 -0.288000 -0.936000 0.160000 +-0.500000 -0.637800 -0.304800 -0.208000 -0.976000 -0.032000 +-0.450000 -0.644000 -0.243900 -0.352000 -0.912000 0.200000 +-0.500000 -0.625200 -0.243900 -0.096000 -0.960000 0.240000 +-0.450000 -0.629600 -0.182900 -0.344000 -0.872000 0.320000 +-0.500000 -0.610400 -0.182900 -0.136000 -0.936000 0.304000 +-0.450000 -0.612400 -0.121900 0.032000 -0.944000 0.312000 +-0.500000 -0.602500 -0.155300 0.000000 -0.920000 0.376000 +-0.474100 -0.602500 -0.121900 -0.520000 -0.712000 0.456000 +-0.474100 -0.602500 -0.121900 -0.520000 -0.712000 0.456000 +-0.350000 0.148000 -0.060900 -0.504000 0.552000 0.656000 +-0.350000 0.148000 -0.060900 -0.504000 0.552000 0.656000 +-0.350000 0.100400 -0.017600 -0.744000 0.352000 0.552000 +-0.361800 0.100400 -0.060900 -0.920000 0.112000 -0.352000 +-0.350000 0.077100 0.000000 -0.776000 0.256000 0.568000 +-0.358600 0.050200 -0.060900 -0.920000 0.168000 -0.328000 +-0.355100 0.050200 0.000000 -0.872000 0.216000 0.416000 +-0.355100 0.050200 0.000000 -0.872000 0.216000 0.416000 +-0.307400 0.401700 -0.060900 -0.696000 0.688000 -0.152000 +-0.307400 0.401700 -0.060900 -0.696000 0.688000 -0.152000 +-0.300000 0.408800 -0.060900 -0.664000 0.712000 -0.184000 +-0.300000 0.401700 -0.053800 -0.512000 0.520000 0.672000 +-0.250000 0.447500 -0.060900 -0.512000 0.744000 0.408000 +-0.250000 0.401700 -0.023000 -0.400000 -0.016000 0.912000 +-0.242600 0.451900 -0.060900 -0.440000 0.728000 0.512000 +-0.208400 0.401700 0.000000 -0.424000 0.248000 0.864000 +-0.200000 0.451900 -0.034900 -0.360000 0.584000 0.720000 +-0.200000 0.408700 0.000000 -0.112000 0.496000 0.856000 +-0.150000 0.451900 -0.004000 -0.136000 0.584000 0.792000 +-0.185900 0.401700 0.000000 0.264000 0.248000 0.928000 +-0.150000 0.401700 -0.011900 0.240000 0.256000 0.928000 +-0.150000 0.451900 -0.004000 -0.136000 0.584000 0.792000 +-0.100000 0.401700 -0.042400 0.232000 -0.088000 0.960000 +-0.100000 0.451900 -0.019200 0.136000 0.056000 0.984000 +-0.050000 0.401700 -0.052300 0.176000 0.040000 0.976000 +-0.050000 0.451900 -0.049700 0.432000 0.024000 0.896000 +-0.100000 0.451900 -0.019200 0.136000 0.056000 0.984000 +-0.050000 0.502100 -0.046900 0.400000 0.496000 0.760000 +-0.100000 0.502100 -0.041900 -0.080000 0.528000 0.840000 +-0.050000 0.515300 -0.060900 0.432000 0.792000 0.408000 +-0.100000 0.517800 -0.060900 -0.120000 0.976000 0.136000 +-0.100000 0.502100 -0.041900 -0.080000 0.528000 0.840000 +-0.146800 0.502100 -0.060900 -0.272000 0.960000 0.016000 +-0.100000 0.451900 -0.019200 0.136000 0.056000 0.984000 +-0.150000 0.501300 -0.060900 -0.376000 0.880000 -0.280000 +-0.150000 0.451900 -0.004000 -0.136000 0.584000 0.792000 +-0.200000 0.477600 -0.060900 -0.544000 0.808000 -0.208000 +-0.200000 0.451900 -0.034900 -0.360000 0.584000 0.720000 +-0.242600 0.451900 -0.060900 -0.440000 0.728000 0.512000 +-0.200000 0.477600 -0.060900 -0.544000 0.808000 -0.208000 +-0.200000 0.451900 -0.081300 -0.400000 0.504000 -0.752000 +-0.200000 0.451900 -0.081300 -0.400000 0.504000 -0.752000 +-0.321000 0.100400 0.000000 -0.264000 0.416000 0.864000 +-0.321000 0.100400 0.000000 -0.264000 0.416000 0.864000 +-0.350000 0.077100 0.000000 -0.776000 0.256000 0.568000 +-0.350000 0.100400 -0.017600 -0.744000 0.352000 0.552000 +-0.350000 0.100400 -0.017600 -0.744000 0.352000 0.552000 +-0.250000 0.351500 -0.004200 0.040000 0.000000 0.992000 +-0.250000 0.351500 -0.004200 0.040000 0.000000 0.992000 +-0.300000 0.351500 -0.024700 -0.384000 0.216000 0.896000 +-0.250000 0.301200 -0.005700 0.112000 -0.104000 0.984000 +-0.300000 0.301200 -0.020200 -0.184000 0.032000 0.976000 +-0.250000 0.251000 -0.029400 0.176000 -0.456000 0.864000 +-0.300000 0.251000 -0.020200 0.208000 -0.160000 0.960000 +-0.250000 0.219300 -0.060900 0.304000 -0.640000 0.696000 +-0.300000 0.200800 -0.040500 0.440000 0.208000 0.864000 +-0.277600 0.200800 -0.060900 0.584000 -0.072000 0.800000 +-0.250000 0.219300 -0.060900 0.304000 -0.640000 0.696000 +-0.250000 0.200800 -0.094600 -0.184000 -0.064000 0.976000 +-0.200000 0.206100 -0.060900 -0.448000 -0.184000 0.872000 +-0.200000 0.200800 -0.062300 -0.304000 0.376000 0.864000 +-0.198000 0.200800 -0.060900 -0.464000 0.288000 0.832000 +-0.200000 0.199100 -0.060900 -0.320000 0.504000 0.792000 +-0.200000 0.200800 -0.062300 -0.304000 0.376000 0.864000 +-0.250000 0.177000 -0.060900 -0.096000 0.568000 0.808000 +-0.250000 0.200800 -0.094600 -0.184000 -0.064000 0.976000 +-0.277600 0.200800 -0.060900 0.584000 -0.072000 0.800000 +-0.277600 0.200800 -0.060900 0.584000 -0.072000 0.800000 +-0.250000 -0.351500 -0.038300 0.104000 -0.504000 0.848000 +-0.250000 -0.351500 -0.038300 0.104000 -0.504000 0.848000 +-0.300000 -0.351500 -0.012600 0.872000 -0.352000 0.320000 +-0.250000 -0.401700 -0.058800 -0.096000 -0.136000 0.984000 +-0.300000 -0.401700 -0.045100 0.792000 -0.248000 0.544000 +-0.250000 -0.451900 -0.040500 -0.352000 -0.008000 0.928000 +-0.300000 -0.435300 -0.060900 -0.192000 -0.360000 0.912000 +-0.287100 -0.451900 -0.060900 -0.448000 -0.328000 0.824000 +-0.300000 -0.451900 -0.070300 -0.328000 -0.392000 0.856000 +-0.279200 -0.502100 -0.060900 -0.688000 -0.328000 0.640000 +-0.300000 -0.502100 -0.097100 -0.592000 -0.576000 0.560000 +-0.250000 -0.533000 -0.060900 -0.336000 -0.760000 0.544000 +-0.300000 -0.516400 -0.121900 -0.256000 -0.872000 0.400000 +-0.250000 -0.552300 -0.101500 -0.080000 -0.904000 0.400000 +-0.260200 -0.552300 -0.121900 -0.560000 -0.752000 0.336000 +-0.250000 -0.559400 -0.121900 -0.088000 -0.912000 0.384000 +-0.285200 -0.552300 -0.182900 -0.616000 -0.680000 0.384000 +-0.250000 -0.581300 -0.182900 -0.104000 -0.888000 0.440000 +-0.300000 -0.552300 -0.209900 -0.624000 -0.616000 0.456000 +-0.250000 -0.602500 -0.226600 0.288000 -0.512000 0.800000 +-0.300000 -0.594300 -0.243900 -0.424000 -0.464000 0.768000 +-0.286800 -0.602500 -0.243900 -0.320000 0.232000 0.912000 +-0.300000 -0.602500 -0.250000 -0.408000 0.368000 0.824000 +-0.300000 -0.607200 -0.243900 -0.248000 0.672000 0.688000 +-0.344900 -0.602500 -0.304800 -0.744000 0.664000 -0.032000 +-0.350000 -0.630200 -0.243900 -0.144000 0.776000 0.600000 +-0.350000 -0.605300 -0.304800 0.248000 0.960000 -0.032000 +-0.371400 -0.602500 -0.243900 0.928000 0.016000 0.352000 +-0.351600 -0.602500 -0.304800 0.944000 0.304000 0.024000 +-0.363900 -0.552300 -0.243900 0.816000 -0.480000 0.304000 +-0.350000 -0.594300 -0.304800 0.520000 -0.800000 0.280000 +-0.350000 -0.552300 -0.283400 -0.096000 -0.680000 0.720000 +-0.344900 -0.602500 -0.304800 -0.744000 0.664000 -0.032000 +-0.317500 -0.552300 -0.243900 -0.600000 -0.648000 0.448000 +-0.300000 -0.602500 -0.250000 -0.408000 0.368000 0.824000 +-0.300000 -0.594300 -0.243900 -0.424000 -0.464000 0.768000 +-0.317500 -0.552300 -0.243900 -0.600000 -0.648000 0.448000 +-0.300000 -0.552300 -0.209900 -0.624000 -0.616000 0.456000 +-0.350000 -0.535600 -0.243900 0.360000 -0.840000 0.384000 +-0.300000 -0.538300 -0.182900 -0.584000 -0.696000 0.408000 +-0.350000 -0.518400 -0.182900 -0.088000 -0.928000 0.360000 +-0.300000 -0.516400 -0.121900 -0.256000 -0.872000 0.400000 +-0.350000 -0.503000 -0.121900 0.232000 -0.880000 0.400000 +-0.300000 -0.502100 -0.097100 -0.592000 -0.576000 0.560000 +-0.350000 -0.502100 -0.119400 0.240000 -0.864000 0.424000 +-0.300000 -0.451900 -0.070300 -0.328000 -0.392000 0.856000 +-0.350000 -0.453900 -0.060900 0.248000 -0.624000 0.728000 +-0.338500 -0.451900 -0.060900 0.112000 -0.632000 0.760000 +-0.300000 -0.451900 -0.070300 -0.328000 -0.392000 0.856000 +-0.300000 -0.435300 -0.060900 -0.192000 -0.360000 0.912000 +-0.300000 -0.435300 -0.060900 -0.192000 -0.360000 0.912000 +-0.287100 -0.451900 -0.060900 -0.448000 -0.328000 0.824000 +-0.287100 -0.451900 -0.060900 -0.448000 -0.328000 0.824000 +-0.279200 -0.502100 -0.060900 -0.688000 -0.328000 0.640000 +-0.250000 -0.451900 -0.040500 -0.352000 -0.008000 0.928000 +-0.250000 -0.502100 -0.016400 -0.320000 -0.344000 0.872000 +-0.200000 -0.451900 -0.018000 0.376000 -0.112000 0.912000 +-0.200000 -0.502100 -0.039000 0.512000 -0.608000 0.592000 +-0.250000 -0.502100 -0.016400 -0.320000 -0.344000 0.872000 +-0.200000 -0.511900 -0.060900 0.416000 -0.800000 0.424000 +-0.250000 -0.533000 -0.060900 -0.336000 -0.760000 0.544000 +-0.200000 -0.534300 -0.121900 0.456000 -0.832000 0.296000 +-0.250000 -0.552300 -0.101500 -0.080000 -0.904000 0.400000 +-0.235800 -0.552300 -0.121900 0.448000 -0.816000 0.336000 +-0.250000 -0.559400 -0.121900 -0.088000 -0.912000 0.384000 +-0.204600 -0.552300 -0.182900 0.504000 -0.776000 0.360000 +-0.250000 -0.581300 -0.182900 -0.104000 -0.888000 0.440000 +-0.200000 -0.552300 -0.190900 0.520000 -0.768000 0.360000 +-0.250000 -0.602500 -0.226600 0.288000 -0.512000 0.800000 +-0.200000 -0.579600 -0.243900 0.568000 -0.648000 0.496000 +-0.233200 -0.602500 -0.243900 0.608000 -0.320000 0.720000 +-0.200000 -0.602500 -0.268600 0.488000 -0.432000 0.752000 +-0.241600 -0.652700 -0.243900 0.680000 -0.216000 0.688000 +-0.200000 -0.652700 -0.286600 0.488000 -0.272000 0.824000 +-0.250000 -0.679700 -0.243900 0.728000 -0.208000 0.640000 +-0.200000 -0.693500 -0.304800 0.872000 -0.464000 -0.120000 +-0.250000 -0.703000 -0.252700 0.704000 -0.368000 0.600000 +-0.204300 -0.703000 -0.304800 0.856000 -0.496000 -0.088000 +-0.250000 -0.737300 -0.304800 0.568000 -0.808000 -0.112000 +-0.250000 -0.703000 -0.346500 0.432000 -0.280000 -0.848000 +-0.204300 -0.703000 -0.304800 0.856000 -0.496000 -0.088000 +-0.250000 -0.652700 -0.361600 0.240000 -0.216000 -0.944000 +-0.200000 -0.693500 -0.304800 0.872000 -0.464000 -0.120000 +-0.200000 -0.652700 -0.326500 0.488000 -0.272000 -0.824000 +-0.171500 -0.652700 -0.304800 0.576000 -0.304000 0.752000 +-0.200000 -0.693500 -0.304800 0.872000 -0.464000 -0.120000 +-0.200000 -0.652700 -0.286600 0.488000 -0.272000 0.824000 +-0.200000 -0.652700 -0.286600 0.488000 -0.272000 0.824000 +-0.279200 -0.502100 -0.060900 -0.688000 -0.328000 0.640000 +-0.279200 -0.502100 -0.060900 -0.688000 -0.328000 0.640000 +-0.250000 -0.502100 -0.016400 -0.320000 -0.344000 0.872000 +-0.250000 -0.533000 -0.060900 -0.336000 -0.760000 0.544000 +-0.250000 -0.533000 -0.060900 -0.336000 -0.760000 0.544000 +-0.200000 0.351500 -0.009600 0.208000 -0.208000 0.952000 +-0.200000 0.351500 -0.009600 0.208000 -0.208000 0.952000 +-0.250000 0.351500 -0.004200 0.040000 0.000000 0.992000 +-0.200000 0.301200 -0.022600 0.056000 -0.176000 0.976000 +-0.250000 0.301200 -0.005700 0.112000 -0.104000 0.984000 +-0.200000 0.251000 -0.048300 -0.120000 -0.296000 0.944000 +-0.250000 0.251000 -0.029400 0.176000 -0.456000 0.864000 +-0.200000 0.206100 -0.060900 -0.448000 -0.184000 0.872000 +-0.250000 0.219300 -0.060900 0.304000 -0.640000 0.696000 +-0.250000 0.219300 -0.060900 0.304000 -0.640000 0.696000 +-0.200000 -0.351500 -0.031500 -0.320000 -0.128000 0.936000 +-0.200000 -0.351500 -0.031500 -0.320000 -0.128000 0.936000 +-0.250000 -0.351500 -0.038300 0.104000 -0.504000 0.848000 +-0.200000 -0.401700 -0.023400 -0.056000 -0.008000 0.992000 +-0.250000 -0.401700 -0.058800 -0.096000 -0.136000 0.984000 +-0.200000 -0.451900 -0.018000 0.376000 -0.112000 0.912000 +-0.250000 -0.451900 -0.040500 -0.352000 -0.008000 0.928000 +-0.250000 -0.451900 -0.040500 -0.352000 -0.008000 0.928000 +-0.200000 0.150600 -0.023100 -0.360000 0.472000 0.792000 +-0.200000 0.150600 -0.023100 -0.360000 0.472000 0.792000 +-0.200000 0.100400 -0.008800 0.176000 0.488000 0.848000 +-0.150000 0.150600 -0.037800 0.256000 -0.016000 0.960000 +-0.150000 0.100400 -0.027500 0.432000 0.296000 0.848000 +-0.114400 0.150600 -0.060900 0.520000 -0.344000 0.776000 +-0.122500 0.100400 -0.060900 0.768000 -0.048000 0.624000 +-0.100000 0.150600 -0.075000 0.592000 -0.416000 0.688000 +-0.100000 0.100400 -0.099400 0.760000 -0.264000 0.584000 +-0.067900 0.150600 -0.121900 0.736000 -0.432000 0.504000 +-0.089100 0.100400 -0.121900 0.816000 -0.232000 0.520000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +-0.053800 0.100400 -0.182900 0.984000 -0.072000 0.112000 +-0.050000 0.116900 -0.182900 0.944000 -0.304000 0.048000 +-0.051400 0.100400 -0.243900 0.776000 0.216000 -0.576000 +-0.050000 0.150600 -0.210200 0.840000 -0.208000 -0.496000 +-0.077600 0.150600 -0.243900 0.320000 0.328000 -0.880000 +-0.051400 0.100400 -0.243900 0.776000 0.216000 -0.576000 +-0.100000 0.150600 -0.251000 -0.024000 0.408000 -0.904000 +-0.100000 0.100400 -0.276400 0.032000 0.376000 -0.920000 +-0.126800 0.150600 -0.243900 -0.208000 0.496000 -0.832000 +-0.150000 0.100400 -0.267100 -0.312000 0.440000 -0.832000 +-0.150000 0.141700 -0.243900 -0.352000 0.528000 -0.768000 +-0.198500 0.100400 -0.243900 -0.376000 0.480000 -0.784000 +-0.150000 0.100400 -0.267100 -0.312000 0.440000 -0.832000 +-0.200000 0.099300 -0.243900 -0.456000 0.488000 -0.736000 +-0.150000 0.050200 -0.299600 -0.080000 0.408000 -0.904000 +-0.200000 0.050200 -0.277000 -0.312000 0.416000 -0.848000 +-0.150000 0.040500 -0.304800 -0.136000 0.416000 -0.896000 +-0.200000 0.008900 -0.304800 -0.304000 0.456000 -0.832000 +-0.150000 0.000000 -0.322200 0.064000 0.240000 -0.968000 +-0.200000 0.000000 -0.310700 -0.288000 0.424000 -0.848000 +-0.150000 -0.050200 -0.328000 0.128000 0.064000 -0.984000 +-0.200000 -0.050200 -0.330400 -0.144000 0.264000 -0.944000 +-0.150000 -0.100400 -0.338700 0.056000 -0.088000 -0.992000 +-0.200000 -0.100400 -0.330100 -0.024000 -0.008000 -0.992000 +-0.150000 -0.150600 -0.309500 -0.032000 -0.400000 -0.912000 +-0.200000 -0.150600 -0.333300 0.216000 -0.272000 -0.936000 +-0.200000 -0.100400 -0.330100 -0.024000 -0.008000 -0.992000 +-0.250000 -0.150600 -0.327500 -0.120000 0.152000 -0.976000 +-0.250000 -0.100400 -0.327300 -0.384000 0.152000 -0.904000 +-0.200000 -0.100400 -0.330100 -0.024000 -0.008000 -0.992000 +-0.250000 -0.050200 -0.318700 -0.440000 0.320000 -0.832000 +-0.200000 -0.050200 -0.330400 -0.144000 0.264000 -0.944000 +-0.250000 -0.028200 -0.304800 -0.400000 0.416000 -0.808000 +-0.200000 0.000000 -0.310700 -0.288000 0.424000 -0.848000 +-0.213400 0.000000 -0.304800 -0.304000 0.448000 -0.832000 +-0.200000 0.008900 -0.304800 -0.304000 0.456000 -0.832000 +-0.250000 0.000000 -0.286200 -0.320000 0.712000 -0.616000 +-0.200000 0.050200 -0.277000 -0.312000 0.416000 -0.848000 +-0.250000 0.050200 -0.254100 -0.584000 0.656000 -0.464000 +-0.200000 0.099300 -0.243900 -0.456000 0.488000 -0.736000 +-0.250000 0.055800 -0.243900 -0.560000 0.648000 -0.504000 +-0.250000 0.050200 -0.254100 -0.584000 0.656000 -0.464000 +-0.256300 0.050200 -0.243900 -0.592000 0.624000 -0.488000 +-0.256300 0.050200 -0.243900 -0.592000 0.624000 -0.488000 +-0.200000 -0.502100 -0.039000 0.512000 -0.608000 0.592000 +-0.200000 -0.502100 -0.039000 0.512000 -0.608000 0.592000 +-0.181900 -0.502100 -0.060900 0.504000 -0.680000 0.520000 +-0.200000 -0.511900 -0.060900 0.416000 -0.800000 0.424000 +-0.200000 -0.511900 -0.060900 0.416000 -0.800000 0.424000 +-0.100000 0.401700 -0.042400 0.232000 -0.088000 0.960000 +-0.100000 0.401700 -0.042400 0.232000 -0.088000 0.960000 +-0.150000 0.401700 -0.011900 0.240000 0.256000 0.928000 +-0.100000 0.351500 -0.035500 0.120000 0.000000 0.992000 +-0.150000 0.351500 -0.029900 0.096000 -0.168000 0.976000 +-0.100000 0.301200 -0.032000 0.168000 0.008000 0.984000 +-0.150000 0.301200 -0.033800 0.040000 -0.024000 0.992000 +-0.100000 0.251000 -0.029400 0.344000 -0.104000 0.928000 +-0.150000 0.251000 -0.027500 -0.136000 -0.104000 0.984000 +-0.100000 0.200800 -0.041900 0.456000 -0.304000 0.832000 +-0.150000 0.200800 -0.027500 -0.320000 -0.168000 0.928000 +-0.100000 0.167200 -0.060900 0.520000 -0.424000 0.736000 +-0.150000 0.150600 -0.037800 0.256000 -0.016000 0.960000 +-0.114400 0.150600 -0.060900 0.520000 -0.344000 0.776000 +-0.100000 0.167200 -0.060900 0.520000 -0.424000 0.736000 +-0.100000 0.150600 -0.075000 0.592000 -0.416000 0.688000 +-0.078700 0.200800 -0.060900 0.568000 -0.416000 0.704000 +-0.067900 0.150600 -0.121900 0.736000 -0.432000 0.504000 +-0.050000 0.200800 -0.090500 0.520000 -0.520000 0.672000 +-0.050000 0.170300 -0.121900 0.584000 -0.576000 0.560000 +-0.067900 0.150600 -0.121900 0.736000 -0.432000 0.504000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +-0.150000 0.100400 -0.027500 0.432000 0.296000 0.848000 +-0.150000 0.100400 -0.027500 0.432000 0.296000 0.848000 +-0.150000 0.050200 -0.012600 0.624000 0.240000 0.728000 +-0.122500 0.100400 -0.060900 0.768000 -0.048000 0.624000 +-0.123500 0.050200 -0.060900 0.888000 -0.104000 0.440000 +-0.100000 0.100400 -0.099400 0.760000 -0.264000 0.584000 +-0.100700 0.050200 -0.121900 0.856000 0.048000 0.504000 +-0.100000 0.054100 -0.121900 0.816000 -0.176000 0.544000 +-0.100000 0.050200 -0.123300 0.696000 -0.176000 0.688000 +-0.089100 0.100400 -0.121900 0.816000 -0.232000 0.520000 +-0.051100 0.050200 -0.182900 0.712000 0.184000 0.664000 +-0.053800 0.100400 -0.182900 0.984000 -0.072000 0.112000 +-0.050000 0.050200 -0.189300 0.800000 0.488000 0.336000 +-0.051400 0.100400 -0.243900 0.776000 0.216000 -0.576000 +-0.050000 0.095100 -0.243900 0.808000 0.256000 -0.520000 +-0.100000 0.100400 -0.276400 0.032000 0.376000 -0.920000 +-0.050000 0.050200 -0.257500 0.608000 0.208000 -0.760000 +-0.100000 0.050200 -0.292200 0.304000 0.312000 -0.896000 +-0.050000 0.000000 -0.288000 0.256000 0.560000 -0.776000 +-0.100000 0.022400 -0.304800 0.184000 0.304000 -0.928000 +-0.077600 0.000000 -0.304800 0.248000 0.344000 -0.896000 +-0.100000 0.000000 -0.309600 0.168000 0.152000 -0.968000 +-0.050000 -0.015100 -0.304800 0.280000 0.536000 -0.784000 +-0.100000 -0.050200 -0.318600 0.080000 0.144000 -0.984000 +-0.050000 -0.050200 -0.321000 0.120000 0.280000 -0.944000 +-0.100000 -0.100400 -0.323700 -0.040000 -0.152000 -0.984000 +-0.050000 -0.100400 -0.342800 0.056000 -0.032000 -0.992000 +-0.100000 -0.150600 -0.315000 -0.456000 -0.064000 -0.880000 +-0.050000 -0.150600 -0.332400 0.016000 -0.080000 -0.992000 +-0.050000 -0.100400 -0.342800 0.056000 -0.032000 -0.992000 +0.000000 -0.150600 -0.318000 0.160000 0.016000 -0.984000 +0.000000 -0.100400 -0.336000 0.328000 -0.184000 -0.920000 +0.050000 -0.150600 -0.318000 0.352000 0.312000 -0.872000 +0.039400 -0.100400 -0.304800 0.408000 0.224000 -0.880000 +0.050000 -0.119800 -0.304800 0.416000 0.264000 -0.864000 +0.050000 -0.100400 -0.298100 0.360000 0.248000 -0.896000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +0.100000 -0.100400 -0.298900 0.040000 0.136000 -0.984000 +0.100000 -0.150600 -0.303900 -0.176000 0.088000 -0.976000 +0.114400 -0.100400 -0.304800 -0.344000 0.128000 -0.928000 +0.101900 -0.150600 -0.304800 -0.296000 0.368000 -0.872000 +0.100000 -0.150600 -0.303900 -0.176000 0.088000 -0.976000 +0.100000 -0.151600 -0.304800 -0.176000 0.536000 -0.816000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +-0.150000 0.050200 -0.012600 0.624000 0.240000 0.728000 +-0.150000 0.050200 -0.012600 0.624000 0.240000 0.728000 +-0.150000 0.000000 -0.001200 0.744000 0.064000 0.656000 +-0.123500 0.050200 -0.060900 0.888000 -0.104000 0.440000 +-0.120900 0.000000 -0.060900 0.800000 0.080000 0.592000 +-0.100700 0.050200 -0.121900 0.856000 0.048000 0.504000 +-0.100000 0.000000 -0.110200 0.808000 0.176000 0.552000 +-0.100000 0.044900 -0.121900 0.816000 0.112000 0.552000 +-0.089600 0.000000 -0.121900 0.568000 0.512000 0.632000 +-0.100000 0.050200 -0.123300 0.696000 -0.176000 0.688000 +-0.050000 0.000000 -0.158900 0.584000 0.336000 0.728000 +-0.051100 0.050200 -0.182900 0.712000 0.184000 0.664000 +-0.050000 0.047900 -0.182900 0.488000 0.480000 0.720000 +-0.050000 0.050200 -0.189300 0.800000 0.488000 0.336000 +0.000000 0.039200 -0.182900 0.256000 0.544000 0.792000 +0.000000 0.050200 -0.198900 0.168000 0.840000 0.504000 +0.050000 0.005700 -0.182900 0.312000 0.584000 0.744000 +0.046000 0.050200 -0.243900 0.728000 0.480000 -0.472000 +0.050000 0.042300 -0.243900 0.688000 0.376000 -0.616000 +0.000000 0.050200 -0.275900 0.288000 0.416000 -0.856000 +0.050000 0.000000 -0.258500 0.448000 0.256000 -0.848000 +0.000000 0.000000 -0.289100 0.520000 0.272000 -0.800000 +0.050000 -0.050200 -0.279200 0.280000 0.320000 -0.896000 +0.000000 -0.038700 -0.304800 0.368000 0.192000 -0.904000 +0.004800 -0.050200 -0.304800 0.368000 0.176000 -0.904000 +0.000000 -0.050200 -0.306900 0.320000 0.152000 -0.928000 +0.039400 -0.100400 -0.304800 0.408000 0.224000 -0.880000 +0.000000 -0.100400 -0.336000 0.328000 -0.184000 -0.920000 +0.000000 -0.050200 -0.306900 0.320000 0.152000 -0.928000 +-0.050000 -0.100400 -0.342800 0.056000 -0.032000 -0.992000 +-0.050000 -0.050200 -0.321000 0.120000 0.280000 -0.944000 +0.000000 -0.050200 -0.306900 0.320000 0.152000 -0.928000 +-0.050000 -0.015100 -0.304800 0.280000 0.536000 -0.784000 +0.000000 -0.038700 -0.304800 0.368000 0.192000 -0.904000 +-0.050000 0.000000 -0.288000 0.256000 0.560000 -0.776000 +0.000000 0.000000 -0.289100 0.520000 0.272000 -0.800000 +-0.050000 0.050200 -0.257500 0.608000 0.208000 -0.760000 +0.000000 0.050200 -0.275900 0.288000 0.416000 -0.856000 +-0.050000 0.095100 -0.243900 0.808000 0.256000 -0.520000 +0.000000 0.087200 -0.243900 0.456000 0.816000 -0.344000 +-0.050000 0.050200 -0.189300 0.800000 0.488000 0.336000 +0.000000 0.050200 -0.198900 0.168000 0.840000 0.504000 +0.000000 0.087200 -0.243900 0.456000 0.816000 -0.344000 +0.046000 0.050200 -0.243900 0.728000 0.480000 -0.472000 +0.000000 0.050200 -0.275900 0.288000 0.416000 -0.856000 +0.000000 0.050200 -0.275900 0.288000 0.416000 -0.856000 +-0.150000 0.000000 -0.001200 0.744000 0.064000 0.656000 +-0.150000 0.000000 -0.001200 0.744000 0.064000 0.656000 +-0.150000 -0.050200 -0.005700 0.768000 -0.024000 0.632000 +-0.120900 0.000000 -0.060900 0.800000 0.080000 0.592000 +-0.114700 -0.050200 -0.060900 0.632000 0.112000 0.760000 +-0.100000 0.000000 -0.110200 0.808000 0.176000 0.552000 +-0.100000 -0.050200 -0.077100 0.584000 0.232000 0.768000 +-0.089600 0.000000 -0.121900 0.568000 0.512000 0.632000 +-0.050000 -0.050200 -0.098600 0.240000 0.488000 0.832000 +-0.050000 -0.024600 -0.121900 0.296000 0.656000 0.688000 +0.000000 -0.050200 -0.114000 0.064000 0.408000 0.904000 +0.000000 -0.035500 -0.121900 0.072000 0.496000 0.856000 +0.050000 -0.050200 -0.115700 0.016000 0.416000 0.904000 +0.050000 -0.038600 -0.121900 0.000000 0.528000 0.840000 +0.100000 -0.050200 -0.113200 -0.016000 0.464000 0.880000 +0.100000 -0.037100 -0.121900 -0.016000 0.544000 0.832000 +0.150000 -0.050200 -0.113700 0.032000 0.448000 0.888000 +0.150000 -0.036300 -0.121900 0.008000 0.488000 0.864000 +0.100000 -0.037100 -0.121900 -0.016000 0.544000 0.832000 +0.150000 0.000000 -0.166100 -0.096000 0.688000 0.712000 +0.100000 0.000000 -0.179900 0.000000 0.528000 0.840000 +0.150000 0.016800 -0.182900 -0.152000 0.840000 0.520000 +0.100000 0.004900 -0.182900 -0.288000 0.864000 0.400000 +0.150000 0.015400 -0.243900 -0.208000 0.728000 -0.640000 +0.100000 0.000000 -0.203800 -0.256000 0.936000 -0.224000 +0.113100 0.000000 -0.243900 -0.392000 0.768000 -0.496000 +0.100000 -0.005500 -0.243900 -0.184000 0.760000 -0.616000 +0.150000 0.000000 -0.257100 -0.208000 0.552000 -0.800000 +0.100000 -0.050200 -0.272200 -0.136000 0.384000 -0.904000 +0.150000 -0.050200 -0.298400 -0.176000 0.328000 -0.920000 +0.100000 -0.100400 -0.298900 0.040000 0.136000 -0.984000 +0.150000 -0.064700 -0.304800 -0.200000 0.328000 -0.912000 +0.114400 -0.100400 -0.304800 -0.344000 0.128000 -0.928000 +0.114400 -0.100400 -0.304800 -0.344000 0.128000 -0.928000 +-0.150000 -0.050200 -0.005700 0.768000 -0.024000 0.632000 +-0.150000 -0.050200 -0.005700 0.768000 -0.024000 0.632000 +-0.150000 -0.100400 -0.001300 0.848000 0.032000 0.520000 +-0.114700 -0.050200 -0.060900 0.632000 0.112000 0.760000 +-0.104300 -0.100400 -0.060900 0.528000 0.416000 0.728000 +-0.100000 -0.050200 -0.077100 0.584000 0.232000 0.768000 +-0.100000 -0.100400 -0.064700 0.496000 0.416000 0.752000 +-0.050000 -0.050200 -0.098600 0.240000 0.488000 0.832000 +-0.050000 -0.100400 -0.073900 0.136000 0.480000 0.864000 +0.000000 -0.050200 -0.114000 0.064000 0.408000 0.904000 +0.000000 -0.100400 -0.085100 0.096000 0.456000 0.880000 +0.050000 -0.050200 -0.115700 0.016000 0.416000 0.904000 +0.050000 -0.100400 -0.083400 0.000000 0.440000 0.888000 +0.100000 -0.050200 -0.113200 -0.016000 0.464000 0.880000 +0.100000 -0.100400 -0.084200 0.032000 0.360000 0.928000 +0.150000 -0.050200 -0.113700 0.032000 0.448000 0.888000 +0.150000 -0.100400 -0.080500 0.184000 0.336000 0.920000 +0.100000 -0.100400 -0.084200 0.032000 0.360000 0.928000 +0.150000 -0.150600 -0.071000 0.136000 0.176000 0.968000 +0.100000 -0.150600 -0.068400 0.184000 0.416000 0.888000 +0.150000 -0.200800 -0.071800 0.312000 -0.208000 0.920000 +0.100000 -0.170000 -0.060900 0.256000 0.296000 0.912000 +0.130700 -0.200800 -0.060900 0.504000 0.008000 0.856000 +0.150000 -0.200800 -0.071800 0.312000 -0.208000 0.920000 +0.110300 -0.251000 -0.060900 0.504000 -0.760000 0.392000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +-0.100000 -0.188700 0.000000 0.176000 0.408000 0.888000 +-0.100000 -0.188700 0.000000 0.176000 0.408000 0.888000 +-0.129500 -0.150600 0.000000 0.416000 0.264000 0.864000 +-0.100000 -0.150600 -0.019000 0.512000 0.456000 0.720000 +-0.100000 -0.150600 -0.019000 0.512000 0.456000 0.720000 +-0.150000 -0.346200 0.000000 -0.392000 -0.160000 0.904000 +-0.150000 -0.346200 0.000000 -0.392000 -0.160000 0.904000 +-0.150000 -0.351500 -0.001100 -0.192000 -0.352000 0.912000 +-0.100000 -0.344900 0.000000 0.072000 -0.528000 0.840000 +-0.100000 -0.351500 -0.005700 0.248000 -0.576000 0.776000 +-0.050000 -0.329200 0.000000 0.264000 -0.624000 0.720000 +-0.050000 -0.351500 -0.027000 0.488000 -0.688000 0.528000 +-0.100000 -0.351500 -0.005700 0.248000 -0.576000 0.776000 +-0.050000 -0.370100 -0.060900 0.592000 -0.672000 0.424000 +-0.100000 -0.401700 -0.044900 0.592000 -0.496000 0.624000 +-0.087700 -0.401700 -0.060900 0.608000 -0.600000 0.504000 +-0.100000 -0.415900 -0.060900 0.680000 -0.544000 0.480000 +-0.054100 -0.401700 -0.121900 0.656000 -0.688000 0.280000 +-0.100000 -0.451900 -0.117700 0.624000 -0.664000 0.392000 +-0.098000 -0.451900 -0.121900 0.712000 -0.680000 0.120000 +-0.100000 -0.453500 -0.121900 0.600000 -0.776000 0.168000 +-0.098100 -0.451900 -0.182900 0.736000 -0.672000 0.032000 +-0.100000 -0.453800 -0.182900 0.696000 -0.712000 0.024000 +-0.094700 -0.451900 -0.243900 0.784000 -0.568000 0.216000 +-0.100000 -0.458900 -0.243900 0.744000 -0.632000 0.192000 +-0.061500 -0.451900 -0.304800 0.928000 -0.352000 0.088000 +-0.100000 -0.502100 -0.283200 0.616000 -0.376000 0.680000 +-0.074100 -0.502100 -0.304800 0.864000 -0.480000 0.112000 +-0.100000 -0.549700 -0.304800 0.696000 -0.392000 0.592000 +-0.100000 -0.502100 -0.325200 0.520000 -0.368000 -0.760000 +-0.101500 -0.552300 -0.304800 0.552000 -0.392000 0.720000 +-0.147100 -0.502100 -0.365800 0.472000 -0.192000 -0.848000 +-0.150000 -0.552300 -0.337600 0.424000 -0.304000 -0.840000 +-0.150000 -0.505900 -0.365800 0.272000 -0.320000 -0.904000 +-0.196100 -0.552300 -0.365800 0.320000 -0.272000 -0.904000 +-0.150000 -0.502100 -0.367300 0.088000 -0.320000 -0.936000 +-0.200000 -0.552300 -0.367100 0.360000 -0.232000 -0.896000 +-0.200000 -0.502100 -0.370700 0.184000 -0.352000 -0.912000 +-0.200000 -0.502100 -0.370700 0.184000 -0.352000 -0.912000 +-0.100000 -0.351500 -0.005700 0.248000 -0.576000 0.776000 +-0.100000 -0.351500 -0.005700 0.248000 -0.576000 0.776000 +-0.150000 -0.351500 -0.001100 -0.192000 -0.352000 0.912000 +-0.100000 -0.401700 -0.044900 0.592000 -0.496000 0.624000 +-0.150000 -0.401700 -0.019000 0.408000 -0.232000 0.880000 +-0.100000 -0.415900 -0.060900 0.680000 -0.544000 0.480000 +-0.150000 -0.451900 -0.041900 0.560000 -0.440000 0.696000 +-0.133200 -0.451900 -0.060900 0.584000 -0.656000 0.464000 +-0.150000 -0.470000 -0.060900 0.568000 -0.552000 0.600000 +-0.100000 -0.451900 -0.117700 0.624000 -0.664000 0.392000 +-0.150000 -0.502100 -0.111600 0.592000 -0.752000 0.280000 +-0.100000 -0.453500 -0.121900 0.600000 -0.776000 0.168000 +-0.146100 -0.502100 -0.121900 0.616000 -0.744000 0.232000 +-0.100000 -0.453800 -0.182900 0.696000 -0.712000 0.024000 +-0.141200 -0.502100 -0.182900 0.696000 -0.688000 0.184000 +-0.100000 -0.458900 -0.243900 0.744000 -0.632000 0.192000 +-0.125700 -0.502100 -0.243900 0.664000 -0.408000 0.624000 +-0.100000 -0.502100 -0.283200 0.616000 -0.376000 0.680000 +-0.150000 -0.530700 -0.243900 0.632000 -0.664000 0.392000 +-0.100000 -0.549700 -0.304800 0.696000 -0.392000 0.592000 +-0.150000 -0.552300 -0.270100 0.544000 -0.504000 0.656000 +-0.101500 -0.552300 -0.304800 0.552000 -0.392000 0.720000 +-0.150000 -0.602500 -0.302600 0.392000 -0.240000 0.880000 +-0.145700 -0.602500 -0.304800 0.824000 -0.528000 0.192000 +-0.150000 -0.609400 -0.304800 0.840000 -0.512000 0.152000 +-0.150000 -0.602500 -0.307600 0.456000 -0.280000 -0.840000 +-0.145700 -0.602500 -0.304800 0.824000 -0.528000 0.192000 +-0.150000 -0.552300 -0.337600 0.424000 -0.304000 -0.840000 +-0.101500 -0.552300 -0.304800 0.552000 -0.392000 0.720000 +-0.101500 -0.552300 -0.304800 0.552000 -0.392000 0.720000 +-0.050000 0.401700 -0.052300 0.176000 0.040000 0.976000 +-0.050000 0.401700 -0.052300 0.176000 0.040000 0.976000 +-0.100000 0.401700 -0.042400 0.232000 -0.088000 0.960000 +-0.050000 0.351500 -0.043600 0.248000 0.032000 0.960000 +-0.100000 0.351500 -0.035500 0.120000 0.000000 0.992000 +-0.050000 0.301200 -0.044600 0.440000 -0.008000 0.896000 +-0.100000 0.301200 -0.032000 0.168000 0.008000 0.984000 +-0.050000 0.251000 -0.047300 0.528000 -0.360000 0.760000 +-0.100000 0.251000 -0.029400 0.344000 -0.104000 0.928000 +-0.050000 0.236000 -0.060900 0.536000 -0.496000 0.672000 +-0.100000 0.200800 -0.041900 0.456000 -0.304000 0.832000 +-0.078700 0.200800 -0.060900 0.568000 -0.416000 0.704000 +-0.100000 0.167200 -0.060900 0.520000 -0.424000 0.736000 +-0.100000 0.167200 -0.060900 0.520000 -0.424000 0.736000 +-0.027600 0.301200 -0.060900 0.456000 -0.208000 0.856000 +-0.027600 0.301200 -0.060900 0.456000 -0.208000 0.856000 +-0.050000 0.301200 -0.044600 0.440000 -0.008000 0.896000 +-0.035000 0.251000 -0.060900 0.512000 -0.448000 0.728000 +-0.050000 0.251000 -0.047300 0.528000 -0.360000 0.760000 +-0.050000 0.236000 -0.060900 0.536000 -0.496000 0.672000 +-0.050000 0.236000 -0.060900 0.536000 -0.496000 0.672000 +-0.002200 -0.301200 0.000000 0.384000 -0.648000 0.648000 +-0.002200 -0.301200 0.000000 0.384000 -0.648000 0.648000 +0.000000 -0.299000 0.000000 0.440000 -0.464000 0.760000 +0.000000 -0.301200 -0.001900 0.408000 -0.704000 0.568000 +0.050000 -0.253500 0.000000 0.448000 -0.608000 0.648000 +0.032200 -0.301200 -0.060900 0.552000 -0.696000 0.448000 +0.050000 -0.286400 -0.060900 0.528000 -0.720000 0.440000 +0.050000 -0.301200 -0.085900 0.528000 -0.704000 0.464000 +0.050000 -0.301200 -0.085900 0.528000 -0.704000 0.464000 +-0.050000 -0.351500 -0.027000 0.488000 -0.688000 0.528000 +-0.050000 -0.351500 -0.027000 0.488000 -0.688000 0.528000 +-0.029100 -0.351500 -0.060900 0.584000 -0.680000 0.424000 +-0.050000 -0.370100 -0.060900 0.592000 -0.672000 0.424000 +0.000000 -0.351500 -0.112600 0.544000 -0.704000 0.448000 +-0.050000 -0.398200 -0.121900 0.592000 -0.704000 0.368000 +0.000000 -0.356400 -0.121900 0.560000 -0.728000 0.384000 +-0.050000 -0.389600 -0.182900 0.656000 -0.736000 -0.128000 +0.000000 -0.353400 -0.182900 0.520000 -0.832000 -0.160000 +-0.050000 -0.380500 -0.243900 0.664000 -0.736000 -0.104000 +0.000000 -0.351500 -0.193300 0.504000 -0.832000 -0.176000 +-0.013800 -0.351500 -0.243900 0.552000 -0.808000 -0.168000 +0.000000 -0.343100 -0.243900 0.464000 -0.864000 -0.160000 +-0.026900 -0.351500 -0.304800 0.608000 -0.688000 -0.384000 +0.000000 -0.336000 -0.304800 0.392000 -0.872000 -0.264000 +-0.050000 -0.351500 -0.336900 0.024000 -0.576000 -0.808000 +0.000000 -0.316900 -0.365800 0.224000 -0.832000 -0.496000 +-0.050000 -0.309800 -0.365800 -0.336000 -0.416000 -0.840000 +0.000000 -0.301200 -0.413400 -0.392000 -0.192000 -0.896000 +-0.050000 -0.301200 -0.370400 -0.392000 -0.264000 -0.872000 +0.000000 -0.251000 -0.386300 -0.352000 0.496000 -0.792000 +-0.050000 -0.266900 -0.365800 -0.288000 0.088000 -0.944000 +-0.044700 -0.251000 -0.365800 -0.216000 0.376000 -0.896000 +-0.050000 -0.251000 -0.364300 -0.216000 0.352000 -0.904000 +0.000000 -0.238800 -0.365800 -0.192000 0.648000 -0.728000 +-0.050000 -0.200800 -0.320900 -0.056000 0.280000 -0.952000 +0.000000 -0.200800 -0.332000 -0.296000 0.528000 -0.784000 +0.000000 -0.238800 -0.365800 -0.192000 0.648000 -0.728000 +0.050000 -0.200800 -0.360800 -0.016000 0.576000 -0.808000 +0.050000 -0.206300 -0.365800 -0.112000 0.608000 -0.776000 +0.000000 -0.238800 -0.365800 -0.192000 0.648000 -0.728000 +0.050000 -0.251000 -0.406500 0.232000 -0.312000 -0.912000 +0.000000 -0.251000 -0.386300 -0.352000 0.496000 -0.792000 +0.050000 -0.301200 -0.369000 0.376000 -0.768000 -0.512000 +0.000000 -0.301200 -0.413400 -0.392000 -0.192000 -0.896000 +0.050000 -0.303000 -0.365800 0.400000 -0.792000 -0.448000 +0.000000 -0.316900 -0.365800 0.224000 -0.832000 -0.496000 +0.050000 -0.326800 -0.304800 0.424000 -0.880000 -0.184000 +0.000000 -0.336000 -0.304800 0.392000 -0.872000 -0.264000 +0.050000 -0.327900 -0.243900 0.480000 -0.872000 0.000000 +0.000000 -0.343100 -0.243900 0.464000 -0.864000 -0.160000 +0.050000 -0.327900 -0.182900 0.552000 -0.824000 0.048000 +0.000000 -0.351500 -0.193300 0.504000 -0.832000 -0.176000 +0.003100 -0.351500 -0.182900 0.504000 -0.840000 -0.160000 +0.000000 -0.353400 -0.182900 0.520000 -0.832000 -0.160000 +0.006400 -0.351500 -0.121900 0.552000 -0.776000 0.288000 +0.000000 -0.356400 -0.121900 0.560000 -0.728000 0.384000 +0.000000 -0.351500 -0.112600 0.544000 -0.704000 0.448000 +0.000000 -0.351500 -0.112600 0.544000 -0.704000 0.448000 +0.000000 0.351500 -0.051600 0.280000 -0.248000 0.920000 +0.000000 0.351500 -0.051600 0.280000 -0.248000 0.920000 +0.000000 0.393800 -0.060900 0.224000 0.176000 0.952000 +0.042100 0.351500 -0.060900 0.160000 -0.080000 0.976000 +0.000000 0.401700 -0.062800 0.256000 0.176000 0.944000 +0.050000 0.351500 -0.062500 0.000000 -0.264000 0.960000 +0.050000 0.401700 -0.062500 -0.008000 0.136000 0.984000 +0.065700 0.351500 -0.060900 -0.064000 -0.312000 0.944000 +0.100000 0.401700 -0.066700 -0.048000 0.000000 0.992000 +0.100000 0.368600 -0.060900 0.104000 0.120000 0.984000 +0.150000 0.401700 -0.062100 -0.392000 -0.400000 0.816000 +0.111400 0.351500 -0.060900 0.184000 -0.224000 0.952000 +0.150000 0.351500 -0.070300 -0.056000 -0.480000 0.872000 +0.100000 0.345700 -0.060900 0.056000 -0.392000 0.912000 +0.150000 0.301200 -0.094700 0.096000 -0.408000 0.904000 +0.100000 0.301200 -0.081200 0.144000 -0.392000 0.904000 +0.150000 0.253300 -0.121900 0.144000 -0.672000 0.712000 +0.100000 0.251000 -0.119300 0.048000 -0.664000 0.736000 +0.134200 0.251000 -0.121900 0.072000 -0.752000 0.648000 +0.100000 0.248700 -0.121900 0.064000 -0.824000 0.552000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.100000 0.246100 -0.182900 0.136000 -0.488000 -0.856000 +0.150000 0.224100 -0.182900 0.056000 -0.672000 -0.728000 +0.100000 0.251000 -0.185300 0.160000 -0.296000 -0.936000 +0.150000 0.251000 -0.192500 0.112000 0.024000 -0.992000 +0.100000 0.301200 -0.188500 0.112000 0.128000 -0.984000 +0.150000 0.284700 -0.182900 0.352000 0.368000 -0.856000 +0.133500 0.301200 -0.182900 0.272000 0.264000 -0.920000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.150000 0.301200 -0.172900 0.456000 0.432000 -0.768000 +0.134200 0.251000 -0.121900 0.072000 -0.752000 0.648000 +0.150000 0.253300 -0.121900 0.144000 -0.672000 0.712000 +0.150000 0.301200 -0.172900 0.456000 0.432000 -0.768000 +0.200000 0.269500 -0.121900 -0.008000 -0.896000 0.432000 +0.200000 0.301200 -0.179700 -0.152000 -0.352000 -0.920000 +0.250000 0.256500 -0.121900 -0.200000 -0.800000 0.552000 +0.215700 0.301200 -0.182900 -0.120000 -0.160000 -0.976000 +0.250000 0.284000 -0.182900 -0.096000 -0.256000 -0.952000 +0.250000 0.301200 -0.184400 -0.080000 -0.056000 -0.992000 +0.215700 0.301200 -0.182900 -0.120000 -0.160000 -0.976000 +0.250000 0.351500 -0.189100 -0.160000 0.168000 -0.968000 +0.226900 0.351500 -0.182900 -0.224000 0.192000 -0.952000 +0.250000 0.370000 -0.182900 -0.184000 0.304000 -0.928000 +0.200000 0.351500 -0.169700 -0.320000 0.304000 -0.888000 +0.250000 0.401700 -0.172700 -0.016000 0.288000 -0.952000 +0.200000 0.401700 -0.169400 -0.056000 0.168000 -0.976000 +0.250000 0.451900 -0.137900 0.128000 0.536000 -0.824000 +0.200000 0.451900 -0.151000 0.136000 0.400000 -0.896000 +0.250000 0.466900 -0.121900 0.232000 0.968000 0.016000 +0.200000 0.484800 -0.121900 0.312000 0.872000 0.360000 +0.250000 0.451900 -0.094000 0.248000 0.784000 0.552000 +0.200000 0.453000 -0.060900 0.112000 0.728000 0.672000 +0.203100 0.451900 -0.060900 0.264000 0.672000 0.680000 +0.200000 0.451900 -0.059700 0.136000 0.632000 0.760000 +0.250000 0.432000 -0.060900 0.224000 0.624000 0.736000 +0.200000 0.401700 -0.033800 -0.352000 0.000000 0.928000 +0.250000 0.401700 -0.026800 -0.216000 0.176000 0.952000 +0.200000 0.352900 -0.060900 -0.368000 -0.496000 0.776000 +0.250000 0.351500 -0.020200 -0.488000 -0.416000 0.760000 +0.201200 0.351500 -0.060900 -0.488000 -0.576000 0.648000 +0.250000 0.317900 -0.060900 -0.432000 -0.680000 0.584000 +0.200000 0.351500 -0.062100 -0.312000 -0.640000 0.696000 +0.250000 0.301200 -0.083600 -0.096000 -0.744000 0.648000 +0.200000 0.301200 -0.098800 -0.120000 -0.584000 0.800000 +0.250000 0.256500 -0.121900 -0.200000 -0.800000 0.552000 +0.200000 0.269500 -0.121900 -0.008000 -0.896000 0.432000 +0.200000 0.301200 -0.098800 -0.120000 -0.584000 0.800000 +0.150000 0.253300 -0.121900 0.144000 -0.672000 0.712000 +0.150000 0.301200 -0.094700 0.096000 -0.408000 0.904000 +0.200000 0.301200 -0.098800 -0.120000 -0.584000 0.800000 +0.150000 0.351500 -0.070300 -0.056000 -0.480000 0.872000 +0.200000 0.351500 -0.062100 -0.312000 -0.640000 0.696000 +0.150000 0.401700 -0.062100 -0.392000 -0.400000 0.816000 +0.200000 0.352900 -0.060900 -0.368000 -0.496000 0.776000 +0.151400 0.401700 -0.060900 -0.480000 -0.416000 0.760000 +0.200000 0.401700 -0.033800 -0.352000 0.000000 0.928000 +0.150000 0.409600 -0.060900 -0.208000 -0.072000 0.968000 +0.200000 0.451900 -0.059700 0.136000 0.632000 0.760000 +0.150000 0.451900 -0.057100 -0.080000 0.496000 0.856000 +0.200000 0.453000 -0.060900 0.112000 0.728000 0.672000 +0.150000 0.456100 -0.060900 0.048000 0.664000 0.736000 +0.200000 0.484800 -0.121900 0.312000 0.872000 0.360000 +0.150000 0.502100 -0.119700 0.016000 0.656000 0.752000 +0.153400 0.502100 -0.121900 0.448000 0.824000 -0.336000 +0.150000 0.503100 -0.121900 0.272000 0.456000 -0.840000 +0.150000 0.502100 -0.123200 0.032000 0.424000 -0.896000 +0.138500 0.502100 -0.121900 -0.184000 0.952000 -0.216000 +0.150000 0.451900 -0.151900 0.184000 0.376000 -0.904000 +0.100000 0.494400 -0.121900 -0.184000 0.952000 -0.216000 +0.100000 0.451900 -0.146900 -0.088000 0.224000 -0.968000 +0.050000 0.485400 -0.121900 -0.032000 0.904000 -0.408000 +0.050000 0.451900 -0.139600 -0.080000 0.232000 -0.960000 +0.000000 0.493800 -0.121900 0.128000 0.960000 -0.232000 +0.000000 0.451900 -0.135500 0.000000 0.160000 -0.984000 +-0.050000 0.500300 -0.121900 -0.104000 0.896000 -0.424000 +-0.050000 0.451900 -0.137500 0.040000 0.112000 -0.992000 +-0.100000 0.479800 -0.121900 -0.288000 0.584000 -0.752000 +-0.100000 0.451900 -0.142300 -0.128000 0.312000 -0.936000 +-0.150000 0.453400 -0.121900 -0.320000 0.624000 -0.704000 +-0.150000 0.451900 -0.123200 -0.344000 0.512000 -0.784000 +-0.152100 0.451900 -0.121900 -0.424000 0.536000 -0.720000 +-0.150000 0.401700 -0.148200 -0.240000 0.400000 -0.872000 +-0.200000 0.409200 -0.121900 -0.400000 0.464000 -0.776000 +-0.200000 0.401700 -0.127400 -0.400000 0.440000 -0.800000 +-0.208300 0.401700 -0.121900 -0.432000 0.432000 -0.784000 +-0.200000 0.351500 -0.146000 -0.416000 0.224000 -0.872000 +-0.233300 0.351500 -0.121900 -0.616000 0.184000 -0.752000 +-0.200000 0.301200 -0.154100 -0.392000 0.112000 -0.904000 +-0.245300 0.301200 -0.121900 -0.680000 0.120000 -0.720000 +-0.200000 0.251000 -0.156200 -0.432000 0.168000 -0.880000 +-0.250000 0.268200 -0.121900 -0.464000 0.088000 -0.872000 +-0.250000 0.251000 -0.124000 -0.376000 0.088000 -0.920000 +-0.254200 0.251000 -0.121900 -0.384000 0.088000 -0.912000 +-0.250000 0.200800 -0.129700 -0.392000 0.152000 -0.904000 +-0.263400 0.200800 -0.121900 -0.480000 0.216000 -0.840000 +-0.250000 0.150600 -0.154100 -0.464000 0.344000 -0.808000 +-0.295300 0.150600 -0.121900 -0.728000 0.520000 -0.432000 +-0.250000 0.100400 -0.182000 -0.504000 0.488000 -0.704000 +-0.300000 0.144000 -0.121900 -0.728000 0.496000 -0.456000 +-0.300000 0.100400 -0.141500 -0.560000 0.512000 -0.640000 +-0.250000 0.100400 -0.182000 -0.504000 0.488000 -0.704000 +-0.300000 0.052000 -0.182900 -0.664000 0.464000 -0.568000 +-0.250000 0.099600 -0.182900 -0.488000 0.616000 -0.608000 +-0.250000 0.100400 -0.182000 -0.504000 0.488000 -0.704000 +-0.249100 0.100400 -0.182900 -0.576000 0.496000 -0.640000 +-0.250000 0.150600 -0.154100 -0.464000 0.344000 -0.808000 +-0.216700 0.150600 -0.182900 -0.560000 0.376000 -0.728000 +-0.250000 0.200800 -0.129700 -0.392000 0.152000 -0.904000 +-0.200000 0.172600 -0.182900 -0.488000 0.416000 -0.760000 +-0.200000 0.200800 -0.161600 -0.480000 0.384000 -0.776000 +-0.173800 0.200800 -0.182900 -0.480000 0.344000 -0.800000 +-0.200000 0.251000 -0.156200 -0.432000 0.168000 -0.880000 +-0.153800 0.251000 -0.182900 -0.312000 0.176000 -0.928000 +-0.200000 0.301200 -0.154100 -0.392000 0.112000 -0.904000 +-0.150000 0.257900 -0.182900 -0.288000 0.168000 -0.936000 +-0.150000 0.301200 -0.169700 -0.080000 0.248000 -0.960000 +-0.100000 0.273500 -0.182900 -0.112000 0.208000 -0.968000 +-0.100000 0.301200 -0.172200 -0.168000 0.416000 -0.888000 +-0.058500 0.301200 -0.182900 -0.128000 0.320000 -0.936000 +-0.100000 0.351500 -0.158200 0.008000 0.264000 -0.960000 +-0.050000 0.304700 -0.182900 -0.120000 0.336000 -0.928000 +-0.050000 0.351500 -0.155800 -0.048000 0.328000 -0.936000 +0.000000 0.313300 -0.182900 -0.064000 0.304000 -0.944000 +0.000000 0.351500 -0.164900 -0.080000 0.368000 -0.920000 +0.050000 0.327400 -0.182900 -0.016000 0.344000 -0.936000 +0.050000 0.351500 -0.166400 0.000000 0.392000 -0.912000 +0.100000 0.320500 -0.182900 0.096000 0.312000 -0.936000 +0.100000 0.351500 -0.169000 0.056000 0.272000 -0.952000 +0.133500 0.301200 -0.182900 0.272000 0.264000 -0.920000 +0.150000 0.351500 -0.160600 0.144000 0.128000 -0.976000 +0.150000 0.301200 -0.172900 0.456000 0.432000 -0.768000 +0.200000 0.351500 -0.169700 -0.320000 0.304000 -0.888000 +0.200000 0.301200 -0.179700 -0.152000 -0.352000 -0.920000 +0.226900 0.351500 -0.182900 -0.224000 0.192000 -0.952000 +0.215700 0.301200 -0.182900 -0.120000 -0.160000 -0.976000 +0.215700 0.301200 -0.182900 -0.120000 -0.160000 -0.976000 +0.000000 0.351500 -0.051600 0.280000 -0.248000 0.920000 +0.000000 0.351500 -0.051600 0.280000 -0.248000 0.920000 +0.042100 0.351500 -0.060900 0.160000 -0.080000 0.976000 +0.000000 0.334500 -0.060900 0.312000 -0.368000 0.864000 +0.050000 0.351500 -0.062500 0.000000 -0.264000 0.960000 +0.000000 0.301200 -0.076500 0.296000 -0.272000 0.904000 +0.050000 0.301200 -0.074400 0.160000 -0.248000 0.952000 +0.000000 0.251000 -0.086600 0.344000 -0.360000 0.864000 +0.050000 0.251000 -0.100200 0.224000 -0.464000 0.848000 +0.000000 0.211400 -0.121900 0.496000 -0.712000 0.480000 +0.050000 0.230600 -0.121900 0.312000 -0.824000 0.464000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +0.050000 0.219300 -0.182900 0.280000 -0.632000 -0.712000 +0.008500 0.200800 -0.182900 0.416000 -0.688000 -0.584000 +0.050000 0.251000 -0.200200 0.040000 -0.232000 -0.968000 +0.000000 0.200800 -0.186400 0.272000 -0.456000 -0.840000 +0.000000 0.251000 -0.201400 0.024000 -0.152000 -0.984000 +-0.050000 0.200800 -0.204500 0.304000 -0.328000 -0.888000 +-0.050000 0.251000 -0.205600 -0.136000 0.216000 -0.960000 +-0.100000 0.200800 -0.221500 0.056000 0.392000 -0.912000 +-0.100000 0.251000 -0.188700 -0.192000 0.256000 -0.944000 +-0.150000 0.200800 -0.199200 -0.328000 0.272000 -0.896000 +-0.150000 0.251000 -0.184400 -0.280000 0.168000 -0.936000 +-0.173800 0.200800 -0.182900 -0.480000 0.344000 -0.800000 +-0.153800 0.251000 -0.182900 -0.312000 0.176000 -0.928000 +-0.150000 0.251000 -0.184400 -0.280000 0.168000 -0.936000 +-0.150000 0.257900 -0.182900 -0.288000 0.168000 -0.936000 +-0.100000 0.251000 -0.188700 -0.192000 0.256000 -0.944000 +-0.100000 0.273500 -0.182900 -0.112000 0.208000 -0.968000 +-0.050000 0.251000 -0.205600 -0.136000 0.216000 -0.960000 +-0.058500 0.301200 -0.182900 -0.128000 0.320000 -0.936000 +-0.050000 0.301200 -0.184300 -0.112000 0.296000 -0.944000 +-0.050000 0.304700 -0.182900 -0.120000 0.336000 -0.928000 +0.000000 0.301200 -0.186500 -0.056000 0.232000 -0.968000 +0.000000 0.313300 -0.182900 -0.064000 0.304000 -0.944000 +0.050000 0.301200 -0.192400 0.024000 0.192000 -0.976000 +0.050000 0.327400 -0.182900 -0.016000 0.344000 -0.936000 +0.100000 0.301200 -0.188500 0.112000 0.128000 -0.984000 +0.100000 0.320500 -0.182900 0.096000 0.312000 -0.936000 +0.133500 0.301200 -0.182900 0.272000 0.264000 -0.920000 +0.133500 0.301200 -0.182900 0.272000 0.264000 -0.920000 +0.000000 -0.301200 -0.001900 0.408000 -0.704000 0.568000 +0.000000 -0.301200 -0.001900 0.408000 -0.704000 0.568000 +0.032200 -0.301200 -0.060900 0.552000 -0.696000 0.448000 +0.000000 -0.326800 -0.060900 0.344000 -0.824000 0.432000 +0.000000 -0.326800 -0.060900 0.344000 -0.824000 0.432000 +0.065700 0.351500 -0.060900 -0.064000 -0.312000 0.944000 +0.065700 0.351500 -0.060900 -0.064000 -0.312000 0.944000 +0.100000 0.368600 -0.060900 0.104000 0.120000 0.984000 +0.100000 0.351500 -0.058100 0.120000 -0.240000 0.960000 +0.111400 0.351500 -0.060900 0.184000 -0.224000 0.952000 +0.100000 0.345700 -0.060900 0.056000 -0.392000 0.912000 +0.100000 0.351500 -0.058100 0.120000 -0.240000 0.960000 +0.065700 0.351500 -0.060900 -0.064000 -0.312000 0.944000 +0.100000 0.345700 -0.060900 0.056000 -0.392000 0.912000 +0.050000 0.351500 -0.062500 0.000000 -0.264000 0.960000 +0.100000 0.301200 -0.081200 0.144000 -0.392000 0.904000 +0.050000 0.301200 -0.074400 0.160000 -0.248000 0.952000 +0.100000 0.251000 -0.119300 0.048000 -0.664000 0.736000 +0.050000 0.251000 -0.100200 0.224000 -0.464000 0.848000 +0.100000 0.248700 -0.121900 0.064000 -0.824000 0.552000 +0.050000 0.230600 -0.121900 0.312000 -0.824000 0.464000 +0.100000 0.246100 -0.182900 0.136000 -0.488000 -0.856000 +0.050000 0.219300 -0.182900 0.280000 -0.632000 -0.712000 +0.100000 0.251000 -0.185300 0.160000 -0.296000 -0.936000 +0.050000 0.251000 -0.200200 0.040000 -0.232000 -0.968000 +0.100000 0.301200 -0.188500 0.112000 0.128000 -0.984000 +0.050000 0.301200 -0.192400 0.024000 0.192000 -0.976000 +0.050000 0.251000 -0.200200 0.040000 -0.232000 -0.968000 +0.000000 0.301200 -0.186500 -0.056000 0.232000 -0.968000 +0.000000 0.251000 -0.201400 0.024000 -0.152000 -0.984000 +-0.050000 0.301200 -0.184300 -0.112000 0.296000 -0.944000 +-0.050000 0.251000 -0.205600 -0.136000 0.216000 -0.960000 +-0.050000 0.251000 -0.205600 -0.136000 0.216000 -0.960000 +0.150000 0.456100 -0.060900 0.048000 0.664000 0.736000 +0.150000 0.456100 -0.060900 0.048000 0.664000 0.736000 +0.150000 0.451900 -0.057100 -0.080000 0.496000 0.856000 +0.121900 0.451900 -0.060900 -0.112000 0.472000 0.872000 +0.150000 0.409600 -0.060900 -0.208000 -0.072000 0.968000 +0.100000 0.451900 -0.066700 -0.192000 0.072000 0.976000 +0.150000 0.401700 -0.062100 -0.392000 -0.400000 0.816000 +0.100000 0.401700 -0.066700 -0.048000 0.000000 0.992000 +0.100000 0.451900 -0.066700 -0.192000 0.072000 0.976000 +0.050000 0.401700 -0.062500 -0.008000 0.136000 0.984000 +0.050000 0.451900 -0.077800 0.016000 0.408000 0.912000 +0.000000 0.401700 -0.062800 0.256000 0.176000 0.944000 +0.000000 0.451900 -0.081100 0.280000 0.456000 0.832000 +-0.005200 0.401700 -0.060900 0.264000 0.168000 0.944000 +-0.023600 0.451900 -0.060900 0.376000 0.152000 0.904000 +0.000000 0.451900 -0.081100 0.280000 0.456000 0.832000 +-0.033200 0.502100 -0.060900 0.616000 0.496000 0.600000 +0.000000 0.493800 -0.121900 0.128000 0.960000 -0.232000 +-0.050000 0.502100 -0.117100 -0.040000 0.912000 -0.392000 +-0.050000 0.500300 -0.121900 -0.104000 0.896000 -0.424000 +-0.100000 0.502100 -0.081300 -0.184000 0.840000 -0.488000 +-0.100000 0.479800 -0.121900 -0.288000 0.584000 -0.752000 +-0.100000 0.479800 -0.121900 -0.288000 0.584000 -0.752000 +0.350000 0.302200 -0.060900 -0.144000 -0.624000 0.760000 +0.350000 0.302200 -0.060900 -0.144000 -0.624000 0.760000 +0.300000 0.310700 -0.060900 -0.072000 -0.760000 0.640000 +0.350000 0.351500 -0.021800 0.032000 -0.048000 0.992000 +0.300000 0.351500 -0.009100 -0.016000 -0.144000 0.984000 +0.300000 0.351500 -0.009100 -0.016000 -0.144000 0.984000 +0.395100 0.251000 -0.060900 -0.344000 -0.184000 0.912000 +0.395100 0.251000 -0.060900 -0.344000 -0.184000 0.912000 +0.400000 0.251000 -0.058700 -0.328000 -0.176000 0.920000 +0.400000 0.242400 -0.060900 -0.352000 -0.192000 0.904000 +0.400000 0.242400 -0.060900 -0.352000 -0.192000 0.904000 +0.450000 0.401700 -0.038900 -0.120000 0.592000 0.784000 +0.450000 0.401700 -0.038900 -0.120000 0.592000 0.784000 +0.500000 0.401700 -0.057700 0.096000 0.864000 0.480000 +0.450000 0.414500 -0.060900 0.192000 0.928000 0.304000 +0.500000 0.403100 -0.060900 0.112000 0.944000 0.280000 +0.450000 0.422200 -0.121900 0.368000 0.832000 -0.392000 +0.500000 0.401700 -0.069300 0.168000 0.952000 -0.216000 +0.488600 0.401700 -0.121900 0.504000 0.776000 -0.368000 +0.450000 0.422200 -0.121900 0.368000 0.832000 -0.392000 +0.450000 0.401700 -0.160800 0.376000 0.656000 -0.640000 +0.450000 0.401700 -0.160800 0.376000 0.656000 -0.640000 +0.460500 0.150600 -0.060900 -0.624000 -0.512000 0.584000 +0.460500 0.150600 -0.060900 -0.624000 -0.512000 0.584000 +0.500000 0.150600 -0.020200 -0.704000 -0.472000 0.520000 +0.500000 0.107000 -0.060900 -0.608000 -0.480000 0.616000 +0.500000 0.107000 -0.060900 -0.608000 -0.480000 0.616000 +0.500000 0.000000 -0.045100 -0.376000 -0.208000 0.896000 +0.500000 0.000000 -0.045100 -0.376000 -0.208000 0.896000 +0.500000 0.050200 -0.057700 -0.560000 0.128000 0.816000 +0.478700 0.000000 -0.060900 -0.440000 -0.008000 0.888000 +0.495100 0.050200 -0.060900 -0.456000 0.136000 0.872000 +0.450000 0.000000 -0.073300 -0.344000 -0.088000 0.928000 +0.450000 0.050200 -0.077000 -0.360000 0.120000 0.920000 +0.400000 0.000000 -0.102200 -0.272000 0.176000 0.936000 +0.400000 0.050200 -0.114800 -0.552000 0.256000 0.784000 +0.351500 0.000000 -0.121900 -0.376000 0.528000 0.752000 +0.393200 0.050200 -0.121900 -0.648000 0.352000 0.664000 +0.350000 0.000000 -0.123200 -0.512000 0.592000 0.608000 +0.357200 0.050200 -0.182900 -0.736000 0.640000 0.184000 +0.350000 0.043300 -0.182900 -0.488000 0.704000 0.504000 +0.351400 0.050200 -0.243900 -0.480000 0.768000 -0.416000 +0.350000 0.049300 -0.243900 -0.512000 0.784000 -0.320000 +0.350000 0.043300 -0.182900 -0.488000 0.704000 0.504000 +0.300000 0.032100 -0.243900 -0.576000 0.680000 -0.432000 +0.300000 0.018000 -0.182900 -0.296000 0.768000 0.552000 +0.350000 0.043300 -0.182900 -0.488000 0.704000 0.504000 +0.300000 0.000000 -0.166100 -0.488000 0.464000 0.728000 +0.350000 0.000000 -0.123200 -0.512000 0.592000 0.608000 +0.300000 -0.050200 -0.130700 -0.504000 0.472000 0.720000 +0.350000 -0.001200 -0.121900 -0.472000 0.472000 0.736000 +0.307700 -0.050200 -0.121900 -0.592000 0.464000 0.648000 +0.350000 -0.050200 -0.093300 -0.312000 0.392000 0.856000 +0.300000 -0.060700 -0.121900 -0.512000 0.456000 0.720000 +0.350000 -0.100400 -0.081200 -0.280000 0.032000 0.952000 +0.300000 -0.100400 -0.098900 -0.360000 0.344000 0.856000 +0.350000 -0.150600 -0.101500 0.088000 -0.352000 0.928000 +0.300000 -0.150600 -0.090800 0.240000 -0.024000 0.968000 +0.350000 -0.182300 -0.121900 -0.032000 -0.520000 0.848000 +0.300000 -0.200800 -0.101500 0.424000 -0.216000 0.872000 +0.329200 -0.200800 -0.121900 0.376000 -0.264000 0.880000 +0.300000 -0.234400 -0.121900 0.104000 -0.472000 0.872000 +0.350000 -0.200800 -0.137500 0.248000 -0.232000 0.936000 +0.300000 -0.251000 -0.132800 -0.224000 -0.464000 0.856000 +0.350000 -0.234100 -0.121900 0.384000 0.224000 0.888000 +0.328900 -0.251000 -0.121900 -0.264000 -0.304000 0.912000 +0.350000 -0.251000 -0.114600 0.576000 -0.200000 0.784000 +0.350000 -0.260400 -0.121900 0.448000 -0.472000 0.752000 +0.354900 -0.251000 -0.121900 0.704000 -0.304000 0.632000 +0.350000 -0.251000 -0.114600 0.576000 -0.200000 0.784000 +0.350000 -0.234100 -0.121900 0.384000 0.224000 0.888000 +0.354900 -0.251000 -0.121900 0.704000 -0.304000 0.632000 +0.350000 -0.200800 -0.137500 0.248000 -0.232000 0.936000 +0.400000 -0.203000 -0.121900 -0.184000 -0.672000 0.712000 +0.391400 -0.200800 -0.121900 -0.176000 -0.648000 0.736000 +0.400000 -0.200800 -0.119100 -0.200000 -0.688000 0.688000 +0.350000 -0.182300 -0.121900 -0.032000 -0.520000 0.848000 +0.400000 -0.150600 -0.068400 -0.344000 -0.312000 0.880000 +0.350000 -0.150600 -0.101500 0.088000 -0.352000 0.928000 +0.400000 -0.100400 -0.080400 -0.024000 0.176000 0.976000 +0.350000 -0.100400 -0.081200 -0.280000 0.032000 0.952000 +0.400000 -0.050200 -0.089900 -0.128000 0.176000 0.968000 +0.350000 -0.050200 -0.093300 -0.312000 0.392000 0.856000 +0.400000 0.000000 -0.102200 -0.272000 0.176000 0.936000 +0.350000 -0.001200 -0.121900 -0.472000 0.472000 0.736000 +0.351500 0.000000 -0.121900 -0.376000 0.528000 0.752000 +0.350000 0.000000 -0.123200 -0.512000 0.592000 0.608000 +0.350000 0.000000 -0.123200 -0.512000 0.592000 0.608000 +0.478700 0.000000 -0.060900 -0.440000 -0.008000 0.888000 +0.478700 0.000000 -0.060900 -0.440000 -0.008000 0.888000 +0.500000 0.000000 -0.045100 -0.376000 -0.208000 0.896000 +0.500000 -0.026100 -0.060900 -0.336000 -0.328000 0.872000 +0.550000 0.000000 -0.046900 0.008000 -0.120000 0.992000 +0.550000 -0.046200 -0.060900 -0.104000 -0.168000 0.976000 +0.600000 0.000000 -0.044900 -0.016000 -0.720000 0.688000 +0.600000 -0.012300 -0.060900 0.104000 -0.576000 0.800000 +0.550000 -0.046200 -0.060900 -0.104000 -0.168000 0.976000 +0.600000 -0.050200 -0.088500 0.448000 -0.400000 0.792000 +0.550000 -0.050200 -0.061500 -0.064000 -0.152000 0.984000 +0.600000 -0.100400 -0.077400 0.584000 0.048000 0.800000 +0.550000 -0.100400 -0.076900 0.056000 0.056000 0.992000 +0.550000 -0.050200 -0.061500 -0.064000 -0.152000 0.984000 +0.500000 -0.100400 -0.086800 -0.048000 0.256000 0.960000 +0.500000 -0.050200 -0.068900 -0.136000 -0.144000 0.976000 +0.450000 -0.100400 -0.078400 -0.088000 0.200000 0.968000 +0.450000 -0.050200 -0.086300 -0.128000 -0.040000 0.984000 +0.400000 -0.100400 -0.080400 -0.024000 0.176000 0.976000 +0.400000 -0.050200 -0.089900 -0.128000 0.176000 0.968000 +0.450000 -0.050200 -0.086300 -0.128000 -0.040000 0.984000 +0.400000 0.000000 -0.102200 -0.272000 0.176000 0.936000 +0.450000 0.000000 -0.073300 -0.344000 -0.088000 0.928000 +0.450000 -0.050200 -0.086300 -0.128000 -0.040000 0.984000 +0.478700 0.000000 -0.060900 -0.440000 -0.008000 0.888000 +0.500000 -0.050200 -0.068900 -0.136000 -0.144000 0.976000 +0.500000 -0.026100 -0.060900 -0.336000 -0.328000 0.872000 +0.550000 -0.050200 -0.061500 -0.064000 -0.152000 0.984000 +0.550000 -0.046200 -0.060900 -0.104000 -0.168000 0.976000 +0.550000 -0.046200 -0.060900 -0.104000 -0.168000 0.976000 +0.500000 0.401700 -0.057700 0.096000 0.864000 0.480000 +0.500000 0.401700 -0.057700 0.096000 0.864000 0.480000 +0.500000 0.403100 -0.060900 0.112000 0.944000 0.280000 +0.517100 0.401700 -0.060900 0.080000 0.968000 0.224000 +0.500000 0.401700 -0.069300 0.168000 0.952000 -0.216000 +0.500000 0.401700 -0.069300 0.168000 0.952000 -0.216000 +0.500000 0.266900 0.000000 -0.760000 -0.040000 0.640000 +0.500000 0.266900 0.000000 -0.760000 -0.040000 0.640000 +0.500800 0.251000 0.000000 -0.792000 -0.016000 0.608000 +0.500000 0.251000 -0.000900 -0.496000 0.112000 0.856000 +0.500000 0.251000 -0.000900 -0.496000 0.112000 0.856000 +0.500000 0.050200 -0.057700 -0.560000 0.128000 0.816000 +0.500000 0.050200 -0.057700 -0.560000 0.128000 0.816000 +0.500000 0.000000 -0.045100 -0.376000 -0.208000 0.896000 +0.550000 0.050200 -0.037800 -0.320000 -0.688000 0.640000 +0.550000 0.000000 -0.046900 0.008000 -0.120000 0.992000 +0.600000 0.050200 -0.005300 -0.440000 -0.752000 0.480000 +0.600000 0.000000 -0.044900 -0.016000 -0.720000 0.688000 +0.600000 0.000000 -0.044900 -0.016000 -0.720000 0.688000 +0.550000 0.104000 0.000000 -0.664000 -0.568000 0.464000 +0.550000 0.104000 0.000000 -0.664000 -0.568000 0.464000 +0.553100 0.100400 0.000000 -0.664000 -0.576000 0.464000 +0.550000 0.100400 -0.005700 -0.672000 -0.576000 0.448000 +0.550000 0.100400 -0.005700 -0.672000 -0.576000 0.448000 +0.550000 -0.200800 -0.034900 0.016000 -0.040000 0.992000 +0.550000 -0.200800 -0.034900 0.016000 -0.040000 0.992000 +0.600000 -0.200800 -0.056500 0.336000 0.448000 0.816000 +0.550000 -0.159500 -0.060900 0.248000 0.472000 0.840000 +0.600000 -0.194800 -0.060900 0.352000 0.496000 0.784000 +0.550000 -0.150600 -0.067100 0.240000 0.480000 0.840000 +0.600000 -0.150600 -0.093600 0.304000 0.568000 0.752000 +0.600000 -0.194800 -0.060900 0.352000 0.496000 0.784000 +0.650000 -0.150600 -0.116200 0.720000 0.480000 0.488000 +0.608400 -0.200800 -0.060900 0.360000 0.488000 0.792000 +0.650000 -0.200800 -0.092600 0.656000 0.384000 0.640000 +0.650000 -0.242600 -0.060900 0.392000 0.384000 0.824000 +0.677400 -0.200800 -0.121900 0.528000 0.512000 0.672000 +0.657600 -0.251000 -0.060900 0.456000 -0.072000 0.880000 +0.700000 -0.217500 -0.121900 0.616000 0.552000 0.544000 +0.700000 -0.251000 -0.086700 0.608000 0.464000 0.632000 +0.719200 -0.251000 -0.121900 0.760000 0.456000 0.440000 +0.700000 -0.301200 -0.068800 0.336000 0.392000 0.848000 +0.750000 -0.297400 -0.121900 0.656000 0.584000 0.464000 +0.750000 -0.301200 -0.116500 0.704000 0.400000 0.568000 +0.752700 -0.301200 -0.121900 0.792000 0.344000 0.488000 +0.750000 -0.351500 -0.097900 0.640000 0.048000 0.760000 +0.775700 -0.351500 -0.121900 0.600000 0.328000 0.720000 +0.750000 -0.401700 -0.115900 -0.264000 -0.344000 0.896000 +0.800000 -0.391100 -0.121900 0.384000 0.416000 0.816000 +0.800000 -0.401700 -0.115500 0.392000 0.184000 0.896000 +0.810500 -0.401700 -0.121900 0.456000 0.104000 0.872000 +0.800000 -0.418600 -0.121900 0.304000 -0.320000 0.888000 +0.850000 -0.401700 -0.151500 0.608000 0.552000 0.560000 +0.800000 -0.451900 -0.135400 0.168000 -0.384000 0.904000 +0.850000 -0.451900 -0.123600 0.328000 0.296000 0.888000 +0.800000 -0.502100 -0.171200 -0.360000 -0.648000 0.664000 +0.850000 -0.502100 -0.142100 -0.224000 -0.520000 0.816000 +0.800000 -0.511100 -0.182900 -0.376000 -0.744000 0.544000 +0.850000 -0.533300 -0.182900 -0.416000 -0.736000 0.528000 +0.800000 -0.519900 -0.243900 -0.400000 -0.904000 -0.112000 +0.850000 -0.540400 -0.243900 -0.360000 -0.768000 -0.512000 +0.800000 -0.502100 -0.293400 -0.120000 -0.840000 -0.520000 +0.850000 -0.504700 -0.304800 -0.096000 -0.664000 -0.736000 +0.832800 -0.502100 -0.304800 -0.104000 -0.544000 -0.824000 +0.850000 -0.502100 -0.307100 0.032000 -0.240000 -0.968000 +0.850000 -0.490600 -0.304800 0.216000 0.112000 -0.968000 +0.856800 -0.502100 -0.304800 0.288000 0.144000 -0.944000 +0.850000 -0.451900 -0.293100 0.448000 0.248000 -0.848000 +0.900000 -0.502100 -0.284600 -0.008000 -0.096000 -0.992000 +0.900000 -0.451900 -0.272400 0.368000 0.408000 -0.824000 +0.950000 -0.502100 -0.277800 0.272000 0.288000 -0.912000 +0.950000 -0.451900 -0.300000 0.488000 0.464000 -0.728000 +1.000000 -0.502100 -0.271100 0.392000 0.584000 -0.696000 +0.980700 -0.451900 -0.243900 0.752000 0.648000 0.032000 +1.000000 -0.475100 -0.243900 0.736000 0.608000 -0.280000 +0.950000 -0.451900 -0.206400 0.504000 0.736000 0.440000 +1.000000 -0.502100 -0.189300 0.760000 0.568000 0.296000 +0.950000 -0.463500 -0.182900 0.464000 0.672000 0.568000 +0.998000 -0.502100 -0.182900 0.528000 0.664000 0.520000 +0.950000 -0.502100 -0.136000 -0.296000 0.400000 0.864000 +1.000000 -0.503200 -0.182900 0.400000 0.704000 0.576000 +0.950000 -0.531200 -0.121900 -0.376000 0.368000 0.840000 +1.000000 -0.544400 -0.121900 0.360000 0.712000 0.592000 +0.950000 -0.552300 -0.115100 -0.432000 -0.368000 0.816000 +1.000000 -0.552300 -0.111000 0.040000 -0.024000 0.992000 +0.950000 -0.560000 -0.121900 -0.400000 -0.536000 0.728000 +1.000000 -0.602500 -0.115100 -0.504000 -0.464000 0.712000 +0.992300 -0.602500 -0.121900 -0.520000 -0.480000 0.696000 +1.000000 -0.611000 -0.121900 -0.528000 -0.480000 0.696000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +1.000000 -0.652700 -0.168000 -0.488000 -0.568000 0.656000 +0.950000 -0.619400 -0.182900 -0.632000 -0.592000 0.480000 +0.983200 -0.652700 -0.182900 -0.528000 -0.608000 0.584000 +0.950000 -0.619400 -0.243900 -0.600000 -0.584000 -0.536000 +0.979500 -0.652700 -0.243900 -0.672000 -0.664000 -0.304000 +0.950000 -0.602500 -0.260200 -0.544000 -0.504000 -0.664000 +1.000000 -0.652700 -0.268800 -0.592000 -0.512000 -0.608000 +0.990600 -0.602500 -0.304800 -0.488000 -0.376000 -0.784000 +1.000000 -0.614600 -0.304800 -0.488000 -0.376000 -0.776000 +1.000000 -0.602500 -0.311200 -0.448000 -0.336000 -0.816000 +0.990600 -0.602500 -0.304800 -0.488000 -0.376000 -0.784000 +1.000000 -0.552300 -0.319800 -0.248000 0.216000 -0.936000 +0.953900 -0.552300 -0.304800 -0.328000 0.312000 -0.888000 +1.000000 -0.525900 -0.304800 -0.248000 0.496000 -0.824000 +0.950000 -0.552300 -0.303200 -0.304000 0.392000 -0.864000 +1.000000 -0.502100 -0.271100 0.392000 0.584000 -0.696000 +0.950000 -0.502100 -0.277800 0.272000 0.288000 -0.912000 +0.950000 -0.552300 -0.303200 -0.304000 0.392000 -0.864000 +0.900000 -0.502100 -0.284600 -0.008000 -0.096000 -0.992000 +0.900000 -0.552300 -0.278500 -0.424000 -0.592000 -0.672000 +0.856800 -0.502100 -0.304800 0.288000 0.144000 -0.944000 +0.868400 -0.552300 -0.243900 -0.552000 -0.760000 -0.328000 +0.850000 -0.504700 -0.304800 -0.096000 -0.664000 -0.736000 +0.850000 -0.540400 -0.243900 -0.360000 -0.768000 -0.512000 +0.868400 -0.552300 -0.243900 -0.552000 -0.760000 -0.328000 +0.850000 -0.533300 -0.182900 -0.416000 -0.736000 0.528000 +0.876500 -0.552300 -0.182900 -0.528000 -0.672000 0.504000 +0.850000 -0.502100 -0.142100 -0.224000 -0.520000 0.816000 +0.900000 -0.552300 -0.159100 -0.496000 -0.592000 0.632000 +0.900000 -0.502100 -0.123800 -0.168000 -0.208000 0.960000 +0.940600 -0.552300 -0.121900 -0.512000 -0.272000 0.808000 +0.950000 -0.502100 -0.136000 -0.296000 0.400000 0.864000 +0.950000 -0.531200 -0.121900 -0.376000 0.368000 0.840000 +0.940600 -0.552300 -0.121900 -0.512000 -0.272000 0.808000 +0.950000 -0.552300 -0.115100 -0.432000 -0.368000 0.816000 +0.950000 -0.560000 -0.121900 -0.400000 -0.536000 0.728000 +0.940600 -0.552300 -0.121900 -0.512000 -0.272000 0.808000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +0.900000 -0.552300 -0.159100 -0.496000 -0.592000 0.632000 +0.935000 -0.602500 -0.182900 -0.552000 -0.552000 0.608000 +0.900000 -0.573700 -0.182900 -0.608000 -0.704000 0.344000 +0.933200 -0.602500 -0.243900 -0.584000 -0.624000 -0.512000 +0.900000 -0.578300 -0.243900 -0.552000 -0.704000 -0.440000 +0.950000 -0.602500 -0.260200 -0.544000 -0.504000 -0.664000 +0.900000 -0.552300 -0.278500 -0.424000 -0.592000 -0.672000 +0.950000 -0.552300 -0.303200 -0.304000 0.392000 -0.864000 +0.950000 -0.602500 -0.260200 -0.544000 -0.504000 -0.664000 +0.953900 -0.552300 -0.304800 -0.328000 0.312000 -0.888000 +0.990600 -0.602500 -0.304800 -0.488000 -0.376000 -0.784000 +0.990600 -0.602500 -0.304800 -0.488000 -0.376000 -0.784000 +0.550000 -0.242100 -0.060900 -0.400000 -0.536000 0.736000 +0.550000 -0.242100 -0.060900 -0.400000 -0.536000 0.736000 +0.550000 -0.200800 -0.034900 0.016000 -0.040000 0.992000 +0.562800 -0.251000 -0.060900 -0.368000 -0.568000 0.720000 +0.600000 -0.200800 -0.056500 0.336000 0.448000 0.816000 +0.600000 -0.251000 -0.042400 -0.104000 -0.208000 0.968000 +0.608400 -0.200800 -0.060900 0.360000 0.488000 0.792000 +0.650000 -0.251000 -0.056300 0.424000 -0.024000 0.896000 +0.650000 -0.242600 -0.060900 0.392000 0.384000 0.824000 +0.657600 -0.251000 -0.060900 0.456000 -0.072000 0.880000 +0.650000 -0.251000 -0.056300 0.424000 -0.024000 0.896000 +0.650000 -0.258100 -0.060900 0.392000 -0.456000 0.792000 +0.600000 -0.251000 -0.042400 -0.104000 -0.208000 0.968000 +0.600000 -0.272000 -0.060900 -0.264000 -0.632000 0.720000 +0.562800 -0.251000 -0.060900 -0.368000 -0.568000 0.720000 +0.600000 -0.301200 -0.098800 -0.176000 -0.576000 0.792000 +0.550000 -0.251000 -0.069700 -0.416000 -0.584000 0.688000 +0.552600 -0.301200 -0.121900 -0.368000 -0.384000 0.840000 +0.550000 -0.300100 -0.121900 -0.624000 -0.616000 0.472000 +0.550000 -0.301200 -0.123600 -0.624000 -0.440000 0.632000 +0.552600 -0.301200 -0.121900 -0.368000 -0.384000 0.840000 +0.550000 -0.317100 -0.121900 -0.368000 0.064000 0.920000 +0.600000 -0.333000 -0.121900 0.024000 -0.312000 0.944000 +0.558500 -0.351500 -0.121900 0.208000 -0.648000 0.728000 +0.600000 -0.351500 -0.136300 0.144000 -0.792000 0.584000 +0.550000 -0.353000 -0.121900 -0.032000 -0.832000 0.536000 +0.600000 -0.392700 -0.182900 -0.184000 -0.752000 0.624000 +0.550000 -0.389500 -0.182900 -0.304000 -0.784000 0.528000 +0.600000 -0.401700 -0.203000 -0.208000 -0.872000 0.432000 +0.550000 -0.401700 -0.218900 -0.128000 -0.904000 0.392000 +0.600000 -0.414700 -0.243900 -0.184000 -0.936000 0.272000 +0.550000 -0.409700 -0.243900 -0.144000 -0.944000 0.272000 +0.600000 -0.422100 -0.304800 -0.120000 -0.768000 -0.616000 +0.550000 -0.415900 -0.304800 -0.192000 -0.848000 -0.480000 +0.600000 -0.401700 -0.327900 -0.024000 -0.544000 -0.832000 +0.550000 -0.401700 -0.333700 -0.144000 -0.688000 -0.704000 +0.600000 -0.351500 -0.337900 0.040000 -0.080000 -0.992000 +0.550000 -0.351500 -0.364500 0.120000 -0.104000 -0.984000 +0.600000 -0.301200 -0.352300 -0.528000 -0.312000 -0.776000 +0.550000 -0.316300 -0.304800 -0.472000 0.688000 -0.536000 +0.567500 -0.301200 -0.304800 -0.696000 0.400000 -0.584000 +0.550000 -0.301200 -0.279200 -0.712000 0.120000 -0.680000 +0.550000 -0.272400 -0.304800 -0.680000 -0.440000 -0.576000 +0.550000 -0.272400 -0.304800 -0.680000 -0.440000 -0.576000 +0.616700 0.401700 0.000000 0.496000 0.864000 -0.032000 +0.616700 0.401700 0.000000 0.496000 0.864000 -0.032000 +0.650000 0.368200 0.000000 0.792000 0.584000 -0.144000 +0.600000 0.401700 -0.057700 0.168000 0.920000 -0.344000 +0.650000 0.351500 -0.057700 0.800000 0.552000 -0.208000 +0.600000 0.400600 -0.060900 -0.072000 0.912000 -0.384000 +0.648900 0.351500 -0.060900 0.576000 0.600000 -0.544000 +0.600000 0.351500 -0.101600 0.448000 0.496000 -0.736000 +0.650000 0.350500 -0.060900 0.712000 0.536000 -0.440000 +0.600000 0.310600 -0.121900 0.480000 0.424000 -0.760000 +0.650000 0.301200 -0.100800 0.528000 0.504000 -0.672000 +0.608400 0.301200 -0.121900 0.448000 0.488000 -0.744000 +0.600000 0.310600 -0.121900 0.480000 0.424000 -0.760000 +0.600000 0.301200 -0.128700 0.472000 0.520000 -0.704000 +0.600000 0.301200 -0.128700 0.472000 0.520000 -0.704000 +0.648900 0.351500 -0.060900 0.576000 0.600000 -0.544000 +0.648900 0.351500 -0.060900 0.576000 0.600000 -0.544000 +0.650000 0.350500 -0.060900 0.712000 0.536000 -0.440000 +0.650000 0.351500 -0.057700 0.800000 0.552000 -0.208000 +0.680100 0.301200 -0.060900 0.752000 0.544000 -0.368000 +0.660900 0.351500 0.000000 0.832000 0.512000 -0.176000 +0.685300 0.301200 0.000000 0.832000 0.536000 -0.104000 +0.680100 0.301200 -0.060900 0.752000 0.544000 -0.368000 +0.700000 0.279600 0.000000 0.792000 0.600000 -0.048000 +0.700000 0.278700 -0.060900 0.648000 0.584000 -0.472000 +0.700000 0.278700 -0.060900 0.648000 0.584000 -0.472000 +0.600000 -0.194800 -0.060900 0.352000 0.496000 0.784000 +0.600000 -0.194800 -0.060900 0.352000 0.496000 0.784000 +0.608400 -0.200800 -0.060900 0.360000 0.488000 0.792000 +0.600000 -0.200800 -0.056500 0.336000 0.448000 0.816000 +0.600000 -0.200800 -0.056500 0.336000 0.448000 0.816000 +0.650000 0.368200 0.000000 0.792000 0.584000 -0.144000 +0.650000 0.368200 0.000000 0.792000 0.584000 -0.144000 +0.650000 0.351500 -0.057700 0.800000 0.552000 -0.208000 +0.660900 0.351500 0.000000 0.832000 0.512000 -0.176000 +0.660900 0.351500 0.000000 0.832000 0.512000 -0.176000 +0.650000 0.000000 -0.040500 0.104000 -0.944000 0.296000 +0.650000 0.000000 -0.040500 0.104000 -0.944000 0.296000 +0.686800 0.000000 -0.060900 0.208000 -0.960000 0.144000 +0.650000 -0.010200 -0.060900 0.168000 -0.784000 0.592000 +0.698200 0.000000 -0.121900 0.296000 -0.952000 0.032000 +0.650000 -0.033500 -0.121900 0.512000 -0.672000 0.520000 +0.687300 0.000000 -0.182900 0.648000 -0.600000 -0.456000 +0.650000 -0.048900 -0.182900 0.792000 -0.584000 0.152000 +0.653800 0.000000 -0.243900 0.576000 -0.112000 -0.808000 +0.650000 -0.016900 -0.243900 0.704000 -0.184000 -0.672000 +0.650000 -0.048900 -0.182900 0.792000 -0.584000 0.152000 +0.637200 -0.050200 -0.243900 0.840000 -0.080000 -0.528000 +0.649100 -0.050200 -0.182900 0.816000 -0.544000 0.144000 +0.650000 -0.048900 -0.182900 0.792000 -0.584000 0.152000 +0.638000 -0.050200 -0.121900 0.800000 -0.536000 0.256000 +0.650000 -0.033500 -0.121900 0.512000 -0.672000 0.520000 +0.650000 -0.033500 -0.121900 0.512000 -0.672000 0.520000 +0.800000 -0.015400 0.000000 -0.560000 -0.800000 0.184000 +0.800000 -0.015400 0.000000 -0.560000 -0.800000 0.184000 +0.772100 0.000000 0.000000 -0.504000 -0.832000 0.224000 +0.800000 -0.024700 -0.060900 -0.616000 -0.776000 0.088000 +0.753100 0.000000 -0.060900 -0.472000 -0.872000 0.000000 +0.800000 -0.027900 -0.121900 -0.664000 -0.736000 -0.072000 +0.756600 0.000000 -0.121900 -0.496000 -0.856000 -0.080000 +0.800000 -0.017800 -0.182900 -0.616000 -0.680000 -0.376000 +0.776700 0.000000 -0.182900 -0.576000 -0.728000 -0.360000 +0.800000 0.000000 -0.217200 -0.656000 -0.464000 -0.584000 +0.800000 0.000000 -0.217200 -0.656000 -0.464000 -0.584000 +0.900000 0.131100 0.000000 0.480000 0.848000 0.192000 +0.900000 0.131100 0.000000 0.480000 0.848000 0.192000 +0.950000 0.102000 0.000000 0.472000 0.864000 0.120000 +0.900000 0.143500 -0.060900 0.528000 0.808000 -0.240000 +0.950000 0.106300 -0.060900 0.576000 0.776000 -0.240000 +0.900000 0.127900 -0.121900 0.560000 0.776000 -0.264000 +0.950000 0.100400 -0.078300 0.560000 0.768000 -0.304000 +0.931600 0.100400 -0.121900 0.600000 0.744000 -0.272000 +0.950000 0.086300 -0.121900 0.544000 0.784000 -0.280000 +0.912000 0.100400 -0.182900 0.600000 0.704000 -0.360000 +0.950000 0.069900 -0.182900 0.544000 0.736000 -0.392000 +0.900000 0.100400 -0.203200 0.536000 0.688000 -0.472000 +0.950000 0.050200 -0.224500 0.472000 0.712000 -0.504000 +0.900000 0.070800 -0.243900 -0.096000 0.744000 -0.656000 +0.929600 0.050200 -0.243900 0.432000 0.672000 -0.584000 +0.900000 0.050200 -0.268900 0.208000 0.672000 -0.696000 +0.950000 0.037500 -0.243900 0.432000 0.688000 -0.576000 +0.900000 0.016700 -0.304800 -0.152000 0.720000 -0.664000 +0.950000 0.000000 -0.291100 0.424000 0.536000 -0.720000 +0.927400 0.000000 -0.304800 0.400000 0.560000 -0.720000 +0.950000 -0.016600 -0.304800 0.448000 0.520000 -0.720000 +0.900000 0.000000 -0.329500 -0.080000 0.648000 -0.744000 +0.950000 -0.050200 -0.338500 0.440000 0.400000 -0.800000 +0.900000 -0.050200 -0.348300 -0.256000 0.192000 -0.944000 +0.950000 -0.100400 -0.351000 0.336000 0.064000 -0.936000 +0.900000 -0.100400 -0.341700 -0.464000 -0.104000 -0.872000 +0.950000 -0.150600 -0.345500 -0.032000 0.064000 -0.992000 +0.900000 -0.150600 -0.332000 -0.672000 -0.328000 -0.656000 +0.900000 -0.150600 -0.332000 -0.672000 -0.328000 -0.656000 +0.995800 -0.200800 0.000000 -0.648000 -0.704000 0.264000 +0.995800 -0.200800 0.000000 -0.648000 -0.704000 0.264000 +0.950000 -0.168100 0.000000 -0.640000 -0.744000 0.184000 +0.973000 -0.200800 -0.060900 -0.584000 -0.760000 0.264000 +0.950000 -0.183700 -0.060900 -0.632000 -0.728000 0.232000 +0.950500 -0.200800 -0.121900 -0.632000 -0.744000 0.192000 +0.950000 -0.200400 -0.121900 -0.720000 -0.672000 0.136000 +0.950000 -0.200800 -0.124000 -0.680000 -0.712000 0.160000 +0.950000 -0.200800 -0.124000 -0.680000 -0.712000 0.160000 +-0.910500 0.251000 -0.121900 0.344000 0.880000 -0.304000 +-0.910500 0.251000 -0.121900 0.344000 0.880000 -0.304000 +-0.900000 0.246900 -0.121900 0.360000 0.872000 -0.304000 +-0.900000 0.251000 -0.101700 0.376000 0.896000 -0.216000 +-0.900000 0.251000 -0.101700 0.376000 0.896000 -0.216000 +-0.900000 -0.502100 -0.104000 -0.752000 0.000000 0.656000 +-0.900000 -0.502100 -0.104000 -0.752000 0.000000 0.656000 +-0.900000 -0.511500 -0.121900 -0.520000 -0.664000 0.528000 +-0.906100 -0.502100 -0.121900 -0.920000 0.072000 0.376000 +-0.900000 -0.542100 -0.182900 -0.808000 -0.560000 0.136000 +-0.925200 -0.502100 -0.182900 -0.976000 -0.008000 0.208000 +-0.900000 -0.551700 -0.243900 -0.808000 -0.568000 -0.120000 +-0.929300 -0.502100 -0.243900 -0.992000 0.064000 -0.008000 +-0.900000 -0.539600 -0.304800 -0.720000 -0.488000 -0.480000 +-0.920600 -0.502100 -0.304800 -0.888000 -0.288000 -0.344000 +-0.900000 -0.502100 -0.352600 -0.672000 0.128000 -0.720000 +-0.900000 -0.539600 -0.304800 -0.720000 -0.488000 -0.480000 +-0.864000 -0.502100 -0.365800 -0.304000 0.480000 -0.816000 +-0.891900 -0.552300 -0.304800 -0.800000 -0.568000 -0.136000 +-0.860100 -0.552300 -0.365800 -0.680000 -0.432000 -0.584000 +-0.850000 -0.602000 -0.304800 -0.640000 -0.736000 -0.184000 +-0.850000 -0.564700 -0.365800 -0.608000 -0.528000 -0.584000 +-0.849200 -0.602500 -0.304800 -0.536000 -0.720000 -0.432000 +-0.806700 -0.602500 -0.365800 -0.520000 -0.656000 -0.536000 +-0.800000 -0.636000 -0.304800 -0.536000 -0.792000 -0.272000 +-0.800000 -0.607700 -0.365800 -0.488000 -0.640000 -0.584000 +-0.750000 -0.652200 -0.304800 -0.040000 -0.952000 -0.288000 +-0.750000 -0.628000 -0.365800 -0.232000 -0.808000 -0.528000 +-0.734200 -0.652700 -0.304800 -0.024000 -0.976000 -0.192000 +-0.700000 -0.639000 -0.365800 -0.040000 -0.920000 -0.376000 +-0.700000 -0.652700 -0.309000 0.024000 -0.952000 -0.296000 +-0.650000 -0.641900 -0.365800 -0.024000 -0.952000 -0.280000 +-0.688500 -0.652700 -0.304800 0.080000 -0.992000 -0.064000 +-0.650000 -0.650400 -0.304800 0.048000 -0.992000 0.096000 +-0.700000 -0.652700 -0.298900 0.056000 -0.976000 0.184000 +-0.650000 -0.641500 -0.243900 0.040000 -0.976000 0.168000 +-0.700000 -0.645500 -0.243900 -0.008000 -0.984000 0.160000 +-0.650000 -0.630900 -0.182900 0.008000 -0.968000 0.232000 +-0.700000 -0.633400 -0.182900 -0.064000 -0.960000 0.248000 +-0.650000 -0.615500 -0.121900 -0.008000 -0.952000 0.304000 +-0.700000 -0.614700 -0.121900 -0.136000 -0.888000 0.424000 +-0.650000 -0.602500 -0.069700 -0.072000 -0.800000 0.584000 +-0.700000 -0.602500 -0.083600 -0.192000 -0.680000 0.704000 +-0.650000 -0.594800 -0.060900 -0.368000 -0.640000 0.664000 +-0.700000 -0.552300 -0.082500 -0.736000 -0.280000 0.608000 +-0.685200 -0.552300 -0.060900 -0.696000 -0.384000 0.592000 +-0.700000 -0.507800 -0.060900 -0.864000 -0.200000 0.448000 +-0.700000 -0.507800 -0.060900 -0.864000 -0.200000 0.448000 +-0.868200 -0.552300 -0.121900 -0.520000 -0.224000 0.816000 +-0.868200 -0.552300 -0.121900 -0.520000 -0.224000 0.816000 +-0.850000 -0.552300 -0.082300 -0.704000 -0.480000 0.504000 +-0.850000 -0.569100 -0.121900 -0.488000 -0.776000 0.384000 +-0.800000 -0.552300 -0.095900 0.424000 0.264000 0.864000 +-0.800000 -0.584500 -0.121900 -0.288000 -0.544000 0.776000 +-0.750000 -0.552300 -0.119400 0.072000 0.512000 0.848000 +-0.764000 -0.602500 -0.121900 -0.176000 -0.816000 0.544000 +-0.750000 -0.602500 -0.116200 -0.176000 -0.808000 0.544000 +-0.750000 -0.605000 -0.121900 -0.152000 -0.872000 0.456000 +-0.700000 -0.602500 -0.083600 -0.192000 -0.680000 0.704000 +-0.700000 -0.614700 -0.121900 -0.136000 -0.888000 0.424000 +-0.750000 -0.605000 -0.121900 -0.152000 -0.872000 0.456000 +-0.700000 -0.633400 -0.182900 -0.064000 -0.960000 0.248000 +-0.750000 -0.630100 -0.182900 -0.144000 -0.912000 0.360000 +-0.700000 -0.645500 -0.243900 -0.008000 -0.984000 0.160000 +-0.750000 -0.646000 -0.243900 -0.088000 -0.984000 0.144000 +-0.700000 -0.652700 -0.298900 0.056000 -0.976000 0.184000 +-0.750000 -0.652200 -0.304800 -0.040000 -0.952000 -0.288000 +-0.734200 -0.652700 -0.304800 -0.024000 -0.976000 -0.192000 +-0.700000 -0.652700 -0.298900 0.056000 -0.976000 0.184000 +-0.700000 -0.653800 -0.304800 0.056000 -0.992000 -0.080000 +-0.688500 -0.652700 -0.304800 0.080000 -0.992000 -0.064000 +-0.700000 -0.652700 -0.309000 0.024000 -0.952000 -0.296000 +-0.700000 -0.653800 -0.304800 0.056000 -0.992000 -0.080000 +-0.734200 -0.652700 -0.304800 -0.024000 -0.976000 -0.192000 +-0.734200 -0.652700 -0.304800 -0.024000 -0.976000 -0.192000 +-0.804300 0.200800 -0.121900 0.384000 0.872000 -0.288000 +-0.804300 0.200800 -0.121900 0.384000 0.872000 -0.288000 +-0.800000 0.198900 -0.121900 0.384000 0.872000 -0.288000 +-0.800000 0.200800 -0.113900 0.392000 0.880000 -0.256000 +-0.800000 0.200800 -0.113900 0.392000 0.880000 -0.256000 +-0.762700 -0.401700 -0.060900 -0.840000 -0.496000 0.168000 +-0.762700 -0.401700 -0.060900 -0.840000 -0.496000 0.168000 +-0.771000 -0.401700 -0.121900 -0.872000 -0.456000 0.128000 +-0.750000 -0.426100 -0.060900 -0.864000 -0.448000 0.200000 +-0.750000 -0.448400 -0.121900 -0.880000 -0.432000 0.160000 +-0.735400 -0.451900 -0.060900 -0.768000 -0.512000 0.360000 +-0.748200 -0.451900 -0.121900 -0.880000 -0.440000 0.160000 +-0.701200 -0.502100 -0.060900 -0.816000 -0.416000 0.392000 +-0.723300 -0.502100 -0.121900 -0.896000 -0.224000 0.368000 +-0.748200 -0.451900 -0.121900 -0.880000 -0.440000 0.160000 +-0.749300 -0.502100 -0.182900 -0.920000 -0.232000 0.288000 +-0.750000 -0.451900 -0.133400 -0.896000 -0.392000 0.184000 +-0.750000 -0.499500 -0.182900 -0.936000 -0.200000 0.264000 +-0.757600 -0.451900 -0.182900 -0.952000 -0.232000 0.184000 +-0.750000 -0.502100 -0.184800 -0.496000 0.696000 0.496000 +-0.769800 -0.451900 -0.243900 -0.952000 -0.080000 0.272000 +-0.800000 -0.502100 -0.227500 0.432000 0.824000 0.352000 +-0.800000 -0.496000 -0.243900 0.424000 0.840000 0.320000 +-0.820300 -0.502100 -0.182900 0.496000 0.792000 0.344000 +-0.850000 -0.480800 -0.243900 0.376000 0.912000 0.152000 +-0.850000 -0.490700 -0.182900 0.328000 0.896000 0.288000 +-0.896800 -0.451900 -0.243900 0.600000 0.776000 0.136000 +-0.900000 -0.462200 -0.182900 0.320000 0.888000 0.304000 +-0.900000 -0.451900 -0.229200 0.512000 0.832000 0.168000 +-0.896800 -0.451900 -0.243900 0.600000 0.776000 0.136000 +-0.900000 -0.449600 -0.243900 0.496000 0.856000 0.136000 +-0.891000 -0.451900 -0.304800 0.528000 0.824000 -0.192000 +-0.900000 -0.446300 -0.304800 0.160000 0.912000 -0.360000 +-0.900000 -0.451900 -0.318500 0.104000 0.872000 -0.464000 +-0.912200 -0.451900 -0.304800 -0.496000 0.720000 -0.464000 +-0.900000 -0.446300 -0.304800 0.160000 0.912000 -0.360000 +-0.921000 -0.451900 -0.243900 -0.184000 0.968000 0.160000 +-0.900000 -0.449600 -0.243900 0.496000 0.856000 0.136000 +-0.900000 -0.451900 -0.229200 0.512000 0.832000 0.168000 +-0.900000 -0.451900 -0.229200 0.512000 0.832000 0.168000 +-0.700000 -0.602500 -0.083600 -0.192000 -0.680000 0.704000 +-0.700000 -0.602500 -0.083600 -0.192000 -0.680000 0.704000 +-0.750000 -0.602500 -0.116200 -0.176000 -0.808000 0.544000 +-0.700000 -0.552300 -0.082500 -0.736000 -0.280000 0.608000 +-0.750000 -0.552300 -0.119400 0.072000 0.512000 0.848000 +-0.750000 -0.552300 -0.119400 0.072000 0.512000 0.848000 +-0.650000 -0.594800 -0.060900 -0.368000 -0.640000 0.664000 +-0.650000 -0.594800 -0.060900 -0.368000 -0.640000 0.664000 +-0.650000 -0.602500 -0.069700 -0.072000 -0.800000 0.584000 +-0.600000 -0.601900 -0.060900 -0.072000 -0.808000 0.568000 +-0.600000 -0.602500 -0.062100 -0.056000 -0.816000 0.560000 +-0.550000 -0.588500 -0.060900 0.224000 -0.888000 0.384000 +-0.550000 -0.602500 -0.100200 0.256000 -0.912000 0.288000 +-0.500000 -0.570000 -0.060900 0.480000 -0.800000 0.328000 +-0.531000 -0.602500 -0.121900 0.248000 -0.920000 0.272000 +-0.500000 -0.589900 -0.121900 0.408000 -0.832000 0.352000 +-0.500000 -0.602500 -0.155300 0.000000 -0.920000 0.376000 +-0.531000 -0.602500 -0.121900 0.248000 -0.920000 0.272000 +-0.500000 -0.610400 -0.182900 -0.136000 -0.936000 0.304000 +-0.550000 -0.606400 -0.121900 0.192000 -0.952000 0.216000 +-0.550000 -0.618800 -0.182900 0.168000 -0.944000 0.272000 +-0.600000 -0.616000 -0.121900 0.080000 -0.960000 0.256000 +-0.600000 -0.629300 -0.182900 0.072000 -0.968000 0.224000 +-0.650000 -0.615500 -0.121900 -0.008000 -0.952000 0.304000 +-0.650000 -0.630900 -0.182900 0.008000 -0.968000 0.232000 +-0.600000 -0.629300 -0.182900 0.072000 -0.968000 0.224000 +-0.650000 -0.641500 -0.243900 0.040000 -0.976000 0.168000 +-0.600000 -0.640700 -0.243900 0.080000 -0.976000 0.192000 +-0.650000 -0.650400 -0.304800 0.048000 -0.992000 0.096000 +-0.600000 -0.650800 -0.304800 0.064000 -0.992000 0.000000 +-0.650000 -0.641900 -0.365800 -0.024000 -0.952000 -0.280000 +-0.600000 -0.645500 -0.365800 0.016000 -0.968000 -0.216000 +-0.650000 -0.621300 -0.426800 -0.080000 -0.904000 -0.400000 +-0.600000 -0.630300 -0.426800 -0.072000 -0.944000 -0.312000 +-0.600000 -0.645500 -0.365800 0.016000 -0.968000 -0.216000 +-0.550000 -0.626200 -0.426800 0.144000 -0.960000 -0.232000 +-0.550000 -0.637200 -0.365800 0.152000 -0.968000 -0.168000 +-0.500000 -0.621400 -0.426800 0.072000 -0.968000 -0.232000 +-0.500000 -0.633000 -0.365800 -0.088000 -0.968000 -0.200000 +-0.450000 -0.629300 -0.426800 -0.048000 -0.904000 -0.416000 +-0.450000 -0.645700 -0.365800 -0.144000 -0.904000 -0.392000 +-0.400000 -0.621700 -0.426800 0.392000 -0.856000 -0.304000 +-0.405700 -0.652700 -0.365800 -0.144000 -0.920000 -0.344000 +-0.400000 -0.652700 -0.368100 -0.128000 -0.872000 -0.456000 +-0.400000 -0.652700 -0.368100 -0.128000 -0.872000 -0.456000 +-0.650000 -0.602500 -0.069700 -0.072000 -0.800000 0.584000 +-0.650000 -0.602500 -0.069700 -0.072000 -0.800000 0.584000 +-0.650000 -0.615500 -0.121900 -0.008000 -0.952000 0.304000 +-0.600000 -0.602500 -0.062100 -0.056000 -0.816000 0.560000 +-0.600000 -0.616000 -0.121900 0.080000 -0.960000 0.256000 +-0.550000 -0.602500 -0.100200 0.256000 -0.912000 0.288000 +-0.550000 -0.606400 -0.121900 0.192000 -0.952000 0.216000 +-0.531000 -0.602500 -0.121900 0.248000 -0.920000 0.272000 +-0.531000 -0.602500 -0.121900 0.248000 -0.920000 0.272000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.554400 -0.050200 -0.060900 0.944000 0.280000 0.128000 +-0.586600 -0.050200 -0.121900 0.872000 0.224000 -0.424000 +-0.550000 -0.066800 -0.060900 0.944000 0.320000 -0.008000 +-0.578300 -0.100400 -0.121900 0.848000 0.312000 -0.424000 +-0.550000 -0.100400 -0.079500 0.552000 0.552000 -0.616000 +-0.550000 -0.145600 -0.121900 0.512000 0.792000 -0.312000 +-0.578300 -0.100400 -0.121900 0.848000 0.312000 -0.424000 +-0.550000 -0.150600 -0.142400 0.376000 0.896000 -0.200000 +-0.594100 -0.100400 -0.182900 0.816000 0.296000 -0.480000 +-0.561800 -0.150600 -0.182900 0.544000 0.784000 -0.280000 +-0.550000 -0.150600 -0.142400 0.376000 0.896000 -0.200000 +-0.550000 -0.155500 -0.182900 0.296000 0.920000 -0.232000 +-0.550000 -0.155500 -0.182900 0.296000 0.920000 -0.232000 +-0.452400 -0.100400 -0.060900 -0.344000 0.936000 -0.016000 +-0.452400 -0.100400 -0.060900 -0.344000 0.936000 -0.016000 +-0.450000 -0.100400 -0.065100 -0.512000 0.824000 -0.200000 +-0.450000 -0.099400 -0.060900 -0.760000 0.616000 0.160000 +-0.450000 -0.099400 -0.060900 -0.760000 0.616000 0.160000 +-0.450000 -0.512800 -0.060900 0.208000 -0.760000 0.608000 +-0.450000 -0.512800 -0.060900 0.208000 -0.760000 0.608000 +-0.478800 -0.552300 -0.060900 0.704000 -0.592000 0.376000 +-0.450000 -0.549200 -0.121900 -0.080000 -0.800000 0.584000 +-0.452200 -0.552300 -0.121900 0.864000 0.184000 0.464000 +-0.450000 -0.552300 -0.127200 0.616000 -0.144000 0.768000 +-0.450000 -0.549200 -0.121900 -0.080000 -0.800000 0.584000 +-0.440600 -0.552300 -0.121900 -0.264000 -0.768000 0.568000 +-0.450000 -0.512800 -0.060900 0.208000 -0.760000 0.608000 +-0.400000 -0.552300 -0.100200 0.624000 -0.512000 0.584000 +-0.400000 -0.527700 -0.060900 0.080000 -0.768000 0.624000 +-0.393200 -0.552300 -0.121900 0.872000 -0.352000 0.320000 +-0.380200 -0.502100 -0.060900 0.648000 -0.616000 0.432000 +-0.350000 -0.503000 -0.121900 0.232000 -0.880000 0.400000 +-0.350000 -0.502100 -0.119400 0.240000 -0.864000 0.424000 +-0.380200 -0.502100 -0.060900 0.648000 -0.616000 0.432000 +-0.350000 -0.453900 -0.060900 0.248000 -0.624000 0.728000 +-0.350000 -0.453900 -0.060900 0.248000 -0.624000 0.728000 +-0.450000 -0.602500 -0.084100 -0.232000 -0.736000 0.624000 +-0.450000 -0.602500 -0.084100 -0.232000 -0.736000 0.624000 +-0.450000 -0.558900 -0.121900 0.808000 0.320000 0.488000 +-0.410500 -0.602500 -0.121900 0.456000 -0.632000 0.616000 +-0.450000 -0.552300 -0.127200 0.616000 -0.144000 0.768000 +-0.400000 -0.602500 -0.131300 0.560000 -0.576000 0.584000 +-0.440600 -0.552300 -0.121900 -0.264000 -0.768000 0.568000 +-0.400000 -0.588000 -0.121900 0.672000 -0.144000 0.720000 +-0.400000 -0.552300 -0.100200 0.624000 -0.512000 0.584000 +-0.393200 -0.552300 -0.121900 0.872000 -0.352000 0.320000 +-0.400000 -0.588000 -0.121900 0.672000 -0.144000 0.720000 +-0.379200 -0.552300 -0.182900 0.864000 -0.416000 0.264000 +-0.400000 -0.602500 -0.131300 0.560000 -0.576000 0.584000 +-0.386500 -0.602500 -0.182900 0.376000 -0.032000 0.920000 +-0.379200 -0.552300 -0.182900 0.864000 -0.416000 0.264000 +-0.371400 -0.602500 -0.243900 0.928000 0.016000 0.352000 +-0.363900 -0.552300 -0.243900 0.816000 -0.480000 0.304000 +-0.379200 -0.552300 -0.182900 0.864000 -0.416000 0.264000 +-0.350000 -0.535600 -0.243900 0.360000 -0.840000 0.384000 +-0.350000 -0.518400 -0.182900 -0.088000 -0.928000 0.360000 +-0.379200 -0.552300 -0.182900 0.864000 -0.416000 0.264000 +-0.350000 -0.503000 -0.121900 0.232000 -0.880000 0.400000 +-0.393200 -0.552300 -0.121900 0.872000 -0.352000 0.320000 +-0.393200 -0.552300 -0.121900 0.872000 -0.352000 0.320000 +-0.350000 0.148000 -0.060900 -0.504000 0.552000 0.656000 +-0.350000 0.148000 -0.060900 -0.504000 0.552000 0.656000 +-0.361800 0.100400 -0.060900 -0.920000 0.112000 -0.352000 +-0.350000 0.100400 -0.076700 -0.736000 0.256000 -0.616000 +-0.358600 0.050200 -0.060900 -0.920000 0.168000 -0.328000 +-0.350000 0.050200 -0.078800 -0.832000 0.272000 -0.472000 +-0.350000 0.100400 -0.076700 -0.736000 0.256000 -0.616000 +-0.335400 0.050200 -0.121900 -0.752000 0.472000 -0.456000 +-0.317300 0.100400 -0.121900 -0.712000 0.264000 -0.640000 +-0.317300 0.100400 -0.121900 -0.712000 0.264000 -0.640000 +-0.377800 0.000000 -0.060900 -0.864000 0.424000 -0.248000 +-0.377800 0.000000 -0.060900 -0.864000 0.424000 -0.248000 +-0.400000 -0.037800 -0.060900 -0.728000 0.664000 0.152000 +-0.372200 0.000000 -0.121900 -0.848000 0.480000 -0.200000 +-0.400000 -0.050200 -0.118700 -0.832000 0.528000 -0.160000 +-0.399400 -0.050200 -0.121900 -0.760000 0.504000 -0.392000 +-0.400000 -0.050900 -0.121900 -0.736000 0.536000 -0.408000 +-0.400000 -0.050900 -0.121900 -0.736000 0.536000 -0.408000 +-0.350000 0.301200 -0.064600 -0.624000 0.064000 -0.768000 +-0.350000 0.301200 -0.064600 -0.624000 0.064000 -0.768000 +-0.300000 0.301200 -0.089300 -0.344000 0.056000 -0.936000 +-0.350000 0.251000 -0.067500 -0.624000 0.048000 -0.768000 +-0.300000 0.251000 -0.090000 -0.368000 0.088000 -0.920000 +-0.350000 0.200800 -0.076700 -0.368000 -0.104000 -0.920000 +-0.300000 0.200800 -0.077300 -0.504000 0.240000 -0.824000 +-0.350000 0.153200 -0.060900 -0.608000 -0.784000 0.016000 +-0.300000 0.150600 -0.105900 -0.768000 0.536000 -0.320000 +-0.346000 0.150600 -0.060900 -0.768000 -0.144000 0.616000 +-0.346000 0.150600 -0.060900 -0.768000 -0.144000 0.616000 +-0.300000 0.401700 -0.066400 -0.448000 0.440000 -0.768000 +-0.300000 0.401700 -0.066400 -0.448000 0.440000 -0.768000 +-0.250000 0.401700 -0.091800 -0.416000 0.456000 -0.776000 +-0.300000 0.351500 -0.083400 -0.432000 0.176000 -0.880000 +-0.250000 0.351500 -0.107800 -0.464000 0.176000 -0.864000 +-0.300000 0.301200 -0.089300 -0.344000 0.056000 -0.936000 +-0.250000 0.301200 -0.116200 -0.672000 0.120000 -0.720000 +-0.300000 0.251000 -0.090000 -0.368000 0.088000 -0.920000 +-0.250000 0.268200 -0.121900 -0.464000 0.088000 -0.872000 +-0.254200 0.251000 -0.121900 -0.384000 0.088000 -0.912000 +-0.300000 0.251000 -0.090000 -0.368000 0.088000 -0.920000 +-0.263400 0.200800 -0.121900 -0.480000 0.216000 -0.840000 +-0.300000 0.200800 -0.077300 -0.504000 0.240000 -0.824000 +-0.295300 0.150600 -0.121900 -0.728000 0.520000 -0.432000 +-0.300000 0.150600 -0.105900 -0.768000 0.536000 -0.320000 +-0.300000 0.144000 -0.121900 -0.728000 0.496000 -0.456000 +-0.300000 0.144000 -0.121900 -0.728000 0.496000 -0.456000 +-0.250000 0.401700 -0.091800 -0.416000 0.456000 -0.776000 +-0.250000 0.401700 -0.091800 -0.416000 0.456000 -0.776000 +-0.208300 0.401700 -0.121900 -0.432000 0.432000 -0.784000 +-0.250000 0.351500 -0.107800 -0.464000 0.176000 -0.864000 +-0.233300 0.351500 -0.121900 -0.616000 0.184000 -0.752000 +-0.250000 0.301200 -0.116200 -0.672000 0.120000 -0.720000 +-0.245300 0.301200 -0.121900 -0.680000 0.120000 -0.720000 +-0.250000 0.268200 -0.121900 -0.464000 0.088000 -0.872000 +-0.250000 0.268200 -0.121900 -0.464000 0.088000 -0.872000 +-0.104300 -0.100400 -0.060900 0.528000 0.416000 0.728000 +-0.104300 -0.100400 -0.060900 0.528000 0.416000 0.728000 +-0.100000 -0.100400 -0.064700 0.496000 0.416000 0.752000 +-0.100000 -0.105500 -0.060900 0.480000 0.464000 0.736000 +-0.050000 -0.100400 -0.073900 0.136000 0.480000 0.864000 +-0.050000 -0.119400 -0.060900 0.168000 0.528000 0.824000 +0.000000 -0.100400 -0.085100 0.096000 0.456000 0.880000 +0.000000 -0.136800 -0.060900 0.088000 0.520000 0.840000 +0.050000 -0.100400 -0.083400 0.000000 0.440000 0.888000 +0.050000 -0.140200 -0.060900 0.152000 0.504000 0.848000 +0.100000 -0.100400 -0.084200 0.032000 0.360000 0.928000 +0.076800 -0.150600 -0.060900 0.208000 0.432000 0.872000 +0.100000 -0.150600 -0.068400 0.184000 0.416000 0.888000 +0.100000 -0.170000 -0.060900 0.256000 0.296000 0.912000 +0.100000 -0.170000 -0.060900 0.256000 0.296000 0.912000 +-0.133200 -0.451900 -0.060900 0.584000 -0.656000 0.464000 +-0.133200 -0.451900 -0.060900 0.584000 -0.656000 0.464000 +-0.100000 -0.415900 -0.060900 0.680000 -0.544000 0.480000 +-0.100000 -0.451900 -0.117700 0.624000 -0.664000 0.392000 +-0.100000 -0.451900 -0.117700 0.624000 -0.664000 0.392000 +-0.150000 -0.502100 -0.111600 0.592000 -0.752000 0.280000 +-0.150000 -0.502100 -0.111600 0.592000 -0.752000 0.280000 +-0.146100 -0.502100 -0.121900 0.616000 -0.744000 0.232000 +-0.150000 -0.505100 -0.121900 0.584000 -0.768000 0.240000 +-0.141200 -0.502100 -0.182900 0.696000 -0.688000 0.184000 +-0.150000 -0.510100 -0.182900 0.616000 -0.760000 0.168000 +-0.125700 -0.502100 -0.243900 0.664000 -0.408000 0.624000 +-0.150000 -0.530700 -0.243900 0.632000 -0.664000 0.392000 +-0.150000 -0.530700 -0.243900 0.632000 -0.664000 0.392000 +-0.078700 0.200800 -0.060900 0.568000 -0.416000 0.704000 +-0.078700 0.200800 -0.060900 0.568000 -0.416000 0.704000 +-0.050000 0.236000 -0.060900 0.536000 -0.496000 0.672000 +-0.050000 0.200800 -0.090500 0.520000 -0.520000 0.672000 +-0.050000 0.200800 -0.090500 0.520000 -0.520000 0.672000 +-0.100000 0.100400 -0.099400 0.760000 -0.264000 0.584000 +-0.100000 0.100400 -0.099400 0.760000 -0.264000 0.584000 +-0.089100 0.100400 -0.121900 0.816000 -0.232000 0.520000 +-0.100000 0.054100 -0.121900 0.816000 -0.176000 0.544000 +-0.100000 0.054100 -0.121900 0.816000 -0.176000 0.544000 +-0.050000 -0.370100 -0.060900 0.592000 -0.672000 0.424000 +-0.050000 -0.370100 -0.060900 0.592000 -0.672000 0.424000 +-0.087700 -0.401700 -0.060900 0.608000 -0.600000 0.504000 +-0.050000 -0.398200 -0.121900 0.592000 -0.704000 0.368000 +-0.054100 -0.401700 -0.121900 0.656000 -0.688000 0.280000 +-0.050000 -0.389600 -0.182900 0.656000 -0.736000 -0.128000 +-0.061900 -0.401700 -0.182900 0.744000 -0.648000 -0.120000 +-0.050000 -0.380500 -0.243900 0.664000 -0.736000 -0.104000 +-0.071000 -0.401700 -0.243900 0.856000 -0.496000 -0.072000 +-0.050000 -0.374600 -0.304800 0.584000 -0.672000 -0.448000 +-0.073900 -0.401700 -0.304800 0.784000 -0.304000 -0.528000 +-0.050000 -0.351500 -0.336900 0.024000 -0.576000 -0.808000 +-0.100000 -0.401700 -0.330800 0.576000 -0.152000 -0.792000 +-0.100000 -0.351500 -0.338800 0.024000 -0.312000 -0.944000 +-0.150000 -0.401700 -0.364300 0.552000 0.080000 -0.824000 +-0.150000 -0.351500 -0.350300 0.512000 0.192000 -0.832000 +-0.100000 -0.351500 -0.338800 0.024000 -0.312000 -0.944000 +-0.150000 -0.301200 -0.318500 -0.024000 0.504000 -0.856000 +-0.100000 -0.301200 -0.349000 -0.368000 0.264000 -0.888000 +-0.150000 -0.286300 -0.304800 -0.184000 0.480000 -0.848000 +-0.100000 -0.251000 -0.333700 -0.512000 0.248000 -0.816000 +-0.123600 -0.251000 -0.304800 -0.536000 0.288000 -0.784000 +-0.100000 -0.200800 -0.311700 -0.496000 0.128000 -0.856000 +-0.108400 -0.200800 -0.304800 -0.496000 -0.048000 -0.856000 +-0.123600 -0.251000 -0.304800 -0.536000 0.288000 -0.784000 +-0.150000 -0.200800 -0.284500 0.024000 -0.216000 -0.968000 +-0.150000 -0.251000 -0.289400 -0.264000 0.272000 -0.920000 +-0.196100 -0.200800 -0.304800 0.360000 -0.200000 -0.904000 +-0.195100 -0.251000 -0.304800 0.376000 0.112000 -0.912000 +-0.150000 -0.251000 -0.289400 -0.264000 0.272000 -0.920000 +-0.150000 -0.286300 -0.304800 -0.184000 0.480000 -0.848000 +-0.123600 -0.251000 -0.304800 -0.536000 0.288000 -0.784000 +-0.123600 -0.251000 -0.304800 -0.536000 0.288000 -0.784000 +0.000000 0.393800 -0.060900 0.224000 0.176000 0.952000 +0.000000 0.393800 -0.060900 0.224000 0.176000 0.952000 +-0.005200 0.401700 -0.060900 0.264000 0.168000 0.944000 +0.000000 0.401700 -0.062800 0.256000 0.176000 0.944000 +0.000000 0.401700 -0.062800 0.256000 0.176000 0.944000 +0.000000 0.493800 -0.121900 0.128000 0.960000 -0.232000 +0.000000 0.493800 -0.121900 0.128000 0.960000 -0.232000 +0.000000 0.451900 -0.081100 0.280000 0.456000 0.832000 +0.050000 0.485400 -0.121900 -0.032000 0.904000 -0.408000 +0.050000 0.451900 -0.077800 0.016000 0.408000 0.912000 +0.100000 0.494400 -0.121900 -0.184000 0.952000 -0.216000 +0.100000 0.451900 -0.066700 -0.192000 0.072000 0.976000 +0.138500 0.502100 -0.121900 -0.184000 0.952000 -0.216000 +0.121900 0.451900 -0.060900 -0.112000 0.472000 0.872000 +0.150000 0.502100 -0.119700 0.016000 0.656000 0.752000 +0.150000 0.456100 -0.060900 0.048000 0.664000 0.736000 +0.150000 0.456100 -0.060900 0.048000 0.664000 0.736000 +0.150000 0.503100 -0.121900 0.272000 0.456000 -0.840000 +0.150000 0.503100 -0.121900 0.272000 0.456000 -0.840000 +0.150000 0.502100 -0.119700 0.016000 0.656000 0.752000 +0.138500 0.502100 -0.121900 -0.184000 0.952000 -0.216000 +0.138500 0.502100 -0.121900 -0.184000 0.952000 -0.216000 +0.150000 0.409600 -0.060900 -0.208000 -0.072000 0.968000 +0.150000 0.409600 -0.060900 -0.208000 -0.072000 0.968000 +0.151400 0.401700 -0.060900 -0.480000 -0.416000 0.760000 +0.150000 0.401700 -0.062100 -0.392000 -0.400000 0.816000 +0.150000 0.401700 -0.062100 -0.392000 -0.400000 0.816000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +0.150000 -0.251000 -0.118100 0.224000 -0.792000 0.560000 +0.161400 -0.251000 -0.121900 0.152000 -0.792000 0.576000 +0.150000 -0.253200 -0.121900 0.192000 -0.808000 0.552000 +0.150000 -0.253200 -0.121900 0.192000 -0.808000 0.552000 +0.250000 0.432000 -0.060900 0.224000 0.624000 0.736000 +0.250000 0.432000 -0.060900 0.224000 0.624000 0.736000 +0.203100 0.451900 -0.060900 0.264000 0.672000 0.680000 +0.250000 0.451900 -0.094000 0.248000 0.784000 0.552000 +0.250000 0.451900 -0.094000 0.248000 0.784000 0.552000 +0.200000 0.352900 -0.060900 -0.368000 -0.496000 0.776000 +0.200000 0.352900 -0.060900 -0.368000 -0.496000 0.776000 +0.201200 0.351500 -0.060900 -0.488000 -0.576000 0.648000 +0.200000 0.351500 -0.062100 -0.312000 -0.640000 0.696000 +0.200000 0.351500 -0.062100 -0.312000 -0.640000 0.696000 +0.200000 -0.041200 -0.121900 0.160000 0.488000 0.856000 +0.200000 -0.041200 -0.121900 0.160000 0.488000 0.856000 +0.222300 -0.050200 -0.121900 0.200000 0.432000 0.872000 +0.200000 -0.050200 -0.116900 0.136000 0.368000 0.912000 +0.200000 -0.050200 -0.116900 0.136000 0.368000 0.912000 +0.300000 0.451900 -0.106900 0.184000 0.864000 0.456000 +0.300000 0.451900 -0.106900 0.184000 0.864000 0.456000 +0.300000 0.458100 -0.121900 0.224000 0.952000 -0.176000 +0.323400 0.451900 -0.121900 0.248000 0.944000 -0.200000 +0.300000 0.451900 -0.131100 0.200000 0.712000 -0.664000 +0.300000 0.451900 -0.131100 0.200000 0.712000 -0.664000 +0.366500 0.200800 -0.121900 -0.760000 -0.624000 0.168000 +0.366500 0.200800 -0.121900 -0.760000 -0.624000 0.168000 +0.400000 0.200800 -0.077800 -0.600000 -0.432000 0.664000 +0.400000 0.152400 -0.121900 -0.688000 -0.712000 -0.048000 +0.400000 0.152400 -0.121900 -0.688000 -0.712000 -0.048000 +0.400000 0.072600 -0.121900 -0.632000 0.256000 0.720000 +0.400000 0.072600 -0.121900 -0.632000 0.256000 0.720000 +0.400000 0.050200 -0.114800 -0.552000 0.256000 0.784000 +0.393200 0.050200 -0.121900 -0.648000 0.352000 0.664000 +0.393200 0.050200 -0.121900 -0.648000 0.352000 0.664000 +0.450000 -0.100400 -0.078400 -0.088000 0.200000 0.968000 +0.450000 -0.100400 -0.078400 -0.088000 0.200000 0.968000 +0.400000 -0.100400 -0.080400 -0.024000 0.176000 0.976000 +0.450000 -0.150600 -0.064700 -0.192000 0.128000 0.968000 +0.400000 -0.150600 -0.068400 -0.344000 -0.312000 0.880000 +0.450000 -0.200800 -0.072200 -0.256000 -0.536000 0.800000 +0.400000 -0.200800 -0.119100 -0.200000 -0.688000 0.688000 +0.450000 -0.227100 -0.121900 -0.296000 -0.712000 0.624000 +0.400000 -0.203000 -0.121900 -0.184000 -0.672000 0.712000 +0.450000 -0.251000 -0.179900 -0.288000 -0.680000 0.664000 +0.400000 -0.249800 -0.182900 0.472000 -0.752000 0.448000 +0.415700 -0.251000 -0.182900 -0.088000 -0.872000 0.480000 +0.400000 -0.249400 -0.243900 0.760000 -0.472000 -0.424000 +0.450000 -0.251000 -0.203800 -0.216000 -0.960000 -0.144000 +0.450000 -0.248400 -0.243900 -0.224000 -0.888000 -0.384000 +0.459300 -0.251000 -0.243900 -0.280000 -0.864000 -0.400000 +0.459300 -0.251000 -0.243900 -0.280000 -0.864000 -0.400000 +0.450000 0.163500 -0.060900 -0.600000 -0.504000 0.608000 +0.450000 0.163500 -0.060900 -0.600000 -0.504000 0.608000 +0.460500 0.150600 -0.060900 -0.624000 -0.512000 0.584000 +0.450000 0.150600 -0.075000 -0.616000 -0.488000 0.608000 +0.450000 0.150600 -0.075000 -0.616000 -0.488000 0.608000 +0.504600 0.100400 -0.060900 -0.704000 -0.248000 0.656000 +0.504600 0.100400 -0.060900 -0.704000 -0.248000 0.656000 +0.500000 0.067400 -0.060900 -0.592000 0.120000 0.792000 +0.500000 0.100400 -0.067100 -0.632000 -0.296000 0.704000 +0.500000 0.100400 -0.067100 -0.632000 -0.296000 0.704000 +0.550000 -0.159500 -0.060900 0.248000 0.472000 0.840000 +0.550000 -0.159500 -0.060900 0.248000 0.472000 0.840000 +0.530700 -0.150600 -0.060900 0.208000 0.504000 0.832000 +0.550000 -0.150600 -0.067100 0.240000 0.480000 0.840000 +0.550000 -0.150600 -0.067100 0.240000 0.480000 0.840000 +0.546800 -0.351500 -0.121900 -0.560000 -0.304000 0.760000 +0.546800 -0.351500 -0.121900 -0.560000 -0.304000 0.760000 +0.550000 -0.317100 -0.121900 -0.368000 0.064000 0.920000 +0.550000 -0.351500 -0.118900 -0.368000 0.056000 0.920000 +0.558500 -0.351500 -0.121900 0.208000 -0.648000 0.728000 +0.550000 -0.353000 -0.121900 -0.032000 -0.832000 0.536000 +0.550000 -0.351500 -0.118900 -0.368000 0.056000 0.920000 +0.546800 -0.351500 -0.121900 -0.560000 -0.304000 0.760000 +0.550000 -0.353000 -0.121900 -0.032000 -0.832000 0.536000 +0.500000 -0.351500 -0.156800 -0.392000 -0.248000 0.880000 +0.550000 -0.389500 -0.182900 -0.304000 -0.784000 0.528000 +0.500000 -0.372900 -0.182900 -0.184000 -0.776000 0.592000 +0.550000 -0.401700 -0.218900 -0.128000 -0.904000 0.392000 +0.500000 -0.400600 -0.243900 0.024000 -0.920000 0.384000 +0.503900 -0.401700 -0.243900 -0.232000 -0.936000 0.256000 +0.500000 -0.400200 -0.304800 -0.176000 -0.672000 -0.712000 +0.502600 -0.401700 -0.304800 -0.320000 -0.840000 -0.416000 +0.500000 -0.351500 -0.354900 -0.384000 -0.472000 -0.784000 +0.550000 -0.401700 -0.333700 -0.144000 -0.688000 -0.704000 +0.550000 -0.351500 -0.364500 0.120000 -0.104000 -0.984000 +0.500000 -0.351500 -0.354900 -0.384000 -0.472000 -0.784000 +0.550000 -0.316300 -0.304800 -0.472000 0.688000 -0.536000 +0.500000 -0.333600 -0.304800 -0.408000 0.824000 -0.376000 +0.550000 -0.301200 -0.279200 -0.712000 0.120000 -0.680000 +0.500000 -0.310500 -0.243900 -0.600000 0.776000 -0.152000 +0.513800 -0.301200 -0.243900 -0.728000 0.592000 -0.328000 +0.500000 -0.316400 -0.182900 -0.704000 0.472000 0.520000 +0.511800 -0.301200 -0.182900 -0.912000 0.352000 0.176000 +0.500000 -0.351500 -0.156800 -0.392000 -0.248000 0.880000 +0.550000 -0.301200 -0.123600 -0.624000 -0.440000 0.632000 +0.546800 -0.351500 -0.121900 -0.560000 -0.304000 0.760000 +0.550000 -0.317100 -0.121900 -0.368000 0.064000 0.920000 +0.550000 -0.317100 -0.121900 -0.368000 0.064000 0.920000 +0.550000 -0.242100 -0.060900 -0.400000 -0.536000 0.736000 +0.550000 -0.242100 -0.060900 -0.400000 -0.536000 0.736000 +0.562800 -0.251000 -0.060900 -0.368000 -0.568000 0.720000 +0.550000 -0.251000 -0.069700 -0.416000 -0.584000 0.688000 +0.550000 -0.251000 -0.069700 -0.416000 -0.584000 0.688000 +0.552600 -0.301200 -0.121900 -0.368000 -0.384000 0.840000 +0.552600 -0.301200 -0.121900 -0.368000 -0.384000 0.840000 +0.600000 -0.301200 -0.098800 -0.176000 -0.576000 0.792000 +0.600000 -0.333000 -0.121900 0.024000 -0.312000 0.944000 +0.650000 -0.301200 -0.100200 0.264000 -0.568000 0.768000 +0.650000 -0.327200 -0.121900 -0.280000 -0.536000 0.792000 +0.700000 -0.301200 -0.068800 0.336000 0.392000 0.848000 +0.679500 -0.351500 -0.121900 -0.424000 -0.464000 0.768000 +0.700000 -0.351500 -0.108700 -0.352000 -0.464000 0.808000 +0.700000 -0.372000 -0.121900 -0.360000 -0.440000 0.816000 +0.750000 -0.351500 -0.097900 0.640000 0.048000 0.760000 +0.737900 -0.401700 -0.121900 -0.352000 -0.448000 0.816000 +0.750000 -0.401700 -0.115900 -0.264000 -0.344000 0.896000 +0.750000 -0.411100 -0.121900 -0.304000 -0.456000 0.824000 +0.800000 -0.401700 -0.115500 0.392000 0.184000 0.896000 +0.800000 -0.418600 -0.121900 0.304000 -0.320000 0.888000 +0.750000 -0.411100 -0.121900 -0.304000 -0.456000 0.824000 +0.800000 -0.451900 -0.135400 0.168000 -0.384000 0.904000 +0.750000 -0.451900 -0.153800 -0.384000 -0.528000 0.752000 +0.800000 -0.502100 -0.171200 -0.360000 -0.648000 0.664000 +0.750000 -0.479900 -0.182900 -0.456000 -0.632000 0.616000 +0.783200 -0.502100 -0.182900 -0.448000 -0.720000 0.512000 +0.750000 -0.502100 -0.236900 -0.448000 -0.776000 0.432000 +0.800000 -0.511100 -0.182900 -0.376000 -0.744000 0.544000 +0.750000 -0.505200 -0.243900 -0.480000 -0.856000 0.152000 +0.800000 -0.519900 -0.243900 -0.400000 -0.904000 -0.112000 +0.750000 -0.502100 -0.254300 -0.448000 -0.832000 -0.312000 +0.800000 -0.502100 -0.293400 -0.120000 -0.840000 -0.520000 +0.750000 -0.487000 -0.304800 -0.104000 -0.744000 -0.656000 +0.800000 -0.493800 -0.304800 0.032000 -0.688000 -0.720000 +0.750000 -0.451900 -0.330900 0.152000 -0.080000 -0.984000 +0.800000 -0.451900 -0.330300 0.328000 0.200000 -0.920000 +0.750000 -0.401700 -0.321600 0.336000 0.000000 -0.936000 +0.800000 -0.418300 -0.304800 0.408000 0.496000 -0.760000 +0.779200 -0.401700 -0.304800 0.400000 0.336000 -0.848000 +0.800000 -0.401700 -0.291400 0.440000 0.456000 -0.760000 +0.754800 -0.351500 -0.304800 0.424000 0.136000 -0.888000 +0.800000 -0.351500 -0.277300 0.568000 0.408000 -0.704000 +0.750000 -0.334300 -0.304800 0.512000 0.112000 -0.840000 +0.800000 -0.328800 -0.243900 0.640000 0.656000 -0.384000 +0.750000 -0.301200 -0.299800 0.512000 0.144000 -0.840000 +0.780500 -0.301200 -0.243900 0.848000 0.504000 -0.128000 +0.750000 -0.251000 -0.256700 0.824000 0.520000 -0.208000 +0.752500 -0.251000 -0.243900 0.840000 0.528000 -0.096000 +0.750000 -0.247000 -0.243900 0.832000 0.536000 -0.096000 +0.750000 -0.251000 -0.218200 0.840000 0.520000 0.096000 +0.717800 -0.200800 -0.243900 0.824000 0.560000 -0.064000 +0.746300 -0.251000 -0.182900 0.848000 0.496000 0.152000 +0.713600 -0.200800 -0.182900 0.824000 0.512000 0.224000 +0.719200 -0.251000 -0.121900 0.760000 0.456000 0.440000 +0.700000 -0.200800 -0.144600 0.696000 0.528000 0.480000 +0.700000 -0.217500 -0.121900 0.616000 0.552000 0.544000 +0.677400 -0.200800 -0.121900 0.528000 0.512000 0.672000 +0.700000 -0.200800 -0.144600 0.696000 0.528000 0.480000 +0.652900 -0.150600 -0.121900 0.752000 0.456000 0.464000 +0.700000 -0.178500 -0.182900 0.792000 0.568000 0.200000 +0.675300 -0.150600 -0.182900 0.768000 0.552000 0.296000 +0.700000 -0.175300 -0.243900 0.752000 0.600000 -0.240000 +0.674200 -0.150600 -0.243900 0.696000 0.600000 -0.384000 +0.674200 -0.150600 -0.243900 0.696000 0.600000 -0.384000 +0.600000 -0.272000 -0.060900 -0.264000 -0.632000 0.720000 +0.600000 -0.272000 -0.060900 -0.264000 -0.632000 0.720000 +0.600000 -0.301200 -0.098800 -0.176000 -0.576000 0.792000 +0.650000 -0.258100 -0.060900 0.392000 -0.456000 0.792000 +0.650000 -0.301200 -0.100200 0.264000 -0.568000 0.768000 +0.657600 -0.251000 -0.060900 0.456000 -0.072000 0.880000 +0.700000 -0.301200 -0.068800 0.336000 0.392000 0.848000 +0.700000 -0.251000 -0.086700 0.608000 0.464000 0.632000 +0.700000 -0.251000 -0.086700 0.608000 0.464000 0.632000 +0.650000 0.350500 -0.060900 0.712000 0.536000 -0.440000 +0.650000 0.350500 -0.060900 0.712000 0.536000 -0.440000 +0.650000 0.301200 -0.100800 0.528000 0.504000 -0.672000 +0.680100 0.301200 -0.060900 0.752000 0.544000 -0.368000 +0.680100 0.301200 -0.060900 0.752000 0.544000 -0.368000 +0.700000 0.251000 -0.093200 0.552000 0.600000 -0.568000 +0.700000 0.251000 -0.093200 0.552000 0.600000 -0.568000 +0.673000 0.251000 -0.121900 0.568000 0.576000 -0.584000 +0.700000 0.229200 -0.121900 0.528000 0.656000 -0.528000 +0.650000 0.251000 -0.154700 0.488000 0.640000 -0.584000 +0.700000 0.200800 -0.171600 0.480000 0.608000 -0.616000 +0.650000 0.227800 -0.182900 0.368000 0.576000 -0.720000 +0.687200 0.200800 -0.182900 0.432000 0.544000 -0.712000 +0.700000 0.200800 -0.171600 0.480000 0.608000 -0.616000 +0.700000 0.190400 -0.182900 0.432000 0.560000 -0.696000 +0.700000 0.190400 -0.182900 0.432000 0.560000 -0.696000 +0.650000 -0.200800 -0.092600 0.656000 0.384000 0.640000 +0.650000 -0.200800 -0.092600 0.656000 0.384000 0.640000 +0.650000 -0.150600 -0.116200 0.720000 0.480000 0.488000 +0.677400 -0.200800 -0.121900 0.528000 0.512000 0.672000 +0.652900 -0.150600 -0.121900 0.752000 0.456000 0.464000 +0.652900 -0.150600 -0.121900 0.752000 0.456000 0.464000 +0.734900 0.200800 -0.121900 0.552000 0.608000 -0.552000 +0.734900 0.200800 -0.121900 0.552000 0.608000 -0.552000 +0.750000 0.186400 -0.121900 0.504000 0.648000 -0.560000 +0.750000 0.200800 -0.104400 0.480000 0.680000 -0.544000 +0.750000 0.200800 -0.104400 0.480000 0.680000 -0.544000 +0.750000 -0.351500 -0.097900 0.640000 0.048000 0.760000 +0.750000 -0.351500 -0.097900 0.640000 0.048000 0.760000 +0.700000 -0.351500 -0.108700 -0.352000 -0.464000 0.808000 +0.750000 -0.301200 -0.116500 0.704000 0.400000 0.568000 +0.700000 -0.301200 -0.068800 0.336000 0.392000 0.848000 +0.700000 -0.301200 -0.068800 0.336000 0.392000 0.848000 +-0.950000 -0.150600 -0.169000 -0.584000 -0.792000 0.136000 +-0.950000 -0.150600 -0.169000 -0.584000 -0.792000 0.136000 +-0.950000 -0.152700 -0.182900 -0.600000 -0.784000 0.144000 +-0.952800 -0.150600 -0.182900 -0.568000 -0.808000 0.136000 +-0.950000 -0.161800 -0.243900 -0.584000 -0.784000 0.176000 +-0.966700 -0.150600 -0.243900 -0.472000 -0.864000 0.152000 +-0.950000 -0.180000 -0.304800 -0.552000 -0.600000 -0.568000 +-0.989000 -0.150600 -0.304800 -0.440000 -0.624000 -0.640000 +-0.950000 -0.150600 -0.330800 -0.416000 -0.432000 -0.792000 +-0.950000 -0.150600 -0.330800 -0.416000 -0.432000 -0.792000 +-0.900000 -0.492700 -0.121900 -0.520000 0.712000 0.448000 +-0.900000 -0.492700 -0.121900 -0.520000 0.712000 0.448000 +-0.900000 -0.462200 -0.182900 0.320000 0.888000 0.304000 +-0.878700 -0.502100 -0.121900 0.408000 0.368000 0.832000 +-0.850000 -0.490700 -0.182900 0.328000 0.896000 0.288000 +-0.850000 -0.502100 -0.144600 0.400000 0.776000 0.480000 +-0.820300 -0.502100 -0.182900 0.496000 0.792000 0.344000 +-0.850000 -0.519700 -0.121900 0.200000 0.624000 0.752000 +-0.800000 -0.513200 -0.182900 -0.080000 0.880000 0.456000 +-0.800000 -0.539500 -0.121900 0.176000 0.680000 0.704000 +-0.750000 -0.503000 -0.182900 -0.200000 0.848000 0.472000 +-0.750000 -0.549900 -0.121900 0.080000 0.648000 0.752000 +-0.749300 -0.502100 -0.182900 -0.920000 -0.232000 0.288000 +-0.723300 -0.502100 -0.121900 -0.896000 -0.224000 0.368000 +-0.723300 -0.502100 -0.121900 -0.896000 -0.224000 0.368000 +-0.900000 -0.511500 -0.121900 -0.520000 -0.664000 0.528000 +-0.900000 -0.511500 -0.121900 -0.520000 -0.664000 0.528000 +-0.900000 -0.542100 -0.182900 -0.808000 -0.560000 0.136000 +-0.868200 -0.552300 -0.121900 -0.520000 -0.224000 0.816000 +-0.892400 -0.552300 -0.182900 -0.760000 -0.624000 0.176000 +-0.850000 -0.569100 -0.121900 -0.488000 -0.776000 0.384000 +-0.850000 -0.592600 -0.182900 -0.520000 -0.800000 0.264000 +-0.800000 -0.584500 -0.121900 -0.288000 -0.544000 0.776000 +-0.832500 -0.602500 -0.182900 -0.576000 -0.768000 0.272000 +-0.800000 -0.602500 -0.136500 -0.416000 -0.648000 0.632000 +-0.800000 -0.620600 -0.182900 -0.312000 -0.880000 0.336000 +-0.764000 -0.602500 -0.121900 -0.176000 -0.816000 0.544000 +-0.750000 -0.630100 -0.182900 -0.144000 -0.912000 0.360000 +-0.750000 -0.605000 -0.121900 -0.152000 -0.872000 0.456000 +-0.750000 -0.605000 -0.121900 -0.152000 -0.872000 0.456000 +-0.802000 -0.351500 -0.121900 -0.840000 -0.520000 0.096000 +-0.802000 -0.351500 -0.121900 -0.840000 -0.520000 0.096000 +-0.832400 -0.301200 -0.121900 -0.840000 -0.528000 0.048000 +-0.802200 -0.351500 -0.182900 -0.872000 -0.480000 0.016000 +-0.831100 -0.301200 -0.182900 -0.848000 -0.520000 0.016000 +-0.807300 -0.351500 -0.243900 -0.864000 -0.472000 0.152000 +-0.834700 -0.301200 -0.243900 -0.840000 -0.504000 0.184000 +-0.834700 -0.301200 -0.243900 -0.840000 -0.504000 0.184000 +-0.779100 0.150600 -0.182900 0.400000 0.664000 -0.616000 +-0.779100 0.150600 -0.182900 0.400000 0.664000 -0.616000 +-0.750000 0.132600 -0.182900 0.408000 0.656000 -0.624000 +-0.750000 0.150600 -0.159200 0.432000 0.664000 -0.600000 +-0.750000 0.150600 -0.159200 0.432000 0.664000 -0.600000 +-0.750000 -0.448400 -0.121900 -0.880000 -0.432000 0.160000 +-0.750000 -0.448400 -0.121900 -0.880000 -0.432000 0.160000 +-0.750000 -0.451900 -0.133400 -0.896000 -0.392000 0.184000 +-0.771000 -0.401700 -0.121900 -0.872000 -0.456000 0.128000 +-0.757600 -0.451900 -0.182900 -0.952000 -0.232000 0.184000 +-0.775200 -0.401700 -0.182900 -0.904000 -0.400000 0.120000 +-0.769800 -0.451900 -0.243900 -0.952000 -0.080000 0.272000 +-0.781800 -0.401700 -0.243900 -0.912000 -0.336000 0.208000 +-0.787800 -0.451900 -0.304800 -0.984000 0.136000 -0.040000 +-0.797400 -0.401700 -0.304800 -0.928000 -0.344000 0.056000 +-0.797400 -0.401700 -0.304800 -0.928000 -0.344000 0.056000 +-0.800000 -0.584500 -0.121900 -0.288000 -0.544000 0.776000 +-0.800000 -0.584500 -0.121900 -0.288000 -0.544000 0.776000 +-0.764000 -0.602500 -0.121900 -0.176000 -0.816000 0.544000 +-0.800000 -0.602500 -0.136500 -0.416000 -0.648000 0.632000 +-0.800000 -0.602500 -0.136500 -0.416000 -0.648000 0.632000 +-0.750000 0.174400 -0.121900 0.448000 0.824000 -0.336000 +-0.750000 0.174400 -0.121900 0.448000 0.824000 -0.336000 +-0.750000 0.150600 -0.159200 0.432000 0.664000 -0.600000 +-0.715000 0.150600 -0.121900 0.512000 0.744000 -0.408000 +-0.715000 0.150600 -0.121900 0.512000 0.744000 -0.408000 +-0.700900 0.100400 -0.182900 0.440000 0.608000 -0.648000 +-0.700900 0.100400 -0.182900 0.440000 0.608000 -0.648000 +-0.700000 0.099700 -0.182900 0.504000 0.560000 -0.640000 +-0.700000 0.100400 -0.182100 0.536000 0.592000 -0.592000 +-0.700000 0.100400 -0.182100 0.536000 0.592000 -0.592000 +-0.750000 -0.448400 -0.121900 -0.880000 -0.432000 0.160000 +-0.750000 -0.448400 -0.121900 -0.880000 -0.432000 0.160000 +-0.748200 -0.451900 -0.121900 -0.880000 -0.440000 0.160000 +-0.750000 -0.451900 -0.133400 -0.896000 -0.392000 0.184000 +-0.750000 -0.451900 -0.133400 -0.896000 -0.392000 0.184000 +-0.700000 0.140000 -0.121900 0.536000 0.728000 -0.408000 +-0.700000 0.140000 -0.121900 0.536000 0.728000 -0.408000 +-0.700000 0.100400 -0.182100 0.536000 0.592000 -0.592000 +-0.657700 0.100400 -0.121900 0.728000 0.576000 -0.360000 +-0.657700 0.100400 -0.121900 0.728000 0.576000 -0.360000 +-0.652800 0.050200 -0.182900 0.592000 0.536000 -0.592000 +-0.652800 0.050200 -0.182900 0.592000 0.536000 -0.592000 +-0.650000 0.045800 -0.182900 0.672000 0.432000 -0.592000 +-0.650000 0.050200 -0.178200 0.664000 0.544000 -0.504000 +-0.621400 0.000000 -0.182900 0.848000 0.280000 -0.440000 +-0.614300 0.050200 -0.121900 0.720000 0.480000 -0.480000 +-0.601900 0.000000 -0.121900 0.848000 0.208000 -0.472000 +-0.601900 0.000000 -0.121900 0.848000 0.208000 -0.472000 +-0.650000 0.089500 -0.121900 0.728000 0.552000 -0.384000 +-0.650000 0.089500 -0.121900 0.728000 0.552000 -0.384000 +-0.650000 0.050200 -0.178200 0.664000 0.544000 -0.504000 +-0.614300 0.050200 -0.121900 0.720000 0.480000 -0.480000 +-0.614300 0.050200 -0.121900 0.720000 0.480000 -0.480000 +-0.491700 -0.150600 -0.182900 -0.448000 0.848000 -0.264000 +-0.491700 -0.150600 -0.182900 -0.448000 0.848000 -0.264000 +-0.500000 -0.150600 -0.154000 -0.424000 0.880000 -0.160000 +-0.500000 -0.154300 -0.182900 -0.320000 0.920000 -0.176000 +-0.500000 -0.154300 -0.182900 -0.320000 0.920000 -0.176000 +-0.372200 0.000000 -0.121900 -0.848000 0.480000 -0.200000 +-0.372200 0.000000 -0.121900 -0.848000 0.480000 -0.200000 +-0.350000 0.000000 -0.171400 -0.688000 0.416000 -0.584000 +-0.350000 0.031200 -0.121900 -0.744000 0.552000 -0.352000 +-0.350000 0.031200 -0.121900 -0.744000 0.552000 -0.352000 +-0.350000 -0.652700 -0.168800 -0.864000 0.056000 0.488000 +-0.350000 -0.652700 -0.168800 -0.864000 0.056000 0.488000 +-0.300000 -0.652700 -0.176500 0.496000 0.568000 0.648000 +-0.350000 -0.647900 -0.182900 0.008000 0.768000 0.624000 +-0.300000 -0.647500 -0.182900 0.464000 0.632000 0.616000 +-0.350000 -0.630200 -0.243900 -0.144000 0.776000 0.600000 +-0.300000 -0.607200 -0.243900 -0.248000 0.672000 0.688000 +-0.300000 -0.647500 -0.182900 0.464000 0.632000 0.616000 +-0.286800 -0.602500 -0.243900 -0.320000 0.232000 0.912000 +-0.293900 -0.652700 -0.182900 0.576000 0.496000 0.640000 +-0.250000 -0.602500 -0.226600 0.288000 -0.512000 0.800000 +-0.250000 -0.652700 -0.232900 0.624000 0.072000 0.768000 +-0.233200 -0.602500 -0.243900 0.608000 -0.320000 0.720000 +-0.241600 -0.652700 -0.243900 0.680000 -0.216000 0.688000 +-0.250000 -0.652700 -0.232900 0.624000 0.072000 0.768000 +-0.250000 -0.679700 -0.243900 0.728000 -0.208000 0.640000 +-0.293900 -0.652700 -0.182900 0.576000 0.496000 0.640000 +-0.256000 -0.703000 -0.243900 0.696000 -0.392000 0.584000 +-0.293800 -0.703000 -0.182900 0.608000 -0.624000 0.488000 +-0.293900 -0.652700 -0.182900 0.576000 0.496000 0.640000 +-0.300000 -0.703000 -0.173800 0.616000 -0.544000 0.552000 +-0.300000 -0.652700 -0.176500 0.496000 0.568000 0.648000 +-0.350000 -0.703000 -0.180700 -0.616000 -0.504000 0.592000 +-0.350000 -0.652700 -0.168800 -0.864000 0.056000 0.488000 +-0.350000 -0.652700 -0.168800 -0.864000 0.056000 0.488000 +-0.260200 -0.552300 -0.121900 -0.560000 -0.752000 0.336000 +-0.260200 -0.552300 -0.121900 -0.560000 -0.752000 0.336000 +-0.300000 -0.516400 -0.121900 -0.256000 -0.872000 0.400000 +-0.285200 -0.552300 -0.182900 -0.616000 -0.680000 0.384000 +-0.300000 -0.538300 -0.182900 -0.584000 -0.696000 0.408000 +-0.300000 -0.552300 -0.209900 -0.624000 -0.616000 0.456000 +-0.300000 -0.552300 -0.209900 -0.624000 -0.616000 0.456000 +-0.300000 -0.647500 -0.182900 0.464000 0.632000 0.616000 +-0.300000 -0.647500 -0.182900 0.464000 0.632000 0.616000 +-0.293900 -0.652700 -0.182900 0.576000 0.496000 0.640000 +-0.300000 -0.652700 -0.176500 0.496000 0.568000 0.648000 +-0.300000 -0.652700 -0.176500 0.496000 0.568000 0.648000 +-0.200000 0.251000 -0.156200 -0.432000 0.168000 -0.880000 +-0.200000 0.251000 -0.156200 -0.432000 0.168000 -0.880000 +-0.250000 0.251000 -0.124000 -0.376000 0.088000 -0.920000 +-0.200000 0.200800 -0.161600 -0.480000 0.384000 -0.776000 +-0.250000 0.200800 -0.129700 -0.392000 0.152000 -0.904000 +-0.250000 0.200800 -0.129700 -0.392000 0.152000 -0.904000 +-0.200000 -0.534300 -0.121900 0.456000 -0.832000 0.296000 +-0.200000 -0.534300 -0.121900 0.456000 -0.832000 0.296000 +-0.235800 -0.552300 -0.121900 0.448000 -0.816000 0.336000 +-0.200000 -0.549300 -0.182900 0.504000 -0.784000 0.344000 +-0.204600 -0.552300 -0.182900 0.504000 -0.776000 0.360000 +-0.200000 -0.552300 -0.190900 0.520000 -0.768000 0.360000 +-0.200000 -0.552300 -0.190900 0.520000 -0.768000 0.360000 +-0.200000 0.401700 -0.127400 -0.400000 0.440000 -0.800000 +-0.200000 0.401700 -0.127400 -0.400000 0.440000 -0.800000 +-0.150000 0.401700 -0.148200 -0.240000 0.400000 -0.872000 +-0.200000 0.351500 -0.146000 -0.416000 0.224000 -0.872000 +-0.150000 0.351500 -0.156300 -0.024000 0.152000 -0.984000 +-0.200000 0.301200 -0.154100 -0.392000 0.112000 -0.904000 +-0.150000 0.301200 -0.169700 -0.080000 0.248000 -0.960000 +-0.150000 0.351500 -0.156300 -0.024000 0.152000 -0.984000 +-0.100000 0.301200 -0.172200 -0.168000 0.416000 -0.888000 +-0.100000 0.351500 -0.158200 0.008000 0.264000 -0.960000 +-0.150000 0.351500 -0.156300 -0.024000 0.152000 -0.984000 +-0.100000 0.401700 -0.143600 0.056000 0.120000 -0.984000 +-0.150000 0.401700 -0.148200 -0.240000 0.400000 -0.872000 +-0.100000 0.451900 -0.142300 -0.128000 0.312000 -0.936000 +-0.150000 0.451900 -0.123200 -0.344000 0.512000 -0.784000 +-0.150000 0.451900 -0.123200 -0.344000 0.512000 -0.784000 +-0.100000 0.044900 -0.121900 0.816000 0.112000 0.552000 +-0.100000 0.044900 -0.121900 0.816000 0.112000 0.552000 +-0.100700 0.050200 -0.121900 0.856000 0.048000 0.504000 +-0.100000 0.050200 -0.123300 0.696000 -0.176000 0.688000 +-0.100000 0.050200 -0.123300 0.696000 -0.176000 0.688000 +-0.100000 0.451900 -0.142300 -0.128000 0.312000 -0.936000 +-0.100000 0.451900 -0.142300 -0.128000 0.312000 -0.936000 +-0.050000 0.451900 -0.137500 0.040000 0.112000 -0.992000 +-0.100000 0.401700 -0.143600 0.056000 0.120000 -0.984000 +-0.050000 0.401700 -0.142300 0.000000 0.168000 -0.984000 +-0.100000 0.351500 -0.158200 0.008000 0.264000 -0.960000 +-0.050000 0.351500 -0.155800 -0.048000 0.328000 -0.936000 +-0.050000 0.401700 -0.142300 0.000000 0.168000 -0.984000 +0.000000 0.351500 -0.164900 -0.080000 0.368000 -0.920000 +0.000000 0.401700 -0.144600 -0.056000 0.192000 -0.976000 +0.050000 0.351500 -0.166400 0.000000 0.392000 -0.912000 +0.050000 0.401700 -0.150400 -0.088000 0.216000 -0.968000 +0.100000 0.351500 -0.169000 0.056000 0.272000 -0.952000 +0.100000 0.401700 -0.152800 -0.048000 0.168000 -0.984000 +0.150000 0.351500 -0.160600 0.144000 0.128000 -0.976000 +0.150000 0.401700 -0.154900 -0.096000 0.088000 -0.984000 +0.200000 0.351500 -0.169700 -0.320000 0.304000 -0.888000 +0.200000 0.401700 -0.169400 -0.056000 0.168000 -0.976000 +0.150000 0.401700 -0.154900 -0.096000 0.088000 -0.984000 +0.200000 0.451900 -0.151000 0.136000 0.400000 -0.896000 +0.150000 0.451900 -0.151900 0.184000 0.376000 -0.904000 +0.200000 0.484800 -0.121900 0.312000 0.872000 0.360000 +0.150000 0.502100 -0.123200 0.032000 0.424000 -0.896000 +0.153400 0.502100 -0.121900 0.448000 0.824000 -0.336000 +0.153400 0.502100 -0.121900 0.448000 0.824000 -0.336000 +-0.089600 0.000000 -0.121900 0.568000 0.512000 0.632000 +-0.089600 0.000000 -0.121900 0.568000 0.512000 0.632000 +-0.050000 0.000000 -0.158900 0.584000 0.336000 0.728000 +-0.050000 -0.024600 -0.121900 0.296000 0.656000 0.688000 +0.000000 0.000000 -0.165000 0.096000 0.640000 0.752000 +0.000000 -0.035500 -0.121900 0.072000 0.496000 0.856000 +0.050000 0.000000 -0.179700 0.216000 0.504000 0.832000 +0.050000 -0.038600 -0.121900 0.000000 0.528000 0.840000 +0.100000 0.000000 -0.179900 0.000000 0.528000 0.840000 +0.100000 -0.037100 -0.121900 -0.016000 0.544000 0.832000 +0.100000 -0.037100 -0.121900 -0.016000 0.544000 0.832000 +-0.054100 -0.401700 -0.121900 0.656000 -0.688000 0.280000 +-0.054100 -0.401700 -0.121900 0.656000 -0.688000 0.280000 +-0.098000 -0.451900 -0.121900 0.712000 -0.680000 0.120000 +-0.061900 -0.401700 -0.182900 0.744000 -0.648000 -0.120000 +-0.098100 -0.451900 -0.182900 0.736000 -0.672000 0.032000 +-0.071000 -0.401700 -0.243900 0.856000 -0.496000 -0.072000 +-0.094700 -0.451900 -0.243900 0.784000 -0.568000 0.216000 +-0.073900 -0.401700 -0.304800 0.784000 -0.304000 -0.528000 +-0.061500 -0.451900 -0.304800 0.928000 -0.352000 0.088000 +-0.100000 -0.401700 -0.330800 0.576000 -0.152000 -0.792000 +-0.100000 -0.451900 -0.336100 0.496000 -0.048000 -0.856000 +-0.150000 -0.401700 -0.364300 0.552000 0.080000 -0.824000 +-0.145700 -0.451900 -0.365800 0.464000 0.040000 -0.880000 +-0.150000 -0.417500 -0.365800 0.544000 0.056000 -0.832000 +-0.150000 -0.451900 -0.368100 0.456000 -0.056000 -0.880000 +-0.145700 -0.451900 -0.365800 0.464000 0.040000 -0.880000 +-0.150000 -0.502100 -0.367300 0.088000 -0.320000 -0.936000 +-0.147100 -0.502100 -0.365800 0.472000 -0.192000 -0.848000 +-0.150000 -0.505900 -0.365800 0.272000 -0.320000 -0.904000 +-0.150000 -0.505900 -0.365800 0.272000 -0.320000 -0.904000 +-0.050000 0.401700 -0.142300 0.000000 0.168000 -0.984000 +-0.050000 0.401700 -0.142300 0.000000 0.168000 -0.984000 +-0.050000 0.451900 -0.137500 0.040000 0.112000 -0.992000 +0.000000 0.401700 -0.144600 -0.056000 0.192000 -0.976000 +0.000000 0.451900 -0.135500 0.000000 0.160000 -0.984000 +0.050000 0.401700 -0.150400 -0.088000 0.216000 -0.968000 +0.050000 0.451900 -0.139600 -0.080000 0.232000 -0.960000 +0.100000 0.401700 -0.152800 -0.048000 0.168000 -0.984000 +0.100000 0.451900 -0.146900 -0.088000 0.224000 -0.968000 +0.150000 0.401700 -0.154900 -0.096000 0.088000 -0.984000 +0.150000 0.451900 -0.151900 0.184000 0.376000 -0.904000 +0.150000 0.451900 -0.151900 0.184000 0.376000 -0.904000 +-0.012800 0.200800 -0.121900 0.688000 -0.616000 0.376000 +-0.012800 0.200800 -0.121900 0.688000 -0.616000 0.376000 +0.000000 0.211400 -0.121900 0.496000 -0.712000 0.480000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +-0.050000 0.150600 -0.159500 0.712000 -0.480000 0.504000 +-0.033200 0.150600 -0.182900 0.832000 -0.552000 -0.016000 +-0.050000 0.116900 -0.182900 0.944000 -0.304000 0.048000 +-0.050000 0.150600 -0.210200 0.840000 -0.208000 -0.496000 +-0.050000 0.150600 -0.210200 0.840000 -0.208000 -0.496000 +-0.050000 0.047900 -0.182900 0.488000 0.480000 0.720000 +-0.050000 0.047900 -0.182900 0.488000 0.480000 0.720000 +-0.050000 0.000000 -0.158900 0.584000 0.336000 0.728000 +0.000000 0.039200 -0.182900 0.256000 0.544000 0.792000 +0.000000 0.000000 -0.165000 0.096000 0.640000 0.752000 +0.050000 0.005700 -0.182900 0.312000 0.584000 0.744000 +0.050000 0.000000 -0.179700 0.216000 0.504000 0.832000 +0.100000 0.004900 -0.182900 -0.288000 0.864000 0.400000 +0.100000 0.000000 -0.179900 0.000000 0.528000 0.840000 +0.100000 0.000000 -0.179900 0.000000 0.528000 0.840000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +0.000000 0.200800 -0.169000 0.576000 -0.744000 0.320000 +0.008500 0.200800 -0.182900 0.416000 -0.688000 -0.584000 +0.000000 0.195100 -0.182900 0.504000 -0.656000 -0.544000 +0.000000 0.200800 -0.186400 0.272000 -0.456000 -0.840000 +0.000000 0.200800 -0.186400 0.272000 -0.456000 -0.840000 +0.050000 -0.327900 -0.182900 0.552000 -0.824000 0.048000 +0.050000 -0.327900 -0.182900 0.552000 -0.824000 0.048000 +0.003100 -0.351500 -0.182900 0.504000 -0.840000 -0.160000 +0.050000 -0.321600 -0.121900 0.584000 -0.712000 0.376000 +0.006400 -0.351500 -0.121900 0.552000 -0.776000 0.288000 +0.006400 -0.351500 -0.121900 0.552000 -0.776000 0.288000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.150000 0.284700 -0.182900 0.352000 0.368000 -0.856000 +0.194700 0.251000 -0.182900 0.496000 -0.104000 -0.856000 +0.150000 0.251000 -0.192500 0.112000 0.024000 -0.992000 +0.150000 0.224100 -0.182900 0.056000 -0.672000 -0.728000 +0.194700 0.251000 -0.182900 0.496000 -0.104000 -0.856000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.150000 0.251000 -0.128300 0.144000 -0.904000 0.392000 +0.211500 -0.301200 -0.182900 -0.568000 -0.672000 0.464000 +0.211500 -0.301200 -0.182900 -0.568000 -0.672000 0.464000 +0.250000 -0.301200 -0.149400 -0.376000 -0.584000 0.712000 +0.250000 -0.319600 -0.182900 -0.280000 -0.832000 0.472000 +0.300000 -0.301200 -0.149800 -0.024000 -0.480000 0.872000 +0.300000 -0.330300 -0.182900 -0.312000 -0.696000 0.632000 +0.350000 -0.301200 -0.148100 0.392000 -0.048000 0.912000 +0.331500 -0.351500 -0.182900 -0.432000 -0.576000 0.688000 +0.350000 -0.351500 -0.171100 -0.312000 -0.512000 0.792000 +0.350000 -0.366900 -0.182900 -0.368000 -0.552000 0.736000 +0.400000 -0.351500 -0.165500 0.064000 -0.056000 0.992000 +0.400000 -0.370500 -0.182900 -0.008000 -0.616000 0.776000 +0.450000 -0.351500 -0.174300 0.040000 0.080000 0.992000 +0.450000 -0.370700 -0.182900 -0.080000 -0.520000 0.848000 +0.500000 -0.351500 -0.156800 -0.392000 -0.248000 0.880000 +0.500000 -0.372900 -0.182900 -0.184000 -0.776000 0.592000 +0.450000 -0.370700 -0.182900 -0.080000 -0.520000 0.848000 +0.500000 -0.400600 -0.243900 0.024000 -0.920000 0.384000 +0.450000 -0.401700 -0.212100 0.240000 -0.816000 0.520000 +0.496800 -0.401700 -0.243900 0.256000 -0.880000 0.376000 +0.450000 -0.418500 -0.243900 -0.152000 -0.896000 0.400000 +0.492100 -0.401700 -0.304800 0.152000 -0.576000 -0.792000 +0.450000 -0.411100 -0.304800 -0.144000 -0.808000 -0.560000 +0.450000 -0.401700 -0.316200 -0.184000 -0.360000 -0.904000 +0.428900 -0.401700 -0.304800 -0.392000 -0.464000 -0.784000 +0.450000 -0.380500 -0.304800 -0.144000 0.256000 -0.952000 +0.400000 -0.401700 -0.257800 0.112000 -0.952000 -0.280000 +0.450000 -0.351500 -0.290700 -0.176000 0.632000 -0.744000 +0.400000 -0.388800 -0.304800 0.392000 -0.800000 -0.448000 +0.437100 -0.351500 -0.304800 0.688000 0.472000 -0.536000 +0.400000 -0.351500 -0.338800 0.360000 -0.568000 -0.728000 +0.401200 -0.301200 -0.304800 0.744000 0.488000 -0.440000 +0.400000 -0.301200 -0.307300 0.704000 0.496000 -0.496000 +0.400000 -0.299100 -0.304800 0.736000 0.472000 -0.472000 +0.401200 -0.301200 -0.304800 0.744000 0.488000 -0.440000 +0.400000 -0.252300 -0.243900 0.744000 0.488000 -0.440000 +0.429200 -0.301200 -0.243900 0.816000 0.544000 -0.176000 +0.400000 -0.252800 -0.182900 0.760000 0.464000 0.440000 +0.427100 -0.301200 -0.182900 0.776000 0.464000 0.416000 +0.400000 -0.301200 -0.149800 0.528000 0.376000 0.752000 +0.450000 -0.338000 -0.182900 0.248000 0.592000 0.752000 +0.400000 -0.351500 -0.165500 0.064000 -0.056000 0.992000 +0.450000 -0.351500 -0.174300 0.040000 0.080000 0.992000 +0.450000 -0.338000 -0.182900 0.248000 0.592000 0.752000 +0.500000 -0.351500 -0.156800 -0.392000 -0.248000 0.880000 +0.500000 -0.316400 -0.182900 -0.704000 0.472000 0.520000 +0.450000 -0.338000 -0.182900 0.248000 0.592000 0.752000 +0.500000 -0.310500 -0.243900 -0.600000 0.776000 -0.152000 +0.450000 -0.327300 -0.243900 -0.064000 0.864000 -0.488000 +0.500000 -0.333600 -0.304800 -0.408000 0.824000 -0.376000 +0.450000 -0.351500 -0.290700 -0.176000 0.632000 -0.744000 +0.458900 -0.351500 -0.304800 -0.472000 0.360000 -0.792000 +0.450000 -0.380500 -0.304800 -0.144000 0.256000 -0.952000 +0.500000 -0.400200 -0.304800 -0.176000 -0.672000 -0.712000 +0.492100 -0.401700 -0.304800 0.152000 -0.576000 -0.792000 +0.500000 -0.400600 -0.243900 0.024000 -0.920000 0.384000 +0.496800 -0.401700 -0.243900 0.256000 -0.880000 0.376000 +0.496800 -0.401700 -0.243900 0.256000 -0.880000 0.376000 +0.265700 0.200800 -0.182900 -0.312000 -0.760000 -0.552000 +0.265700 0.200800 -0.182900 -0.312000 -0.760000 -0.552000 +0.300000 0.218000 -0.182900 0.768000 0.424000 -0.464000 +0.300000 0.200800 -0.174500 0.536000 -0.360000 0.752000 +0.306800 0.200800 -0.182900 0.752000 -0.400000 -0.512000 +0.300000 0.193900 -0.182900 0.520000 -0.696000 -0.480000 +0.300000 0.200800 -0.185900 0.256000 -0.192000 -0.944000 +0.265700 0.200800 -0.182900 -0.312000 -0.760000 -0.552000 +0.300000 0.218000 -0.182900 0.768000 0.424000 -0.464000 +0.300000 0.200800 -0.185900 0.256000 -0.192000 -0.944000 +0.306800 0.200800 -0.182900 0.752000 -0.400000 -0.512000 +0.306800 0.200800 -0.182900 0.752000 -0.400000 -0.512000 +0.265700 0.200800 -0.182900 -0.312000 -0.760000 -0.552000 +0.265700 0.200800 -0.182900 -0.312000 -0.760000 -0.552000 +0.300000 0.200800 -0.174500 0.536000 -0.360000 0.752000 +0.300000 0.193900 -0.182900 0.520000 -0.696000 -0.480000 +0.300000 0.193900 -0.182900 0.520000 -0.696000 -0.480000 +0.300000 0.284000 -0.182900 -0.168000 -0.184000 -0.960000 +0.300000 0.284000 -0.182900 -0.168000 -0.184000 -0.960000 +0.300000 0.251000 -0.156100 -0.368000 -0.808000 -0.448000 +0.321900 0.251000 -0.182900 -0.240000 -0.296000 -0.920000 +0.321900 0.251000 -0.182900 -0.240000 -0.296000 -0.920000 +0.307700 -0.050200 -0.121900 -0.592000 0.464000 0.648000 +0.307700 -0.050200 -0.121900 -0.592000 0.464000 0.648000 +0.300000 -0.060700 -0.121900 -0.512000 0.456000 0.720000 +0.300000 -0.050200 -0.130700 -0.504000 0.472000 0.720000 +0.300000 -0.050200 -0.130700 -0.504000 0.472000 0.720000 +0.329200 -0.200800 -0.121900 0.376000 -0.264000 0.880000 +0.329200 -0.200800 -0.121900 0.376000 -0.264000 0.880000 +0.350000 -0.182300 -0.121900 -0.032000 -0.520000 0.848000 +0.350000 -0.200800 -0.137500 0.248000 -0.232000 0.936000 +0.391400 -0.200800 -0.121900 -0.176000 -0.648000 0.736000 +0.391400 -0.200800 -0.121900 -0.176000 -0.648000 0.736000 +0.400000 0.100400 -0.150800 -0.768000 0.376000 0.512000 +0.400000 0.100400 -0.150800 -0.768000 0.376000 0.512000 +0.381500 0.100400 -0.182900 -0.896000 0.440000 -0.008000 +0.400000 0.146600 -0.182900 -0.440000 0.464000 -0.760000 +0.400000 0.100400 -0.207800 -0.424000 0.688000 -0.576000 +0.400000 0.100400 -0.207800 -0.424000 0.688000 -0.576000 +0.400000 -0.203000 -0.121900 -0.184000 -0.672000 0.712000 +0.400000 -0.203000 -0.121900 -0.184000 -0.672000 0.712000 +0.354900 -0.251000 -0.121900 0.704000 -0.304000 0.632000 +0.400000 -0.249800 -0.182900 0.472000 -0.752000 0.448000 +0.398900 -0.251000 -0.182900 0.896000 -0.160000 0.400000 +0.400000 -0.249400 -0.243900 0.760000 -0.472000 -0.424000 +0.399000 -0.251000 -0.243900 0.912000 -0.008000 -0.392000 +0.399000 -0.251000 -0.243900 0.912000 -0.008000 -0.392000 +0.400000 -0.351500 -0.165500 0.064000 -0.056000 0.992000 +0.400000 -0.351500 -0.165500 0.064000 -0.056000 0.992000 +0.350000 -0.351500 -0.171100 -0.312000 -0.512000 0.792000 +0.400000 -0.301200 -0.149800 0.528000 0.376000 0.752000 +0.350000 -0.301200 -0.148100 0.392000 -0.048000 0.912000 +0.350000 -0.301200 -0.148100 0.392000 -0.048000 0.912000 +0.450000 -0.251000 -0.179900 -0.288000 -0.680000 0.664000 +0.450000 -0.251000 -0.179900 -0.288000 -0.680000 0.664000 +0.450000 -0.255300 -0.182900 -0.208000 -0.656000 0.712000 +0.415700 -0.251000 -0.182900 -0.088000 -0.872000 0.480000 +0.450000 -0.251000 -0.203800 -0.216000 -0.960000 -0.144000 +0.450000 -0.251000 -0.203800 -0.216000 -0.960000 -0.144000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.506000 0.351500 -0.182900 0.424000 0.584000 -0.680000 +0.500000 0.393600 -0.121900 0.504000 0.744000 -0.432000 +0.550000 0.351500 -0.135900 0.456000 0.632000 -0.616000 +0.550000 0.362300 -0.121900 0.400000 0.656000 -0.632000 +0.566700 0.351500 -0.121900 0.448000 0.536000 -0.704000 +0.566700 0.351500 -0.121900 0.448000 0.536000 -0.704000 +0.550000 0.351500 -0.135900 0.456000 0.632000 -0.616000 +0.550000 0.351500 -0.135900 0.456000 0.632000 -0.616000 +0.550000 0.301200 -0.167400 0.408000 0.504000 -0.752000 +0.506000 0.351500 -0.182900 0.424000 0.584000 -0.680000 +0.526000 0.301200 -0.182900 0.408000 0.312000 -0.848000 +0.500000 0.351500 -0.187300 0.416000 0.568000 -0.696000 +0.500000 0.301200 -0.193500 0.168000 0.072000 -0.976000 +0.526000 0.301200 -0.182900 0.408000 0.312000 -0.848000 +0.500000 0.251000 -0.199400 0.072000 0.096000 -0.984000 +0.550000 0.283200 -0.182900 0.320000 0.472000 -0.816000 +0.550000 0.251000 -0.199600 0.176000 0.288000 -0.936000 +0.500000 0.251000 -0.199400 0.072000 0.096000 -0.984000 +0.550000 0.200800 -0.211100 0.016000 0.048000 -0.992000 +0.500000 0.200800 -0.200200 -0.104000 -0.048000 -0.992000 +0.550000 0.150600 -0.215400 -0.144000 0.080000 -0.984000 +0.500000 0.150600 -0.194400 -0.208000 0.240000 -0.944000 +0.550000 0.100400 -0.212600 -0.200000 0.352000 -0.904000 +0.500000 0.100400 -0.210700 0.048000 0.704000 -0.704000 +0.550000 0.067800 -0.243900 0.024000 0.672000 -0.728000 +0.500000 0.082500 -0.243900 0.216000 0.832000 -0.504000 +0.550000 0.050200 -0.258400 0.160000 0.632000 -0.752000 +0.500000 0.050200 -0.303800 0.264000 0.816000 -0.504000 +0.550000 0.015600 -0.304800 0.472000 0.712000 -0.512000 +0.500000 0.049600 -0.304800 0.264000 0.736000 -0.616000 +0.550000 0.000000 -0.335900 0.576000 0.464000 -0.664000 +0.500000 0.014000 -0.365800 0.216000 0.784000 -0.568000 +0.524100 0.000000 -0.365800 0.648000 0.312000 -0.688000 +0.500000 0.000000 -0.393700 0.528000 0.072000 -0.840000 +0.500000 -0.027200 -0.365800 0.264000 -0.576000 -0.768000 +0.524100 0.000000 -0.365800 0.648000 0.312000 -0.688000 +0.500000 -0.050200 -0.339600 -0.136000 -0.672000 -0.720000 +0.550000 0.000000 -0.335900 0.576000 0.464000 -0.664000 +0.550000 -0.050200 -0.345500 0.192000 -0.560000 -0.792000 +0.550000 -0.050200 -0.345500 0.192000 -0.560000 -0.792000 +0.526000 0.301200 -0.182900 0.408000 0.312000 -0.848000 +0.526000 0.301200 -0.182900 0.408000 0.312000 -0.848000 +0.550000 0.283200 -0.182900 0.320000 0.472000 -0.816000 +0.550000 0.301200 -0.167400 0.408000 0.504000 -0.752000 +0.550000 0.301200 -0.167400 0.408000 0.504000 -0.752000 +0.500000 -0.250100 -0.121900 -0.432000 -0.712000 0.536000 +0.500000 -0.250100 -0.121900 -0.432000 -0.712000 0.536000 +0.501100 -0.251000 -0.121900 -0.552000 -0.624000 0.544000 +0.500000 -0.251000 -0.123800 -0.544000 -0.688000 0.456000 +0.500000 -0.251000 -0.123800 -0.544000 -0.688000 0.456000 +0.608400 0.251000 -0.182900 0.328000 0.488000 -0.800000 +0.608400 0.251000 -0.182900 0.328000 0.488000 -0.800000 +0.650000 0.227800 -0.182900 0.368000 0.576000 -0.720000 +0.650000 0.251000 -0.154700 0.488000 0.640000 -0.584000 +0.650000 0.251000 -0.154700 0.488000 0.640000 -0.584000 +0.600000 -0.333000 -0.121900 0.024000 -0.312000 0.944000 +0.600000 -0.333000 -0.121900 0.024000 -0.312000 0.944000 +0.600000 -0.351500 -0.136300 0.144000 -0.792000 0.584000 +0.650000 -0.327200 -0.121900 -0.280000 -0.536000 0.792000 +0.650000 -0.351500 -0.143500 -0.280000 -0.536000 0.784000 +0.679500 -0.351500 -0.121900 -0.424000 -0.464000 0.768000 +0.650000 -0.401700 -0.175000 -0.240000 -0.688000 0.680000 +0.700000 -0.372000 -0.121900 -0.360000 -0.440000 0.816000 +0.700000 -0.401700 -0.145100 -0.400000 -0.504000 0.752000 +0.737900 -0.401700 -0.121900 -0.352000 -0.448000 0.816000 +0.700000 -0.435200 -0.182900 -0.448000 -0.712000 0.536000 +0.750000 -0.411100 -0.121900 -0.304000 -0.456000 0.824000 +0.719600 -0.451900 -0.182900 -0.568000 -0.640000 0.512000 +0.750000 -0.451900 -0.153800 -0.384000 -0.528000 0.752000 +0.750000 -0.479900 -0.182900 -0.456000 -0.632000 0.616000 +0.719600 -0.451900 -0.182900 -0.568000 -0.640000 0.512000 +0.750000 -0.502100 -0.236900 -0.448000 -0.776000 0.432000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.744200 -0.502100 -0.243900 -0.480000 -0.864000 0.128000 +0.700000 -0.472400 -0.243900 -0.560000 -0.816000 -0.016000 +0.750000 -0.502100 -0.254300 -0.448000 -0.832000 -0.312000 +0.700000 -0.481300 -0.304800 -0.240000 -0.712000 -0.656000 +0.750000 -0.487000 -0.304800 -0.104000 -0.744000 -0.656000 +0.700000 -0.451900 -0.321600 -0.136000 -0.312000 -0.936000 +0.750000 -0.451900 -0.330900 0.152000 -0.080000 -0.984000 +0.700000 -0.401700 -0.334100 0.120000 -0.128000 -0.976000 +0.750000 -0.401700 -0.321600 0.336000 0.000000 -0.936000 +0.700000 -0.351500 -0.333900 0.344000 -0.040000 -0.936000 +0.750000 -0.351500 -0.307800 0.512000 0.128000 -0.840000 +0.700000 -0.301200 -0.354900 0.160000 -0.240000 -0.952000 +0.750000 -0.334300 -0.304800 0.512000 0.112000 -0.840000 +0.744500 -0.301200 -0.304800 0.640000 0.104000 -0.760000 +0.750000 -0.301200 -0.299800 0.512000 0.144000 -0.840000 +0.728900 -0.251000 -0.304800 0.720000 0.440000 -0.528000 +0.750000 -0.251000 -0.256700 0.824000 0.520000 -0.208000 +0.700000 -0.211400 -0.304800 0.288000 0.624000 -0.720000 +0.750000 -0.247000 -0.243900 0.832000 0.536000 -0.096000 +0.700000 -0.200800 -0.294000 0.576000 0.608000 -0.536000 +0.717800 -0.200800 -0.243900 0.824000 0.560000 -0.064000 +0.700000 -0.175300 -0.243900 0.752000 0.600000 -0.240000 +0.713600 -0.200800 -0.182900 0.824000 0.512000 0.224000 +0.700000 -0.178500 -0.182900 0.792000 0.568000 0.200000 +0.700000 -0.200800 -0.144600 0.696000 0.528000 0.480000 +0.700000 -0.200800 -0.144600 0.696000 0.528000 0.480000 +0.600000 -0.351500 -0.136300 0.144000 -0.792000 0.584000 +0.600000 -0.351500 -0.136300 0.144000 -0.792000 0.584000 +0.650000 -0.351500 -0.143500 -0.280000 -0.536000 0.784000 +0.600000 -0.392700 -0.182900 -0.184000 -0.752000 0.624000 +0.650000 -0.401700 -0.175000 -0.240000 -0.688000 0.680000 +0.628900 -0.401700 -0.182900 -0.216000 -0.760000 0.608000 +0.650000 -0.407700 -0.182900 -0.272000 -0.728000 0.624000 +0.600000 -0.401700 -0.203000 -0.208000 -0.872000 0.432000 +0.650000 -0.436800 -0.243900 -0.416000 -0.848000 0.320000 +0.600000 -0.414700 -0.243900 -0.184000 -0.936000 0.272000 +0.650000 -0.449600 -0.304800 -0.280000 -0.432000 -0.848000 +0.600000 -0.422100 -0.304800 -0.120000 -0.768000 -0.616000 +0.650000 -0.401700 -0.330300 -0.240000 -0.360000 -0.896000 +0.600000 -0.401700 -0.327900 -0.024000 -0.544000 -0.832000 +0.650000 -0.351500 -0.332000 0.016000 -0.144000 -0.984000 +0.600000 -0.351500 -0.337900 0.040000 -0.080000 -0.992000 +0.650000 -0.301200 -0.350300 0.016000 -0.440000 -0.888000 +0.600000 -0.301200 -0.352300 -0.528000 -0.312000 -0.776000 +0.600000 -0.301200 -0.352300 -0.528000 -0.312000 -0.776000 +0.650000 0.278000 -0.121900 0.448000 0.624000 -0.624000 +0.650000 0.278000 -0.121900 0.448000 0.624000 -0.624000 +0.650000 0.251000 -0.154700 0.488000 0.640000 -0.584000 +0.673000 0.251000 -0.121900 0.568000 0.576000 -0.584000 +0.673000 0.251000 -0.121900 0.568000 0.576000 -0.584000 +0.700000 -0.401700 -0.145100 -0.400000 -0.504000 0.752000 +0.700000 -0.401700 -0.145100 -0.400000 -0.504000 0.752000 +0.650000 -0.401700 -0.175000 -0.240000 -0.688000 0.680000 +0.700000 -0.435200 -0.182900 -0.448000 -0.712000 0.536000 +0.650000 -0.407700 -0.182900 -0.272000 -0.728000 0.624000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.650000 -0.436800 -0.243900 -0.416000 -0.848000 0.320000 +0.673600 -0.451900 -0.243900 -0.480000 -0.752000 0.448000 +0.650000 -0.449600 -0.304800 -0.280000 -0.432000 -0.848000 +0.653100 -0.451900 -0.304800 -0.336000 -0.480000 -0.800000 +0.650000 -0.401700 -0.330300 -0.240000 -0.360000 -0.896000 +0.700000 -0.451900 -0.321600 -0.136000 -0.312000 -0.936000 +0.700000 -0.401700 -0.334100 0.120000 -0.128000 -0.976000 +0.650000 -0.401700 -0.330300 -0.240000 -0.360000 -0.896000 +0.700000 -0.351500 -0.333900 0.344000 -0.040000 -0.936000 +0.650000 -0.351500 -0.332000 0.016000 -0.144000 -0.984000 +0.700000 -0.301200 -0.354900 0.160000 -0.240000 -0.952000 +0.650000 -0.301200 -0.350300 0.016000 -0.440000 -0.888000 +0.650000 -0.301200 -0.350300 0.016000 -0.440000 -0.888000 +0.719200 -0.251000 -0.121900 0.760000 0.456000 0.440000 +0.719200 -0.251000 -0.121900 0.760000 0.456000 0.440000 +0.750000 -0.297400 -0.121900 0.656000 0.584000 0.464000 +0.746300 -0.251000 -0.182900 0.848000 0.496000 0.152000 +0.750000 -0.257500 -0.182900 0.856000 0.488000 0.120000 +0.750000 -0.251000 -0.218200 0.840000 0.520000 0.096000 +0.777000 -0.301200 -0.182900 0.784000 0.536000 0.304000 +0.752500 -0.251000 -0.243900 0.840000 0.528000 -0.096000 +0.780500 -0.301200 -0.243900 0.848000 0.504000 -0.128000 +0.777000 -0.301200 -0.182900 0.784000 0.536000 0.304000 +0.800000 -0.328800 -0.243900 0.640000 0.656000 -0.384000 +0.800000 -0.333100 -0.182900 0.680000 0.680000 0.256000 +0.829500 -0.351500 -0.243900 0.648000 0.640000 -0.400000 +0.821300 -0.351500 -0.182900 0.624000 0.648000 0.416000 +0.850000 -0.375700 -0.243900 0.544000 0.616000 -0.552000 +0.850000 -0.381900 -0.182900 0.632000 0.696000 0.328000 +0.890600 -0.401700 -0.243900 0.576000 0.616000 -0.528000 +0.872200 -0.401700 -0.182900 0.632000 0.640000 0.416000 +0.900000 -0.412700 -0.243900 0.520000 0.640000 -0.552000 +0.900000 -0.433800 -0.182900 0.512000 0.688000 0.504000 +0.950000 -0.433400 -0.243900 0.528000 0.832000 0.152000 +0.933400 -0.451900 -0.182900 0.464000 0.712000 0.512000 +0.950000 -0.451900 -0.206400 0.504000 0.736000 0.440000 +0.950000 -0.463500 -0.182900 0.464000 0.672000 0.568000 +0.933400 -0.451900 -0.182900 0.464000 0.712000 0.512000 +0.950000 -0.502100 -0.136000 -0.296000 0.400000 0.864000 +0.900000 -0.451900 -0.156900 0.400000 0.632000 0.656000 +0.900000 -0.502100 -0.123800 -0.168000 -0.208000 0.960000 +0.850000 -0.451900 -0.123600 0.328000 0.296000 0.888000 +0.850000 -0.502100 -0.142100 -0.224000 -0.520000 0.816000 +0.850000 -0.502100 -0.142100 -0.224000 -0.520000 0.816000 +0.750000 -0.257500 -0.182900 0.856000 0.488000 0.120000 +0.750000 -0.257500 -0.182900 0.856000 0.488000 0.120000 +0.750000 -0.297400 -0.121900 0.656000 0.584000 0.464000 +0.777000 -0.301200 -0.182900 0.784000 0.536000 0.304000 +0.752700 -0.301200 -0.121900 0.792000 0.344000 0.488000 +0.800000 -0.333100 -0.182900 0.680000 0.680000 0.256000 +0.775700 -0.351500 -0.121900 0.600000 0.328000 0.720000 +0.800000 -0.351500 -0.149400 0.664000 0.512000 0.528000 +0.800000 -0.391100 -0.121900 0.384000 0.416000 0.816000 +0.821300 -0.351500 -0.182900 0.624000 0.648000 0.416000 +0.810500 -0.401700 -0.121900 0.456000 0.104000 0.872000 +0.850000 -0.381900 -0.182900 0.632000 0.696000 0.328000 +0.850000 -0.401700 -0.151500 0.608000 0.552000 0.560000 +0.872200 -0.401700 -0.182900 0.632000 0.640000 0.416000 +0.850000 -0.451900 -0.123600 0.328000 0.296000 0.888000 +0.900000 -0.433800 -0.182900 0.512000 0.688000 0.504000 +0.900000 -0.451900 -0.156900 0.400000 0.632000 0.656000 +0.933400 -0.451900 -0.182900 0.464000 0.712000 0.512000 +0.933400 -0.451900 -0.182900 0.464000 0.712000 0.512000 +0.783200 -0.502100 -0.182900 -0.448000 -0.720000 0.512000 +0.783200 -0.502100 -0.182900 -0.448000 -0.720000 0.512000 +0.800000 -0.502100 -0.171200 -0.360000 -0.648000 0.664000 +0.800000 -0.511100 -0.182900 -0.376000 -0.744000 0.544000 +0.800000 -0.511100 -0.182900 -0.376000 -0.744000 0.544000 +0.800000 -0.333100 -0.182900 0.680000 0.680000 0.256000 +0.800000 -0.333100 -0.182900 0.680000 0.680000 0.256000 +0.821300 -0.351500 -0.182900 0.624000 0.648000 0.416000 +0.800000 -0.351500 -0.149400 0.664000 0.512000 0.528000 +0.800000 -0.351500 -0.149400 0.664000 0.512000 0.528000 +0.900000 -0.552300 -0.159100 -0.496000 -0.592000 0.632000 +0.900000 -0.552300 -0.159100 -0.496000 -0.592000 0.632000 +0.900000 -0.573700 -0.182900 -0.608000 -0.704000 0.344000 +0.876500 -0.552300 -0.182900 -0.528000 -0.672000 0.504000 +0.900000 -0.578300 -0.243900 -0.552000 -0.704000 -0.440000 +0.868400 -0.552300 -0.243900 -0.552000 -0.760000 -0.328000 +0.900000 -0.552300 -0.278500 -0.424000 -0.592000 -0.672000 +0.900000 -0.552300 -0.278500 -0.424000 -0.592000 -0.672000 +0.900000 0.127900 -0.121900 0.560000 0.776000 -0.264000 +0.900000 0.127900 -0.121900 0.560000 0.776000 -0.264000 +0.931600 0.100400 -0.121900 0.600000 0.744000 -0.272000 +0.900000 0.111100 -0.182900 0.552000 0.712000 -0.416000 +0.912000 0.100400 -0.182900 0.600000 0.704000 -0.360000 +0.900000 0.100400 -0.203200 0.536000 0.688000 -0.472000 +0.900000 0.100400 -0.203200 0.536000 0.688000 -0.472000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +0.950000 -0.619400 -0.182900 -0.632000 -0.592000 0.480000 +0.935000 -0.602500 -0.182900 -0.552000 -0.552000 0.608000 +0.950000 -0.619400 -0.243900 -0.600000 -0.584000 -0.536000 +0.933200 -0.602500 -0.243900 -0.584000 -0.624000 -0.512000 +0.950000 -0.602500 -0.260200 -0.544000 -0.504000 -0.664000 +0.950000 -0.602500 -0.260200 -0.544000 -0.504000 -0.664000 +1.000000 -0.251000 -0.154300 -0.728000 -0.648000 0.200000 +1.000000 -0.251000 -0.154300 -0.728000 -0.648000 0.200000 +1.000000 -0.258900 -0.182900 -0.752000 -0.616000 0.208000 +0.993400 -0.251000 -0.182900 -0.736000 -0.640000 0.200000 +1.000000 -0.277900 -0.243900 -0.712000 -0.592000 0.360000 +0.978600 -0.251000 -0.243900 -0.696000 -0.616000 0.352000 +0.978600 -0.251000 -0.243900 -0.696000 -0.616000 0.352000 +0.950000 -0.560000 -0.121900 -0.400000 -0.536000 0.728000 +0.950000 -0.560000 -0.121900 -0.400000 -0.536000 0.728000 +0.992300 -0.602500 -0.121900 -0.520000 -0.480000 0.696000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +0.950000 -0.602500 -0.169200 -0.536000 -0.520000 0.656000 +1.000000 -0.652700 -0.168000 -0.488000 -0.568000 0.656000 +1.000000 -0.652700 -0.168000 -0.488000 -0.568000 0.656000 +1.000000 -0.666200 -0.182900 -0.536000 -0.632000 0.544000 +0.983200 -0.652700 -0.182900 -0.528000 -0.608000 0.584000 +1.000000 -0.673300 -0.243900 -0.656000 -0.656000 -0.368000 +0.979500 -0.652700 -0.243900 -0.672000 -0.664000 -0.304000 +1.000000 -0.652700 -0.268800 -0.592000 -0.512000 -0.608000 +1.000000 -0.652700 -0.268800 -0.592000 -0.512000 -0.608000 +-1.000000 0.256900 -0.182900 0.288000 0.752000 -0.584000 +-1.000000 0.256900 -0.182900 0.288000 0.752000 -0.584000 +-1.000000 0.251000 -0.191500 0.280000 0.728000 -0.616000 +-0.985000 0.251000 -0.182900 0.288000 0.752000 -0.576000 +-0.985000 0.251000 -0.182900 0.288000 0.752000 -0.576000 +-0.980800 0.200800 -0.243900 0.232000 0.632000 -0.736000 +-0.980800 0.200800 -0.243900 0.232000 0.632000 -0.736000 +-0.950000 0.189400 -0.243900 0.264000 0.616000 -0.728000 +-0.950000 0.200800 -0.231900 0.272000 0.640000 -0.704000 +-0.950000 0.200800 -0.231900 0.272000 0.640000 -0.704000 +-0.900000 0.214200 -0.182900 0.360000 0.720000 -0.576000 +-0.900000 0.214200 -0.182900 0.360000 0.720000 -0.576000 +-0.900000 0.200800 -0.201400 0.352000 0.680000 -0.640000 +-0.874200 0.200800 -0.182900 0.360000 0.712000 -0.584000 +-0.874200 0.200800 -0.182900 0.360000 0.712000 -0.584000 +-0.878700 0.150600 -0.243900 0.328000 0.616000 -0.704000 +-0.878700 0.150600 -0.243900 0.328000 0.616000 -0.704000 +-0.850000 0.135500 -0.243900 0.320000 0.608000 -0.712000 +-0.850000 0.150600 -0.229000 0.320000 0.608000 -0.720000 +-0.850000 0.150600 -0.229000 0.320000 0.608000 -0.720000 +-0.900000 -0.542100 -0.182900 -0.808000 -0.560000 0.136000 +-0.900000 -0.542100 -0.182900 -0.808000 -0.560000 0.136000 +-0.900000 -0.551700 -0.243900 -0.808000 -0.568000 -0.120000 +-0.892400 -0.552300 -0.182900 -0.760000 -0.624000 0.176000 +-0.899500 -0.552300 -0.243900 -0.800000 -0.592000 -0.072000 +-0.850000 -0.592600 -0.182900 -0.520000 -0.800000 0.264000 +-0.851300 -0.602500 -0.243900 -0.680000 -0.720000 -0.008000 +-0.850000 -0.602500 -0.238600 -0.616000 -0.752000 0.216000 +-0.850000 -0.603800 -0.243900 -0.656000 -0.744000 0.064000 +-0.832500 -0.602500 -0.182900 -0.576000 -0.768000 0.272000 +-0.800000 -0.632800 -0.243900 -0.432000 -0.896000 0.072000 +-0.800000 -0.620600 -0.182900 -0.312000 -0.880000 0.336000 +-0.750000 -0.646000 -0.243900 -0.088000 -0.984000 0.144000 +-0.750000 -0.630100 -0.182900 -0.144000 -0.912000 0.360000 +-0.750000 -0.630100 -0.182900 -0.144000 -0.912000 0.360000 +-0.820300 -0.502100 -0.182900 0.496000 0.792000 0.344000 +-0.820300 -0.502100 -0.182900 0.496000 0.792000 0.344000 +-0.800000 -0.502100 -0.227500 0.432000 0.824000 0.352000 +-0.800000 -0.513200 -0.182900 -0.080000 0.880000 0.456000 +-0.750000 -0.502100 -0.184800 -0.496000 0.696000 0.496000 +-0.750000 -0.503000 -0.182900 -0.200000 0.848000 0.472000 +-0.749300 -0.502100 -0.182900 -0.920000 -0.232000 0.288000 +-0.750000 -0.502100 -0.184800 -0.496000 0.696000 0.496000 +-0.750000 -0.499500 -0.182900 -0.936000 -0.200000 0.264000 +-0.750000 -0.499500 -0.182900 -0.936000 -0.200000 0.264000 +-0.850000 -0.592600 -0.182900 -0.520000 -0.800000 0.264000 +-0.850000 -0.592600 -0.182900 -0.520000 -0.800000 0.264000 +-0.832500 -0.602500 -0.182900 -0.576000 -0.768000 0.272000 +-0.850000 -0.602500 -0.238600 -0.616000 -0.752000 0.216000 +-0.850000 -0.602500 -0.238600 -0.616000 -0.752000 0.216000 +-0.650000 0.045800 -0.182900 0.672000 0.432000 -0.592000 +-0.650000 0.045800 -0.182900 0.672000 0.432000 -0.592000 +-0.650000 0.000000 -0.224600 0.632000 0.368000 -0.672000 +-0.621400 0.000000 -0.182900 0.848000 0.280000 -0.440000 +-0.621400 0.000000 -0.182900 0.848000 0.280000 -0.440000 +-0.600000 -0.629300 -0.182900 0.072000 -0.968000 0.224000 +-0.600000 -0.629300 -0.182900 0.072000 -0.968000 0.224000 +-0.600000 -0.640700 -0.243900 0.080000 -0.976000 0.192000 +-0.550000 -0.618800 -0.182900 0.168000 -0.944000 0.272000 +-0.550000 -0.629900 -0.243900 0.160000 -0.960000 0.200000 +-0.500000 -0.610400 -0.182900 -0.136000 -0.936000 0.304000 +-0.500000 -0.625200 -0.243900 -0.096000 -0.960000 0.240000 +-0.550000 -0.629900 -0.243900 0.160000 -0.960000 0.200000 +-0.500000 -0.637800 -0.304800 -0.208000 -0.976000 -0.032000 +-0.550000 -0.639800 -0.304800 0.152000 -0.984000 0.000000 +-0.500000 -0.633000 -0.365800 -0.088000 -0.968000 -0.200000 +-0.550000 -0.637200 -0.365800 0.152000 -0.968000 -0.168000 +-0.550000 -0.639800 -0.304800 0.152000 -0.984000 0.000000 +-0.600000 -0.645500 -0.365800 0.016000 -0.968000 -0.216000 +-0.600000 -0.650800 -0.304800 0.064000 -0.992000 0.000000 +-0.550000 -0.639800 -0.304800 0.152000 -0.984000 0.000000 +-0.600000 -0.640700 -0.243900 0.080000 -0.976000 0.192000 +-0.550000 -0.629900 -0.243900 0.160000 -0.960000 0.200000 +-0.550000 -0.629900 -0.243900 0.160000 -0.960000 0.200000 +-0.403600 -0.100400 -0.182900 -0.616000 0.592000 -0.512000 +-0.403600 -0.100400 -0.182900 -0.616000 0.592000 -0.512000 +-0.400000 -0.100400 -0.188300 -0.616000 0.576000 -0.520000 +-0.400000 -0.096400 -0.182900 -0.664000 0.552000 -0.496000 +-0.354400 -0.100400 -0.243900 -0.584000 0.448000 -0.664000 +-0.365500 -0.050200 -0.182900 -0.728000 0.384000 -0.560000 +-0.350000 -0.093900 -0.243900 -0.600000 0.408000 -0.680000 +-0.350000 -0.050200 -0.209400 -0.696000 0.392000 -0.584000 +-0.321700 -0.050200 -0.243900 -0.656000 0.344000 -0.656000 +-0.350000 -0.016600 -0.182900 -0.688000 0.360000 -0.616000 +-0.301700 0.000000 -0.243900 -0.744000 0.392000 -0.536000 +-0.340600 0.000000 -0.182900 -0.696000 0.480000 -0.520000 +-0.340600 0.000000 -0.182900 -0.696000 0.480000 -0.520000 +-0.444500 -0.150600 -0.243900 -0.312000 0.784000 -0.528000 +-0.444500 -0.150600 -0.243900 -0.312000 0.784000 -0.528000 +-0.450000 -0.150600 -0.239400 -0.408000 0.792000 -0.448000 +-0.450000 -0.152500 -0.243900 -0.384000 0.800000 -0.448000 +-0.450000 -0.152500 -0.243900 -0.384000 0.800000 -0.448000 +-0.400000 -0.651500 -0.182900 -0.552000 -0.472000 0.672000 +-0.400000 -0.651500 -0.182900 -0.552000 -0.472000 0.672000 +-0.400000 -0.652700 -0.184800 -0.640000 -0.536000 0.536000 +-0.450000 -0.629600 -0.182900 -0.344000 -0.872000 0.320000 +-0.428400 -0.652700 -0.243900 -0.584000 -0.736000 0.336000 +-0.450000 -0.644000 -0.243900 -0.352000 -0.912000 0.200000 +-0.450000 -0.652700 -0.293400 -0.288000 -0.936000 0.160000 +-0.428400 -0.652700 -0.243900 -0.584000 -0.736000 0.336000 +-0.450000 -0.654300 -0.304800 -0.272000 -0.952000 0.040000 +-0.400000 -0.663600 -0.243900 -0.504000 -0.840000 0.160000 +-0.400000 -0.672200 -0.304800 -0.400000 -0.904000 -0.128000 +-0.363900 -0.703000 -0.243900 -0.784000 -0.584000 0.176000 +-0.371300 -0.703000 -0.304800 -0.816000 -0.552000 -0.144000 +-0.350000 -0.730400 -0.243900 -0.544000 -0.776000 0.296000 +-0.350000 -0.747900 -0.304800 -0.512000 -0.832000 -0.184000 +-0.300000 -0.736500 -0.243900 0.320000 -0.832000 0.440000 +-0.330700 -0.753200 -0.304800 -0.192000 -0.968000 -0.112000 +-0.300000 -0.753200 -0.286100 0.088000 -0.928000 0.352000 +-0.300000 -0.758500 -0.304800 0.104000 -0.976000 -0.144000 +-0.281500 -0.753200 -0.304800 0.312000 -0.920000 -0.216000 +-0.300000 -0.753200 -0.317300 0.136000 -0.840000 -0.512000 +-0.300000 -0.758500 -0.304800 0.104000 -0.976000 -0.144000 +-0.330700 -0.753200 -0.304800 -0.192000 -0.968000 -0.112000 +-0.300000 -0.753200 -0.317300 0.136000 -0.840000 -0.512000 +-0.350000 -0.747900 -0.304800 -0.512000 -0.832000 -0.184000 +-0.300000 -0.703000 -0.365100 0.056000 -0.232000 -0.968000 +-0.350000 -0.703000 -0.357000 -0.336000 -0.496000 -0.792000 +-0.300000 -0.687100 -0.365800 0.104000 -0.048000 -0.992000 +-0.350000 -0.679200 -0.365800 -0.072000 -0.176000 -0.976000 +-0.350000 -0.703000 -0.357000 -0.336000 -0.496000 -0.792000 +-0.400000 -0.653700 -0.365800 -0.176000 -0.888000 -0.416000 +-0.371300 -0.703000 -0.304800 -0.816000 -0.552000 -0.144000 +-0.400000 -0.672200 -0.304800 -0.400000 -0.904000 -0.128000 +-0.400000 -0.672200 -0.304800 -0.400000 -0.904000 -0.128000 +-0.428400 -0.652700 -0.243900 -0.584000 -0.736000 0.336000 +-0.428400 -0.652700 -0.243900 -0.584000 -0.736000 0.336000 +-0.400000 -0.652700 -0.184800 -0.640000 -0.536000 0.536000 +-0.400000 -0.663600 -0.243900 -0.504000 -0.840000 0.160000 +-0.396000 -0.652700 -0.182900 -0.176000 0.000000 0.984000 +-0.363900 -0.703000 -0.243900 -0.784000 -0.584000 0.176000 +-0.350700 -0.703000 -0.182900 -0.792000 -0.176000 0.576000 +-0.350000 -0.730400 -0.243900 -0.544000 -0.776000 0.296000 +-0.350000 -0.704300 -0.182900 -0.112000 -0.808000 0.576000 +-0.300000 -0.736500 -0.243900 0.320000 -0.832000 0.440000 +-0.300000 -0.708000 -0.182900 0.360000 -0.768000 0.520000 +-0.300000 -0.708000 -0.182900 0.360000 -0.768000 0.520000 +-0.365500 -0.050200 -0.182900 -0.728000 0.384000 -0.560000 +-0.365500 -0.050200 -0.182900 -0.728000 0.384000 -0.560000 +-0.350000 -0.050200 -0.209400 -0.696000 0.392000 -0.584000 +-0.350000 -0.016600 -0.182900 -0.688000 0.360000 -0.616000 +-0.350000 -0.016600 -0.182900 -0.688000 0.360000 -0.616000 +-0.400000 -0.100400 -0.188300 -0.616000 0.576000 -0.520000 +-0.400000 -0.100400 -0.188300 -0.616000 0.576000 -0.520000 +-0.400000 -0.131400 -0.243900 -0.384000 0.744000 -0.536000 +-0.354400 -0.100400 -0.243900 -0.584000 0.448000 -0.664000 +-0.400000 -0.150600 -0.272200 -0.312000 0.624000 -0.704000 +-0.350000 -0.100400 -0.248500 -0.576000 0.440000 -0.680000 +-0.350000 -0.150600 -0.298700 -0.264000 0.464000 -0.840000 +-0.400000 -0.150600 -0.272200 -0.312000 0.624000 -0.704000 +-0.350000 -0.159400 -0.304800 -0.248000 0.528000 -0.808000 +-0.400000 -0.174400 -0.304800 -0.224000 0.736000 -0.632000 +-0.350000 -0.200800 -0.339000 0.200000 0.416000 -0.880000 +-0.400000 -0.200800 -0.333600 -0.064000 0.568000 -0.816000 +-0.350000 -0.248400 -0.365800 0.184000 0.424000 -0.880000 +-0.400000 -0.239300 -0.365800 0.048000 0.512000 -0.848000 +-0.350000 -0.251000 -0.367200 0.240000 0.168000 -0.952000 +-0.400000 -0.251000 -0.373300 0.080000 0.400000 -0.904000 +-0.350000 -0.301200 -0.377400 0.232000 0.208000 -0.944000 +-0.400000 -0.301200 -0.390900 0.144000 0.296000 -0.936000 +-0.350000 -0.351500 -0.416300 -0.176000 0.600000 -0.768000 +-0.400000 -0.351500 -0.411400 0.000000 0.616000 -0.784000 +-0.400000 -0.351500 -0.411400 0.000000 0.616000 -0.784000 +-0.350000 -0.647900 -0.182900 0.008000 0.768000 0.624000 +-0.350000 -0.647900 -0.182900 0.008000 0.768000 0.624000 +-0.386500 -0.602500 -0.182900 0.376000 -0.032000 0.920000 +-0.350000 -0.630200 -0.243900 -0.144000 0.776000 0.600000 +-0.371400 -0.602500 -0.243900 0.928000 0.016000 0.352000 +-0.371400 -0.602500 -0.243900 0.928000 0.016000 0.352000 +-0.200000 0.172600 -0.182900 -0.488000 0.416000 -0.760000 +-0.200000 0.172600 -0.182900 -0.488000 0.416000 -0.760000 +-0.216700 0.150600 -0.182900 -0.560000 0.376000 -0.728000 +-0.200000 0.150600 -0.197300 -0.488000 0.464000 -0.728000 +-0.249100 0.100400 -0.182900 -0.576000 0.496000 -0.640000 +-0.200000 0.100400 -0.242800 -0.520000 0.512000 -0.672000 +-0.200000 0.100400 -0.242800 -0.520000 0.512000 -0.672000 +-0.200000 0.172600 -0.182900 -0.488000 0.416000 -0.760000 +-0.200000 0.172600 -0.182900 -0.488000 0.416000 -0.760000 +-0.200000 0.150600 -0.197300 -0.488000 0.464000 -0.728000 +-0.173800 0.200800 -0.182900 -0.480000 0.344000 -0.800000 +-0.150000 0.150600 -0.235500 -0.296000 0.536000 -0.784000 +-0.150000 0.200800 -0.199200 -0.328000 0.272000 -0.896000 +-0.150000 0.200800 -0.199200 -0.328000 0.272000 -0.896000 +0.100000 0.004900 -0.182900 -0.288000 0.864000 0.400000 +0.100000 0.004900 -0.182900 -0.288000 0.864000 0.400000 +0.050000 0.005700 -0.182900 0.312000 0.584000 0.744000 +0.100000 0.000000 -0.203800 -0.256000 0.936000 -0.224000 +0.050000 0.042300 -0.243900 0.688000 0.376000 -0.616000 +0.078000 0.000000 -0.243900 0.336000 0.616000 -0.696000 +0.050000 0.000000 -0.258500 0.448000 0.256000 -0.848000 +0.100000 -0.005500 -0.243900 -0.184000 0.760000 -0.616000 +0.050000 -0.050200 -0.279200 0.280000 0.320000 -0.896000 +0.100000 -0.050200 -0.272200 -0.136000 0.384000 -0.904000 +0.050000 -0.100400 -0.298100 0.360000 0.248000 -0.896000 +0.100000 -0.100400 -0.298900 0.040000 0.136000 -0.984000 +0.100000 -0.100400 -0.298900 0.040000 0.136000 -0.984000 +0.078000 0.000000 -0.243900 0.336000 0.616000 -0.696000 +0.078000 0.000000 -0.243900 0.336000 0.616000 -0.696000 +0.100000 -0.005500 -0.243900 -0.184000 0.760000 -0.616000 +0.100000 0.000000 -0.203800 -0.256000 0.936000 -0.224000 +0.100000 0.000000 -0.203800 -0.256000 0.936000 -0.224000 +0.200000 -0.301200 -0.206400 -0.600000 -0.688000 0.384000 +0.200000 -0.301200 -0.206400 -0.600000 -0.688000 0.384000 +0.200000 -0.319700 -0.243900 -0.624000 -0.696000 0.328000 +0.176900 -0.301200 -0.243900 -0.504000 -0.800000 0.304000 +0.200000 -0.340400 -0.304800 -0.480000 -0.448000 -0.744000 +0.170700 -0.301200 -0.304800 -0.520000 -0.608000 -0.592000 +0.200000 -0.301200 -0.321600 -0.488000 -0.368000 -0.784000 +0.200000 -0.301200 -0.321600 -0.488000 -0.368000 -0.784000 +0.300000 -0.330300 -0.182900 -0.312000 -0.696000 0.632000 +0.300000 -0.330300 -0.182900 -0.312000 -0.696000 0.632000 +0.300000 -0.351500 -0.225700 -0.416000 -0.800000 0.416000 +0.250000 -0.319600 -0.182900 -0.280000 -0.832000 0.472000 +0.277600 -0.351500 -0.243900 -0.264000 -0.888000 0.352000 +0.250000 -0.343100 -0.243900 -0.320000 -0.920000 0.208000 +0.271900 -0.351500 -0.304800 -0.112000 -0.784000 -0.608000 +0.250000 -0.348300 -0.304800 -0.128000 -0.736000 -0.656000 +0.300000 -0.351500 -0.310200 -0.192000 -0.728000 -0.648000 +0.250000 -0.313600 -0.365800 -0.336000 -0.640000 -0.680000 +0.300000 -0.308000 -0.365800 0.080000 -0.656000 -0.744000 +0.250000 -0.301200 -0.379400 -0.536000 -0.264000 -0.792000 +0.300000 -0.301200 -0.372900 0.128000 -0.472000 -0.864000 +0.300000 -0.308000 -0.365800 0.080000 -0.656000 -0.744000 +0.333500 -0.301200 -0.365800 0.208000 -0.080000 -0.968000 +0.300000 -0.351500 -0.310200 -0.192000 -0.728000 -0.648000 +0.350000 -0.301200 -0.360500 0.376000 0.184000 -0.904000 +0.348000 -0.351500 -0.365800 -0.720000 -0.032000 -0.680000 +0.350000 -0.334300 -0.365800 -0.304000 0.096000 -0.944000 +0.350000 -0.351500 -0.368100 -0.440000 0.096000 -0.888000 +0.355700 -0.351500 -0.365800 0.360000 -0.072000 -0.928000 +0.350000 -0.354600 -0.365800 -0.264000 -0.632000 -0.720000 +0.400000 -0.351500 -0.338800 0.360000 -0.568000 -0.728000 +0.350000 -0.401700 -0.317400 -0.608000 -0.560000 -0.544000 +0.400000 -0.388800 -0.304800 0.392000 -0.800000 -0.448000 +0.376800 -0.401700 -0.304800 0.336000 -0.848000 -0.392000 +0.400000 -0.401700 -0.257800 0.112000 -0.952000 -0.280000 +0.350000 -0.410700 -0.304800 -0.592000 -0.664000 -0.440000 +0.400000 -0.404800 -0.243900 0.016000 -0.968000 0.240000 +0.350000 -0.409600 -0.243900 -0.632000 -0.696000 0.320000 +0.400000 -0.401700 -0.239700 -0.184000 -0.720000 0.656000 +0.350000 -0.401700 -0.229000 -0.616000 -0.656000 0.416000 +0.400000 -0.370500 -0.182900 -0.008000 -0.616000 0.776000 +0.350000 -0.366900 -0.182900 -0.368000 -0.552000 0.736000 +0.350000 -0.401700 -0.229000 -0.616000 -0.656000 0.416000 +0.331500 -0.351500 -0.182900 -0.432000 -0.576000 0.688000 +0.343800 -0.401700 -0.243900 -0.728000 -0.584000 0.344000 +0.300000 -0.351500 -0.225700 -0.416000 -0.800000 0.416000 +0.300000 -0.357600 -0.243900 -0.288000 -0.920000 0.248000 +0.277600 -0.351500 -0.243900 -0.264000 -0.888000 0.352000 +0.300000 -0.355300 -0.304800 -0.272000 -0.752000 -0.592000 +0.271900 -0.351500 -0.304800 -0.112000 -0.784000 -0.608000 +0.300000 -0.351500 -0.310200 -0.192000 -0.728000 -0.648000 +0.300000 -0.355300 -0.304800 -0.272000 -0.752000 -0.592000 +0.348000 -0.351500 -0.365800 -0.720000 -0.032000 -0.680000 +0.344100 -0.401700 -0.304800 -0.784000 -0.512000 -0.336000 +0.350000 -0.354600 -0.365800 -0.264000 -0.632000 -0.720000 +0.350000 -0.401700 -0.317400 -0.608000 -0.560000 -0.544000 +0.344100 -0.401700 -0.304800 -0.784000 -0.512000 -0.336000 +0.350000 -0.410700 -0.304800 -0.592000 -0.664000 -0.440000 +0.343800 -0.401700 -0.243900 -0.728000 -0.584000 0.344000 +0.350000 -0.409600 -0.243900 -0.632000 -0.696000 0.320000 +0.350000 -0.401700 -0.229000 -0.616000 -0.656000 0.416000 +0.350000 -0.401700 -0.229000 -0.616000 -0.656000 0.416000 +0.300000 -0.330300 -0.182900 -0.312000 -0.696000 0.632000 +0.300000 -0.330300 -0.182900 -0.312000 -0.696000 0.632000 +0.331500 -0.351500 -0.182900 -0.432000 -0.576000 0.688000 +0.300000 -0.351500 -0.225700 -0.416000 -0.800000 0.416000 +0.300000 -0.351500 -0.225700 -0.416000 -0.800000 0.416000 +0.427100 -0.301200 -0.182900 0.776000 0.464000 0.416000 +0.427100 -0.301200 -0.182900 0.776000 0.464000 0.416000 +0.450000 -0.338000 -0.182900 0.248000 0.592000 0.752000 +0.429200 -0.301200 -0.243900 0.816000 0.544000 -0.176000 +0.450000 -0.327300 -0.243900 -0.064000 0.864000 -0.488000 +0.401200 -0.301200 -0.304800 0.744000 0.488000 -0.440000 +0.450000 -0.351500 -0.290700 -0.176000 0.632000 -0.744000 +0.437100 -0.351500 -0.304800 0.688000 0.472000 -0.536000 +0.437100 -0.351500 -0.304800 0.688000 0.472000 -0.536000 +0.450000 -0.370700 -0.182900 -0.080000 -0.520000 0.848000 +0.450000 -0.370700 -0.182900 -0.080000 -0.520000 0.848000 +0.400000 -0.370500 -0.182900 -0.008000 -0.616000 0.776000 +0.450000 -0.401700 -0.212100 0.240000 -0.816000 0.520000 +0.400000 -0.401700 -0.239700 -0.184000 -0.720000 0.656000 +0.450000 -0.418500 -0.243900 -0.152000 -0.896000 0.400000 +0.400000 -0.404800 -0.243900 0.016000 -0.968000 0.240000 +0.450000 -0.411100 -0.304800 -0.144000 -0.808000 -0.560000 +0.400000 -0.401700 -0.257800 0.112000 -0.952000 -0.280000 +0.428900 -0.401700 -0.304800 -0.392000 -0.464000 -0.784000 +0.428900 -0.401700 -0.304800 -0.392000 -0.464000 -0.784000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.500000 0.355500 -0.182900 0.400000 0.616000 -0.664000 +0.500000 0.351500 -0.187300 0.416000 0.568000 -0.696000 +0.506000 0.351500 -0.182900 0.424000 0.584000 -0.680000 +0.506000 0.351500 -0.182900 0.424000 0.584000 -0.680000 +0.550000 -0.401700 -0.218900 -0.128000 -0.904000 0.392000 +0.550000 -0.401700 -0.218900 -0.128000 -0.904000 0.392000 +0.550000 -0.409700 -0.243900 -0.144000 -0.944000 0.272000 +0.503900 -0.401700 -0.243900 -0.232000 -0.936000 0.256000 +0.550000 -0.415900 -0.304800 -0.192000 -0.848000 -0.480000 +0.502600 -0.401700 -0.304800 -0.320000 -0.840000 -0.416000 +0.550000 -0.401700 -0.333700 -0.144000 -0.688000 -0.704000 +0.550000 -0.401700 -0.333700 -0.144000 -0.688000 -0.704000 +0.600000 0.200800 -0.209200 0.248000 0.288000 -0.920000 +0.600000 0.200800 -0.209200 0.248000 0.288000 -0.920000 +0.650000 0.200800 -0.204000 0.272000 0.408000 -0.864000 +0.600000 0.150600 -0.225200 0.008000 0.128000 -0.984000 +0.650000 0.150600 -0.219600 0.200000 0.280000 -0.928000 +0.600000 0.100400 -0.237100 -0.096000 0.168000 -0.976000 +0.650000 0.100400 -0.241400 0.232000 0.064000 -0.968000 +0.600000 0.076600 -0.243900 -0.096000 0.360000 -0.920000 +0.650000 0.067400 -0.243900 0.208000 0.056000 -0.968000 +0.600000 0.050200 -0.251100 0.248000 0.344000 -0.896000 +0.650000 0.050200 -0.244900 0.216000 0.040000 -0.968000 +0.600000 0.000000 -0.284600 0.512000 0.112000 -0.840000 +0.650000 0.000000 -0.248500 0.680000 -0.160000 -0.712000 +0.650000 0.000000 -0.248500 0.680000 -0.160000 -0.712000 +0.600000 -0.392700 -0.182900 -0.184000 -0.752000 0.624000 +0.600000 -0.392700 -0.182900 -0.184000 -0.752000 0.624000 +0.628900 -0.401700 -0.182900 -0.216000 -0.760000 0.608000 +0.600000 -0.401700 -0.203000 -0.208000 -0.872000 0.432000 +0.600000 -0.401700 -0.203000 -0.208000 -0.872000 0.432000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.700000 -0.472400 -0.243900 -0.560000 -0.816000 -0.016000 +0.673600 -0.451900 -0.243900 -0.480000 -0.752000 0.448000 +0.700000 -0.481300 -0.304800 -0.240000 -0.712000 -0.656000 +0.653100 -0.451900 -0.304800 -0.336000 -0.480000 -0.800000 +0.700000 -0.451900 -0.321600 -0.136000 -0.312000 -0.936000 +0.700000 -0.451900 -0.321600 -0.136000 -0.312000 -0.936000 +0.700000 -0.435200 -0.182900 -0.448000 -0.712000 0.536000 +0.700000 -0.435200 -0.182900 -0.448000 -0.712000 0.536000 +0.719600 -0.451900 -0.182900 -0.568000 -0.640000 0.512000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.700000 -0.451900 -0.215800 -0.528000 -0.696000 0.472000 +0.750000 -0.502100 -0.236900 -0.448000 -0.776000 0.432000 +0.750000 -0.502100 -0.236900 -0.448000 -0.776000 0.432000 +0.750000 -0.505200 -0.243900 -0.480000 -0.856000 0.152000 +0.744200 -0.502100 -0.243900 -0.480000 -0.864000 0.128000 +0.750000 -0.502100 -0.254300 -0.448000 -0.832000 -0.312000 +0.750000 -0.502100 -0.254300 -0.448000 -0.832000 -0.312000 +0.750000 0.157000 -0.182900 0.280000 0.720000 -0.624000 +0.750000 0.157000 -0.182900 0.280000 0.720000 -0.624000 +0.750000 0.150600 -0.191500 0.256000 0.656000 -0.704000 +0.769100 0.150600 -0.182900 0.248000 0.704000 -0.648000 +0.769100 0.150600 -0.182900 0.248000 0.704000 -0.648000 +0.929600 0.050200 -0.243900 0.432000 0.672000 -0.584000 +0.929600 0.050200 -0.243900 0.432000 0.672000 -0.584000 +0.950000 0.037500 -0.243900 0.432000 0.688000 -0.576000 +0.950000 0.050200 -0.224500 0.472000 0.712000 -0.504000 +0.950000 0.050200 -0.224500 0.472000 0.712000 -0.504000 +0.950000 0.069900 -0.182900 0.544000 0.736000 -0.392000 +0.950000 0.069900 -0.182900 0.544000 0.736000 -0.392000 +0.950000 0.050200 -0.224500 0.472000 0.712000 -0.504000 +0.978000 0.050200 -0.182900 0.512000 0.768000 -0.376000 +0.978000 0.050200 -0.182900 0.512000 0.768000 -0.376000 +0.950000 -0.451900 -0.206400 0.504000 0.736000 0.440000 +0.950000 -0.451900 -0.206400 0.504000 0.736000 0.440000 +0.950000 -0.433400 -0.243900 0.528000 0.832000 0.152000 +0.980700 -0.451900 -0.243900 0.752000 0.648000 0.032000 +0.950000 -0.451900 -0.300000 0.488000 0.464000 -0.728000 +0.950000 -0.433400 -0.243900 0.528000 0.832000 0.152000 +0.900000 -0.451900 -0.272400 0.368000 0.408000 -0.824000 +0.900000 -0.412700 -0.243900 0.520000 0.640000 -0.552000 +0.850000 -0.451900 -0.293100 0.448000 0.248000 -0.848000 +0.890600 -0.401700 -0.243900 0.576000 0.616000 -0.528000 +0.850000 -0.401700 -0.268600 0.504000 0.432000 -0.744000 +0.850000 -0.375700 -0.243900 0.544000 0.616000 -0.552000 +0.800000 -0.401700 -0.291400 0.440000 0.456000 -0.760000 +0.829500 -0.351500 -0.243900 0.648000 0.640000 -0.400000 +0.800000 -0.351500 -0.277300 0.568000 0.408000 -0.704000 +0.800000 -0.328800 -0.243900 0.640000 0.656000 -0.384000 +0.800000 -0.328800 -0.243900 0.640000 0.656000 -0.384000 +1.000000 -0.503200 -0.182900 0.400000 0.704000 0.576000 +1.000000 -0.503200 -0.182900 0.400000 0.704000 0.576000 +0.998000 -0.502100 -0.182900 0.528000 0.664000 0.520000 +1.000000 -0.502100 -0.189300 0.760000 0.568000 0.296000 +1.000000 -0.502100 -0.189300 0.760000 0.568000 0.296000 +-0.891000 -0.451900 -0.304800 0.528000 0.824000 -0.192000 +-0.891000 -0.451900 -0.304800 0.528000 0.824000 -0.192000 +-0.896800 -0.451900 -0.243900 0.600000 0.776000 0.136000 +-0.850000 -0.473200 -0.304800 0.272000 0.896000 -0.336000 +-0.850000 -0.480800 -0.243900 0.376000 0.912000 0.152000 +-0.800000 -0.473000 -0.304800 -0.736000 0.648000 -0.168000 +-0.800000 -0.496000 -0.243900 0.424000 0.840000 0.320000 +-0.787800 -0.451900 -0.304800 -0.984000 0.136000 -0.040000 +-0.769800 -0.451900 -0.243900 -0.952000 -0.080000 0.272000 +-0.769800 -0.451900 -0.243900 -0.952000 -0.080000 0.272000 +-0.900000 -0.551700 -0.243900 -0.808000 -0.568000 -0.120000 +-0.900000 -0.551700 -0.243900 -0.808000 -0.568000 -0.120000 +-0.900000 -0.539600 -0.304800 -0.720000 -0.488000 -0.480000 +-0.899500 -0.552300 -0.243900 -0.800000 -0.592000 -0.072000 +-0.891900 -0.552300 -0.304800 -0.800000 -0.568000 -0.136000 +-0.851300 -0.602500 -0.243900 -0.680000 -0.720000 -0.008000 +-0.850000 -0.602000 -0.304800 -0.640000 -0.736000 -0.184000 +-0.850000 -0.602500 -0.285600 -0.672000 -0.728000 -0.024000 +-0.849200 -0.602500 -0.304800 -0.536000 -0.720000 -0.432000 +-0.850000 -0.603800 -0.243900 -0.656000 -0.744000 0.064000 +-0.800000 -0.636000 -0.304800 -0.536000 -0.792000 -0.272000 +-0.800000 -0.632800 -0.243900 -0.432000 -0.896000 0.072000 +-0.750000 -0.652200 -0.304800 -0.040000 -0.952000 -0.288000 +-0.750000 -0.646000 -0.243900 -0.088000 -0.984000 0.144000 +-0.750000 -0.646000 -0.243900 -0.088000 -0.984000 0.144000 +-0.850000 -0.603800 -0.243900 -0.656000 -0.744000 0.064000 +-0.850000 -0.603800 -0.243900 -0.656000 -0.744000 0.064000 +-0.850000 -0.602500 -0.285600 -0.672000 -0.728000 -0.024000 +-0.851300 -0.602500 -0.243900 -0.680000 -0.720000 -0.008000 +-0.851300 -0.602500 -0.243900 -0.680000 -0.720000 -0.008000 +-0.800000 0.108800 -0.243900 0.352000 0.608000 -0.704000 +-0.800000 0.108800 -0.243900 0.352000 0.608000 -0.704000 +-0.800000 0.100400 -0.252800 0.360000 0.584000 -0.720000 +-0.785800 0.100400 -0.243900 0.360000 0.584000 -0.720000 +-0.785800 0.100400 -0.243900 0.360000 0.584000 -0.720000 +-0.750000 0.077000 -0.243900 0.368000 0.552000 -0.744000 +-0.750000 0.077000 -0.243900 0.368000 0.552000 -0.744000 +-0.750000 0.050200 -0.267100 0.368000 0.432000 -0.816000 +-0.711800 0.050200 -0.243900 0.416000 0.432000 -0.792000 +-0.711800 0.050200 -0.243900 0.416000 0.432000 -0.792000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.700000 -0.175200 -0.304800 0.352000 0.528000 -0.768000 +-0.700000 -0.150600 -0.284500 0.376000 0.392000 -0.832000 +-0.700000 -0.150600 -0.284500 0.376000 0.392000 -0.832000 +-0.650000 -0.200800 -0.303800 0.136000 0.680000 -0.712000 +-0.650000 -0.200800 -0.303800 0.136000 0.680000 -0.712000 +-0.651700 -0.200800 -0.304800 0.320000 0.544000 -0.768000 +-0.650000 -0.201600 -0.304800 0.104000 0.688000 -0.704000 +-0.700000 -0.200800 -0.326900 0.208000 0.528000 -0.816000 +-0.650000 -0.251000 -0.354800 0.152000 0.632000 -0.752000 +-0.700000 -0.251000 -0.364900 0.104000 0.560000 -0.816000 +-0.650000 -0.261300 -0.365800 0.088000 0.568000 -0.808000 +-0.700000 -0.252100 -0.365800 0.096000 0.552000 -0.824000 +-0.700000 -0.251000 -0.364900 0.104000 0.560000 -0.816000 +-0.707800 -0.251000 -0.365800 0.064000 0.432000 -0.896000 +-0.700000 -0.200800 -0.326900 0.208000 0.528000 -0.816000 +-0.750000 -0.240500 -0.365800 0.056000 0.272000 -0.952000 +-0.750000 -0.200800 -0.348300 0.272000 0.384000 -0.872000 +-0.800000 -0.234100 -0.365800 -0.112000 0.264000 -0.952000 +-0.800000 -0.200800 -0.355700 0.080000 0.256000 -0.960000 +-0.800000 -0.200800 -0.355700 0.080000 0.256000 -0.960000 +-0.650000 -0.035200 -0.243900 0.544000 0.264000 -0.792000 +-0.650000 -0.035200 -0.243900 0.544000 0.264000 -0.792000 +-0.650000 -0.050200 -0.249300 0.496000 0.208000 -0.840000 +-0.642900 -0.050200 -0.243900 0.560000 0.208000 -0.792000 +-0.642900 -0.050200 -0.243900 0.560000 0.208000 -0.792000 +-0.544700 -0.200800 -0.304800 -0.080000 0.824000 -0.552000 +-0.544700 -0.200800 -0.304800 -0.080000 0.824000 -0.552000 +-0.550000 -0.200800 -0.303600 -0.040000 0.880000 -0.464000 +-0.550000 -0.201300 -0.304800 -0.032000 0.864000 -0.488000 +-0.550000 -0.201300 -0.304800 -0.032000 0.864000 -0.488000 +-0.354400 -0.100400 -0.243900 -0.584000 0.448000 -0.664000 +-0.354400 -0.100400 -0.243900 -0.584000 0.448000 -0.664000 +-0.350000 -0.100400 -0.248500 -0.576000 0.440000 -0.680000 +-0.350000 -0.093900 -0.243900 -0.600000 0.408000 -0.680000 +-0.350000 -0.093900 -0.243900 -0.600000 0.408000 -0.680000 +-0.363900 -0.552300 -0.243900 0.816000 -0.480000 0.304000 +-0.363900 -0.552300 -0.243900 0.816000 -0.480000 0.304000 +-0.350000 -0.535600 -0.243900 0.360000 -0.840000 0.384000 +-0.350000 -0.552300 -0.283400 -0.096000 -0.680000 0.720000 +-0.317500 -0.552300 -0.243900 -0.600000 -0.648000 0.448000 +-0.317500 -0.552300 -0.243900 -0.600000 -0.648000 0.448000 +-0.300000 -0.050200 -0.270300 -0.824000 0.232000 -0.512000 +-0.300000 -0.050200 -0.270300 -0.824000 0.232000 -0.512000 +-0.266700 -0.050200 -0.304800 -0.504000 0.288000 -0.808000 +-0.300000 -0.100400 -0.298100 -0.480000 0.288000 -0.824000 +-0.288100 -0.100400 -0.304800 -0.408000 0.240000 -0.872000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.256000 -0.703000 -0.243900 0.696000 -0.392000 0.584000 +-0.256000 -0.703000 -0.243900 0.696000 -0.392000 0.584000 +-0.250000 -0.679700 -0.243900 0.728000 -0.208000 0.640000 +-0.250000 -0.703000 -0.252700 0.704000 -0.368000 0.600000 +-0.250000 -0.703000 -0.252700 0.704000 -0.368000 0.600000 +-0.213400 0.000000 -0.304800 -0.304000 0.448000 -0.832000 +-0.213400 0.000000 -0.304800 -0.304000 0.448000 -0.832000 +-0.250000 0.000000 -0.286200 -0.320000 0.712000 -0.616000 +-0.250000 -0.028200 -0.304800 -0.400000 0.416000 -0.808000 +-0.250000 -0.028200 -0.304800 -0.400000 0.416000 -0.808000 +-0.196100 -0.200800 -0.304800 0.360000 -0.200000 -0.904000 +-0.196100 -0.200800 -0.304800 0.360000 -0.200000 -0.904000 +-0.150000 -0.200800 -0.284500 0.024000 -0.216000 -0.968000 +-0.150000 -0.159100 -0.304800 0.152000 -0.400000 -0.896000 +-0.108400 -0.200800 -0.304800 -0.496000 -0.048000 -0.856000 +-0.108400 -0.200800 -0.304800 -0.496000 -0.048000 -0.856000 +-0.172800 -0.552300 -0.243900 0.592000 -0.568000 0.560000 +-0.172800 -0.552300 -0.243900 0.592000 -0.568000 0.560000 +-0.150000 -0.530700 -0.243900 0.632000 -0.664000 0.392000 +-0.150000 -0.552300 -0.270100 0.544000 -0.504000 0.656000 +-0.150000 -0.552300 -0.270100 0.544000 -0.504000 0.656000 +-0.126800 0.150600 -0.243900 -0.208000 0.496000 -0.832000 +-0.126800 0.150600 -0.243900 -0.208000 0.496000 -0.832000 +-0.100000 0.150600 -0.251000 -0.024000 0.408000 -0.904000 +-0.100000 0.164100 -0.243900 -0.032000 0.432000 -0.896000 +-0.077600 0.150600 -0.243900 0.320000 0.328000 -0.880000 +-0.077600 0.150600 -0.243900 0.320000 0.328000 -0.880000 +-0.150000 0.100400 -0.267100 -0.312000 0.440000 -0.832000 +-0.150000 0.100400 -0.267100 -0.312000 0.440000 -0.832000 +-0.100000 0.100400 -0.276400 0.032000 0.376000 -0.920000 +-0.150000 0.050200 -0.299600 -0.080000 0.408000 -0.904000 +-0.100000 0.050200 -0.292200 0.304000 0.312000 -0.896000 +-0.150000 0.040500 -0.304800 -0.136000 0.416000 -0.896000 +-0.100000 0.022400 -0.304800 0.184000 0.304000 -0.928000 +-0.150000 0.000000 -0.322200 0.064000 0.240000 -0.968000 +-0.100000 0.000000 -0.309600 0.168000 0.152000 -0.968000 +-0.150000 -0.050200 -0.328000 0.128000 0.064000 -0.984000 +-0.100000 -0.050200 -0.318600 0.080000 0.144000 -0.984000 +-0.150000 -0.100400 -0.338700 0.056000 -0.088000 -0.992000 +-0.100000 -0.100400 -0.323700 -0.040000 -0.152000 -0.984000 +-0.150000 -0.150600 -0.309500 -0.032000 -0.400000 -0.912000 +-0.100000 -0.150600 -0.315000 -0.456000 -0.064000 -0.880000 +-0.100000 -0.150600 -0.315000 -0.456000 -0.064000 -0.880000 +-0.077600 0.000000 -0.304800 0.248000 0.344000 -0.896000 +-0.077600 0.000000 -0.304800 0.248000 0.344000 -0.896000 +-0.050000 -0.015100 -0.304800 0.280000 0.536000 -0.784000 +-0.050000 0.000000 -0.288000 0.256000 0.560000 -0.776000 +-0.050000 0.000000 -0.288000 0.256000 0.560000 -0.776000 +-0.013800 -0.351500 -0.243900 0.552000 -0.808000 -0.168000 +-0.013800 -0.351500 -0.243900 0.552000 -0.808000 -0.168000 +-0.050000 -0.380500 -0.243900 0.664000 -0.736000 -0.104000 +-0.026900 -0.351500 -0.304800 0.608000 -0.688000 -0.384000 +-0.050000 -0.374600 -0.304800 0.584000 -0.672000 -0.448000 +-0.050000 -0.351500 -0.336900 0.024000 -0.576000 -0.808000 +-0.050000 -0.351500 -0.336900 0.024000 -0.576000 -0.808000 +0.050000 -0.050200 -0.279200 0.280000 0.320000 -0.896000 +0.050000 -0.050200 -0.279200 0.280000 0.320000 -0.896000 +0.004800 -0.050200 -0.304800 0.368000 0.176000 -0.904000 +0.050000 -0.100400 -0.298100 0.360000 0.248000 -0.896000 +0.039400 -0.100400 -0.304800 0.408000 0.224000 -0.880000 +0.039400 -0.100400 -0.304800 0.408000 0.224000 -0.880000 +0.113100 0.000000 -0.243900 -0.392000 0.768000 -0.496000 +0.113100 0.000000 -0.243900 -0.392000 0.768000 -0.496000 +0.150000 0.000000 -0.257100 -0.208000 0.552000 -0.800000 +0.150000 0.015400 -0.243900 -0.208000 0.728000 -0.640000 +0.150000 0.015400 -0.243900 -0.208000 0.728000 -0.640000 +0.200000 -0.100400 -0.298900 0.088000 0.040000 -0.992000 +0.200000 -0.100400 -0.298900 0.088000 0.040000 -0.992000 +0.185500 -0.100400 -0.304800 0.296000 0.104000 -0.944000 +0.200000 -0.139100 -0.304800 0.208000 0.104000 -0.968000 +0.150000 -0.100400 -0.322200 0.000000 0.224000 -0.968000 +0.200000 -0.150600 -0.306400 0.192000 0.112000 -0.968000 +0.150000 -0.150600 -0.323600 -0.232000 0.464000 -0.848000 +0.200000 -0.200800 -0.335700 -0.120000 0.200000 -0.968000 +0.150000 -0.200800 -0.325200 0.160000 0.176000 -0.968000 +0.200000 -0.251000 -0.346500 -0.184000 0.088000 -0.976000 +0.150000 -0.251000 -0.336000 0.080000 -0.336000 -0.928000 +0.150000 -0.251000 -0.336000 0.080000 -0.336000 -0.928000 +0.211400 -0.050200 -0.304800 0.152000 0.184000 -0.968000 +0.211400 -0.050200 -0.304800 0.152000 0.184000 -0.968000 +0.200000 -0.061600 -0.304800 0.000000 -0.144000 -0.984000 +0.250000 -0.050200 -0.297000 0.000000 0.040000 -0.992000 +0.200000 -0.100400 -0.298900 0.088000 0.040000 -0.992000 +0.250000 -0.100400 -0.298400 -0.088000 0.216000 -0.968000 +0.200000 -0.139100 -0.304800 0.208000 0.104000 -0.968000 +0.250000 -0.114900 -0.304800 -0.104000 0.280000 -0.952000 +0.200000 -0.150600 -0.306400 0.192000 0.112000 -0.968000 +0.250000 -0.150600 -0.317700 0.024000 0.336000 -0.936000 +0.200000 -0.200800 -0.335700 -0.120000 0.200000 -0.968000 +0.250000 -0.200800 -0.343100 0.104000 0.232000 -0.960000 +0.200000 -0.251000 -0.346500 -0.184000 0.088000 -0.976000 +0.250000 -0.251000 -0.353900 0.064000 0.384000 -0.920000 +0.250000 -0.251000 -0.353900 0.064000 0.384000 -0.920000 +0.250000 -0.050200 -0.297000 0.000000 0.040000 -0.992000 +0.250000 -0.050200 -0.297000 0.000000 0.040000 -0.992000 +0.266500 -0.050200 -0.304800 -0.280000 0.064000 -0.952000 +0.250000 -0.100400 -0.298400 -0.088000 0.216000 -0.968000 +0.278900 -0.100400 -0.304800 -0.176000 0.256000 -0.944000 +0.250000 -0.114900 -0.304800 -0.104000 0.280000 -0.952000 +0.250000 -0.114900 -0.304800 -0.104000 0.280000 -0.952000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.313400 -0.150600 -0.304800 0.400000 -0.360000 -0.840000 +0.350000 -0.150600 -0.283600 -0.064000 -0.424000 -0.896000 +0.320800 -0.200800 -0.304800 0.496000 0.328000 -0.800000 +0.350000 -0.200800 -0.271400 0.216000 0.224000 -0.944000 +0.350000 -0.228300 -0.304800 0.616000 0.528000 -0.576000 +0.350000 -0.228300 -0.304800 0.616000 0.528000 -0.576000 +0.300000 -0.357600 -0.243900 -0.288000 -0.920000 0.248000 +0.300000 -0.357600 -0.243900 -0.288000 -0.920000 0.248000 +0.343800 -0.401700 -0.243900 -0.728000 -0.584000 0.344000 +0.300000 -0.355300 -0.304800 -0.272000 -0.752000 -0.592000 +0.344100 -0.401700 -0.304800 -0.784000 -0.512000 -0.336000 +0.344100 -0.401700 -0.304800 -0.784000 -0.512000 -0.336000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.350000 -0.127600 -0.304800 0.032000 -0.600000 -0.792000 +0.350000 -0.150600 -0.283600 -0.064000 -0.424000 -0.896000 +0.380400 -0.150600 -0.304800 -0.424000 -0.456000 -0.776000 +0.380400 -0.150600 -0.304800 -0.424000 -0.456000 -0.776000 +0.419200 0.050200 -0.304800 -0.224000 0.736000 -0.632000 +0.419200 0.050200 -0.304800 -0.224000 0.736000 -0.632000 +0.400000 0.050200 -0.294000 -0.352000 0.672000 -0.640000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.400000 -0.168700 -0.304800 -0.504000 -0.464000 -0.720000 +0.400000 -0.168700 -0.304800 -0.504000 -0.464000 -0.720000 +0.400000 -0.200800 -0.276700 0.448000 -0.472000 -0.752000 +0.424400 -0.200800 -0.304800 -0.552000 -0.520000 -0.648000 +0.400000 -0.249400 -0.243900 0.760000 -0.472000 -0.424000 +0.450000 -0.217600 -0.304800 -0.352000 -0.736000 -0.560000 +0.450000 -0.248400 -0.243900 -0.224000 -0.888000 -0.384000 +0.450000 -0.248400 -0.243900 -0.224000 -0.888000 -0.384000 +0.550000 -0.150600 -0.287800 0.352000 0.528000 -0.768000 +0.550000 -0.150600 -0.287800 0.352000 0.528000 -0.768000 +0.523400 -0.150600 -0.304800 0.376000 0.592000 -0.704000 +0.550000 -0.162200 -0.304800 0.376000 0.720000 -0.576000 +0.500000 -0.150600 -0.319100 0.336000 0.504000 -0.792000 +0.550000 -0.194000 -0.365800 0.224000 0.896000 -0.368000 +0.500000 -0.200800 -0.334200 -0.376000 -0.448000 -0.800000 +0.535800 -0.200800 -0.365800 -0.736000 0.208000 -0.632000 +0.500000 -0.222600 -0.304800 -0.320000 -0.704000 -0.624000 +0.550000 -0.216200 -0.365800 -0.080000 -0.576000 -0.808000 +0.535300 -0.251000 -0.304800 -0.648000 -0.480000 -0.576000 +0.550000 -0.251000 -0.326800 -0.648000 -0.504000 -0.560000 +0.550000 -0.216200 -0.365800 -0.080000 -0.576000 -0.808000 +0.573000 -0.251000 -0.365800 -0.696000 0.544000 -0.464000 +0.559600 -0.200800 -0.365800 0.680000 0.504000 -0.520000 +0.600000 -0.231600 -0.365800 0.072000 0.640000 -0.760000 +0.594200 -0.200800 -0.304800 0.544000 0.576000 -0.600000 +0.600000 -0.206100 -0.304800 0.488000 0.616000 -0.608000 +0.600000 -0.200800 -0.298700 0.448000 0.592000 -0.656000 +0.650000 -0.208600 -0.304800 0.024000 0.680000 -0.728000 +0.650000 -0.200800 -0.297000 0.088000 0.616000 -0.776000 +0.600000 -0.200800 -0.298700 0.448000 0.592000 -0.656000 +0.650000 -0.150600 -0.274900 0.544000 0.464000 -0.688000 +0.600000 -0.150600 -0.265200 0.248000 0.032000 -0.960000 +0.600000 -0.200800 -0.298700 0.448000 0.592000 -0.656000 +0.550000 -0.150600 -0.287800 0.352000 0.528000 -0.768000 +0.594200 -0.200800 -0.304800 0.544000 0.576000 -0.600000 +0.550000 -0.162200 -0.304800 0.376000 0.720000 -0.576000 +0.559600 -0.200800 -0.365800 0.680000 0.504000 -0.520000 +0.550000 -0.194000 -0.365800 0.224000 0.896000 -0.368000 +0.550000 -0.200800 -0.388300 0.280000 0.584000 -0.752000 +0.535800 -0.200800 -0.365800 -0.736000 0.208000 -0.632000 +0.550000 -0.216200 -0.365800 -0.080000 -0.576000 -0.808000 +0.550000 -0.200800 -0.388300 0.280000 0.584000 -0.752000 +0.559600 -0.200800 -0.365800 0.680000 0.504000 -0.520000 +0.559600 -0.200800 -0.365800 0.680000 0.504000 -0.520000 +0.500000 -0.222600 -0.304800 -0.320000 -0.704000 -0.624000 +0.500000 -0.222600 -0.304800 -0.320000 -0.704000 -0.624000 +0.500000 -0.251000 -0.264200 -0.272000 -0.744000 -0.600000 +0.535300 -0.251000 -0.304800 -0.648000 -0.480000 -0.576000 +0.535300 -0.251000 -0.304800 -0.648000 -0.480000 -0.576000 +0.800000 -0.401700 -0.291400 0.440000 0.456000 -0.760000 +0.800000 -0.401700 -0.291400 0.440000 0.456000 -0.760000 +0.800000 -0.418300 -0.304800 0.408000 0.496000 -0.760000 +0.850000 -0.401700 -0.268600 0.504000 0.432000 -0.744000 +0.837100 -0.451900 -0.304800 0.528000 0.264000 -0.800000 +0.850000 -0.451900 -0.293100 0.448000 0.248000 -0.848000 +0.800000 -0.493800 -0.304800 0.032000 -0.688000 -0.720000 +0.850000 -0.490600 -0.304800 0.216000 0.112000 -0.968000 +0.800000 -0.502100 -0.293400 -0.120000 -0.840000 -0.520000 +0.832800 -0.502100 -0.304800 -0.104000 -0.544000 -0.824000 +0.832800 -0.502100 -0.304800 -0.104000 -0.544000 -0.824000 +0.858900 0.050200 -0.243900 -0.424000 0.568000 -0.696000 +0.858900 0.050200 -0.243900 -0.424000 0.568000 -0.696000 +0.900000 0.050200 -0.268900 0.208000 0.672000 -0.696000 +0.900000 0.070800 -0.243900 -0.096000 0.744000 -0.656000 +0.900000 0.070800 -0.243900 -0.096000 0.744000 -0.656000 +0.981700 -0.050200 -0.304800 0.528000 0.432000 -0.720000 +0.981700 -0.050200 -0.304800 0.528000 0.432000 -0.720000 +1.000000 -0.073100 -0.304800 0.536000 0.424000 -0.720000 +1.000000 -0.050200 -0.288900 0.520000 0.432000 -0.728000 +1.000000 -0.050200 -0.288900 0.520000 0.432000 -0.728000 +-0.900000 0.104600 -0.304800 0.304000 0.568000 -0.760000 +-0.900000 0.104600 -0.304800 0.304000 0.568000 -0.760000 +-0.900000 0.100400 -0.308600 0.312000 0.536000 -0.776000 +-0.892300 0.100400 -0.304800 0.320000 0.536000 -0.776000 +-0.892300 0.100400 -0.304800 0.320000 0.536000 -0.776000 +-0.850000 -0.301200 -0.321900 -0.728000 -0.616000 -0.280000 +-0.850000 -0.301200 -0.321900 -0.728000 -0.616000 -0.280000 +-0.850000 -0.251000 -0.359600 -0.320000 0.248000 -0.912000 +-0.826000 -0.301200 -0.365800 -0.648000 -0.448000 -0.600000 +-0.828000 -0.251000 -0.365800 -0.248000 0.216000 -0.936000 +-0.800000 -0.301200 -0.380800 -0.264000 0.104000 -0.952000 +-0.800000 -0.251000 -0.370300 -0.064000 0.200000 -0.976000 +-0.750000 -0.301200 -0.392900 -0.104000 0.352000 -0.928000 +-0.750000 -0.251000 -0.369800 0.056000 0.280000 -0.952000 +-0.750000 -0.251000 -0.369800 0.056000 0.280000 -0.952000 +-0.800000 -0.066700 -0.304800 0.296000 0.144000 -0.936000 +-0.800000 -0.066700 -0.304800 0.296000 0.144000 -0.936000 +-0.800000 -0.100400 -0.313000 0.368000 0.216000 -0.896000 +-0.785000 -0.100400 -0.304800 0.328000 0.224000 -0.912000 +-0.785000 -0.100400 -0.304800 0.328000 0.224000 -0.912000 +-0.750000 -0.129200 -0.304800 0.392000 0.376000 -0.832000 +-0.750000 -0.129200 -0.304800 0.392000 0.376000 -0.832000 +-0.750000 -0.150600 -0.317800 0.416000 0.384000 -0.816000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.731900 -0.150600 -0.304800 0.424000 0.400000 -0.808000 +-0.576800 -0.251000 -0.365800 -0.136000 0.624000 -0.760000 +-0.576800 -0.251000 -0.365800 -0.136000 0.624000 -0.760000 +-0.600000 -0.251000 -0.360600 -0.120000 0.624000 -0.760000 +-0.600000 -0.256300 -0.365800 -0.112000 0.608000 -0.776000 +-0.600000 -0.256300 -0.365800 -0.112000 0.608000 -0.776000 +-0.500000 -0.637800 -0.304800 -0.208000 -0.976000 -0.032000 +-0.500000 -0.637800 -0.304800 -0.208000 -0.976000 -0.032000 +-0.455200 -0.652700 -0.304800 -0.280000 -0.952000 0.040000 +-0.500000 -0.633000 -0.365800 -0.088000 -0.968000 -0.200000 +-0.450000 -0.652700 -0.319500 -0.256000 -0.952000 -0.136000 +-0.450000 -0.645700 -0.365800 -0.144000 -0.904000 -0.392000 +-0.405700 -0.652700 -0.365800 -0.144000 -0.920000 -0.344000 +-0.405700 -0.652700 -0.365800 -0.144000 -0.920000 -0.344000 +-0.350000 -0.585900 -0.365800 0.168000 -0.792000 -0.576000 +-0.350000 -0.585900 -0.365800 0.168000 -0.792000 -0.576000 +-0.350000 -0.594300 -0.304800 0.520000 -0.800000 0.280000 +-0.357100 -0.602500 -0.365800 0.904000 0.256000 -0.312000 +-0.351600 -0.602500 -0.304800 0.944000 0.304000 0.024000 +-0.350000 -0.629600 -0.365800 0.056000 0.640000 -0.760000 +-0.350000 -0.605300 -0.304800 0.248000 0.960000 -0.032000 +-0.328400 -0.602500 -0.365800 -0.832000 -0.248000 -0.488000 +-0.344900 -0.602500 -0.304800 -0.744000 0.664000 -0.032000 +-0.350000 -0.585900 -0.365800 0.168000 -0.792000 -0.576000 +-0.350000 -0.594300 -0.304800 0.520000 -0.800000 0.280000 +-0.350000 -0.594300 -0.304800 0.520000 -0.800000 0.280000 +-0.350000 -0.747900 -0.304800 -0.512000 -0.832000 -0.184000 +-0.350000 -0.747900 -0.304800 -0.512000 -0.832000 -0.184000 +-0.350000 -0.703000 -0.357000 -0.336000 -0.496000 -0.792000 +-0.371300 -0.703000 -0.304800 -0.816000 -0.552000 -0.144000 +-0.371300 -0.703000 -0.304800 -0.816000 -0.552000 -0.144000 +-0.331500 -0.150600 -0.304800 -0.256000 0.464000 -0.840000 +-0.331500 -0.150600 -0.304800 -0.256000 0.464000 -0.840000 +-0.300000 -0.150600 -0.319300 -0.256000 0.480000 -0.832000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.300000 -0.118900 -0.304800 -0.376000 0.264000 -0.880000 +-0.250000 -0.639500 -0.365800 0.216000 -0.224000 -0.944000 +-0.250000 -0.639500 -0.365800 0.216000 -0.224000 -0.944000 +-0.282800 -0.652700 -0.365800 0.080000 -0.160000 -0.976000 +-0.250000 -0.652700 -0.361600 0.240000 -0.216000 -0.944000 +-0.250000 -0.652700 -0.361600 0.240000 -0.216000 -0.944000 +-0.250000 -0.150600 -0.327500 -0.120000 0.152000 -0.976000 +-0.250000 -0.150600 -0.327500 -0.120000 0.152000 -0.976000 +-0.200000 -0.150600 -0.333300 0.216000 -0.272000 -0.936000 +-0.250000 -0.200800 -0.333200 0.168000 0.080000 -0.976000 +-0.200000 -0.200800 -0.306700 0.368000 -0.184000 -0.904000 +-0.250000 -0.251000 -0.337900 0.384000 0.112000 -0.912000 +-0.200000 -0.251000 -0.307600 0.408000 0.096000 -0.904000 +-0.250000 -0.301200 -0.349000 0.296000 0.272000 -0.912000 +-0.200000 -0.301200 -0.313400 0.328000 0.152000 -0.928000 +-0.200000 -0.301200 -0.313400 0.328000 0.152000 -0.928000 +-0.200000 -0.602500 -0.345500 0.488000 -0.272000 -0.824000 +-0.200000 -0.602500 -0.345500 0.488000 -0.272000 -0.824000 +-0.200000 -0.558000 -0.365800 0.448000 -0.240000 -0.856000 +-0.229500 -0.602500 -0.365800 0.408000 -0.240000 -0.872000 +-0.200000 -0.552300 -0.367100 0.360000 -0.232000 -0.896000 +-0.250000 -0.602500 -0.376000 0.360000 -0.328000 -0.872000 +-0.250000 -0.552300 -0.402600 0.504000 -0.312000 -0.792000 +-0.250000 -0.552300 -0.402600 0.504000 -0.312000 -0.792000 +-0.150000 -0.602500 -0.307600 0.456000 -0.280000 -0.840000 +-0.150000 -0.602500 -0.307600 0.456000 -0.280000 -0.840000 +-0.150000 -0.552300 -0.337600 0.424000 -0.304000 -0.840000 +-0.200000 -0.602500 -0.345500 0.488000 -0.272000 -0.824000 +-0.196100 -0.552300 -0.365800 0.320000 -0.272000 -0.904000 +-0.200000 -0.558000 -0.365800 0.448000 -0.240000 -0.856000 +-0.200000 -0.552300 -0.367100 0.360000 -0.232000 -0.896000 +-0.200000 -0.552300 -0.367100 0.360000 -0.232000 -0.896000 +-0.147100 -0.502100 -0.365800 0.472000 -0.192000 -0.848000 +-0.147100 -0.502100 -0.365800 0.472000 -0.192000 -0.848000 +-0.145700 -0.451900 -0.365800 0.464000 0.040000 -0.880000 +-0.100000 -0.502100 -0.325200 0.520000 -0.368000 -0.760000 +-0.100000 -0.451900 -0.336100 0.496000 -0.048000 -0.856000 +-0.074100 -0.502100 -0.304800 0.864000 -0.480000 0.112000 +-0.061500 -0.451900 -0.304800 0.928000 -0.352000 0.088000 +-0.061500 -0.451900 -0.304800 0.928000 -0.352000 0.088000 +-0.100000 -0.200800 -0.311700 -0.496000 0.128000 -0.856000 +-0.100000 -0.200800 -0.311700 -0.496000 0.128000 -0.856000 +-0.050000 -0.200800 -0.320900 -0.056000 0.280000 -0.952000 +-0.100000 -0.251000 -0.333700 -0.512000 0.248000 -0.816000 +-0.050000 -0.251000 -0.364300 -0.216000 0.352000 -0.904000 +-0.100000 -0.301200 -0.349000 -0.368000 0.264000 -0.888000 +-0.050000 -0.266900 -0.365800 -0.288000 0.088000 -0.944000 +-0.058500 -0.301200 -0.365800 -0.384000 -0.288000 -0.872000 +-0.050000 -0.301200 -0.370400 -0.392000 -0.264000 -0.872000 +-0.050000 -0.309800 -0.365800 -0.336000 -0.416000 -0.840000 +-0.058500 -0.301200 -0.365800 -0.384000 -0.288000 -0.872000 +-0.050000 -0.351500 -0.336900 0.024000 -0.576000 -0.808000 +-0.100000 -0.301200 -0.349000 -0.368000 0.264000 -0.888000 +-0.100000 -0.351500 -0.338800 0.024000 -0.312000 -0.944000 +-0.100000 -0.351500 -0.338800 0.024000 -0.312000 -0.944000 +0.050000 -0.119800 -0.304800 0.416000 0.264000 -0.864000 +0.050000 -0.119800 -0.304800 0.416000 0.264000 -0.864000 +0.050000 -0.150600 -0.318000 0.352000 0.312000 -0.872000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +0.096000 -0.150600 -0.304800 0.176000 0.336000 -0.920000 +0.301400 0.000000 -0.304800 -0.584000 0.656000 -0.464000 +0.301400 0.000000 -0.304800 -0.584000 0.656000 -0.464000 +0.350000 0.000000 -0.339100 -0.264000 0.552000 -0.784000 +0.350000 0.024300 -0.304800 -0.456000 0.784000 -0.408000 +0.400000 0.000000 -0.343200 -0.216000 0.592000 -0.768000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.400000 0.041200 -0.304800 -0.352000 0.672000 -0.648000 +0.383500 -0.050200 -0.365800 0.200000 -0.288000 -0.928000 +0.383500 -0.050200 -0.365800 0.200000 -0.288000 -0.928000 +0.400000 -0.050200 -0.360800 0.184000 -0.432000 -0.872000 +0.350000 -0.037900 -0.365800 -0.440000 0.432000 -0.776000 +0.400000 0.000000 -0.343200 -0.216000 0.592000 -0.768000 +0.350000 0.000000 -0.339100 -0.264000 0.552000 -0.784000 +0.350000 0.000000 -0.339100 -0.264000 0.552000 -0.784000 +0.355700 -0.351500 -0.365800 0.360000 -0.072000 -0.928000 +0.355700 -0.351500 -0.365800 0.360000 -0.072000 -0.928000 +0.400000 -0.351500 -0.338800 0.360000 -0.568000 -0.728000 +0.350000 -0.334300 -0.365800 -0.304000 0.096000 -0.944000 +0.400000 -0.301200 -0.307300 0.704000 0.496000 -0.496000 +0.350000 -0.301200 -0.360500 0.376000 0.184000 -0.904000 +0.350000 -0.301200 -0.360500 0.376000 0.184000 -0.904000 +0.376800 -0.401700 -0.304800 0.336000 -0.848000 -0.392000 +0.376800 -0.401700 -0.304800 0.336000 -0.848000 -0.392000 +0.350000 -0.401700 -0.317400 -0.608000 -0.560000 -0.544000 +0.350000 -0.410700 -0.304800 -0.592000 -0.664000 -0.440000 +0.350000 -0.410700 -0.304800 -0.592000 -0.664000 -0.440000 +0.400000 -0.050200 -0.360800 0.184000 -0.432000 -0.872000 +0.400000 -0.050200 -0.360800 0.184000 -0.432000 -0.872000 +0.450000 -0.050200 -0.325200 -0.120000 -0.568000 -0.808000 +0.400000 -0.100400 -0.340000 -0.040000 -0.360000 -0.928000 +0.450000 -0.100400 -0.322200 0.392000 -0.360000 -0.840000 +0.400000 -0.150600 -0.318400 -0.432000 -0.416000 -0.792000 +0.450000 -0.150600 -0.321300 -0.008000 0.120000 -0.992000 +0.400000 -0.168700 -0.304800 -0.504000 -0.464000 -0.720000 +0.450000 -0.200800 -0.331300 -0.472000 -0.400000 -0.776000 +0.424400 -0.200800 -0.304800 -0.552000 -0.520000 -0.648000 +0.450000 -0.217600 -0.304800 -0.352000 -0.736000 -0.560000 +0.450000 -0.217600 -0.304800 -0.352000 -0.736000 -0.560000 +0.450000 0.055500 -0.304800 0.064000 0.864000 -0.496000 +0.450000 0.055500 -0.304800 0.064000 0.864000 -0.496000 +0.450000 0.050200 -0.314200 0.064000 0.744000 -0.656000 +0.496000 0.050200 -0.304800 0.104000 0.800000 -0.576000 +0.496000 0.050200 -0.304800 0.104000 0.800000 -0.576000 +0.500000 -0.333600 -0.304800 -0.408000 0.824000 -0.376000 +0.500000 -0.333600 -0.304800 -0.408000 0.824000 -0.376000 +0.458900 -0.351500 -0.304800 -0.472000 0.360000 -0.792000 +0.500000 -0.351500 -0.354900 -0.384000 -0.472000 -0.784000 +0.500000 -0.400200 -0.304800 -0.176000 -0.672000 -0.712000 +0.500000 -0.400200 -0.304800 -0.176000 -0.672000 -0.712000 +0.450000 -0.380500 -0.304800 -0.144000 0.256000 -0.952000 +0.450000 -0.380500 -0.304800 -0.144000 0.256000 -0.952000 +0.450000 -0.401700 -0.316200 -0.184000 -0.360000 -0.904000 +0.492100 -0.401700 -0.304800 0.152000 -0.576000 -0.792000 +0.492100 -0.401700 -0.304800 0.152000 -0.576000 -0.792000 +0.500000 -0.127100 -0.304800 0.480000 0.456000 -0.744000 +0.500000 -0.127100 -0.304800 0.480000 0.456000 -0.744000 +0.500000 -0.150600 -0.319100 0.336000 0.504000 -0.792000 +0.523400 -0.150600 -0.304800 0.376000 0.592000 -0.704000 +0.523400 -0.150600 -0.304800 0.376000 0.592000 -0.704000 +0.600000 -0.086300 -0.304800 0.440000 0.312000 -0.832000 +0.600000 -0.086300 -0.304800 0.440000 0.312000 -0.832000 +0.589400 -0.100400 -0.304800 -0.440000 -0.424000 -0.784000 +0.600000 -0.100400 -0.312700 0.376000 -0.472000 -0.792000 +0.600000 -0.105700 -0.304800 0.312000 -0.728000 -0.600000 +0.604900 -0.100400 -0.304800 0.744000 -0.360000 -0.552000 +0.600000 -0.100400 -0.312700 0.376000 -0.472000 -0.792000 +0.600000 -0.086300 -0.304800 0.440000 0.312000 -0.832000 +0.600000 -0.086300 -0.304800 0.440000 0.312000 -0.832000 +0.600000 -0.206100 -0.304800 0.488000 0.616000 -0.608000 +0.600000 -0.206100 -0.304800 0.488000 0.616000 -0.608000 +0.650000 -0.208600 -0.304800 0.024000 0.680000 -0.728000 +0.600000 -0.231600 -0.365800 0.072000 0.640000 -0.760000 +0.650000 -0.245700 -0.365800 0.168000 0.856000 -0.480000 +0.600000 -0.249700 -0.426800 -0.344000 0.872000 -0.328000 +0.650000 -0.251000 -0.378600 0.328000 0.752000 -0.560000 +0.604800 -0.251000 -0.426800 0.544000 0.248000 -0.792000 +0.650000 -0.267900 -0.365800 0.280000 -0.440000 -0.848000 +0.600000 -0.252700 -0.426800 -0.416000 -0.736000 -0.520000 +0.600000 -0.288400 -0.365800 -0.376000 -0.712000 -0.584000 +0.598300 -0.251000 -0.426800 -0.848000 0.144000 -0.496000 +0.573000 -0.251000 -0.365800 -0.696000 0.544000 -0.464000 +0.600000 -0.249700 -0.426800 -0.344000 0.872000 -0.328000 +0.600000 -0.231600 -0.365800 0.072000 0.640000 -0.760000 +0.600000 -0.231600 -0.365800 0.072000 0.640000 -0.760000 +0.700000 -0.211400 -0.304800 0.288000 0.624000 -0.720000 +0.700000 -0.211400 -0.304800 0.288000 0.624000 -0.720000 +0.700000 -0.251000 -0.357800 0.296000 0.496000 -0.808000 +0.728900 -0.251000 -0.304800 0.720000 0.440000 -0.528000 +0.700000 -0.301200 -0.354900 0.160000 -0.240000 -0.952000 +0.744500 -0.301200 -0.304800 0.640000 0.104000 -0.760000 +0.744500 -0.301200 -0.304800 0.640000 0.104000 -0.760000 +0.750000 -0.334300 -0.304800 0.512000 0.112000 -0.840000 +0.750000 -0.334300 -0.304800 0.512000 0.112000 -0.840000 +0.750000 -0.351500 -0.307800 0.512000 0.128000 -0.840000 +0.754800 -0.351500 -0.304800 0.424000 0.136000 -0.888000 +0.750000 -0.401700 -0.321600 0.336000 0.000000 -0.936000 +0.779200 -0.401700 -0.304800 0.400000 0.336000 -0.848000 +0.779200 -0.401700 -0.304800 0.400000 0.336000 -0.848000 +0.800000 -0.418300 -0.304800 0.408000 0.496000 -0.760000 +0.800000 -0.418300 -0.304800 0.408000 0.496000 -0.760000 +0.800000 -0.451900 -0.330300 0.328000 0.200000 -0.920000 +0.837100 -0.451900 -0.304800 0.528000 0.264000 -0.800000 +0.800000 -0.493800 -0.304800 0.032000 -0.688000 -0.720000 +0.800000 -0.493800 -0.304800 0.032000 -0.688000 -0.720000 +0.856800 -0.502100 -0.304800 0.288000 0.144000 -0.944000 +0.856800 -0.502100 -0.304800 0.288000 0.144000 -0.944000 +0.850000 -0.502100 -0.307100 0.032000 -0.240000 -0.968000 +0.850000 -0.504700 -0.304800 -0.096000 -0.664000 -0.736000 +0.850000 -0.504700 -0.304800 -0.096000 -0.664000 -0.736000 +0.900000 0.016700 -0.304800 -0.152000 0.720000 -0.664000 +0.900000 0.016700 -0.304800 -0.152000 0.720000 -0.664000 +0.900000 0.000000 -0.329500 -0.080000 0.648000 -0.744000 +0.927400 0.000000 -0.304800 0.400000 0.560000 -0.720000 +0.927400 0.000000 -0.304800 0.400000 0.560000 -0.720000 +-0.850000 -0.496800 -0.365800 -0.176000 0.616000 -0.760000 +-0.850000 -0.496800 -0.365800 -0.176000 0.616000 -0.760000 +-0.864000 -0.502100 -0.365800 -0.304000 0.480000 -0.816000 +-0.850000 -0.502100 -0.370900 -0.184000 0.560000 -0.800000 +-0.860100 -0.552300 -0.365800 -0.680000 -0.432000 -0.584000 +-0.850000 -0.552300 -0.378600 -0.568000 -0.344000 -0.736000 +-0.850000 -0.564700 -0.365800 -0.608000 -0.528000 -0.584000 +-0.800000 -0.552300 -0.401000 -0.552000 -0.288000 -0.776000 +-0.806700 -0.602500 -0.365800 -0.520000 -0.656000 -0.536000 +-0.800000 -0.602500 -0.372400 -0.488000 -0.592000 -0.624000 +-0.800000 -0.607700 -0.365800 -0.488000 -0.640000 -0.584000 +-0.750000 -0.602500 -0.401000 -0.336000 -0.696000 -0.624000 +-0.750000 -0.628000 -0.365800 -0.232000 -0.808000 -0.528000 +-0.714100 -0.602500 -0.426800 -0.368000 -0.680000 -0.624000 +-0.700000 -0.639000 -0.365800 -0.040000 -0.920000 -0.376000 +-0.700000 -0.609100 -0.426800 -0.336000 -0.744000 -0.568000 +-0.650000 -0.641900 -0.365800 -0.024000 -0.952000 -0.280000 +-0.650000 -0.621300 -0.426800 -0.080000 -0.904000 -0.400000 +-0.650000 -0.621300 -0.426800 -0.080000 -0.904000 -0.400000 +-0.850000 -0.496800 -0.365800 -0.176000 0.616000 -0.760000 +-0.850000 -0.496800 -0.365800 -0.176000 0.616000 -0.760000 +-0.800000 -0.496400 -0.365800 -0.664000 0.416000 -0.608000 +-0.850000 -0.502100 -0.370900 -0.184000 0.560000 -0.800000 +-0.800000 -0.502100 -0.369300 -0.768000 0.256000 -0.576000 +-0.850000 -0.552300 -0.378600 -0.568000 -0.344000 -0.736000 +-0.800000 -0.552300 -0.401000 -0.552000 -0.288000 -0.776000 +-0.800000 -0.502100 -0.369300 -0.768000 0.256000 -0.576000 +-0.750000 -0.552300 -0.422100 -0.552000 -0.096000 -0.824000 +-0.750000 -0.502100 -0.424900 -0.848000 -0.112000 -0.512000 +-0.744500 -0.552300 -0.426800 -0.560000 -0.080000 -0.816000 +-0.748800 -0.502100 -0.426800 -0.584000 -0.048000 -0.800000 +-0.750000 -0.502100 -0.424900 -0.848000 -0.112000 -0.512000 +-0.750000 -0.498100 -0.426800 -0.864000 -0.184000 -0.448000 +-0.800000 -0.502100 -0.369300 -0.768000 0.256000 -0.576000 +-0.764100 -0.451900 -0.426800 -0.880000 -0.256000 -0.384000 +-0.800000 -0.496400 -0.365800 -0.664000 0.416000 -0.608000 +-0.786000 -0.451900 -0.365800 -0.872000 0.080000 -0.472000 +-0.764100 -0.451900 -0.426800 -0.880000 -0.256000 -0.384000 +-0.796500 -0.401700 -0.365800 -0.952000 -0.168000 -0.232000 +-0.777800 -0.401700 -0.426800 -0.928000 0.040000 -0.360000 +-0.777800 -0.401700 -0.426800 -0.928000 0.040000 -0.360000 +-0.800000 -0.602500 -0.372400 -0.488000 -0.592000 -0.624000 +-0.800000 -0.602500 -0.372400 -0.488000 -0.592000 -0.624000 +-0.800000 -0.552300 -0.401000 -0.552000 -0.288000 -0.776000 +-0.750000 -0.602500 -0.401000 -0.336000 -0.696000 -0.624000 +-0.750000 -0.552300 -0.422100 -0.552000 -0.096000 -0.824000 +-0.714100 -0.602500 -0.426800 -0.368000 -0.680000 -0.624000 +-0.744500 -0.552300 -0.426800 -0.560000 -0.080000 -0.816000 +-0.744500 -0.552300 -0.426800 -0.560000 -0.080000 -0.816000 +-0.350000 -0.248400 -0.365800 0.184000 0.424000 -0.880000 +-0.350000 -0.248400 -0.365800 0.184000 0.424000 -0.880000 +-0.350000 -0.251000 -0.367200 0.240000 0.168000 -0.952000 +-0.345700 -0.251000 -0.365800 0.320000 0.336000 -0.880000 +-0.345700 -0.251000 -0.365800 0.320000 0.336000 -0.880000 +-0.250000 -0.342900 -0.365800 0.504000 0.512000 -0.680000 +-0.250000 -0.342900 -0.365800 0.504000 0.512000 -0.680000 +-0.250000 -0.351500 -0.379700 0.552000 0.712000 -0.416000 +-0.241400 -0.351500 -0.365800 0.488000 0.640000 -0.576000 +-0.241400 -0.351500 -0.365800 0.488000 0.640000 -0.576000 +-0.200000 -0.365300 -0.365800 0.504000 0.768000 -0.376000 +-0.200000 -0.365300 -0.365800 0.504000 0.768000 -0.376000 +-0.200000 -0.393200 -0.426800 0.696000 0.632000 -0.328000 +-0.151700 -0.401700 -0.365800 0.568000 0.104000 -0.808000 +-0.194300 -0.401700 -0.426800 0.792000 0.416000 -0.432000 +-0.194300 -0.401700 -0.426800 0.792000 0.416000 -0.432000 +-0.044700 -0.251000 -0.365800 -0.216000 0.376000 -0.896000 +-0.044700 -0.251000 -0.365800 -0.216000 0.376000 -0.896000 +0.000000 -0.251000 -0.386300 -0.352000 0.496000 -0.792000 +0.000000 -0.238800 -0.365800 -0.192000 0.648000 -0.728000 +0.000000 -0.238800 -0.365800 -0.192000 0.648000 -0.728000 +0.100000 -0.224900 -0.365800 0.352000 0.456000 -0.808000 +0.100000 -0.224900 -0.365800 0.352000 0.456000 -0.808000 +0.100000 -0.251000 -0.380100 0.472000 -0.384000 -0.784000 +0.118000 -0.251000 -0.365800 0.536000 -0.224000 -0.808000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +0.100000 -0.263400 -0.365800 0.480000 -0.672000 -0.544000 +0.350000 -0.354600 -0.365800 -0.264000 -0.632000 -0.720000 +0.350000 -0.354600 -0.365800 -0.264000 -0.632000 -0.720000 +0.350000 -0.351500 -0.368100 -0.440000 0.096000 -0.888000 +0.348000 -0.351500 -0.365800 -0.720000 -0.032000 -0.680000 +0.348000 -0.351500 -0.365800 -0.720000 -0.032000 -0.680000 +0.450000 0.007700 -0.365800 -0.264000 0.744000 -0.600000 +0.450000 0.007700 -0.365800 -0.264000 0.744000 -0.600000 +0.431500 0.000000 -0.365800 -0.424000 0.312000 -0.840000 +0.450000 0.000000 -0.377000 -0.360000 0.400000 -0.840000 +0.450000 -0.014200 -0.365800 -0.336000 -0.568000 -0.744000 +0.450000 -0.014200 -0.365800 -0.336000 -0.568000 -0.744000 +0.650000 -0.245700 -0.365800 0.168000 0.856000 -0.480000 +0.650000 -0.245700 -0.365800 0.168000 0.856000 -0.480000 +0.650000 -0.251000 -0.378600 0.328000 0.752000 -0.560000 +0.678000 -0.251000 -0.365800 0.264000 0.520000 -0.808000 +0.650000 -0.267900 -0.365800 0.280000 -0.440000 -0.848000 diff --git a/progs/demos/lodbias.c b/progs/demos/lodbias.c new file mode 100644 index 00000000000..a4db22e26e4 --- /dev/null +++ b/progs/demos/lodbias.c @@ -0,0 +1,282 @@ +/* + * GL_EXT_texture_lod_bias demo + * + * Thanks to Michael Vance for implementing this extension in Mesa. + * + * Brian Paul + * 20 March 2000 + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <GL/glut.h> +#include <GL/glext.h> + +#include "readtex.h" + +#define TEXTURE_FILE "../images/girl.rgb" + +static GLfloat Xrot = 0, Yrot = -30, Zrot = 0; +static GLboolean Anim = GL_TRUE; +static GLint Bias = 0, BiasStepSign = +1; /* ints avoid fp precision problem */ +static GLint BiasMin = -400, BiasMax = 400; + + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + +static void Idle( void ) +{ + static int lastTime = 0; + int time = glutGet(GLUT_ELAPSED_TIME); + int step; + + if (lastTime == 0) + lastTime = time; + else if (time - lastTime < 10) + return; + + step = (time - lastTime) / 10 * BiasStepSign; + lastTime = time; + + Bias += step; + if (Bias < BiasMin) { + Bias = BiasMin; + BiasStepSign = +1; + } + else if (Bias > BiasMax) { + Bias = BiasMax; + BiasStepSign = -1; + } + + glutPostRedisplay(); +} + + +static void Display( void ) +{ + char str[100]; + + glClear( GL_COLOR_BUFFER_BIT ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 1); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glDisable(GL_TEXTURE_2D); + glColor3f(1,1,1); + glRasterPos3f(-0.9, -0.9, 0.0); + sprintf(str, "Texture LOD Bias = %4.1f", Bias * 0.01); + PrintString(str); + + 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, -8.0 ); + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glRotatef(Zrot, 0, 0, 1); + + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0.01 * Bias); + + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex2f(-1, -1); + glTexCoord2f(2, 0); glVertex2f( 1, -1); + glTexCoord2f(2, 2); glVertex2f( 1, 1); + glTexCoord2f(0, 2); glVertex2f(-1, 1); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); +} + + +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 'b': + Bias -= 10; + break; + case 'B': + Bias += 10; + 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 ) +{ + GLfloat maxBias; + + if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) { + printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n"); + exit(1); + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + if (glutExtensionSupported("GL_SGIS_generate_mipmap")) { + /* test auto mipmap generation */ + GLint width, height, i; + GLenum format; + GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); + if (!image) { + printf("Error: could not load texture image %s\n", TEXTURE_FILE); + exit(1); + } + /* resize to 256 x 256 */ + if (width != 256 || height != 256) { + GLubyte *newImage = malloc(256 * 256 * 4); + gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, + 256, 256, GL_UNSIGNED_BYTE, newImage); + free(image); + image = newImage; + } + printf("Using GL_SGIS_generate_mipmap\n"); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, format, 256, 256, 0, + format, GL_UNSIGNED_BYTE, image); + free(image); + + /* make sure mipmap was really generated correctly */ + width = height = 256; + for (i = 0; i < 9; i++) { + GLint w, h; + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); + printf("Level %d size: %d x %d\n", i, w, h); + assert(w == width); + assert(h == height); + width /= 2; + height /= 2; + } + + } + else if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: could not load texture image %s\n", TEXTURE_FILE); + exit(1); + } + + /* mipmapping required for this extension */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &maxBias); + printf("LOD bias range: [%g, %g]\n", -maxBias, maxBias); + BiasMin = -100 * maxBias; + BiasMax = 100 * maxBias; + + /* Since we have (about) 8 mipmap levels, no need to bias beyond + * the range [-1, +8]. + */ + if (BiasMin < -100) + BiasMin = -100; + if (BiasMax > 800) + BiasMax = 800; +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 350, 350 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/morph3d.c b/progs/demos/morph3d.c new file mode 100644 index 00000000000..162a6ff847e --- /dev/null +++ b/progs/demos/morph3d.c @@ -0,0 +1,896 @@ + +/*- + * morph3d.c - Shows 3D morphing objects + * + * Converted to GLUT by brianp on 1/1/98 + * + * This program was inspired on a WindowsNT(R)'s screen saver. It was written + * from scratch and it was not based on any other source code. + * + * Porting it to xlock (the final objective of this code since the moment I + * decided to create it) was possible by comparing the original Mesa's gear + * demo with it's ported version, so thanks for Danny Sung for his indirect + * help (look at gear.c in xlock source tree). NOTE: At the moment this code + * was sent to Brian Paul for package inclusion, the XLock Version was not + * available. In fact, I'll wait it to appear on the next Mesa release (If you + * are reading this, it means THIS release) to send it for xlock package + * inclusion). It will probably there be a GLUT version too. + * + * Thanks goes also to Brian Paul for making it possible and inexpensive + * to use OpenGL at home. + * + * Since I'm not a native english speaker, my apologies for any gramatical + * mistake. + * + * My e-mail addresses are + * + * and + * + * Marcelo F. Vianna (Feb-13-1997) + */ + +/* +This document is VERY incomplete, but tries to describe the mathematics used +in the program. At this moment it just describes how the polyhedra are +generated. On futhurer versions, this document will be probabbly improved. + +Since I'm not a native english speaker, my apologies for any gramatical +mistake. + +Marcelo Fernandes Vianna +- Undergraduate in Computer Engeneering at Catholic Pontifical University +- of Rio de Janeiro (PUC-Rio) Brasil. +- e-mail: [email protected] or [email protected] +- Feb-13-1997 + +POLYHEDRA GENERATION + +For the purpose of this program it's not sufficient to know the polyhedra +vertexes coordinates. Since the morphing algorithm applies a nonlinear +transformation over the surfaces (faces) of the polyhedron, each face has +to be divided into smaller ones. The morphing algorithm needs to transform +each vertex of these smaller faces individually. It's a very time consoming +task. + +In order to reduce calculation overload, and since all the macro faces of +the polyhedron are transformed by the same way, the generation is made by +creating only one face of the polyhedron, morphing it and then rotating it +around the polyhedron center. + +What we need to know is the face radius of the polyhedron (the radius of +the inscribed sphere) and the angle between the center of two adjacent +faces using the center of the sphere as the angle's vertex. + +The face radius of the regular polyhedra are known values which I decided +to not waste my time calculating. Following is a table of face radius for +the regular polyhedra with edge length = 1: + + TETRAHEDRON : 1/(2*sqrt(2))/sqrt(3) + CUBE : 1/2 + OCTAHEDRON : 1/sqrt(6) + DODECAHEDRON : T^2 * sqrt((T+2)/5) / 2 -> 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 <stdio.h> +#include <stdlib.h> +#ifndef _WIN32 +#include <unistd.h> +#endif +#include <GL/glut.h> +#include <math.h> +#include <string.h> + +#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 int anim=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<Ri; Ti++) { \ + Xf=(float)(Ri-Ti)*Ax + (float)Ti*Bx; \ + Yf=Vr+(float)(Ri-Ti)*Ay + (float)Ti*Ay; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + \ + Xf=(float)(Ri-Ti-1)*Ax + (float)Ti*Bx; \ + Yf=Vr+(float)(Ri-Ti-1)*Ay + (float)Ti*Ay; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + \ + } \ + Xf=(float)Ri*Bx; \ + Yf=Vr+(float)Ri*Ay; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + glEnd(); \ + } \ +} + +#define SQUARE(Edge, Amp, Divisions, Z) \ +{ \ + int Xi,Yi; \ + GLfloat Xf,Yf,Y,Xf2,Yf2,Y2,Xa,Yb; \ + GLfloat Factor,Factor1,Factor2; \ + GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \ + GLfloat Zf=(Edge)*(Z); \ + GLfloat AmpVr2=(Amp)/sqr((Edge)*SQRT2/2); \ + \ + for (Yi=0; Yi<(Divisions); Yi++) { \ + Yf=-((Edge)/2.0) + ((float)Yi)/(Divisions)*(Edge); \ + Yf2=sqr(Yf); \ + Y=Yf+1.0/(Divisions)*(Edge); \ + Y2=sqr(Y); \ + glBegin(GL_QUAD_STRIP); \ + for (Xi=0; Xi<=(Divisions); Xi++) { \ + Xf=-((Edge)/2.0) + ((float)Xi)/(Divisions)*(Edge); \ + Xf2=sqr(Xf); \ + \ + Xa=Xf+0.001; Yb=Y+0.001; \ + Factor=1-((Xf2+Y2)*AmpVr2); \ + Factor1=1-((sqr(Xa)+Y2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Y; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Y-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-((Xf2+Yf2)*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + } \ + glEnd(); \ + } \ +} + +#define PENTAGON(Edge, Amp, Divisions, Z) \ +{ \ + int Ri,Ti,Fi; \ + GLfloat Xf,Yf,Xa,Yb,Xf2,Yf2; \ + GLfloat x[6],y[6]; \ + GLfloat Factor,Factor1,Factor2; \ + GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \ + GLfloat Zf=(Edge)*(Z); \ + GLfloat AmpVr2=(Amp)/sqr((Edge)*cossec36_2); \ + \ + for(Fi=0;Fi<6;Fi++) { \ + x[Fi]=-cos( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge); \ + y[Fi]=sin( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge); \ + } \ + \ + for (Ri=1; Ri<=(Divisions); Ri++) { \ + for (Fi=0; Fi<5; Fi++) { \ + glBegin(GL_TRIANGLE_STRIP); \ + for (Ti=0; Ti<Ri; Ti++) { \ + Xf=(float)(Ri-Ti)*x[Fi] + (float)Ti*x[Fi+1]; \ + Yf=(float)(Ri-Ti)*y[Fi] + (float)Ti*y[Fi+1]; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + \ + Xf=(float)(Ri-Ti-1)*x[Fi] + (float)Ti*x[Fi+1]; \ + Yf=(float)(Ri-Ti-1)*y[Fi] + (float)Ti*y[Fi+1]; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + \ + } \ + Xf=(float)Ri*x[Fi+1]; \ + Yf=(float)Ri*y[Fi+1]; \ + Xa=Xf+0.001; Yb=Yf+0.001; \ + Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \ + Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \ + Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \ + VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \ + NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \ + NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \ + glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \ + glVertex3f(VertX, VertY, VertZ); \ + glEnd(); \ + } \ + } \ +} + +static void draw_tetra( void ) +{ + GLuint list; + + list = glGenLists( 1 ); + glNewList( list, GL_COMPILE ); + TRIANGLE(2,seno,edgedivisions,0.5/SQRT6); + glEndList(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,0,1); + glRotatef(-tetraangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+tetraangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+tetraangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); + glCallList(list); + + glDeleteLists(list,1); +} + +static void draw_cube( void ) +{ + GLuint list; + + list = glGenLists( 1 ); + glNewList( list, GL_COMPILE ); + SQUARE(2, seno, edgedivisions, 0.5) + glEndList(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); + glCallList(list); + glRotatef(cubeangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); + glCallList(list); + glRotatef(cubeangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); + glCallList(list); + glRotatef(cubeangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); + glCallList(list); + glRotatef(cubeangle,0,1,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]); + glCallList(list); + glRotatef(2*cubeangle,0,1,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]); + glCallList(list); + + glDeleteLists(list,1); +} + +static void draw_octa( void ) +{ + GLuint list; + + list = glGenLists( 1 ); + glNewList( list, GL_COMPILE ); + TRIANGLE(2,seno,edgedivisions,1/SQRT6); + glEndList(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,0,1); + glRotatef(-180+octaangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-octaangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-octaangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); + glCallList(list); + glPopMatrix(); + glRotatef(180,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,0,1); + glRotatef(-180+octaangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-octaangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-octaangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]); + glCallList(list); + + glDeleteLists(list,1); +} + +static void draw_dodeca( void ) +{ + GLuint list; + +#define TAU ((SQRT5+1)/2) + + list = glGenLists( 1 ); + glNewList( list, GL_COMPILE ); + PENTAGON(1,seno,edgedivisions,sqr(TAU) * sqrt((TAU+2)/5) / 2); + glEndList(); + + glPushMatrix(); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); + glCallList(list); + glRotatef(180,0,0,1); + glPushMatrix(); + glRotatef(-dodecaangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(-dodecaangle,cos72,sin72,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(-dodecaangle,cos72,-sin72,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(dodecaangle,cos36,-sin36,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]); + glCallList(list); + glPopMatrix(); + glRotatef(dodecaangle,cos36,sin36,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]); + glCallList(list); + glPopMatrix(); + glRotatef(180,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]); + glCallList(list); + glRotatef(180,0,0,1); + glPushMatrix(); + glRotatef(-dodecaangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(-dodecaangle,cos72,sin72,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(-dodecaangle,cos72,-sin72,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(dodecaangle,cos36,-sin36,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]); + glCallList(list); + glPopMatrix(); + glRotatef(dodecaangle,cos36,sin36,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]); + glCallList(list); + + glDeleteLists(list,1); +} + +static void draw_ico( void ) +{ + GLuint list; + + list = glGenLists( 1 ); + glNewList( list, GL_COMPILE ); + TRIANGLE(1.5,seno,edgedivisions,(3*SQRT3+SQRT15)/12); + glEndList(); + + glPushMatrix(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]); + glCallList(list); + glPopMatrix(); + glRotatef(180,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[12]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[13]); + glCallList(list); + glPopMatrix(); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[14]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[15]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[16]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[17]); + glCallList(list); + glPushMatrix(); + glRotatef(180,0,1,0); + glRotatef(-180+icoangle,0.5,-SQRT3/2,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[18]); + glCallList(list); + glPopMatrix(); + glRotatef(180,0,0,1); + glRotatef(-icoangle,1,0,0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[19]); + glCallList(list); + + glDeleteLists(list,1); +} + +static void draw ( void ) { + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + + glTranslatef( 0.0, 0.0, -10.0 ); + glScalef( Scale*WindH/WindW, Scale, Scale ); + glTranslatef(2.5*WindW/WindH*sin(step*1.11),2.5*cos(step*1.25*1.11),0); + glRotatef(step*100,1,0,0); + glRotatef(step*95,0,1,0); + glRotatef(step*90,0,0,1); + + seno=(sin(step)+1.0/3.0)*(4.0/5.0)*Magnitude; + + draw_object(); + + glPopMatrix(); + + glFlush(); + + glutSwapBuffers(); + +} + +static void idle_( void ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + step += dt; + + glutPostRedisplay(); +} + +static void reshape( int width, int height ) +{ + glViewport(0, 0, WindW=(GLint)width, WindH=(GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); + glMatrixMode(GL_MODELVIEW); +} + +static void pinit(void); + +static void key( unsigned char k, int x, int y ) +{ + (void) x; + (void) y; + switch (k) { + case '1': object=1; break; + case '2': object=2; break; + case '3': object=3; break; + case '4': object=4; break; + case '5': object=5; break; + case ' ': mono^=1; break; + case 's': smooth^=1; break; + case 'a': + anim^=1; + if (anim) + glutIdleFunc( idle_ ); + else + glutIdleFunc(NULL); + break; + case 27: + exit(0); + } + pinit(); + glutPostRedisplay(); +} + +static void pinit(void) +{ + switch(object) { + case 1: + draw_object=draw_tetra; + MaterialColor[0]=MaterialRed; + MaterialColor[1]=MaterialGreen; + MaterialColor[2]=MaterialBlue; + MaterialColor[3]=MaterialWhite; + edgedivisions=tetradivisions; + Magnitude=2.5; + break; + case 2: + draw_object=draw_cube; + MaterialColor[0]=MaterialRed; + MaterialColor[1]=MaterialGreen; + MaterialColor[2]=MaterialCyan; + MaterialColor[3]=MaterialMagenta; + MaterialColor[4]=MaterialYellow; + MaterialColor[5]=MaterialBlue; + edgedivisions=cubedivisions; + Magnitude=2.0; + break; + case 3: + draw_object=draw_octa; + MaterialColor[0]=MaterialRed; + MaterialColor[1]=MaterialGreen; + MaterialColor[2]=MaterialBlue; + MaterialColor[3]=MaterialWhite; + MaterialColor[4]=MaterialCyan; + MaterialColor[5]=MaterialMagenta; + MaterialColor[6]=MaterialGray; + MaterialColor[7]=MaterialYellow; + edgedivisions=octadivisions; + Magnitude=2.5; + break; + case 4: + draw_object=draw_dodeca; + MaterialColor[ 0]=MaterialRed; + MaterialColor[ 1]=MaterialGreen; + MaterialColor[ 2]=MaterialCyan; + MaterialColor[ 3]=MaterialBlue; + MaterialColor[ 4]=MaterialMagenta; + MaterialColor[ 5]=MaterialYellow; + MaterialColor[ 6]=MaterialGreen; + MaterialColor[ 7]=MaterialCyan; + MaterialColor[ 8]=MaterialRed; + MaterialColor[ 9]=MaterialMagenta; + MaterialColor[10]=MaterialBlue; + MaterialColor[11]=MaterialYellow; + edgedivisions=dodecadivisions; + Magnitude=2.0; + break; + case 5: + draw_object=draw_ico; + MaterialColor[ 0]=MaterialRed; + MaterialColor[ 1]=MaterialGreen; + MaterialColor[ 2]=MaterialBlue; + MaterialColor[ 3]=MaterialCyan; + MaterialColor[ 4]=MaterialYellow; + MaterialColor[ 5]=MaterialMagenta; + MaterialColor[ 6]=MaterialRed; + MaterialColor[ 7]=MaterialGreen; + MaterialColor[ 8]=MaterialBlue; + MaterialColor[ 9]=MaterialWhite; + MaterialColor[10]=MaterialCyan; + MaterialColor[11]=MaterialYellow; + MaterialColor[12]=MaterialMagenta; + MaterialColor[13]=MaterialRed; + MaterialColor[14]=MaterialGreen; + MaterialColor[15]=MaterialBlue; + MaterialColor[16]=MaterialCyan; + MaterialColor[17]=MaterialYellow; + MaterialColor[18]=MaterialMagenta; + MaterialColor[19]=MaterialGray; + edgedivisions=icodivisions; + Magnitude=2.5; + break; + } + if (mono) { + int loop; + for (loop=0; loop<20; loop++) MaterialColor[loop]=MaterialGray; + } + if (smooth) { + glShadeModel( GL_SMOOTH ); + } else { + glShadeModel( GL_FLAT ); + } + +} + +static void INIT(void) +{ + printf("Morph 3D - Shows morphing platonic polyhedra\n"); + printf("Author: Marcelo Fernandes Vianna ([email protected])\n\n"); + printf(" [1] - Tetrahedron\n"); + printf(" [2] - Hexahedron (Cube)\n"); + printf(" [3] - Octahedron\n"); + printf(" [4] - Dodecahedron\n"); + printf(" [5] - Icosahedron\n"); + printf("[SPACE] - Toggle colored faces\n"); + printf("[RETURN] - Toggle smooth/flat shading\n"); + printf(" [ESC] - Quit\n"); + + object=1; + + glutInitWindowPosition(0,0); + glutInitWindowSize(640,480); + + glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB ); + + if (glutCreateWindow("Morph 3D - Shows morphing platonic polyhedra") <= 0) { + exit(0); + } + + glClearDepth(1.0); + glClearColor( 0.0, 0.0, 0.0, 1.0 ); + glColor3f( 1.0, 1.0, 1.0 ); + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glFlush(); + glutSwapBuffers(); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position0); + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT1, GL_POSITION, position1); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + glEnable(GL_DEPTH_TEST); + glEnable(GL_NORMALIZE); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); + + glHint(GL_FOG_HINT, GL_FASTEST); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); + + pinit(); + + glutReshapeFunc( reshape ); + glutKeyboardFunc( key ); + glutIdleFunc( idle_ ); + glutDisplayFunc( draw ); + glutMainLoop(); + +} + +int main(int argc, char **argv) +{ + INIT(); + return(0); +} diff --git a/progs/demos/multiarb.c b/progs/demos/multiarb.c new file mode 100644 index 00000000000..d963985c69d --- /dev/null +++ b/progs/demos/multiarb.c @@ -0,0 +1,345 @@ + +/* + * GL_ARB_multitexture demo + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul November 1998 This program is in the public domain. + * Modified on 12 Feb 2002 for > 2 texture units. + */ + + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define TEXTURE_1_FILE "../images/girl.rgb" +#define TEXTURE_2_FILE "../images/reflect.rgb" + +#define TEX0 1 +#define TEX7 8 +#define ANIMATE 10 +#define QUIT 100 + +static GLboolean Animate = GL_TRUE; +static GLint NumUnits = 1; +static GLboolean TexEnabled[8]; + +static GLfloat Drift = 0.0; +static GLfloat drift_increment = 0.005; +static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0; + + +static void Idle( void ) +{ + if (Animate) { + GLint i; + + Drift += drift_increment; + if (Drift >= 1.0) + Drift = 0.0; + + for (i = 0; i < NumUnits; i++) { + glActiveTextureARB(GL_TEXTURE0_ARB + i); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + if (i == 0) { + glTranslatef(Drift, 0.0, 0.0); + glScalef(2, 2, 1); + } + else if (i == 1) { + glTranslatef(0.0, Drift, 0.0); + } + else { + glTranslatef(0.5, 0.5, 0.0); + glRotatef(180.0 * Drift, 0, 0, 1); + glScalef(1.0/i, 1.0/i, 1.0/i); + glTranslatef(-0.5, -0.5, 0.0); + } + } + glMatrixMode(GL_MODELVIEW); + + glutPostRedisplay(); + } +} + + +static void DrawObject(void) +{ + GLint i; + GLint j; + static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; + static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; + + if (!TexEnabled[0] && !TexEnabled[1]) + glColor3f(0.1, 0.1, 0.1); /* add onto this */ + else + glColor3f(1, 1, 1); /* modulate this */ + + glBegin(GL_QUADS); + + /* Toggle between the vector and scalar entry points. This is done purely + * to hit multiple paths in the driver. + */ + if ( Drift > 0.49 ) { + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) + glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, + tex_coords[j], tex_coords[j+1]); + glVertex2f( vtx_coords[j], vtx_coords[j+1] ); + } + } + else { + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) + glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, & tex_coords[j]); + glVertex2fv( & vtx_coords[j] ); + } + } + + glEnd(); +} + + + +static void Display( void ) +{ + static GLint T0 = 0; + static GLint Frames = 0; + GLint t; + + 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(); + + Frames++; + + t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 250) { + GLfloat seconds = (t - T0) / 1000.0; + drift_increment = 2.2 * seconds / Frames; + T0 = t; + Frames = 0; + } +} + + +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) +{ + if (entry >= TEX0 && entry <= TEX7) { + /* toggle */ + GLint i = entry - TEX0; + TexEnabled[i] = !TexEnabled[i]; + glActiveTextureARB(GL_TEXTURE0_ARB + i); + if (TexEnabled[i]) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + printf("Enabled: "); + for (i = 0; i < NumUnits; i++) + printf("%d ", (int) TexEnabled[i]); + printf("\n"); + } + else if (entry==ANIMATE) { + Animate = !Animate; + } + else if (entry==QUIT) { + exit(0); + } + + 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( int argc, char *argv[] ) +{ + GLuint texObj[8]; + GLint size, i; + + 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); + } + + glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &NumUnits); + printf("%d texture units supported\n", NumUnits); + if (NumUnits > 8) + NumUnits = 8; + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); + printf("%d x %d max texture size\n", size, size); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + for (i = 0; i < NumUnits; i++) { + if (i < 2) + TexEnabled[i] = GL_TRUE; + else + TexEnabled[i] = GL_FALSE; + } + + /* allocate two texture objects */ + glGenTextures(NumUnits, texObj); + + /* setup the texture objects */ + for (i = 0; i < NumUnits; i++) { + + glActiveTextureARB(GL_TEXTURE0_ARB + i); + glBindTexture(GL_TEXTURE_2D, texObj[i]); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (i == 0) { + if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + } + else if (i == 1) { + if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) { + printf("Error: couldn't load texture image\n"); + exit(1); + } + } + else { + /* checker */ + GLubyte image[8][8][3]; + GLint i, j; + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if ((i + j) & 1) { + image[i][j][0] = 50; + image[i][j][1] = 50; + image[i][j][2] = 50; + } + else { + image[i][j][0] = 25; + image[i][j][1] = 25; + image[i][j][2] = 25; + } + } + } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, + GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *) image); + } + + /* Bind texObj[i] to ith texture unit */ + if (i < 2) + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + else + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); + + if (TexEnabled[i]) + glEnable(GL_TEXTURE_2D); + } + + glShadeModel(GL_FLAT); + glClearColor(0.3, 0.3, 0.4, 1.0); + + if (argc > 1 && strcmp(argv[1], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } +} + + +int main( int argc, char *argv[] ) +{ + GLint i; + + glutInit( &argc, argv ); + glutInitWindowSize( 300, 300 ); + glutInitWindowPosition( 0, 0 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow(argv[0] ); + + Init( argc, argv ); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutCreateMenu(ModeMenu); + + for (i = 0; i < NumUnits; i++) { + char s[100]; + sprintf(s, "Toggle Texture %d", i); + glutAddMenuEntry(s, TEX0 + i); + } + glutAddMenuEntry("Toggle Animation", ANIMATE); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/paltex.c b/progs/demos/paltex.c new file mode 100644 index 00000000000..aa9c0da36b7 --- /dev/null +++ b/progs/demos/paltex.c @@ -0,0 +1,270 @@ + +/* + * Paletted texture demo. Written by Brian Paul. + * This program is in the public domain. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + + +static float Rot = 0.0; +static GLboolean Anim = 1; + + +static void Idle( void ) +{ + float t = glutGet(GLUT_ELAPSED_TIME) * 0.001; /* in seconds */ + Rot = t * 360 / 4; /* 1 rotation per 4 seconds */ + glutPostRedisplay(); +} + + +static void Display( void ) +{ + /* draw background gradient */ + glDisable(GL_TEXTURE_2D); + glBegin(GL_POLYGON); + glColor3f(1.0, 0.0, 0.2); glVertex2f(-1.5, -1.0); + glColor3f(1.0, 0.0, 0.2); glVertex2f( 1.5, -1.0); + glColor3f(0.0, 0.0, 1.0); glVertex2f( 1.5, 1.0); + glColor3f(0.0, 0.0, 1.0); glVertex2f(-1.5, 1.0); + glEnd(); + + glPushMatrix(); + glRotatef(Rot, 0, 0, 1); + + glEnable(GL_TEXTURE_2D); + glBegin(GL_POLYGON); + glTexCoord2f(0, 1); glVertex2f(-1, -0.5); + glTexCoord2f(1, 1); glVertex2f( 1, -0.5); + glTexCoord2f(1, 0); glVertex2f( 1, 0.5); + glTexCoord2f(0, 0); glVertex2f(-1, 0.5); + glEnd(); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.5, 1.5, -1.0, 1.0, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + case 's': + Rot += 0.5; + break; + case ' ': + Anim = !Anim; + if (Anim) + glutIdleFunc( Idle ); + else + glutIdleFunc( NULL ); + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ +#define HEIGHT 8 +#define WIDTH 32 + /* 257 = HEIGHT * WIDTH + 1 (for trailing '\0') */ + static char texture[257] = {"\ + \ + MMM EEEE SSS AAA \ + M M M E S S A A \ + M M M EEEE SS A A \ + M M M E SS AAAAA \ + M M E S S A A \ + M M EEEE SSS A A \ + " + }; + GLubyte table[256][4]; + + if (!glutExtensionSupported("GL_EXT_paletted_texture")) { + printf("Sorry, GL_EXT_paletted_texture not supported\n"); + exit(0); + } + + /* load the color table for each texel-index */ + memset(table, 0, 256*4); + table[' '][0] = 255; + table[' '][1] = 255; + table[' '][2] = 255; + table[' '][3] = 64; + table['M'][0] = 255; + table['M'][1] = 0; + table['M'][2] = 0; + table['M'][3] = 255; + table['E'][0] = 0; + table['E'][1] = 255; + table['E'][2] = 0; + table['E'][3] = 255; + table['S'][0] = 0; + table['S'][1] = 0; + table['S'][2] = 255; + table['S'][3] = 255; + table['A'][0] = 255; + table['A'][1] = 255; + table['A'][2] = 0; + table['A'][3] = 255; + +#ifdef GL_EXT_paletted_texture + +#if defined(GL_EXT_shared_texture_palette) && defined(USE_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 */ + WIDTH, HEIGHT, /* width, height */ + 0, /* border */ + GL_COLOR_INDEX, /* texture format */ + GL_UNSIGNED_BYTE, /* texture type */ + texture); /* the 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); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#undef HEIGHT +#undef WIDTH +} + + + +/* + * Color ramp test + */ +static void Init2( void ) +{ +#define HEIGHT 32 +#define WIDTH 256 + static char texture[HEIGHT][WIDTH]; + GLubyte table[256][4]; + int i, j; + + if (!glutExtensionSupported("GL_EXT_paletted_texture")) { + printf("Sorry, GL_EXT_paletted_texture not supported\n"); + exit(0); + } + + for (j = 0; j < HEIGHT; j++) { + for (i = 0; i < WIDTH; i++) { + texture[j][i] = i; + } + } + + for (i = 0; i < 255; i++) { + table[i][0] = i; + table[i][1] = 0; + table[i][2] = 0; + table[i][3] = 255; + } + +#ifdef GL_EXT_paletted_texture + +#if defined(GL_EXT_shared_texture_palette) && defined(USE_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 */ + WIDTH, HEIGHT, /* 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); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 400, 300 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0]); + + Init(); + (void) Init2; /* silence warning */ + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + if (Anim) + glutIdleFunc( Idle ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/particles.cxx b/progs/demos/particles.cxx new file mode 100644 index 00000000000..b88c318e0bc --- /dev/null +++ b/progs/demos/particles.cxx @@ -0,0 +1,219 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdlib.h> + +#include "particles.h" + +#define vinit(a,i,j,k) {\ + (a)[0]=i;\ + (a)[1]=j;\ + (a)[2]=k;\ +} + +#define vadds(a,dt,b) {\ + (a)[0]+=(dt)*(b)[0];\ + (a)[1]+=(dt)*(b)[1];\ + (a)[2]+=(dt)*(b)[2];\ +} + +#define vequ(a,b) {\ + (a)[0]=(b)[0];\ + (a)[1]=(b)[1];\ + (a)[2]=(b)[2];\ +} + +#define vinter(a,dt,b,c) {\ + (a)[0]=(dt)*(b)[0]+(1.0-dt)*(c)[0];\ + (a)[1]=(dt)*(b)[1]+(1.0-dt)*(c)[1];\ + (a)[2]=(dt)*(b)[2]+(1.0-dt)*(c)[2];\ +} + +#define clamp(a) ((a) < 0.0 ? 0.0 : ((a) < 1.0 ? (a) : 1.0)) + +#define vclamp(v) {\ + (v)[0]=clamp((v)[0]);\ + (v)[1]=clamp((v)[1]);\ + (v)[2]=clamp((v)[2]);\ +} + + +float rainParticle::min[3]; +float rainParticle::max[3]; +float rainParticle::partLength=0.2f; + + +static float vrnd(void) +{ + return(((float)rand())/RAND_MAX); +} + + +particle::particle() +{ + age=0.0f; + + vinit(acc,0.0f,0.0f,0.0f); + vinit(vel,0.0f,0.0f,0.0f); + vinit(pos,0.0f,0.0f,0.0f); +} + +void particle::elapsedTime(float dt) +{ + age+=dt; + + vadds(vel,dt,acc); + + vadds(pos,dt,vel); +} + +///////////////////////////////////////// +// Particle System +///////////////////////////////////////// + +particleSystem::particleSystem() +{ + t=0.0f; + + part=NULL; + + particleNum=0; +} + +particleSystem::~particleSystem() +{ + if(part) + free(part); +} + +void particleSystem::addParticle(particle *p) +{ + if(!part) { + part=(particle **)calloc(1,sizeof(particle *)); + part[0]=p; + particleNum=1; + } else { + particleNum++; + part=(particle **)realloc(part,sizeof(particle *)*particleNum); + part[particleNum-1]=p; + } +} + +void particleSystem::reset(void) +{ + if(part) + free(part); + + t=0.0f; + + part=NULL; + + particleNum=0; +} + +void particleSystem::draw(void) +{ + if(!part) + return; + + part[0]->beginDraw(); + for(unsigned int i=0;i<particleNum;i++) + part[i]->draw(); + part[0]->endDraw(); +} + +void particleSystem::addTime(float dt) +{ + if(!part) + return; + + for(unsigned int i=0;i<particleNum;i++) { + part[i]->elapsedTime(dt); + part[i]->checkAge(); + } +} + +///////////////////////////////////////// +// Rain +///////////////////////////////////////// + +void rainParticle::init(void) +{ + age=0.0f; + + acc[0]=0.0f; + acc[1]=-0.98f; + acc[2]=0.0f; + + vel[0]=0.0f; + vel[1]=0.0f; + vel[2]=0.0f; + + oldpos[0]=pos[0]=min[0]+(max[0]-min[0])*vrnd(); + oldpos[1]=pos[1]=max[1]+0.2f*max[1]*vrnd(); + oldpos[2]=pos[2]=min[2]+(max[2]-min[2])*vrnd(); + + vadds(oldpos,-partLength,vel); +} + +rainParticle::rainParticle() +{ + init(); +} + +void rainParticle::setRainingArea(float minx, float miny, float minz, + float maxx, float maxy, float maxz) +{ + vinit(min,minx,miny,minz); + vinit(max,maxx,maxy,maxz); +} + +void rainParticle::setLength(float l) +{ + partLength=l; +} + +void rainParticle::draw(void) +{ + glColor4f(0.7f,0.95f,1.0f,0.0f); + glVertex3fv(oldpos); + + glColor4f(0.3f,0.7f,1.0f,1.0f); + glVertex3fv(pos); +} + +void rainParticle::checkAge(void) +{ + if(pos[1]<min[1]) + init(); +} + +void rainParticle::elapsedTime(float dt) +{ + particle::elapsedTime(dt); + + if(pos[0]<min[0]) + pos[0]=max[0]-(min[0]-pos[0]); + if(pos[2]<min[2]) + pos[2]=max[2]-(min[2]-pos[2]); + + if(pos[0]>max[0]) + pos[0]=min[0]+(pos[0]-max[0]); + if(pos[2]>max[2]) + pos[2]=min[2]+(pos[2]-max[2]); + + vequ(oldpos,pos); + vadds(oldpos,-partLength,vel); +} + +void rainParticle::randomHeight(void) +{ + pos[1]=(max[1]-min[1])*vrnd()+min[1]; + + oldpos[1]=pos[1]-partLength*vel[1]; +} diff --git a/progs/demos/particles.h b/progs/demos/particles.h new file mode 100644 index 00000000000..a49dd691e4a --- /dev/null +++ b/progs/demos/particles.h @@ -0,0 +1,81 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#ifndef PARTICLES_H +#define PARTICLES_H + +#include <GL/gl.h> + +class particle { + protected: + float age; // in seconds + float acc[3]; + float vel[3]; + float pos[3]; + + public: + particle(); + virtual ~particle() {}; + + virtual void beginDraw(void) {}; + virtual void draw(void)=0; + virtual void endDraw(void) {}; + + virtual void elapsedTime(float); + virtual void checkAge(void) {}; +}; + +class particleSystem { + protected: + particle **part; + + float t; + + unsigned long particleNum; + public: + particleSystem(); + ~particleSystem(); + + void addParticle(particle *); + + void reset(void); + + void draw(void); + + void addTime(float); +}; + +class rainParticle : public particle { + protected: + static float min[3]; + static float max[3]; + static float partLength; + + float oldpos[3]; + + void init(void); + public: + rainParticle(); + + static void setRainingArea(float, float, float, + float, float, float); + static void setLength(float); + static float getLength(void) { return partLength; }; + + void beginDraw(void) { glBegin(GL_LINES); }; + void draw(void); + void endDraw(void) { glEnd(); }; + + void elapsedTime(float); + + void checkAge(void); + + void randomHeight(void); +}; + +#endif diff --git a/progs/demos/pointblast.c b/progs/demos/pointblast.c new file mode 100644 index 00000000000..dbbe2f35a28 --- /dev/null +++ b/progs/demos/pointblast.c @@ -0,0 +1,503 @@ + +/* 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. */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> /* for cos(), sin(), and sqrt() */ +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + +/* Some <math.h> 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 + +/* Modeling units of ground extent in each X and Z direction. */ +#define EDGE 12 + +static void +makePointList(void) +{ + float angle, velocity, direction; + int i; + + motion = 1; + for (i=0; i<numPoints; i++) { + pointList[i][0] = 0.0; + pointList[i][1] = 0.0; + pointList[i][2] = 0.0; + pointTime[i] = 0.0; + angle = (RANDOM_RANGE(60.0, 70.0)) * M_PI/180.0; + direction = RANDOM_RANGE(0.0, 360.0) * M_PI/180.0; + pointDirection[i][0] = cos(direction); + pointDirection[i][1] = sin(direction); + velocity = MEAN_VELOCITY + RANDOM_RANGE(-0.8, 1.0); + pointVelocity[i][0] = velocity * cos(angle); + pointVelocity[i][1] = velocity * sin(angle); + colorList[i] = rand() % NUM_COLORS; + } + theTime = 0.0; +} + +static void +updatePointList(void) +{ + float distance; + int i; + + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + motion = 0; + for (i=0; i<numPoints; i++) { + distance = pointVelocity[i][0] * theTime; + + /* X and Z */ + pointList[i][0] = pointDirection[i][0] * distance; + pointList[i][2] = pointDirection[i][1] * distance; + + /* Z */ + pointList[i][1] = + (pointVelocity[i][1] - 0.5 * GRAVITY * pointTime[i])*pointTime[i]; + + /* If we hit the ground, bounce the point upward again. */ + if (pointList[i][1] <= 0.0) { + if (distance > 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] += dt; + } + theTime += dt; + if (!motion && !spin) { + if (repeat) { + makePointList(); + } else { + glutIdleFunc(NULL); + } + } +} + +static void +idle(void) +{ + updatePointList(); + if (spin) { + angle += 0.3; + newModel = 1; + } + glutPostRedisplay(); +} + +static void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) { + if (animate && (motion || spin)) { + glutIdleFunc(idle); + } + } else { + glutIdleFunc(NULL); + } +} + +static void +recalcModelView(void) +{ + glPopMatrix(); + glPushMatrix(); + glRotatef(angle, 0.0, 1.0, 0.0); + newModel = 0; +} + +static 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<numPoints; i++) { + /* Draw alive particles. */ + if (colorList[i] != DEAD) { + glColor4fv(colorSet[colorList[i]]); + glVertex3fv(pointList[i]); + } + } + glEnd(); + + glDisable(GL_BLEND); + + glutSwapBuffers(); +} + +/* ARGSUSED2 */ +static void +mouse(int button, int state, int x, int y) +{ + /* Scene can be spun around Y axis using left + mouse button movement. */ + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { + moving = 1; + begin = x; + } + if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { + moving = 0; + } +} + +/* ARGSUSED1 */ +static void +mouseMotion(int x, int y) +{ + if (moving) { + angle = angle + (x - begin); + begin = x; + newModel = 1; + glutPostRedisplay(); + } +} + +static void +menu(int option) +{ + switch (option) { + case 0: + makePointList(); + break; +#ifdef GL_ARB_point_parameters + case 1: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, constant); + break; + case 2: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, linear); + break; + case 3: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); + break; +#endif + case 4: + blend = 1; + break; + case 5: + blend = 0; + break; +#ifdef GL_ARB_point_parameters + case 6: + glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0); + break; + case 7: + glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 10.0); + break; +#endif + case 8: + glEnable(GL_POINT_SMOOTH); + break; + case 9: + glDisable(GL_POINT_SMOOTH); + break; + case 10: + glPointSize(2.0); + break; + case 11: + glPointSize(4.0); + break; + case 12: + glPointSize(8.0); + break; + case 13: + spin = 1 - spin; + if (animate && (spin || motion)) { + glutIdleFunc(idle); + } else { + glutIdleFunc(NULL); + } + break; + case 14: + numPoints = 200; + break; + case 15: + numPoints = 500; + break; + case 16: + numPoints = 1000; + break; + case 17: + numPoints = 2000; + break; + case 666: + exit(0); + } + glutPostRedisplay(); +} + +/* ARGSUSED1 */ +static void +key(unsigned char c, int x, int y) +{ + switch (c) { + case 13: + animate = 1 - animate; /* toggle. */ + if (animate && (motion || spin)) { + glutIdleFunc(idle); + } else { + glutIdleFunc(NULL); + } + break; + case ' ': + animate = 1; + makePointList(); + glutIdleFunc(idle); + break; + case 27: + exit(0); + } +} + +/* Nice floor texture tiling pattern. */ +static char *circles[] = { + "....xxxx........", + "..xxxxxxxx......", + ".xxxxxxxxxx.....", + ".xxx....xxx.....", + "xxx......xxx....", + "xxx......xxx....", + "xxx......xxx....", + "xxx......xxx....", + ".xxx....xxx.....", + ".xxxxxxxxxx.....", + "..xxxxxxxx......", + "....xxxx........", + "................", + "................", + "................", + "................", +}; + +static void +makeFloorTexture(void) +{ + GLubyte floorTexture[16][16][3]; + GLubyte *loc; + int s, t; + + /* Setup RGB image for the texture. */ + loc = (GLubyte*) floorTexture; + for (t = 0; t < 16; t++) { + for (s = 0; s < 16; s++) { + if (circles[t][s] == 'x') { + /* Nice blue. */ + loc[0] = 0x1f; + loc[1] = 0x1f; + loc[2] = 0x8f; + } else { + /* Light gray. */ + loc[0] = 0xca; + loc[1] = 0xca; + loc[2] = 0xca; + } + loc += 3; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + if (useMipmaps) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16, + GL_RGB, GL_UNSIGNED_BYTE, floorTexture); + } else { + if (linearFiltering) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0, + GL_RGB, GL_UNSIGNED_BYTE, floorTexture); + } +} + +int +main(int argc, char **argv) +{ + int i; + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); + glutInitWindowPosition(0, 0); + glutInitWindowSize(300, 300); + + for (i=1; i<argc; i++) { + if(!strcmp("-noms", argv[i])) { + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + printf("forcing no multisampling\n"); + } else if(!strcmp("-nomipmaps", argv[i])) { + useMipmaps = 0; + } else if(!strcmp("-nearest", argv[i])) { + linearFiltering = 0; + } + } + + glutCreateWindow("point burst"); + glutDisplayFunc(redraw); + glutMouseFunc(mouse); + glutMotionFunc(mouseMotion); + glutVisibilityFunc(visible); + glutKeyboardFunc(key); + glutCreateMenu(menu); + glutAddMenuEntry("Reset time", 0); + glutAddMenuEntry("Constant", 1); + glutAddMenuEntry("Linear", 2); + glutAddMenuEntry("Quadratic", 3); + glutAddMenuEntry("Blend on", 4); + glutAddMenuEntry("Blend off", 5); + glutAddMenuEntry("Threshold 1", 6); + glutAddMenuEntry("Threshold 10", 7); + glutAddMenuEntry("Point smooth on", 8); + glutAddMenuEntry("Point smooth off", 9); + glutAddMenuEntry("Point size 2", 10); + glutAddMenuEntry("Point size 4", 11); + glutAddMenuEntry("Point size 8", 12); + glutAddMenuEntry("Toggle spin", 13); + glutAddMenuEntry("200 points ", 14); + glutAddMenuEntry("500 points ", 15); + glutAddMenuEntry("1000 points ", 16); + glutAddMenuEntry("2000 points ", 17); + glutAddMenuEntry("Quit", 666); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + if (!glutExtensionSupported("GL_ARB_point_parameters")) { + fprintf(stderr, "Sorry, GL_ARB_point_parameters is not supported.\n"); + return -1; + } + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + glEnable(GL_POINT_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glPointSize(8.0); +#if GL_ARB_point_parameters + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); +#endif + glMatrixMode(GL_PROJECTION); + gluPerspective( /* field of view in degree */ 40.0, + /* aspect ratio */ 1.0, + /* Z near */ 0.5, /* Z far */ 40.0); + glMatrixMode(GL_MODELVIEW); + gluLookAt(0.0, 1.0, 8.0, /* eye location */ + 0.0, 1.0, 0.0, /* center is at (0,0,0) */ + 0.0, 1.0, 0.); /* up is in postivie Y direction */ + glPushMatrix(); /* dummy push so we can pop on model + recalc */ + + makePointList(); + makeFloorTexture(); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/rain.cxx b/progs/demos/rain.cxx new file mode 100644 index 00000000000..d19f049c5f3 --- /dev/null +++ b/progs/demos/rain.cxx @@ -0,0 +1,394 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> +#include <GL/glut.h> +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +#include "particles.h" +extern "C" { +#include "readtex.h" +} + +#ifdef _WIN32 +#include <windows.h> +#include <mmsystem.h> +#include "particles.cxx" +#include "readtex.c" +#endif + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen=1; +#endif + +static int WIDTH=640; +static int HEIGHT=480; +static int NUMPART=7500; + +#define FRAME 50 + +static float fogcolor[4]={1.0,1.0,1.0,1.0}; + +#define DIMP 40.0 +#define DIMTP 32.0 + +static float q[4][3]={ + {-DIMP,0.0,-DIMP}, + {DIMP,0.0,-DIMP}, + {DIMP,0.0,DIMP}, + {-DIMP,0.0,DIMP} +}; + +static float qt[4][2]={ + {-DIMTP,-DIMTP}, + {DIMTP,-DIMTP}, + {DIMTP,DIMTP}, + {-DIMTP,DIMTP} +}; + +static int win=0; + +static int fog=1; +static int help=1; + +static GLuint groundid; + +static float obs[3]={2.0,1.0,0.0}; +static float dir[3]; +static float v=0.0; +static float alpha=-90.0; +static float beta=90.0; + +static particleSystem *ps; + +static float gettime() +{ + static clock_t told=0; + clock_t tnew,ris; + + tnew=clock(); + + ris=tnew-told; + + told=tnew; + + return(ris/(float)CLOCKS_PER_SEC); +} + +static float gettimerain() +{ + static clock_t told=0; + clock_t tnew,ris; + + tnew=clock(); + + ris=tnew-told; + + told=tnew; + + return(ris/(float)CLOCKS_PER_SEC); +} + +static void calcposobs(void) +{ + dir[0]=sin(alpha*M_PI/180.0); + dir[2]=cos(alpha*M_PI/180.0)*sin(beta*M_PI/180.0); + dir[1]=cos(beta*M_PI/180.0); + + obs[0]+=v*dir[0]; + obs[1]+=v*dir[1]; + obs[2]+=v*dir[2]; + + rainParticle::setRainingArea(obs[0]-7.0f,-0.2f,obs[2]-7.0f,obs[0]+7.0f,8.0f,obs[2]+7.0f); +} + +static void printstring(void *font, char *string) +{ + int len,i; + + len=(int)strlen(string); + for(i=0;i<len;i++) + glutBitmapCharacter(font,string[i]); +} + +static void reshape(int width, int height) +{ + WIDTH=width; + HEIGHT=height; + glViewport(0,0,(GLint)width,(GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(70.0,width/(float)height,0.1,30.0); + + glMatrixMode(GL_MODELVIEW); +} + +static void printhelp(void) +{ + glEnable(GL_BLEND); + glColor4f(0.0,0.0,0.0,0.5); + glRecti(40,40,600,440); + glDisable(GL_BLEND); + + glColor3f(1.0,0.0,0.0); + glRasterPos2i(300,420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"Help"); + + glRasterPos2i(60,390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"h - Toggle Help"); + + glRasterPos2i(60,360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"f - Toggle Fog"); + glRasterPos2i(60,330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"Arrow Keys - Rotate"); + glRasterPos2i(60,300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"a - Increase velocity"); + glRasterPos2i(60,270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"z - Decrease velocity"); + glRasterPos2i(60,240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"l - Increase rain length"); + glRasterPos2i(60,210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"k - Increase rain length"); +} + +static void drawrain(void) +{ + static int count=0; + static char frbuf[80]; + float fr; + + glEnable(GL_DEPTH_TEST); + + if(fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glDepthMask(GL_TRUE); + glClearColor(1.0,1.0,1.0,1.0); + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + calcposobs(); + gluLookAt(obs[0],obs[1],obs[2], + obs[0]+dir[0],obs[1]+dir[1],obs[2]+dir[2], + 0.0,1.0,0.0); + + glColor4f(1.0,1.0,1.0,1.0); + + glEnable(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D,groundid); + glBegin(GL_QUADS); + glTexCoord2fv(qt[0]); + glVertex3fv(q[0]); + glTexCoord2fv(qt[1]); + glVertex3fv(q[1]); + glTexCoord2fv(qt[2]); + glVertex3fv(q[2]); + glTexCoord2fv(qt[3]); + glVertex3fv(q[3]); + glEnd(); + + // Particle System + + glDisable(GL_TEXTURE_2D); + glShadeModel(GL_SMOOTH); + glEnable(GL_BLEND); + + ps->draw(); + ps->addTime(gettimerain()); + + glShadeModel(GL_FLAT); + + + if((count % FRAME)==0) { + fr=gettime(); + sprintf(frbuf,"Frame rate: %f",FRAME/fr); + } + + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5,639.5,-0.5,479.5,-1.0,1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0,0.0,0.0); + glRasterPos2i(10,10); + printstring(GLUT_BITMAP_HELVETICA_18,frbuf); + glRasterPos2i(350,470); + printstring(GLUT_BITMAP_HELVETICA_10,"Rain V1.0 Written by David Bucciarelli ([email protected])"); + + if(help) + printhelp(); + + reshape(WIDTH,HEIGHT); + glPopMatrix(); + + glutSwapBuffers(); + + count++; +} + + +static void special(int key, int x, int y) +{ + switch (key) { + case GLUT_KEY_LEFT: + alpha+=2.0; + break; + case GLUT_KEY_RIGHT: + alpha-=2.0; + break; + case GLUT_KEY_DOWN: + beta-=2.0; + break; + case GLUT_KEY_UP: + beta+=2.0; + break; + } +} + +static void key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + + case 'a': + v+=0.01; + break; + case 'z': + v-=0.01; + break; + + case 'l': + rainParticle::setLength(rainParticle::getLength()+0.025f); + break; + case 'k': + rainParticle::setLength(rainParticle::getLength()-0.025f); + break; + + case 'h': + help=(!help); + break; + case 'f': + fog=(!fog); + break; +#ifdef XMESA + case ' ': + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + fullscreen=(!fullscreen); + break; +#endif + } +} + +static void inittextures(void) +{ + GLubyte *img; + GLint width,height; + GLenum format; + GLenum gluerr; + + glGenTextures(1,&groundid); + glBindTexture(GL_TEXTURE_2D,groundid); + + if(!(img=LoadRGBImage("../images/s128.rgb",&width,&height,&format))){ + fprintf(stderr,"Error reading a texture.\n"); + exit(-1); + } + glPixelStorei(GL_UNPACK_ALIGNMENT,4); + if((gluerr=(GLenum)gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height,GL_RGB, + GL_UNSIGNED_BYTE, (GLvoid *)(img)))) { + fprintf(stderr,"GLULib%s\n",gluErrorString(gluerr)); + exit(-1); + } + + 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_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL); +} + +static void initparticle(void) +{ + ps=new particleSystem; + + rainParticle::setRainingArea(-7.0f,-0.2f,-7.0f,7.0f,8.0f,7.0f); + + for(int i=0;i<NUMPART;i++) { + rainParticle *p=new rainParticle; + p->randomHeight(); + + ps->addParticle((particle *)p); + } +} + +int main(int ac,char **av) +{ + fprintf(stderr,"Rain V1.0\nWritten by David Bucciarelli ([email protected])\n"); + + /* Default settings */ + + WIDTH=640; + HEIGHT=480; + + glutInitWindowPosition(0,0); + glutInitWindowSize(WIDTH,HEIGHT); + glutInit(&ac,av); + + glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE); + + if(!(win=glutCreateWindow("Rain"))) { + fprintf(stderr,"Error opening a window.\n"); + exit(-1); + } + + reshape(WIDTH,HEIGHT); + + inittextures(); + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE,GL_EXP); + glFogfv(GL_FOG_COLOR,fogcolor); + glFogf(GL_FOG_DENSITY,0.1); +#ifdef FX + glHint(GL_FOG_HINT,GL_NICEST); +#endif + + initparticle(); + + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutDisplayFunc(drawrain); + glutIdleFunc(drawrain); + glutReshapeFunc(reshape); + glutMainLoop(); + + return(0); +} diff --git a/progs/demos/ray.c b/progs/demos/ray.c new file mode 100644 index 00000000000..c2d8e4f545e --- /dev/null +++ b/progs/demos/ray.c @@ -0,0 +1,904 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <GL/glut.h> + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +static int WIDTH = 640; +static int HEIGHT = 480; + +static GLint T0 = 0; +static GLint Frames = 0; + +#define BASESIZE 7.5f +#define SPHERE_RADIUS 0.75f + +#define TEX_CHECK_WIDTH 256 +#define TEX_CHECK_HEIGHT 256 +#define TEX_CHECK_SLOT_SIZE (TEX_CHECK_HEIGHT/16) +#define TEX_CHECK_NUMSLOT (TEX_CHECK_HEIGHT/TEX_CHECK_SLOT_SIZE) + +#define TEX_REFLECT_WIDTH 256 +#define TEX_REFLECT_HEIGHT 256 +#define TEX_REFLECT_SLOT_SIZE (TEX_REFLECT_HEIGHT/16) +#define TEX_REFLECT_NUMSLOT (TEX_REFLECT_HEIGHT/TEX_REFLECT_SLOT_SIZE) + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +#define EPSILON 0.0001 + +#define clamp255(a) ( (a)<(0.0f) ? (0.0f) : ((a)>(255.0f) ? (255.0f) : (a)) ) + +#ifndef fabs +#define fabs(x) ((x)<0.0f?-(x):(x)) +#endif + +#define vequ(a,b) { (a)[0]=(b)[0]; (a)[1]=(b)[1]; (a)[2]=(b)[2]; } +#define vsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; (a)[1]=(b)[1]-(c)[1]; (a)[2]=(b)[2]-(c)[2]; } +#define dprod(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) +#define vnormalize(a,b) { \ + register float m_norm; \ + m_norm=sqrt((double)dprod((a),(a))); \ + (a)[0] /=m_norm; \ + (a)[1] /=m_norm; \ + (a)[2] /=m_norm; } + +static GLubyte checkmap[TEX_CHECK_HEIGHT][TEX_CHECK_WIDTH][3]; +static GLuint checkid; +static int checkmap_currentslot = 0; + +static GLubyte reflectmap[TEX_REFLECT_HEIGHT][TEX_REFLECT_WIDTH][3]; +static GLuint reflectid; +static int reflectmap_currentslot = 0; + +static GLuint lightdlist; +static GLuint objdlist; + +static float lightpos[3] = { 2.1, 2.1, 2.8 }; +static float objpos[3] = { 0.0, 0.0, 1.0 }; + +static float sphere_pos[TEX_CHECK_HEIGHT][TEX_REFLECT_WIDTH][3]; + +static int win = 0; + +static float fogcolor[4] = { 0.05, 0.05, 0.05, 1.0 }; + +static float obs[3] = { 7.0, 0.0, 2.0 }; +static float dir[3]; +static float v = 0.0; +static float alpha = -90.0; +static float beta = 90.0; + +static int fog = 1; +static int bfcull = 1; +static int poutline = 0; +static int help = 1; +static int showcheckmap = 1; +static int showreflectmap = 1; +static int joyavailable = 0; +static int joyactive = 0; + +static void +calcposobs(void) +{ + dir[0] = sin(alpha * M_PI / 180.0); + dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[2] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + obs[0] += v * dir[0]; + obs[1] += v * dir[1]; + obs[2] += v * dir[2]; +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_LEFT: + alpha -= 2.0; + break; + case GLUT_KEY_RIGHT: + alpha += 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: + exit(0); + break; + + case 's': + lightpos[1] -= 0.1; + break; + case 'd': + lightpos[1] += 0.1; + break; + case 'e': + lightpos[0] -= 0.1; + break; + case 'x': + lightpos[0] += 0.1; + break; + case 'w': + lightpos[2] -= 0.1; + break; + case 'r': + lightpos[2] += 0.1; + break; + + case 'j': + objpos[1] -= 0.1; + break; + case 'k': + objpos[1] += 0.1; + break; + case 'i': + objpos[0] -= 0.1; + break; + case 'm': + objpos[0] += 0.1; + break; + case 'u': + objpos[2] -= 0.1; + break; + case 'o': + objpos[2] += 0.1; + break; + + case 'a': + v += 0.005; + break; + case 'z': + v -= 0.005; + break; + + case 'g': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + + case '1': + showcheckmap = (!showcheckmap); + break; + case '2': + showreflectmap = (!showreflectmap); + break; + + case 'b': + if (bfcull) { + glDisable(GL_CULL_FACE); + bfcull = 0; + } + else { + glEnable(GL_CULL_FACE); + bfcull = 1; + } + break; + case 'p': + if (poutline) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + poutline = 0; + } + else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + poutline = 1; + } + break; +#ifdef XMESA + case ' ': + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + fullscreen = (!fullscreen); + break; +#endif + } +} + +static void +reshape(int w, int h) +{ + WIDTH = w; + HEIGHT = h; + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, w / (float) h, 0.8, 40.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +printhelp(void) +{ + glEnable(GL_BLEND); + glColor4f(0.5, 0.5, 0.5, 0.5); + glRecti(40, 40, 600, 440); + glDisable(GL_BLEND); + + glColor3f(0.0, 0.0, 1.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_HELVETICA_18, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_HELVETICA_12, "h - Toggle Help"); + glRasterPos2i(60, 370); + printstring(GLUT_BITMAP_HELVETICA_12, "f - Toggle Fog"); + glRasterPos2i(60, 350); + printstring(GLUT_BITMAP_HELVETICA_12, "b - Toggle Back face culling"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_HELVETICA_12, "p - Toggle Wire frame"); + glRasterPos2i(60, 310); + printstring(GLUT_BITMAP_HELVETICA_12, "Arrow Keys - Rotate"); + glRasterPos2i(60, 290); + printstring(GLUT_BITMAP_HELVETICA_12, "a - Increase velocity"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_HELVETICA_12, "z - Decrease velocity"); + + glRasterPos2i(60, 250); + if (joyavailable) + printstring(GLUT_BITMAP_HELVETICA_12, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_HELVETICA_12, + "(No Joystick control available)"); + + glRasterPos2i(60, 230); + printstring(GLUT_BITMAP_HELVETICA_12, + "To move the light source: s - left, d - right, e - far, x - near, w - down r - up"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_HELVETICA_12, + "To move the mirror sphere: j - left, k - right, i - far, m - near, u - down o - up"); + + glRasterPos2i(60, 190); + printstring(GLUT_BITMAP_HELVETICA_12, + "1 - Toggle the plane texture map window"); + + glRasterPos2i(60, 170); + printstring(GLUT_BITMAP_HELVETICA_12, + "2 - Toggle the sphere texture map window"); +} + +static GLboolean +seelight(float p[3], float dir[3]) +{ + float c[3], b, a, d, t, dist[3]; + + vsub(c, p, objpos); + b = -dprod(c, dir); + a = dprod(c, c) - SPHERE_RADIUS * SPHERE_RADIUS; + + if ((d = b * b - a) < 0.0 || (b < 0.0 && a > 0.0)) + return GL_FALSE; + + d = sqrt(d); + + t = b - d; + + if (t < EPSILON) { + t = b + d; + if (t < EPSILON) + return GL_FALSE; + } + + vsub(dist, lightpos, p); + if (dprod(dist, dist) < t * t) + return GL_FALSE; + + return GL_TRUE; +} + +static int +colorcheckmap(float ppos[3], float c[3]) +{ + static float norm[3] = { 0.0f, 0.0f, 1.0f }; + float ldir[3], vdir[3], h[3], dfact, kfact, r, g, b; + int x, y; + + x = (int) ((ppos[0] + BASESIZE / 2) * (10.0f / BASESIZE)); + if ((x < 0) || (x > 10)) + return GL_FALSE; + + y = (int) ((ppos[1] + BASESIZE / 2) * (10.0f / BASESIZE)); + if ((y < 0) || (y > 10)) + return GL_FALSE; + + r = 255.0f; + if (y & 1) { + if (x & 1) + g = 255.0f; + else + g = 0.0f; + } + else { + if (x & 1) + g = 0.0f; + else + g = 255.0f; + } + b = 0.0f; + + vsub(ldir, lightpos, ppos); + vnormalize(ldir, ldir); + + if (seelight(ppos, ldir)) { + c[0] = r * 0.05f; + c[1] = g * 0.05f; + c[2] = b * 0.05f; + + return GL_TRUE; + } + + dfact = dprod(ldir, norm); + if (dfact < 0.0f) + dfact = 0.0f; + + vsub(vdir, obs, ppos); + vnormalize(vdir, vdir); + h[0] = 0.5f * (vdir[0] + ldir[0]); + h[1] = 0.5f * (vdir[1] + ldir[1]); + h[2] = 0.5f * (vdir[2] + ldir[2]); + kfact = dprod(h, norm); + kfact = pow(kfact, 6.0) * 7.0 * 255.0; + + r = r * dfact + kfact; + g = g * dfact + kfact; + b = b * dfact + kfact; + + c[0] = clamp255(r); + c[1] = clamp255(g); + c[2] = clamp255(b); + + return GL_TRUE; +} + +static void +updatecheckmap(int slot) +{ + float c[3], ppos[3]; + int x, y; + + glBindTexture(GL_TEXTURE_2D, checkid); + + ppos[2] = 0.0f; + for (y = slot * TEX_CHECK_SLOT_SIZE; y < (slot + 1) * TEX_CHECK_SLOT_SIZE; + y++) { + ppos[1] = (y / (float) TEX_CHECK_HEIGHT) * BASESIZE - BASESIZE / 2; + + for (x = 0; x < TEX_CHECK_WIDTH; x++) { + ppos[0] = (x / (float) TEX_CHECK_WIDTH) * BASESIZE - BASESIZE / 2; + + colorcheckmap(ppos, c); + checkmap[y][x][0] = (GLubyte) c[0]; + checkmap[y][x][1] = (GLubyte) c[1]; + checkmap[y][x][2] = (GLubyte) c[2]; + } + } + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, slot * TEX_CHECK_SLOT_SIZE, + TEX_CHECK_WIDTH, TEX_CHECK_SLOT_SIZE, GL_RGB, + GL_UNSIGNED_BYTE, + &checkmap[slot * TEX_CHECK_SLOT_SIZE][0][0]); + +} + +static void +updatereflectmap(int slot) +{ + float rf, r, g, b, t, dfact, kfact, rdir[3]; + float rcol[3], ppos[3], norm[3], ldir[3], h[3], vdir[3], planepos[3]; + int x, y; + + glBindTexture(GL_TEXTURE_2D, reflectid); + + for (y = slot * TEX_REFLECT_SLOT_SIZE; + y < (slot + 1) * TEX_REFLECT_SLOT_SIZE; y++) + for (x = 0; x < TEX_REFLECT_WIDTH; x++) { + ppos[0] = sphere_pos[y][x][0] + objpos[0]; + ppos[1] = sphere_pos[y][x][1] + objpos[1]; + ppos[2] = sphere_pos[y][x][2] + objpos[2]; + + vsub(norm, ppos, objpos); + vnormalize(norm, norm); + + vsub(ldir, lightpos, ppos); + vnormalize(ldir, ldir); + vsub(vdir, obs, ppos); + vnormalize(vdir, vdir); + + rf = 2.0f * dprod(norm, vdir); + if (rf > EPSILON) { + rdir[0] = rf * norm[0] - vdir[0]; + rdir[1] = rf * norm[1] - vdir[1]; + rdir[2] = rf * norm[2] - vdir[2]; + + t = -objpos[2] / rdir[2]; + + if (t > EPSILON) { + planepos[0] = objpos[0] + t * rdir[0]; + planepos[1] = objpos[1] + t * rdir[1]; + planepos[2] = 0.0f; + + if (!colorcheckmap(planepos, rcol)) + rcol[0] = rcol[1] = rcol[2] = 0.0f; + } + else + rcol[0] = rcol[1] = rcol[2] = 0.0f; + } + else + rcol[0] = rcol[1] = rcol[2] = 0.0f; + + dfact = 0.1f * dprod(ldir, norm); + + if (dfact < 0.0f) { + dfact = 0.0f; + kfact = 0.0f; + } + else { + h[0] = 0.5f * (vdir[0] + ldir[0]); + h[1] = 0.5f * (vdir[1] + ldir[1]); + h[2] = 0.5f * (vdir[2] + ldir[2]); + kfact = dprod(h, norm); + kfact = pow(kfact, 4.0); + if (kfact < 1.0e-10) + kfact = 0.0; + } + + r = dfact + kfact; + g = dfact + kfact; + b = dfact + kfact; + + r *= 255.0f; + g *= 255.0f; + b *= 255.0f; + + r += rcol[0]; + g += rcol[1]; + b += rcol[2]; + + r = clamp255(r); + g = clamp255(g); + b = clamp255(b); + + reflectmap[y][x][0] = (GLubyte) r; + reflectmap[y][x][1] = (GLubyte) g; + reflectmap[y][x][2] = (GLubyte) b; + } + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, slot * TEX_REFLECT_SLOT_SIZE, + TEX_REFLECT_WIDTH, TEX_REFLECT_SLOT_SIZE, GL_RGB, + GL_UNSIGNED_BYTE, + &reflectmap[slot * TEX_REFLECT_SLOT_SIZE][0][0]); +} + +static void +drawbase(void) +{ + glColor3f(0.0, 0.0, 0.0); + glBindTexture(GL_TEXTURE_2D, checkid); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-BASESIZE / 2.0f, -BASESIZE / 2.0f, 0.0f); + + glTexCoord2f(1.0f, 0.0f); + glVertex3f(BASESIZE / 2.0f, -BASESIZE / 2.0f, 0.0f); + + glTexCoord2f(1.0f, 1.0f); + glVertex3f(BASESIZE / 2.0f, BASESIZE / 2.0f, 0.0f); + + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-BASESIZE / 2.0f, BASESIZE / 2.0f, 0.0f); + + glEnd(); +} + +static void +drawobj(void) +{ + glColor3f(0.0, 0.0, 0.0); + glBindTexture(GL_TEXTURE_2D, reflectid); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glPushMatrix(); + glTranslatef(objpos[0], objpos[1], objpos[2]); + glCallList(objdlist); + glPopMatrix(); +} + +static void +dojoy(void) +{ +#ifdef WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha -= + 2.5 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.5 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.005; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.005; + } + } + else + joyavailable = 0; +#endif +} + +static void +updatemaps(void) +{ + updatecheckmap(checkmap_currentslot); + checkmap_currentslot = (checkmap_currentslot + 1) % TEX_CHECK_NUMSLOT; + + updatereflectmap(reflectmap_currentslot); + reflectmap_currentslot = + (reflectmap_currentslot + 1) % TEX_REFLECT_NUMSLOT; +} + +static void +draw(void) +{ + static char frbuf[80] = ""; + + dojoy(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glPushMatrix(); + calcposobs(); + + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 0.0, 1.0); + + drawbase(); + drawobj(); + + glColor3f(1.0, 1.0, 1.0); + glDisable(GL_TEXTURE_2D); + + glPushMatrix(); + glTranslatef(lightpos[0], lightpos[1], lightpos[2]); + glCallList(lightdlist); + glPopMatrix(); + + glPopMatrix(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glColor3f(0.0f, 0.3f, 1.0f); + + if (showcheckmap) { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, checkid); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin(GL_QUADS); + glTexCoord2f(1.0f, 0.0f); + glVertex2i(10, 30); + glTexCoord2f(1.0f, 1.0f); + glVertex2i(10 + 90, 30); + glTexCoord2f(0.0f, 1.0f); + glVertex2i(10 + 90, 30 + 90); + glTexCoord2f(0.0f, 0.0f); + glVertex2i(10, 30 + 90); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glBegin(GL_LINE_LOOP); + glVertex2i(10, 30); + glVertex2i(10 + 90, 30); + glVertex2i(10 + 90, 30 + 90); + glVertex2i(10, 30 + 90); + glEnd(); + glRasterPos2i(105, 65); + printstring(GLUT_BITMAP_HELVETICA_18, "Plane Texture Map"); + } + + if (showreflectmap) { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, reflectid); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin(GL_QUADS); + glTexCoord2f(1.0f, 0.0f); + glVertex2i(540, 30); + glTexCoord2f(1.0f, 1.0f); + glVertex2i(540 + 90, 30); + glTexCoord2f(0.0f, 1.0f); + glVertex2i(540 + 90, 30 + 90); + glTexCoord2f(0.0f, 0.0f); + glVertex2i(540, 30 + 90); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glBegin(GL_LINE_LOOP); + glVertex2i(540, 30); + glVertex2i(540 + 90, 30); + glVertex2i(540 + 90, 30 + 90); + glVertex2i(540, 30 + 90); + glEnd(); + glRasterPos2i(360, 65); + printstring(GLUT_BITMAP_HELVETICA_18, "Sphere Texture Map"); + } + + glDisable(GL_TEXTURE_2D); + + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(360, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "Ray V1.0 Written by David Bucciarelli ([email protected])"); + + if (help) + printhelp(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + + updatemaps(); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + +static void +inittextures(void) +{ + int y; + + glGenTextures(1, &checkid); + glBindTexture(GL_TEXTURE_2D, checkid); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, 3, TEX_CHECK_WIDTH, TEX_CHECK_HEIGHT, + 0, GL_RGB, GL_UNSIGNED_BYTE, checkmap); + + 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_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + for (y = 0; y < TEX_CHECK_NUMSLOT; y++) + updatecheckmap(y); + + + + glGenTextures(1, &reflectid); + glBindTexture(GL_TEXTURE_2D, reflectid); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, 3, TEX_REFLECT_WIDTH, TEX_REFLECT_HEIGHT, + 0, GL_RGB, GL_UNSIGNED_BYTE, reflectmap); + + 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_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + for (y = 0; y < TEX_REFLECT_NUMSLOT; y++) + updatereflectmap(y); + + +} + +static void +initspherepos(void) +{ + float alpha, beta, sa, ca, sb, cb; + int x, y; + + for (y = 0; y < TEX_REFLECT_HEIGHT; y++) { + beta = M_PI - y * (M_PI / TEX_REFLECT_HEIGHT); + + for (x = 0; x < TEX_REFLECT_WIDTH; x++) { + alpha = -x * (2.0f * M_PI / TEX_REFLECT_WIDTH); + + sa = sin(alpha); + ca = cos(alpha); + + sb = sin(beta); + cb = cos(beta); + + sphere_pos[y][x][0] = SPHERE_RADIUS * sa * sb; + sphere_pos[y][x][1] = SPHERE_RADIUS * ca * sb; + sphere_pos[y][x][2] = SPHERE_RADIUS * cb; + } + } +} + +static void +initdlists(void) +{ + GLUquadricObj *obj; + + obj = gluNewQuadric(); + + lightdlist = glGenLists(1); + glNewList(lightdlist, GL_COMPILE); + gluQuadricDrawStyle(obj, GLU_FILL); + gluQuadricNormals(obj, GLU_NONE); + gluQuadricTexture(obj, GL_TRUE); + gluSphere(obj, 0.25f, 6, 6); + glEndList(); + + objdlist = glGenLists(1); + glNewList(objdlist, GL_COMPILE); + gluQuadricDrawStyle(obj, GLU_FILL); + gluQuadricNormals(obj, GLU_NONE); + gluQuadricTexture(obj, GL_TRUE); + gluSphere(obj, SPHERE_RADIUS, 16, 16); + glEndList(); +} + +int +main(int ac, char **av) +{ + fprintf(stderr, + "Ray V1.0\nWritten by David Bucciarelli ([email protected])\n"); + + /* + if(!SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)) { + fprintf(stderr,"Error setting the process class.\n"); + return 0; + } + + if(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL)) { + fprintf(stderr,"Error setting the process priority.\n"); + return 0; + } + */ + + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + if (!(win = glutCreateWindow("Ray"))) { + fprintf(stderr, "Error, couldn't open window\n"); + return -1; + } + + reshape(WIDTH, HEIGHT); + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogfv(GL_FOG_COLOR, fogcolor); + + glFogf(GL_FOG_DENSITY, 0.01); +#ifdef FX + glHint(GL_FOG_HINT, GL_NICEST); +#endif + + calcposobs(); + + initspherepos(); + + inittextures(); + initdlists(); + + glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); + + glutReshapeFunc(reshape); + glutDisplayFunc(draw); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutIdleFunc(draw); + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c new file mode 100644 index 00000000000..75ba45c1e5f --- /dev/null +++ b/progs/demos/readpix.c @@ -0,0 +1,344 @@ + +/* + * glReadPixels and glCopyPixels test + * + * Brian Paul March 1, 2000 This file is in the public domain. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define IMAGE_FILE "../images/girl.rgb" + +static int ImgWidth, ImgHeight; +static GLenum ImgFormat; +static GLubyte *Image = NULL; + +static int APosX, APosY; /* simple drawpixels */ +static int BPosX, BPosY; /* read/draw pixels */ +static int CPosX, CPosY; /* copypixels */ + +static GLboolean DrawFront = GL_FALSE; +static GLboolean ScaleAndBias = GL_FALSE; +static GLboolean Benchmark = GL_FALSE; +static GLubyte *TempImage = NULL; + +#if 0 +#define ReadFormat ImgFormat +#define ReadType GL_UNSIGNED_BYTE +#endif +#if 1 +static GLenum ReadFormat = GL_RGBA; +static GLenum ReadType = GL_UNSIGNED_BYTE; +#endif +#if 0 +static GLenum ReadFormat = GL_RGB; +static GLenum ReadType = GL_UNSIGNED_BYTE; +#endif +#if 0 +static GLenum ReadFormat = GL_RGB; +static GLenum ReadType = GL_UNSIGNED_SHORT_5_6_5; +#endif +#if 0 +static GLenum ReadFormat = GL_RGBA; +static GLenum ReadType = GL_UNSIGNED_SHORT_1_5_5_5_REV; +#endif +#if 0 +static GLenum ReadFormat = GL_BGRA; +static GLenum ReadType = GL_UNSIGNED_SHORT_5_5_5_1; +#endif +#if 0 +static GLenum ReadFormat = GL_BGRA; +static GLenum ReadType = GL_UNSIGNED_SHORT_4_4_4_4_REV; +#endif + + +static void +Reset( void ) +{ + APosX = 5; APosY = 20; + BPosX = APosX + ImgWidth + 5; BPosY = 20; + CPosX = BPosX + ImgWidth + 5; CPosY = 20; +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +SetupPixelTransfer(GLboolean invert) +{ + if (invert) { + glPixelTransferf(GL_RED_SCALE, -1.0); + glPixelTransferf(GL_RED_BIAS, 1.0); + glPixelTransferf(GL_GREEN_SCALE, -1.0); + glPixelTransferf(GL_GREEN_BIAS, 1.0); + glPixelTransferf(GL_BLUE_SCALE, -1.0); + glPixelTransferf(GL_BLUE_BIAS, 1.0); + } + else { + glPixelTransferf(GL_RED_SCALE, 1.0); + glPixelTransferf(GL_RED_BIAS, 0.0); + glPixelTransferf(GL_GREEN_SCALE, 1.0); + glPixelTransferf(GL_GREEN_BIAS, 0.0); + glPixelTransferf(GL_BLUE_SCALE, 1.0); + glPixelTransferf(GL_BLUE_BIAS, 0.0); + } +} + + +/** + * Exercise Pixel Pack parameters by reading the image in four pieces. + */ +static void +ComplexReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, GLvoid *pixels) +{ + const GLsizei width0 = width / 2; + const GLsizei width1 = width - width0; + const GLsizei height0 = height / 2; + const GLsizei height1 = height - height0; + + glPixelStorei(GL_PACK_ROW_LENGTH, width); + + /* lower-left quadrant */ + glReadPixels(x, y, width0, height0, format, type, pixels); + + /* lower-right quadrant */ + glPixelStorei(GL_PACK_SKIP_PIXELS, width0); + glReadPixels(x + width0, y, width1, height0, format, type, pixels); + + /* upper-left quadrant */ + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + glPixelStorei(GL_PACK_SKIP_ROWS, height0); + glReadPixels(x, y + height0, width0, height1, format, type, pixels); + + /* upper-right quadrant */ + glPixelStorei(GL_PACK_SKIP_PIXELS, width0); + glPixelStorei(GL_PACK_SKIP_ROWS, height0); + glReadPixels(x + width0, y + height0, width1, height1, format, type, pixels); + + /* restore defaults */ + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + glPixelStorei(GL_PACK_SKIP_ROWS, 0); + glPixelStorei(GL_PACK_ROW_LENGTH, ImgWidth); +} + + + +static void +Display( void ) +{ + glClearColor(.3, .3, .3, 1); + glClear( GL_COLOR_BUFFER_BIT ); + + glRasterPos2i(5, ImgHeight+25); + PrintString("f = toggle front/back s = toggle scale/bias b = benchmark"); + + /* draw original image */ + glRasterPos2i(APosX, 5); + PrintString("Original"); + glRasterPos2i(APosX, APosY); + glEnable(GL_DITHER); + SetupPixelTransfer(GL_FALSE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + + /* might try alignment=4 here for testing */ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + /* do readpixels, drawpixels */ + glRasterPos2i(BPosX, 5); + PrintString("Read/DrawPixels"); + SetupPixelTransfer(ScaleAndBias); + if (Benchmark) { + GLint reads = 0; + GLint endTime; + GLint startTime = glutGet(GLUT_ELAPSED_TIME); + GLdouble seconds, pixelsPerSecond; + printf("Benchmarking...\n"); + do { + glReadPixels(APosX, APosY, ImgWidth, ImgHeight, + ReadFormat, ReadType, TempImage); + reads++; + endTime = glutGet(GLUT_ELAPSED_TIME); + } while (endTime - startTime < 4000); /* 4 seconds */ + seconds = (double) (endTime - startTime) / 1000.0; + pixelsPerSecond = reads * ImgWidth * ImgHeight / seconds; + printf("Result: %d reads in %f seconds = %f pixels/sec\n", + reads, seconds, pixelsPerSecond); + Benchmark = GL_FALSE; + } + else { + /* clear the temporary image to white (helpful for debugging */ + memset(TempImage, 255, ImgWidth * ImgHeight * 4); +#if 1 + glReadPixels(APosX, APosY, ImgWidth, ImgHeight, + ReadFormat, ReadType, TempImage); + (void) ComplexReadPixels; +#else + /* you might use this when debugging */ + ComplexReadPixels(APosX, APosY, ImgWidth, ImgHeight, + ReadFormat, ReadType, TempImage); +#endif + } + glRasterPos2i(BPosX, BPosY); + glDisable(GL_DITHER); + SetupPixelTransfer(GL_FALSE); + glDrawPixels(ImgWidth, ImgHeight, ReadFormat, ReadType, TempImage); + + /* do copypixels */ + glRasterPos2i(CPosX, 5); + PrintString("CopyPixels"); + glRasterPos2i(CPosX, CPosY); + glDisable(GL_DITHER); + SetupPixelTransfer(ScaleAndBias); + glCopyPixels(APosX, APosY, ImgWidth, ImgHeight, GL_COLOR); + + if (!DrawFront) + glutSwapBuffers(); + else + glFinish(); +} + + +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(); +} + + +static void +Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 'b': + Benchmark = GL_TRUE; + break; + case 's': + ScaleAndBias = !ScaleAndBias; + break; + case 'f': + DrawFront = !DrawFront; + if (DrawFront) { + glDrawBuffer(GL_FRONT); + glReadBuffer(GL_FRONT); + } + else { + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + } + printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +Init( GLboolean ciMode ) +{ + GLboolean have_read_format = GL_FALSE; + + 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 = (GLubyte *) malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i<ImgWidth*ImgHeight; i++) { + int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; + indexImage[i] = gray / 3; + } + free(Image); + Image = indexImage; + ImgFormat = GL_COLOR_INDEX; + + for (i=0;i<255;i++) { + float g = i / 255.0; + glutSetColor(i, g, g, g); + } + } + +#ifdef GL_OES_read_format + if ( glutExtensionSupported( "GL_OES_read_format" ) ) { + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, (GLint *) &ReadType); + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, (GLint *) &ReadFormat); + + have_read_format = GL_TRUE; + } +#endif + + printf( "GL_OES_read_format %ssupported. " + "Using type / format = 0x%04x / 0x%04x\n", + (have_read_format) ? "" : "not ", + ReadType, ReadFormat ); + + printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); + glPixelStorei(GL_PACK_ROW_LENGTH, ImgWidth); + + Reset(); + + /* allocate an extra 1KB in case we're tinkering with pack alignment */ + TempImage = (GLubyte *) malloc(ImgWidth * ImgHeight * 4 * sizeof(GLubyte) + + 1000); + assert(TempImage); +} + + +int +main( int argc, char *argv[] ) +{ + GLboolean ciMode = GL_FALSE; + if (argc > 1 && strcmp(argv[1], "-ci")==0) { + ciMode = GL_TRUE; + } + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 750, 250 ); + if (ciMode) + glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE ); + else + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow(argv[0]); + Init(ciMode); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/readtex.c b/progs/demos/readtex.c new file mode 100644 index 00000000000..37d5fcd0d3a --- /dev/null +++ b/progs/demos/readtex.c @@ -0,0 +1,454 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + + + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + 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->rowStart) + free(raw->rowStart); + if (raw->rowSize) + free(raw->rowSize); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + 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 w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + 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; +} + +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) + + +static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes, + const GLubyte *src, + GLushort *dest) +{ + GLint i, j; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + const GLfloat r = (src[0]) / 255.0; + const GLfloat g = (src[1]) / 255.0; + const GLfloat b = (src[2]) / 255.0; + GLfloat y, cr, cb; + GLint iy, icr, icb; + + y = r * 65.481 + g * 128.553 + b * 24.966 + 16; + cb = r * -37.797 + g * -74.203 + b * 112.0 + 128; + cr = r * 112.0 + g * -93.786 + b * -18.214 + 128; + /*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/ + iy = (GLint) CLAMP(y, 0, 254); + icb = (GLint) CLAMP(cb, 0, 254); + icr = (GLint) CLAMP(cr, 0, 254); + + if (j & 1) { + /* odd */ + *dest = (iy << 8) | icr; + } + else { + /* even */ + *dest = (iy << 8) | icb; + } + dest++; + src += texel_bytes; + } + } +} + + +/* + * Load an SGI .rgb file and return a pointer to the image data, converted + * to 422 yuv. + * + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * Return: pointer to image data or NULL if error + */ +GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height ) +{ + TK_RGBImageRec *image; + GLushort *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components != 3 && image->components !=4 ) { + /* not implemented */ + fprintf(stderr, + "Error in LoadYUVImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 ); + + if (buffer) + ConvertRGBtoYUV( image->sizeX, + image->sizeY, + image->components, + image->data, + buffer ); + + + FreeImage(image); + return buffer; +} + diff --git a/progs/demos/readtex.h b/progs/demos/readtex.h new file mode 100644 index 00000000000..6c9a3828d38 --- /dev/null +++ b/progs/demos/readtex.h @@ -0,0 +1,26 @@ +/* readtex.h */ + +#ifndef READTEX_H +#define READTEX_H + + +#include <GL/gl.h> + + +extern GLboolean +LoadRGBMipmaps( const char *imageFile, GLint intFormat ); + + +extern GLboolean +LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ); + + +extern GLubyte * +LoadRGBImage( const char *imageFile, + GLint *width, GLint *height, GLenum *format ); + +extern GLushort * +LoadYUVImage( const char *imageFile, GLint *width, GLint *height ); + +#endif diff --git a/progs/demos/reflect.c b/progs/demos/reflect.c new file mode 100644 index 00000000000..0bec0663bc2 --- /dev/null +++ b/progs/demos/reflect.c @@ -0,0 +1,590 @@ +/* + * Demo of a reflective, texture-mapped surface with OpenGL. + * Brian Paul August 14, 1995 This file is in the public domain. + * + * Hardware texture mapping is highly recommended! + * + * The basic steps are: + * 1. Render the reflective object (a polygon) from the normal viewpoint, + * setting the stencil planes = 1. + * 2. Render the scene from a special viewpoint: the viewpoint which + * is on the opposite side of the reflective plane. Only draw where + * stencil = 1. This draws the objects in the reflective surface. + * 3. Render the scene from the original viewpoint. This draws the + * objects in the normal fashion. Use blending when drawing + * the reflective, textured surface. + * + * This is a very crude demo. It could be much better. + */ + +/* + * Authors: + * Brian Paul + * Dirk Reiners ([email protected]) made some modifications to this code. + * Mark Kilgard (April 1997) + * Brian Paul (April 2000 - added keyboard d/s options) + * Brian Paul (August 2005 - added multi window feature) + */ + + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include "GL/glut.h" +#include "showbuffer.h" +#include "readtex.h" + + +#define DEG2RAD (3.14159/180.0) +#define TABLE_TEXTURE "../images/tile.rgb" +#define MAX_OBJECTS 2 +#define INIT_WIDTH 400 +#define INIT_HEIGHT 300 + +#ifdef _WIN32 +#undef CreateWindowA +#endif + +struct window { + int id; /* returned by glutCreateWindow() */ + int width, height; + GLboolean anim; + GLfloat xrot, yrot; + GLfloat spin; + GLenum showBuffer; + GLenum drawBuffer; + GLuint table_list; + GLuint objects_list[MAX_OBJECTS]; + double t0; + struct window *next; +}; + + +static struct window *FirstWindow = NULL; + + +static void +CreateWindow(void); + + +static struct window * +CurrentWindow(void) +{ + int id = glutGetWindow(); + struct window *w; + for (w = FirstWindow; w; w = w->next) { + if (w->id == id) + return w; + } + return NULL; +} + + +static GLboolean +AnyAnimating(void) +{ + struct window *w; + for (w = FirstWindow; w; w = w->next) { + if (w->anim) + return 1; + } + return 0; +} + + +static void +KillWindow(struct window *w) +{ + struct window *win, *prev = NULL; + for (win = FirstWindow; win; win = win->next) { + if (win == w) { + if (prev) { + prev->next = win->next; + } + else { + FirstWindow = win->next; + } + glutDestroyWindow(win->id); + win->next = NULL; + free(win); + return; + } + prev = win; + } +} + + +static void +KillAllWindows(void) +{ + while (FirstWindow) + KillWindow(FirstWindow); +} + + +static GLuint +MakeTable(void) +{ + static GLfloat table_mat[] = { 1.0, 1.0, 1.0, 0.6 }; + static GLfloat gray[] = { 0.4, 0.4, 0.4, 1.0 }; + GLuint table_list; + + 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(); + return table_list; +} + + +static void +MakeObjects(GLuint *objects_list) +{ + 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(); + + gluDeleteQuadric(q); +} + + +static void +InitWindow(struct window *w) +{ + GLint imgWidth, imgHeight; + GLenum imgFormat; + GLubyte *image = NULL; + + w->table_list = MakeTable(); + MakeObjects(w->objects_list); + + 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); + free(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 ); + + glShadeModel( GL_FLAT ); + + glEnable( GL_LIGHT0 ); + glEnable( GL_LIGHTING ); + + glClearColor( 0.5, 0.5, 0.9, 0.0 ); + + glEnable( GL_NORMALIZE ); +} + + +static void +Reshape(int width, int height) +{ + struct window *w = CurrentWindow(); + GLfloat yAspect = 2.5; + GLfloat xAspect = yAspect * (float) width / (float) height; + w->width = width; + w->height = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -xAspect, xAspect, -yAspect, yAspect, 10.0, 30.0 ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +DrawObjects(struct window *w, 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( w->spin, 1.0, 0.5, 0.0 ); + glRotatef( 0.5*w->spin, 0.0, 0.5, 1.0 ); + glCallList( w->objects_list[0] ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*w->spin) ), 0.0 ); + glRotatef( 0.5*w->spin, 0.0, 0.5, 1.0 ); + glRotatef( w->spin, 1.0, 0.5, 0.0 ); + glScalef( 0.5, 0.5, 0.5 ); + glCallList( w->objects_list[1] ); + glPopMatrix(); +#ifndef USE_ZBUFFER + } + else { + glPushMatrix(); + glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*w->spin) ), 0.0 ); + glRotatef( 0.5*w->spin, 0.0, 0.5, 1.0 ); + glRotatef( w->spin, 1.0, 0.5, 0.0 ); + glScalef( 0.5, 0.5, 0.5 ); + glCallList( w->objects_list[1] ); + glPopMatrix(); + + glPushMatrix(); + glTranslatef( 1.0, 1.5, 0.0 ); + glRotatef( w->spin, 1.0, 0.5, 0.0 ); + glRotatef( 0.5*w->spin, 0.0, 0.5, 1.0 ); + glCallList( w->objects_list[0] ); + glPopMatrix(); + } +#endif +} + + +static void +DrawTable(struct window *w) +{ + glCallList(w->table_list); +} + + +static void +DrawWindow(void) +{ + struct window *w = CurrentWindow(); + static GLfloat light_pos[] = { 0.0, 20.0, 0.0, 1.0 }; + GLfloat dist = 20.0; + GLfloat eyex, eyey, eyez; + + if (w->drawBuffer == GL_NONE) { + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + } + else { + glDrawBuffer(w->drawBuffer); + glReadBuffer(w->drawBuffer); + } + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + if (w->drawBuffer == GL_NONE) { + glDrawBuffer(GL_NONE); + } + + eyex = dist * cos(w->yrot * DEG2RAD) * cos(w->xrot * DEG2RAD); + eyez = dist * sin(w->yrot * DEG2RAD) * cos(w->xrot * DEG2RAD); + eyey = dist * sin(w->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 */ + glDisable( GL_DEPTH_TEST ); + glEnable( GL_STENCIL_TEST ); + glStencilFunc( GL_ALWAYS, 1, 0xffffffff ); + glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE ); + glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); + DrawTable(w); + glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); + + glEnable( GL_DEPTH_TEST ); + + /* 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); + + DrawObjects(w, 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 ); + + glEnable( GL_TEXTURE_2D ); + DrawTable(w); + glDisable( GL_TEXTURE_2D ); + glDisable( GL_BLEND ); + + /* view from top */ + glPushMatrix(); + + DrawObjects(w, eyex, eyey, eyez); + + glPopMatrix(); + + glPopMatrix(); + + if (w->showBuffer == GL_DEPTH) { + ShowDepthBuffer(w->width, w->height, 1.0, 0.0); + } + else if (w->showBuffer == GL_STENCIL) { + ShowStencilBuffer(w->width, w->height, 255.0, 0.0); + } + else if (w->showBuffer == GL_ALPHA) { + ShowAlphaBuffer(w->width, w->height); + } + + if (w->drawBuffer == GL_FRONT) + glFinish(); + else + glutSwapBuffers(); + + /* calc/show frame rate */ + { + static GLint t0 = 0; + static GLint frames = 0; + GLint t = glutGet(GLUT_ELAPSED_TIME); + frames++; + 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) +{ + double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + struct window *w; + for (w = FirstWindow; w; w = w->next) { + if (w->anim) { + double dt; + if (w->t0 < 0.0) + w->t0 = t; + dt = t - w->t0; + w->t0 = t; + w->spin += 60.0 * dt; + w->yrot += 90.0 * dt; + assert(w->id); + glutSetWindow(w->id); + glutPostRedisplay(); + } + } +} + + +static void +UpdateIdleFunc(void) +{ + if (AnyAnimating()) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); +} + +static void +Key(unsigned char key, int x, int y) +{ + struct window *w = CurrentWindow(); + (void) x; + (void) y; + + switch (key) { + case 'd': + w->showBuffer = GL_DEPTH; + glutPostRedisplay(); + break; + case 's': + w->showBuffer = GL_STENCIL; + glutPostRedisplay(); + break; + case 'a': + w->showBuffer = GL_ALPHA; + glutPostRedisplay(); + break; + case 'c': + w->showBuffer = GL_NONE; + glutPostRedisplay(); + break; + case 'f': + if (w->drawBuffer == GL_FRONT) + w->drawBuffer = GL_BACK; + else + w->drawBuffer = GL_FRONT; + glutPostRedisplay(); + break; + case '0': + w->drawBuffer = GL_NONE; + glutPostRedisplay(); + break; + case ' ': + w->anim = !w->anim; + w->t0 = -1; + UpdateIdleFunc(); + glutPostRedisplay(); + break; + case 'n': + CreateWindow(); + UpdateIdleFunc(); + break; + case 'k': + KillWindow(w); + if (FirstWindow == NULL) + exit(0); + break; + case 27: + KillAllWindows(); + exit(0); + break; + default: + ; + } +} + + +static void +SpecialKey(int key, int x, int y) +{ + struct window *w = CurrentWindow(); + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + w->xrot += 3.0; + if (w->xrot > 85) + w->xrot = 85; + break; + case GLUT_KEY_DOWN: + w->xrot -= 3.0; + if (w->xrot < 5) + w->xrot = 5; + break; + case GLUT_KEY_LEFT: + w->yrot += 3.0; + break; + case GLUT_KEY_RIGHT: + w->yrot -= 3.0; + break; + } + glutPostRedisplay(); +} + + +static void +CreateWindow(void) +{ + char title[1000]; + struct window *w = (struct window *) calloc(1, sizeof(struct window)); + + glutInitWindowSize(INIT_WIDTH, INIT_HEIGHT); + w->id = glutCreateWindow("foo"); + sprintf(title, "reflect window %d", w->id); + glutSetWindowTitle(title); + assert(w->id); + w->width = INIT_WIDTH; + w->height = INIT_HEIGHT; + w->anim = GL_TRUE; + w->xrot = 30.0; + w->yrot = 50.0; + w->spin = 0.0; + w->showBuffer = GL_NONE; + w->drawBuffer = GL_BACK; + + InitWindow(w); + + glutReshapeFunc(Reshape); + glutDisplayFunc(DrawWindow); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + + /* insert at head of list */ + w->next = FirstWindow; + FirstWindow = w; +} + + +static void +Usage(void) +{ + printf("Keys:\n"); + printf(" a - show alpha buffer\n"); + printf(" d - show depth buffer\n"); + printf(" s - show stencil buffer\n"); + printf(" c - show color buffer\n"); + printf(" f - toggle rendering to front/back color buffer\n"); + printf(" n - create new window\n"); + printf(" k - kill window\n"); + printf(" SPACE - toggle animation\n"); + printf(" ARROWS - rotate scene\n"); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | + GLUT_STENCIL | GLUT_ALPHA); + CreateWindow(); + glutIdleFunc(Idle); + Usage(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/renormal.c b/progs/demos/renormal.c new file mode 100644 index 00000000000..9e5da95484c --- /dev/null +++ b/progs/demos/renormal.c @@ -0,0 +1,139 @@ + +/* + * Test GL_EXT_rescale_normal extension + * Brian Paul January 1998 This program is in the public domain. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +static GLfloat Phi = 0.0; + + +static void Idle( void ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Phi += 3.0 * dt; + 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(); +} + +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition(0, 0); + glutInitWindowSize( 400, 400 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0]); + + Init(); + + glutIdleFunc( Idle ); + glutReshapeFunc( Reshape ); + glutDisplayFunc( Display ); + glutKeyboardFunc(key); + + 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/shadowtex.c b/progs/demos/shadowtex.c new file mode 100644 index 00000000000..b32fb45b4fa --- /dev/null +++ b/progs/demos/shadowtex.c @@ -0,0 +1,766 @@ +/* + * Shadow demo using the GL_ARB_depth_texture, GL_ARB_shadow and + * GL_ARB_shadow_ambient extensions. + * + * Brian Paul + * 19 Feb 2001 + * + * Added GL_EXT_shadow_funcs support on 23 March 2002 + * Added GL_EXT_packed_depth_stencil support on 15 March 2006. + * Added GL_EXT_framebuffer_object support on 27 March 2006. + * Removed old SGIX extension support on 5 April 2006. + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#define GL_GLEXT_PROTOTYPES +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> +#include "showbuffer.h" + +#define DEG_TO_RAD (3.14159 / 180.0) + +static GLint WindowWidth = 450, WindowHeight = 300; +static GLfloat Xrot = 15, Yrot = 0, Zrot = 0; + +static GLfloat Red[4] = {1, 0, 0, 1}; +static GLfloat Green[4] = {0, 1, 0, 1}; +static GLfloat Blue[4] = {0, 0, 1, 1}; +static GLfloat Yellow[4] = {1, 1, 0, 1}; + +static GLfloat LightDist = 10; +static GLfloat LightLatitude = 45.0; +static GLfloat LightLongitude = 45.0; +static GLfloat LightPos[4]; +static GLfloat SpotDir[3]; +static GLfloat SpotAngle = 40.0 * DEG_TO_RAD; +static GLfloat ShadowNear = 4.0, ShadowFar = 24.0; +static GLint ShadowTexWidth = 256, ShadowTexHeight = 256; + +static GLboolean LinearFilter = GL_FALSE; + +static GLfloat Bias = -0.06; + +static GLboolean Anim = GL_TRUE; + +static GLboolean NeedNewShadowMap = GL_FALSE; +static GLuint ShadowTexture, GrayTexture; +static GLuint ShadowFBO; + +static GLboolean HaveFBO = GL_FALSE; +static GLboolean UseFBO = GL_FALSE; +static GLboolean HavePackedDepthStencil = GL_FALSE; +static GLboolean UsePackedDepthStencil = GL_FALSE; +static GLboolean HaveEXTshadowFuncs = GL_FALSE; +static GLboolean HaveShadowAmbient = GL_FALSE; + +static GLint Operator = 0; +static const GLenum OperatorFunc[8] = { + GL_LEQUAL, GL_LESS, GL_GEQUAL, GL_GREATER, + GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER }; +static const char *OperatorName[8] = { + "GL_LEQUAL", "GL_LESS", "GL_GEQUAL", "GL_GREATER", + "GL_EQUAL", "GL_NOTEQUAL", "GL_ALWAYS", "GL_NEVER" }; + + +static GLuint DisplayMode; +#define SHOW_SHADOWS 0 +#define SHOW_DEPTH_IMAGE 1 +#define SHOW_DEPTH_MAPPING 2 +#define SHOW_DISTANCE 3 + + + +static void +DrawScene(void) +{ + GLfloat k = 6; + + /* sphere */ + glPushMatrix(); + glTranslatef(1.6, 2.2, 2.7); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Green); + glColor4fv(Green); + glutSolidSphere(1.5, 15, 15); + glPopMatrix(); + /* dodecahedron */ + glPushMatrix(); + glTranslatef(-2.0, 1.2, 2.1); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Red); + glColor4fv(Red); + glutSolidDodecahedron(); + glPopMatrix(); + /* icosahedron */ + glPushMatrix(); + glTranslatef(-0.6, 1.3, -0.5); + glScalef(1.5, 1.5, 1.5); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Yellow); + glColor4fv(Red); + glutSolidIcosahedron(); + glPopMatrix(); + /* a plane */ + glPushMatrix(); + glTranslatef(0, -1.1, 0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Blue); + glColor4fv(Blue); + glNormal3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex3f(-k, 0, -k); + glVertex3f( k, 0, -k); + glVertex3f( k, 0, k); + glVertex3f(-k, 0, k); + glEnd(); + glPopMatrix(); +} + + +/* + * Load the GL_TEXTURE matrix with the projection from the light + * source's point of view. + */ +static void +MakeShadowMatrix(const GLfloat lightPos[4], const GLfloat spotDir[3], + GLfloat spotAngle, GLfloat shadowNear, GLfloat shadowFar) +{ + GLfloat d; + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glTranslatef(0.5, 0.5, 0.5 + Bias); + glScalef(0.5, 0.5, 0.5); + d = shadowNear * tan(spotAngle); + glFrustum(-d, d, -d, d, shadowNear, shadowFar); + gluLookAt(lightPos[0], lightPos[1], lightPos[2], + lightPos[0] + spotDir[0], + lightPos[1] + spotDir[1], + lightPos[2] + spotDir[2], + 0, 1, 0); + glMatrixMode(GL_MODELVIEW); +} + + +static void +EnableIdentityTexgen(void) +{ + /* texgen so that texcoord = vertex coord */ + static GLfloat sPlane[4] = { 1, 0, 0, 0 }; + static GLfloat tPlane[4] = { 0, 1, 0, 0 }; + static GLfloat rPlane[4] = { 0, 0, 1, 0 }; + static GLfloat qPlane[4] = { 0, 0, 0, 1 }; + + glTexGenfv(GL_S, GL_EYE_PLANE, sPlane); + glTexGenfv(GL_T, GL_EYE_PLANE, tPlane); + glTexGenfv(GL_R, GL_EYE_PLANE, rPlane); + glTexGenfv(GL_Q, GL_EYE_PLANE, qPlane); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + glEnable(GL_TEXTURE_GEN_Q); +} + + +/* + * Setup 1-D texgen so that the distance from the light source, between + * the near and far planes maps to s=0 and s=1. When we draw the scene, + * the grayness will indicate the fragment's distance from the light + * source. + */ +static void +EnableDistanceTexgen(const GLfloat lightPos[4], const GLfloat lightDir[3], + GLfloat lightNear, GLfloat lightFar) +{ + GLfloat m, d; + GLfloat sPlane[4]; + GLfloat nearPoint[3]; + + m = sqrt(lightDir[0] * lightDir[0] + + lightDir[1] * lightDir[1] + + lightDir[2] * lightDir[2]); + + d = lightFar - lightNear; + + /* nearPoint = point on light direction vector which intersects the + * near plane of the light frustum. + */ + nearPoint[0] = lightPos[0] + lightDir[0] / m * lightNear; + nearPoint[1] = lightPos[1] + lightDir[1] / m * lightNear; + nearPoint[2] = lightPos[2] + lightDir[2] / m * lightNear; + + sPlane[0] = lightDir[0] / d / m; + sPlane[1] = lightDir[1] / d / m; + sPlane[2] = lightDir[2] / d / m; + sPlane[3] = -(sPlane[0] * nearPoint[0] + + sPlane[1] * nearPoint[1] + + sPlane[2] * nearPoint[2]); + + glTexGenfv(GL_S, GL_EYE_PLANE, sPlane); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glEnable(GL_TEXTURE_GEN_S); +} + + +static void +DisableTexgen(void) +{ + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + glDisable(GL_TEXTURE_GEN_Q); +} + + +static void +ComputeLightPos(GLfloat dist, GLfloat latitude, GLfloat longitude, + GLfloat pos[4], GLfloat dir[3]) +{ + + pos[0] = dist * sin(longitude * DEG_TO_RAD); + pos[1] = dist * sin(latitude * DEG_TO_RAD); + pos[2] = dist * cos(latitude * DEG_TO_RAD) * cos(longitude * DEG_TO_RAD); + pos[3] = 1; + dir[0] = -pos[0]; + dir[1] = -pos[1]; + dir[2] = -pos[2]; +} + + +/** + * Render the shadow map / depth texture. + * The result will be in the texture object named ShadowTexture. + */ +static void +RenderShadowMap(void) +{ + GLenum depthFormat; /* GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL_EXT */ + GLenum depthType; /* GL_UNSIGNED_INT_24_8_EXT or GL_UNSIGNED_INT */ + float d; + + if (WindowWidth >= 1024 && WindowHeight >= 1024) { + ShadowTexWidth = ShadowTexHeight = 1024; + } + else if (WindowWidth >= 512 && WindowHeight >= 512) { + ShadowTexWidth = ShadowTexHeight = 512; + } + else if (WindowWidth >= 256 && WindowHeight >= 256) { + ShadowTexWidth = ShadowTexHeight = 256; + } + else { + ShadowTexWidth = ShadowTexHeight = 128; + } + printf("Rendering %d x %d depth texture\n", ShadowTexWidth, ShadowTexHeight); + + if (UsePackedDepthStencil) { + depthFormat = GL_DEPTH_STENCIL_EXT; + depthType = GL_UNSIGNED_INT_24_8_EXT; + } + else { + depthFormat = GL_DEPTH_COMPONENT; + depthType = GL_UNSIGNED_INT; + } + + /* compute frustum to enclose spot light cone */ + d = ShadowNear * tan(SpotAngle); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-d, d, -d, d, ShadowNear, ShadowFar); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(LightPos[0], LightPos[1], LightPos[2], /* from */ + 0, 0, 0, /* target */ + 0, 1, 0); /* up */ + + if (UseFBO) { + glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, + ShadowTexWidth, ShadowTexHeight, 0, + depthFormat, depthType, NULL); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFBO); + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) + == GL_FRAMEBUFFER_COMPLETE_EXT); + } + + assert(!glIsEnabled(GL_TEXTURE_1D)); + assert(!glIsEnabled(GL_TEXTURE_2D)); + + glViewport(0, 0, ShadowTexWidth, ShadowTexHeight); + glClear(GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + DrawScene(); + + if (UseFBO) { + /* all done! */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } + else { + /* + * copy depth buffer into the texture map + */ + if (DisplayMode == SHOW_DEPTH_MAPPING) { + /* load depth image as gray-scale luminance texture */ + GLuint *depth = (GLuint *) + malloc(ShadowTexWidth * ShadowTexHeight * sizeof(GLuint)); + assert(depth); + glReadPixels(0, 0, ShadowTexWidth, ShadowTexHeight, + depthFormat, depthType, depth); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, + ShadowTexWidth, ShadowTexHeight, 0, + GL_LUMINANCE, GL_UNSIGNED_INT, depth); + free(depth); + } + else { + /* The normal shadow case - a real depth texture */ + glCopyTexImage2D(GL_TEXTURE_2D, 0, depthFormat, + 0, 0, ShadowTexWidth, ShadowTexHeight, 0); + if (UsePackedDepthStencil) { + /* debug check */ + GLint intFormat; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, + GL_TEXTURE_INTERNAL_FORMAT, &intFormat); + assert(intFormat == GL_DEPTH_STENCIL_EXT); + } + } + } +} + + +/** + * Show the shadow map as a grayscale image. + */ +static void +ShowShadowMap(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, WindowWidth, 0, WindowHeight, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glEnable(GL_TEXTURE_2D); + + DisableTexgen(); + + /* interpret texture's depth values as luminance values */ +#if defined(GL_ARB_shadow) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); + glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE); +#endif + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(ShadowTexWidth, 0); + glTexCoord2f(1, 1); glVertex2f(ShadowTexWidth, ShadowTexHeight); + glTexCoord2f(0, 1); glVertex2f(0, ShadowTexHeight); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); +} + + +/** + * Redraw window image + */ +static void +Display(void) +{ + GLenum error; + + ComputeLightPos(LightDist, LightLatitude, LightLongitude, + LightPos, SpotDir); + + if (NeedNewShadowMap) { + RenderShadowMap(); + NeedNewShadowMap = GL_FALSE; + } + + glViewport(0, 0, WindowWidth, WindowHeight); + if (DisplayMode == SHOW_DEPTH_IMAGE) { + ShowShadowMap(); + } + else { + /* prepare to draw scene from camera's view */ + const GLfloat ar = (GLfloat) WindowWidth / (GLfloat) WindowHeight; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1.0, 1.0, 4.0, 50.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -22.0); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glRotatef(Zrot, 0, 0, 1); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLightfv(GL_LIGHT0, GL_POSITION, LightPos); + + if (LinearFilter) { + 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); + } + + if (DisplayMode == SHOW_DEPTH_MAPPING) { +#if defined(GL_ARB_shadow) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); +#endif + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable(GL_TEXTURE_2D); + MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar); + EnableIdentityTexgen(); + } + else if (DisplayMode == SHOW_DISTANCE) { + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + EnableDistanceTexgen(LightPos, SpotDir, ShadowNear+Bias, ShadowFar); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable(GL_TEXTURE_1D); + assert(!glIsEnabled(GL_TEXTURE_2D)); + } + else { + assert(DisplayMode == SHOW_SHADOWS); +#if defined(GL_ARB_shadow) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); +#endif + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable(GL_TEXTURE_2D); + MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar); + EnableIdentityTexgen(); + } + + DrawScene(); + + DisableTexgen(); + glDisable(GL_TEXTURE_1D); + glDisable(GL_TEXTURE_2D); + } + + glutSwapBuffers(); + + error = glGetError(); + if (error) { + printf("GL Error: %s\n", (char *) gluErrorString(error)); + } +} + + +static void +Reshape(int width, int height) +{ + WindowWidth = width; + WindowHeight = height; + NeedNewShadowMap = GL_TRUE; +} + + +static void +Idle(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Yrot += 75.0 * dt; + /*LightLongitude -= 5.0;*/ + glutPostRedisplay(); +} + + +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 'b': + Bias -= 0.01; + printf("Bias %g\n", Bias); + break; + case 'B': + Bias += 0.01; + printf("Bias %g\n", Bias); + break; + case 'd': + DisplayMode = SHOW_DISTANCE; + break; + case 'f': + LinearFilter = !LinearFilter; + printf("%s filtering\n", LinearFilter ? "Bilinear" : "Nearest"); + break; + case 'i': + DisplayMode = SHOW_DEPTH_IMAGE; + break; + case 'm': + DisplayMode = SHOW_DEPTH_MAPPING; + break; + case 'n': + case 's': + case ' ': + DisplayMode = SHOW_SHADOWS; + break; + case 'o': + if (HaveEXTshadowFuncs) { + Operator++; + if (Operator >= 8) + Operator = 0; + printf("Operator: %s\n", OperatorName[Operator]); +#if defined(GL_ARB_shadow) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, + OperatorFunc[Operator]); +#endif + } + break; + case 'p': + UsePackedDepthStencil = !UsePackedDepthStencil; + if (UsePackedDepthStencil && !HavePackedDepthStencil) { + printf("Sorry, GL_EXT_packed_depth_stencil not supported\n"); + UsePackedDepthStencil = GL_FALSE; + } + else { + printf("Use GL_DEPTH_STENCIL_EXT: %d\n", UsePackedDepthStencil); + /* Don't really need to regenerate shadow map texture, but do so + * to exercise more code more often. + */ + NeedNewShadowMap = GL_TRUE; + } + 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; + const int mod = glutGetModifiers(); + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + if (mod) + LightLatitude += step; + else + Xrot += step; + break; + case GLUT_KEY_DOWN: + if (mod) + LightLatitude -= step; + else + Xrot -= step; + break; + case GLUT_KEY_LEFT: + if (mod) + LightLongitude += step; + else + Yrot += step; + break; + case GLUT_KEY_RIGHT: + if (mod) + LightLongitude -= step; + else + Yrot -= step; + break; + } + if (mod) + NeedNewShadowMap = GL_TRUE; + + glutPostRedisplay(); +} + + +static void +Init(void) +{ + static const GLfloat borderColor[4] = {1.0, 0.0, 0.0, 0.0}; + +#if defined(GL_ARB_depth_texture) && defined(GL_ARB_shadow) + if (!glutExtensionSupported("GL_ARB_depth_texture") || + !glutExtensionSupported("GL_ARB_shadow")) { +#else + if (1) { +#endif + printf("Sorry, this demo requires the GL_ARB_depth_texture and GL_ARB_shadow extensions\n"); + exit(1); + } + printf("Using GL_ARB_depth_texture and GL_ARB_shadow\n"); + +#if defined(GL_ARB_shadow_ambient) + HaveShadowAmbient = glutExtensionSupported("GL_ARB_shadow_ambient"); + if (HaveShadowAmbient) { + printf("and GL_ARB_shadow_ambient\n"); + } +#endif + + HaveEXTshadowFuncs = glutExtensionSupported("GL_EXT_shadow_funcs"); + + HavePackedDepthStencil = glutExtensionSupported("GL_EXT_packed_depth_stencil"); + UsePackedDepthStencil = HavePackedDepthStencil; + +#if defined(GL_EXT_framebuffer_object) + HaveFBO = glutExtensionSupported("GL_EXT_framebuffer_object"); + UseFBO = HaveFBO; + if (UseFBO) { + printf("Using GL_EXT_framebuffer_object\n"); + } +#endif + + /* + * Set up the 2D shadow map texture + */ + glGenTextures(1, &ShadowTexture); + glBindTexture(GL_TEXTURE_2D, ShadowTexture); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); +#if defined(GL_ARB_shadow) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); +#endif + if (HaveShadowAmbient) { +#if defined(GL_ARB_shadow_ambient) + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.3); +#endif + } + +#if defined(GL_EXT_framebuffer_object) + if (UseFBO) { + glGenFramebuffersEXT(1, &ShadowFBO); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFBO); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + GL_RENDERBUFFER_EXT, 0); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, + GL_TEXTURE_2D, ShadowTexture, 0); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } +#endif + + /* + * Setup 1-D grayscale texture image for SHOW_DISTANCE mode + */ + glGenTextures(1, &GrayTexture); + glBindTexture(GL_TEXTURE_1D, GrayTexture); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + { + GLuint i; + GLubyte image[256]; + for (i = 0; i < 256; i++) + image[i] = i; + glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, + 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image); + } + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); +} + + +static void +PrintHelp(void) +{ + printf("Keys:\n"); + printf(" a = toggle animation\n"); + printf(" i = show depth texture image\n"); + printf(" m = show depth texture mapping\n"); + printf(" d = show fragment distance from light source\n"); + printf(" n = show normal, shadowed image\n"); + printf(" f = toggle nearest/bilinear texture filtering\n"); + printf(" b/B = decrease/increase shadow map Z bias\n"); + printf(" p = toggle use of packed depth/stencil\n"); + printf(" cursor keys = rotate scene\n"); + printf(" <shift> + cursor keys = rotate light source\n"); + if (HaveEXTshadowFuncs) + printf(" o = cycle through comparison modes\n"); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(WindowWidth, WindowHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); + glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Display); + if (Anim) + glutIdleFunc(Idle); + Init(); + PrintHelp(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/showbuffer.c b/progs/demos/showbuffer.c new file mode 100644 index 00000000000..17f84dc62bd --- /dev/null +++ b/progs/demos/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 <assert.h> +#include <stdlib.h> +#include <GL/gl.h> +#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/demos/showbuffer.h b/progs/demos/showbuffer.h new file mode 100644 index 00000000000..63533d8e9b5 --- /dev/null +++ b/progs/demos/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 <GL/gl.h> + + + +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/demos/singlebuffer.c b/progs/demos/singlebuffer.c new file mode 100644 index 00000000000..9899c245b2a --- /dev/null +++ b/progs/demos/singlebuffer.c @@ -0,0 +1,269 @@ +/* + * Demo of (nearly) flicker-free drawing with a single color buffer. + * + * Basically, draw the scene into the Z buffer first, then draw the + * scene into the color buffer. Finally, "clear" the background by + * setting the fragments we didn't hit earlier. + * + * This won't work if you need blending. The technique works best + * when the scene is relatively simple and can be rendered quickly + * (i.e. with hardware), and when the objects don't move too much from + * one frame to the next. + * + * Brian Paul + * 25 August 2005 + * + * See Mesa license for terms. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define FLICKER 0 +#define NO_FLICKER 1 + +static GLint Mode = NO_FLICKER; +static GLfloat Xrot = 0, Yrot = 0, Zrot = 0; +static GLboolean Anim = GL_TRUE; +static GLfloat ClearColor[4] = {0.2, 0.2, 0.9, 0.0}; +static GLfloat NearClip = 5.0, FarClip = 25.0, ViewDist = 7.0; +static double PrevTime = -1; + +struct box { + float tx, ty, tz; + float rx, ry, rz, ra; + float sx, sy, sz; + float color[4]; +}; + +#define NUM_BOXES 25 + +struct box Boxes[NUM_BOXES]; + + +/* Return random float in [0,1] */ +static float +Random(void) +{ + int i = rand(); + return (float) (i % 1000) / 1000.0; +} + + +static void +MakeBoxes(void) +{ + int i; + for (i = 0; i < NUM_BOXES; i++) { + Boxes[i].tx = -1.0 + 2.0 * Random(); + Boxes[i].ty = -1.0 + 2.0 * Random(); + Boxes[i].tz = -1.0 + 2.0 * Random(); + Boxes[i].sx = 0.1 + Random() * 0.4; + Boxes[i].sy = 0.1 + Random() * 0.4; + Boxes[i].sz = 0.1 + Random() * 0.4; + Boxes[i].rx = Random(); + Boxes[i].ry = Random(); + Boxes[i].rz = Random(); + Boxes[i].ra = Random() * 360.0; + Boxes[i].color[0] = Random(); + Boxes[i].color[1] = Random(); + Boxes[i].color[2] = Random(); + Boxes[i].color[3] = 1.0; + } +} + + +static void +DrawBoxes(void) +{ + int i; + for (i = 0; i < NUM_BOXES; i++) { + glPushMatrix(); + glTranslatef(Boxes[i].tx, Boxes[i].ty, Boxes[i].tz); + glRotatef(Boxes[i].ra, Boxes[i].rx, Boxes[i].ry, Boxes[i].rz); + glScalef(Boxes[i].sx, Boxes[i].sy, Boxes[i].sz); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Boxes[i].color); + glutSolidCube(1.0); + glPopMatrix(); + } +} + + +static void +Idle(void) +{ + double dt, t = glutGet(GLUT_ELAPSED_TIME) * 0.001; + if (PrevTime < 0.0) + PrevTime = t; + dt = t - PrevTime; + PrevTime = t; + Xrot += 16.0 * dt; + Yrot += 12.0 * dt; + Zrot += 8.0 * dt; + glutPostRedisplay(); +} + + +static void +Draw(void) +{ + if (Mode == FLICKER) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + else { + /* don't clear color buffer */ + glClear(GL_DEPTH_BUFFER_BIT); + /* update Z buffer only */ + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + } + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + glRotatef(Zrot, 0, 0, 1); + + DrawBoxes(); + + if (Mode == NO_FLICKER) { + /* update color buffer now */ + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthFunc(GL_EQUAL); + DrawBoxes(); + glDepthFunc(GL_LESS); + } + + glPopMatrix(); + + if (Mode == NO_FLICKER) { + /* "clear" the untouched pixels now. + * Note: if you comment-out this code you'll see something interesting. + */ + GLfloat x = FarClip / NearClip; + GLfloat z = -(FarClip - ViewDist - 1.0); + glDisable(GL_LIGHTING); + glColor4fv(ClearColor); + glBegin(GL_POLYGON); + glVertex3f(-x, -x, z); + glVertex3f( x, -x, z); + glVertex3f( x, x, z); + glVertex3f(-x, x, z); + glEnd(); + glEnable(GL_LIGHTING); + } + + /* This is where you'd normally do SwapBuffers */ + glFinish(); +} + + +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, NearClip, FarClip); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -ViewDist); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + PrevTime = -1; + break; + case 'm': + Mode = !Mode; + break; + case 'b': + MakeBoxes(); + 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) +{ + glClearColor(ClearColor[0], ClearColor[1], ClearColor[2], ClearColor[3]); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_CULL_FACE); + glEnable(GL_NORMALIZE); + MakeBoxes(); +} + + +static void +Usage(void) +{ + printf("Keys:\n"); + printf(" m - toggle drawing mode (flicker vs. no flicker)\n"); + printf(" a - toggle animation\n"); + printf(" b - generate new boxes\n"); + printf(" ARROWS - rotate scene\n"); + printf(" ESC - exit\n"); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(800, 800); + glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); + glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Draw); + if (Anim) + glutIdleFunc(Idle); + Init(); + Usage(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/spectex.c b/progs/demos/spectex.c new file mode 100644 index 00000000000..6ab1191579c --- /dev/null +++ b/progs/demos/spectex.c @@ -0,0 +1,272 @@ + +/* + * 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 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +static GLUquadricObj *Quadric; +static GLuint Sphere; +static GLfloat LightPos[4] = {10.0, 10.0, 10.0, 1.0}; +static GLfloat Delta = 20.0; +static GLint Mode = 4; + +/*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 GLboolean smooth = 1; + +static void +Idle(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + LightPos[0] += Delta * dt; + if (LightPos[0]>15.0 || LightPos[0]<-15.0) + Delta = -Delta; + + 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; + case 's': + smooth = !smooth; + if (smooth) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + 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); + + glShadeModel(GL_SMOOTH); + + 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/spriteblast.c b/progs/demos/spriteblast.c new file mode 100644 index 00000000000..f0d3d0dfd41 --- /dev/null +++ b/progs/demos/spriteblast.c @@ -0,0 +1,554 @@ + +/* 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. */ + + +/* Modified by Brian Paul to test GL_ARB_point_sprite */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> /* for cos(), sin(), and sqrt() */ +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + +/* Some <math.h> 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 float theTime; +static int repeat = 1; +static int blend = 1; +int useMipmaps = 1; +int linearFiltering = 1; + +static GLfloat constant[3] = { .2, 0.0, 0.0 }; +static GLfloat linear[3] = { .0, .1, 0.0 }; +static GLfloat theQuad[3] = { .005, 0.1, 1/600.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, org = 0, sprite = 1, smooth = 1; + +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) + + +/* GL */ +static GLint spritePattern[16][16] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0 }, + { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +}; + + + + +#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 + +/* Modeling units of ground extent in each X and Z direction. */ +#define EDGE 12 + +static void +makePointList(void) +{ + float angle, velocity, direction; + int i; + + motion = 1; + for (i=0; i<numPoints; i++) { + pointList[i][0] = 0.0; + pointList[i][1] = 0.0; + pointList[i][2] = 0.0; + pointTime[i] = 0.0; + angle = (RANDOM_RANGE(60.0, 70.0)) * M_PI/180.0; + direction = RANDOM_RANGE(0.0, 360.0) * M_PI/180.0; + pointDirection[i][0] = cos(direction); + pointDirection[i][1] = sin(direction); + velocity = MEAN_VELOCITY + RANDOM_RANGE(-0.8, 1.0); + pointVelocity[i][0] = velocity * cos(angle); + pointVelocity[i][1] = velocity * sin(angle); + colorList[i] = rand() % NUM_COLORS; + } + theTime = 0.0; +} + +static void +updatePointList(void) +{ + float distance; + int i; + + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + motion = 0; + for (i=0; i<numPoints; i++) { + distance = pointVelocity[i][0] * theTime; + + /* X and Z */ + pointList[i][0] = pointDirection[i][0] * distance; + pointList[i][2] = pointDirection[i][1] * distance; + + /* Z */ + pointList[i][1] = + (pointVelocity[i][1] - 0.5 * GRAVITY * pointTime[i])*pointTime[i]; + + /* If we hit the ground, bounce the point upward again. */ + if (pointList[i][1] <= 0.0) { + if (distance > 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] += dt; + } + theTime += dt; + if (!motion && !spin) { + if (repeat) { + makePointList(); + } else { + glutIdleFunc(NULL); + } + } +} + +static void +idle(void) +{ + updatePointList(); + if (spin) { + angle += 0.3; + } + glutPostRedisplay(); +} + +static void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) { + if (animate && (motion || spin)) { + glutIdleFunc(idle); + } + } else { + glutIdleFunc(NULL); + } +} + +static void +redraw(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(15.0, 1.0, 0.0, 0.0); + glRotatef(angle, 0.0, 1.0, 0.0); + + glDepthMask(GL_FALSE); + + /* Draw the floor. */ +/* glEnable(GL_TEXTURE_2D);*/ + glColor3f(0.1, 0.5, 1.0); + 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); + + if (sprite) { + glEnable(GL_TEXTURE_2D); +#ifdef GL_ARB_point_sprite + glEnable(GL_POINT_SPRITE_ARB); +#endif + } + + glColor3f(1,1,1); + glBegin(GL_POINTS); + for (i=0; i<numPoints; i++) { + /* Draw alive particles. */ + if (colorList[i] != DEAD) { + if (!sprite) glColor4fv(colorSet[colorList[i]]); + glVertex3fv(pointList[i]); + } + } + glEnd(); + + glDisable(GL_TEXTURE_2D); +#ifdef GL_ARB_point_sprite + glDisable(GL_POINT_SPRITE_ARB); +#endif + glDisable(GL_BLEND); + + glPopMatrix(); + + glutSwapBuffers(); +} + +/* ARGSUSED2 */ +static void +mouse(int button, int state, int x, int y) +{ + /* Scene can be spun around Y axis using left + mouse button movement. */ + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { + moving = 1; + begin = x; + } + if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { + moving = 0; + } +} + +/* ARGSUSED1 */ +static void +mouseMotion(int x, int y) +{ + if (moving) { + angle = angle + (x - begin); + begin = x; + glutPostRedisplay(); + } +} + +static void +menu(int option) +{ + switch (option) { + case 0: + makePointList(); + break; +#ifdef GL_ARB_point_parameters + case 1: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, constant); + break; + case 2: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, linear); + break; + case 3: + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); + break; +#endif + case 4: + blend = 1; + break; + case 5: + blend = 0; + break; +#ifdef GL_ARB_point_parameters + case 6: + glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0); + break; + case 7: + glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 10.0); + break; +#endif + case 8: + glEnable(GL_POINT_SMOOTH); + smooth = 1; + break; + case 9: + glDisable(GL_POINT_SMOOTH); + smooth = 0; + break; + case 10: + glPointSize(4.0); + break; + case 11: + glPointSize(8.0); + break; + case 12: + glPointSize(16.0); + break; + case 13: + spin = 1 - spin; + if (animate && (spin || motion)) { + glutIdleFunc(idle); + } else { + glutIdleFunc(NULL); + } + break; + case 14: + numPoints = 200; + break; + case 15: + numPoints = 500; + break; + case 16: + numPoints = 1000; + break; + case 17: + numPoints = 2000; + break; + case 666: + exit(0); + } + glutPostRedisplay(); +} + +/* ARGSUSED1 */ +static void +key(unsigned char c, int x, int y) +{ + switch (c) { + case 13: + animate = 1 - animate; /* toggle. */ + if (animate && (motion || spin)) { + glutIdleFunc(idle); + } else { + glutIdleFunc(NULL); + } + break; + case ' ': + animate = 1; + makePointList(); + glutIdleFunc(idle); + break; + case 'o': + case 'O': + org ^= 1; +#ifdef GL_VERSION_2_0 +#ifdef GL_ARB_point_parameters + glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, + org ? GL_LOWER_LEFT : GL_UPPER_LEFT); +#endif +#endif + glutPostRedisplay(); + break; + case 't': + case 'T': + sprite ^= 1; + glutPostRedisplay(); + break; + case 's': + case 'S': + (smooth ^= 1) ? glEnable(GL_POINT_SMOOTH) : glDisable(GL_POINT_SMOOTH); + glutPostRedisplay(); + break; + case '0': + glPointSize(1.0); + glutPostRedisplay(); + break; + case '1': + glPointSize(2.0); + glutPostRedisplay(); + break; + case '2': + glPointSize(4.0); + glutPostRedisplay(); + break; + case '3': + glPointSize(8.0); + glutPostRedisplay(); + break; + case '4': + glPointSize(16.0); + glutPostRedisplay(); + break; + case 27: + exit(0); + } +} + + + +static void +makeSprite(void) +{ + GLubyte texture[16][16][4]; + int i, j; + + if (!glutExtensionSupported("GL_ARB_point_sprite")) { + printf("Sorry, this demo requires GL_ARB_point_sprite.\n"); + exit(0); + } + if (!glutExtensionSupported("GL_ARB_point_parameters")) { + printf("Sorry, this demo requires GL_ARB_point_parameters.\n"); + exit(0); + } + + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + if (spritePattern[i][j]) { + texture[i][j][0] = 255; + texture[i][j][1] = 255; + texture[i][j][2] = 255; + texture[i][j][3] = 255; + } + else { + texture[i][j][0] = 255; + texture[i][j][1] = 0; + texture[i][j][2] = 0; + texture[i][j][3] = 0; + } + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, + texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#ifdef GL_ARB_point_sprite + glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); +#endif +} + + +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, 2.0, 30.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); +} + +int +main(int argc, char **argv) +{ + int i; + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); + + for (i=1; i<argc; i++) { + if(!strcmp("-noms", argv[i])) { + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + printf("forcing no multisampling\n"); + } else if(!strcmp("-nomipmaps", argv[i])) { + useMipmaps = 0; + } else if(!strcmp("-nearest", argv[i])) { + linearFiltering = 0; + } + } + glutInitWindowPosition(0, 0); + glutInitWindowSize(600,300); + glutCreateWindow("sprite blast"); + glutReshapeFunc(reshape); + glutDisplayFunc(redraw); + glutMouseFunc(mouse); + glutMotionFunc(mouseMotion); + glutVisibilityFunc(visible); + glutKeyboardFunc(key); + glutCreateMenu(menu); + glutAddMenuEntry("Reset time", 0); + glutAddMenuEntry("Constant", 1); + glutAddMenuEntry("Linear", 2); + glutAddMenuEntry("Quadratic", 3); + glutAddMenuEntry("Blend on", 4); + glutAddMenuEntry("Blend off", 5); + glutAddMenuEntry("Threshold 1", 6); + glutAddMenuEntry("Threshold 10", 7); + glutAddMenuEntry("Point smooth on", 8); + glutAddMenuEntry("Point smooth off", 9); + glutAddMenuEntry("Point size 4", 10); + glutAddMenuEntry("Point size 8", 11); + glutAddMenuEntry("Point size 16", 12); + glutAddMenuEntry("Toggle spin", 13); + glutAddMenuEntry("200 points ", 14); + glutAddMenuEntry("500 points ", 15); + glutAddMenuEntry("1000 points ", 16); + glutAddMenuEntry("2000 points ", 17); + glutAddMenuEntry("Quit", 666); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + makePointList(); + makeSprite(); + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + glEnable(GL_POINT_SMOOTH); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glPointSize(16.0); +#ifdef GL_ARB_point_parameters + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); +#endif + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/stex3d.c b/progs/demos/stex3d.c new file mode 100644 index 00000000000..83ae3684ae2 --- /dev/null +++ b/progs/demos/stex3d.c @@ -0,0 +1,678 @@ +/*----------------------------- + * 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 + * + * Converted to GLUT by brianp on 1/1/98 + * Massive clean-up on 2002/10/23 by brianp + * + * + * cc stex3d.c -o stex3d -lglut -lMesaGLU -lMesaGL -lX11 -lXext -lm + * + *---------------------------- */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> + + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define NOISE_TEXTURE 1 +#define GRADIENT_TEXTURE 2 + +#define TORUS 1 +#define SPHERE 2 + +static int tex_width=64, tex_height=64, tex_depth=64; +static float angx=0, angy=0, angz=0; +static int texgen = 2, animate = 1, smooth = 1, wireframe = 0; +static int CurTexture = NOISE_TEXTURE, CurObject = TORUS; + + +static void +BuildTorus(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.25; + float outerRadius = 0.5; + float scalFac; + + rings = 16; + sides = 12; + scalFac = 1 / (outerRadius * 2); + + glNewList(TORUS, 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(); +} + + +/*-------------------------------------------------------------------- + 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 128 +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.; + +static 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 */ +} + +static void +initNoise(void) +{ + /*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]; + } +} + + +static 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 */ +} + + +static void +create3Dtexture(void) +{ + unsigned char *voxels = NULL; + int i, j, k; + unsigned char *vp; + float vec[3]; + int tmp; + + printf("creating 3d textures...\n"); + voxels = + (unsigned char *) + malloc((size_t) (4 * tex_width * tex_height * tex_depth)); + vp = voxels; + for (i = 0; i < tex_width; i++) { + vec[0] = i; + for (j = 0; j < tex_height; j++) { + vec[1] = j; + for (k = 0; k < tex_depth; k++) { + vec[2] = k; + tmp = (sin(k * i * j + turbulence(vec, 0.01, 1)) + 1) * 127.5; + *vp++ = 0; + *vp++ = 0; + *vp++ = tmp; + *vp++ = tmp + 128; + } + } + } + + printf("setting up 3d texture...\n"); + + glBindTexture(GL_TEXTURE_3D, NOISE_TEXTURE); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, + tex_width, tex_height, tex_depth, + 0, GL_RGBA, GL_UNSIGNED_BYTE, voxels); + + free(voxels); + + printf("finished setting up 3d texture image.\n"); +} + + +static void +printHelp(void) +{ + printf("\nUsage: stex3d <cmd line options>\n"); + printf(" cmd line options:\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(" up/down rotate around X\n"); + printf(" left/right rotate around Y\n"); + printf(" z/Z rotate around Z\n"); + printf(" a toggle animation\n"); + printf(" s toggle smooth shading\n"); + printf(" t toggle texgen mode\n"); + printf(" o toggle object: torus/sphere\n"); + printf(" i toggle texture image: noise/gradient\n"); +} + + +static GLenum +parseCmdLine(int argc, char **argv) +{ + GLint i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-help") == 0) { + printHelp(); + return GL_FALSE; + } + else if (strstr(argv[i], "-w") != NULL) { + tex_width = atoi((argv[i]) + 2); + } + else if (strstr(argv[i], "-h") != NULL) { + tex_height = atoi((argv[i]) + 2); + } + else if (strstr(argv[i], "-d") != NULL) { + tex_depth = atoi((argv[i]) + 2); + } + 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; +} + + +static void +drawScene(void) +{ + static const GLfloat sPlane[4] = { 0.5, 0, 0, -.5 }; + static const GLfloat tPlane[4] = { 0, 0.5, 0, -.5 }; + static const GLfloat rPlane[4] = { 0, 0, 0.5, -.5 }; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + if (texgen == 2) { + glTexGenfv(GL_S, GL_EYE_PLANE, sPlane); + glTexGenfv(GL_T, GL_EYE_PLANE, tPlane); + glTexGenfv(GL_R, GL_EYE_PLANE, rPlane); + } + + glRotatef(angx, 1.0, 0.0, 0.0); + glRotatef(angy, 0.0, 1.0, 0.0); + glRotatef(angz, 0.0, 0.0, 1.0); + + if (texgen == 1) { + glTexGenfv(GL_S, GL_EYE_PLANE, sPlane); + glTexGenfv(GL_T, GL_EYE_PLANE, tPlane); + glTexGenfv(GL_R, GL_EYE_PLANE, rPlane); + } + + if (texgen) { + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + } + else { + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + } + + glCallList(CurObject); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +resize(int w, int h) +{ + float ar = (float) w / (float) h; + float ax = 0.6 * ar; + float ay = 0.6; + glViewport(0, 0, (GLint) w, (GLint) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ax, ax, -ay, ay, 2, 20); + /*glOrtho(-2, 2, -2, 2, -10, 10);*/ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -4); +} + + +static void +Idle(void) +{ + float t = glutGet(GLUT_ELAPSED_TIME); + angx = 0.01 * t; + angy = 0.03 * t; + angz += 0; + glutPostRedisplay(); +} + + +static void +SpecialKey(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + angx += 5.0; + break; + case GLUT_KEY_DOWN: + angx -= 5.0; + break; + case GLUT_KEY_LEFT: + angy += 5.0; + break; + case GLUT_KEY_RIGHT: + angy -= 5.0; + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void +KeyHandler(unsigned char key, int x, int y) +{ + static const char *mode[] = { + "glTexCoord3f (no texgen)", + "texgen fixed to object coords", + "texgen fixed to eye coords" + }; + (void) x; + (void) y; + switch (key) { + case 27: + case 'q': + case 'Q': /* quit game. */ + exit(0); + break; + case 'z': + angz += 10; + break; + case 'Z': + angz -= 10; + break; + case 's': + smooth = !smooth; + if (smooth) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); + break; + case 't': + texgen++; + if (texgen > 2) + texgen = 0; + printf("Texgen: %s\n", mode[texgen]); + break; + case 'o': + if (CurObject == TORUS) + CurObject = SPHERE; + else + CurObject = TORUS; + break; + case 'i': + if (CurTexture == NOISE_TEXTURE) + CurTexture = GRADIENT_TEXTURE; + else + CurTexture = NOISE_TEXTURE; + glBindTexture(GL_TEXTURE_3D, CurTexture); + break; + case 'a': + animate = !animate; + if (animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'w': + wireframe = !wireframe; + if (wireframe) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + break; + default: + break; + } + glutPostRedisplay(); +} + + +static void +create3Dgradient(void) +{ + unsigned char *v; + int i, j, k; + unsigned char *voxels = NULL; + + voxels = (unsigned char *) malloc(4 * tex_width * tex_height * tex_depth); + v = voxels; + + for (i = 0; i < tex_depth; i++) { + for (j = 0; j < tex_height; j++) { + for (k = 0; k < tex_width; k++) { + GLint r = (255 * i) / (tex_depth - 1); + GLint g = (255 * j) / (tex_height - 1); + GLint b = (255 * k) / (tex_width - 1); + *v++ = r; + *v++ = g; + *v++ = b; + *v++ = 255; + } + } + } + + + glBindTexture(GL_TEXTURE_3D, GRADIENT_TEXTURE); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, + tex_width, tex_height, tex_depth, + 0, GL_RGBA, GL_UNSIGNED_BYTE, voxels); + + free(voxels); +} + + + +static void +init(void) +{ + static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat mat_shininess[] = { 25.0 }; + static const GLfloat gray[] = { 0.6, 0.6, 0.6, 0.0 }; + static const GLfloat white[] = { 1.0, 1.0, 1.0, 0.0 }; + static const GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 }; + + int max; + + /* see if we have OpenGL 1.2 or later, for 3D texturing */ + { + const char *version = (const char *) glGetString(GL_VERSION); + if (strncmp(version, "1.0", 3) == 0 || strncmp(version, "1.1", 3) == 0) { + printf("Sorry, OpenGL 1.2 or later is required\n"); + exit(1); + } + } + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); + glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &max); + printf("GL_MAX_3D_TEXTURE_SIZE: %d\n", max); + printf("Current 3D texture size: %d x %d x %d\n", + tex_width, tex_height, tex_depth); + + /* init light */ + 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); + + glClearColor(.5, .5, .5, 0); + + { + GLUquadricObj *q; + q = gluNewQuadric(); + gluQuadricTexture( q, GL_TRUE ); + glNewList(SPHERE, GL_COMPILE); + gluSphere( q, 0.95, 30, 15 ); + glEndList(); + gluDeleteQuadric(q); + } + + BuildTorus(); + + + create3Dgradient(); + + initNoise(); + create3Dtexture(); + + glEnable(GL_TEXTURE_3D); + + /* + glBlendFunc(GL_SRC_COLOR, GL_SRC_ALPHA); + glEnable(GL_BLEND); + */ + glEnable(GL_DEPTH_TEST); + + glColor3f(0.6, 0.7, 0.8); +} + + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (parseCmdLine(argc, argv) == GL_FALSE) { + exit(0); + } + + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + + if (glutCreateWindow("stex3d") <= 0) { + exit(0); + } + + init(); + + printHelp(); + + glutReshapeFunc(resize); + glutKeyboardFunc(KeyHandler); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(drawScene); + if (animate) + glutIdleFunc(Idle); + glutMainLoop(); + return 0; +} + diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c new file mode 100644 index 00000000000..38ede7ac3e1 --- /dev/null +++ b/progs/demos/teapot.c @@ -0,0 +1,675 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> +#include <string.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <GL/glut.h> +#include "readtex.h" + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen=1; +#endif + +static int WIDTH=640; +static int HEIGHT=480; + +static GLint T0 = 0; +static GLint Frames = 0; + +#define BASESIZE 10.0 + +#define BASERES 12 +#define TEAPOTRES 3 + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +extern void shadowmatrix(GLfloat [4][4], GLfloat [4], GLfloat [4]); +extern void findplane(GLfloat [4], GLfloat [3], GLfloat [3], GLfloat [3]); + + +static int win=0; + +static float obs[3]={5.0,0.0,1.0}; +static float dir[3]; +static float v=0.0; +static float alpha=-90.0; +static float beta=90.0; + +static GLfloat baseshadow[4][4]; +static GLfloat lightpos[4]={2.3,0.0,3.0,1.0}; +static GLfloat lightdir[3]={-2.3,0.0,-3.0}; +static GLfloat lightalpha=0.0; + +static int fog=1; +static int bfcull=1; +static int usetex=1; +static int help=1; +static int joyavailable=0; +static int joyactive=0; + +static GLuint t1id,t2id; +static GLuint teapotdlist,basedlist,lightdlist; + + + +/******************** begin shadow code ********************/ + +/* Taken from the projshadow.c - by Tom McReynolds, SGI */ + +/* Modified by David Bucciarelli */ + +enum { + X, Y, Z, W +}; +enum { + A, B, C, D +}; + +/* create a matrix that will project the desired shadow */ +void +shadowmatrix(GLfloat shadowMat[4][4], + GLfloat groundplane[4], + GLfloat lightpos[4]) +{ + GLfloat dot; + + /* find dot product between light position vector and ground plane normal */ + dot = groundplane[X] * lightpos[X] + + groundplane[Y] * lightpos[Y] + + groundplane[Z] * lightpos[Z] + + groundplane[W] * lightpos[W]; + + shadowMat[0][0] = dot - lightpos[X] * groundplane[X]; + shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y]; + shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z]; + shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W]; + + shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X]; + shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y]; + shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z]; + shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W]; + + shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X]; + shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y]; + shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z]; + shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W]; + + shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X]; + shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y]; + shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z]; + shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; + +} + +/* find the plane equation given 3 points */ +void +findplane(GLfloat plane[4], + GLfloat v0[3], GLfloat v1[3], GLfloat v2[3]) +{ + GLfloat vec0[3], vec1[3]; + + /* need 2 vectors to find cross product */ + vec0[X] = v1[X] - v0[X]; + vec0[Y] = v1[Y] - v0[Y]; + vec0[Z] = v1[Z] - v0[Z]; + + vec1[X] = v2[X] - v0[X]; + vec1[Y] = v2[Y] - v0[Y]; + vec1[Z] = v2[Z] - v0[Z]; + + /* find cross product to get A, B, and C of plane equation */ + plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y]; + plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]); + plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X]; + + plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]); +} + +/******************** end shadow code ********************/ + + +static void calcposobs(void) +{ + dir[0]=sin(alpha*M_PI/180.0); + dir[1]=cos(alpha*M_PI/180.0)*sin(beta*M_PI/180.0); + dir[2]=cos(beta*M_PI/180.0); + + obs[0]+=v*dir[0]; + obs[1]+=v*dir[1]; + obs[2]+=v*dir[2]; +} + +static void special(int k, int x, int y) +{ + switch(k) { + case GLUT_KEY_LEFT: + alpha-=2.0; + break; + case GLUT_KEY_RIGHT: + alpha+=2.0; + break; + case GLUT_KEY_DOWN: + beta-=2.0; + break; + case GLUT_KEY_UP: + beta+=2.0; + break; + } +} + +static void key(unsigned char k, int x, int y) +{ + switch(k) { + case 27: + exit(0); + break; + + case 'a': + v+=0.005; + break; + case 'z': + v-=0.005; + break; + + case 'j': + joyactive=(!joyactive); + break; + case 'h': + help=(!help); + break; + case 'f': + fog=(!fog); + break; + case 't': + usetex=(!usetex); + break; + case 'b': + if(bfcull) { + glDisable(GL_CULL_FACE); + bfcull=0; + } else { + glEnable(GL_CULL_FACE); + bfcull=1; + } + break; +#ifdef XMESA + case ' ': + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + fullscreen=(!fullscreen); + break; +#endif + } +} + +static void reshape(int w, int h) +{ + WIDTH=w; + HEIGHT=h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0,w/(float)h,0.2,40.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0,0,w,h); +} + +static void printstring(void *font, char *string) +{ + int len,i; + + len=(int)strlen(string); + for(i=0;i<len;i++) + glutBitmapCharacter(font,string[i]); +} + +static void printhelp(void) +{ + glEnable(GL_BLEND); + glColor4f(0.5,0.5,0.5,0.5); + glRecti(40,40,600,440); + glDisable(GL_BLEND); + + glColor3f(1.0,0.0,0.0); + glRasterPos2i(300,420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"Help"); + + glRasterPos2i(60,390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"h - Toggle Help"); + glRasterPos2i(60,360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"t - Toggle Textures"); + glRasterPos2i(60,330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"f - Toggle Fog"); + glRasterPos2i(60,300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"b - Toggle Back face culling"); + glRasterPos2i(60,270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"Arrow Keys - Rotate"); + glRasterPos2i(60,240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"a - Increase velocity"); + glRasterPos2i(60,210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"z - Decrease velocity"); + + glRasterPos2i(60,180); + if(joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24,"(No Joystick control available)"); +} + +static void drawbase(void) +{ + static const GLfloat amb[4] = { 1, .5, 0.2, 1 }; + static const GLfloat diff[4] = { 1, .4, 0.2, 1 }; + int i,j; + float x,y,dx,dy; + + glBindTexture(GL_TEXTURE_2D,t1id); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff); + dx=BASESIZE/BASERES; + dy=-BASESIZE/BASERES; + for(y=BASESIZE/2.0,j=0;j<BASERES;y+=dy,j++) { + glBegin(GL_QUAD_STRIP); + glColor3f(1.0,1.0,1.0); + glNormal3f(0.0,0.0,1.0); + for(x=-BASESIZE/2.0,i=0;i<BASERES;x+=dx,i++) { + glTexCoord2f(x,y); + glVertex3f(x,y,0.0); + + glTexCoord2f(x,y+dy); + glVertex3f(x,y+dy,0.0); + } + glEnd(); + } +} + +static void drawteapot(void) +{ + static const GLfloat amb[4] = { 0.2, 0.2, 0.2, 1 }; + static const GLfloat diff[4] = { 0.8, 0.3, 0.5, 1 }; + static float xrot=0.0; + static float zrot=0.0; + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff); + + glPushMatrix(); + glRotatef(lightalpha,0.0,0.0,1.0); + glMultMatrixf((GLfloat *)baseshadow); + glRotatef(-lightalpha,0.0,0.0,1.0); + + glTranslatef(0.0,0.0,1.0); + glRotatef(xrot,1.0,0.0,0.0); + glRotatef(zrot,0.0,0.0,1.0); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glColor3f(0.0,0.0,0.0); + glCallList(teapotdlist); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + if(usetex) + glEnable(GL_TEXTURE_2D); + + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.0,0.0,1.0); + glRotatef(xrot,1.0,0.0,0.0); + glRotatef(zrot,0.0,0.0,1.0); + + glCallList(teapotdlist); + glPopMatrix(); + + xrot+=2.0; + zrot+=1.0; +} + +static void drawlight1(void) +{ + glPushMatrix(); + glRotatef(lightalpha,0.0,0.0,1.0); + glLightfv(GL_LIGHT0,GL_POSITION,lightpos); + glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,lightdir); + + glPopMatrix(); +} + +static void drawlight2(void) +{ + glPushMatrix(); + glRotatef(lightalpha,0.0,0.0,1.0); + glTranslatef(lightpos[0],lightpos[1],lightpos[2]); + + glDisable(GL_TEXTURE_2D); + glCallList(lightdlist); + if(usetex) + glEnable(GL_TEXTURE_2D); + + glPopMatrix(); + + lightalpha+=1.0; +} + +static void dojoy(void) +{ +#ifdef WIN32 + static UINT max[2]={0,0}; + static UINT min[2]={0xffffffff,0xffffffff},center[2]; + MMRESULT res; + JOYINFO joy; + + res=joyGetPos(JOYSTICKID1,&joy); + + if(res==JOYERR_NOERROR) { + joyavailable=1; + + if(max[0]<joy.wXpos) + max[0]=joy.wXpos; + if(min[0]>joy.wXpos) + min[0]=joy.wXpos; + center[0]=(max[0]+min[0])/2; + + if(max[1]<joy.wYpos) + max[1]=joy.wYpos; + if(min[1]>joy.wYpos) + min[1]=joy.wYpos; + center[1]=(max[1]+min[1])/2; + + if(joyactive) { + if(fabs(center[0]-(float)joy.wXpos)>0.1*(max[0]-min[0])) + alpha-=2.5*(center[0]-(float)joy.wXpos)/(max[0]-min[0]); + if(fabs(center[1]-(float)joy.wYpos)>0.1*(max[1]-min[1])) + beta+=2.5*(center[1]-(float)joy.wYpos)/(max[1]-min[1]); + + if(joy.wButtons & JOY_BUTTON1) + v+=0.005; + if(joy.wButtons & JOY_BUTTON2) + v-=0.005; + } + } else + joyavailable=0; +#endif +} + +static void draw(void) +{ + static char frbuf[80] = ""; + + dojoy(); + + glEnable(GL_DEPTH_TEST); + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + if(usetex) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if(fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glEnable(GL_LIGHTING); + + glShadeModel(GL_SMOOTH); + + glPushMatrix(); + calcposobs(); + + gluLookAt(obs[0],obs[1],obs[2], + obs[0]+dir[0],obs[1]+dir[1],obs[2]+dir[2], + 0.0,0.0,1.0); + + drawlight1(); + glCallList(basedlist); + drawteapot(); + drawlight2(); + glPopMatrix(); + + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5,639.5,-0.5,479.5,-1.0,1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0,0.0,0.0); + glRasterPos2i(10,10); + printstring(GLUT_BITMAP_HELVETICA_18,frbuf); + glRasterPos2i(350,470); + printstring(GLUT_BITMAP_HELVETICA_10,"Teapot V1.2 Written by David Bucciarelli ([email protected])"); + + if(help) + printhelp(); + + reshape(WIDTH,HEIGHT); + + glutSwapBuffers(); + + Frames++; + + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + +static void inittextures(void) +{ + glGenTextures(1,&t1id); + glBindTexture(GL_TEXTURE_2D,t1id); + + glPixelStorei(GL_UNPACK_ALIGNMENT,4); + if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB)) { + fprintf(stderr,"Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); + + glGenTextures(1,&t2id); + glBindTexture(GL_TEXTURE_2D,t2id); + + glPixelTransferf(GL_RED_SCALE, 0.75); + glPixelTransferf(GL_RED_BIAS, 0.25); + glPixelTransferf(GL_GREEN_SCALE, 0.75); + glPixelTransferf(GL_GREEN_BIAS, 0.25); + glPixelTransferf(GL_BLUE_SCALE, 0.75); + glPixelTransferf(GL_BLUE_BIAS, 0.25); + + if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB)) { + fprintf(stderr,"Error reading a texture.\n"); + exit(-1); + } + + glPixelTransferf(GL_RED_SCALE, 1.0); + glPixelTransferf(GL_RED_BIAS, 0.0); + glPixelTransferf(GL_GREEN_SCALE, 1.0); + glPixelTransferf(GL_GREEN_BIAS, 0.0); + glPixelTransferf(GL_BLUE_SCALE, 1.0); + glPixelTransferf(GL_BLUE_BIAS, 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_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); +} + +static void initlight(void) +{ + float matamb[4] ={0.5, 0.5, 0.5, 1.0}; + float matdiff[4]={0.9, 0.2, 0.2, 1.0}; + float matspec[4]={1.0,1.0,1.0,1.0}; + + float lamb[4] ={1.5, 1.5, 1.5, 1.0}; + float ldiff[4]={1.0, 1.0, 1.0, 1.0}; + float lspec[4]={1.0, 1.0, 1.0, 1.0}; + + glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,70.0); + glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,20.0); + glLightfv(GL_LIGHT0,GL_AMBIENT,lamb); + glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiff); + glLightfv(GL_LIGHT0,GL_SPECULAR,lspec); + + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 15.0); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matdiff); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matspec); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matamb); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lamb); + glEnable(GL_LIGHT0); +} + +static void initdlists(void) +{ + GLUquadricObj *lcone,*lbase; + GLfloat plane[4]; + GLfloat v0[3]={0.0,0.0,0.0}; + GLfloat v1[3]={1.0,0.0,0.0}; + GLfloat v2[3]={0.0,1.0,0.0}; + + findplane(plane,v0,v1,v2); + shadowmatrix(baseshadow,plane,lightpos); + + teapotdlist=glGenLists(1); + glNewList(teapotdlist,GL_COMPILE); + glRotatef(90.0,1.0,0.0,0.0); + glCullFace(GL_FRONT); + glBindTexture(GL_TEXTURE_2D,t2id); + glutSolidTeapot(0.75); + glCullFace(GL_BACK); + glEndList(); + + basedlist=glGenLists(1); + glNewList(basedlist,GL_COMPILE); + drawbase(); + glEndList(); + + lightdlist=glGenLists(1); + glNewList(lightdlist,GL_COMPILE); + glDisable(GL_LIGHTING); + + lcone=gluNewQuadric(); + lbase=gluNewQuadric(); + glRotatef(45.0,0.0,1.0,0.0); + + glColor3f(1.0,1.0,1.0); + glCullFace(GL_FRONT); + gluDisk(lbase,0.0,0.2,12.0,1.0); + glCullFace(GL_BACK); + + glColor3f(0.5,0.0,0.0); + gluCylinder(lcone,0.2,0.0,0.5,12,1); + + gluDeleteQuadric(lcone); + gluDeleteQuadric(lbase); + + glEnable(GL_LIGHTING); + glEndList(); +} + +int main(int ac, char **av) +{ + float fogcolor[4]={0.025,0.025,0.025,1.0}; + + fprintf(stderr,"Teapot V1.2\nWritten by David Bucciarelli ([email protected])\n"); + + /* + if(!SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)) { + fprintf(stderr,"Error setting the process class.\n"); + return 0; + } + + if(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL)) { + fprintf(stderr,"Error setting the process priority.\n"); + return 0; + } + */ + + glutInitWindowPosition(0,0); + glutInitWindowSize(WIDTH,HEIGHT); + glutInit(&ac,av); + + glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE); + + if(!(win=glutCreateWindow("Teapot"))) { + fprintf(stderr,"Error, couldn't open window\n"); + return -1; + } + + reshape(WIDTH,HEIGHT); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE,GL_EXP2); + glFogfv(GL_FOG_COLOR,fogcolor); + + glFogf(GL_FOG_DENSITY,0.04); + glHint(GL_FOG_HINT,GL_NICEST); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + calcposobs(); + + inittextures(); + initlight(); + + initdlists(); + + glClearColor(fogcolor[0],fogcolor[1],fogcolor[2],fogcolor[3]); + + glutReshapeFunc(reshape); + glutDisplayFunc(draw); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutIdleFunc(draw); + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c new file mode 100644 index 00000000000..be78ea4950f --- /dev/null +++ b/progs/demos/terrain.c @@ -0,0 +1,656 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + * + * based on a Mikael SkiZoWalker's (MoDEL) / France ([email protected]) demo + */ + +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <GL/glut.h> + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +#define heightMnt 450 +#define lenghtXmnt 62 +#define lenghtYmnt 62 + +#define stepXmnt 96.0 +#define stepYmnt 96.0 + +#define WIDTH 640 +#define HEIGHT 480 + +static GLint T0 = 0; +static GLint Frames = 0; + +#define TSCALE 4 + +#define FOV 85 + +static GLfloat terrain[256 * 256]; +static GLfloat terraincolor[256 * 256][3]; + +static int win = 0; + +static int fog = 1; +static int bfcull = 1; +static int usetex = 1; +static int poutline = 0; +static int help = 1; +static int joyavailable = 0; +static int joyactive = 0; +static float ModZMnt; +static long GlobalMnt = 0; + +static int scrwidth = WIDTH; +static int scrheight = HEIGHT; + +#define OBSSTARTX 992.0 +#define OBSSTARTY 103.0 + +static float obs[3] = { OBSSTARTX, heightMnt * 1.3, OBSSTARTY }; +static float dir[3], v1[2], v2[2]; +static float v = 900.0; +static float alpha = 75.0; +static float beta = 90.0; + +static void +calcposobs(void) +{ + float alpha1, alpha2; + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + dir[0] = sin(alpha * M_PI / 180.0); + dir[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[1] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + alpha1 = alpha + FOV / 2.0; + v1[0] = sin(alpha1 * M_PI / 180.0); + v1[1] = cos(alpha1 * M_PI / 180.0); + + alpha2 = alpha - FOV / 2.0; + v2[0] = sin(alpha2 * M_PI / 180.0); + v2[1] = cos(alpha2 * M_PI / 180.0); + + obs[0] += v * dir[0] * dt; + obs[1] += v * dir[1] * dt; + obs[2] += v * dir[2] * dt; + + if (obs[1] < 0.0) + obs[1] = 0.0; +} + +static void +reshape(int width, int height) +{ + scrwidth = width; + scrheight = height; + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(50.0, ((GLfloat) width / (GLfloat) height), + lenghtXmnt * stepYmnt * 0.01, lenghtXmnt * stepYmnt * 0.7); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static int +clipstrip(float y, float *start, float *end) +{ + float x1, x2, t1, t2, tmp; + + if (v1[1] == 0.0) { + t1 = 0.0; + x1 = -HUGE_VAL; + } + else { + t1 = y / v1[1]; + x1 = t1 * v1[0]; + } + + if (v2[1] == 0.0) { + t2 = 0.0; + x2 = HUGE_VAL; + } + else { + t2 = y / v2[1]; + x2 = t2 * v2[0]; + } + + if (((x1 < -(lenghtXmnt * stepXmnt) / 2) && (t2 <= 0.0)) || + ((t1 <= 0.0) && (x2 > (lenghtXmnt * stepXmnt) / 2)) || + ((t1 < 0.0) && (t2 < 0.0))) + return 0; + + if ((t1 == 0.0) && (t2 == 0.0)) { + if ((v1[0] < 0.0) && (v1[1] > 0.0) && (v2[0] < 0.0) && (v2[1] < 0.0)) { + *start = -(lenghtXmnt * stepXmnt) / 2; + *end = stepXmnt; + return 1; + } + else { + if ((v1[0] > 0.0) && (v1[1] < 0.0) && (v2[0] > 0.0) && (v2[1] > 0.0)) { + *start = -stepXmnt; + *end = (lenghtXmnt * stepXmnt) / 2; + return 1; + } + else + return 0; + } + } + else { + if (t2 < 0.0) { + if (x1 < 0.0) + x2 = -(lenghtXmnt * stepXmnt) / 2; + else + x2 = (lenghtXmnt * stepXmnt) / 2; + } + + if (t1 < 0.0) { + if (x2 < 0.0) + x1 = -(lenghtXmnt * stepXmnt) / 2; + else + x1 = (lenghtXmnt * stepXmnt) / 2; + } + } + + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } + + x1 -= stepXmnt; + if (x1 < -(lenghtXmnt * stepXmnt) / 2) + x1 = -(lenghtXmnt * stepXmnt) / 2; + + x2 += stepXmnt; + if (x2 > (lenghtXmnt * stepXmnt) / 2) + x2 = (lenghtXmnt * stepXmnt) / 2; + + *start = ((int) (x1 / stepXmnt)) * stepXmnt; + *end = ((int) (x2 / stepXmnt)) * stepXmnt; + + return 1; +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +printhelp(void) +{ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.0, 0.0, 0.0, 0.5); + glRecti(40, 40, 600, 440); + glDisable(GL_BLEND); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); + glRasterPos2i(60, 360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); + glRasterPos2i(60, 300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "p - Wire frame"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling"); + glRasterPos2i(60, 240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); + glRasterPos2i(60, 180); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); + + glRasterPos2i(60, 150); + if (joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "(No Joystick control available)"); +} + +static void +drawterrain(void) +{ + int h, i, idx, ox, oy; + float j, k, start, end; + + ox = (int) (obs[0] / stepXmnt); + oy = (int) (obs[2] / stepYmnt); + GlobalMnt = ((ox * TSCALE) & 255) + ((oy * TSCALE) & 255) * 256; + + glPushMatrix(); + glTranslatef((float) ox * stepXmnt, 0, (float) oy * stepYmnt); + + for (h = 0, k = -(lenghtYmnt * stepYmnt) / 2; h < lenghtYmnt; + k += stepYmnt, h++) { + if (!clipstrip(k, &start, &end)) + continue; + + glBegin(GL_TRIANGLE_STRIP); /* I hope that the optimizer will be able to improve this code */ + for (i = (int) (lenghtXmnt / 2 + start / stepXmnt), j = start; j <= end; + j += stepXmnt, i++) { + idx = (i * TSCALE + h * 256 * TSCALE + GlobalMnt) & 65535; + glColor3fv(terraincolor[idx]); + glTexCoord2f((ox + i) / 8.0, (oy + h) / 8.0); + glVertex3f(j, terrain[idx], k); + + idx = + (i * TSCALE + h * 256 * TSCALE + 256 * TSCALE + + GlobalMnt) & 65535; + glColor3fv(terraincolor[idx]); + glTexCoord2f((ox + i) / 8.0, (oy + h + 1) / 8.0); + glVertex3f(j, terrain[idx], k + stepYmnt); + } + glEnd(); + } + + glDisable(GL_CULL_FACE); + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBegin(GL_QUADS); + glColor4f(0.1, 0.7, 1.0, 0.4); + glVertex3f(-(lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6, + -(lenghtYmnt * stepYmnt) / 2.0); + glVertex3f(-(lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6, + (lenghtYmnt * stepYmnt) / 2.0); + glVertex3f((lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6, + (lenghtYmnt * stepYmnt) / 2.0); + glVertex3f((lenghtXmnt * stepXmnt) / 2.0, heightMnt * 0.6, + -(lenghtYmnt * stepYmnt) / 2.0); + glEnd(); + glDisable(GL_BLEND); + if (bfcull) + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glPopMatrix(); + +} + +static void +dojoy(void) +{ +#ifdef WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha += + 2.5 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.5 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.5; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.5; + } + } + else + joyavailable = 0; +#endif +} + +static void +drawscene(void) +{ + static char frbuf[80] = ""; + + dojoy(); + + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + + if (usetex) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + calcposobs(); + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 1.0, 0.0); + + drawterrain(); + glPopMatrix(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(350, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "Terrain V1.2 Written by David Bucciarelli ([email protected])"); + glRasterPos2i(434, 457); + printstring(GLUT_BITMAP_HELVETICA_10, + "Based on a Mickael's demo ([email protected])"); + + if (help) + printhelp(); + + reshape(scrwidth, scrheight); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: + exit(0); + break; + case 'a': + v += 50.; + break; + case 'z': + v -= 50.; + break; + case 'p': + if (poutline) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + poutline = 0; + } + else { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + poutline = 1; + } + break; + case 'j': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + case 't': + usetex = (!usetex); + break; + case 'b': + if (bfcull) { + glDisable(GL_CULL_FACE); + bfcull = 0; + } + else { + glEnable(GL_CULL_FACE); + bfcull = 1; + } + break; +#ifdef XMESA + case ' ': + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + fullscreen = (!fullscreen); + break; +#endif + } +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_LEFT: + alpha += 2.0; + break; + case GLUT_KEY_RIGHT: + alpha -= 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } +} + +static void +calccolor(GLfloat height, GLfloat c[3]) +{ + GLfloat color[4][3] = { + {1.0, 1.0, 1.0}, + {0.0, 0.8, 0.0}, + {1.0, 1.0, 0.3}, + {0.0, 0.0, 0.8} + }; + GLfloat fact; + + height = height * (1.0 / 255.0); + + if (height >= 0.9) { + c[0] = color[0][0]; + c[1] = color[0][1]; + c[2] = color[0][2]; + return; + } + + if ((height < 0.9) && (height >= 0.7)) { + fact = (height - 0.7) * 5.0; + c[0] = fact * color[0][0] + (1.0 - fact) * color[1][0]; + c[1] = fact * color[0][1] + (1.0 - fact) * color[1][1]; + c[2] = fact * color[0][2] + (1.0 - fact) * color[1][2]; + return; + } + + if ((height < 0.7) && (height >= 0.6)) { + fact = (height - 0.6) * 10.0; + c[0] = fact * color[1][0] + (1.0 - fact) * color[2][0]; + c[1] = fact * color[1][1] + (1.0 - fact) * color[2][1]; + c[2] = fact * color[1][2] + (1.0 - fact) * color[2][2]; + return; + } + + if ((height < 0.6) && (height >= 0.5)) { + fact = (height - 0.5) * 10.0; + c[0] = fact * color[2][0] + (1.0 - fact) * color[3][0]; + c[1] = fact * color[2][1] + (1.0 - fact) * color[3][1]; + c[2] = fact * color[2][2] + (1.0 - fact) * color[3][2]; + return; + } + + c[0] = color[3][0]; + c[1] = color[3][1]; + c[2] = color[3][2]; +} + +static void +loadpic(void) +{ + GLubyte bufferter[256 * 256], terrainpic[256 * 256]; + FILE *FilePic; + int i, tmp; + GLenum gluerr; + + if ((FilePic = fopen("terrain.dat", "r")) == NULL) { + fprintf(stderr, "Error loading terrain.dat\n"); + exit(-1); + } + fread(bufferter, 256 * 256, 1, FilePic); + fclose(FilePic); + + for (i = 0; i < (256 * 256); i++) { + terrain[i] = (bufferter[i] * (heightMnt / 255.0f)); + calccolor((GLfloat) bufferter[i], terraincolor[i]); + tmp = (((int) bufferter[i]) + 96); + terrainpic[i] = (tmp > 255) ? 255 : tmp; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 256, 256, GL_LUMINANCE, + GL_UNSIGNED_BYTE, + (GLvoid *) (&terrainpic[0])))) { + fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glEnable(GL_TEXTURE_2D); +} + +static void +init(void) +{ + float fogcolor[4] = { 0.6, 0.7, 0.7, 1.0 }; + + glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); + glClearDepth(1.0); + glDepthFunc(GL_LEQUAL); + glShadeModel(GL_SMOOTH); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + + glDisable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogfv(GL_FOG_COLOR, fogcolor); + glFogf(GL_FOG_DENSITY, 0.0007); +#ifdef FX + glHint(GL_FOG_HINT, GL_NICEST); +#endif + + reshape(scrwidth, scrheight); +} + + +int +main(int ac, char **av) +{ + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + if (!(win = glutCreateWindow("Terrain"))) { + fprintf(stderr, "Error, couldn't open window\n"); + return -1; + } + + ModZMnt = 0.0f; + loadpic(); + + init(); + +#ifndef FX + glDisable(GL_TEXTURE_2D); + usetex = 0; +#endif + + glutReshapeFunc(reshape); + glutDisplayFunc(drawscene); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutIdleFunc(drawscene); + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/terrain.dat b/progs/demos/terrain.dat new file mode 100644 index 00000000000..2af385e9c25 --- /dev/null +++ b/progs/demos/terrain.dat @@ -0,0 +1 @@ +�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ÿ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¿�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ŀ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ÿ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¿������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ŀ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������½��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¿��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ÿ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ž��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ü�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ǿ�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¼��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ľ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ž������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ſ�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������þ�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ŀ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������½�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¾���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ÿ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Ŀ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������¿����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ž�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ÿ��������������������������½���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������½�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������½�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ü�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ž�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������þ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������0
\ No newline at end of file diff --git a/progs/demos/tessdemo.c b/progs/demos/tessdemo.c new file mode 100644 index 00000000000..26403eee0a2 --- /dev/null +++ b/progs/demos/tessdemo.c @@ -0,0 +1,524 @@ + +/* + * A demo of the GLU polygon tesselation functions written by Bogdan Sikorski. + * Updated for GLU 1.3 tessellation by Gareth Hughes <[email protected]> + */ + +#include <GL/glut.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAX_POINTS 256 +#define MAX_CONTOURS 32 +#define MAX_TRIANGLES 256 + +#ifndef GLCALLBACK +#ifdef CALLBACK +#define GLCALLBACK CALLBACK +#else +#define GLCALLBACK +#endif +#endif + +#ifdef GLU_VERSION_1_2 + +typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries; +typedef enum{ DEFINE, TESSELATED } mode_type; + +static GLsizei width, height; +static GLuint contour_cnt; +static GLuint triangle_cnt; + +static mode_type mode; +static int menu; + +static GLuint list_start; + +static GLfloat edge_color[3]; + +static struct { + GLfloat p[MAX_POINTS][2]; + GLuint point_cnt; +} contours[MAX_CONTOURS]; + +static struct { + GLsizei no; + GLfloat p[3][2]; + GLclampf color[3][3]; +} triangles[MAX_TRIANGLES]; + + + +static void GLCALLBACK error_callback( 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 ; i < len ; i++ ) { + glutBitmapCharacter( GLUT_BITMAP_9_BY_15, str[i] ); + } +} + +static void GLCALLBACK begin_callback( GLenum mode ) +{ + /* Allow multiple triangles to be output inside the begin/end pair. */ + triangle_cnt = 0; + triangles[triangle_cnt].no = 0; +} + +static void GLCALLBACK edge_callback( GLenum flag ) +{ + /* Persist the edge flag across triangles. */ + if ( flag == GL_TRUE ) { + edge_color[0] = 1.0; + edge_color[1] = 1.0; + edge_color[2] = 0.5; + } else { + edge_color[0] = 1.0; + edge_color[1] = 0.0; + edge_color[2] = 0.0; + } +} + +static void GLCALLBACK end_callback() +{ + GLuint i; + + glBegin( GL_LINES ); + + /* Output the three edges of each triangle as lines colored + according to their edge flag. */ + for ( i = 0 ; i < triangle_cnt ; i++ ) { + glColor3f( triangles[i].color[0][0], + triangles[i].color[0][1], + triangles[i].color[0][2] ); + + glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] ); + glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] ); + + glColor3f( triangles[i].color[1][0], + triangles[i].color[1][1], + triangles[i].color[1][2] ); + + glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] ); + glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] ); + + glColor3f( triangles[i].color[2][0], + triangles[i].color[2][1], + triangles[i].color[2][2] ); + + glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] ); + glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] ); + } + + glEnd(); +} + +static void GLCALLBACK vertex_callback( void *data ) +{ + GLsizei no; + GLfloat *p; + + p = (GLfloat *) data; + no = triangles[triangle_cnt].no; + + triangles[triangle_cnt].p[no][0] = p[0]; + triangles[triangle_cnt].p[no][1] = p[1]; + + triangles[triangle_cnt].color[no][0] = edge_color[0]; + triangles[triangle_cnt].color[no][1] = edge_color[1]; + triangles[triangle_cnt].color[no][2] = edge_color[2]; + + /* After every three vertices, initialize the next triangle. */ + if ( ++(triangles[triangle_cnt].no) == 3 ) { + triangle_cnt++; + triangles[triangle_cnt].no = 0; + } +} + +static void GLCALLBACK combine_callback( GLdouble coords[3], + GLdouble *vertex_data[4], + GLfloat weight[4], void **data ) +{ + GLfloat *vertex; + + vertex = (GLfloat *) malloc( 2 * sizeof(GLfloat) ); + + vertex[0] = (GLfloat) coords[0]; + vertex[1] = (GLfloat) coords[1]; + + *data = vertex; +} + + +static void set_screen_wh( GLsizei w, GLsizei h ) +{ + width = w; + height = h; +} + +typedef void (GLAPIENTRY *callback_t)(); + +static void tesse( void ) +{ + GLUtesselator *tobj; + GLdouble data[3]; + GLuint i, j, point_cnt; + + list_start = glGenLists( 2 ); + + tobj = gluNewTess(); + + if ( tobj != NULL ) { + gluTessNormal( tobj, 0.0, 0.0, 1.0 ); + gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) glBegin ); + gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) glVertex2fv ); + gluTessCallback( tobj, GLU_TESS_END, (callback_t) glEnd ); + gluTessCallback( tobj, GLU_TESS_ERROR, (callback_t) error_callback ); + gluTessCallback( tobj, GLU_TESS_COMBINE, (callback_t) combine_callback ); + + glNewList( list_start, GL_COMPILE ); + gluBeginPolygon( tobj ); + + for ( j = 0 ; j <= contour_cnt ; j++ ) { + point_cnt = contours[j].point_cnt; + gluNextContour( tobj, GLU_UNKNOWN ); + + for ( i = 0 ; i < point_cnt ; i++ ) { + data[0] = (GLdouble)( contours[j].p[i][0] ); + data[1] = (GLdouble)( contours[j].p[i][1] ); + data[2] = 0.0; + gluTessVertex( tobj, data, contours[j].p[i] ); + } + } + + gluEndPolygon( tobj ); + glEndList(); + + gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) begin_callback ); + gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) vertex_callback ); + gluTessCallback( tobj, GLU_TESS_END, (callback_t) end_callback ); + gluTessCallback( tobj, GLU_TESS_EDGE_FLAG, (callback_t) edge_callback ); + + glNewList( list_start + 1, GL_COMPILE ); + gluBeginPolygon( tobj ); + + for ( j = 0 ; j <= contour_cnt ; j++ ) { + point_cnt = contours[j].point_cnt; + gluNextContour( tobj, GLU_UNKNOWN ); + + for ( i = 0 ; i < point_cnt ; i++ ) { + data[0] = (GLdouble)( contours[j].p[i][0] ); + data[1] = (GLdouble)( contours[j].p[i][1] ); + data[2] = 0.0; + gluTessVertex( tobj, data, contours[j].p[i] ); + } + } + + gluEndPolygon( tobj ); + glEndList(); + + gluDeleteTess( tobj ); + + glutMouseFunc( NULL ); + mode = TESSELATED; + } +} + +static void left_down( int x1, int y1 ) +{ + GLfloat P[2]; + GLuint point_cnt; + + /* translate GLUT into GL coordinates */ + + P[0] = x1; + P[1] = height - y1; + + point_cnt = contours[contour_cnt].point_cnt; + + contours[contour_cnt].p[point_cnt][0] = P[0]; + contours[contour_cnt].p[point_cnt][1] = P[1]; + + glBegin( GL_LINES ); + + if ( point_cnt ) { + glVertex2fv( contours[contour_cnt].p[point_cnt-1] ); + glVertex2fv( P ); + } else { + glVertex2fv( P ); + glVertex2fv( P ); + } + + glEnd(); + glFinish(); + + contours[contour_cnt].point_cnt++; +} + +static void middle_down( int x1, int y1 ) +{ + GLuint point_cnt; + (void) x1; + (void) y1; + + point_cnt = contours[contour_cnt].point_cnt; + + if ( point_cnt > 2 ) { + glBegin( GL_LINES ); + + glVertex2fv( contours[contour_cnt].p[0] ); + glVertex2fv( 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; + } +} + +static 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; + } +} + +static void display( void ) +{ + GLuint i,j; + GLsizei ii, jj; + 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 ( ii = 0 ; ii < width ; ii += 10 ) { + for ( jj = 0 ; jj < height ; jj += 10 ) { + glVertex2i( 0, jj ); + glVertex2i( width, jj ); + glVertex2i( ii, height ); + glVertex2i( ii, 0 ); + } + } + + glEnd(); + + glColor3f( 1.0, 1.0, 0.0 ); + + for ( i = 0 ; i <= contour_cnt ; i++ ) { + point_cnt = contours[i].point_cnt; + + glBegin( GL_LINES ); + + switch ( point_cnt ) { + case 0: + break; + case 1: + glVertex2fv( contours[i].p[0] ); + glVertex2fv( contours[i].p[0] ); + break; + case 2: + glVertex2fv( contours[i].p[0] ); + glVertex2fv( contours[i].p[1] ); + break; + default: + --point_cnt; + for ( j = 0 ; j < point_cnt ; j++ ) { + glVertex2fv( contours[i].p[j] ); + glVertex2fv( contours[i].p[j+1] ); + } + if ( contours[i].p[j+1][0] == -1 ) { + glVertex2fv( contours[i].p[0] ); + glVertex2fv( contours[i].p[j] ); + } + break; + } + + glEnd(); + } + + glFinish(); + break; + + case TESSELATED: + /* draw triangles */ + glColor3f( 0.7, 0.7, 0.0 ); + glCallList( list_start ); + + glLineWidth( 2.0 ); + glCallList( list_start + 1 ); + glLineWidth( 1.0 ); + + glFlush(); + break; + } + + glColor3f( 1.0, 1.0, 0.0 ); +} + +static void clear( void ) +{ + contour_cnt = 0; + contours[0].point_cnt = 0; + triangle_cnt = 0; + + glutMouseFunc( mouse_clicked ); + + mode = DEFINE; + + glDeleteLists( list_start, 2 ); + list_start = 0; +} + +static void quit( void ) +{ + exit( 0 ); +} + +static void menu_selected( int entry ) +{ + switch ( entry ) { + case CLEAR: + clear(); + break; + case TESSELATE: + tesse(); + break; + case QUIT: + quit(); + break; + } + + glutPostRedisplay(); +} + +static void key_pressed( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + + switch ( key ) { + case 'c': + case 'C': + clear(); + break; + case 't': + case 'T': + tesse(); + break; + case 27: + case 'q': + case 'Q': + quit(); + break; + } + + glutPostRedisplay(); +} + +static void myinit( void ) +{ + /* clear background to gray */ + glClearColor( 0.4, 0.4, 0.4, 0.0 ); + glShadeModel( GL_FLAT ); + glPolygonMode( GL_FRONT, GL_FILL ); + + menu = glutCreateMenu( menu_selected ); + + glutAddMenuEntry( "clear", CLEAR ); + glutAddMenuEntry( "tesselate", TESSELATE ); + glutAddMenuEntry( "quit", QUIT ); + + glutAttachMenu( GLUT_RIGHT_BUTTON ); + + glutMouseFunc( mouse_clicked ); + glutKeyboardFunc( key_pressed ); + + contour_cnt = 0; + mode = DEFINE; +} + +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(); + + set_screen_wh( w, h ); +} + +#endif + + +static void usage( void ) +{ + printf( "Use left mouse button to place vertices.\n" ); + printf( "Press middle mouse button when done.\n" ); + printf( "Select tesselate from the pop-up menu.\n" ); +} + + +int main( int argc, char **argv ) +{ + const char *version = (const char *) gluGetString( GLU_VERSION ); + printf( "GLU version string: %s\n", version ); + if ( strstr( version, "1.0" ) || strstr( version, "1.1" ) ) { + fprintf( stderr, "Sorry, this demo reqiures GLU 1.2 or later.\n" ); + exit( 1 ); + } + + usage(); + + glutInit( &argc, argv ); + glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); + glutInitWindowPosition(0, 0); + glutInitWindowSize( 400, 400 ); + glutCreateWindow( argv[0] ); + + /* GH: Bit of a hack... + */ +#ifdef GLU_VERSION_1_2 + myinit(); + + glutDisplayFunc( display ); + glutReshapeFunc( reshape ); + + glutMainLoop(); +#endif + + return 0; +} diff --git a/progs/demos/texcyl.c b/progs/demos/texcyl.c new file mode 100644 index 00000000000..c04d5004e37 --- /dev/null +++ b/progs/demos/texcyl.c @@ -0,0 +1,288 @@ + +/* + * Textured cylinder demo: lighting, texturing, reflection mapping. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul May 1997 This program is in the public domain. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" + +#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 = 50.0, DYrot = 125.0; + +/* performance info */ +static GLint T0 = 0; +static GLint Frames = 0; + + +static void Idle( void ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + if (Animate) { + Xrot += DXrot * dt; + Yrot += DYrot * dt; + 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(); + + if (Animate) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + Frames++; + 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 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; + if (Animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + } + 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 ' ': + Animate = !Animate; + if (Animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + 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( int argc, char *argv[] ) +{ + 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); + + if (argc > 1 && strcmp(argv[1], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowSize( 400, 400 ); + glutInitWindowPosition( 0, 0 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + + glutCreateWindow(argv[0] ); + + Init(argc, argv); + + 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/texdown.c b/progs/demos/texdown.c new file mode 100644 index 00000000000..79525a0395e --- /dev/null +++ b/progs/demos/texdown.c @@ -0,0 +1,403 @@ + +/* + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * texdown + * + * Measure texture download speed. + * Use keyboard to change texture size, format, datatype, scale/bias, + * subimageload, etc. + * + * Brian Paul 28 January 2000 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +static GLsizei MaxSize = 1024; +static GLsizei TexWidth = 256, TexHeight = 256, TexBorder = 0; +static GLboolean ScaleAndBias = GL_FALSE; +static GLboolean SubImage = GL_FALSE; +static GLdouble DownloadRate = 0.0; /* texels/sec */ + +static GLuint Mode = 0; + + +struct FormatRec { + GLenum Format; + GLenum Type; + GLenum IntFormat; + GLint TexelSize; +}; + + +static const struct FormatRec FormatTable[] = { + /* Format Type IntFormat TexelSize */ + { GL_BGRA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, + { GL_RGB, GL_UNSIGNED_BYTE, GL_RGB, 3 }, + { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, + { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB, 4 }, + { GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, 2 }, + { GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE, 1 }, + { GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA, 2 }, + { GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA, 1 }, +}; +static GLint Format; + +#define NUM_FORMATS (sizeof(FormatTable)/sizeof(FormatTable[0])) + +static int +BytesPerTexel(GLint format) +{ + return FormatTable[format].TexelSize; +} + + +static const char * +FormatStr(GLenum format) +{ + switch (format) { + case GL_RGB: + return "GL_RGB"; + case GL_RGBA: + return "GL_RGBA"; + case GL_BGRA: + return "GL_BGRA"; + case GL_LUMINANCE: + return "GL_LUMINANCE"; + case GL_LUMINANCE_ALPHA: + return "GL_LUMINANCE_ALPHA"; + case GL_ALPHA: + return "GL_ALPHA"; + default: + return ""; + } +} + + +static const char * +TypeStr(GLenum type) +{ + switch (type) { + case GL_UNSIGNED_BYTE: + return "GL_UNSIGNED_BYTE"; + case GL_UNSIGNED_SHORT: + return "GL_UNSIGNED_SHORT"; + case GL_UNSIGNED_SHORT_5_6_5: + return "GL_UNSIGNED_SHORT_5_6_5"; + case GL_UNSIGNED_SHORT_5_6_5_REV: + return "GL_UNSIGNED_SHORT_5_6_5_REV"; + default: + return ""; + } +} + + +static void +MeasureDownloadRate(void) +{ + const int w = TexWidth + 2 * TexBorder; + const int h = TexHeight + 2 * TexBorder; + const int bytes = w * h * BytesPerTexel(Format); + GLubyte *texImage, *getImage; + GLdouble t0, t1, time; + int count; + int i; + + texImage = (GLubyte *) malloc(bytes); + getImage = (GLubyte *) malloc(bytes); + if (!texImage || !getImage) { + DownloadRate = 0.0; + return; + } + + for (i = 0; i < bytes; i++) { + texImage[i] = i & 0xff; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + if (ScaleAndBias) { + glPixelTransferf(GL_RED_SCALE, 0.5); + glPixelTransferf(GL_GREEN_SCALE, 0.5); + glPixelTransferf(GL_BLUE_SCALE, 0.5); + glPixelTransferf(GL_RED_BIAS, 0.5); + glPixelTransferf(GL_GREEN_BIAS, 0.5); + glPixelTransferf(GL_BLUE_BIAS, 0.5); + } + else { + glPixelTransferf(GL_RED_SCALE, 1.0); + glPixelTransferf(GL_GREEN_SCALE, 1.0); + glPixelTransferf(GL_BLUE_SCALE, 1.0); + glPixelTransferf(GL_RED_BIAS, 0.0); + glPixelTransferf(GL_GREEN_BIAS, 0.0); + glPixelTransferf(GL_BLUE_BIAS, 0.0); + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glEnable(GL_TEXTURE_2D); + + count = 0; + t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + do { + if (SubImage && count > 0) { + glTexSubImage2D(GL_TEXTURE_2D, 0, -TexBorder, -TexBorder, w, h, + FormatTable[Format].Format, + FormatTable[Format].Type, texImage); + } + else { + glTexImage2D(GL_TEXTURE_2D, 0, + FormatTable[Format].IntFormat, w, h, TexBorder, + FormatTable[Format].Format, + FormatTable[Format].Type, texImage); + } + + /* draw a tiny polygon to force texture into texram */ + glBegin(GL_TRIANGLES); + glTexCoord2f(0, 0); glVertex2f(1, 1); + glTexCoord2f(1, 0); glVertex2f(3, 1); + glTexCoord2f(0.5, 1); glVertex2f(2, 3); + glEnd(); + + t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + time = t1 - t0; + count++; + } while (time < 3.0); + + glDisable(GL_TEXTURE_2D); + + printf("w*h=%d count=%d time=%f\n", w*h, count, time); + DownloadRate = w * h * count / time; + +#if 0 + if (!ScaleAndBias) { + /* verify texture readback */ + glGetTexImage(GL_TEXTURE_2D, 0, + FormatTable[Format].Format, + FormatTable[Format].Type, getImage); + for (i = 0; i < w * h; i++) { + if (texImage[i] != getImage[i]) { + printf("[%d] %d != %d\n", i, texImage[i], getImage[i]); + } + } + } +#endif + + free(texImage); + free(getImage); + + { + GLint err = glGetError(); + if (err) + printf("GL error %d\n", err); + } +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +Display(void) +{ + const int w = TexWidth + 2 * TexBorder; + const int h = TexHeight + 2 * TexBorder; + char s[1000]; + + glClear(GL_COLOR_BUFFER_BIT); + + glRasterPos2i(10, 80); + sprintf(s, "Texture size[cursor]: %d x %d Border[b]: %d", w, h, TexBorder); + PrintString(s); + + glRasterPos2i(10, 65); + sprintf(s, "Format[f]: %s Type: %s IntFormat: %s", + FormatStr(FormatTable[Format].Format), + TypeStr( FormatTable[Format].Type), + FormatStr(FormatTable[Format].IntFormat)); + PrintString(s); + + glRasterPos2i(10, 50); + sprintf(s, "Pixel Scale&Bias[p]: %s TexSubImage[s]: %s", + ScaleAndBias ? "Yes" : "No", + SubImage ? "Yes" : "No"); + PrintString(s); + + if (Mode == 0) { + glRasterPos2i(200, 10); + sprintf(s, "...Measuring..."); + PrintString(s); + glutSwapBuffers(); + glutPostRedisplay(); + Mode++; + } + else if (Mode == 1) { + MeasureDownloadRate(); + glutPostRedisplay(); + Mode++; + } + else { + /* show results */ + glRasterPos2i(10, 10); + sprintf(s, "Download rate: %g Mtexels/second %g MB/second", + DownloadRate / 1000000.0, + DownloadRate * BytesPerTexel(Format) / 1000000.0); + PrintString(s); + { + GLint r, g, b, a, l, i; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &r); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &g); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &b); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &a); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &l); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &i); + sprintf(s, "TexelBits: R=%d G=%d B=%d A=%d L=%d I=%d", r, g, b, a, l, i); + glRasterPos2i(10, 25); + PrintString(s); + } + + glutSwapBuffers(); + } +} + + +static void +Reshape(int width, int height) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); +} + + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case ' ': + Mode = 0; + break; + case 'b': + /* toggle border */ + TexBorder = 1 - TexBorder; + Mode = 0; + break; + case 'f': + /* change format */ + Format = (Format + 1) % NUM_FORMATS; + Mode = 0; + break; + case 'F': + /* change format */ + Format = (Format - 1) % NUM_FORMATS; + Mode = 0; + break; + case 'p': + /* toggle border */ + ScaleAndBias = !ScaleAndBias; + Mode = 0; + break; + case 's': + SubImage = !SubImage; + Mode = 0; + 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: + if (TexHeight < MaxSize) + TexHeight *= 2; + break; + case GLUT_KEY_DOWN: + if (TexHeight > 1) + TexHeight /= 2; + break; + case GLUT_KEY_LEFT: + if (TexWidth > 1) + TexWidth /= 2; + break; + case GLUT_KEY_RIGHT: + if (TexWidth < MaxSize) + TexWidth *= 2; + break; + } + Mode = 0; + glutPostRedisplay(); +} + + +static void +Init(void) +{ + printf("GL_VENDOR = %s\n", (const char *) glGetString(GL_VENDOR)); + printf("GL_VERSION = %s\n", (const char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 600, 100 ); + 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/demos/texenv.c b/progs/demos/texenv.c new file mode 100644 index 00000000000..590867b4945 --- /dev/null +++ b/progs/demos/texenv.c @@ -0,0 +1,815 @@ + +/* 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. + */ + +/* + * Demonstrates texture environment modes and internal image formats. + */ + +/* + * Hacked on, updated by Gareth Hughes <[email protected]> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glut.h> + +#undef max +#undef min +#define max( a, b ) ((a) >= (b) ? (a) : (b)) +#define min( a, b ) ((a) <= (b) ? (a) : (b)) + +GLfloat lightCheck[4] = { 0.7, 0.7, 0.7, 1.0 }; +GLfloat darkCheck[4] = { 0.3, 0.3, 0.3, 1.0 }; + +GLfloat labelColor0[4] = { 1.0, 1.0, 1.0, 1.0 }; +GLfloat labelColor1[4] = { 1.0, 1.0, 0.4, 1.0 }; +GLfloat *labelInfoColor = labelColor0; +GLfloat labelLevelColor0[4] = { 0.8, 0.8, 0.1, 1.0 }; +GLfloat labelLevelColor1[4] = { 0.0, 0.0, 0.0, 1.0 }; + +GLboolean doubleBuffered = GL_TRUE; +GLboolean drawBackground = GL_FALSE; +GLboolean drawBlended = GL_TRUE; +GLboolean drawSmooth = GL_FALSE; +GLboolean drawTextured = GL_TRUE; +GLboolean displayLevelInfo = GL_FALSE; + +int textureWidth = 64; +int textureHeight = 64; + +int winWidth = 580, winHeight = 720; + +struct formatInfo { + GLenum baseFormat; + GLenum internalFormat; + char *name; +}; + +#define NUM_LUMINANCE_FORMATS (sizeof(luminanceFormats) / sizeof(luminanceFormats[0])) +struct formatInfo luminanceFormats[] = +{ + { GL_LUMINANCE, GL_LUMINANCE, "LUMINANCE" }, + { GL_LUMINANCE, GL_LUMINANCE4, "LUMINANCE4" }, + { GL_LUMINANCE, GL_LUMINANCE8, "LUMINANCE8" }, + { GL_LUMINANCE, GL_LUMINANCE12, "LUMINANCE12" }, + { GL_LUMINANCE, GL_LUMINANCE16, "LUMINANCE16" }, +}; + +#define NUM_ALPHA_FORMATS (sizeof(alphaFormats) / sizeof(alphaFormats[0])) +struct formatInfo alphaFormats[] = +{ + { GL_ALPHA, GL_ALPHA, "ALPHA" }, + { GL_ALPHA, GL_ALPHA4, "ALPHA4" }, + { GL_ALPHA, GL_ALPHA8, "ALPHA8" }, + { GL_ALPHA, GL_ALPHA12, "ALPHA12" }, + { GL_ALPHA, GL_ALPHA16, "ALPHA16" }, +}; + +#define NUM_INTENSITY_FORMATS (sizeof(intensityFormats) / sizeof(intensityFormats[0])) +struct formatInfo intensityFormats[] = +{ + { GL_INTENSITY, GL_INTENSITY, "INTENSITY" }, + { GL_INTENSITY, GL_INTENSITY4, "INTENSITY4" }, + { GL_INTENSITY, GL_INTENSITY8, "INTENSITY8" }, + { GL_INTENSITY, GL_INTENSITY12, "INTENSITY12" }, + { GL_INTENSITY, GL_INTENSITY16, "INTENSITY16" }, +}; + +#define NUM_LUMINANCE_ALPHA_FORMATS (sizeof(luminanceAlphaFormats) / sizeof(luminanceAlphaFormats[0])) +struct formatInfo luminanceAlphaFormats[] = +{ + { GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, "LUMINANCE_ALPHA" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE4_ALPHA4, "LUMINANCE4_ALPHA4" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE6_ALPHA2, "LUMINANCE6_ALPHA2" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE8_ALPHA8, "LUMINANCE8_ALPHA8" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE12_ALPHA4, "LUMINANCE12_ALPHA4" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE12_ALPHA12, "LUMINANCE12_ALPHA12" }, + { GL_LUMINANCE_ALPHA, GL_LUMINANCE16_ALPHA16, "LUMINANCE16_ALPHA16" }, +}; + +#define NUM_RGB_FORMATS (sizeof(rgbFormats) / sizeof(rgbFormats[0])) +struct formatInfo rgbFormats[] = +{ + { GL_RGB, GL_RGB, "RGB" }, + { GL_RGB, GL_R3_G3_B2, "R3_G3_B2" }, + { GL_RGB, GL_RGB4, "RGB4" }, + { GL_RGB, GL_RGB5, "RGB5" }, + { GL_RGB, GL_RGB8, "RGB8" }, + { GL_RGB, GL_RGB10, "RGB10" }, + { GL_RGB, GL_RGB12, "RGB12" }, + { GL_RGB, GL_RGB16, "RGB16" }, +}; + +#define NUM_RGBA_FORMATS (sizeof(rgbaFormats) / sizeof(rgbaFormats[0])) +struct formatInfo rgbaFormats[] = +{ + { GL_RGBA, GL_RGBA, "RGBA" }, + { GL_RGBA, GL_RGBA2, "RGBA2" }, + { GL_RGBA, GL_RGBA4, "RGBA4" }, + { GL_RGBA, GL_RGB5_A1, "RGB5_A1" }, + { GL_RGBA, GL_RGBA8, "RGBA8" }, + { GL_RGBA, GL_RGB10_A2, "RGB10_A2" }, + { GL_RGBA, GL_RGBA12, "RGBA12" }, + { GL_RGBA, GL_RGBA16, "RGBA16" }, +}; + +struct baseFormatInfo { + struct formatInfo *format; + int current, number; +}; + +#define NUM_BASE_FORMATS (sizeof(baseFormats) / sizeof(baseFormats[0])) +int baseFormat; +struct baseFormatInfo baseFormats[] = +{ + { luminanceFormats, 0, NUM_LUMINANCE_FORMATS }, + { alphaFormats, 0, NUM_ALPHA_FORMATS }, + { intensityFormats, 0, NUM_INTENSITY_FORMATS }, + { luminanceAlphaFormats, 0, NUM_LUMINANCE_ALPHA_FORMATS }, + { rgbFormats, 0, NUM_RGB_FORMATS }, + { rgbaFormats, 0, NUM_RGBA_FORMATS }, +}; + +#define NUM_ENV_COLORS (sizeof(envColors) / sizeof(envColors[0])) +int envColor = 0; +GLfloat envColors[][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 }, + { 0.0, 0.0, 1.0, 1.0 }, + { 1.0, 1.0, 1.0, 1.0 }, +}; + +struct envModeInfo { + GLenum mode; + char *name; +}; + +/* allow for run-time check for GL_EXT_texture_env_add */ +int NUM_ENV_MODES = 5; +struct envModeInfo envModes[] = +{ + { GL_REPLACE, "REPLACE" }, + { GL_MODULATE, "MODULATE" }, + { GL_BLEND, "BLEND" }, + { GL_DECAL, "DECAL" }, +#if GL_EXT_texture_env_add + { GL_ADD, "ADD" }, +#endif +}; + +static void checkErrors( void ) +{ + GLenum error; + + while ( (error = glGetError()) != GL_NO_ERROR ) { + fprintf( stderr, "Error: %s\n", (char *) gluErrorString( error ) ); + } +} + +static void drawString( const char *string, GLfloat x, GLfloat y, + const GLfloat color[4] ) +{ + glColor4fv( color ); + glRasterPos2f( x, y ); + + while ( *string ) { + glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_10, *string ); + string++; + } +} + +static void drawStringOutline( const char *string, GLfloat x, GLfloat y, + const GLfloat color[4], + const GLfloat outline[4] ) +{ + drawString( string, x - 1, y, outline ); + drawString( string, x + 1, y, outline ); + drawString( string, x, y - 1, outline ); + drawString( string, x, y + 1, outline ); + drawString( string, x, y, color ); +} + +static void begin2D( int width, int height ) +{ + glMatrixMode( GL_PROJECTION ); + + glPushMatrix(); + glLoadIdentity(); + + glOrtho( 0, width, 0, height, -1, 1 ); + glMatrixMode( GL_MODELVIEW ); + + glPushMatrix(); + glLoadIdentity(); +} + +static void end2D( void ) +{ + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + glPopMatrix(); +} + +static void initialize( void ) +{ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + + glOrtho( -1.5, 1.5, -1.5, 1.5, -1.5, 1.5 ); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glShadeModel( GL_FLAT ); +} + +/* ARGSUSED1 */ +static void keyboard( unsigned char c, int x, int y ) +{ + switch ( c ) { + case 'c': + envColor++; + envColor = envColor % (int) NUM_ENV_COLORS; + break; + case 'g': + drawBackground = !drawBackground; + break; + case 'b': + drawBlended = !drawBlended; + break; + case 's': + drawSmooth = !drawSmooth; + break; + case 't': + drawTextured = !drawTextured; + break; + case 'i': + displayLevelInfo = !displayLevelInfo; + break; + case 27: /* Escape key should force exit. */ + exit(0); + break; + default: + break; + } + glutPostRedisplay(); +} + +/* ARGSUSED1 */ +static void special( int key, int x, int y ) +{ + switch ( key ) { + case GLUT_KEY_DOWN: + if ( ++baseFormat > NUM_BASE_FORMATS - 1 ) { + baseFormat = 0; + } + break; + case GLUT_KEY_UP: + if ( --baseFormat < 0 ) { + baseFormat = NUM_BASE_FORMATS - 1; + } + break; + case GLUT_KEY_LEFT: + --baseFormats[baseFormat].current; + if ( baseFormats[baseFormat].current < 0 ) { + baseFormats[baseFormat].current = baseFormats[baseFormat].number - 1; + } + break; + case GLUT_KEY_RIGHT: + ++baseFormats[baseFormat].current; + if ( baseFormats[baseFormat].current > baseFormats[baseFormat].number - 1 ) { + baseFormats[baseFormat].current = 0; + } + break; + default: + break; + } + glutPostRedisplay(); +} + +static void +reshape( int w, int h ) +{ + winWidth = w; + winHeight = h; + /* No need to call glViewPort here since "draw" calls it! */ +} + +static void loadTexture( int width, int height, + const struct formatInfo *format ) +{ + int luminanceSize = 0; + int alphaSize = 0; + int rgbSize = 0; + GLenum textureFormat; + GLubyte *texImage, *p; + int elementsPerGroup, elementSize, groupSize, rowSize; + int i, j; + + switch ( format->baseFormat ) { + case GL_LUMINANCE: + luminanceSize = 1; + textureFormat = GL_LUMINANCE; + break; + case GL_INTENSITY: + luminanceSize = 1; + /* Note: format=GL_INTENSITY for glTexImage is not legal */ + textureFormat = GL_LUMINANCE; + break; + case GL_ALPHA: + alphaSize = 1; + textureFormat = GL_ALPHA; + break; + case GL_LUMINANCE_ALPHA: + luminanceSize = 1; + alphaSize = 1; + textureFormat = GL_LUMINANCE_ALPHA; + break; + case GL_RGB: + rgbSize = 3; + textureFormat = GL_RGB; + break; + case GL_RGBA: + rgbSize = 3; + alphaSize = 1; + textureFormat = GL_RGBA; + break; + default: + fprintf(stderr, "bad internal format info\n"); + return; + } + + elementsPerGroup = luminanceSize + alphaSize + rgbSize; + elementSize = sizeof(GLubyte); + groupSize = elementsPerGroup * elementSize; + rowSize = width * groupSize; + + if ( (texImage = (GLubyte *) malloc( height * rowSize ) ) == NULL ) { + fprintf( stderr, "texture malloc failed\n" ); + return; + } + + for ( i = 0 ; i < height ; i++ ) + { + p = texImage + i * rowSize; + + for ( j = 0 ; j < width ; j++ ) + { + if ( luminanceSize > 0 ) + { + /** + ** +-----+-----+ + ** | | | + ** | W | LG | + ** | | | + ** +-----+-----+ + ** | | | + ** | DG | B | + ** | | | + ** +-----+-----+ + **/ + if ( i > height / 2 ) { + if ( j < width / 2 ) { + p[0] = 0xff; + } else { + p[0] = 0xaa; + } + } else { + if ( j < width / 2 ) { + p[0] = 0x55; + } else { + p[0] = 0x00; + } + } + p += elementSize; + } + + if ( rgbSize > 0 ) + { + /** + ** +-----+-----+ + ** | | | + ** | R | G | + ** | | | + ** +-----+-----+ + ** | | | + ** | Y | B | + ** | | | + ** +-----+-----+ + **/ + if ( i > height / 2 ) { + if ( j < width / 2 ) { + p[0] = 0xff; + p[1] = 0x00; + p[2] = 0x00; + } else { + p[0] = 0x00; + p[1] = 0xff; + p[2] = 0x00; + } + } else { + if ( j < width / 2 ) { + p[0] = 0xff; + p[1] = 0xff; + p[2] = 0x00; + } else { + p[0] = 0x00; + p[1] = 0x00; + p[2] = 0xff; + } + } + p += 3 * elementSize; + } + + if ( alphaSize > 0 ) + { + /** + ** +-----------+ + ** | W | + ** | +-----+ | + ** | | | | + ** | | B | | + ** | | | | + ** | +-----+ | + ** | | + ** +-----------+ + **/ + int i2 = i - height / 2; + int j2 = j - width / 2; + int h8 = height / 8; + int w8 = width / 8; + if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) { + p[0] = 0x00; + } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) { + p[0] = 0x55; + } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) { + p[0] = 0xaa; + } else { + p[0] = 0xff; + } + p += elementSize; + } + } + } + + glTexImage2D( GL_TEXTURE_2D, 0, + format->internalFormat, width, height, 0, + textureFormat, GL_UNSIGNED_BYTE, texImage ); + + free( texImage ); +} + +static void drawCheck( int w, int h, const GLfloat lightCheck[4], + const GLfloat darkCheck[4] ) +{ + float dw = 2.0 / w; + float dh = 2.0 / h; + int i, j; + + for ( i = 0 ; i < w ; i++ ) { + GLfloat x0 = -1.0 + i * dw; + GLfloat x1 = x0 + dw; + + glBegin( GL_QUAD_STRIP ); + + for ( j = 0 ; j <= h ; j++ ) { + GLfloat y = -1.0 + j * dh; + + if ( (i ^ j) & 1 ) { + glColor4fv( lightCheck ); + } else { + glColor4fv( darkCheck ); + } + + glVertex2f( x0, y ); + glVertex2f( x1, y ); + } + + glEnd(); + } +} + +static const char *lookupFormat( GLint format ) +{ + switch ( format ) { + case GL_RGBA: + return "GL_RGBA"; + case GL_RGB: + return "GL_RGB"; + case GL_ALPHA: + return "GL_ALPHA"; + case GL_LUMINANCE: + return "GL_LUMINANCE"; + case GL_LUMINANCE_ALPHA: + return "GL_LUMINANCE_ALPHA"; + case GL_INTENSITY: + return "GL_INTENSITY"; + case GL_COLOR_INDEX: + return "GL_COLOR_INDEX"; + case GL_BGRA: + return "GL_BGRA"; + case GL_BGR: + return "GL_BGR"; + default: + return "unknown format"; + } +} + +static void drawSample( int x, int y, int w, int h, + const struct formatInfo *format, + const struct envModeInfo *envMode ) +{ + glViewport( x, y, w, h ); + glScissor( x, y, w, h ); + + glClearColor( 0.1, 0.1, 0.1, 1.0 ); + glClear( GL_COLOR_BUFFER_BIT ); + + begin2D( w, h ); + drawString( format->name, 10, h - 15, labelInfoColor ); + drawString( envMode->name, 10, 5, labelInfoColor ); + end2D(); + + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envMode->mode ); + glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envColors[envColor] ); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + + loadTexture( textureWidth, textureHeight, format ); + + if ( drawBackground ) { + drawCheck( 15, 15, lightCheck, darkCheck ); + } + if ( drawBlended ) { + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glEnable( GL_BLEND ); + } + if ( drawSmooth ) { + glShadeModel( GL_SMOOTH ); + } + else { + glShadeModel( GL_FLAT ); + glColor4f(1, 1, 1, 1); + } + if ( drawTextured ) { + glEnable( GL_TEXTURE_2D ); + } + + /* + * if (drawSmooth) then draw quad which goes from purple at the + * bottom (100% alpha) to green at the top (50% alpha). + */ + glBegin( GL_QUADS ); + if ( drawSmooth ) glColor4f( 1.0, 0.0, 1.0, 1.0 ); + glTexCoord2f( 0.0, 0.0 ); + glVertex2f( -0.8, -0.8 ); + + if ( drawSmooth ) glColor4f( 1.0, 0.0, 1.0, 1.0 ); + glTexCoord2f( 1.0, 0.0 ); + glVertex2f( 0.8, -0.8 ); + + if ( drawSmooth ) glColor4f( 0.0, 1.0, 0.0, 0.5 ); + glTexCoord2f( 1.0, 1.0 ); + glVertex2f( 0.8, 0.8 ); + + if ( drawSmooth ) glColor4f( 0.0, 1.0, 0.0, 0.5 ); + glTexCoord2f( 0.0, 1.0 ); + glVertex2f( -0.8, 0.8 ); + glEnd(); + + glDisable( GL_BLEND ); + glShadeModel( GL_FLAT ); + glDisable( GL_TEXTURE_2D ); + + if ( envMode->mode == GL_DECAL && + (format->baseFormat == GL_ALPHA || + format->baseFormat == GL_LUMINANCE || + format->baseFormat == GL_LUMINANCE_ALPHA || + format->baseFormat == GL_INTENSITY)) { + /* undefined format/mode combination */ + begin2D( w, h ); + drawStringOutline( "UNDEFINED MODE", 15, h / 2, + labelLevelColor0, labelLevelColor1 ); + end2D(); + } + else if ( displayLevelInfo ) { + GLint width, height, border, format; + GLint redSize, greenSize, blueSize, alphaSize; + GLint luminanceSize, intensitySize; + char buf[255]; + + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, &border ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &redSize ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &greenSize ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &blueSize ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alphaSize ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &luminanceSize ); + glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &intensitySize ); + + begin2D( w, h ); + sprintf( buf, "dimensions: %d x %d", width, height ); + drawStringOutline( buf, 15, h / 2 + 20, labelLevelColor0, labelLevelColor1 ); + + sprintf( buf, "border: %d", border ); + drawStringOutline( buf, 15, h / 2 + 10, labelLevelColor0, labelLevelColor1 ); + + sprintf( buf, "internal format:" ); + drawStringOutline( buf, 15, h / 2, labelLevelColor0, labelLevelColor1 ); + + sprintf( buf, " %s", lookupFormat( format ) ); + drawStringOutline( buf, 15, h / 2 - 10, labelLevelColor0, labelLevelColor1 ); + + sprintf( buf, "sizes:" ); + drawStringOutline( buf, 15, h / 2 - 20, labelLevelColor0, labelLevelColor1 ); + + sprintf( buf, " %d / %d / %d / %d / %d / %d", + redSize, greenSize, blueSize, alphaSize, + luminanceSize, intensitySize ); + drawStringOutline( buf, 15, h / 2 - 30, labelLevelColor0, labelLevelColor1 ); + + end2D(); + } +} + +static void display( void ) +{ + int numX = NUM_ENV_MODES, numY = NUM_BASE_FORMATS; + float xBase = (float) winWidth * 0.01; + float xOffset = (winWidth - xBase) / numX; + float xSize = max( xOffset - xBase, 1 ); + float yBase = (float) winHeight * 0.01; + float yOffset = (winHeight - yBase) / numY; + float ySize = max( yOffset - yBase, 1 ); + float x, y; + int i, j; + + glViewport( 0, 0, winWidth, winHeight ); + glDisable( GL_SCISSOR_TEST ); + glClearColor( 0.0, 0.0, 0.0, 0.0 ); + glClear( GL_COLOR_BUFFER_BIT ); + glEnable( GL_SCISSOR_TEST ); + + x = xBase; + y = (winHeight - 1) - yOffset; + + for ( i = 0 ; i < NUM_BASE_FORMATS ; i++ ) + { + struct formatInfo *format; + + if ( i == baseFormat ) { + labelInfoColor = labelColor1; + } else { + labelInfoColor = labelColor0; + } + + format = &baseFormats[i].format[baseFormats[i].current]; + + for ( j = 0 ; j < NUM_ENV_MODES ; j++ ) { + struct envModeInfo *envMode; + + envMode = &envModes[j]; + drawSample( x, y, xSize, ySize, format, envMode ); + x += xOffset; + } + + x = xBase; + y -= yOffset; + } + + if ( doubleBuffered ) { + glutSwapBuffers(); + } else { + glFlush(); + } + + checkErrors(); +} + +static void usage( char *name ) +{ + fprintf( stderr, "usage: %s [ options ]\n", name ); + fprintf( stderr, "\n" ); + fprintf( stderr, "options:\n" ); + fprintf( stderr, " -sb single buffered\n" ); + fprintf( stderr, " -db double buffered\n" ); + fprintf( stderr, " -info print OpenGL driver info\n" ); +} + +static void instructions( void ) +{ + fprintf( stderr, "texenv - texture environment and internal format test\n" ); + fprintf( stderr, "\n" ); + fprintf( stderr, " [c] - cycle through background colors\n" ); + fprintf( stderr, " [g] - toggle background\n" ); + fprintf( stderr, " [b] - toggle blend\n" ); + fprintf( stderr, " [s] - toggle smooth shading\n" ); + fprintf( stderr, " [t] - toggle texturing\n" ); + fprintf( stderr, " [i] - toggle information display\n" ); + fprintf( stderr, " up/down - select row\n" ); + fprintf( stderr, " left/right - change row's internal format\n" ); +} + +int main( int argc, char *argv[] ) +{ + GLboolean info = GL_FALSE; + int i; + + glutInit( &argc, argv ); + + for ( i = 1 ; i < argc ; i++ ) { + if ( !strcmp( "-sb", argv[i] ) ) { + doubleBuffered = GL_FALSE; + } else if ( !strcmp( "-db", argv[i] ) ) { + doubleBuffered = GL_TRUE; + } else if ( !strcmp( "-info", argv[i] ) ) { + info = GL_TRUE; + } else { + usage( argv[0] ); + exit( 1 ); + } + } + + if ( doubleBuffered ) { + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + } else { + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE ); + } + + glutInitWindowSize( winWidth, winHeight ); + glutInitWindowPosition( 0, 0 ); + glutCreateWindow( "Texture Environment Test" ); + + initialize(); + instructions(); + + if ( info ) { + printf( "\n" ); + printf( "GL_RENDERER = %s\n", (char *) glGetString( GL_RENDERER ) ); + printf( "GL_VERSION = %s\n", (char *) glGetString( GL_VERSION ) ); + printf( "GL_VENDOR = %s\n", (char *) glGetString( GL_VENDOR ) ) ; + printf( "GL_EXTENSIONS = %s\n", (char *) glGetString( GL_EXTENSIONS ) ); + } + +#if GL_EXT_texture_env_add + if ( !glutExtensionSupported( "GL_EXT_texture_env_add" ) ) { + fprintf( stderr, "missing extension: GL_EXT_texture_env_add\n" ); + NUM_ENV_MODES--; + } +#endif + + glutDisplayFunc( display ); + glutReshapeFunc( reshape ); + glutKeyboardFunc( keyboard ); + glutSpecialFunc( special ); + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/texobj.c b/progs/demos/texobj.c new file mode 100644 index 00000000000..40bce6e5695 --- /dev/null +++ b/progs/demos/texobj.c @@ -0,0 +1,284 @@ + +/* + * 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. + */ + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "GL/glut.h" + +static GLuint Window = 0; + +static GLuint TexObj[2]; +static GLfloat Angle = 0.0f; +static GLboolean UseObj = GL_FALSE; + + +#if defined(GL_VERSION_1_1) || defined(GL_VERSION_1_2) +# 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 ) +{ + 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 (UseObj) { +#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 (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[1] ); +#endif + } + else { + glCallList( TexObj[1] ); + } + 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 ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Angle += 120.0*dt; + 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 (UseObj) { +#ifdef TEXTURE_OBJECT + glGenTextures( 2, TexObj ); +#endif + } + else { + TexObj[0] = glGenLists(2); + TexObj[1] = TexObj[0]+1; + } + + /* setup first texture object */ + if (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[0] ); + assert(glIsTexture(TexObj[0])); +#endif + } + else { + glNewList( TexObj[0], GL_COMPILE ); + } + /* red on white */ + for (i=0;i<height;i++) { + for (j=0;j<width;j++) { + int p = i*width+j; + if (tex1[(height-i-1)*width+j]) { + tex[p][0] = 255; tex[p][1] = 0; tex[p][2] = 0; + } + else { + tex[p][0] = 255; tex[p][1] = 255; tex[p][2] = 255; + } + } + } + + glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, tex ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + if (!UseObj) { + glEndList(); + } + /* end of texture object */ + + /* setup second texture object */ + if (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[1] ); + assert(glIsTexture(TexObj[1])); +#endif + assert(!glIsTexture(TexObj[1] + 999)); + } + else { + glNewList( TexObj[1], GL_COMPILE ); + } + /* green on blue */ + for (i=0;i<height;i++) { + for (j=0;j<width;j++) { + int p = i*width+j; + if (tex2[(height-i-1)*width+j]) { + tex[p][0] = 0; tex[p][1] = 255; tex[p][2] = 0; + } + else { + tex[p][0] = 0; tex[p][1] = 0; tex[p][2] = 255; + } + } + } + glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, tex ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + if (!UseObj) { + glEndList(); + } + /* end texture object */ + +} + + + +int main( int argc, char *argv[] ) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(300, 300); + glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); + + Window = glutCreateWindow("Texture Objects"); + if (!Window) { + exit(1); + } + + /* check that renderer has the GL_EXT_texture_object extension + * or supports OpenGL 1.1 + */ +#ifdef TEXTURE_OBJECT + { + char *exten = (char *) glGetString( GL_EXTENSIONS ); + char *version = (char *) glGetString( GL_VERSION ); + if ( strstr( exten, "GL_EXT_texture_object" ) + || strncmp( version, "1.1", 3 )==0 + || strncmp( version, "1.2", 3 )==0 ) { + UseObj = GL_TRUE; + } + } +#endif + + init(); + + glutReshapeFunc( reshape ); + glutKeyboardFunc( key ); + glutIdleFunc( idle ); + glutDisplayFunc( draw ); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/trackball.c b/progs/demos/trackball.c new file mode 100644 index 00000000000..a6c4c60d06b --- /dev/null +++ b/progs/demos/trackball.c @@ -0,0 +1,338 @@ +#include <stdio.h> +/* + * (c) Copyright 1993, 1994, 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. + */ +/* + * Trackball code: + * + * Implementation of a virtual trackball. + * Implemented by Gavin Bell, lots of ideas from Thant Tessman and + * the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129. + * + * Vector manip code: + * + * Original code from: + * David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli + * + * Much mucking with by: + * Gavin Bell + */ +#if defined(_WIN32) +#pragma warning (disable:4244) /* disable bogus conversion warnings */ +#endif +#include <math.h> +#include "trackball.h" + +/* + * This size should really be based on the distance from the center of + * rotation to the point on the object underneath the mouse. That + * point would then track the mouse as closely as possible. This is a + * simple example, though, so that is left as an Exercise for the + * Programmer. + */ +#define TRACKBALLSIZE (0.8f) + +/* + * Local function prototypes (not defined in trackball.h) + */ +static float tb_project_to_sphere(float, float, float); +static void normalize_quat(float [4]); + +static void +vzero(float v[3]) +{ + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; +} + +static void +vset(float v[3], float x, float y, float z) +{ + v[0] = x; + v[1] = y; + v[2] = z; +} + +static void +vsub(const float src1[3], const float src2[3], float dst[3]) +{ + dst[0] = src1[0] - src2[0]; + dst[1] = src1[1] - src2[1]; + dst[2] = src1[2] - src2[2]; +} + +static void +vcopy(const float v1[3], float v2[3]) +{ + register int i; + for (i = 0 ; i < 3 ; i++) + v2[i] = v1[i]; +} + +static void +vcross(const float v1[3], const float v2[3], float cross[3]) +{ + float temp[3]; + + temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]); + temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]); + temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]); + vcopy(temp, cross); +} + +static float +vlength(const float v[3]) +{ + return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +} + +static void +vscale(float v[3], float div) +{ + v[0] *= div; + v[1] *= div; + v[2] *= div; +} + +static void +vnormal(float v[3]) +{ + vscale(v,1.0/vlength(v)); +} + +static float +vdot(const float v1[3], const float v2[3]) +{ + return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; +} + +static void +vadd(const float src1[3], const float src2[3], float dst[3]) +{ + dst[0] = src1[0] + src2[0]; + dst[1] = src1[1] + src2[1]; + dst[2] = src1[2] + src2[2]; +} + +/* + * Ok, simulate a track-ball. Project the points onto the virtual + * trackball, then figure out the axis of rotation, which is the cross + * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0) + * Note: This is a deformed trackball-- is a trackball in the center, + * but is deformed into a hyperbolic sheet of rotation away from the + * center. This particular function was chosen after trying out + * several variations. + * + * It is assumed that the arguments to this routine are in the range + * (-1.0 ... 1.0) + */ +void +trackball(float q[4], float p1x, float p1y, float p2x, float p2y) +{ + float a[3]; /* Axis of rotation */ + float phi; /* how much to rotate about axis */ + float p1[3], p2[3], d[3]; + float t; + + if (p1x == p2x && p1y == p2y) { + /* Zero rotation */ + vzero(q); + q[3] = 1.0; + return; + } + + /* + * First, figure out z-coordinates for projection of P1 and P2 to + * deformed sphere + */ + vset(p1,p1x,p1y,tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y)); + vset(p2,p2x,p2y,tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y)); + + /* + * Now, we want the cross product of P1 and P2 + */ + vcross(p2,p1,a); + + /* + * Figure out how much to rotate around that axis. + */ + vsub(p1,p2,d); + t = vlength(d) / (2.0*TRACKBALLSIZE); + + /* + * Avoid problems with out-of-control values... + */ + if (t > 1.0) t = 1.0; + if (t < -1.0) t = -1.0; + phi = 2.0 * asin(t); + + axis_to_quat(a,phi,q); +} + +/* + * Given an axis and angle, compute quaternion. + */ +void +axis_to_quat(const float a[3], float phi, float q[4]) +{ + vcopy(a,q); + vnormal(q); + vscale(q, sin(phi/2.0)); + q[3] = cos(phi/2.0); +} + +/* + * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet + * if we are away from the center of the sphere. + */ +static float +tb_project_to_sphere(float r, float x, float y) +{ + float d, t, z; + + d = sqrt(x*x + y*y); + if (d < r * 0.70710678118654752440) { /* Inside sphere */ + z = sqrt(r*r - d*d); + } else { /* On hyperbola */ + t = r / 1.41421356237309504880; + z = t*t / d; + } + return z; +} + +/* + * Given two rotations, e1 and e2, expressed as quaternion rotations, + * figure out the equivalent single rotation and stuff it into dest. + * + * This routine also normalizes the result every RENORMCOUNT times it is + * called, to keep error from creeping in. + * + * NOTE: This routine is written so that q1 or q2 may be the same + * as dest (or each other). + */ + +#define RENORMCOUNT 97 + +void +add_quats(const float q1[4], const float q2[4], float dest[4]) +{ + static int count=0; + float t1[4], t2[4], t3[4]; + float tf[4]; + +#if 0 +printf("q1 = %f %f %f %f\n", q1[0], q1[1], q1[2], q1[3]); +printf("q2 = %f %f %f %f\n", q2[0], q2[1], q2[2], q2[3]); +#endif + + vcopy(q1,t1); + vscale(t1,q2[3]); + + vcopy(q2,t2); + vscale(t2,q1[3]); + + vcross(q2,q1,t3); + vadd(t1,t2,tf); + vadd(t3,tf,tf); + tf[3] = q1[3] * q2[3] - vdot(q1,q2); + +#if 0 +printf("tf = %f %f %f %f\n", tf[0], tf[1], tf[2], tf[3]); +#endif + + dest[0] = tf[0]; + dest[1] = tf[1]; + dest[2] = tf[2]; + dest[3] = tf[3]; + + if (++count > RENORMCOUNT) { + count = 0; + normalize_quat(dest); + } +} + +/* + * Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0 + * If they don't add up to 1.0, dividing by their magnitued will + * renormalize them. + * + * Note: See the following for more information on quaternions: + * + * - Shoemake, K., Animating rotation with quaternion curves, Computer + * Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985. + * - Pletinckx, D., Quaternion calculus as a basic tool in computer + * graphics, The Visual Computer 5, 2-13, 1989. + */ +static void +normalize_quat(float q[4]) +{ + int i; + float mag; + + mag = sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]); + for (i = 0; i < 4; i++) + q[i] /= mag; +} + +/* + * Build a rotation matrix, given a quaternion rotation. + * + */ +void +build_rotmatrix(float m[4][4], const float q[4]) +{ + m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]); + m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]); + m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]); + m[0][3] = 0.0; + + m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]); + m[1][1]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]); + m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]); + m[1][3] = 0.0; + + m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]); + m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]); + m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]); + m[2][3] = 0.0; + + m[3][0] = 0.0; + m[3][1] = 0.0; + m[3][2] = 0.0; + m[3][3] = 1.0; +} + diff --git a/progs/demos/trackball.h b/progs/demos/trackball.h new file mode 100644 index 00000000000..9b278640e10 --- /dev/null +++ b/progs/demos/trackball.h @@ -0,0 +1,84 @@ +/* + * (c) Copyright 1993, 1994, 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. + */ +/* + * trackball.h + * A virtual trackball implementation + * Written by Gavin Bell for Silicon Graphics, November 1988. + */ + +#ifndef TRACKBALL_H +#define TRACKBALL_H + + +/* + * Pass the x and y coordinates of the last and current positions of + * the mouse, scaled so they are from (-1.0 ... 1.0). + * + * The resulting rotation is returned as a quaternion rotation in the + * first paramater. + */ +void +trackball(float q[4], float p1x, float p1y, float p2x, float p2y); + +/* + * Given two quaternions, add them together to get a third quaternion. + * Adding quaternions to get a compound rotation is analagous to adding + * translations to get a compound translation. When incrementally + * adding rotations, the first argument here should be the new + * rotation, the second and third the total rotation (which will be + * over-written with the resulting new total rotation). + */ +void +add_quats(const float q1[4], const float q2[4], float dest[4]); + +/* + * A useful function, builds a rotation matrix in Matrix based on + * given quaternion. + */ +void +build_rotmatrix(float m[4][4], const float q[4]); + +/* + * This function computes a quaternion based on an axis (defined by + * the given vector) and an angle about which to rotate. The angle is + * expressed in radians. The result is put into the third argument. + */ +void +axis_to_quat(const float a[3], float phi, float q[4]); + + +#endif /* TRACKBALL_H */ diff --git a/progs/demos/trispd.c b/progs/demos/trispd.c new file mode 100644 index 00000000000..165d088e3d3 --- /dev/null +++ b/progs/demos/trispd.c @@ -0,0 +1,253 @@ + +/* + * Simple GLUT program to measure triangle strip rendering speed. + * Brian Paul February 15, 1997 This file is in the public domain. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <GL/glut.h> + + +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<Loops; i++) { + for (y=1.0, v=0.0f; y<Height-yStep; y+=yStep, v+=vStep) { + glBegin(GL_TRIANGLE_STRIP); + for (x=1.0, u=0.0f; x<Width; x+=xStep, u+=uStep) { + glColor3fv(red); + glTexCoord2f(u, v); + glVertex2f(x, y); + glColor3fv(blue); + glTexCoord2f(u, v+vStep); + glVertex2f(x, y+yStep); + triCount += 2; + } + glEnd(); + triCount -= 2; + } + } + } + else { + for (i=0; i<Loops; i++) { + for (y=1.0; y<Height-yStep; y+=yStep) { + glBegin(GL_TRIANGLE_STRIP); + for (x=1.0; x<Width; x+=xStep) { + glColor3fv(red); + glVertex2f(x, y); + glColor3fv(blue); + glVertex2f(x, y+yStep); + triCount += 2; + } + glEnd(); + triCount -= 2; + } + } + } + glFinish(); + t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + + if (t1-t0 < MinPeriod) { + /* Next time draw more triangles to get longer elapsed time */ + Loops *= 2; + return; + } + + triRate = triCount / (t1-t0); + pixelRate = triRate * Size; + printf("Rate: %d tri in %gs = %g tri/s %d pixels/s\n", + triCount, t1-t0, triRate, (int)pixelRate); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + Width = width; + Height = 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(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void LoadTex(int comp, int filter) +{ + GLubyte *pixels; + int x, y; + pixels = (GLubyte *) malloc(4*256*256); + for (y = 0; y < 256; ++y) + for (x = 0; x < 256; ++x) { + pixels[(y*256+x)*4+0] = (int)(128.5 + 127.0 * cos(0.024544 * x)); + pixels[(y*256+x)*4+1] = 255; + pixels[(y*256+x)*4+2] = (int)(128.5 + 127.0 * cos(0.024544 * y)); + pixels[(y*256+x)*4+3] = 255; + } + glEnable(GL_TEXTURE_2D); + glTexImage2D(GL_TEXTURE_2D, 0, comp, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + printf("Texture: GL_MODULATE, %d comps, %s\n", comp, filter == GL_NEAREST ? "GL_NEAREST" : "GL_LINEAR"); +} + + +static void Init( int argc, char *argv[] ) +{ + GLint shade; + GLint rBits, gBits, bBits; + int filter = GL_NEAREST, comp = 3; + + int i; + for (i=1; i<argc; i++) { + if (strcmp(argv[i],"-dither")==0) + glDisable(GL_DITHER); + else if (strcmp(argv[i],"+dither")==0) + glEnable(GL_DITHER); + else if (strcmp(argv[i],"+smooth")==0) + glShadeModel(GL_SMOOTH); + else if (strcmp(argv[i],"+flat")==0) + glShadeModel(GL_FLAT); + else if (strcmp(argv[i],"+depth")==0) + glEnable(GL_DEPTH_TEST); + else if (strcmp(argv[i],"-depth")==0) + glDisable(GL_DEPTH_TEST); + else if (strcmp(argv[i],"-size")==0) { + Size = atoi(argv[i+1]); + i++; + } + else if (strcmp(argv[i],"-texture")==0) + Texture = 0; + else if (strcmp(argv[i],"+texture")==0) + Texture = 1; + else if (strcmp(argv[i],"-linear")==0) + filter = GL_NEAREST; + else if (strcmp(argv[i],"+linear")==0) + filter = GL_LINEAR; + else if (strcmp(argv[i],"-persp")==0) + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + else if (strcmp(argv[i],"+persp")==0) + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + else if (strcmp(argv[i],"-comp")==0) { + comp = atoi(argv[i+1]); + i++; + } + else + printf("Unknown option: %s\n", argv[i]); + } + + glGetIntegerv(GL_SHADE_MODEL, &shade); + + printf("Dither: %s\n", glIsEnabled(GL_DITHER) ? "on" : "off"); + printf("ShadeModel: %s\n", (shade==GL_FLAT) ? "flat" : "smooth"); + printf("DepthTest: %s\n", glIsEnabled(GL_DEPTH_TEST) ? "on" : "off"); + printf("Size: %d pixels\n", Size); + + if (Texture) + LoadTex(comp, filter); + + glGetIntegerv(GL_RED_BITS, &rBits); + glGetIntegerv(GL_GREEN_BITS, &gBits); + glGetIntegerv(GL_BLUE_BITS, &bBits); + printf("RedBits: %d GreenBits: %d BlueBits: %d\n", rBits, gBits, bBits); +} + + +static void Help( const char *program ) +{ + printf("%s options:\n", program); + printf(" +/-dither enable/disable dithering\n"); + printf(" +/-depth enable/disable depth test\n"); + printf(" +flat flat shading\n"); + printf(" +smooth smooth shading\n"); + printf(" -size pixels specify pixels/triangle\n"); + printf(" +/-texture enable/disable texture\n"); + printf(" -comp n texture format\n"); + printf(" +/-linear bilinear texture filter\n"); + printf(" +/-persp perspective correction hint\n"); +} + + +int main( int argc, char *argv[] ) +{ + printf("For options: %s -help\n", argv[0]); + glutInit( &argc, argv ); + glutInitWindowSize( (int) Width, (int) Height ); + glutInitWindowPosition( 0, 0 ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + + glutCreateWindow( argv[0] ); + + if (argc==2 && strcmp(argv[1],"-help")==0) { + Help(argv[0]); + return 0; + } + + Init( argc, argv ); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c new file mode 100644 index 00000000000..6a240580e8a --- /dev/null +++ b/progs/demos/tunnel.c @@ -0,0 +1,535 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <GL/glut.h> +#include "readtex.h" +#include "tunneldat.h" + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +static int WIDTH = 640; +static int HEIGHT = 480; + +static GLint T0 = 0; +static GLint Frames = 0; +static GLint NiceFog = 1; + +#define NUMBLOC 5 + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +/* +extern int striplength_skin_13[]; +extern float stripdata_skin_13[]; + +extern int striplength_skin_12[]; +extern float stripdata_skin_12[]; + +extern int striplength_skin_11[]; +extern float stripdata_skin_11[]; + +extern int striplength_skin_9[]; +extern float stripdata_skin_9[]; +*/ + +static int win = 0; + +static float obs[3] = { 1000.0, 0.0, 2.0 }; +static float dir[3]; +static float v = 30.; +static float alpha = 90.0; +static float beta = 90.0; + +static int fog = 1; +static int bfcull = 1; +static int usetex = 1; +static int cstrip = 0; +static int help = 1; +static int joyavailable = 0; +static int joyactive = 0; + +static GLuint t1id, t2id; + +static void +inittextures(void) +{ + glGenTextures(1, &t1id); + glBindTexture(GL_TEXTURE_2D, t1id); + + if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glGenTextures(1, &t2id); + glBindTexture(GL_TEXTURE_2D, t2id); + + if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +static void +drawobjs(const int *l, const float *f) +{ + int mend, j; + + if (cstrip) { + float r = 0.33, g = 0.33, b = 0.33; + + for (; (*l) != 0;) { + mend = *l++; + + r += 0.33; + if (r > 1.0) { + r = 0.33; + g += 0.33; + if (g > 1.0) { + g = 0.33; + b += 0.33; + if (b > 1.0) + b = 0.33; + } + } + + glColor3f(r, g, b); + glBegin(GL_TRIANGLE_STRIP); + for (j = 0; j < mend; j++) { + f += 4; + glTexCoord2fv(f); + f += 2; + glVertex3fv(f); + f += 3; + } + glEnd(); + } + } + else + for (; (*l) != 0;) { + mend = *l++; + + glBegin(GL_TRIANGLE_STRIP); + for (j = 0; j < mend; j++) { + glColor4fv(f); + f += 4; + glTexCoord2fv(f); + f += 2; + glVertex3fv(f); + f += 3; + } + glEnd(); + } +} + +static void +calcposobs(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + dir[0] = sin(alpha * M_PI / 180.0); + dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[2] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + obs[0] += v * dir[0] * dt; + obs[1] += v * dir[1] * dt; + obs[2] += v * dir[2] * dt; +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_LEFT: + alpha -= 2.0; + break; + case GLUT_KEY_RIGHT: + alpha += 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: + exit(0); + break; + + case 'a': + v += 5.; + break; + case 'z': + v -= 5.; + break; + +#ifdef XMESA + case ' ': + fullscreen = (!fullscreen); + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + break; +#endif + case 'j': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + case 't': + usetex = (!usetex); + break; + case 'b': + if (bfcull) { + glDisable(GL_CULL_FACE); + bfcull = 0; + } + else { + glEnable(GL_CULL_FACE); + bfcull = 1; + } + break; + case 'm': + cstrip = (!cstrip); + break; + + case 'd': + fprintf(stderr, "Deleting textures...\n"); + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + fprintf(stderr, "Loading textures...\n"); + inittextures(); + fprintf(stderr, "Done.\n"); + break; + case 'n': + NiceFog = !NiceFog; + printf("NiceFog %d\n", NiceFog); + break; + } + glutPostRedisplay(); +} + +static void +reshape(int w, int h) +{ + WIDTH = w; + HEIGHT = h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(80.0, w / (float) h, 1.0, 50.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, w, h); +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +printhelp(void) +{ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.0, 0.0, 0.0, 0.5); + glRecti(40, 40, 600, 440); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); + glRasterPos2i(60, 360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); + glRasterPos2i(60, 300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "m - Toggle strips"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling"); + glRasterPos2i(60, 240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); + glRasterPos2i(60, 180); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); + + glRasterPos2i(60, 150); + if (joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "(No Joystick control available)"); +} + +static void +dojoy(void) +{ +#ifdef WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha -= + 2.0 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.0 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.01; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.01; + } + } + else + joyavailable = 0; +#endif +} + +static void +draw(void) +{ + static char frbuf[80] = ""; + int i; + float base, offset; + + if (NiceFog) + glHint(GL_FOG_HINT, GL_NICEST); + else + glHint(GL_FOG_HINT, GL_DONT_CARE); + + dojoy(); + + glClear(GL_COLOR_BUFFER_BIT); + + if (usetex) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glShadeModel(GL_SMOOTH); + + glPushMatrix(); + calcposobs(); + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 0.0, 1.0); + + if (dir[0] > 0) { + offset = 8.0; + base = obs[0] - fmod(obs[0], 8.0); + } + else { + offset = -8.0; + base = obs[0] + (8.0 - fmod(obs[0], 8.0)); + } + + glPushMatrix(); + glTranslatef(base - offset / 2.0, 0.0, 0.0); + for (i = 0; i < NUMBLOC; i++) { + glTranslatef(offset, 0.0, 0.0); + glBindTexture(GL_TEXTURE_2D, t1id); + drawobjs(striplength_skin_11, stripdata_skin_11); + glBindTexture(GL_TEXTURE_2D, t2id); + drawobjs(striplength_skin_12, stripdata_skin_12); + drawobjs(striplength_skin_9, stripdata_skin_9); + drawobjs(striplength_skin_13, stripdata_skin_13); + } + glPopMatrix(); + glPopMatrix(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(350, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "Tunnel V1.5 Written by David Bucciarelli ([email protected])"); + + if (help) + printhelp(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + +static void +idle(void) +{ + glutPostRedisplay(); +} + + + +int +main(int ac, char **av) +{ + float fogcolor[4] = { 0.7, 0.7, 0.7, 1.0 }; + + fprintf(stderr, + "Tunnel V1.5\nWritten by David Bucciarelli ([email protected])\n"); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + + if (!(win = glutCreateWindow("Tunnel"))) { + fprintf(stderr, "Error, couldn't open window\n"); + return -1; + } + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(80.0, WIDTH / (float) HEIGHT, 1.0, 50.0); + + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_SMOOTH); + glDisable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogfv(GL_FOG_COLOR, fogcolor); + + glFogf(GL_FOG_DENSITY, 0.06); + glHint(GL_FOG_HINT, GL_NICEST); + + inittextures(); + + glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); + glClear(GL_COLOR_BUFFER_BIT); + + calcposobs(); + + glutReshapeFunc(reshape); + glutDisplayFunc(draw); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutIdleFunc(idle); + + glEnable(GL_BLEND); + /*glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); */ + /*glEnable(GL_POLYGON_SMOOTH); */ + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c new file mode 100644 index 00000000000..75a199af5d3 --- /dev/null +++ b/progs/demos/tunnel2.c @@ -0,0 +1,605 @@ +/* + * This program is under the GNU GPL. + * Use at your own risk. + * + * You need TWO Voodoo Graphics boards in order to run + * this demo ! + * + * written by David Bucciarelli ([email protected]) + * Humanware s.r.l. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> + +#ifdef WIN32 +#include <windows.h> +#endif + +#include <GL/glut.h> +#include "readtex.h" +#include "tunneldat.h" + +#ifdef FX +#endif + +#ifdef XMESA +#include "GL/xmesa.h" +static int fullscreen = 1; +#endif + +#ifdef FX +GLint fxMesaSelectCurrentBoard(int); +#endif + +static int WIDTHC0 = 640; +static int HEIGHTC0 = 480; + +static int WIDTHC1 = 640; +static int HEIGHTC1 = 480; + +static GLint T0 = 0; +static GLint Frames = 0; + +#define NUMBLOC 5 + +#ifndef M_PI +#define M_PI 3.1415926535 +#endif + +static float obs[3] = { 1000.0, 0.0, 2.0 }; +static float dir[3]; +static float v = 30.; +static float alpha = 90.0; +static float beta = 90.0; + +static int fog = 1; +static int bfcull = 1; +static int usetex = 1; +static int cstrip = 0; +static int help = 1; +static int joyavailable = 0; +static int joyactive = 0; + +static int channel[2]; + +static GLuint t1id, t2id; + +static void +inittextures(void) +{ + glGenTextures(1, &t1id); + glBindTexture(GL_TEXTURE_2D, t1id); + + if (!LoadRGBMipmaps("../images/tile.rgb", GL_RGB)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glGenTextures(1, &t2id); + glBindTexture(GL_TEXTURE_2D, t2id); + + if (!LoadRGBMipmaps("../images/bw.rgb", GL_RGB)) { + fprintf(stderr, "Error reading a texture.\n"); + exit(-1); + } + + 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_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +static void +drawobjs(const int *l, const float *f) +{ + int mend, j; + + if (cstrip) { + float r = 0.33, g = 0.33, b = 0.33; + + for (; (*l) != 0;) { + mend = *l++; + + r += 0.33; + if (r > 1.0) { + r = 0.33; + g += 0.33; + if (g > 1.0) { + g = 0.33; + b += 0.33; + if (b > 1.0) + b = 0.33; + } + } + + glColor3f(r, g, b); + glBegin(GL_TRIANGLE_STRIP); + for (j = 0; j < mend; j++) { + f += 4; + glTexCoord2fv(f); + f += 2; + glVertex3fv(f); + f += 3; + } + glEnd(); + } + } + else + for (; (*l) != 0;) { + mend = *l++; + + glBegin(GL_TRIANGLE_STRIP); + for (j = 0; j < mend; j++) { + glColor4fv(f); + f += 4; + glTexCoord2fv(f); + f += 2; + glVertex3fv(f); + f += 3; + } + glEnd(); + } +} + +static void +calcposobs(void) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + dir[0] = sin(alpha * M_PI / 180.0); + dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); + dir[2] = cos(beta * M_PI / 180.0); + + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + + obs[0] += v * dir[0] * dt; + obs[1] += v * dir[1] * dt; + obs[2] += v * dir[2] * dt; +} + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_LEFT: + alpha -= 2.0; + break; + case GLUT_KEY_RIGHT: + alpha += 2.0; + break; + case GLUT_KEY_DOWN: + beta -= 2.0; + break; + case GLUT_KEY_UP: + beta += 2.0; + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: + exit(0); + break; + + case 'a': + v += 5.; + break; + case 'z': + v -= 5.; + break; + +#ifdef XMESA + case ' ': + fullscreen = (!fullscreen); + + glutSetWindow(channel[0]); + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + + glutSetWindow(channel[1]); + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + break; +#endif + + case 'j': + joyactive = (!joyactive); + break; + case 'h': + help = (!help); + break; + case 'f': + fog = (!fog); + break; + case 't': + usetex = (!usetex); + break; + case 'b': + if (bfcull) { + glDisable(GL_CULL_FACE); + bfcull = 0; + } + else { + glEnable(GL_CULL_FACE); + bfcull = 1; + } + break; + case 'm': + cstrip = (!cstrip); + break; + + case 'd': + fprintf(stderr, "Deleting textures...\n"); + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + fprintf(stderr, "Loading textures...\n"); + inittextures(); + fprintf(stderr, "Done.\n"); + break; + } +} + +static void +reshapechannel0(int w, int h) +{ + float ratio; + + WIDTHC0 = w; + HEIGHTC0 = h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + ratio = 0.5f * w / (float) h; + + glFrustum(-2.0, 0.0, -1.0 * ratio, 1.0 * ratio, 1.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, w, h); +} + +static void +reshapechannel1(int w, int h) +{ + float ratio; + + WIDTHC1 = w; + HEIGHTC1 = h; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + ratio = 0.5f * w / (float) h; + + glFrustum(0.0, 2.0, -1.0 * ratio, 1.0 * ratio, 1.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, w, h); +} + +static void +printstring(void *font, char *string) +{ + int len, i; + + len = (int) strlen(string); + for (i = 0; i < len; i++) + glutBitmapCharacter(font, string[i]); +} + +static void +printhelp(void) +{ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.0, 0.0, 0.0, 0.5); + glRecti(40, 40, 600, 440); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(300, 420); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Help"); + + glRasterPos2i(60, 390); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "h - Toggle Help"); + glRasterPos2i(60, 360); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "t - Toggle Textures"); + glRasterPos2i(60, 330); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "f - Toggle Fog"); + glRasterPos2i(60, 300); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "m - Toggle strips"); + glRasterPos2i(60, 270); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "b - Toggle Back face culling"); + glRasterPos2i(60, 240); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "Arrow Keys - Rotate"); + glRasterPos2i(60, 210); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "a - Increase velocity"); + glRasterPos2i(60, 180); + printstring(GLUT_BITMAP_TIMES_ROMAN_24, "z - Decrease velocity"); + + glRasterPos2i(60, 150); + if (joyavailable) + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "j - Toggle jostick control (Joystick control available)"); + else + printstring(GLUT_BITMAP_TIMES_ROMAN_24, + "(No Joystick control available)"); +} + +static void +dojoy(void) +{ +#ifdef WIN32 + static UINT max[2] = { 0, 0 }; + static UINT min[2] = { 0xffffffff, 0xffffffff }, center[2]; + MMRESULT res; + JOYINFO joy; + + res = joyGetPos(JOYSTICKID1, &joy); + + if (res == JOYERR_NOERROR) { + joyavailable = 1; + + if (max[0] < joy.wXpos) + max[0] = joy.wXpos; + if (min[0] > joy.wXpos) + min[0] = joy.wXpos; + center[0] = (max[0] + min[0]) / 2; + + if (max[1] < joy.wYpos) + max[1] = joy.wYpos; + if (min[1] > joy.wYpos) + min[1] = joy.wYpos; + center[1] = (max[1] + min[1]) / 2; + + if (joyactive) { + if (fabs(center[0] - (float) joy.wXpos) > 0.1 * (max[0] - min[0])) + alpha -= + 2.0 * (center[0] - (float) joy.wXpos) / (max[0] - min[0]); + if (fabs(center[1] - (float) joy.wYpos) > 0.1 * (max[1] - min[1])) + beta += 2.0 * (center[1] - (float) joy.wYpos) / (max[1] - min[1]); + + if (joy.wButtons & JOY_BUTTON1) + v += 0.01; + if (joy.wButtons & JOY_BUTTON2) + v -= 0.01; + } + } + else + joyavailable = 0; +#endif +} + +static void +draw(void) +{ + static char frbuf[80] = ""; + int i; + float base, offset; + + dojoy(); + + glClear(GL_COLOR_BUFFER_BIT); + + glClear(GL_COLOR_BUFFER_BIT); + + if (usetex) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + if (fog) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + + glShadeModel(GL_SMOOTH); + + glPushMatrix(); + calcposobs(); + gluLookAt(obs[0], obs[1], obs[2], + obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2], + 0.0, 0.0, 1.0); + + if (dir[0] > 0) { + offset = 8.0; + base = obs[0] - fmod(obs[0], 8.0); + } + else { + offset = -8.0; + base = obs[0] + (8.0 - fmod(obs[0], 8.0)); + } + + glPushMatrix(); + glTranslatef(base - offset / 2.0, 0.0, 0.0); + for (i = 0; i < NUMBLOC; i++) { + glTranslatef(offset, 0.0, 0.0); + glBindTexture(GL_TEXTURE_2D, t1id); + drawobjs(striplength_skin_11, stripdata_skin_11); + glBindTexture(GL_TEXTURE_2D, t2id); + drawobjs(striplength_skin_12, stripdata_skin_12); + drawobjs(striplength_skin_9, stripdata_skin_9); + drawobjs(striplength_skin_13, stripdata_skin_13); + } + glPopMatrix(); + glPopMatrix(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_FOG); + glShadeModel(GL_FLAT); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor3f(1.0, 0.0, 0.0); + glRasterPos2i(10, 10); + printstring(GLUT_BITMAP_HELVETICA_18, frbuf); + glRasterPos2i(350, 470); + printstring(GLUT_BITMAP_HELVETICA_10, + "Tunnel2 V1.0 Written by David Bucciarelli ([email protected])"); + + if (help) + printhelp(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 2000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + sprintf(frbuf, "Frame rate: %f", fps); + T0 = t; + Frames = 0; + } + } +} + +static void +drawchannel0(void) +{ + glutSetWindow(channel[0]); + draw(); + glutSwapBuffers(); +} + +static void +drawchannel1(void) +{ + glutSetWindow(channel[1]); + draw(); + glutSwapBuffers(); +} + +static void +drawall(void) +{ + glutSetWindow(channel[0]); + draw(); + glutSetWindow(channel[1]); + draw(); + + glutSetWindow(channel[0]); + glutSwapBuffers(); + glutSetWindow(channel[1]); + glutSwapBuffers(); +} + +static void +init(void) +{ + float fogcolor[4] = { 0.7, 0.7, 0.7, 1.0 }; + + glShadeModel(GL_SMOOTH); + glDisable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); + glFogfv(GL_FOG_COLOR, fogcolor); + + glFogf(GL_FOG_DENSITY, 0.06); + glHint(GL_FOG_HINT, GL_NICEST); + + glEnable(GL_BLEND); + /* + glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); + glEnable(GL_POLYGON_SMOOTH); + */ + + glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); + glClear(GL_COLOR_BUFFER_BIT); +} + +int +main(int ac, char **av) +{ + fprintf(stderr, + "Tunnel2 V1.0\nWritten by David Bucciarelli ([email protected])\n"); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTHC0, HEIGHTC0); + glutInit(&ac, av); + + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + +#ifdef FX + if (fxMesaSelectCurrentBoard(0) < 0) { + fprintf(stderr, "The first Voodoo Graphics board is missing !?!?\n"); + return -1; + } +#endif + if (!(channel[0] = glutCreateWindow("Channel 0"))) { + fprintf(stderr, "Error, couldn't open window\n"); + return -1; + } + + reshapechannel0(WIDTHC0, HEIGHTC0); + init(); + inittextures(); + glutDisplayFunc(drawchannel0); + glutReshapeFunc(reshapechannel0); + glutKeyboardFunc(key); + glutSpecialFunc(special); + +#ifdef FX + if (fxMesaSelectCurrentBoard(1) < 0) { + fprintf(stderr, "The second Voodoo Graphics board is missing !\n"); + exit(-1); + } +#endif + glutInitWindowPosition(WIDTHC0, 0); + glutInitWindowSize(WIDTHC1, HEIGHTC1); + if (!(channel[1] = glutCreateWindow("Channel 1"))) { + fprintf(stderr, "Error, couldn't open window\n"); + exit(-1); + } + + reshapechannel1(WIDTHC1, HEIGHTC1); + init(); + inittextures(); + glutDisplayFunc(drawchannel1); + glutReshapeFunc(reshapechannel1); + glutKeyboardFunc(key); + glutSpecialFunc(special); + + glutIdleFunc(drawall); + + calcposobs(); + + glutMainLoop(); + + return 0; +} diff --git a/progs/demos/tunneldat.h b/progs/demos/tunneldat.h new file mode 100644 index 00000000000..af1e52e1f17 --- /dev/null +++ b/progs/demos/tunneldat.h @@ -0,0 +1,395 @@ +/* Object: skin_13 */ + +#if defined(_MSC_VER) && defined(_WIN32) +#pragma warning( disable : 4305 ) /* 'initializing' : truncation from 'const double' to 'float' */ +#endif + +static const int striplength_skin_13[] = { + 10, 7, 3, 5, 5, 4, 4, 4, 4, 5, 3, 4, 5, 4, 4, 4, 4, 4, 4, 6, + 6, 3, 6, 3, 3, 3, 3, 0 +}; + +static const float stripdata_skin_13[] = { + 0.415686, 0.415686, 0.415686, 1.000000, 0.000000, 1.500000, 2.000000, + 4.000000, 0.000000, 0.341176, 0.341176, 0.341176, 1.000000, -0.500000, + 1.500000, 4.000000, 4.000000, 0.000000, 0.545098, 0.545098, 0.545098, + 1.000000, 0.000000, 1.000000, 2.000000, 4.000000, 2.000000, 0.435294, + 0.435294, 0.435294, 1.000000, -0.500000, 1.000000, 4.000000, 4.000000, + 2.000000, 0.517647, 0.517647, 0.517647, 1.000000, 0.000000, 0.500000, + 2.000000, 4.000000, 4.000000, 0.450980, 0.450980, 0.450980, 1.000000, + -0.500000, 0.500000, 4.000000, 4.000000, 4.000000, 0.427451, 0.427451, + 0.427451, 1.000000, 0.000000, 0.000000, 2.000000, 4.000000, 6.000000, + 0.388235, 0.388235, 0.388235, 1.000000, -0.500000, 0.000000, 4.000000, + 4.000000, 6.000000, 0.356863, 0.356863, 0.356863, 1.000000, 0.000000, + -0.500000, 2.000000, 4.000000, 8.000000, 0.333333, 0.333333, 0.333333, + 1.000000, -0.500000, -0.500000, 4.000000, 4.000000, 8.000000, + 0.435294, 0.435294, 0.435294, 1.000000, 1.500000, 1.000000, -4.000000, + 4.000000, 2.000000, 0.415686, 0.415686, 0.415686, 1.000000, 1.000000, + 1.500000, -2.000000, 4.000000, 0.000000, 0.545098, 0.545098, 0.545098, + 1.000000, 1.000000, 1.000000, -2.000000, 4.000000, 2.000000, 0.450980, + 0.450980, 0.450980, 1.000000, 0.500000, 1.500000, 0.000000, 4.000000, + 0.000000, 0.600000, 0.600000, 0.600000, 1.000000, 0.500000, 1.000000, + 0.000000, 4.000000, 2.000000, 0.415686, 0.415686, 0.415686, 1.000000, + 0.000000, 1.500000, 2.000000, 4.000000, 0.000000, 0.545098, 0.545098, + 0.545098, 1.000000, 0.000000, 1.000000, 2.000000, 4.000000, 2.000000, + 0.435294, 0.435294, 0.435294, 1.000000, 1.500000, 1.000000, -4.000000, + 4.000000, 2.000000, 0.341176, 0.341176, 0.341176, 1.000000, 1.500000, + 1.500000, -4.000000, 4.000000, 0.000000, 0.415686, 0.415686, 0.415686, + 1.000000, 1.000000, 1.500000, -2.000000, 4.000000, 0.000000, + 0.356863, 0.356863, 0.356863, 1.000000, 0.000000, -0.500000, 2.000000, + 4.000000, 8.000000, 0.364706, 0.364706, 0.364706, 1.000000, 0.500000, + -0.500000, 0.000000, 4.000000, 8.000000, 0.427451, 0.427451, 0.427451, + 1.000000, 0.000000, 0.000000, 2.000000, 4.000000, 6.000000, 0.415686, + 0.415686, 0.415686, 1.000000, 0.395020, -0.133318, 0.420032, 4.000000, + 6.533272, 0.423529, 0.423529, 0.423529, 1.000000, 0.388550, -0.103582, + 0.445932, 4.000000, 6.414327, + 0.423529, 0.423529, 0.423529, 1.000000, 0.388550, -0.103582, 0.445932, + 4.000000, 6.414327, 0.427451, 0.427451, 0.427451, 1.000000, 0.383423, + -0.069344, 0.466541, 4.000000, 6.277375, 0.427451, 0.427451, 0.427451, + 1.000000, 0.000000, 0.000000, 2.000000, 4.000000, 6.000000, 0.435294, + 0.435294, 0.435294, 1.000000, 0.380371, -0.034595, 0.478689, 4.000000, + 6.138380, 0.439216, 0.439216, 0.439216, 1.000000, 0.379272, 0.000000, + 0.482673, 4.000000, 6.000000, + 0.407843, 0.407843, 0.407843, 1.000000, 0.414673, -0.191394, 0.341301, + 4.000000, 6.765576, 0.411765, 0.411765, 0.411765, 1.000000, 0.403687, + -0.162957, 0.385368, 4.000000, 6.651829, 0.364706, 0.364706, 0.364706, + 1.000000, 0.500000, -0.500000, 0.000000, 4.000000, 8.000000, 0.415686, + 0.415686, 0.415686, 1.000000, 0.395020, -0.133318, 0.420032, 4.000000, + 6.533272, + 0.400000, 0.400000, 0.400000, 1.000000, 0.438232, -0.232438, 0.247284, + 4.000000, 6.929754, 0.403922, 0.403922, 0.403922, 1.000000, 0.425171, + -0.212276, 0.299425, 4.000000, 6.849104, 0.364706, 0.364706, 0.364706, + 1.000000, 0.500000, -0.500000, 0.000000, 4.000000, 8.000000, 0.407843, + 0.407843, 0.407843, 1.000000, 0.414673, -0.191394, 0.341301, 4.000000, + 6.765576, + 0.396078, 0.396078, 0.396078, 1.000000, 0.467285, -0.260554, 0.130636, + 4.000000, 7.042214, 0.400000, 0.400000, 0.400000, 1.000000, 0.453857, + -0.250068, 0.184711, 4.000000, 7.000273, 0.364706, 0.364706, 0.364706, + 1.000000, 0.500000, -0.500000, 0.000000, 4.000000, 8.000000, 0.400000, + 0.400000, 0.400000, 1.000000, 0.438232, -0.232438, 0.247284, 4.000000, + 6.929754, + 0.396078, 0.396078, 0.396078, 1.000000, 0.500000, -0.270672, 0.000000, + 4.000000, 7.082688, 0.396078, 0.396078, 0.396078, 1.000000, 0.482788, + -0.267902, 0.068730, 4.000000, 7.071609, 0.364706, 0.364706, 0.364706, + 1.000000, 0.500000, -0.500000, 0.000000, 4.000000, 8.000000, 0.396078, + 0.396078, 0.396078, 1.000000, 0.467285, -0.260554, 0.130636, 4.000000, + 7.042214, + 0.439216, 0.439216, 0.439216, 1.000000, 0.379272, 0.000000, 0.482673, + 4.000000, 6.000000, 0.474510, 0.474510, 0.474510, 1.000000, 0.379272, + 0.180448, 0.482673, 4.000000, 5.278208, 0.517647, 0.517647, 0.517647, + 1.000000, 0.000000, 0.500000, 2.000000, 4.000000, 4.000000, 0.513726, + 0.513726, 0.513726, 1.000000, 0.379272, 0.360896, 0.482673, 4.000000, + 4.556417, 0.545098, 0.545098, 0.545098, 1.000000, 0.379272, 0.500000, + 0.482673, 4.000000, 4.000000, + 0.545098, 0.545098, 0.545098, 1.000000, 0.379272, 0.500000, 0.482673, + 4.000000, 4.000000, 0.545098, 0.545098, 0.545098, 1.000000, 0.000000, + 1.000000, 2.000000, 4.000000, 2.000000, 0.517647, 0.517647, 0.517647, + 1.000000, 0.000000, 0.500000, 2.000000, 4.000000, 4.000000, + 0.600000, 0.600000, 0.600000, 1.000000, 0.500000, 1.000000, 0.000000, + 4.000000, 2.000000, 0.545098, 0.545098, 0.545098, 1.000000, 0.000000, + 1.000000, 2.000000, 4.000000, 2.000000, 0.552941, 0.552941, 0.552941, + 1.000000, 0.379272, 0.541344, 0.482673, 4.000000, 3.834625, 0.545098, + 0.545098, 0.545098, 1.000000, 0.379272, 0.500000, 0.482673, 4.000000, + 4.000000, + 0.552941, 0.552941, 0.552941, 1.000000, 0.379272, 0.541344, 0.482673, + 4.000000, 3.834625, 0.556863, 0.556863, 0.556863, 1.000000, 0.459717, + 0.541344, 0.160891, 4.000000, 3.834625, 0.600000, 0.600000, 0.600000, + 1.000000, 0.500000, 1.000000, 0.000000, 4.000000, 2.000000, 0.556863, + 0.556863, 0.556863, 1.000000, 0.500000, 0.541344, 0.000000, 4.000000, + 3.834625, 0.556863, 0.556863, 0.556863, 1.000000, 0.540283, 0.541344, + -0.160891, 4.000000, 3.834625, + 0.396078, 0.396078, 0.396078, 1.000000, 0.517212, -0.267902, -0.068730, + 4.000000, 7.071609, 0.396078, 0.396078, 0.396078, 1.000000, 0.500000, + -0.270672, 0.000000, 4.000000, 7.082688, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.364706, + 0.364706, 0.364706, 1.000000, 0.500000, -0.500000, 0.000000, 4.000000, + 8.000000, + 0.400000, 0.400000, 0.400000, 1.000000, 0.546143, -0.250068, -0.184711, + 4.000000, 7.000273, 0.396078, 0.396078, 0.396078, 1.000000, 0.532715, + -0.260554, -0.130636, 4.000000, 7.042214, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.396078, + 0.396078, 0.396078, 1.000000, 0.517212, -0.267902, -0.068730, 4.000000, + 7.071609, + 0.403922, 0.403922, 0.403922, 1.000000, 0.574829, -0.212276, -0.299425, + 4.000000, 6.849104, 0.400000, 0.400000, 0.400000, 1.000000, 0.561768, + -0.232438, -0.247284, 4.000000, 6.929754, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.400000, + 0.400000, 0.400000, 1.000000, 0.546143, -0.250068, -0.184711, 4.000000, + 7.000273, + 0.411765, 0.411765, 0.411765, 1.000000, 0.596313, -0.162957, -0.385368, + 4.000000, 6.651829, 0.407843, 0.407843, 0.407843, 1.000000, 0.585327, + -0.191394, -0.341301, 4.000000, 6.765576, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.403922, + 0.403922, 0.403922, 1.000000, 0.574829, -0.212276, -0.299425, 4.000000, + 6.849104, + 0.423529, 0.423529, 0.423529, 1.000000, 0.611450, -0.103582, -0.445931, + 4.000000, 6.414327, 0.415686, 0.415686, 0.415686, 1.000000, 0.604980, + -0.133318, -0.420033, 4.000000, 6.533272, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.411765, + 0.411765, 0.411765, 1.000000, 0.596313, -0.162957, -0.385368, 4.000000, + 6.651829, + 0.435294, 0.435294, 0.435294, 1.000000, 0.619629, -0.034595, -0.478689, + 4.000000, 6.138380, 0.427451, 0.427451, 0.427451, 1.000000, 0.616577, + -0.069344, -0.466541, 4.000000, 6.277375, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, 0.423529, + 0.423529, 0.423529, 1.000000, 0.611450, -0.103582, -0.445931, 4.000000, + 6.414327, + 0.513726, 0.513726, 0.513726, 1.000000, 0.620728, 0.360896, -0.482673, + 4.000000, 4.556417, 0.474510, 0.474510, 0.474510, 1.000000, 0.620728, + 0.180448, -0.482673, 4.000000, 5.278208, 0.427451, 0.427451, 0.427451, + 1.000000, 1.000000, 0.000000, -2.000000, 4.000000, 6.000000, 0.439216, + 0.439216, 0.439216, 1.000000, 0.620728, 0.000000, -0.482673, 4.000000, + 6.000000, 0.356863, 0.356863, 0.356863, 1.000000, 1.000000, -0.500000, + -2.000000, 4.000000, 8.000000, 0.435294, 0.435294, 0.435294, 1.000000, + 0.619629, -0.034595, -0.478689, 4.000000, 6.138380, + 0.333333, 0.333333, 0.333333, 1.000000, 1.500000, -0.500000, -4.000000, + 4.000000, 8.000000, 0.388235, 0.388235, 0.388235, 1.000000, 1.500000, + 0.000000, -4.000000, 4.000000, 6.000000, 0.427451, 0.427451, 0.427451, + 1.000000, 1.000000, 0.000000, -2.000000, 4.000000, 6.000000, 0.517647, + 0.517647, 0.517647, 1.000000, 1.000000, 0.500000, -2.000000, 4.000000, + 4.000000, 0.513726, 0.513726, 0.513726, 1.000000, 0.620728, 0.360896, + -0.482673, 4.000000, 4.556417, 0.545098, 0.545098, 0.545098, 1.000000, + 0.620728, 0.500000, -0.482673, 4.000000, 4.000000, + 0.333333, 0.333333, 0.333333, 1.000000, 1.500000, -0.500000, -4.000000, + 4.000000, 8.000000, 0.427451, 0.427451, 0.427451, 1.000000, 1.000000, + 0.000000, -2.000000, 4.000000, 6.000000, 0.356863, 0.356863, 0.356863, + 1.000000, 1.000000, -0.500000, -2.000000, 4.000000, 8.000000, + 0.556863, 0.556863, 0.556863, 1.000000, 0.540283, 0.541344, -0.160891, + 4.000000, 3.834625, 0.552941, 0.552941, 0.552941, 1.000000, 0.620728, + 0.541344, -0.482673, 4.000000, 3.834625, 0.545098, 0.545098, 0.545098, + 1.000000, 1.000000, 1.000000, -2.000000, 4.000000, 2.000000, 0.517647, + 0.517647, 0.517647, 1.000000, 1.000000, 0.500000, -2.000000, 4.000000, + 4.000000, 0.450980, 0.450980, 0.450980, 1.000000, 1.500000, 0.500000, + -4.000000, 4.000000, 4.000000, 0.388235, 0.388235, 0.388235, 1.000000, + 1.500000, 0.000000, -4.000000, 4.000000, 6.000000, + 0.517647, 0.517647, 0.517647, 1.000000, 1.000000, 0.500000, -2.000000, + 4.000000, 4.000000, 0.552941, 0.552941, 0.552941, 1.000000, 0.620728, + 0.541344, -0.482673, 4.000000, 3.834625, 0.545098, 0.545098, 0.545098, + 1.000000, 0.620728, 0.500000, -0.482673, 4.000000, 4.000000, + 0.450980, 0.450980, 0.450980, 1.000000, 1.500000, 0.500000, -4.000000, + 4.000000, 4.000000, 0.435294, 0.435294, 0.435294, 1.000000, 1.500000, + 1.000000, -4.000000, 4.000000, 2.000000, 0.545098, 0.545098, 0.545098, + 1.000000, 1.000000, 1.000000, -2.000000, 4.000000, 2.000000, + 0.439216, 0.439216, 0.439216, 1.000000, 0.379272, 0.000000, 0.482673, + 4.000000, 6.000000, 0.517647, 0.517647, 0.517647, 1.000000, 0.000000, + 0.500000, 2.000000, 4.000000, 4.000000, 0.427451, 0.427451, 0.427451, + 1.000000, 0.000000, 0.000000, 2.000000, 4.000000, 6.000000, + 0.556863, 0.556863, 0.556863, 1.000000, 0.540283, 0.541344, -0.160891, + 4.000000, 3.834625, 0.545098, 0.545098, 0.545098, 1.000000, 1.000000, + 1.000000, -2.000000, 4.000000, 2.000000, 0.600000, 0.600000, 0.600000, + 1.000000, 0.500000, 1.000000, 0.000000, 4.000000, 2.000000 +}; + + +/* Object: skin_12 */ + +static const int striplength_skin_12[] = { + 12, 12, 12, 12, 12, 0 +}; + +static const float stripdata_skin_12[] = { + 0.498039, 0.498039, 0.498039, 1.000000, -0.099976, 1.500000, -2.400000, + -4.000000, -0.000002, 0.337255, 0.337255, 0.337255, 1.000000, -0.500000, + 1.500000, -4.000000, -4.000000, -0.000002, 0.568627, 0.568627, 0.568627, + 1.000000, -0.099976, 1.100000, -2.400000, -4.000000, 1.599999, 0.341176, + 0.341176, 0.341176, 1.000000, -0.500000, 1.100000, -4.000000, -4.000000, + 1.599999, 0.498039, 0.498039, 0.498039, 1.000000, -0.099976, 0.700000, + -2.400000, -4.000000, 3.200000, 0.325490, 0.325490, 0.325490, 1.000000, + -0.500000, 0.700000, -4.000000, -4.000000, 3.199999, 0.352941, 0.352941, + 0.352941, 1.000000, -0.099976, 0.300000, -2.400000, -4.000000, 4.800000, + 0.282353, 0.282353, 0.282353, 1.000000, -0.500000, 0.300000, -4.000000, + -4.000000, 4.800000, 0.282353, 0.282353, 0.282353, 1.000000, -0.099976, + -0.100000, -2.400000, -4.000000, 6.400001, 0.254902, 0.254902, 0.254902, + 1.000000, -0.500000, -0.100000, -4.000000, -4.000000, 6.400000, + 0.239216, 0.239216, 0.239216, 1.000000, -0.099976, -0.500000, -2.400000, + -4.000000, 8.000000, 0.227451, 0.227451, 0.227451, 1.000000, -0.500000, + -0.500000, -4.000000, -4.000000, 8.000000, + 0.239216, 0.239216, 0.239216, 1.000000, 1.099976, -0.500000, 2.400001, + -4.000000, 8.000000, 0.227451, 0.227451, 0.227451, 1.000000, 1.500000, + -0.500000, 4.000002, -4.000000, 8.000000, 0.282353, 0.282353, 0.282353, + 1.000000, 1.099976, -0.100000, 2.400001, -4.000000, 6.400001, 0.254902, + 0.254902, 0.254902, 1.000000, 1.500000, -0.100000, 4.000002, -4.000000, + 6.400001, 0.352941, 0.352941, 0.352941, 1.000000, 1.099976, 0.300000, + 2.400002, -4.000000, 4.800001, 0.282353, 0.282353, 0.282353, 1.000000, + 1.500000, 0.300000, 4.000002, -4.000000, 4.800001, 0.498039, 0.498039, + 0.498039, 1.000000, 1.099976, 0.700000, 2.400002, -4.000000, 3.200000, + 0.321569, 0.321569, 0.321569, 1.000000, 1.500000, 0.700000, 4.000003, + -4.000000, 3.200000, 0.568627, 0.568627, 0.568627, 1.000000, 1.099976, + 1.100000, 2.400002, -4.000000, 1.599999, 0.341176, 0.341176, 0.341176, + 1.000000, 1.500000, 1.100000, 4.000003, -4.000000, 1.599999, 0.494118, + 0.494118, 0.494118, 1.000000, 1.099976, 1.500000, 2.400003, -4.000000, + -0.000002, 0.337255, 0.337255, 0.337255, 1.000000, 1.500000, 1.500000, + 4.000004, -4.000000, -0.000002, + 0.639216, 0.639216, 0.639216, 1.000000, 0.300049, 1.500000, -0.799999, + -4.000000, -0.000002, 0.498039, 0.498039, 0.498039, 1.000000, -0.099976, + 1.500000, -2.400000, -4.000000, -0.000002, 0.858824, 0.858824, 0.858824, + 1.000000, 0.300049, 1.100000, -0.799999, -4.000000, 1.599999, 0.568627, + 0.568627, 0.568627, 1.000000, -0.099976, 1.100000, -2.400000, -4.000000, + 1.599999, 0.686275, 0.686275, 0.686275, 1.000000, 0.300049, 0.700000, + -0.799999, -4.000000, 3.200000, 0.498039, 0.498039, 0.498039, 1.000000, + -0.099976, 0.700000, -2.400000, -4.000000, 3.200000, 0.419608, 0.419608, + 0.419608, 1.000000, 0.300049, 0.300000, -0.800000, -4.000000, 4.800000, + 0.352941, 0.352941, 0.352941, 1.000000, -0.099976, 0.300000, -2.400000, + -4.000000, 4.800000, 0.298039, 0.298039, 0.298039, 1.000000, 0.300049, + -0.100000, -0.800000, -4.000000, 6.400001, 0.282353, 0.282353, 0.282353, + 1.000000, -0.099976, -0.100000, -2.400000, -4.000000, 6.400001, + 0.247059, 0.247059, 0.247059, 1.000000, 0.300049, -0.500000, -0.800000, + -4.000000, 8.000000, 0.239216, 0.239216, 0.239216, 1.000000, -0.099976, + -0.500000, -2.400000, -4.000000, 8.000000, + 0.639216, 0.639216, 0.639216, 1.000000, 0.699951, 1.500000, 0.800002, + -4.000000, -0.000002, 0.639216, 0.639216, 0.639216, 1.000000, 0.300049, + 1.500000, -0.799999, -4.000000, -0.000002, 0.858824, 0.858824, 0.858824, + 1.000000, 0.699951, 1.100000, 0.800001, -4.000000, 1.599999, 0.858824, + 0.858824, 0.858824, 1.000000, 0.300049, 1.100000, -0.799999, -4.000000, + 1.599999, 0.686275, 0.686275, 0.686275, 1.000000, 0.699951, 0.700000, + 0.800001, -4.000000, 3.200000, 0.686275, 0.686275, 0.686275, 1.000000, + 0.300049, 0.700000, -0.799999, -4.000000, 3.200000, 0.419608, 0.419608, + 0.419608, 1.000000, 0.699951, 0.300000, 0.800001, -4.000000, 4.800001, + 0.419608, 0.419608, 0.419608, 1.000000, 0.300049, 0.300000, -0.800000, + -4.000000, 4.800000, 0.298039, 0.298039, 0.298039, 1.000000, 0.699951, + -0.100000, 0.800001, -4.000000, 6.400001, 0.298039, 0.298039, 0.298039, + 1.000000, 0.300049, -0.100000, -0.800000, -4.000000, 6.400001, 0.247059, + 0.247059, 0.247059, 1.000000, 0.699951, -0.500000, 0.800000, -4.000000, + 8.000000, 0.247059, 0.247059, 0.247059, 1.000000, 0.300049, -0.500000, + -0.800000, -4.000000, 8.000000, + 0.494118, 0.494118, 0.494118, 1.000000, 1.099976, 1.500000, 2.400003, + -4.000000, -0.000002, 0.639216, 0.639216, 0.639216, 1.000000, 0.699951, + 1.500000, 0.800002, -4.000000, -0.000002, 0.568627, 0.568627, 0.568627, + 1.000000, 1.099976, 1.100000, 2.400002, -4.000000, 1.599999, 0.858824, + 0.858824, 0.858824, 1.000000, 0.699951, 1.100000, 0.800001, -4.000000, + 1.599999, 0.498039, 0.498039, 0.498039, 1.000000, 1.099976, 0.700000, + 2.400002, -4.000000, 3.200000, 0.686275, 0.686275, 0.686275, 1.000000, + 0.699951, 0.700000, 0.800001, -4.000000, 3.200000, 0.352941, 0.352941, + 0.352941, 1.000000, 1.099976, 0.300000, 2.400002, -4.000000, 4.800001, + 0.419608, 0.419608, 0.419608, 1.000000, 0.699951, 0.300000, 0.800001, + -4.000000, 4.800001, 0.282353, 0.282353, 0.282353, 1.000000, 1.099976, + -0.100000, 2.400001, -4.000000, 6.400001, 0.298039, 0.298039, 0.298039, + 1.000000, 0.699951, -0.100000, 0.800001, -4.000000, 6.400001, 0.239216, + 0.239216, 0.239216, 1.000000, 1.099976, -0.500000, 2.400001, -4.000000, + 8.000000, 0.247059, 0.247059, 0.247059, 1.000000, 0.699951, -0.500000, + 0.800000, -4.000000, 8.000000 +}; + + +/* Object: skin_11 */ + +static const int striplength_skin_11[] = { + 12, 12, 12, 12, 12, 0 +}; + +static const float stripdata_skin_11[] = { + 0.145098, 0.145098, 0.145098, 1.000000, -0.099976, 1.500000, -2.400000, + 4.000002, 0.000000, 0.141176, 0.141176, 0.141176, 1.000000, -0.500000, + 1.500000, -4.000000, 4.000002, 0.000000, 0.176471, 0.176471, 0.176471, + 1.000000, -0.099976, 1.100000, -2.400000, 2.400001, 0.000000, 0.145098, + 0.145098, 0.145098, 1.000000, -0.500000, 1.100000, -4.000000, 2.400001, + 0.000000, 0.341176, 0.341176, 0.341176, 1.000000, -0.099976, 0.700000, + -2.400000, 0.800000, 0.000000, 0.188235, 0.188235, 0.188235, 1.000000, + -0.500000, 0.700000, -4.000000, 0.800000, 0.000000, 0.450980, 0.450980, + 0.450980, 1.000000, -0.099976, 0.300000, -2.400000, -0.800000, 0.000000, + 0.247059, 0.247059, 0.247059, 1.000000, -0.500000, 0.300000, -4.000000, + -0.800000, 0.000000, 0.439216, 0.439216, 0.439216, 1.000000, -0.099976, + -0.100000, -2.400000, -2.400000, 0.000000, 0.270588, 0.270588, 0.270588, + 1.000000, -0.500000, -0.100000, -4.000000, -2.400000, 0.000000, + 0.364706, 0.364706, 0.364706, 1.000000, -0.099976, -0.500000, -2.400000, + -4.000000, 0.000000, 0.258824, 0.258824, 0.258824, 1.000000, -0.500000, + -0.500000, -4.000000, -4.000000, 0.000000, + 0.364706, 0.364706, 0.364706, 1.000000, 1.099976, -0.500000, 2.400001, + -4.000000, 0.000000, 0.258824, 0.258824, 0.258824, 1.000000, 1.500000, + -0.500000, 4.000002, -4.000000, 0.000000, 0.439216, 0.439216, 0.439216, + 1.000000, 1.099976, -0.100000, 2.400001, -2.400001, 0.000000, 0.270588, + 0.270588, 0.270588, 1.000000, 1.500000, -0.100000, 4.000002, -2.400001, + 0.000000, 0.454902, 0.454902, 0.454902, 1.000000, 1.099976, 0.300000, + 2.400002, -0.800000, 0.000000, 0.247059, 0.247059, 0.247059, 1.000000, + 1.500000, 0.300000, 4.000002, -0.800000, 0.000000, 0.341176, 0.341176, + 0.341176, 1.000000, 1.099976, 0.700000, 2.400002, 0.800000, 0.000000, + 0.184314, 0.184314, 0.184314, 1.000000, 1.500000, 0.700000, 4.000003, + 0.800000, 0.000000, 0.176471, 0.176471, 0.176471, 1.000000, 1.099976, + 1.100000, 2.400002, 2.400001, 0.000000, 0.145098, 0.145098, 0.145098, + 1.000000, 1.500000, 1.100000, 4.000003, 2.400001, 0.000000, 0.145098, + 0.145098, 0.145098, 1.000000, 1.099976, 1.500000, 2.400003, 4.000003, + 0.000000, 0.141176, 0.141176, 0.141176, 1.000000, 1.500000, 1.500000, + 4.000004, 4.000002, 0.000000, + 0.145098, 0.145098, 0.145098, 1.000000, 0.300049, 1.500000, -0.799999, + 4.000002, 0.000000, 0.145098, 0.145098, 0.145098, 1.000000, -0.099976, + 1.500000, -2.400000, 4.000002, 0.000000, 0.262745, 0.262745, 0.262745, + 1.000000, 0.300049, 1.100000, -0.799999, 2.400001, 0.000000, 0.176471, + 0.176471, 0.176471, 1.000000, -0.099976, 1.100000, -2.400000, 2.400001, + 0.000000, 0.580392, 0.580392, 0.580392, 1.000000, 0.300049, 0.700000, + -0.799999, 0.800000, 0.000000, 0.341176, 0.341176, 0.341176, 1.000000, + -0.099976, 0.700000, -2.400000, 0.800000, 0.000000, 0.709804, 0.709804, + 0.709804, 1.000000, 0.300049, 0.300000, -0.800000, -0.800000, 0.000000, + 0.450980, 0.450980, 0.450980, 1.000000, -0.099976, 0.300000, -2.400000, + -0.800000, 0.000000, 0.627451, 0.627451, 0.627451, 1.000000, 0.300049, + -0.100000, -0.800000, -2.400001, 0.000000, 0.439216, 0.439216, 0.439216, + 1.000000, -0.099976, -0.100000, -2.400000, -2.400000, 0.000000, + 0.458824, 0.458824, 0.458824, 1.000000, 0.300049, -0.500000, -0.800000, + -4.000000, 0.000000, 0.364706, 0.364706, 0.364706, 1.000000, -0.099976, + -0.500000, -2.400000, -4.000000, 0.000000, + 0.145098, 0.145098, 0.145098, 1.000000, 0.699951, 1.500000, 0.800002, + 4.000002, 0.000000, 0.145098, 0.145098, 0.145098, 1.000000, 0.300049, + 1.500000, -0.799999, 4.000002, 0.000000, 0.262745, 0.262745, 0.262745, + 1.000000, 0.699951, 1.100000, 0.800001, 2.400001, 0.000000, 0.262745, + 0.262745, 0.262745, 1.000000, 0.300049, 1.100000, -0.799999, 2.400001, + 0.000000, 0.580392, 0.580392, 0.580392, 1.000000, 0.699951, 0.700000, + 0.800001, 0.800000, 0.000000, 0.580392, 0.580392, 0.580392, 1.000000, + 0.300049, 0.700000, -0.799999, 0.800000, 0.000000, 0.713726, 0.713726, + 0.713726, 1.000000, 0.699951, 0.300000, 0.800001, -0.800000, 0.000000, + 0.709804, 0.709804, 0.709804, 1.000000, 0.300049, 0.300000, -0.800000, + -0.800000, 0.000000, 0.631373, 0.631373, 0.631373, 1.000000, 0.699951, + -0.100000, 0.800001, -2.400001, 0.000000, 0.627451, 0.627451, 0.627451, + 1.000000, 0.300049, -0.100000, -0.800000, -2.400001, 0.000000, 0.458824, + 0.458824, 0.458824, 1.000000, 0.699951, -0.500000, 0.800000, -4.000000, + 0.000000, 0.458824, 0.458824, 0.458824, 1.000000, 0.300049, -0.500000, + -0.800000, -4.000000, 0.000000, + 0.145098, 0.145098, 0.145098, 1.000000, 1.099976, 1.500000, 2.400003, + 4.000003, 0.000000, 0.145098, 0.145098, 0.145098, 1.000000, 0.699951, + 1.500000, 0.800002, 4.000002, 0.000000, 0.176471, 0.176471, 0.176471, + 1.000000, 1.099976, 1.100000, 2.400002, 2.400001, 0.000000, 0.262745, + 0.262745, 0.262745, 1.000000, 0.699951, 1.100000, 0.800001, 2.400001, + 0.000000, 0.341176, 0.341176, 0.341176, 1.000000, 1.099976, 0.700000, + 2.400002, 0.800000, 0.000000, 0.580392, 0.580392, 0.580392, 1.000000, + 0.699951, 0.700000, 0.800001, 0.800000, 0.000000, 0.454902, 0.454902, + 0.454902, 1.000000, 1.099976, 0.300000, 2.400002, -0.800000, 0.000000, + 0.713726, 0.713726, 0.713726, 1.000000, 0.699951, 0.300000, 0.800001, + -0.800000, 0.000000, 0.439216, 0.439216, 0.439216, 1.000000, 1.099976, + -0.100000, 2.400001, -2.400001, 0.000000, 0.631373, 0.631373, 0.631373, + 1.000000, 0.699951, -0.100000, 0.800001, -2.400001, 0.000000, 0.364706, + 0.364706, 0.364706, 1.000000, 1.099976, -0.500000, 2.400001, -4.000000, + 0.000000, 0.458824, 0.458824, 0.458824, 1.000000, 0.699951, -0.500000, + 0.800000, -4.000000, 0.000000 +}; + + +/* Object: skin_9 */ + +static const int striplength_skin_9[] = { + 18, 0 +}; + +static const float stripdata_skin_9[] = { + 0.384314, 0.384314, 0.384314, 1.000000, -0.500000, 1.500000, -4.000000, + 4.000000, 8.000000, 0.384314, 0.384314, 0.384314, 1.000000, 1.500000, + 1.500000, 4.000000, 4.000000, 8.000000, 0.376471, 0.376471, 0.376471, + 1.000000, -0.500000, 1.250000, -4.000000, 3.695518, 9.530733, 0.403922, + 0.403922, 0.403922, 1.000000, 1.500000, 1.250000, 4.000000, 3.695518, + 9.530733, 0.415686, 0.415686, 0.415686, 1.000000, -0.500000, 1.000000, + -4.000000, 2.828427, 10.828427, 0.431373, 0.431373, 0.431373, 1.000000, + 1.500000, 1.000000, 4.000000, 2.828427, 10.828427, 0.435294, 0.435294, + 0.435294, 1.000000, -0.500000, 0.750000, -4.000000, 1.530734, 11.695518, + 0.443137, 0.443137, 0.443137, 1.000000, 1.500000, 0.750000, 4.000000, + 1.530734, 11.695518, 0.439216, 0.439216, 0.439216, 1.000000, -0.500000, + 0.500000, -4.000000, 0.000000, 12.000000, 0.435294, 0.435294, 0.435294, + 1.000000, 1.500000, 0.500000, 4.000000, 0.000000, 12.000000, 0.427451, + 0.427451, 0.427451, 1.000000, -0.500000, 0.250000, -4.000000, -1.530734, + 11.695518, 0.411765, 0.411765, 0.411765, 1.000000, 1.500000, 0.250000, + 4.000000, -1.530734, 11.695518, 0.396078, 0.396078, 0.396078, 1.000000, + -0.500000, 0.000000, -4.000000, -2.828427, 10.828427, 0.368627, + 0.368627, 0.368627, 1.000000, 1.500000, 0.000000, 4.000000, -2.828427, + 10.828427, 0.341176, 0.341176, 0.341176, 1.000000, -0.500000, -0.250000, + -4.000000, -3.695518, 9.530733, 0.301961, 0.301961, 0.301961, 1.000000, + 1.500000, -0.250000, 4.000000, -3.695518, 9.530733, 0.294118, 0.294118, + 0.294118, 1.000000, -0.500000, -0.500000, -4.000000, -4.000000, + 8.000000, 0.294118, 0.294118, 0.294118, 1.000000, 1.500000, -0.500000, + 4.000000, -4.000000, 8.000000 +}; diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c new file mode 100644 index 00000000000..ce416712fe2 --- /dev/null +++ b/progs/demos/vao_demo.c @@ -0,0 +1,330 @@ +/* + * (C) Copyright IBM Corporation 2006 + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#ifdef __darwin__ +#include <GLUT/glut.h> + +typedef void (* PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (* PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (* PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef GLboolean (* PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); + +#else +#include <GL/glut.h> +#endif + +static PFNGLBINDVERTEXARRAYAPPLEPROC bind_vertex_array = NULL; +static PFNGLGENVERTEXARRAYSAPPLEPROC gen_vertex_arrays = NULL; +static PFNGLDELETEVERTEXARRAYSAPPLEPROC delete_vertex_arrays = NULL; +static PFNGLISVERTEXARRAYAPPLEPROC is_vertex_array = NULL; + +static int Width = 400; +static int Height = 200; +static int Win = 0; +static const GLfloat Near = 5.0, Far = 25.0; +static GLfloat angle = 0.0; + +static GLuint cube_array_obj = 0; +static GLuint oct_array_obj = 0; + +static const GLfloat cube_vert[] = { + -0.5, -0.5, -0.5, 1.0, + 0.5, -0.5, -0.5, 1.0, + 0.5, 0.5, -0.5, 1.0, + -0.5, 0.5, -0.5, 1.0, + + -0.5, -0.5, 0.5, 1.0, + 0.5, -0.5, 0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, + -0.5, 0.5, 0.5, 1.0, + + -0.5, 0.5, -0.5, 1.0, + 0.5, 0.5, -0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, + -0.5, 0.5, 0.5, 1.0, + + -0.5, -0.5, -0.5, 1.0, + 0.5, -0.5, -0.5, 1.0, + 0.5, -0.5, 0.5, 1.0, + -0.5, -0.5, 0.5, 1.0, + + 0.5, -0.5, -0.5, 1.0, + 0.5, -0.5, 0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, + 0.5, 0.5, -0.5, 1.0, + + -0.5, -0.5, -0.5, 1.0, + -0.5, -0.5, 0.5, 1.0, + -0.5, 0.5, 0.5, 1.0, + -0.5, 0.5, -0.5, 1.0, + +}; + +static const GLfloat cube_color[] = { + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + + 0.0, 1.0, 0.0, 1.0, + 0.0, 1.0, 0.0, 1.0, + 0.0, 1.0, 0.0, 1.0, + 0.0, 1.0, 0.0, 1.0, + + 0.0, 0.0, 1.0, 1.0, + 0.0, 0.0, 1.0, 1.0, + 0.0, 0.0, 1.0, 1.0, + 0.0, 0.0, 1.0, 1.0, + + 1.0, 0.0, 1.0, 1.0, + 1.0, 0.0, 1.0, 1.0, + 1.0, 0.0, 1.0, 1.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, + 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + + 0.5, 0.5, 0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, + 0.5, 0.5, 0.5, 1.0, +}; + +static const GLfloat oct_vert[] = { + 0.0, 0.0, 0.7071, 1.0, + 0.5, 0.5, 0.0, 1.0, + -0.5, 0.5, 0.0, 1.0, + + 0.0, 0.0, 0.7071, 1.0, + 0.5, -0.5, 0.0, 1.0, + -0.5, -0.5, 0.0, 1.0, + + 0.0, 0.0, 0.7071, 1.0, + -0.5, -0.5, 0.0, 1.0, + -0.5, 0.5, 0.0, 1.0, + + 0.0, 0.0, 0.7071, 1.0, + 0.5, 0.5, 0.0, 1.0, + 0.5, -0.5, 0.0, 1.0, + + + 0.0, 0.0, -0.7071, 1.0, + 0.5, 0.5, 0.0, 1.0, + -0.5, 0.5, 0.0, 1.0, + + 0.0, 0.0, -0.7071, 1.0, + 0.5, -0.5, 0.0, 1.0, + -0.5, -0.5, 0.0, 1.0, + + 0.0, 0.0, -0.7071, 1.0, + -0.5, -0.5, 0.0, 1.0, + -0.5, 0.5, 0.0, 1.0, + + 0.0, 0.0, -0.7071, 1.0, + 0.5, 0.5, 0.0, 1.0, + 0.5, -0.5, 0.0, 1.0, +}; + +static const GLfloat oct_color[] = { + 1.0, 0.64, 0.0, 1.0, + 1.0, 0.64, 0.0, 1.0, + 1.0, 0.64, 0.0, 1.0, + + 0.8, 0.51, 0.0, 1.0, + 0.8, 0.51, 0.0, 1.0, + 0.8, 0.51, 0.0, 1.0, + + 0.5, 0.32, 0.0, 1.0, + 0.5, 0.32, 0.0, 1.0, + 0.5, 0.32, 0.0, 1.0, + + 0.2, 0.13, 0.0, 1.0, + 0.2, 0.13, 0.0, 1.0, + 0.2, 0.13, 0.0, 1.0, + + 0.2, 0.13, 0.0, 1.0, + 0.2, 0.13, 0.0, 1.0, + 0.2, 0.13, 0.0, 1.0, + + 0.5, 0.32, 0.0, 1.0, + 0.5, 0.32, 0.0, 1.0, + 0.5, 0.32, 0.0, 1.0, + + 0.8, 0.51, 0.0, 1.0, + 0.8, 0.51, 0.0, 1.0, + 0.8, 0.51, 0.0, 1.0, + + 1.0, 0.64, 0.0, 1.0, + 1.0, 0.64, 0.0, 1.0, + 1.0, 0.64, 0.0, 1.0, +}; + +static void Display( void ) +{ + glClearColor(0.1, 0.1, 0.4, 0); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); + glRotatef( angle, 0.0 * angle , 0.0 * angle, 1.0 ); + + + (*bind_vertex_array)( cube_array_obj ); + glPushMatrix(); + glTranslatef(-1.5, 0, 0); + glRotatef( angle, 0.3 * angle , 0.8 * angle, 1.0 ); + glDrawArrays( GL_QUADS, 0, 4 * 6 ); + glPopMatrix(); + + + (*bind_vertex_array)( oct_array_obj ); + glPushMatrix(); + glTranslatef(1.5, 0, 0); + glRotatef( angle, 0.3 * angle , 0.8 * angle, 1.0 ); + glDrawArrays( GL_TRIANGLES, 0, 3 * 8 ); + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Idle( void ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + + angle += 70.0 * dt; /* 70 degrees per second */ + angle = fmod(angle, 360.0); /* prevents eventual overflow */ + + glutPostRedisplay(); +} + + +static void Visible( int vis ) +{ + if ( vis == GLUT_VISIBLE ) { + glutIdleFunc( Idle ); + } + else { + glutIdleFunc( NULL ); + } +} +static void Reshape( int width, int height ) +{ + GLfloat ar = (float) width / (float) height; + Width = width; + Height = height; + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ar, ar, -1.0, 1.0, Near, Far ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char * const ver_string = (const char * const) + glGetString( GL_VERSION ); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", ver_string); + + if ( !glutExtensionSupported("GL_APPLE_vertex_array_object") ) { + printf("Sorry, this program requires GL_APPLE_vertex_array_object\n"); + exit(1); + } + + bind_vertex_array = (PFNGLBINDVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glBindVertexArrayAPPLE" ); + gen_vertex_arrays = (PFNGLGENVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glGenVertexArraysAPPLE" ); + delete_vertex_arrays = (PFNGLDELETEVERTEXARRAYSAPPLEPROC) glutGetProcAddress( "glDeleteVertexArraysAPPLE" ); + is_vertex_array = (PFNGLISVERTEXARRAYAPPLEPROC) glutGetProcAddress( "glIsVertexArrayAPPLE" ); + + assert(bind_vertex_array); + assert(gen_vertex_arrays); + assert(delete_vertex_arrays); + assert(is_vertex_array); + + glEnable( GL_DEPTH_TEST ); + + (*gen_vertex_arrays)( 1, & cube_array_obj ); + (*bind_vertex_array)( cube_array_obj ); + glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, cube_vert); + glColorPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, cube_color); + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + (*gen_vertex_arrays)( 1, & oct_array_obj ); + (*bind_vertex_array)( oct_array_obj ); + glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, oct_vert); + glColorPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, oct_color); + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + (*bind_vertex_array)( 0 ); + glVertexPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xDEADBEEF ); + glColorPointer( 4, GL_FLOAT, sizeof(GLfloat) * 4, (void *) 0xBADDC0DE ); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( Width, Height ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + Win = glutCreateWindow( "GL_APPLE_vertex_array_object demo" ); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + glutVisibilityFunc( Visible ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/winpos.c b/progs/demos/winpos.c new file mode 100644 index 00000000000..2ee1df69fbc --- /dev/null +++ b/progs/demos/winpos.c @@ -0,0 +1,118 @@ + +/* + * Example of how to use the GL_MESA_window_pos extension. + * Brian Paul This file is in the public domain. + */ + +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_PROTOTYPES +#include "GL/glut.h" + +#include "readtex.h" + +#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; + +typedef void (APIENTRY * PFNWINDOWPOSFUNC)(GLfloat x, GLfloat y); +static PFNWINDOWPOSFUNC WindowPosFunc; + +static void draw( void ) +{ + GLfloat angle; + + 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!!! */ + (*WindowPosFunc)( x, y ); + + glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image ); + } + glFinish(); +} + + +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 ) +{ +#ifdef GL_ARB_window_pos + if (glutExtensionSupported("GL_ARB_window_pos")) { + printf("Using GL_ARB_window_pos\n"); + WindowPosFunc = &glWindowPos2fARB; + } + else +#elif defined(GL_ARB_window_pos) + if (glutExtensionSupported("GL_MESA_window_pos")) { + printf("Using GL_MESA_window_pos\n"); + WindowPosFunc = &glWindowPos2fMESA; + } + else +#endif + { + printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); + exit(1); + } + + 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/ggi/asc-view.c b/progs/ggi/asc-view.c new file mode 100644 index 00000000000..d37fba9d9f7 --- /dev/null +++ b/progs/ggi/asc-view.c @@ -0,0 +1,377 @@ +/* + test program for the ggi-mesa driver + + Copyright (C) 1997,1998 Uwe Maurer - [email protected] + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <sys/time.h> +#include <stdio.h> +#include <string.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/ggimesa.h> +#include <ggi/ggi.h> +#include <stdlib.h> + +ggi_visual_t vis,vis_mem; + +GGIMesaContext ctx; + +int screen_x=GGI_AUTO,screen_y=GGI_AUTO; +ggi_graphtype bpp=GT_AUTO; + +//#define ZBUFFER + +//#define SMOOTH_NORMALS + +void Init() +{ + GLfloat h=(GLfloat)3/4; + GLfloat pos[4]={5,5,-20,0}; + GLfloat specular[4]={.4,.4,.4,1}; + GLfloat diffuse[4]={.3,.3,.3,1}; + GLfloat ambient[4]={.2,.2,.2,1}; + + int err; + + if (ggiInit()<0) + { + printf("ggiInit() failed\n"); + exit(1); + } + ctx=GGIMesaCreateContext(); + if (ctx==NULL) + { + printf("Can't create Context!\n"); + exit(1); + } + + vis=ggiOpen(NULL); + vis_mem=ggiOpen("display-memory",NULL); + if (vis==NULL || vis_mem==NULL) + { + printf("Can't open ggi_visuals!\n"); + exit(1); + } + err=ggiSetGraphMode(vis,screen_x,screen_y,screen_x,screen_y,bpp); + err+=ggiSetGraphMode(vis_mem,screen_x,screen_y,screen_x,screen_y,bpp); + if (err) + { + printf("Can't set %ix%i\n",screen_x,screen_y); + exit(1); + } + + if (GGIMesaSetVisual(ctx,vis_mem,GL_TRUE,GL_FALSE)<0) + { + printf("GGIMesaSetVisual() failed!\n"); + exit(1); + } + + GGIMesaMakeCurrent(ctx); + + glViewport(0,0,screen_x,screen_y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1,1,-h,h,1,50); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0,0,-9); + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glLightfv(GL_LIGHT0,GL_POSITION,pos); + + glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse); + glLightfv(GL_LIGHT0,GL_AMBIENT,ambient); + glLightfv(GL_LIGHT0,GL_SPECULAR,specular); + + #ifdef ZBUFFER + glEnable(GL_DEPTH_TEST); + #endif +} + + +#define MAX_VERTS 1000 +#define MAX_TRIS 2000 +#define MAX_LEN 1024 +#define MAX_F 100000000 + +void LoadAsc(GLuint *list,char *file) +{ + FILE *fp; + + GLfloat p[MAX_VERTS][3]; + GLfloat normal[MAX_VERTS][3]; + float ncount[MAX_VERTS]; + int v[MAX_TRIS][3]; + char line[MAX_LEN]; + char *s; + int i,j; + int verts,faces; + GLuint v0,v1,v2; + GLfloat n[3]; + GLfloat len,k; + GLfloat min[3]={MAX_F,MAX_F,MAX_F}; + GLfloat max[3]={-MAX_F,-MAX_F,-MAX_F}; + char *coord_str[]={"X","Z","Y"}; + + fp=fopen(file,"r"); + if (!fp) + { + printf("Can't open %s!\n",file); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Tri-mesh",8)) ; + + s=strstr(line,":")+1; + verts=atoi(s); + s=strstr(s,":")+1; + faces=atoi(s); + + if (verts>MAX_VERTS) + { + printf("Too many vertices..\n"); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Vertex list",11)) ; + + for (i=0;i<verts;i++) + { + while (strncmp(fgets(line,MAX_LEN,fp),"Vertex",6)) ; + for (j=0;j<3;j++) + { + s=strstr(line,coord_str[j])+2; + k=atoi(s); + if (k>max[j]) max[j]=k; + if (k<min[j]) min[j]=k; + p[i][j]=k; + } + + } + len=0; + for (i=0;i<3;i++) + { + k=max[i]-min[i]; + if (k>len) {len=k;j=i;} + n[i]=(max[i]+min[i])/2; + } + + len/=2; + + for (i=0;i<verts;i++) + { + for (j=0;j<3;j++) + { + p[i][j]-=n[j]; + p[i][j]/=len; + } + } + + *list=glGenLists(1); + glNewList(*list,GL_COMPILE); + glBegin(GL_TRIANGLES); + + memset(ncount,0,sizeof(ncount)); + memset(normal,0,sizeof(normal)); + + while (strncmp(fgets(line,MAX_LEN,fp),"Face list",9)) ; + for (i=0;i<faces;i++) + { + while (strncmp(fgets(line,MAX_LEN,fp),"Face",4)) ; + s=strstr(line,"A")+2; + v0=v[i][0]=atoi(s); + s=strstr(line,"B")+2; + v1=v[i][1]=atoi(s); + s=strstr(line,"C")+2; + v2=v[i][2]=atoi(s); + n[0]=((p[v1][1]-p[v0][1])*(p[v2][2]-p[v0][2]) + - (p[v1][2]-p[v0][2])*(p[v2][1]-p[v0][1])); + n[1]=((p[v1][2]-p[v0][2])*(p[v2][0]-p[v0][0]) + - (p[v1][0]-p[v0][0])*(p[v2][2]-p[v0][2])); + n[2]=((p[v1][0]-p[v0][0])*(p[v2][1]-p[v0][1]) + - (p[v1][1]-p[v0][1])*(p[v2][0]-p[v0][0])); + len=n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; + len=sqrt(len); + n[0]/=len; + n[1]/=len; + n[2]/=len; + #ifdef SMOOTH_NORMALS + for (j=0;j<3;j++){ + normal[v[i][j]][0]+=n[0]; + normal[v[i][j]][1]+=n[1]; + normal[v[i][j]][2]+=n[2]; + ncount[v[i][j]]++; + } + #else + glNormal3fv(n); + for (j=0;j<3;j++) + glVertex3fv(p[v[i][j]]); + #endif + } + + #ifdef SMOOTH_NORMALS + for (i=0;i<verts;i++) { + for (j=0;j<3;j++) { + normal[i][j]/=ncount[i]; + } + } + for (i=0;i<faces;i++) { + for (j=0;j<3;j++) { + glNormal3f(normal[v[i][j]][0], + normal[v[i][j]][1], + normal[v[i][j]][2]); + glVertex3fv(p[v[i][j]]); + } + } + #endif + + glEnd(); + glEndList(); + fclose(fp); +} + +double Display(GLuint l,int *maxframes) +{ + int x,y; + GLfloat col[]={.25,0,.25,1}; + int frames=0; + struct timeval start,stop; + double len; + GLfloat rotate=0; + + gettimeofday(&start,NULL); + + + while(1) + { + glClearColor(0,0,0,0); + glClearIndex(0); + + #ifdef ZBUFFER + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + #else + glClear(GL_COLOR_BUFFER_BIT); + #endif + + glPushMatrix(); + + glRotatef(30,1,0,0); + glRotatef(rotate/10,0,0,1); + glTranslatef(-6,-4,0); + for (y=0;y<3;y++) + { + glPushMatrix(); + for (x=0;x<5;x++) + { + glPushMatrix(); + glRotatef(rotate,y+1,-x-1,0); + + col[0]=(GLfloat)(x+1)/4; + col[1]=0; + col[2]=(GLfloat)(y+1)/2; + glMaterialfv(GL_FRONT,GL_AMBIENT,col); + glCallList(l); + glPopMatrix(); + glTranslatef(3,0,0); + } + glPopMatrix(); + glTranslatef(0,4,0); + } + glPopMatrix(); + glFinish(); + + ggiPutBox(vis,0,0,screen_x,screen_y,ggiDBGetBuffer(vis,0)->read); + rotate+=10; + frames++; + if (frames==(*maxframes)) break; + + if (ggiKbhit(vis)) + { + *maxframes=frames; + break; + } + } + + gettimeofday(&stop,NULL); + len=(double)(stop.tv_sec-start.tv_sec)+ + (double)(stop.tv_usec-start.tv_usec)/1e6; + return len; +} + +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("asc-view"); + init(); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutVisibilityFunc(visible); + + glutMainLoop(); +#if 0 + GLuint l; + char *file; + int maxframes=0; + double len; + + Init(); + + file=(argc>1) ? argv[1] : "asc/box.asc"; + if (argc>2) maxframes=atoi(argv[2]); + + if (argc==1) + { + printf("usage: %s filename.asc\n",argv[0]); + } + + LoadAsc(&l,file); + + len=Display(l,&maxframes); + + printf("\ttime: %.3f sec\n",len); + printf("\tframes: %i\n",maxframes); + printf("\tfps: %.3f \n",(double)maxframes/len); + + GGIMesaDestroyContext(ctx); + ggiClose(vis); + ggiClose(vis_mem); + ggiExit(); +#endif + return 0; +} + diff --git a/progs/ggi/gears.c b/progs/ggi/gears.c new file mode 100644 index 00000000000..ac2e9f2a6ea --- /dev/null +++ b/progs/ggi/gears.c @@ -0,0 +1,340 @@ +/* $Id: gears.c,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + +#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); /* FIXME: Shutdown and free resources cleanly in ggiglut */ + 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; +} diff --git a/progs/ggi/gears2.c b/progs/ggi/gears2.c new file mode 100644 index 00000000000..9468c031777 --- /dev/null +++ b/progs/ggi/gears2.c @@ -0,0 +1,390 @@ +/* gears.c */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + * modified by Uwe Maurer ([email protected]) + */ + +#include <string.h> +#include <math.h> +#include <stdlib.h> +#include <ggi/ggi.h> +#include <GL/ggimesa.h> +#ifndef M_PI +# define M_PI 3.14159265 +#endif + + +ggi_visual_t vis; +char text[100]; +int db_flag,vis_x, vis_y, vir_x, vir_y, gt; + +/* + * 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;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 ); + 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 GLuint limit; +static GLuint count = 1; + + +static void draw( void ) +{ + static int n = 0; + glClearColor(0,0,0,0); + glClearIndex(0); + 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(); + glFlush(); + glFinish(); + +#if 0 + ggiSetGCForeground(vis,255); + ggiPuts(vis,0,0,"Mesa -> GGI"); + ggiPuts(vis,0,ggiGetInfo(vis)->mode->visible.y," Mesa -> GGI"); + + ggiPuts(vis,0,16,text); + ggiPuts(vis,0,ggiGetInfo(vis)->mode->visible.y+16,text); +#endif + + if(db_flag) + ggiMesaSwapBuffers(); + + count++; + if (count==limit) { + exit(1); + } + ++n; + /* + if (!(n%10)){ + ggi_color rgb = { 10000, 10000, 10000 }; + ggiSetSimpleMode(vis,vis_x+(n/10),vis_y+(n/10),db_flag?2:1, gt); + glViewport(0, 0,vis_x+(n/10),vis_y+(n/10)); + ggiSetGCForeground(vis, ggiMapColor(vis, &rgb)); + ggiDrawBox(vis, 20, 20, 100, 100); + if(db_flag) + ggiSetWriteFrame(vis, 1); + } + */ +} + +static void idle( void ) +{ + angle += 2.0; + draw(); +} + +/* new window size or exposure */ +static void reshape( int width, int height ) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + if(db_flag) + glDrawBuffer(GL_BACK); + else + glDrawBuffer(GL_FRONT); + 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 ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + +} + + +static void init( void ) +{ + static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 }; + static GLfloat red[4] = {0.9, 0.9, 0.9, 1.0 }; + static GLfloat green[4] = {0.0, 0.8, 0.9, 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 ); + glIndexi(1); + 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 ); + glIndexi(2); + 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 ); + glIndexi(3); + gear( 1.3, 2.0, 0.5, 10, 0.7 ); + glEndList(); + + glEnable( GL_NORMALIZE ); +} + +static void usage(char *s) +{ + printf("%s visible_x visible_y virtual_x virtual_y bpp db_flag\n",s); + printf("example:\n"); + printf("%s 320 200 320 400 8 1\n",s); + exit(1); +} + +int main( int argc, char *argv[] ) +{ + ggi_mesa_context_t ctx; + ggi_mode mode; + int bpp; + + limit=0; + + if (argc<7) usage(argv[0]); + + vis_x=atoi(argv[1]); + vis_y=atoi(argv[2]); + vir_x=atoi(argv[3]); + vir_y=atoi(argv[4]); + bpp=atoi(argv[5]); + db_flag=atoi(argv[6]); + + switch(bpp) + { + case 4: gt=GT_4BIT;break; + case 8: gt=GT_8BIT;break; + case 15:gt=GT_15BIT;break; + case 16:gt=GT_16BIT;break; + case 24:gt=GT_24BIT;break; + case 32:gt=GT_32BIT;break; + default: + printf("%i Bits per Pixel ???\n",bpp); + exit(1); + } + sprintf(text,"%sx%s %i colors, RGB mode, %s", + argv[1],argv[2],1<<bpp, + (db_flag) ? "doublebuffer" : "no doublebuffer"); + + if (ggiInit()<0) + { + printf("ggiInit() failed\n"); + exit(1); + } + + if (ggiMesaInit() < 0) + { + printf("ggiMesaInit failed\n"); + exit(1); + } + + vis=ggiOpen(NULL); + if (vis==NULL) + { + printf("ggiOpen() failed\n"); + exit(1); + } + + if (ggiSetSimpleMode(vis,vis_x,vis_y,db_flag ? 2 : 1,gt)<0) + { + printf("%s: can't set graphmode (%i %i %i %i) %i BPP\n", + argv[0],vis_x,vis_y,vir_x,vir_y,bpp); + exit(1); + } + + if (ggiMesaAttach(vis) < 0) + { + printf("ggiMesaAttach failed\n"); + exit(1); + } + if (ggiMesaExtendVisual(vis, GL_FALSE, GL_FALSE, 16, + 0, 0, 0, 0, 0, 1) < 0) + { + printf ("GGIMesaSetVisual() failed\n"); + exit(1); + } + + ctx = ggiMesaCreateContext(vis); + if (ctx==NULL) + { + printf("GGIMesaCreateContext() failed\n"); + exit(1); + } + + ggiMesaMakeCurrent(ctx, vis); + ggiGetMode(vis,&mode); + + reshape(mode.visible.x,mode.visible.y); + + init(); + + while (!ggiKbhit(vis)) { /*sleep(1);*/ idle(); } + + ggiMesaDestroyContext(ctx); + ggiClose(vis); + + printf("%s\n",text); + + ggiExit(); + return 0; +} diff --git a/progs/images/arch.rgb b/progs/images/arch.rgb Binary files differnew file mode 100644 index 00000000000..5f35bbd0aee --- /dev/null +++ b/progs/images/arch.rgb diff --git a/progs/images/bw.rgb b/progs/images/bw.rgb Binary files differnew file mode 100644 index 00000000000..f5de0f14026 --- /dev/null +++ b/progs/images/bw.rgb diff --git a/progs/images/girl.rgb b/progs/images/girl.rgb Binary files differnew file mode 100644 index 00000000000..ed5459c9c92 --- /dev/null +++ b/progs/images/girl.rgb diff --git a/progs/images/girl2.rgb b/progs/images/girl2.rgb Binary files differnew file mode 100644 index 00000000000..d5e557de072 --- /dev/null +++ b/progs/images/girl2.rgb diff --git a/progs/images/reflect.rgb b/progs/images/reflect.rgb Binary files differnew file mode 100644 index 00000000000..45319e96346 --- /dev/null +++ b/progs/images/reflect.rgb diff --git a/progs/images/s128.rgb b/progs/images/s128.rgb Binary files differnew file mode 100644 index 00000000000..79f5c1d98c6 --- /dev/null +++ b/progs/images/s128.rgb diff --git a/progs/images/tile.rgb b/progs/images/tile.rgb Binary files differnew file mode 100644 index 00000000000..5c1c73b06e4 --- /dev/null +++ b/progs/images/tile.rgb diff --git a/progs/images/tree2.rgba b/progs/images/tree2.rgba Binary files differnew file mode 100644 index 00000000000..67b02799cf5 --- /dev/null +++ b/progs/images/tree2.rgba diff --git a/progs/images/tree3.rgb b/progs/images/tree3.rgb Binary files differnew file mode 100644 index 00000000000..ce2c44dd663 --- /dev/null +++ b/progs/images/tree3.rgb diff --git a/progs/images/wrs_logo.rgb b/progs/images/wrs_logo.rgb Binary files differnew file mode 100644 index 00000000000..f1b921489a9 --- /dev/null +++ b/progs/images/wrs_logo.rgb diff --git a/progs/osdemos/Makefile b/progs/osdemos/Makefile new file mode 100644 index 00000000000..f8cba9ee99a --- /dev/null +++ b/progs/osdemos/Makefile @@ -0,0 +1,82 @@ +# progs/demos/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCDIR = $(TOP)/include + +OSMESA_LIBS = -L$(TOP)/$(LIB_DIR) -lOSMesa $(APP_LIB_DEPS) + +OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa16 -lGLU -lGL $(APP_LIB_DEPS) + +OSMESA32_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa32 -lGLU -lGL $(APP_LIB_DEPS) + +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) + +PROGS = \ + osdemo \ + ostest1 + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + + +# make executable from .c file: +.c: $(LIB_DEP) readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(APP_LIB_DEPS) -o $@ + + +##### TARGETS ##### + +default: readtex.o $(PROGS) + + +readtex.c: $(TOP)/progs/util/readtex.c + cp $< . + +readtex.h: $(TOP)/progs/util/readtex.h + cp $< . + +readtex.o: readtex.c readtex.h + $(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c + + +showbuffer.c: $(TOP)/progs/util/showbuffer.c + cp $< . + +showbuffer.h: $(TOP)/progs/util/showbuffer.h + cp $< . + +showbuffer.o: showbuffer.c showbuffer.h + $(CC) -c -I$(INCDIR) $(CFLAGS) showbuffer.c + + +# special case: need the -lOSMesa library: +osdemo: osdemo.c + $(CC) -I$(INCDIR) $(CFLAGS) osdemo.c $(OSMESA_LIBS) -o $@ + +# special case: need the -lOSMesa library: +ostest1: ostest1.c + $(CC) -I$(INCDIR) $(CFLAGS) ostest1.c $(OSMESA_LIBS) -o $@ + +# another special case: need the -lOSMesa16 library: +osdemo16: osdemo16.c + $(CC) -I$(INCDIR) $(CFLAGS) osdemo16.c $(OSMESA16_LIBS) -o $@ + +# another special case: need the -lOSMesa32 library: +osdemo32: osdemo32.c + $(CC) -I$(INCDIR) $(CFLAGS) osdemo32.c $(OSMESA32_LIBS) -o $@ + + + +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + -rm -f readtex.[ch] showbuffer.[ch] + -rm -f *.ppm + -rm -f osdemo16 osdemo32 + + diff --git a/progs/osdemos/osdemo.c b/progs/osdemos/osdemo.c new file mode 100644 index 00000000000..f7ce121f702 --- /dev/null +++ b/progs/osdemos/osdemo.c @@ -0,0 +1,316 @@ +/* + * Demo of off-screen Mesa rendering + * + * See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions. + * + * If you want to render BIG images you'll probably have to increase + * MAX_WIDTH and MAX_HEIGHT in src/config.h. + * + * This program is in the public domain. + * + * Brian Paul + * + * PPM output provided by Joerg Schmalzl. + * ASCII PPM output added by Brian Paul. + * + * Usage: osdemo [filename] + */ + + +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "GL/osmesa.h" +#include "GL/glu.h" + + +#define SAVE_TARGA + +#define WIDTH 400 +#define HEIGHT 400 + + +static void +Sphere(float radius, int slices, int stacks) +{ + GLUquadric *q = gluNewQuadric(); + gluQuadricNormals(q, GLU_SMOOTH); + gluSphere(q, radius, slices, stacks); + gluDeleteQuadric(q); +} + + +static void +Cone(float base, float height, int slices, int stacks) +{ + GLUquadric *q = gluNewQuadric(); + gluQuadricDrawStyle(q, GLU_FILL); + gluQuadricNormals(q, GLU_SMOOTH); + gluCylinder(q, base, 0.0, height, slices, stacks); + gluDeleteQuadric(q); +} + + +static void +Torus(float innerRadius, float outerRadius, int sides, int rings) +{ + /* from GLUT... */ + int i, j; + GLfloat theta, phi, theta1; + GLfloat cosTheta, sinTheta; + GLfloat cosTheta1, sinTheta1; + const GLfloat ringDelta = 2.0 * M_PI / rings; + const GLfloat sideDelta = 2.0 * M_PI / sides; + + theta = 0.0; + cosTheta = 1.0; + sinTheta = 0.0; + for (i = rings - 1; i >= 0; i--) { + theta1 = theta + ringDelta; + cosTheta1 = cos(theta1); + sinTheta1 = sin(theta1); + glBegin(GL_QUAD_STRIP); + phi = 0.0; + for (j = sides; j >= 0; j--) { + GLfloat cosPhi, sinPhi, dist; + + phi += sideDelta; + cosPhi = cos(phi); + sinPhi = sin(phi); + dist = outerRadius + innerRadius * cosPhi; + + glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); + glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, innerRadius * sinPhi); + glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); + glVertex3f(cosTheta * dist, -sinTheta * dist, innerRadius * sinPhi); + } + glEnd(); + theta = theta1; + cosTheta = cosTheta1; + sinTheta = sinTheta1; + } +} + + +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 ); + Torus(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 ); + Cone(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 ); + Sphere(1.0, 20, 20); + glPopMatrix(); + + glPopMatrix(); + + /* This is very important!!! + * Make sure buffered commands are finished!!! + */ + glFinish(); +} + + +#ifdef SAVE_TARGA + +static void +write_targa(const char *filename, const GLubyte *buffer, int width, int height) +{ + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLubyte *ptr = buffer; + printf ("osdemo, writing tga file \n"); + fputc (0x00, f); /* ID Length, 0 => No ID */ + fputc (0x00, f); /* Color Map Type, 0 => No color map included */ + fputc (0x02, f); /* Image Type, 2 => Uncompressed, True-color Image */ + fputc (0x00, f); /* Next five bytes are about the color map entries */ + fputc (0x00, f); /* 2 bytes Index, 2 bytes length, 1 byte size */ + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); /* X-origin of Image */ + fputc (0x00, f); + fputc (0x00, f); /* Y-origin of Image */ + fputc (0x00, f); + fputc (WIDTH & 0xff, f); /* Image Width */ + fputc ((WIDTH>>8) & 0xff, f); + fputc (HEIGHT & 0xff, f); /* Image Height */ + fputc ((HEIGHT>>8) & 0xff, f); + fputc (0x18, f); /* Pixel Depth, 0x18 => 24 Bits */ + fputc (0x20, f); /* Image Descriptor */ + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + fputc(ptr[i+2], f); /* write blue */ + fputc(ptr[i+1], f); /* write green */ + fputc(ptr[i], f); /* write red */ + } + } + } +} + +#else + +static void +write_ppm(const char *filename, const GLubyte *buffer, int width, int height) +{ + const int binary = 0; + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLubyte *ptr = buffer; + if (binary) { + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + fputc(ptr[i], f); /* write red */ + fputc(ptr[i+1], f); /* write green */ + fputc(ptr[i+2], f); /* write blue */ + } + } + } + else { + /*ASCII*/ + int counter = 0; + fprintf(f,"P3\n"); + fprintf(f,"# ascii ppm file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width, height); + fprintf(f,"255\n"); + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]); + counter++; + if (counter % 5 == 0) + fprintf(f, "\n"); + } + } + } + fclose(f); + } +} + +#endif + + + +int +main(int argc, char *argv[]) +{ + void *buffer; + int i; + char *filename = NULL; + + /* Create an RGBA-mode context */ +#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 + /* specify Z, stencil, accum sizes */ + OSMesaContext ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL ); +#else + OSMesaContext ctx = OSMesaCreateContext( OSMESA_RGBA, NULL ); +#endif + if (!ctx) { + printf("OSMesaCreateContext failed!\n"); + return 0; + } + + for (i = 1; i < argc; i++) { + if (argv[i][0] != '-') + filename = argv[i]; + } + + /* Allocate the image buffer */ + buffer = malloc( WIDTH * HEIGHT * 4 * sizeof(GLubyte) ); + if (!buffer) { + printf("Alloc image buffer failed!\n"); + return 0; + } + + /* Bind the buffer to the context and make it current */ + if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, WIDTH, HEIGHT )) { + printf("OSMesaMakeCurrent failed!\n"); + return 0; + } + + + { + int z, s, a; + glGetIntegerv(GL_DEPTH_BITS, &z); + glGetIntegerv(GL_STENCIL_BITS, &s); + glGetIntegerv(GL_ACCUM_RED_BITS, &a); + printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a); + } + + render_image(); + + if (filename != NULL) { +#ifdef SAVE_TARGA + write_targa(filename, buffer, WIDTH, HEIGHT); +#else + write_ppm(filename, buffer, WIDTH, HEIGHT); +#endif + } + else { + printf("Specify a filename if you want to make an image file\n"); + } + + printf("all done\n"); + + /* free the image buffer */ + free( buffer ); + + /* destroy the context */ + OSMesaDestroyContext( ctx ); + + return 0; +} diff --git a/progs/osdemos/osdemo16.c b/progs/osdemos/osdemo16.c new file mode 100644 index 00000000000..10ed695d7a5 --- /dev/null +++ b/progs/osdemos/osdemo16.c @@ -0,0 +1,291 @@ +/* + * Demo of off-screen Mesa rendering with 16-bit color channels. + * This requires the libOSMesa16.so library. + * + * Compile with something like this: + * + * gcc osdemo16.c -I../../include -L../../lib -lglut -lGLU -lOSMesa16 -lm -o osdemo16 + */ + + + +#include <stdio.h> +#include <stdlib.h> +#include "GL/osmesa.h" +#include "GL/glut.h" + + +#define SAVE_TARGA + + +#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, 0.5 }; + GLfloat blue_mat[] = { 0.2, 0.2, 1.0, 1.0 }; + GLfloat white_mat[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat purple_mat[] = { 1.0, 0.2, 1.0, 1.0 }; + GLUquadricObj *qobj = gluNewQuadric(); + + 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); + +#if 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(); +#endif + + /* red square */ + glPushMatrix(); + glTranslatef(0.0, -0.5, 0.0); + glRotatef(90, 1, 0.5, 0); + glScalef(3, 3, 3); + glDisable(GL_LIGHTING); + glColor4f(1, 0, 0, 0.5); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); + +#if 0 + /* green square */ + glPushMatrix(); + glTranslatef(0.0, 0.5, 0.1); + glDisable(GL_LIGHTING); + glColor3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); + + /* blue square */ + glPushMatrix(); + glTranslatef(0.75, 0.5, 0.3); + glDisable(GL_LIGHTING); + glColor3f(0, 0, 0.5); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); +#endif + 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 ); + glColor4f(0,1,0,0.5); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gluCylinder(qobj, 1.0, 0.0, 2.0, 16, 1); + glDisable(GL_BLEND); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.75, 1.0, 1.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat ); + gluSphere(qobj, 1.0, 20, 20); + glPopMatrix(); + + glPopMatrix(); + + /* This is very important!!! + * Make sure buffered commands are finished!!! + */ + glFinish(); + + gluDeleteQuadric(qobj); + + { + GLint r, g, b, a; + glGetIntegerv(GL_RED_BITS, &r); + glGetIntegerv(GL_GREEN_BITS, &g); + glGetIntegerv(GL_BLUE_BITS, &b); + glGetIntegerv(GL_ALPHA_BITS, &a); + printf("channel sizes: %d %d %d %d\n", r, g, b, a); + } +} + + + +static void +write_targa(const char *filename, const GLushort *buffer, int width, int height) +{ + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLushort *ptr = buffer; + printf ("osdemo, writing tga file \n"); + fputc (0x00, f); /* ID Length, 0 => No ID */ + fputc (0x00, f); /* Color Map Type, 0 => No color map included */ + fputc (0x02, f); /* Image Type, 2 => Uncompressed, True-color Image */ + fputc (0x00, f); /* Next five bytes are about the color map entries */ + fputc (0x00, f); /* 2 bytes Index, 2 bytes length, 1 byte size */ + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); /* X-origin of Image */ + fputc (0x00, f); + fputc (0x00, f); /* Y-origin of Image */ + fputc (0x00, f); + fputc (WIDTH & 0xff, f); /* Image Width */ + fputc ((WIDTH>>8) & 0xff, f); + fputc (HEIGHT & 0xff, f); /* Image Height */ + fputc ((HEIGHT>>8) & 0xff, f); + fputc (0x18, f); /* Pixel Depth, 0x18 => 24 Bits */ + fputc (0x20, f); /* Image Descriptor */ + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + /* just write 8 high bits */ + fputc(ptr[i+2] >> 8, f); /* write blue */ + fputc(ptr[i+1] >> 8, f); /* write green */ + fputc(ptr[i] >> 8, f); /* write red */ + } + } + } +} + + +static void +write_ppm(const char *filename, const GLushort *buffer, int width, int height) +{ + const int binary = 0; + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLushort *ptr = buffer; + if (binary) { + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + /* just write 8 high bits */ + fputc(ptr[i] >> 8, f); /* write red */ + fputc(ptr[i+1] >> 8, f); /* write green */ + fputc(ptr[i+2] >> 8, f); /* write blue */ + } + } + } + else { + /*ASCII*/ + int counter = 0; + fprintf(f,"P3\n"); + fprintf(f,"# ascii ppm file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width, height); + fprintf(f,"255\n"); + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + /* just write 8 high bits */ + fprintf(f, " %3d %3d %3d", ptr[i] >> 8, ptr[i+1] >> 8, ptr[i+2] >> 8); + counter++; + if (counter % 5 == 0) + fprintf(f, "\n"); + } + } + } + fclose(f); + } +} + + + +int main( int argc, char *argv[] ) +{ + GLushort *buffer; + + /* Create an RGBA-mode context */ +#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 + /* specify Z, stencil, accum sizes */ + OSMesaContext ctx = OSMesaCreateContextExt( GL_RGBA, 16, 0, 0, NULL ); +#else + OSMesaContext ctx = OSMesaCreateContext( GL_RGBA, NULL ); +#endif + if (!ctx) { + printf("OSMesaCreateContext failed!\n"); + return 0; + } + + /* Allocate the image buffer */ + buffer = (GLushort *) malloc( WIDTH * HEIGHT * 4 * sizeof(GLushort)); + if (!buffer) { + printf("Alloc image buffer failed!\n"); + return 0; + } + + /* Bind the buffer to the context and make it current */ + if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_SHORT, WIDTH, HEIGHT )) { + printf("OSMesaMakeCurrent failed!\n"); + return 0; + } + + render_image(); + + if (argc>1) { +#ifdef SAVE_TARGA + write_targa(argv[1], buffer, WIDTH, HEIGHT); +#else + write_ppm(argv[1], buffer, WIDTH, HEIGHT); +#endif + } + else { + printf("Specify a filename if you want to make an image file\n"); + } + + printf("all done\n"); + + /* free the image buffer */ + free( buffer ); + + /* destroy the context */ + OSMesaDestroyContext( ctx ); + + return 0; +} diff --git a/progs/osdemos/osdemo32.c b/progs/osdemos/osdemo32.c new file mode 100644 index 00000000000..7295b46a830 --- /dev/null +++ b/progs/osdemos/osdemo32.c @@ -0,0 +1,308 @@ +/* + * Demo of off-screen Mesa rendering with 32-bit float color channels. + * This requires the libOSMesa32.so library. + * + * Compile with something like this: + * + * gcc osdemo32.c -I../../include -L../../lib -lglut -lGLU -lOSMesa32 -lm -o osdemo32 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include "GL/osmesa.h" +#include "GL/glut.h" + + +#define SAVE_TARGA + + +#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, 0.5 }; + GLfloat blue_mat[] = { 0.2, 0.2, 1.0, 1.0 }; + GLfloat white_mat[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat purple_mat[] = { 1.0, 0.2, 1.0, 1.0 }; + GLUquadricObj *qobj = gluNewQuadric(); + + 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); + +#if 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(); +#endif + + /* red square */ + glPushMatrix(); + glTranslatef(0.0, -0.5, 0.0); + glRotatef(90, 1, 0.5, 0); + glScalef(3, 3, 3); + glDisable(GL_LIGHTING); + glColor4f(1, 0, 0, 0.5); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); + +#if 0 + /* green square */ + glPushMatrix(); + glTranslatef(0.0, 0.5, 0.1); + glDisable(GL_LIGHTING); + glColor3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); + + /* blue square */ + glPushMatrix(); + glTranslatef(0.75, 0.5, 0.3); + glDisable(GL_LIGHTING); + glColor3f(0, 0, 0.5); + glBegin(GL_POLYGON); + glVertex2f(-1, -1); + glVertex2f( 1, -1); + glVertex2f( 1, 1); + glVertex2f(-1, 1); + glEnd(); + glEnable(GL_LIGHTING); + glPopMatrix(); +#endif + 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 ); + glColor4f(0,1,0,0.5); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gluCylinder(qobj, 1.0, 0.0, 2.0, 16, 1); + glDisable(GL_BLEND); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.75, 1.0, 1.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat ); + gluSphere(qobj, 1.0, 20, 20); + glPopMatrix(); + + glPopMatrix(); + + /* This is very important!!! + * Make sure buffered commands are finished!!! + */ + glFinish(); + + gluDeleteQuadric(qobj); + + { + GLint r, g, b, a; + glGetIntegerv(GL_RED_BITS, &r); + glGetIntegerv(GL_GREEN_BITS, &g); + glGetIntegerv(GL_BLUE_BITS, &b); + glGetIntegerv(GL_ALPHA_BITS, &a); + printf("channel sizes: %d %d %d %d\n", r, g, b, a); + } +} + + + +static void +write_targa(const char *filename, const GLfloat *buffer, int width, int height) +{ + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLfloat *ptr = buffer; + printf ("osdemo, writing tga file \n"); + fputc (0x00, f); /* ID Length, 0 => No ID */ + fputc (0x00, f); /* Color Map Type, 0 => No color map included */ + fputc (0x02, f); /* Image Type, 2 => Uncompressed, True-color Image */ + fputc (0x00, f); /* Next five bytes are about the color map entries */ + fputc (0x00, f); /* 2 bytes Index, 2 bytes length, 1 byte size */ + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); + fputc (0x00, f); /* X-origin of Image */ + fputc (0x00, f); + fputc (0x00, f); /* Y-origin of Image */ + fputc (0x00, f); + fputc (WIDTH & 0xff, f); /* Image Width */ + fputc ((WIDTH>>8) & 0xff, f); + fputc (HEIGHT & 0xff, f); /* Image Height */ + fputc ((HEIGHT>>8) & 0xff, f); + fputc (0x18, f); /* Pixel Depth, 0x18 => 24 Bits */ + fputc (0x20, f); /* Image Descriptor */ + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + int r, g, b; + i = (y*width + x) * 4; + r = (int) (ptr[i+0] * 255.0); + g = (int) (ptr[i+1] * 255.0); + b = (int) (ptr[i+2] * 255.0); + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + fputc(b, f); /* write blue */ + fputc(g, f); /* write green */ + fputc(r, f); /* write red */ + } + } + } +} + + +static void +write_ppm(const char *filename, const GLfloat *buffer, int width, int height) +{ + const int binary = 0; + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLfloat *ptr = buffer; + if (binary) { + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + int r, g, b; + i = (y*width + x) * 4; + r = (int) (ptr[i+0] * 255.0); + g = (int) (ptr[i+1] * 255.0); + b = (int) (ptr[i+2] * 255.0); + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + fputc(r, f); /* write red */ + fputc(g, f); /* write green */ + fputc(b, f); /* write blue */ + } + } + } + else { + /*ASCII*/ + int counter = 0; + fprintf(f,"P3\n"); + fprintf(f,"# ascii ppm file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width, height); + fprintf(f,"255\n"); + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + int r, g, b; + i = (y*width + x) * 4; + r = (int) (ptr[i+0] * 255.0); + g = (int) (ptr[i+1] * 255.0); + b = (int) (ptr[i+2] * 255.0); + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + fprintf(f, " %3d %3d %3d", r, g, b); + counter++; + if (counter % 5 == 0) + fprintf(f, "\n"); + } + } + } + fclose(f); + } +} + + + +int main( int argc, char *argv[] ) +{ + GLfloat *buffer; + + /* Create an RGBA-mode context */ +#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 + /* specify Z, stencil, accum sizes */ + OSMesaContext ctx = OSMesaCreateContextExt( GL_RGBA, 16, 0, 0, NULL ); +#else + OSMesaContext ctx = OSMesaCreateContext( GL_RGBA, NULL ); +#endif + if (!ctx) { + printf("OSMesaCreateContext failed!\n"); + return 0; + } + + /* Allocate the image buffer */ + buffer = (GLfloat *) malloc( WIDTH * HEIGHT * 4 * sizeof(GLfloat)); + if (!buffer) { + printf("Alloc image buffer failed!\n"); + return 0; + } + + /* Bind the buffer to the context and make it current */ + if (!OSMesaMakeCurrent( ctx, buffer, GL_FLOAT, WIDTH, HEIGHT )) { + printf("OSMesaMakeCurrent failed!\n"); + return 0; + } + + render_image(); + + if (argc>1) { +#ifdef SAVE_TARGA + write_targa(argv[1], buffer, WIDTH, HEIGHT); +#else + write_ppm(argv[1], buffer, WIDTH, HEIGHT); +#endif + } + else { + printf("Specify a filename if you want to make an image file\n"); + } + + printf("all done\n"); + + /* free the image buffer */ + free( buffer ); + + /* destroy the context */ + OSMesaDestroyContext( ctx ); + + return 0; +} diff --git a/progs/osdemos/ostest1.c b/progs/osdemos/ostest1.c new file mode 100644 index 00000000000..001e3686162 --- /dev/null +++ b/progs/osdemos/ostest1.c @@ -0,0 +1,470 @@ +/* + * Test OSMesa interface at 8, 16 and 32 bits/channel. + * + * Usage: osdemo [options] + * + * Options: + * -f generate image files + * -g render gradient and print color values + */ + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "GL/osmesa.h" +#include "GL/glu.h" + + +#define WIDTH 600 +#define HEIGHT 600 + +static GLboolean WriteFiles = GL_FALSE; +static GLboolean Gradient = GL_FALSE; + + +static void +Sphere(float radius, int slices, int stacks) +{ + GLUquadric *q = gluNewQuadric(); + gluQuadricNormals(q, GLU_SMOOTH); + gluSphere(q, radius, slices, stacks); + gluDeleteQuadric(q); +} + + +static void +Cone(float base, float height, int slices, int stacks) +{ + GLUquadric *q = gluNewQuadric(); + gluQuadricDrawStyle(q, GLU_FILL); + gluQuadricNormals(q, GLU_SMOOTH); + gluCylinder(q, base, 0.0, height, slices, stacks); + gluDeleteQuadric(q); +} + + +static void +Torus(float innerRadius, float outerRadius, int sides, int rings) +{ + /* from GLUT... */ + int i, j; + GLfloat theta, phi, theta1; + GLfloat cosTheta, sinTheta; + GLfloat cosTheta1, sinTheta1; + const GLfloat ringDelta = 2.0 * M_PI / rings; + const GLfloat sideDelta = 2.0 * M_PI / sides; + + theta = 0.0; + cosTheta = 1.0; + sinTheta = 0.0; + for (i = rings - 1; i >= 0; i--) { + theta1 = theta + ringDelta; + cosTheta1 = cos(theta1); + sinTheta1 = sin(theta1); + glBegin(GL_QUAD_STRIP); + phi = 0.0; + for (j = sides; j >= 0; j--) { + GLfloat cosPhi, sinPhi, dist; + + phi += sideDelta; + cosPhi = cos(phi); + sinPhi = sin(phi); + dist = outerRadius + innerRadius * cosPhi; + + glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); + glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, innerRadius * sinPhi); + glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); + glVertex3f(cosTheta * dist, -sinTheta * dist, innerRadius * sinPhi); + } + glEnd(); + theta = theta1; + cosTheta = cosTheta1; + sinTheta = sinTheta1; + } +} + + +static void Cube(float size) +{ + size = 0.5 * size; + + glBegin(GL_QUADS); + /* +X face */ + glNormal3f(1, 0, 0); + glVertex3f(size, -size, size); + glVertex3f(size, -size, -size); + glVertex3f(size, size, -size); + glVertex3f(size, size, size); + + /* -X face */ + glNormal3f(-1, 0, 0); + glVertex3f(-size, size, size); + glVertex3f(-size, size, -size); + glVertex3f(-size, -size, -size); + glVertex3f(-size, -size, size); + + /* +Y face */ + glNormal3f(0, 1, 0); + glVertex3f(-size, size, size); + glVertex3f( size, size, size); + glVertex3f( size, size, -size); + glVertex3f(-size, size, -size); + + /* -Y face */ + glNormal3f(0, -1, 0); + glVertex3f(-size, -size, -size); + glVertex3f( size, -size, -size); + glVertex3f( size, -size, size); + glVertex3f(-size, -size, size); + + /* +Z face */ + glNormal3f(0, 0, 1); + glVertex3f(-size, -size, size); + glVertex3f( size, -size, size); + glVertex3f( size, size, size); + glVertex3f(-size, size, size); + + /* -Z face */ + glNormal3f(0, 0, -1); + glVertex3f(-size, size, -size); + glVertex3f( size, size, -size); + glVertex3f( size, -size, -size); + glVertex3f(-size, -size, -size); + + glEnd(); +} + + + +/** + * Draw red/green gradient across bottom of image. + * Read pixels to check deltas. + */ +static void +render_gradient(void) +{ + GLfloat row[WIDTH][4]; + int i; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glBegin(GL_POLYGON); + glColor3f(1, 0, 0); + glVertex2f(-1, -1.0); + glVertex2f(-1, -0.9); + glColor3f(0, 1, 0); + glVertex2f(1, -0.9); + glVertex2f(1, -1.0); + glEnd(); + glFinish(); + + glReadPixels(0, 0, WIDTH, 1, GL_RGBA, GL_FLOAT, row); + for (i = 0; i < 4; i++) { + printf("row[i] = %f, %f, %f\n", row[i][0], row[i][1], row[i][2]); + } +} + + +static void +render_image(void) +{ + static const GLfloat light_ambient[4] = { 0.0, 0.0, 0.0, 1.0 }; + static const GLfloat light_diffuse[4] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat light_specular[4] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat light_position[4] = { 1.0, 1.0, 1.0, 0.0 }; + static const GLfloat red_mat[4] = { 1.0, 0.2, 0.2, 1.0 }; + static const GLfloat green_mat[4] = { 0.2, 1.0, 0.2, 1.0 }; + static const GLfloat blue_mat[4] = { 0.2, 0.2, 1.0, 1.0 }; +#if 0 + static const GLfloat yellow_mat[4] = { 0.8, 0.8, 0.0, 1.0 }; +#endif + static const GLfloat purple_mat[4] = { 0.8, 0.4, 0.8, 0.6 }; + + 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_DEPTH_TEST); + glEnable(GL_LIGHT0); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 50.0); + glMatrixMode(GL_MODELVIEW); + glTranslatef(0, 0.5, -7); + + glClearColor(0.3, 0.3, 0.7, 0.0); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(20.0, 1.0, 0.0, 0.0); + + /* ground */ + glEnable(GL_TEXTURE_2D); + glBegin(GL_POLYGON); + glNormal3f(0, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-5, -1, -5); + glTexCoord2f(1, 0); glVertex3f( 5, -1, -5); + glTexCoord2f(1, 1); glVertex3f( 5, -1, 5); + glTexCoord2f(0, 1); glVertex3f(-5, -1, 5); + glEnd(); + glDisable(GL_TEXTURE_2D); + + glEnable(GL_LIGHTING); + + glPushMatrix(); + glTranslatef(-1.5, 0.5, 0.0); + glRotatef(90.0, 1.0, 0.0, 0.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat ); + Torus(0.275, 0.85, 20, 20); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-1.5, -0.5, 0.0); + glRotatef(270.0, 1.0, 0.0, 0.0); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat ); + Cone(1.0, 2.0, 16, 1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(0.95, 0.0, -0.8); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat ); + glLineWidth(2.0); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + Sphere(1.2, 20, 20); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glPopMatrix(); + +#if 0 + glPushMatrix(); + glTranslatef(0.75, 0.0, 1.3); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, yellow_mat ); + glutWireTeapot(1.0); + glPopMatrix(); +#endif + + glPushMatrix(); + glTranslatef(-0.25, 0.0, 2.5); + glRotatef(40, 0, 1, 0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glEnable(GL_CULL_FACE); + glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, purple_mat ); + Cube(1.0); + glDisable(GL_BLEND); + glDisable(GL_CULL_FACE); + glPopMatrix(); + + glDisable(GL_LIGHTING); + + glPopMatrix(); + + glDisable(GL_DEPTH_TEST); +} + + +static void +init_context(void) +{ + const GLint texWidth = 64, texHeight = 64; + GLubyte *texImage; + int i, j; + + /* checker image */ + texImage = malloc(texWidth * texHeight * 4); + for (i = 0; i < texHeight; i++) { + for (j = 0; j < texWidth; j++) { + int k = (i * texWidth + j) * 4; + if ((i % 5) == 0 || (j % 5) == 0) { + texImage[k+0] = 200; + texImage[k+1] = 200; + texImage[k+2] = 200; + texImage[k+3] = 255; + } + else { + if ((i % 5) == 1 || (j % 5) == 1) { + texImage[k+0] = 50; + texImage[k+1] = 50; + texImage[k+2] = 50; + texImage[k+3] = 255; + } + else { + texImage[k+0] = 100; + texImage[k+1] = 100; + texImage[k+2] = 100; + texImage[k+3] = 255; + } + } + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, texImage); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + free(texImage); +} + + +static void +write_ppm(const char *filename, const GLubyte *buffer, int width, int height) +{ + const int binary = 0; + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLubyte *ptr = buffer; + if (binary) { + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + fputc(ptr[i], f); /* write red */ + fputc(ptr[i+1], f); /* write green */ + fputc(ptr[i+2], f); /* write blue */ + } + } + } + else { + /*ASCII*/ + int counter = 0; + fprintf(f,"P3\n"); + fprintf(f,"# ascii ppm file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width, height); + fprintf(f,"255\n"); + for (y=height-1; y>=0; y--) { + for (x=0; x<width; x++) { + i = (y*width + x) * 4; + fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]); + counter++; + if (counter % 5 == 0) + fprintf(f, "\n"); + } + } + } + fclose(f); + } +} + + +static GLboolean +test(GLenum type, GLint bits, const char *filename) +{ + const GLint z = 16, stencil = 0, accum = 0; + OSMesaContext ctx; + void *buffer; + GLint cBits; + + assert(bits == 8 || + bits == 16 || + bits == 32); + + assert(type == GL_UNSIGNED_BYTE || + type == GL_UNSIGNED_SHORT || + type == GL_FLOAT); + + ctx = OSMesaCreateContextExt(OSMESA_RGBA, z, stencil, accum, NULL ); + if (!ctx) { + printf("OSMesaCreateContextExt() failed!\n"); + return 0; + } + + /* Allocate the image buffer */ + buffer = malloc(WIDTH * HEIGHT * 4 * bits / 8); + if (!buffer) { + printf("Alloc image buffer failed!\n"); + return 0; + } + + /* Bind the buffer to the context and make it current */ + if (!OSMesaMakeCurrent( ctx, buffer, type, WIDTH, HEIGHT )) { + printf("OSMesaMakeCurrent (%d bits/channel) failed!\n", bits); + free(buffer); + OSMesaDestroyContext(ctx); + return 0; + } + + /* sanity checks */ + glGetIntegerv(GL_RED_BITS, &cBits); + assert(cBits == bits); + glGetIntegerv(GL_GREEN_BITS, &cBits); + assert(cBits == bits); + glGetIntegerv(GL_BLUE_BITS, &cBits); + assert(cBits == bits); + glGetIntegerv(GL_ALPHA_BITS, &cBits); + assert(cBits == bits); + + printf("Rendering %d bit/channel image: %s\n", bits, filename); + + init_context(); + render_image(); + if (Gradient) + render_gradient(); + + /* Make sure buffered commands are finished! */ + glFinish(); + + + if (WriteFiles && filename != NULL) { + if (type == GL_UNSIGNED_SHORT) { + GLushort *buffer16 = (GLushort *) buffer; + GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4); + int i; + for (i = 0; i < WIDTH * HEIGHT * 4; i++) + buffer8[i] = buffer16[i] >> 8; + write_ppm(filename, buffer8, WIDTH, HEIGHT); + free(buffer8); + } + else if (type == GL_FLOAT) { + GLfloat *buffer32 = (GLfloat *) buffer; + GLubyte *buffer8 = malloc(WIDTH * HEIGHT * 4); + int i; + for (i = 0; i < WIDTH * HEIGHT * 4; i++) + buffer8[i] = (GLubyte) (buffer32[i] * 255.0); + write_ppm(filename, buffer8, WIDTH, HEIGHT); + free(buffer8); + } + else { + write_ppm(filename, buffer, WIDTH, HEIGHT); + } + } + + OSMesaDestroyContext(ctx); + + free(buffer); + + return 1; +} + + +int +main( int argc, char *argv[] ) +{ + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-f") == 0) + WriteFiles = GL_TRUE; + else if (strcmp(argv[i], "-g") == 0) + Gradient = GL_TRUE; + } + + test(GL_UNSIGNED_BYTE, 8, "image8.ppm"); + test(GL_UNSIGNED_SHORT, 16, "image16.ppm"); + test(GL_FLOAT, 32, "image32.ppm"); + + return 0; +} diff --git a/progs/osdemos/readtex.c b/progs/osdemos/readtex.c new file mode 100644 index 00000000000..37d5fcd0d3a --- /dev/null +++ b/progs/osdemos/readtex.c @@ -0,0 +1,454 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + + + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + 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->rowStart) + free(raw->rowStart); + if (raw->rowSize) + free(raw->rowSize); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + 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 w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + 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; +} + +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) + + +static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes, + const GLubyte *src, + GLushort *dest) +{ + GLint i, j; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + const GLfloat r = (src[0]) / 255.0; + const GLfloat g = (src[1]) / 255.0; + const GLfloat b = (src[2]) / 255.0; + GLfloat y, cr, cb; + GLint iy, icr, icb; + + y = r * 65.481 + g * 128.553 + b * 24.966 + 16; + cb = r * -37.797 + g * -74.203 + b * 112.0 + 128; + cr = r * 112.0 + g * -93.786 + b * -18.214 + 128; + /*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/ + iy = (GLint) CLAMP(y, 0, 254); + icb = (GLint) CLAMP(cb, 0, 254); + icr = (GLint) CLAMP(cr, 0, 254); + + if (j & 1) { + /* odd */ + *dest = (iy << 8) | icr; + } + else { + /* even */ + *dest = (iy << 8) | icb; + } + dest++; + src += texel_bytes; + } + } +} + + +/* + * Load an SGI .rgb file and return a pointer to the image data, converted + * to 422 yuv. + * + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * Return: pointer to image data or NULL if error + */ +GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height ) +{ + TK_RGBImageRec *image; + GLushort *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components != 3 && image->components !=4 ) { + /* not implemented */ + fprintf(stderr, + "Error in LoadYUVImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 ); + + if (buffer) + ConvertRGBtoYUV( image->sizeX, + image->sizeY, + image->components, + image->data, + buffer ); + + + FreeImage(image); + return buffer; +} + diff --git a/progs/redbook/Makefile b/progs/redbook/Makefile new file mode 100644 index 00000000000..febc74441b9 --- /dev/null +++ b/progs/redbook/Makefile @@ -0,0 +1,39 @@ +# progs/redbook/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCDIR = $(TOP)/include + +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) + +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) $< $(APP_LIB_DEPS) -o $@ + + + +##### TARGETS ###### + +default: $(PROGS) + + +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + diff --git a/progs/redbook/Makefile.win b/progs/redbook/Makefile.win new file mode 100644 index 00000000000..7e57b8e47f8 --- /dev/null +++ b/progs/redbook/Makefile.win @@ -0,0 +1,78 @@ +# Makefile for Win32 + +TOP = .. +INCDIR = ..\include +LIBDIR = ..\lib + +!include <win32.mak> + +SRCS= \ + aaindex.c \ + aapoly.c \ + aargb.c \ + accanti.c \ + accpersp.c \ + alpha.c \ + alpha3D.c \ + anti.c \ + bezcurve.c \ + bezmesh.c \ + checker.c \ + clip.c \ + colormat.c \ + cube.c \ + depthcue.c \ + dof.c \ + double.c \ + drawf.c \ + feedback.c \ + fog.c \ + fogindex.c \ + font.c \ + hello.c \ + image.c \ + light.c \ + lines.c \ + list.c \ + material.c \ + mipmap.c \ + model.c \ + movelight.c \ + nurbs.c \ + pickdepth.c \ + picksquare.c \ + plane.c \ + planet.c \ + polyoff.c \ + polys.c \ + quadric.c \ + robot.c \ + sccolorlight.c \ + scene.c \ + scenebamb.c \ + sceneflat.c \ + select.c \ + smooth.c \ + stencil.c \ + stroke.c \ + surface.c \ + teaambient.c \ + teapots.c \ + tess.c \ + tesswind.c \ + texbind.c \ + texgen.c \ + texprox.c \ + texsub.c \ + texturesurf.c \ + torus.c \ + trim.c \ + unproject.c \ + varray.c \ + wrap.c + +!include "$(TOP)/mesawin32.mak" + +$(EXES) : $*.obj + @echo $@ + $(link) -out:$@ $* /LIBPATH:$(LIBDIR) $(LIBS)
\ No newline at end of file diff --git a/progs/redbook/README b/progs/redbook/README new file mode 100644 index 00000000000..4c8d5a74c9a --- /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 00000000000..7dbc7b4b9b2 --- /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 <GL/glut.h> +#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 00000000000..757f0f48c43 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +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 00000000000..f51984170e6 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +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 00000000000..12ca16f7a52 --- /dev/null +++ b/progs/redbook/accanti.c @@ -0,0 +1,182 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> +#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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..46e369ae631 --- /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 <stdlib.h> +#include <math.h> +#include <GL/glut.h> +#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 00000000000..6eeb45b96f1 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..6169bd162be --- /dev/null +++ b/progs/redbook/alpha3D.c @@ -0,0 +1,185 @@ +/* + * 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 <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + +#define MAXZ 8.0 +#define MINZ -8.0 +#define ZINC 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) +{ + static double t0 = -1.; + if (solidZ <= MINZ || transparentZ >= MAXZ) + { + glutIdleFunc(NULL); + t0 = -1.; + } + else { + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + t0 = t; + solidZ -= ZINC*dt; + transparentZ += ZINC*dt; + 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_DOUBLE | 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 00000000000..9eab0bc3511 --- /dev/null +++ b/progs/redbook/anti.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. + */ +/* + * anti.c + * This program draws antialiased lines in RGBA mode. + */ +#include <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + +/* 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 */ +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..5dee440396b --- /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 <stdlib.h> +#include <GL/glut.h> + +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 00000000000..55e7e827f2b --- /dev/null +++ b/progs/redbook/bezmesh.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. + */ +/* bezsurf.c + * This program renders a lighted, filled Bezier surface, + * using two-dimensional evaluators. + */ +#include <stdlib.h> +#include <GL/glut.h> + +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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow(argv[0]); + myinit(); + glutReshapeFunc(myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + 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 00000000000..06cbae7dd7e --- /dev/null +++ b/progs/redbook/checker.c @@ -0,0 +1,140 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow("checker"); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + 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 00000000000..90816f2e278 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..9db4491bac5 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..5ecc6280f33 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..a3e5b743aa7 --- /dev/null +++ b/progs/redbook/depthcue.c @@ -0,0 +1,115 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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 */ +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..6673dc2d54f --- /dev/null +++ b/progs/redbook/dof.c @@ -0,0 +1,251 @@ + +/* 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 <stdlib.h> +#include <math.h> +#include <GL/glut.h> +#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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..3153c70cc1d --- /dev/null +++ b/progs/redbook/double.c @@ -0,0 +1,146 @@ +/* + * 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 <GL/glut.h> +#include <stdlib.h> + +static GLfloat spin = 0.0; +static GLdouble t0 = 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(); +} + +GLdouble gettime(void) +{ + return (GLdouble)(glutGet(GLUT_ELAPSED_TIME)) / 1000.; +} + +void spinDisplay(void) +{ + GLdouble t, dt; + t = gettime(); + dt = t - t0; + t0 = t; + spin = spin + 120.0*dt; + 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) + { + t0 = gettime(); + glutIdleFunc(spinDisplay); + } + break; + case GLUT_MIDDLE_BUTTON: + if (state == GLUT_DOWN) + glutIdleFunc(NULL); + break; + default: + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* + * 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); + glutKeyboardFunc(key); + 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 00000000000..5bcccb6aeac --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..cc685d55d34 --- /dev/null +++ b/progs/redbook/feedback.c @@ -0,0 +1,173 @@ +/* + * 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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +/* 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); + + glFinish(); +} + +/* 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 00000000000..14c7700eccf --- /dev/null +++ b/progs/redbook/fog.c @@ -0,0 +1,200 @@ + +/* 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 <stdlib.h> +#include <math.h> +#include <GL/glut.h> + +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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..b8bb691e288 --- /dev/null +++ b/progs/redbook/fogindex.c @@ -0,0 +1,152 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..2d92e9b6003 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <string.h> + +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 00000000000..fb3dae13252 --- /dev/null +++ b/progs/redbook/hello.c @@ -0,0 +1,110 @@ +/* + * 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 <stdlib.h> +#include <GL/glut.h> + +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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* + * 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); + glutKeyboardFunc(key); + 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 00000000000..dc1a7246eba --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +/* 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 00000000000..1ec08c87fd4 --- /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 00000000000..0eed85e10c2 --- /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 <GL/glut.h> +#include <stdlib.h> + +/* 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 00000000000..b34d4c418c6 --- /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 <GL/glut.h> +#include <stdlib.h> + +#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 00000000000..3b4f44bd6da --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..f9a4fc59288 --- /dev/null +++ b/progs/redbook/material.c @@ -0,0 +1,306 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..d32dd725f4b --- /dev/null +++ b/progs/redbook/mipmap.c @@ -0,0 +1,178 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +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); + glutKeyboardFunc(key); + 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 00000000000..8411ef355f1 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..a108cad439a --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..a7c6f0c696e --- /dev/null +++ b/progs/redbook/nurbs.c @@ -0,0 +1,190 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +#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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..ad5bdc81994 --- /dev/null +++ b/progs/redbook/pickdepth.c @@ -0,0 +1,217 @@ + +/* 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 <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + +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[]) +{ + GLint i; + GLuint j, 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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..636edc97b4b --- /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 <stdlib.h> +#include <stdio.h> +#include <GL/glut.h> + +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[]) +{ + GLint i; + GLuint j, ii = 0, jj = 0, 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 00000000000..dc17f7b2386 --- /dev/null +++ b/progs/redbook/plane.c @@ -0,0 +1,171 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..e13672d3f63 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..2017b4d8eed --- /dev/null +++ b/progs/redbook/polyoff.c @@ -0,0 +1,333 @@ +/* + * 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 <GL/glut.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifdef GL_VERSION_1_1 +GLuint list; +GLint fill = 1; +GLfloat spinx = 0; +GLfloat spiny = 0; +GLfloat tdist = 0.0; +GLfloat polyfactor = 1.0; +GLfloat polyunits = 1.0; +GLboolean doubleBuffer; + + +/* display() draws two spheres, one with a gray, diffuse material, + * the other sphere with a magenta material with a specular highlight. + */ +void display (void) +{ + 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); + if (fill) { + 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); + glPolygonOffset(-polyfactor, -polyunits); + if (!fill) glEnable(GL_POLYGON_OFFSET_LINE); + glCallList (list); + glDisable(GL_POLYGON_OFFSET_LINE); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + if (!fill) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glCallList (list); + } + + glPopMatrix (); + glFlush (); + if (doubleBuffer) glutSwapBuffers(); +} + +/* 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); +} + +static void Benchmark( float xdiff, float ydiff ) +{ + int startTime, endTime; + int draws; + double seconds, fps; + + printf("Benchmarking...\n"); + + draws = 0; + startTime = glutGet(GLUT_ELAPSED_TIME); + spinx = spiny = 0.0; + do { + spinx += xdiff; + spiny += ydiff; + display(); + draws++; + endTime = glutGet(GLUT_ELAPSED_TIME); + } while (endTime - startTime < 5000); /* 5 seconds */ + + /* Results */ + seconds = (double) (endTime - startTime) / 1000.0; + fps = draws / seconds; + printf("Result: fps: %g\n", fps); +} + + +/* 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 += 5; + glutPostRedisplay(); + break; + default: + break; + } + break; + case GLUT_MIDDLE_BUTTON: + switch (state) { + case GLUT_DOWN: + spiny += 5; + 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; + case 'b': + Benchmark(5.0, 0); + break; + case 'B': + Benchmark(0, 5.0); + break; + case ' ': + fill = !fill; + printf ("fill/line: %d\n", fill); + glutPostRedisplay(); + break; + case 27: /* Escape */ + exit(0); + break; + default: + break; + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +GLenum Args(int argc, char **argv) +{ + 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; +} + + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + GLuint type; + glutInit(&argc, argv); + + Args(argc, argv); + + type = GLUT_DEPTH | GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + + glutInitDisplayMode(type); + glutCreateWindow("polyoff"); + 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 00000000000..409abd17531 --- /dev/null +++ b/progs/redbook/polys.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. + */ +/* + * polys.c + * This program demonstrates polygon stippling. + */ +#include <stdlib.h> +#include <GL/glut.h> + +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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + break; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..4e46c85f829 --- /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 <GL/glut.h> +#include <stdio.h> +#include <stdlib.h> + +/* 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 00000000000..94e20ac71eb --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..0ea750e5846 --- /dev/null +++ b/progs/redbook/sccolorlight.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. + */ +/* + * 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..c3abc727b78 --- /dev/null +++ b/progs/redbook/scene.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. + */ +/* + * 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..e7264d2003f --- /dev/null +++ b/progs/redbook/scenebamb.c @@ -0,0 +1,140 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..10891fb9977 --- /dev/null +++ b/progs/redbook/sceneflat.c @@ -0,0 +1,140 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..928373b8796 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +/* 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[]) +{ + GLint i; + GLuint j, 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 00000000000..9d22fc90251 --- /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 <GL/glut.h> +#include <stdlib.h> + +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 00000000000..b33e40a0307 --- /dev/null +++ b/progs/redbook/stencil.c @@ -0,0 +1,193 @@ + +/* 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. + */ + +/* + * !!! NOTE !!! + * + * This demo is poorly written. The stencil buffer should be + * redrawn in display(), not in the myReshape() function. + * The reason is if the window gets "damaged" then the stencil buffer + * contents will be in an undefined state (myReshape is not called when + * a window is damaged and needs to be redrawn). If the stencil buffer + * contents are undefined, the results of display() are unpredictable. + * + * -Brian + */ + + +#include <stdlib.h> +#include <GL/glut.h> + +#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); + + glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); + +/* 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); + 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(); + glutSwapBuffers(); +} + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* Main Loop + * Open window with initial window size, title bar, + * RGBA display mode, and handle input events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL); + glutInitWindowSize (400, 400); + glutCreateWindow (argv[0]); + myinit (); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + 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 00000000000..19b0391cbae --- /dev/null +++ b/progs/redbook/stroke.c @@ -0,0 +1,195 @@ + +/* 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 <stdlib.h> +#include <string.h> +#include <GL/glut.h> + +#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(); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..e33ce14f4fc --- /dev/null +++ b/progs/redbook/surface.c @@ -0,0 +1,232 @@ +/* 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 <stdlib.h> +#include <GL/glut.h> + +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; + } + } +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..53b5111752f --- /dev/null +++ b/progs/redbook/teaambient.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. + */ +/** + * teaambient.c + * This program renders three lighted, shaded teapots, with + * different ambient values. + */ +#include <stdlib.h> +#include <GL/glut.h> + +/* 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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* 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); + glutKeyboardFunc(key); + 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 00000000000..fb7aed380eb --- /dev/null +++ b/progs/redbook/teapots.c @@ -0,0 +1,220 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> + +/* + * 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, 18.0 * (GLfloat) h / (GLfloat) w, + -10.0, 10.0); + else + glOrtho(0.0, 16.0 * (GLfloat) w / (GLfloat) h, 0.0, 18.0, + -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* + * 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); + glutKeyboardFunc(key); + 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 00000000000..238a469aff2 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#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", (char *) estring); + exit(0); +} + +void CALLBACK endCallback(void) +{ + glEnd(); +} + +void CALLBACK vertexCallback(GLvoid *vertex) +{ + const GLdouble *pointer; + + pointer = (GLdouble *) vertex; + glColor3dv(pointer+3); + glVertex3dv(pointer); +} + +/* 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 < 6; 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 00000000000..7d00c9f907d --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#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", (char *) 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 00000000000..6a828ab2bdf --- /dev/null +++ b/progs/redbook/texbind.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. + */ + +/* texbind.c + * This program demonstrates using glBindTexture() by + * creating and managing two textures. + */ +#include <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#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 00000000000..7c1802a3be9 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#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 00000000000..6f1e853facd --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#ifdef GL_VERSION_1_1 + +/* Microsoft OpenGL 1.1's <GL/gl.h> 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 00000000000..4e829675aba --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +#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 00000000000..0170070eaa5 --- /dev/null +++ b/progs/redbook/texturesurf.c @@ -0,0 +1,155 @@ + +/* 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 <stdlib.h> +#include <GL/glut.h> +#include <math.h> + +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); +} + +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutCreateWindow (argv[0]); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + 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 00000000000..7ae4d41e263 --- /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 <GL/glut.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> + +/* Some <math.h> 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 00000000000..f17674f6840 --- /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 <stdlib.h> +#include <GL/glut.h> +#include <stdio.h> + + +#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", (char *) 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 00000000000..134c361bac5 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +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 00000000000..b22e723e0ec --- /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 <GL/glut.h> +#include <stdio.h> +#include <stdlib.h> + +#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 00000000000..f9a1f162ab6 --- /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 <GL/glut.h> +#include <stdlib.h> +#include <stdio.h> + +/* 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/Makefile b/progs/samples/Makefile new file mode 100644 index 00000000000..063008dccff --- /dev/null +++ b/progs/samples/Makefile @@ -0,0 +1,48 @@ +# progs/samples/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCDIR = $(TOP)/include + +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) + +PROGS = accum bitmap1 bitmap2 blendeq blendxor copy cursor depth eval fog \ + font line logo nurb 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) $< $(APP_LIB_DEPS) -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + + +sphere: sphere.o readtex.o + $(CC) -I$(INCDIR) $(CFLAGS) sphere.o readtex.o $(APP_LIB_DEPS) -o $@ + +sphere.o: sphere.c readtex.h + $(CC) -c -I$(INCDIR) $(CFLAGS) sphere.c + +readtex.c: $(TOP)/progs/util/readtex.c + cp $< . + +readtex.h: $(TOP)/progs/util/readtex.h + cp $< . + +readtex.o: readtex.c readtex.h + $(CC) -c -I$(INCDIR) $(CFLAGS) $< -o $@ + + +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + -rm -f readtex.c readtex.h diff --git a/progs/samples/Makefile.DJ b/progs/samples/Makefile.DJ new file mode 100644 index 00000000000..cda4e059418 --- /dev/null +++ b/progs/samples/Makefile.DJ @@ -0,0 +1,85 @@ +# Mesa 3-D graphics library +# Version: 4.0 +# +# Copyright (C) 1999 Brian Paul All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# DOS/DJGPP samples makefile v1.6 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : [email protected] +# Web : http://www.geocities.com/dborca + + +# +# Available options: +# +# Environment variables: +# GLIDE path to Glide3 SDK; used with FX. +# default = $(TOP)/glide3 +# FX=1 build for 3dfx Glide3. Note that this disables +# compilation of most DMesa code and requires fxMesa. +# As a consequence, you'll need the DJGPP Glide3 +# library to build any application. +# default = no +# DXE=1 use DXE modules (see README.DJ for details). +# default = no +# +# Targets: +# <file.exe> build a specific file +# + + + +.PHONY: all +.SUFFIXES: .c .o .exe +.SECONDARY: ../util/readtex.o ../util/showbuffer.o + +TOP = ../.. +GLIDE ?= $(TOP)/glide3 + +CC = gcc +CFLAGS = -Wall -W -pedantic +CFLAGS += -O2 -ffast-math +CFLAGS += -I$(TOP)/include -I../util +CFLAGS += -DGLUT_IMPORT_LIB +ifeq ($(FX),1) +CFLAGS += -DFX +endif + +LD = gxx +LDFLAGS = -s -L$(TOP)/lib + +ifeq ($(DXE),1) +LDLIBS += -liglut -liglu -ligl +else +LDLIBS = -lglut -lglu -lgl +ifeq ($(FX),1) +LDFLAGS += -L$(GLIDE)/lib +LDLIBS += -lgld3x +endif +endif + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +%.exe: ../util/readtex.o ../util/showbuffer.o %.o + $(LD) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +all: + $(error Must specify <filename.exe> to build) diff --git a/progs/samples/Makefile.dja b/progs/samples/Makefile.dja new file mode 100644 index 00000000000..b60a11197b6 --- /dev/null +++ b/progs/samples/Makefile.dja @@ -0,0 +1,25 @@ + +# 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/Makefile.mgw b/progs/samples/Makefile.mgw new file mode 100644 index 00000000000..11935405783 --- /dev/null +++ b/progs/samples/Makefile.mgw @@ -0,0 +1,68 @@ +# Mesa 3-D graphics library +# Version: 4.0 +# +# Copyright (C) 1999 Brian Paul All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# MinGW samples makefile v1.2 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : [email protected] +# Web : http://www.geocities.com/dborca + + +# +# Available options: +# +# Environment variables: +# +# Targets: +# <file.exe> build a specific file +# + + + +.PHONY: all +.SUFFIXES: .c .o .exe +.SECONDARY: ../util/readtex.o ../util/showbuffer.o + +TOP = ../.. + +CC = mingw32-gcc +CFLAGS = -Wall -W -pedantic +CFLAGS += -O2 -ffast-math +CFLAGS += -I$(TOP)/include -I../util +ifeq ($(FX),1) +CFLAGS += -DFX +endif +CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK -D_STDCALL_SUPPORTED +CFLAGS += -D_WINDEF_ -D_WINGDI_ + +LD = mingw32-g++ +LDFLAGS = -s -L$(TOP)/lib + +LDLIBS = -lglut32 -lglu32 -lopengl32 + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +%.exe: ../util/readtex.o ../util/showbuffer.o %.o + $(LD) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +all: + $(error Must specify <filename.exe> to build) diff --git a/progs/samples/Makefile.win b/progs/samples/Makefile.win new file mode 100644 index 00000000000..e74568f7c96 --- /dev/null +++ b/progs/samples/Makefile.win @@ -0,0 +1,41 @@ + +# Mesa 3-D graphics library +# Version: 3.5 +# Copyright (C) 1995-2001 Brian Paul + +# Makefile for GLUT-based demo programs for Windows + +!include <win32.mak> + +##### MACROS ##### + +TOP = .. +INCDIR = ..\include +LIBDIR = ..\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 + +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 olympic.c overlay.c point.c prim.c quad.c select.c \ + shape.c sphere.c star.c stencil.c stretch.c texture.c tri.c wave.c + +!include "../mesawin32.mak" + +##### TARGETS ##### + +clean:: + +clobber:: + +$(EXES) : $*.obj + @echo $@ + $(link) -out:$@ $* /LIBPATH:$(LIBDIR) $(LIBS) diff --git a/progs/samples/README b/progs/samples/README new file mode 100644 index 00000000000..853158873c9 --- /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 <file name> 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 <file name> 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 <file name> 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 <file name> 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 <file name> 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 <x> <y> Number of grids. + -size <number> Size of grid. + -wave <number> Height of wave (floating point number). + -frames <count> 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 00000000000..24dfc07d2a6 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +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 00000000000..517d584e212 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..5faac841622 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..f78afd30381 --- /dev/null +++ b/progs/samples/blendeq.c @@ -0,0 +1,319 @@ +/* +** 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 <string.h> +#include <stdlib.h> +#include <stdio.h> +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> + +GLenum doubleBuffer; +static int dithering = 0; +int use11ops = 0; +int supportlogops = 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; + case 'l': + if (supportlogops == 3) + use11ops = (!use11ops); + if (use11ops) + printf("Using GL 1.1 color logic ops.\n"); + else printf("Using GL_EXT_blend_logic_op.\n"); + 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); + if (supportlogops & 2) + glDisable(GL_COLOR_LOGIC_OP); + + 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; + if (!use11ops) + glBlendEquationEXT(GL_LOGIC_OP); + else + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_CLEAR); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_SET); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_COPY); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_NOOP); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_AND); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_INVERT); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_OR); + glRectf(x1, i, x2, i+deltaY); + + i -= deltaY; + glLogicOp(GL_XOR); + glRectf(x1, i, x2, i+deltaY); + glRectf(x1, i+10, x2, i+5); + + if (doPrint) { + glDisable(GL_BLEND); + if (supportlogops & 2) + glDisable(GL_COLOR_LOGIC_OP); + 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"; + char *version; + + 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); + version = (char*) glGetString(GL_VERSION); + if (!s) + exit(1); + if (strstr(s,extName1)) { + supportlogops = 1; + use11ops = 0; + printf("blend_logic_op extension available.\n"); + } + if (strncmp(version,"1.1",3)>=0) { + supportlogops += 2; + use11ops = 1; + printf("1.1 color logic ops available.\n"); + } + if (supportlogops == 0) { + printf("Blend_logic_op extension and GL 1.1 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 00000000000..5bc4aa9bea4 --- /dev/null +++ b/progs/samples/blendxor.c @@ -0,0 +1,206 @@ +/* +** 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 <stdio.h> +#include <string.h> +#ifndef _WIN32 +#include <unistd.h> +#endif +#include <stdlib.h> +#ifdef _WIN32 +#include <windows.h> +#endif +#define GL_GLEXT_LEGACY +#define GL_GLEXT_PROTOTYPES +#include <GL/glut.h> +#include <GL/glext.h> + + +GLenum doubleBuffer; +int dithering = 0; +int use11ops = 0; +int supportlogops = 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; + case 'l': + if (supportlogops == 3) + use11ops = (!use11ops); + if (use11ops) + printf("Using GL 1.1 color logic ops.\n"); + else printf("Using GL_EXT_blend_logic_op.\n"); + break; + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + int i; + + glDisable(GL_BLEND); + if (supportlogops & 2) + glDisable(GL_COLOR_LOGIC_OP); + + (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); + if (!use11ops) + glBlendEquationEXT(GL_LOGIC_OP); + else + glEnable(GL_COLOR_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"; + char *version; + + 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); + version = (char*) glGetString(GL_VERSION); + if (!s) + exit(1); + if (strstr(s,extName)) { + supportlogops = 1; + use11ops = 0; + printf("blend_logic_op extension available.\n"); + } + if (strncmp(version,"1.1",3)>=0) { + supportlogops += 2; + use11ops = 1; + printf("1.1 color logic ops available.\n"); + } + if (supportlogops == 0) { + printf("Blend_logic_op extension and GL 1.1 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 00000000000..391c637d6fa --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..de8fc58556c --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +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 00000000000..afe2ec17a38 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..3ad9c5468f8 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +#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 00000000000..3f3ffdbcc7a --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +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_TRUE; + + 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 00000000000..a0091a65d79 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..83f70cb3ac4 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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_TRUE; + + 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 00000000000..be056d62940 --- /dev/null +++ b/progs/samples/loadppm.c @@ -0,0 +1,72 @@ + +typedef struct { + size_t 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 = (PPMImage *) malloc(sizeof(PPMImage)); + if (!result) + { + fprintf(stderr, "Unable to allocate memory\n"); + exit(1); + } + + if (fscanf(fp, "%lu %lu", &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 = (GLubyte *) 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 00000000000..ae74af685a7 --- /dev/null +++ b/progs/samples/logo.c @@ -0,0 +1,1635 @@ + +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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; + +static float decal[] = { + GL_DECAL, +}; +static float modulate[] = { + GL_MODULATE, +}; +static float repeat[] = { + GL_REPEAT, +}; +static 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; + printf("PolygonMode GL_FRONT\n"); + break; + case GL_FRONT: + polyMode = GL_FRONT_AND_BACK; + printf("PolygonMode GL_FRONT_AND_BACK\n"); + break; + case GL_FRONT_AND_BACK: + polyMode = GL_BACK; + printf("PolygonMode GL_BACK\n"); + 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); + printf("disable culling\n"); + break; + case 'w': + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + printf("enable front face culling\n"); + break; + case 'e': + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + printf("enable back face culling\n"); + 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 00000000000..dc8991295e8 --- /dev/null +++ b/progs/samples/nurb.c @@ -0,0 +1,357 @@ +/* + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + + +#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)); + } +} + +typedef void (GLAPIENTRY *callback_t)(); + +static void Init(void) +{ + + theNurbs = gluNewNurbsRenderer(); + gluNurbsCallback(theNurbs, GLU_ERROR, (callback_t) 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 00000000000..4fe51efb3cb --- /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 <GL/gl.h> +#include <GL/glx.h> +#include <GL/glu.h> +#include <stdio.h> +#include <string.h> + +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 <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 00000000000..5385e487026 --- /dev/null +++ b/progs/samples/olympic.c @@ -0,0 +1,389 @@ +/* + * 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([email protected]) 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + +#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; + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + + if (dt < 1./30.) + return; + + t0 = t; + + 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 ); +} + +#if !defined(GLUTCALLBACK) +#define GLUTCALLBACK +#endif + +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_TRUE; + + 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 00000000000..23b5a4793ba --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> +#include <GL/glut.h> + + +#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_TRUE; + + 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(1); + } + + if (Args(argc, argv) == GL_FALSE) { + return(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) { + return(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 00000000000..4cb6ad7d517 --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..388e0153b4f --- /dev/null +++ b/progs/samples/prim.c @@ -0,0 +1,546 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..193850abc45 --- /dev/null +++ b/progs/samples/quad.c @@ -0,0 +1,457 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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", (char *) gluErrorString(which)); +} + +typedef void (GLAPIENTRY *callback_t)(); + +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, (callback_t) 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/readtex.c b/progs/samples/readtex.c new file mode 100644 index 00000000000..37d5fcd0d3a --- /dev/null +++ b/progs/samples/readtex.c @@ -0,0 +1,454 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + + + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + 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->rowStart) + free(raw->rowStart); + if (raw->rowSize) + free(raw->rowSize); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + 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 w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + 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; +} + +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) + + +static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes, + const GLubyte *src, + GLushort *dest) +{ + GLint i, j; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + const GLfloat r = (src[0]) / 255.0; + const GLfloat g = (src[1]) / 255.0; + const GLfloat b = (src[2]) / 255.0; + GLfloat y, cr, cb; + GLint iy, icr, icb; + + y = r * 65.481 + g * 128.553 + b * 24.966 + 16; + cb = r * -37.797 + g * -74.203 + b * 112.0 + 128; + cr = r * 112.0 + g * -93.786 + b * -18.214 + 128; + /*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/ + iy = (GLint) CLAMP(y, 0, 254); + icb = (GLint) CLAMP(cb, 0, 254); + icr = (GLint) CLAMP(cr, 0, 254); + + if (j & 1) { + /* odd */ + *dest = (iy << 8) | icr; + } + else { + /* even */ + *dest = (iy << 8) | icb; + } + dest++; + src += texel_bytes; + } + } +} + + +/* + * Load an SGI .rgb file and return a pointer to the image data, converted + * to 422 yuv. + * + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * Return: pointer to image data or NULL if error + */ +GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height ) +{ + TK_RGBImageRec *image; + GLushort *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components != 3 && image->components !=4 ) { + /* not implemented */ + fprintf(stderr, + "Error in LoadYUVImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 ); + + if (buffer) + ConvertRGBtoYUV( image->sizeX, + image->sizeY, + image->components, + image->data, + buffer ); + + + FreeImage(image); + return buffer; +} + diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c new file mode 100644 index 00000000000..116d9a8cfa5 --- /dev/null +++ b/progs/samples/rgbtoppm.c @@ -0,0 +1,285 @@ + +/* texture.c - by David Blythe, SGI */ + +/* texload is a simplistic routine for reading an SGI .rgb image file. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <GL/glut.h> + +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; y<image->ysize; 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; y<image->ysize; 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; + char buff[32]; + int n; + FILE *fo; + + if (argc != 3) + { + fprintf(stderr, "usage: %s <infile.rgb> <outfile.p6>\n", argv[0]); + return 1; + } + + data = read_rgb_texture(argv[1], &width, &height); + + n = sprintf(buff, "P6\n%d %d\n255\n", width, height); + + /* [dBorca] avoid LF to CRLF conversion */ + if ((fo = fopen(argv[2], "wb")) == NULL) { + fprintf(stderr, "Cannot open output file!\n"); + exit(1); + } + + fwrite(buff, n, 1, fo); + fwrite(data, width * 3, height, fo); + + fclose(fo); + + return 0; +} diff --git a/progs/samples/select.c b/progs/samples/select.c new file mode 100644 index 00000000000..2c8f333bfa9 --- /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 <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> +#include <time.h> +#include <GL/glut.h> + + +#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 = NULL; + 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 00000000000..d342ee5b07b --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..7d0508dee9f --- /dev/null +++ b/progs/samples/sphere.c @@ -0,0 +1,1014 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <math.h> +#include <stdlib.h> +#include <GL/glut.h> +#include "readtex.h" + + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + + +GLenum doubleBuffer; +int W = 400, H = 400; + +char *imageFileName = "../images/reflect.rgb"; + +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 = -3.0; +GLenum autoRotate = GL_TRUE; +GLboolean isLit = GL_TRUE; +GLboolean isFogged = GL_FALSE; +GLboolean doTexture = GL_TRUE; +float *textureEnvironment = modulate; + +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 SetDefaultSettings(void) +{ + + magFilter = nnearest; + minFilter = nnearest; + sWrapMode = repeat; + tWrapMode = repeat; + textureEnvironment = modulate; + autoRotate = GL_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[] = {1.0, 1.0, 1.0, 1.0}; + float specular[] = {1.0, 1.0, 1.0, 1.0}; + float position[] = {0.0, 0.0, 4.0, 0.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[] = {0.8, 0.8, 0.8, 1.0}; + float lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; + float lmodel_twoside[] = {GL_TRUE}; + int w, h; + GLenum format; + GLubyte *image; + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + SetDefaultSettings(); + + image = LoadRGBImage(imageFileName, &w, &h, &format); + if (!image) { + printf("Error: couldn't load %s\n", imageFileName); + exit(1); + } + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + gluBuild2DMipmaps(GL_TEXTURE_2D, format, w, h, + GL_RGB, GL_UNSIGNED_BYTE, image); + + free(image); + + glFogf(GL_FOG_DENSITY, 0.125); + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, 4.0); + glFogf(GL_FOG_END, 8.5); + 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); + glEnable(GL_LIGHT0); + + 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); + + + glClearColor(0.0, 0.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + 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); + } + glEnable(GL_DEPTH_TEST); + +#if 0 + if (isFogged) { + textureEnvironment = modulate; + } +#endif + + 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) +{ + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + + /* draw cage */ + if (isFogged) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + glColor3f(1, 1, 1); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glCallList(cage); + + /* draw object */ + if (isLit) + glEnable(GL_LIGHTING); + else + glColor3f(1.0, 0.5, 0.2); + if (doTexture) + glEnable(GL_TEXTURE_2D); + + glPushMatrix(); + glTranslatef(0.0, 0.0, zTranslate); + glRotatef(xRotation, 1, 0, 0); + glRotatef(yRotation, 0, 1, 0); + glCallList(genericObject); + glPopMatrix(); + + glFlush(); + glutSwapBuffers(); +} + +void Reshape(int width, int height) +{ + W = width; + H = height; + ReInit(); + glViewport( 0, 0, width, height ); /*new*/ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-0.2, 0.2, -0.2, 0.2, 0.15, 9.0); + glMatrixMode(GL_MODELVIEW); +} + +void Idle(void) +{ + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + t0 = t; + + xRotation += .75*60.*dt; + yRotation += .375*60.*dt; + glutPostRedisplay(); +} + +void Key2(int key, int x, int y) +{ + + switch (key) { + case GLUT_KEY_LEFT: + yRotation -= 0.5; + autoRotate = GL_FALSE; + ReInit(); + break; + case GLUT_KEY_RIGHT: + yRotation += 0.5; + autoRotate = GL_FALSE; + ReInit(); + break; + case GLUT_KEY_UP: + xRotation -= 0.5; + autoRotate = GL_FALSE; + ReInit(); + break; + case GLUT_KEY_DOWN: + xRotation += 0.5; + autoRotate = GL_FALSE; + ReInit(); + break; + default: + return; + } + glutPostRedisplay(); +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + /* free(image->data);*/ + exit(1); + + case 'a': + autoRotate = !autoRotate; + if (autoRotate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + + ReInit(); + break; + case 'o': + if (genericObject == cube) { + genericObject = cylinder; + } + else if (genericObject == cylinder) { + genericObject = torus; + } + else { + genericObject = 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': + doTexture = !doTexture; + 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; + } + glutPostRedisplay(); +} + +GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_TRUE; + + 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 { + 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 (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(Idle); + + glutMainLoop(); + return 0; +} diff --git a/progs/samples/star.c b/progs/samples/star.c new file mode 100644 index 00000000000..2cf470e2a2f --- /dev/null +++ b/progs/samples/star.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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + + +#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 500 +#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; + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = 85.*(t - t0); + t0 = t; + + 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*dt; + stars[n].y[0] += stars[n].offsetY*dt; + stars[n].z[0] -= offset*dt; + stars[n].rotation += stars[n].offsetR*dt; + if (stars[n].rotation > MAXANGLES) { + stars[n].rotation = 0.0; + } + else if (stars[n].rotation < 0.0) { + stars[n].rotation += 360.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_TRUE; + + 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; +} + +#if !defined(GLUTCALLBACK) +#define GLUTCALLBACK +#endif + +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 00000000000..e00bbb61b0d --- /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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + + +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 00000000000..1fd015d794a --- /dev/null +++ b/progs/samples/stretch.c @@ -0,0 +1,390 @@ +/* + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + + +#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) +{ + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + + if (dt < 1./60.) + return; + + t0 = t; + + 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_TRUE; + + 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; +} + +#if !defined(GLUTCALLBACK) +#define GLUTCALLBACK +#endif + +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 00000000000..7ee41eef28b --- /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 <stdio.h> +#include <string.h> +#include <math.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..3ded79cacaa --- /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 00000000000..700325132ef --- /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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#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 00000000000..d3c4687459e --- /dev/null +++ b/progs/samples/wave.c @@ -0,0 +1,619 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + +#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, +}; + +#if !defined(GLUTCALLBACK) +#define GLUTCALLBACK +#endif + + +void GLUTCALLBACK glut_post_redisplay_p(void) +{ + static double t0 = -1.; + double t, dt; + t = glutGet(GLUT_ELAPSED_TIME) / 1000.; + if (t0 < 0.) + t0 = t; + dt = t - t0; + + if (dt < 1./30.) + return; + + t0 = t; + + 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 = 0, percent; + GLint *indexes = 0, 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_TRUE; + 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 00000000000..8c143142e41 --- /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.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 00000000000..4c039a40f97 --- /dev/null +++ b/progs/util/dumpstate.c @@ -0,0 +1,1959 @@ + +/* + * + * From: Stephane Rehel <[email protected]> + * Date: Mon, 31 May 1999 18:40:54 -0400 + * To: Paul Brian <[email protected]> + * 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 <stdio.h> +#include <GL/gl.h> + +/***************************************************************************/ + +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 <GL/glut.h> + +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 00000000000..fe9c2973c33 --- /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 <GL/gl.h> +#include <GL/glu.h> +#incldue <stdio.h> + + + +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 00000000000..fe35c3d3beb --- /dev/null +++ b/progs/util/glstate.c @@ -0,0 +1,504 @@ +/* $Id: glstate.c,v 1.1.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.1.1 1999/08/19 00:55:42 jtg + * Imported sources + * + * 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 <assert.h> +#include <GL/gl.h> +#include <stdio.h> +#include <stdlib.h> +#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 <GL/glut.h> + +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 00000000000..75f0238c591 --- /dev/null +++ b/progs/util/glstate.h @@ -0,0 +1,53 @@ +/* $Id: glstate.h,v 1.1.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.1.1 1999/08/19 00:55:42 jtg + * Imported sources + * + * 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 <GL/gl.h> + + +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 00000000000..273ed9a2f5a --- /dev/null +++ b/progs/util/glutskel.c @@ -0,0 +1,139 @@ +/** + * A skeleton/template GLUT program + * + * Written by Brian Paul and in the public domain. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> + +static int Win; +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 +Draw(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: + glutDestroyWindow(Win); + 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); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Draw); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/util/idproj.c b/progs/util/idproj.c new file mode 100644 index 00000000000..d5ee3409f38 --- /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.h b/progs/util/imagesgi.h new file mode 100644 index 00000000000..e5ecece49dc --- /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/matrix.c b/progs/util/matrix.c new file mode 100644 index 00000000000..8be2c3111f4 --- /dev/null +++ b/progs/util/matrix.c @@ -0,0 +1,181 @@ +/* + * matrix.c + * + * Some useful matrix functions. + * + * Brian Paul + * 10 Feb 2004 + */ + + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + + +/** + * Pretty-print the given matrix. + */ +void +PrintMatrix(const float p[16]) +{ + printf("[ %6.3f %6.3f %6.3f %6.3f ]\n", p[0], p[4], p[8], p[12]); + printf("[ %6.3f %6.3f %6.3f %6.3f ]\n", p[1], p[5], p[9], p[13]); + printf("[ %6.3f %6.3f %6.3f %6.3f ]\n", p[2], p[6], p[10], p[14]); + printf("[ %6.3f %6.3f %6.3f %6.3f ]\n", p[3], p[7], p[11], p[15]); +} + + +/** + * Build a glFrustum matrix. + */ +void +Frustum(float left, float right, float bottom, float top, float nearZ, float farZ, float *m) +{ + float x = (2.0F*nearZ) / (right-left); + float y = (2.0F*nearZ) / (top-bottom); + float a = (right+left) / (right-left); + float b = (top+bottom) / (top-bottom); + float c = -(farZ+nearZ) / ( farZ-nearZ); + float d = -(2.0F*farZ*nearZ) / (farZ-nearZ); + +#define M(row,col) m[col*4+row] + M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F; + M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F; + M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d; + M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F; +#undef M +} + + +/** + * Build a glOrtho marix. + */ +void +Ortho(float left, float right, float bottom, float top, float nearZ, float farZ, float *m) +{ +#define M(row,col) m[col*4+row] + M(0,0) = 2.0F / (right-left); + M(0,1) = 0.0F; + M(0,2) = 0.0F; + M(0,3) = -(right+left) / (right-left); + + M(1,0) = 0.0F; + M(1,1) = 2.0F / (top-bottom); + M(1,2) = 0.0F; + M(1,3) = -(top+bottom) / (top-bottom); + + M(2,0) = 0.0F; + M(2,1) = 0.0F; + M(2,2) = -2.0F / (farZ-nearZ); + M(2,3) = -(farZ+nearZ) / (farZ-nearZ); + + M(3,0) = 0.0F; + M(3,1) = 0.0F; + M(3,2) = 0.0F; + M(3,3) = 1.0F; +#undef M +} + + +/** + * Decompose a projection matrix to determine original glFrustum or + * glOrtho parameters. + */ +void +DecomposeProjection( const float *m, + int *isPerspective, + float *leftOut, float *rightOut, + float *botOut, float *topOut, + float *nearOut, float *farOut) +{ + if (m[15] == 0.0) { + /* perspective */ + float p[16]; + const float x = m[0]; /* 2N / (R-L) */ + const float y = m[5]; /* 2N / (T-B) */ + const float a = m[8]; /* (R+L) / (R-L) */ + const float b = m[9]; /* (T+B) / (T-B) */ + const float c = m[10]; /* -(F+N) / (F-N) */ + const float d = m[14]; /* -2FN / (F-N) */ + + /* These equations found with simple algebra, knowing the arithmetic + * use to set up a typical perspective projection matrix in OpenGL. + */ + const float nearZ = -d / (1.0 - c); + const float farZ = (c - 1.0) * nearZ / (c + 1.0); + const float left = nearZ * (a - 1.0) / x; + const float right = 2.0 * nearZ / x + left; + const float bottom = nearZ * (b - 1.0) / y; + const float top = 2.0 * nearZ / y + bottom; + + *isPerspective = 1; + *leftOut = left; + *rightOut = right; + *botOut = bottom; + *topOut = top; + *nearOut = nearZ; + *farOut = farZ; + } + else { + /* orthographic */ + const float x = m[0]; /* 2 / (R-L) */ + const float y = m[5]; /* 2 / (T-B) */ + const float z = m[10]; /* -2 / (F-N) */ + const float a = m[12]; /* -(R+L) / (R-L) */ + const float b = m[13]; /* -(T+B) / (T-B) */ + const float c = m[14]; /* -(F+N) / (F-N) */ + /* again, simple algebra */ + const float right = -(a - 1.0) / x; + const float left = right - 2.0 / x; + const float top = -(b - 1.0) / y; + const float bottom = top - 2.0 / y; + const float farZ = (c - 1.0) / z; + const float nearZ = farZ + 2.0 / z; + + *isPerspective = 0; + *leftOut = left; + *rightOut = right; + *botOut = bottom; + *topOut = top; + *nearOut = nearZ; + *farOut = farZ; + } +} + + +#if 0 +/* test harness */ +int +main(int argc, char *argv[]) +{ + float m[16], p[16]; + float l, r, b, t, n, f; + int persp; + int i; + +#if 0 + l = -.9; + r = 1.2; + b = -0.5; + t = 1.4; + n = 30; + f = 84; + printf(" Frustum(%f, %f, %f, %f, %f, %f\n",l+1, r+1.2, b+.5, t+.3, n, f); + Frustum(l+1, r+1.2, b+.5, t+.3, n, f, p); + DecomposeProjection(p, &persp, &l, &r, &b, &t, &n, &f); + printf("glFrustum(%f, %f, %f, %f, %f, %f)\n", + l, r, b, t, n, f); + PrintMatrix(p); +#else + printf("Ortho(-1, 1, -1, 1, 10, 84)\n"); + Ortho(-1, 1, -1, 1, 10, 84, m); + PrintMatrix(m); + DecomposeProjection(m, &persp, &l, &r, &b, &t, &n, &f); + printf("Ortho(%f, %f, %f, %f, %f, %f) %d\n", l, r, b, t, n, f, persp); +#endif + + return 0; +} +#endif diff --git a/progs/util/mwmborder.c b/progs/util/mwmborder.c new file mode 100644 index 00000000000..b61ffb50bc2 --- /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 [email protected] + * + * This code is in the public domain. + */ + + +#include <X11/Xlib.h> +#include <X11/Xatom.h> + +#define HAVE_MOTIF +#ifdef HAVE_MOTIF + +#include <X11/Xm/MwmUtil.h> + +#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 00000000000..37d5fcd0d3a --- /dev/null +++ b/progs/util/readtex.c @@ -0,0 +1,454 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + + + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + 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->rowStart) + free(raw->rowStart); + if (raw->rowSize) + free(raw->rowSize); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + 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 w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + 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; +} + +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) + + +static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes, + const GLubyte *src, + GLushort *dest) +{ + GLint i, j; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + const GLfloat r = (src[0]) / 255.0; + const GLfloat g = (src[1]) / 255.0; + const GLfloat b = (src[2]) / 255.0; + GLfloat y, cr, cb; + GLint iy, icr, icb; + + y = r * 65.481 + g * 128.553 + b * 24.966 + 16; + cb = r * -37.797 + g * -74.203 + b * 112.0 + 128; + cr = r * 112.0 + g * -93.786 + b * -18.214 + 128; + /*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/ + iy = (GLint) CLAMP(y, 0, 254); + icb = (GLint) CLAMP(cb, 0, 254); + icr = (GLint) CLAMP(cr, 0, 254); + + if (j & 1) { + /* odd */ + *dest = (iy << 8) | icr; + } + else { + /* even */ + *dest = (iy << 8) | icb; + } + dest++; + src += texel_bytes; + } + } +} + + +/* + * Load an SGI .rgb file and return a pointer to the image data, converted + * to 422 yuv. + * + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * Return: pointer to image data or NULL if error + */ +GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height ) +{ + TK_RGBImageRec *image; + GLushort *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components != 3 && image->components !=4 ) { + /* not implemented */ + fprintf(stderr, + "Error in LoadYUVImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 ); + + if (buffer) + ConvertRGBtoYUV( image->sizeX, + image->sizeY, + image->components, + image->data, + buffer ); + + + FreeImage(image); + return buffer; +} + diff --git a/progs/util/readtex.h b/progs/util/readtex.h new file mode 100644 index 00000000000..6c9a3828d38 --- /dev/null +++ b/progs/util/readtex.h @@ -0,0 +1,26 @@ +/* readtex.h */ + +#ifndef READTEX_H +#define READTEX_H + + +#include <GL/gl.h> + + +extern GLboolean +LoadRGBMipmaps( const char *imageFile, GLint intFormat ); + + +extern GLboolean +LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ); + + +extern GLubyte * +LoadRGBImage( const char *imageFile, + GLint *width, GLint *height, GLenum *format ); + +extern GLushort * +LoadYUVImage( const char *imageFile, GLint *width, GLint *height ); + +#endif diff --git a/progs/util/sampleMakefile b/progs/util/sampleMakefile new file mode 100644 index 00000000000..a7e510f66de --- /dev/null +++ b/progs/util/sampleMakefile @@ -0,0 +1,49 @@ +# $Id: sampleMakefile,v 1.1.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.1.1 1999/08/19 00:55:42 jtg +# Imported sources +# +# 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 00000000000..17f84dc62bd --- /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 <assert.h> +#include <stdlib.h> +#include <GL/gl.h> +#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 00000000000..63533d8e9b5 --- /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 <GL/gl.h> + + + +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/trackball.c b/progs/util/trackball.c new file mode 100644 index 00000000000..a6c4c60d06b --- /dev/null +++ b/progs/util/trackball.c @@ -0,0 +1,338 @@ +#include <stdio.h> +/* + * (c) Copyright 1993, 1994, 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. + */ +/* + * Trackball code: + * + * Implementation of a virtual trackball. + * Implemented by Gavin Bell, lots of ideas from Thant Tessman and + * the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129. + * + * Vector manip code: + * + * Original code from: + * David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli + * + * Much mucking with by: + * Gavin Bell + */ +#if defined(_WIN32) +#pragma warning (disable:4244) /* disable bogus conversion warnings */ +#endif +#include <math.h> +#include "trackball.h" + +/* + * This size should really be based on the distance from the center of + * rotation to the point on the object underneath the mouse. That + * point would then track the mouse as closely as possible. This is a + * simple example, though, so that is left as an Exercise for the + * Programmer. + */ +#define TRACKBALLSIZE (0.8f) + +/* + * Local function prototypes (not defined in trackball.h) + */ +static float tb_project_to_sphere(float, float, float); +static void normalize_quat(float [4]); + +static void +vzero(float v[3]) +{ + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; +} + +static void +vset(float v[3], float x, float y, float z) +{ + v[0] = x; + v[1] = y; + v[2] = z; +} + +static void +vsub(const float src1[3], const float src2[3], float dst[3]) +{ + dst[0] = src1[0] - src2[0]; + dst[1] = src1[1] - src2[1]; + dst[2] = src1[2] - src2[2]; +} + +static void +vcopy(const float v1[3], float v2[3]) +{ + register int i; + for (i = 0 ; i < 3 ; i++) + v2[i] = v1[i]; +} + +static void +vcross(const float v1[3], const float v2[3], float cross[3]) +{ + float temp[3]; + + temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]); + temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]); + temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]); + vcopy(temp, cross); +} + +static float +vlength(const float v[3]) +{ + return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +} + +static void +vscale(float v[3], float div) +{ + v[0] *= div; + v[1] *= div; + v[2] *= div; +} + +static void +vnormal(float v[3]) +{ + vscale(v,1.0/vlength(v)); +} + +static float +vdot(const float v1[3], const float v2[3]) +{ + return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; +} + +static void +vadd(const float src1[3], const float src2[3], float dst[3]) +{ + dst[0] = src1[0] + src2[0]; + dst[1] = src1[1] + src2[1]; + dst[2] = src1[2] + src2[2]; +} + +/* + * Ok, simulate a track-ball. Project the points onto the virtual + * trackball, then figure out the axis of rotation, which is the cross + * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0) + * Note: This is a deformed trackball-- is a trackball in the center, + * but is deformed into a hyperbolic sheet of rotation away from the + * center. This particular function was chosen after trying out + * several variations. + * + * It is assumed that the arguments to this routine are in the range + * (-1.0 ... 1.0) + */ +void +trackball(float q[4], float p1x, float p1y, float p2x, float p2y) +{ + float a[3]; /* Axis of rotation */ + float phi; /* how much to rotate about axis */ + float p1[3], p2[3], d[3]; + float t; + + if (p1x == p2x && p1y == p2y) { + /* Zero rotation */ + vzero(q); + q[3] = 1.0; + return; + } + + /* + * First, figure out z-coordinates for projection of P1 and P2 to + * deformed sphere + */ + vset(p1,p1x,p1y,tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y)); + vset(p2,p2x,p2y,tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y)); + + /* + * Now, we want the cross product of P1 and P2 + */ + vcross(p2,p1,a); + + /* + * Figure out how much to rotate around that axis. + */ + vsub(p1,p2,d); + t = vlength(d) / (2.0*TRACKBALLSIZE); + + /* + * Avoid problems with out-of-control values... + */ + if (t > 1.0) t = 1.0; + if (t < -1.0) t = -1.0; + phi = 2.0 * asin(t); + + axis_to_quat(a,phi,q); +} + +/* + * Given an axis and angle, compute quaternion. + */ +void +axis_to_quat(const float a[3], float phi, float q[4]) +{ + vcopy(a,q); + vnormal(q); + vscale(q, sin(phi/2.0)); + q[3] = cos(phi/2.0); +} + +/* + * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet + * if we are away from the center of the sphere. + */ +static float +tb_project_to_sphere(float r, float x, float y) +{ + float d, t, z; + + d = sqrt(x*x + y*y); + if (d < r * 0.70710678118654752440) { /* Inside sphere */ + z = sqrt(r*r - d*d); + } else { /* On hyperbola */ + t = r / 1.41421356237309504880; + z = t*t / d; + } + return z; +} + +/* + * Given two rotations, e1 and e2, expressed as quaternion rotations, + * figure out the equivalent single rotation and stuff it into dest. + * + * This routine also normalizes the result every RENORMCOUNT times it is + * called, to keep error from creeping in. + * + * NOTE: This routine is written so that q1 or q2 may be the same + * as dest (or each other). + */ + +#define RENORMCOUNT 97 + +void +add_quats(const float q1[4], const float q2[4], float dest[4]) +{ + static int count=0; + float t1[4], t2[4], t3[4]; + float tf[4]; + +#if 0 +printf("q1 = %f %f %f %f\n", q1[0], q1[1], q1[2], q1[3]); +printf("q2 = %f %f %f %f\n", q2[0], q2[1], q2[2], q2[3]); +#endif + + vcopy(q1,t1); + vscale(t1,q2[3]); + + vcopy(q2,t2); + vscale(t2,q1[3]); + + vcross(q2,q1,t3); + vadd(t1,t2,tf); + vadd(t3,tf,tf); + tf[3] = q1[3] * q2[3] - vdot(q1,q2); + +#if 0 +printf("tf = %f %f %f %f\n", tf[0], tf[1], tf[2], tf[3]); +#endif + + dest[0] = tf[0]; + dest[1] = tf[1]; + dest[2] = tf[2]; + dest[3] = tf[3]; + + if (++count > RENORMCOUNT) { + count = 0; + normalize_quat(dest); + } +} + +/* + * Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0 + * If they don't add up to 1.0, dividing by their magnitued will + * renormalize them. + * + * Note: See the following for more information on quaternions: + * + * - Shoemake, K., Animating rotation with quaternion curves, Computer + * Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985. + * - Pletinckx, D., Quaternion calculus as a basic tool in computer + * graphics, The Visual Computer 5, 2-13, 1989. + */ +static void +normalize_quat(float q[4]) +{ + int i; + float mag; + + mag = sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]); + for (i = 0; i < 4; i++) + q[i] /= mag; +} + +/* + * Build a rotation matrix, given a quaternion rotation. + * + */ +void +build_rotmatrix(float m[4][4], const float q[4]) +{ + m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]); + m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]); + m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]); + m[0][3] = 0.0; + + m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]); + m[1][1]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]); + m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]); + m[1][3] = 0.0; + + m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]); + m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]); + m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]); + m[2][3] = 0.0; + + m[3][0] = 0.0; + m[3][1] = 0.0; + m[3][2] = 0.0; + m[3][3] = 1.0; +} + diff --git a/progs/util/trackball.h b/progs/util/trackball.h new file mode 100644 index 00000000000..9b278640e10 --- /dev/null +++ b/progs/util/trackball.h @@ -0,0 +1,84 @@ +/* + * (c) Copyright 1993, 1994, 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. + */ +/* + * trackball.h + * A virtual trackball implementation + * Written by Gavin Bell for Silicon Graphics, November 1988. + */ + +#ifndef TRACKBALL_H +#define TRACKBALL_H + + +/* + * Pass the x and y coordinates of the last and current positions of + * the mouse, scaled so they are from (-1.0 ... 1.0). + * + * The resulting rotation is returned as a quaternion rotation in the + * first paramater. + */ +void +trackball(float q[4], float p1x, float p1y, float p2x, float p2y); + +/* + * Given two quaternions, add them together to get a third quaternion. + * Adding quaternions to get a compound rotation is analagous to adding + * translations to get a compound translation. When incrementally + * adding rotations, the first argument here should be the new + * rotation, the second and third the total rotation (which will be + * over-written with the resulting new total rotation). + */ +void +add_quats(const float q1[4], const float q2[4], float dest[4]); + +/* + * A useful function, builds a rotation matrix in Matrix based on + * given quaternion. + */ +void +build_rotmatrix(float m[4][4], const float q[4]); + +/* + * This function computes a quaternion based on an axis (defined by + * the given vector) and an angle about which to rotate. The angle is + * expressed in radians. The result is put into the third argument. + */ +void +axis_to_quat(const float a[3], float phi, float q[4]); + + +#endif /* TRACKBALL_H */ diff --git a/progs/util/winpos.c b/progs/util/winpos.c new file mode 100644 index 00000000000..5ad98fd2704 --- /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/util/xrotfont.c b/progs/util/xrotfont.c new file mode 100644 index 00000000000..f1779678a7a --- /dev/null +++ b/progs/util/xrotfont.c @@ -0,0 +1,368 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * glXUseRotatedXFontMESA() function - like glXUseXFont() but allows + * specification of a 0, 90, 180 or 270 degree rotation. + * Handy for drawing labels along vertical axes of graphs, etc. + * + * Based on Mesa's glXUseXFont code written and copyrighted by Thorsten Ohl. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/gl.h> +#include <GL/glx.h> + + + +/** + * Generate OpenGL-compatible bitmap by drawing an X character glyph + * to an off-screen pixmap, then getting the image and testing pixels. + * \param width bitmap width in pixels + * \param height bitmap height in pixels + */ +static void +fill_bitmap(Display *dpy, Pixmap pixmap, GC gc, + unsigned int bitmapWidth, unsigned int bitmapHeight, + unsigned int charWidth, unsigned int charHeight, + int xPos, int yPos, unsigned int c, GLubyte * bitmap, + int rotation) +{ + const int bytesPerRow = (bitmapWidth + 7) / 8; + XImage *image; + XChar2b char2b; + + /* clear pixmap to 0 */ + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, pixmap, gc, 0, 0, charWidth, charHeight); + + /* The glyph is drawn snug up against the left/top edges of the pixmap */ + XSetForeground(dpy, gc, 1); + char2b.byte1 = (c >> 8) & 0xff; + char2b.byte2 = (c & 0xff); + XDrawString16(dpy, pixmap, gc, xPos, yPos, &char2b, 1); + + /* initialize GL bitmap */ + memset(bitmap, 0, bytesPerRow * bitmapHeight); + + image = XGetImage(dpy, pixmap, 0, 0, charWidth, charHeight, 1, XYPixmap); + if (image) { + /* Set appropriate bits in the GL bitmap. + * Note: X11 and OpenGL are upside down wrt each other). + */ + unsigned int x, y; + if (rotation == 0) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int y2 = bitmapHeight - y - 1; + bitmap[bytesPerRow * y2 + x / 8] |= (1 << (7 - (x % 8))); + } + } + } + } + else if (rotation == 90) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = y; + int y2 = x; + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + else if (rotation == 180) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = charWidth - x - 1; + bitmap[bytesPerRow * y + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + else { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = charHeight - y - 1; + int y2 = charWidth - x - 1; + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + XDestroyImage(image); + } +} + + +/** + * Determine if a given glyph is valid and return the + * corresponding XCharStruct. + */ +static const XCharStruct * +isvalid(const XFontStruct * fs, unsigned int which) +{ + unsigned int rows, pages; + unsigned int byte1 = 0, byte2 = 0; + int i, valid = 1; + + rows = fs->max_byte1 - fs->min_byte1 + 1; + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + + if (rows == 1) { + /* "linear" fonts */ + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) + valid = 0; + } + else { + /* "matrix" fonts */ + byte2 = which & 0xff; + byte1 = which >> 8; + if ((fs->min_char_or_byte2 > byte2) || + (fs->max_char_or_byte2 < byte2) || + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) + valid = 0; + } + + if (valid) { + if (fs->per_char) { + if (rows == 1) { + /* "linear" fonts */ + return fs->per_char + (which - fs->min_char_or_byte2); + } + else { + /* "matrix" fonts */ + i = ((byte1 - fs->min_byte1) * pages) + + (byte2 - fs->min_char_or_byte2); + return fs->per_char + i; + } + } + else { + return &fs->min_bounds; + } + } + return NULL; +} + + +/** + * Just like glXUseXFont() but with a rotation parameter. + * \param rotation may be 0, 90, 180 or 270 only. + */ +void +glXUseRotatedXFontMESA(Font font, int first, int count, int listbase, + int rotation) +{ + Display *dpy; + Window win; + Pixmap pixmap; + GC gc; + XFontStruct *fs; + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + unsigned int maxCharWidth, maxCharHeight; + GLubyte *bm; + int i; + + if (rotation != 0 && + rotation != 90 && + rotation != 180 && + rotation != 270) + return; + + dpy = glXGetCurrentDisplay(); + if (!dpy) + return; /* I guess glXMakeCurrent wasn't called */ + win = RootWindow(dpy, DefaultScreen(dpy)); + + fs = XQueryFont(dpy, font); + if (!fs) { + fprintf(stderr, "XQueryFont failed"); + return; + } + + /* Allocate a GL bitmap that can fit any character */ + maxCharWidth = fs->max_bounds.rbearing - fs->min_bounds.lbearing; + maxCharHeight = fs->max_bounds.ascent + fs->max_bounds.descent; + /* use max, in case we're rotating */ + if (rotation == 90 || rotation == 270) { + /* swap width/height */ + bm = (GLubyte *) malloc((maxCharHeight + 7) / 8 * maxCharWidth); + } + else { + /* normal or upside down */ + bm = (GLubyte *) malloc((maxCharWidth + 7) / 8 * maxCharHeight); + } + if (!bm) { + XFreeFontInfo(NULL, fs, 1); + fprintf(stderr, "Out of memory in glXUseRotatedXFontMESA"); + return; + } + + /* Save the current packing mode for bitmaps. */ + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + + /* Enforce a standard packing mode which is compatible with + fill_bitmap() from above. This is actually the default mode, + except for the (non)alignment. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + /* Create pixmap and GC */ + pixmap = XCreatePixmap(dpy, win, maxCharWidth, maxCharHeight, 1); + { + XGCValues values; + unsigned long valuemask; + values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); + values.background = WhitePixel(dpy, DefaultScreen(dpy)); + values.font = fs->fid; + valuemask = GCForeground | GCBackground | GCFont; + gc = XCreateGC(dpy, pixmap, valuemask, &values); + } + + for (i = 0; i < count; i++) { + const unsigned int c = first + i; + const int list = listbase + i; + unsigned int charWidth, charHeight; + unsigned int bitmapWidth, bitmapHeight; + GLfloat xOrig, yOrig, xStep, yStep, dtemp; + const XCharStruct *ch; + int xPos, yPos; + int valid; + + /* check on index validity and get the bounds */ + ch = isvalid(fs, c); + if (!ch) { + ch = &fs->max_bounds; + valid = 0; + } + else { + valid = 1; + } + + /* glBitmap()' parameters: + straight from the glXUseXFont(3) manpage. */ + charWidth = ch->rbearing - ch->lbearing; + charHeight = ch->ascent + ch->descent; + xOrig = -ch->lbearing; + yOrig = ch->descent; + xStep = ch->width; + yStep = 0; + + /* X11's starting point. */ + xPos = -ch->lbearing; + yPos = ch->ascent; + + /* Apply rotation */ + switch (rotation) { + case 0: + /* nothing */ + bitmapWidth = charWidth; + bitmapHeight = charHeight; + break; + case 90: + /* xStep, yStep */ + dtemp = xStep; + xStep = -yStep; + yStep = dtemp; + /* xOrig, yOrig */ + yOrig = xOrig; + xOrig = charHeight - (charHeight - yPos); + /* width, height */ + bitmapWidth = charHeight; + bitmapHeight = charWidth; + break; + case 180: + /* xStep, yStep */ + xStep = -xStep; + yStep = -yStep; + /* xOrig, yOrig */ + xOrig = charWidth - xOrig - 1; + yOrig = charHeight - yOrig - 1; + bitmapWidth = charWidth; + bitmapHeight = charHeight; + break; + case 270: + /* xStep, yStep */ + dtemp = xStep; + xStep = yStep; + yStep = -dtemp; + /* xOrig, yOrig */ + dtemp = yOrig; + yOrig = charWidth - xOrig; + xOrig = dtemp; + /* width, height */ + bitmapWidth = charHeight; + bitmapHeight = charWidth; + break; + default: + /* should never get here */ + ; + } + + glNewList(list, GL_COMPILE); + if (valid && bitmapWidth > 0 && bitmapHeight > 0) { + + fill_bitmap(dpy, pixmap, gc, bitmapWidth, bitmapHeight, + charWidth, charHeight, + xPos, yPos, c, bm, rotation); + + glBitmap(bitmapWidth, bitmapHeight, xOrig, yOrig, xStep, yStep, bm); + } + else { + glBitmap(0, 0, 0.0, 0.0, xStep, yStep, NULL); + } + glEndList(); + } + + free(bm); + XFreeFontInfo(NULL, fs, 1); + XFreePixmap(dpy, pixmap); + XFreeGC(dpy, gc); + + /* Restore saved packing modes. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); + glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); + glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} diff --git a/progs/windml/Makefile.ugl b/progs/windml/Makefile.ugl new file mode 100644 index 00000000000..90b0b29bc82 --- /dev/null +++ b/progs/windml/Makefile.ugl @@ -0,0 +1,68 @@ +# Mesa 3-D graphics library +# Version: 3.5 +# +# Copyright (C) 2001 Wind River Systems, Inc + +# The MIT License +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Makefile for UGL/Mesa demos + +DEMO_SOURCES = readtex.c uglaccum.c uglalldemos.c uglbounce.c uglcube.c \ +ugldrawpix.c uglflip.c uglgears.c uglicotorus.c uglline.c uglolympic.c \ +uglpoint.c uglstencil.c uglteapot.c ugltexcube.c ugltexcyl.c +#win2d3d/winRoot.c win2d3d/winBall.c win2d3d/winPuzzle.c win2d3d/winHello.c \ +#win2d3d/winImage.c win2d3d/winGears.c + +DEMO_OBJECTS = $(DEMO_SOURCES:.c=.o) + +SOURCES = $(DEMO_SOURCES) + +include ../rules.windml + +##### TARGETS ##### + +all: depend.$(CPU)$(TOOL) $(DEMO_OBJECTS) + +depend.$(CPU)$(TOOL): +ifeq ($(WIND_HOST_TYPE),x86-win32) + @ $(RM) $@ + @ $(ECHO) Creating depend.$(CPU)$(TOOL) +ifneq ($(SOURCES),) + @ for %f in ($(SOURCES)) do \ + $(CC) -MM $(CFLAGS) %f >>$@ +endif +else +Makefile + @ $(RM) $@ + @ $(ECHO) "Creating depend.$(CPU)$(TOOL)" +ifneq ($(SOURCES),) + @ for FILE in $(filter-out $(NODEPENDOBJS), $(SOURCES)); \ + do \ + $(CC) -MM $(CFLAGS) $$FILE \ + | $(TCL) $(BIN_DIR)/depend.tcl $(TGT_DIR) >>$@; \ + done +endif +endif + +.PHONY = clean + +clean: + $(RM) $(DEMO_OBJECTS) + $(RM) depend.$(CPU)$(TOOL) diff --git a/progs/windml/readtex.c b/progs/windml/readtex.c new file mode 100644 index 00000000000..659c49de8de --- /dev/null +++ b/progs/windml/readtex.c @@ -0,0 +1,365 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "../util/readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + 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 w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + 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/windml/uglaccum.c b/progs/windml/uglaccum.c new file mode 100644 index 00000000000..fd7cb3125c1 --- /dev/null +++ b/progs/windml/uglaccum.c @@ -0,0 +1,250 @@ + +/* 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. + */ + +/* Original name: accanti.c + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/uglglutshapes.h> + +#include "../book/jitter.h" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +/* Initialize lighting and other values. + */ +UGL_LOCAL void initGL(GLsizei w, GLsizei h) + { + 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); + + 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); + } + +UGL_LOCAL 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 + +UGL_LOCAL void drawGL(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(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLAccum (UGL_BOOL windMLMode); + +void uglaccum (void) + { + taskSpawn("tAccum", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLAccum,UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLAccum (UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei width, height; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + if (windMLMode) + umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, + 16, + 0, + 8,8,8,0, + NULL); + else + umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE, + 16, + 0, + 8,8,8,0, + NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, + UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + drawGL(); + + while (!getEvent()); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglalldemos.c b/progs/windml/uglalldemos.c new file mode 100644 index 00000000000..283e4870740 --- /dev/null +++ b/progs/windml/uglalldemos.c @@ -0,0 +1,198 @@ + +/* uglalldemos.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +modification history +-------------------- +02a,29aug01,sra WindML mode added +01a,17jul01,sra written +*/ + +/* +DESCRIPTION +Show all the UGL/Mesa demos +*/ + +#include <stdio.h> +#include <vxWorks.h> +#include <taskLib.h> +#include <ugl/ugl.h> +#include <ugl/uglinput.h> +#include <ugl/uglevent.h> +#include <ugl/uglfont.h> + +#define BLACK 0 +#define RED 1 + +struct _colorStruct + { + UGL_RGB rgbColor; + UGL_COLOR uglColor; + } +colorTable[] = + { + { UGL_MAKE_RGB(0, 0, 0), 0}, + { UGL_MAKE_RGB(255, 0, 0), 0}, + }; + +void windMLPoint (UGL_BOOL windMLMode); +void windMLLine (UGL_BOOL windMLMode); +void windMLFlip (UGL_BOOL windMLMode); +void windMLCube (UGL_BOOL windMLMode); +void windMLBounce (UGL_BOOL windMLMode); +void windMLGears (UGL_BOOL windMLMode); +void windMLIcoTorus (UGL_BOOL windMLMode); +void windMLOlympic (UGL_BOOL windMLMode); +void windMLTexCube (UGL_BOOL windMLMode); +void windMLTexCyl (UGL_BOOL windMLMode); +void windMLTeapot (UGL_BOOL windMLMode); +void windMLStencil (UGL_BOOL windMLMode); +void windMLDrawPix (UGL_BOOL windMLMode); +void windMLAccum (UGL_BOOL windMLMode); +void windMLAllDemos (void); + +void uglalldemos (void) + { + taskSpawn("tAllDemos", 210, VX_FP_TASK, 200000, + (FUNCPTR)windMLAllDemos, 0,1,2,3,4,5,6,7,8,9); + } + +void windMLAllDemos(void) + { + UGL_BOOL windMLFlag = UGL_FALSE; + UGL_FB_INFO fbInfo; + UGL_EVENT event; + UGL_EVENT_SERVICE_ID eventServiceId; + UGL_EVENT_Q_ID qId; + UGL_INPUT_EVENT * pInputEvent; + UGL_INPUT_DEVICE_ID keyboardDevId; + UGL_DEVICE_ID devId; + UGL_GC_ID gc; + UGL_FONT_ID fontId; + UGL_FONT_DEF fontDef; + UGL_FONT_DRIVER_ID fontDrvId; + UGL_ORD textOrigin = UGL_FONT_TEXT_UPPER_LEFT; + int displayHeight, displayWidth; + int textWidth, textHeight; + static UGL_CHAR * message = + "Do you want to use WindML exclusively ? (y/n) "; + + uglInitialize(); + + uglDriverFind (UGL_DISPLAY_TYPE, 0, (UGL_UINT32 *)&devId); + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + qId = uglEventQCreate (eventServiceId, 100); + + gc = uglGcCreate(devId); + + uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&fontDrvId); + uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin); + + uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize = 18", + &fontDef); + + if ((fontId = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) + { + printf("Font not found. Exiting.\n"); + return; + } + + uglInfo(devId, UGL_FB_INFO_REQ, &fbInfo); + displayWidth = fbInfo.width; + displayHeight = fbInfo.height; + + uglColorAlloc (devId, &colorTable[BLACK].rgbColor, UGL_NULL, + &colorTable[BLACK].uglColor, 1); + uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL, + &colorTable[RED].uglColor, 1); + + uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); + uglForegroundColorSet(gc, colorTable[RED].uglColor); + uglFontSet(gc, fontId); + uglTextSizeGet(fontId, &textWidth, &textHeight, -1, message); + uglTextDraw(gc, (displayWidth - textWidth) / 2, + (displayHeight - textHeight) / 2 - textHeight, -1, message); +/* flushQ(); + */ + if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + { + switch(pInputEvent->type.keyboard.key) + { + case 'Y': + case 'y': + windMLFlag = UGL_TRUE; + break; + default: + windMLFlag = UGL_FALSE; + } + } + } + + uglFontDestroy (fontId); + uglGcDestroy (gc); + uglEventQDestroy (eventServiceId, qId); + uglDeinitialize(); + + windMLPoint(windMLFlag); + + windMLLine(windMLFlag); + + windMLFlip(windMLFlag); + + windMLCube(windMLFlag); + + windMLBounce(windMLFlag); + + windMLGears(windMLFlag); + + windMLIcoTorus(windMLFlag); + + windMLOlympic(windMLFlag); + + windMLTexCube(windMLFlag); + + windMLTexCyl(windMLFlag); + + windMLTeapot(windMLFlag); + + windMLStencil(windMLFlag); + + windMLDrawPix(windMLFlag); + + windMLAccum(windMLFlag); + + return; + } diff --git a/progs/windml/uglbounce.c b/progs/windml/uglbounce.c new file mode 100644 index 00000000000..287015a4131 --- /dev/null +++ b/progs/windml/uglbounce.c @@ -0,0 +1,272 @@ +/* + * Bouncing ball demo. + * + * This program is in the public domain + * + * Brian Paul + * + * Conversion to GLUT by Mark J. Kilgard + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> + +#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 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLuint Ball; +UGL_LOCAL GLfloat Zrot, Zstep; +UGL_LOCAL GLfloat Xpos, Ypos; +UGL_LOCAL GLfloat Xvel, Yvel; +UGL_LOCAL GLfloat Xmin, Xmax; +UGL_LOCAL GLfloat Ymin; +/* UGL_LOCAL GLfloat Ymax = 4.0; */ +UGL_LOCAL GLfloat G; + +UGL_LOCAL 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 = radius * COS(b) * COS(a); + y = radius * SIN(b) * COS(a); + z = radius * 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; + } + +UGL_LOCAL void initGL(GLsizei width, GLsizei height) + { + float aspect = (float) width / (float) height; + glViewport(0, 0, (GLint) width, (GLint) height); + + uglMesaSetColor(RED, 1.0, 0.0, 0.0); + uglMesaSetColor(WHITE, 1.0, 1.0, 1.0); + uglMesaSetColor(CYAN, 0.0, 1.0, 1.0); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-6.0 * aspect, 6.0 * aspect, -6.0, 6.0, -6.0, 6.0); + glMatrixMode(GL_MODELVIEW); + + } + +UGL_LOCAL void drawGL(void) + { + GLint i; + static float vel0 = -100.0; + + 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(); + + uglMesaSwapBuffers(); + + 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; + } + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLBounce (UGL_BOOL windMLMode); + +void uglbounce (void) + { + taskSpawn("tBounce", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLBounce, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLBounce(UGL_BOOL windMLMode) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + Zrot = 0.0; + Zstep = 6.0; + Xpos = 0.0; + Ypos = 1.0; + Xvel = 0.2; + Yvel = 0.0; + Xmin = -4.0; + Xmax = 4.0; + Ymin = -3.8; + G = -0.1; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + Ball = make_ball(); + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + while(!getEvent()) + drawGL(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/uglcube.c b/progs/windml/uglcube.c new file mode 100644 index 00000000000..e701d8db462 --- /dev/null +++ b/progs/windml/uglcube.c @@ -0,0 +1,257 @@ +/* uglcube.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +DESCRIPTION +Draw a smooth cube. +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL GLfloat rotx; +UGL_LOCAL GLfloat roty; +UGL_LOCAL GLuint theCube; + +UGL_LOCAL void cube() + { + + /* Front */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + + + /* Back */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glEnd(); + + + /* Right */ + glBegin(GL_QUADS); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glEnd(); + + /* Left */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + + /* Top */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glEnd(); + + + /* Bottom */ + glBegin(GL_QUADS); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + } + +UGL_LOCAL void initGL + ( + int Width, + int Height + ) + { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + + theCube = glGenLists(1); + glNewList(theCube, GL_COMPILE); + cube(); + glEndList(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0f, (GLfloat) Width / (GLfloat) Height, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -6.0f); + } + + +/* The main drawing function. */ + +UGL_LOCAL void drawGL() + { + + /* Clear The Screen And The Depth Buffer */ + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* Rotate the cube */ + + glRotatef(rotx, 1.0f, 0.0f, 0.0f); + glRotatef(roty, 0.0f, 1.0f, 0.0f); + + glCallList(theCube); + + glFlush(); + + uglMesaSwapBuffers(); + } + + +/* The function called whenever a key is pressed. */ + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLCube (UGL_BOOL windMLMode); + +void uglcube (void) + { + taskSpawn("tCube", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLCube, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLCube (UGL_BOOL windMLMode) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + rotx = 2.5f; + roty = 1.0f; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + /* Initialize our window. */ + + initGL(width, height); + + while (!getEvent()) + drawGL(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/ugldrawpix.c b/progs/windml/ugldrawpix.c new file mode 100644 index 00000000000..b33be2c6aee --- /dev/null +++ b/progs/windml/ugldrawpix.c @@ -0,0 +1,438 @@ +/* + * glDrawPixels demo/test/benchmark + * + * Brian Paul September 25, 1997 This file is in the public domain. + * + * Conversion to UGL/Mesa by Stephane Raimbault july, 2001 + */ + +/* + * $Log: ugldrawpix.c,v $ + * Revision 1.2 2001/09/10 19:21:13 brianp + * WindML updates (Stephane Raimbault) + * + * Revision 1.1 2001/08/20 16:07:11 brianp + * WindML driver (Stephane Raimbault) + * + * Revision 1.5 2000/12/24 22:53:54 pesco + * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util. + * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus: + * Essentially the same. + * Program files updated to include "readtex.c", not "../util/readtex.c". + * * demos/reflect.c: Likewise for "showbuffer.c". + * + * + * * Makefile.am (EXTRA_DIST): Added top-level regular files. + * + * * include/GL/Makefile.am (INC_X11): Added glxext.h. + * + * + * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include + * Mesa GGI headers in dist even if HAVE_GGI is not given. + * + * * configure.in: Look for GLUT and demo source dirs in $srcdir. + * + * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch]. + * More source list updates in various Makefile.am's. + * + * * Makefile.am (dist-hook): Remove CVS directory from distribution. + * (DIST_SUBDIRS): List all possible subdirs here. + * (SUBDIRS): Only list subdirs selected for build again. + * The above two applied to all subdir Makefile.am's also. + * + * Revision 1.4 2000/09/08 21:45:21 brianp + * added dither key option + * + * Revision 1.3 1999/10/28 18:23:29 brianp + * minor changes to Usage() function + * + * Revision 1.2 1999/10/21 22:13:58 brianp + * added f key to toggle front/back drawing + * + * Revision 1.1.1.1 1999/08/19 00:55:40 jtg + * Imported sources + * + * Revision 3.3 1999/03/28 18:18:33 brianp + * minor clean-up + * + * Revision 3.2 1998/11/05 04:34:04 brianp + * moved image files to ../images/ directory + * + * Revision 3.1 1998/02/22 16:43:17 brianp + * added a few casts to silence compiler warnings + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#include "../util/readtex.h" + +#define IMAGE_FILE "Mesa/images/wrs_logo.rgb" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL int ImgWidth, ImgHeight; +UGL_LOCAL GLenum ImgFormat; +UGL_LOCAL GLubyte *Image; + +UGL_LOCAL int Xpos, Ypos; +UGL_LOCAL int SkipPixels, SkipRows; +UGL_LOCAL int DrawWidth, DrawHeight; +UGL_LOCAL float Xzoom, Yzoom; +UGL_LOCAL GLboolean Scissor; +UGL_LOCAL GLboolean DrawFront; +UGL_LOCAL GLboolean Dither; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL void reset(void) + { + Xpos = Ypos = 20; + DrawWidth = ImgWidth; + DrawHeight = ImgHeight; + SkipPixels = SkipRows = 0; + Scissor = GL_FALSE; + Xzoom = Yzoom = 1.0; + } + +UGL_LOCAL void initGL(GLboolean ciMode, GLsizei width, GLsizei height) + { + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + + Image = LoadRGBImage(IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat); + if (!Image) + { + printf("Couldn't read %s\n", IMAGE_FILE); + cleanUp(); + exit(1); + } + + glScissor(width/4, height/4, width/2, height/2); + + if (ciMode) + { + /* Convert RGB image to grayscale */ + GLubyte *indexImage = malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i<ImgWidth*ImgHeight; i++) + { + int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; + indexImage[i] = gray / 3; + } + free(Image); + Image = indexImage; + ImgFormat = GL_COLOR_INDEX; + + for (i=0;i<255;i++) + { + float g = i / 255.0; + uglMesaSetColor(i, g, g, g); + } + } + + printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); + + reset(); + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + } + +UGL_LOCAL void drawGL(void) + { + glClear(GL_COLOR_BUFFER_BIT); + + /* This allows negative raster positions: */ + glRasterPos2i(0, 0); + glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL); + + 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); + + uglMesaSwapBuffers(); + } + + +UGL_LOCAL void benchmark( void ) + { + int startTick, endTick, ticksBySec; + int draws; + double seconds, pixelsPerSecond; + + printf("Benchmarking (4 sec)...\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); + + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + + /* Run timing test */ + draws = 0; + + ticksBySec = sysClkRateGet (); + startTick = tickGet(); + + do { + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + draws++; + endTick = tickGet (); + } while ((endTick - startTick)/ticksBySec < 4); /* 4 seconds */ + + /* GL clean-up */ + glDisable(GL_SCISSOR_TEST); + + /* Results */ + seconds = (endTick - startTick)/ticksBySec; + pixelsPerSecond = draws * DrawWidth * DrawHeight / seconds; + printf("Result: %d draws in %f seconds = %f pixels/sec\n", + draws, seconds, pixelsPerSecond); + } + +UGL_LOCAL void echoUse(void) + { + printf("Keys:\n"); + printf(" SPACE Reset Parameters\n"); + printf(" Up/Down Move image up/down\n"); + printf(" Left/Right Move image left/right\n"); + printf(" x Decrease X-axis PixelZoom\n"); + printf(" X Increase X-axis PixelZoom\n"); + printf(" y Decrease Y-axis PixelZoom\n"); + printf(" Y Increase Y-axis PixelZoom\n"); + printf(" w Decrease glDrawPixels width*\n"); + printf(" W Increase glDrawPixels width*\n"); + printf(" h Decrease glDrawPixels height*\n"); + printf(" H Increase glDrawPixels height*\n"); + printf(" p Decrease GL_UNPACK_SKIP_PIXELS*\n"); + printf(" P Increase GL_UNPACK_SKIP_PIXELS*\n"); + printf(" r Decrease GL_UNPACK_SKIP_ROWS*\n"); + printf(" R Increase GL_UNPACK_SKIP_ROWS*\n"); + printf(" s Toggle GL_SCISSOR_TEST\n"); + printf(" f Toggle front/back buffer drawing\n"); + printf(" d Toggle dithering\n"); + printf(" b Benchmark test\n"); + printf(" ESC Exit\n"); + printf("* Warning: no limits are imposed on these parameters so it's\n"); + printf(" possible to cause a segfault if you go too far.\n"); + } + + +UGL_LOCAL void readKey(UGL_WCHAR key) + { + switch (key) + { + case UGL_UNI_SPACE: + reset(); + break; + case 'd': + Dither = !Dither; + if (Dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); + 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 'f': + DrawFront = !DrawFront; + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); + break; + case UGL_UNI_UP_ARROW: + Ypos += 1; + break; + case UGL_UNI_DOWN_ARROW: + Ypos -= 1; + break; + case UGL_UNI_LEFT_ARROW: + Xpos -= 1; + break; + case UGL_UNI_RIGHT_ARROW: + Xpos += 1; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +UGL_LOCAL void cleanUp (void) + { + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + } + +void windMLDrawPix (UGL_BOOL windMLMode); + +void ugldrawpix (void) + { + taskSpawn ("tDrawPix", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLDrawPix, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLDrawPix (UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLuint ciMode; + GLsizei width, height; + + Image = NULL; + Scissor = GL_FALSE; + DrawFront = GL_FALSE; + Dither = GL_TRUE; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_COLOR_INDEXED, &ciMode); + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(ciMode, width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + cleanUp(); + free(Image); + + return; + } diff --git a/progs/windml/uglflip.c b/progs/windml/uglflip.c new file mode 100644 index 00000000000..0ca068f417d --- /dev/null +++ b/progs/windml/uglflip.c @@ -0,0 +1,224 @@ + +/* uglflip.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a triangle and flip the screen +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#define BLACK (0) +#define RED (1) +#define GREEN (2) +#define BLUE (3) +#define CI_OFFSET 4 + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL void initGL (void) + { + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(RED, 1.0, 0.3, 0.3); + uglMesaSetColor(GREEN, 0.3, 1.0, 0.3); + uglMesaSetColor(BLUE, 0.3, 0.3, 1.0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + } + +UGL_LOCAL void drawGL (void) + { + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED); + glVertex2f(0.75, -0.50); + (rgb) ? glColor3f(0.3, 1.0, 0.3) : glIndexi(GREEN); + glVertex2f(0.0, 0.75); + (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE); + glVertex2f(-0.75, -0.50); + glEnd(); + + glBegin(GL_LINES); + (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED); + glVertex2f(-1.0, 1.0); + (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE); + glVertex2f(1.0, -1.0); + glEnd(); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL void echoUse(void) + { + printf("tFlip keys:\n"); + printf(" d Toggle dithering\n"); + printf(" up Reduce the window\n"); + printf(" down Enlarge the window\n"); + printf(" page up Y==0 is the bottom line and increases upward\n"); + printf(" page down Y==0 is the bottom line and increases downward\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case UGL_UNI_UP_ARROW: + uglMesaResizeWindow(8, 8); + break; + case UGL_UNI_DOWN_ARROW: + glDrawBuffer(GL_FRONT_LEFT); + glClear(GL_COLOR_BUFFER_BIT); + glDrawBuffer(GL_BACK_LEFT); + uglMesaResizeWindow(-8, -8); + break; + case UGL_UNI_PAGE_UP: + uglMesaPixelStore(UGL_MESA_Y_UP, GL_TRUE); + break; + case UGL_UNI_PAGE_DOWN: + uglMesaPixelStore(UGL_MESA_Y_UP, GL_FALSE); + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + case 'd': + if (glIsEnabled(GL_DITHER)) + glDisable(GL_DITHER); + else + glEnable(GL_DITHER); + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + drawGL(); + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + { + readKey(pInputEvent->type.keyboard.key); + drawGL(); + } + } + + if (stopWex) + break; + } + } + +void windMLFlip (UGL_BOOL windMLMode); + +void uglflip (void) + { + taskSpawn ("tFlip", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLFlip, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLFlip (UGL_BOOL windMLMode) + { + + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_SINGLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE_SOFTWARE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglgears.c b/progs/windml/uglgears.c new file mode 100644 index 00000000000..468fe899806 --- /dev/null +++ b/progs/windml/uglgears.c @@ -0,0 +1,428 @@ + +/* uglgears.c - WindML/Mesa example program */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + * + * Conversion to GLUT by Mark J. Kilgard + * Conversion to UGL/Mesa from GLUT by Stephane Raimbault + */ + +/* +DESCRIPTION +Spinning gears demo +*/ + +#include <stdio.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define COUNT_FRAMES + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLfloat view_rotx, view_roty, view_rotz; +UGL_LOCAL GLint gear1, gear2, gear3; +UGL_LOCAL GLfloat angle; + +UGL_LOCAL GLuint limit; +UGL_LOCAL GLuint count; +UGL_LOCAL GLuint tickStart, tickStop, tickBySec; + + +/* +* 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 +*/ + +UGL_LOCAL 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; 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); + 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 (); + +} + +UGL_LOCAL void drawGL (void) + { +#ifdef COUNT_FRAMES + int time; +#endif + + angle += 2.0; + + 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 (); + + glFlush(); + + uglMesaSwapBuffers (); + +#ifdef COUNT_FRAMES + if (count > limit) + { + tickStop = tickGet (); + time = (tickStop-tickStart)/tickBySec; + printf (" %i fps\n", count/time); + tickStart = tickStop; + count = 0; + } + else + count++; +#endif +} + + +UGL_LOCAL void initGL (GLsizei width, GLsizei height) + { + UGL_LOCAL GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 }; + UGL_LOCAL GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 }; + UGL_LOCAL GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 }; + UGL_LOCAL 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); + + glViewport (0, 0, width, height); + + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (width>height) + { + 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); + +#ifdef COUNT_FRAMES + tickStart = tickGet (); + tickBySec = sysClkRateGet (); +#endif +} + +UGL_LOCAL void echoUse(void) + { + printf("tGears keys:\n"); + printf(" z Counter clockwise rotation (z-axis)\n"); + printf(" Z Clockwise rotation (z-axis)\n"); + printf(" Up Counter clockwise rotation (x-axis)\n"); + printf(" Down Clockwise rotation (x-axis)\n"); + printf(" Left Counter clockwise rotation (y-axis)\n"); + printf(" Right Clockwise rotation (y-axis)\n"); + printf(" ESC Exit\n"); + } + + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case UGL_UNI_UP_ARROW: + view_rotx += 5.0; + break; + case UGL_UNI_DOWN_ARROW: + view_rotx -= 5.0; + break; + case UGL_UNI_LEFT_ARROW: + view_roty += 5.0; + break; + case UGL_UNI_RIGHT_ARROW: + view_roty -= 5.0; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLGears (UGL_BOOL windMLMode); + +void uglgears (void) + { + taskSpawn ("tGears", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLGears, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLGears (UGL_BOOL windMLMode) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + view_rotx=20.0; + view_roty=30.0; + view_rotz=0.0; + angle = 0.0; + limit = 100; + count = 1; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext (umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL (width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/uglicotorus.c b/progs/windml/uglicotorus.c new file mode 100644 index 00000000000..c09b6d1b520 --- /dev/null +++ b/progs/windml/uglicotorus.c @@ -0,0 +1,315 @@ +/* uglicotorus.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +modification history +-------------------- +01a,jun01,sra +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +/* Need GLUT_SHAPES */ + +#include <GL/uglglutshapes.h> + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL GLfloat angle; +UGL_LOCAL GLboolean chaos_on; +UGL_LOCAL GLboolean color_on; + +UGL_LOCAL GLuint theIco, theTorus, theSphere, theCube; + +UGL_LOCAL void initGL + ( + int w, + int h + ) + { + glViewport(0,0,(GLsizei)w,(GLsizei)h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0,0.0,25.0,0.0,0.0,0.0,0.0,1.0,0.0); + + glClearColor(0.0,0.0,0.0,0.0); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glEnable(GL_COLOR_MATERIAL); + + theIco = glGenLists(1); + glNewList(theIco, GL_COMPILE); + glutSolidIcosahedron(); + glEndList(); + + theTorus = glGenLists(1); + glNewList(theTorus, GL_COMPILE); + glutSolidTorus(0.2,1.0,10,10); + glEndList(); + + theSphere = glGenLists(1); + glNewList(theSphere, GL_COMPILE); + glutSolidSphere(2.5,20,20); + glEndList(); + + theCube = glGenLists(1); + glNewList(theCube, GL_COMPILE); + glutSolidCube(4.0); + glEndList(); + + } + +UGL_LOCAL void createIcoToruses + ( + int i + ) + { + glPushMatrix(); + glRotatef(angle,1.0,1.0,1.0); + glCallList(theIco); + + switch (i) + { + case 9 : + glColor3f(1.0,0.0,0.0); + break; + case 0 : + glColor3f(1.0,0.1,0.7); + break; + case 1 : + glColor3f(1.0,0.0,1.0); + break; + case 2 : + glColor3f(0.0,0.0,1.0); + break; + case 3 : + glColor3f(0.0,0.5,1.0); + break; + case 4 : + glColor3f(0.0,1.0,0.7); + break; + case 5 : + glColor3f(0.0,1.0,0.0); + break; + case 6 : + glColor3f(0.5,1.0,0.0); + break; + case 7 : + glColor3f(1.0,1.0,0.0); + break; + case 8 : + glColor3f(1.0,0.5,0.0); + break; + } + + glRotatef(angle,1.0,1.0,1.0); + glCallList(theTorus); + glRotatef(-2*angle,1.0,1.0,1.0); + glCallList(theTorus); + glPopMatrix(); + } + +UGL_LOCAL void drawGL (void) + { + int i; + + if (color_on) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + else + glClear(GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + if (chaos_on) + glRotatef(angle,1.0,1.0,1.0); + + glPushMatrix(); + glRotatef(angle,1.0,1.0,1.0); + glColor3f(1.0,0.5,0.0); + glCallList(theSphere); + glColor3f(1.0,0.0,0.0); + glCallList(theCube); + glPopMatrix(); + + glRotatef(-angle,0.0,0.0,1.0); + glPushMatrix(); + /* draw ten icosahedrons */ + for (i = 0; i < 10; i++) + { + glPushMatrix(); + glRotatef(36*i,0.0,0.0,1.0); + glTranslatef(10.0,0.0,0.0); + glRotatef(2*angle,0.0,1.0,0.0); + glTranslatef(0.0,0.0,2.0); + + createIcoToruses(i); + glPopMatrix(); + } + glPopMatrix(); + + glPopMatrix(); + + uglMesaSwapBuffers(); + + angle += 1.0; + + } + +UGL_LOCAL void echoUse(void) + { + printf("tIcoTorus keys:\n"); + printf(" c Toggle color buffer clear\n"); + printf(" SPACE Toggle chaos mode\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case 'c': + color_on = !color_on; + break; + case UGL_UNI_SPACE: + chaos_on = !chaos_on; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLIcoTorus (UGL_BOOL windMLMode); + +void uglicotorus (void) + { + taskSpawn ("tIcoTorus", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLIcoTorus, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLIcoTorus (UGL_BOOL windMLMode) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + angle = 0.0; + chaos_on = GL_TRUE; + color_on = GL_TRUE; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + /* Double buffering */ + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL (width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext (); + uglDeinitialize (); + + return; + } + diff --git a/progs/windml/uglline.c b/progs/windml/uglline.c new file mode 100644 index 00000000000..e58f071ea4b --- /dev/null +++ b/progs/windml/uglline.c @@ -0,0 +1,274 @@ + +/* uglline.c - WindML/Mesa example program */ + +/* + * 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. + */ + +/* +modification history +-------------------- +01a,jun01,sra Ported to UGL/Mesa and modifications +*/ + +/* +DESCRIPTION +Draw circular lines +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#define BLACK (0) +#define YELLOW (1) +#define GREEN (2) +#define BLUE (3) +#define CI_OFFSET 4 + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLboolean mode1, mode2; +UGL_LOCAL GLint size; + +UGL_LOCAL GLfloat pntA[3] = { + -10.0, 0.0, 0.0 +}; +UGL_LOCAL GLfloat pntB[3] = { + -5.0, 0.0, 0.0 +}; + +UGL_LOCAL GLint angleA; + +UGL_LOCAL void initGL (void) + { + GLint i; + + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(YELLOW, 1.0, 1.0, 0.0); + uglMesaSetColor(GREEN, 0.0, 1.0, 0.0); + uglMesaSetColor(BLUE, 0.0, 0.0, 1.0); + + for (i = 0; i < 16; i++) + { + uglMesaSetColor(CI_OFFSET+i, i/15.0, i/15.0, 0.0); + } + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-10, 10, -10, 10, -10.0, 10.0); + + glMatrixMode(GL_MODELVIEW); + + glLineStipple(1, 0xF0E0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + mode1 = GL_FALSE; + mode2 = GL_FALSE; + size = 1; + } + +UGL_LOCAL void drawGL (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 = YELLOW; + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glPushMatrix(); + + glRotatef(angleA, 1, 0, 1); + angleA = angleA++ % 360; + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0, 0, 1); + + glColor3f(1.0, 1.0, 0.0); + glBegin(GL_LINE_STRIP); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glPointSize(1); + + glColor3f(0.0, 1.0, 0.0); + glBegin(GL_POINTS); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + } + + glPopMatrix(); + + glFlush(); + + uglMesaSwapBuffers(); + + } + +UGL_LOCAL void echoUse(void) + { + printf("tLine keys:\n"); + printf(" b Blending/antialiasing\n"); + printf(" n Line stipple\n"); + printf(" Up/Down Pixel size\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case 'n': + mode1 = (mode1) ? GL_FALSE: GL_TRUE; + break; + case 'b': + mode2 = (mode2) ? GL_FALSE: GL_TRUE; + break; + case UGL_UNI_DOWN_ARROW: + if(size>0) + size--; + break; + case UGL_UNI_UP_ARROW: + size++; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLLine (UGL_BOOL windMLMode); + +void uglline (void) + { + taskSpawn("tLine", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLLine, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + + +void windMLLine(UGL_BOOL windMLMode) + { + + UGL_INPUT_DEVICE_ID keyboardDevId; + + angleA = 0; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffer */ + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy(eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglolympic.c b/progs/windml/uglolympic.c new file mode 100644 index 00000000000..282558dacbd --- /dev/null +++ b/progs/windml/uglolympic.c @@ -0,0 +1,479 @@ +/* + * 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 Stephane Raimbault to be able to run in VxWorks 07/18/01 + * + * Modified by Li Wei([email protected]) to be able to run in Windows + * 6/13 + * + * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#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 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL int rgb; +UGL_LOCAL unsigned char rgb_colors[RINGS][3]; +UGL_LOCAL int mapped_colors[RINGS]; +UGL_LOCAL float dests[RINGS][3]; +UGL_LOCAL float offsets[RINGS][3]; +UGL_LOCAL float angs[RINGS]; +UGL_LOCAL float rotAxis[RINGS][3]; +UGL_LOCAL int iters[RINGS]; +UGL_LOCAL GLuint theTorus; + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +/* +UGL_LOCAL 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} +}; + +UGL_LOCAL void SetColor(int c) + { + (rgb) ? glColor3fv(RGBMap[c]): glIndexf(c); + } + +UGL_LOCAL void InitMap(void) + { + int i; + + if (rgb) + return; + + for (i = 0; i < 9; i++) + uglMesaSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]); + } + +UGL_LOCAL 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; + uglMesaSetColor(k, intensity, intensity, intensity); + } + } + } + +UGL_LOCAL void SetGreyRamp(void) + { + int i; + float intensity; + + for (i = 0; i < 255; i++) + { + intensity = i / 255.0; + uglMesaSetColor(i, intensity, intensity, intensity); + } + } +*/ + +UGL_LOCAL 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(); + } + } + +UGL_LOCAL float Clamp(int iters_left, float t) + { + if (iters_left < 3) + { + return 0.0; + } + return (iters_left-2)*t/iters_left; + } + +UGL_LOCAL void drawGL(void) + { + int i, j; + + 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]--; + } + } + + 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(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL float MyRand(void) + { + return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 ); + } + +UGL_LOCAL 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); + } + } + +UGL_LOCAL void initGL(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}; + + 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); + } + +UGL_LOCAL void echoUse(void) + { + printf("tOlympic keys:\n"); + printf(" SPACE Reinitialize\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case UGL_UNI_SPACE: + ReInit(); + break; + case UGL_UNI_ESCAPE: + stopWex = 1; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLOlympic (UGL_BOOL windMLMode); + +void uglolympic (void) + { + taskSpawn("tOlympic", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLOlympic, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLOlympic(UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + + stopWex = 0; + loopEvent(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglpoint.c b/progs/windml/uglpoint.c new file mode 100644 index 00000000000..49c432c3a41 --- /dev/null +++ b/progs/windml/uglpoint.c @@ -0,0 +1,277 @@ + +/* uglpoint.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a single point. +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> + +#define DOUBLE_BUFFER GL_TRUE + +enum { + BLACK = 0, + RED, + GREEN, + BLUE, + WHITE +}; + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL GLint angleT; + +UGL_LOCAL void initGL (void) + { + /* By passed in RGB mode */ + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(RED, 1.0, 0.0, 0.0); + uglMesaSetColor(GREEN, 0.0, 1.0, 0.0); + uglMesaSetColor(BLUE, 0.0, 0.0, 1.0); + uglMesaSetColor(WHITE, 1.0, 1.0, 1.0); + + glOrtho(0.0, 1.0, 0.0, 1.0, -20.0, 20.0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + } + +UGL_LOCAL void drawGL (void) + { + GLint i; + GLfloat x, y; + + /* Avoid blinking in single buffer */ + + if (DOUBLE_BUFFER) + glClear(GL_COLOR_BUFFER_BIT); + + /* Random points */ + + glBegin(GL_POINTS); + (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED); + + for (i=0; i<150; i++) + { + x = rand() / (RAND_MAX+1.0); + y = rand() / (RAND_MAX+1.0); + glVertex2f(x, y); + } + + (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN); + + for (i=0; i<150; i++) + { + x = (rand() / (RAND_MAX+1.0)); + y = (rand() / (RAND_MAX+1.0)); + glVertex2f(x, y); + } + + (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE); + glVertex2f(0.5,0.5); + + for (i=0; i<150; i++) + { + x = rand() / (RAND_MAX+1.0); + y = rand() / (RAND_MAX+1.0); + glVertex2f(x, y); + } + + glEnd(); + + /* Smooth triangle */ + + glPushMatrix(); + glTranslatef(0.5, 0.5, 0); + glRotatef(angleT, 1.0, -1.0, 0.0); + angleT = angleT++ % 360; + glBegin(GL_TRIANGLES); + (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED); + glVertex2f(0.75, 0.25); + (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN); + glVertex2f(0.75, 0.75); + (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE); + glVertex2f(0.25, 0.75); + glEnd(); + glPopMatrix(); + + /* Flush and swap */ + + glFlush(); + + uglMesaSwapBuffers(); + } + +/************************************************************************ +* +* getEvent +* +* RETURNS: true or false +* +* NOMANUAL +* +*/ + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLPoint (UGL_BOOL windMLMode); + +void uglpoint (void) + { + taskSpawn ("tPoint", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLPoint, UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLPoint (UGL_BOOL windMLMode) + { + GLubyte pPixels[4]; + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + angleT = 0; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + if (DOUBLE_BUFFER) + { + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + } + else + { + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_SINGLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_SINGLE, NULL); + } + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + /* RGB or CI ? */ + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + while (!getEvent()) + drawGL(); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + printf ("glReadPixel return "); + if (rgb) + { + glReadPixels(width/2, height/2, + 1, 1, GL_RGB, + GL_UNSIGNED_BYTE, pPixels); + glFlush(); + printf ("R:%i G:%i B:%i (RGB)", pPixels[0], pPixels[1], pPixels[2]); + } + else + { + glReadPixels(width/2, height/2, + 1, 1, GL_COLOR_INDEX, + GL_UNSIGNED_BYTE, pPixels); + glFlush(); + if (pPixels[0] == BLUE) + printf ("BLUE (CI)"); + else + printf ("%i (CI))", pPixels[0]); + } + + printf(" for %ix%i\n", width/2, height/2); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglstencil.c b/progs/windml/uglstencil.c new file mode 100644 index 00000000000..07e8fc626f3 --- /dev/null +++ b/progs/windml/uglstencil.c @@ -0,0 +1,242 @@ + +/* 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. + */ + +/* + * Conversion to UGL/Mesa by Stephane Raimbault, 2001 + */ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> +#include <GL/uglglutshapes.h> + +#define YELLOWMAT 1 +#define BLUEMAT 2 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL void initGL (GLsizei w, GLsizei h) + { + 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); + + 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); + } + +/* Draw a sphere in a diamond-shaped section in the + * middle of a window with 2 tori. + */ +UGL_LOCAL void drawGL(void) + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); + +/* 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); + 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(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLStencil (UGL_BOOL windMLMode); + +void uglstencil (void) + { + taskSpawn("tStencil", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLStencil,UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLStencil(UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei width, height; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + if (windMLMode) + umc = uglMesaCreateNewContextExt(UGL_MESA_SINGLE + | UGL_MESA_WINDML_EXCLUSIVE, + 16, + 8, + 0,0,0,0, + NULL); + else + umc = uglMesaCreateNewContextExt(UGL_MESA_SINGLE, + 16, + 8, + 0,0,0,0, + NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + drawGL(); + + while (!getEvent()); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } + diff --git a/progs/windml/uglteapot.c b/progs/windml/uglteapot.c new file mode 100644 index 00000000000..651fe0990e1 --- /dev/null +++ b/progs/windml/uglteapot.c @@ -0,0 +1,295 @@ +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Linux Magazine July 2001 + * Conversion to UGL/Mesa from GLUT by Stephane Raimbault, 2001 + */ + +#include <stdlib.h> +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +/* Need GLUT_SHAPES */ + +#include <GL/uglglutshapes.h> + +#ifndef PI +#define PI 3.14159265 +#endif + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL GLint angle; +UGL_LOCAL GLfloat Sin[360], Cos[360]; +UGL_LOCAL GLfloat L0pos[]={0.0, 2.0, -1.0}; +UGL_LOCAL GLfloat L0dif[]={0.3, 0.3, 0.8}; +UGL_LOCAL GLfloat L1pos[]={2.0, 2.0, 2.0}; +UGL_LOCAL GLfloat L1dif[]={0.5, 0.5, 0.5}; +UGL_LOCAL GLfloat Mspec[3]; +UGL_LOCAL GLfloat Mshiny; +UGL_LOCAL GLuint theTeapot; + +UGL_LOCAL void calcTableCosSin() +{ + int i; + for(i=0;i<360;i++) { + Cos[i] = cos(((float)i)/180.0*PI); + Sin[i] = sin(((float)i)/180.0*PI); + } +} + +UGL_LOCAL void initGL(void) + { + glClearColor(0.0, 0.0, 0.0, 0.0); + glColor3f(1.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + + glShadeModel(GL_SMOOTH); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + glLightfv(GL_LIGHT0, GL_DIFFUSE, L0dif); + glLightfv(GL_LIGHT0, GL_SPECULAR, L0dif); + glLightfv(GL_LIGHT1, GL_DIFFUSE, L1dif); + glLightfv(GL_LIGHT1, GL_SPECULAR, L1dif); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, 1.0, 0.1, 10.0); + glMatrixMode(GL_MODELVIEW); + + theTeapot = glGenLists(1); + glNewList(theTeapot, GL_COMPILE); + glutSolidTeapot(1.0); + glEndList(); + + } + +UGL_LOCAL void drawGL() + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLoadIdentity(); + + gluLookAt(4.5*Cos[angle], 2.0,4.5*Sin[angle],0.0,0.0,0.0,0.0, + 1.0,0.0); + glLightfv(GL_LIGHT0, GL_POSITION, L0pos); + glLightfv(GL_LIGHT1, GL_POSITION, L1pos); + + glCallList(theTeapot); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL void echoUse(void) + { + printf("tTeapot keys:\n"); + printf(" Left Counter clockwise rotation (y-axis)\n"); + printf(" Right Clockwise rotation (y-axis)\n"); + printf(" j Enable/disable Light0\n"); + printf(" k Enable/disable Light1\n"); + printf(" m Add specular\n"); + printf(" l Remove specular\n"); + printf(" o Add shininess\n"); + printf(" p Remove shininess\n"); + printf(" ESC Exit\n"); + } + + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case UGL_UNI_RIGHT_ARROW: + angle +=2; + if (angle>= 360) + angle-=360; + break; + case UGL_UNI_LEFT_ARROW: + angle -=2; + if (angle<0) + angle+=360; + break; + case 'j': + glIsEnabled(GL_LIGHT0) ? + glDisable(GL_LIGHT0) : glEnable(GL_LIGHT0); + break; + case 'k': + glIsEnabled(GL_LIGHT1) ? + glDisable(GL_LIGHT1) : glEnable(GL_LIGHT1); + break; + case 'm': + Mspec[0]+=0.1; + if(Mspec[0]>1) + Mspec[0]=1; + Mspec[1]+=0.1; + if(Mspec[1]>1) + Mspec[1]=1; + Mspec[2]+=0.1; + if(Mspec[2]>1) + Mspec[2]=1; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + break; + case 'l': + Mspec[0]-=0.1; + if(Mspec[0]>1) + Mspec[0]=1; + Mspec[1]-=0.1; + if(Mspec[1]>1) + Mspec[1]=1; + Mspec[2]-=0.1; + if(Mspec[2]>1) + Mspec[2]=1; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + break; + case 'o': + Mshiny -= 1; + if (Mshiny<0) + Mshiny=0; + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + break; + case 'p': + Mshiny += 1; + if (Mshiny>128) + Mshiny=128; + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLTeapot (UGL_BOOL windMLMode); + +void uglteapot (void) + { + taskSpawn ("tTeapot", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTeapot, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLTeapot (UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei displayWidth, displayHeight; + GLsizei x, y, w, h; + + angle = 45; + Mspec[0] = 0.5; + Mspec[1] = 0.5; + Mspec[2] = 0.5; + Mshiny = 50; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, 1, 1); + + uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH, &displayWidth); + uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT, &displayHeight); + + h = (displayHeight*2)/3; + w = h; + x = (displayWidth-w)/2; + y = (displayHeight-h)/2; + + uglMesaMoveToWindow(x, y); + uglMesaResizeToWindow(w, h); + + calcTableCosSin(); + + initGL (); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/ugltexcube.c b/progs/windml/ugltexcube.c new file mode 100644 index 00000000000..62b0306e647 --- /dev/null +++ b/progs/windml/ugltexcube.c @@ -0,0 +1,379 @@ + +/* ugltexcube.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a textured cube +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#include "../util/readtex.h" + +#define IMAGE_FILE "Mesa/images/wrs_logo.rgb" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLfloat xrot, yrot, zrot; +UGL_LOCAL GLuint texture[1]; +UGL_LOCAL GLuint theTexCube; + +typedef struct { + GLubyte *data; + int width, height; + GLenum format; + } TEX_IMAGE; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL void loadGLTexture() + { + TEX_IMAGE * texImage=NULL; + + texImage = (TEX_IMAGE *) malloc(sizeof(TEX_IMAGE)); + + if (texImage == NULL) + { + printf("Error allocating space for image"); + cleanUp(); + exit(1); + } + + texImage->data = LoadRGBImage(IMAGE_FILE, &texImage->width, + &texImage->height, &texImage->format); + if (!texImage->data) + { + printf("Couldn't read %s\n", IMAGE_FILE); + free(texImage); + cleanUp(); + exit(1); + } + + /* Create Texture */ + glGenTextures(1, &texture[0]); + glBindTexture(GL_TEXTURE_2D, texture[0]); + glTexImage2D(GL_TEXTURE_2D, 0, 3, + texImage->width, texImage->height, + 0, GL_RGB, GL_UNSIGNED_BYTE, texImage->data); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + free(texImage->data); + free(texImage); + } + +UGL_LOCAL void initGL(int width, int height) + { + + /* Load the texture(s) */ + loadGLTexture(); + + /* Enable texture mapping */ + glEnable(GL_TEXTURE_2D); + + /* Clear the background color to black */ + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + glEnable(GL_CULL_FACE); + + /* Enables smooth color shading */ + glShadeModel(GL_SMOOTH); + +/* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); */ +/* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); */ + + theTexCube = glGenLists(1); + glNewList(theTexCube, GL_COMPILE); + + /* Choose the texture to use */ + glBindTexture(GL_TEXTURE_2D, texture[0]); + + /* Begin drawing a cube */ + glBegin(GL_QUADS); + + /* Front face (note that the texture's corners have to match the + quad's corners) */ + + /* Bottom left of the texture and quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Back Face */ + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + + /* Top Face */ + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Bottom Face */ + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + + /* Right face */ + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + + /* Left Face */ + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + glEnd(); /* done with the polygon */ + glEndList(); + + glDisable(GL_DITHER); + glMatrixMode(GL_PROJECTION); + /* Reset the projection matrix */ + glLoadIdentity(); + /* Calculate the aspect ratio of the window */ + gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + } + +UGL_LOCAL void drawGL() + { + glClear(GL_COLOR_BUFFER_BIT); + + /* Reset The View */ + glPushMatrix(); + + /* Move 8 units into the screen */ + glTranslatef(0.0f, 0.0f, -8.0f); + + /* Rotate on the X axis */ + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + + /* Rotate on the Y axis */ + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + + /* Rotate On The Z Axis */ + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + glCallList(theTexCube); + + glFlush(); + + uglMesaSwapBuffers(); + + glPopMatrix(); + + xrot += 1.6f; + yrot += 1.6f; + zrot += 1.6f; +} + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +UGL_LOCAL void cleanUp (void) + { + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + } + +void windMLTexCube (UGL_BOOL windMLMode); + +void ugltexcube (void) + { + taskSpawn("tTexCube", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTexCube, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + + +void windMLTexCube(UGL_BOOL windMLMode) + { + GLuint width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, + UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + while(!getEvent()) + drawGL(); + + cleanUp(); + + return; + } + + diff --git a/progs/windml/ugltexcyl.c b/progs/windml/ugltexcyl.c new file mode 100644 index 00000000000..d2fe687b926 --- /dev/null +++ b/progs/windml/ugltexcyl.c @@ -0,0 +1,407 @@ +/* + * Textured cylinder demo: lighting, texturing, reflection mapping. + * + * Brian Paul May 1997 This program is in the public domain. + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +/* + * $Log: ugltexcyl.c,v $ + * Revision 1.2 2001/09/10 19:21:13 brianp + * WindML updates (Stephane Raimbault) + * + * Revision 1.1 2001/08/20 16:07:11 brianp + * WindML driver (Stephane Raimbault) + * + * Revision 1.5 2001/03/27 17:35:26 brianp + * set initial window pos + * + * Revision 1.4 2000/12/24 22:53:54 pesco + * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util. + * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus: + * Essentially the same. + * Program files updated to include "readtex.c", not "../util/readtex.c". + * * demos/reflect.c: Likewise for "showbuffer.c". + * + * + * * Makefile.am (EXTRA_DIST): Added top-level regular files. + * + * * include/GL/Makefile.am (INC_X11): Added glxext.h. + * + * + * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include + * Mesa GGI headers in dist even if HAVE_GGI is not given. + * + * * configure.in: Look for GLUT and demo source dirs in $srcdir. + * + * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch]. + * More source list updates in various Makefile.am's. + * + * * Makefile.am (dist-hook): Remove CVS directory from distribution. + * (DIST_SUBDIRS): List all possible subdirs here. + * (SUBDIRS): Only list subdirs selected for build again. + * The above two applied to all subdir Makefile.am's also. + * + * Revision 1.3 2000/09/29 23:09:39 brianp + * added fps output + * + * Revision 1.2 1999/10/21 16:39:06 brianp + * added -info command line option + * + * Revision 1.1.1.1 1999/08/19 00:55:40 jtg + * Imported sources + * + * Revision 3.3 1999/03/28 18:24:37 brianp + * minor clean-up + * + * Revision 3.2 1998/11/05 04:34:04 brianp + * moved image files to ../images/ directory + * + * Revision 3.1 1998/06/23 03:16:51 brianp + * added Point/Linear sampling menu items + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#include "../util/readtex.h" + +#define TEXTURE_FILE "Mesa/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 +#define COUNT_FRAMES + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLuint CylinderObj; +UGL_LOCAL GLboolean Animate; +UGL_LOCAL GLboolean linearFilter; + +UGL_LOCAL GLfloat Xrot, Yrot, Zrot; +UGL_LOCAL GLfloat DXrot, DYrot; + +UGL_LOCAL GLuint limit; +UGL_LOCAL GLuint count; +UGL_LOCAL GLuint tickStart, tickStop, tickBySec; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL void drawGL(void) + { +#ifdef COUNT_FRAMES + int time; +#endif + + 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(); + + uglMesaSwapBuffers(); + + if (Animate) + { + Xrot += DXrot; + Yrot += DYrot; + } + +#ifdef COUNT_FRAMES + if (count > limit) + { + tickStop = tickGet (); + time = (tickStop-tickStart)/tickBySec; + printf (" %i fps\n", count/time); + tickStart = tickStop; + count = 0; + } + else + count++; +#endif + + } + +UGL_LOCAL void echoUse(void) + { + printf("Keys:\n"); + printf(" Up/Down Rotate on Y\n"); + printf(" Left/Right Rotate on X\n"); + printf(" a Toggle animation\n"); + printf(" f Toggle point/linear filtered\n"); + printf(" l Lit\n"); + printf(" t Textured\n"); + printf(" r Reflect\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey(UGL_WCHAR key) + { + float step = 3.0; + switch (key) + { + case 'a': + Animate = !Animate; + break; + case 'f': + if(linearFilter) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_LINEAR); + } + linearFilter = !linearFilter; + break; + case 'l': + glEnable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + break; + case 't': + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + break; + case 'r': + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + break; + case UGL_UNI_UP_ARROW: + Xrot += step; + break; + case UGL_UNI_DOWN_ARROW: + Xrot -= step; + break; + case UGL_UNI_LEFT_ARROW: + Yrot += step; + break; + case UGL_UNI_RIGHT_ARROW: + Yrot -= step; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +UGL_LOCAL void initGL(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"); + cleanUp(); + exit(1); + } + + glEnable(GL_CULL_FACE); /* don't need Z testing for convex objects */ + + glEnable(GL_LIGHTING); + + 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 ); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + +#ifdef COUNT_FRAMES + tickStart = tickGet (); + tickBySec = sysClkRateGet (); +#endif + + } + +UGL_LOCAL void cleanUp (void) + { + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + } + +void windMLTexCyl (UGL_BOOL windMLMode); + +void ugltexcyl (void) + { + taskSpawn ("tTexCyl", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTexCyl, + UGL_FALSE,1,2,3,4,5,6,7,8,9); + } + +void windMLTexCyl (UGL_BOOL windMLMode) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei displayWidth, displayHeight; + GLsizei x, y, w, h; + + CylinderObj = 0; + Animate = GL_TRUE; + linearFilter = GL_FALSE; + Xrot = 0.0; + Yrot = 0.0; + Zrot = 0.0; + DXrot = 1.0; + DYrot = 2.5; + limit = 100; + count = 1; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + if (windMLMode) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE + | UGL_MESA_WINDML_EXCLUSIVE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, 1, 1); + + uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH, &displayWidth); + uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT, &displayHeight); + + h = (displayHeight*3)/4; + w = h; + x = (displayWidth-w)/2; + y = (displayHeight-h)/2; + + uglMesaMoveToWindow(x, y); + uglMesaResizeToWindow(w, h); + + initGL (); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + cleanUp(); + + return; + } + diff --git a/progs/windml/wrs_logo.bmp b/progs/windml/wrs_logo.bmp Binary files differnew file mode 100644 index 00000000000..9a9f04255be --- /dev/null +++ b/progs/windml/wrs_logo.bmp diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile new file mode 100644 index 00000000000..4ca8b107a24 --- /dev/null +++ b/progs/xdemos/Makefile @@ -0,0 +1,83 @@ +# progs/xdemos/Makefile + +TOP = ../.. +include $(TOP)/configs/current + + +INCDIR = $(TOP)/include + +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) + +PROGS = glthreads \ + glxdemo \ + glxgears \ + glxgears_fbconfig \ + glxcontexts \ + glxheads \ + glxinfo \ + glxpixmap \ + glxpbdemo \ + glxswapcontrol \ + manywin \ + offset \ + overlay \ + pbinfo \ + pbdemo \ + wincopy \ + xdemo \ + xfont \ + xrotfontdemo \ + yuvrect_client + + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: $(LIB_DEP) + $(CC) -I$(INCDIR) $(CFLAGS) $< $(APP_LIB_DEPS) -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + + +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + + +# special cases +pbinfo: pbinfo.o pbutil.o + $(CC) -I$(INCDIR) $(CFLAGS) pbinfo.o pbutil.o $(APP_LIB_DEPS) -o $@ + +pbdemo: pbdemo.o pbutil.o + $(CC) -I$(INCDIR) $(CFLAGS) pbdemo.o pbutil.o $(APP_LIB_DEPS) -o $@ + +pbinfo.o: pbinfo.c pbutil.h + $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbinfo.c + +pbdemo.o: pbdemo.c pbutil.h + $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbdemo.c + +pbutil.o: pbutil.c pbutil.h + $(CC) -c -I. -I$(INCDIR) $(CFLAGS) pbutil.c + +glxgears_fbconfig: glxgears_fbconfig.o pbutil.o + $(CC) -I$(INCDIR) $(CFLAGS) glxgears_fbconfig.o pbutil.o $(APP_LIB_DEPS) -o $@ + +glxgears_fbconfig.o: glxgears_fbconfig.c pbutil.h + $(CC) -I$(INCDIR) $(CFLAGS) -c -I. $(CFLAGS) glxgears_fbconfig.c + +xrotfontdemo: xrotfontdemo.o xuserotfont.o + $(CC) -I$(INCDIR) $(CFLAGS) xrotfontdemo.o xuserotfont.o $(APP_LIB_DEPS) -o $@ + +xuserotfont.o: xuserotfont.c xuserotfont.h + $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xuserotfont.c + +xrotfontdemo.o: xrotfontdemo.c xuserotfont.h + $(CC) -c -I. -I$(INCDIR) $(CFLAGS) xrotfontdemo.c + diff --git a/progs/xdemos/descrip.mms b/progs/xdemos/descrip.mms new file mode 100644 index 00000000000..aa74daff599 --- /dev/null +++ b/progs/xdemos/descrip.mms @@ -0,0 +1,83 @@ +# Makefile for GLUT-based demo programs for VMS +# contributed by Jouk Jansen [email protected] + + +.first + define gl [--.include.gl] + +.include [--]mms-config. + +##### MACROS ##### + +INCDIR = ([--.include],[-.util]) +CFLAGS = /include=$(INCDIR)/prefix=all/name=(as_is,short)/nowarn/float=ieee/ieee=denorm + +.ifdef SHARE +GL_LIBS = $(XLIBS) +.else +GL_LIBS = [--.lib]libGLUT/l,libMesaGLU/l,libMesaGL/l,$(XLIBS) +.endif + +LIB_DEP = [--.lib]$(GL_LIB) [--.lib]$(GLU_LIB) [--.lib]$(GLUT_LIB) + +PROGS =glthreads.exe,\ + glxdemo.exe,\ + glxgears.exe,\ + glxheads.exe,\ + glxinfo.exe,\ + glxpixmap.exe,\ + manywin.exe,\ + offset.exe,\ + pbinfo.exe,\ + pbdemo.exe,\ + wincopy.exe,\ + xdemo.exe,\ + xfont.exe + +##### RULES ##### +.obj.exe : + cxxlink $(MMS$TARGET_NAME),$(GL_LIBS) + +##### TARGETS ##### +default : + $(MMS)$(MMSQUALIFIERS) $(PROGS) + +clean : + delete *.obj;* + +realclean : + delete $(PROGS) + delete *.obj;* + + +glthreads.exe : glthreads.obj $(LIB_DEP) +glxdemo.exe : glxdemo.obj $(LIB_DEP) +glxgears.exe : glxgears.obj $(LIB_DEP) +glxheads.exe : glxheads.obj $(LIB_DEP) +glxinfo.exe : glxinfo.obj $(LIB_DEP) +glxpixmap.exe : glxpixmap.obj $(LIB_DEP) +manywin.exe : manywin.obj $(LIB_DEP) +offset.exe : offset.obj $(LIB_DEP) +pbinfo.exe : pbinfo.obj pbutil.obj $(LIB_DEP) + cxxlink pbinfo.obj,pbutil.obj,$(GL_LIBS) +pbdemo.exe : pbdemo.obj pbutil.obj $(LIB_DEP) + cxxlink pbdemo.obj,pbutil.obj,$(GL_LIBS) +wincopy.exe : wincopy.obj $(LIB_DEP) +xdemo.exe : xdemo.obj $(LIB_DEP) +xfont.exe :xfont.obj $(LIB_DEP) + + +glthreads.obj : glthreads.c +glxdemo.obj : glxdemo.c +glxgears.obj : glxgears.c +glxheads.obj : glxheads.c +glxinfo.obj : glxinfo.c +glxpixmap.obj : glxpixmap.c +manywin.obj : manywin.c +offset.obj : offset.c +pbinfo.obj : pbinfo.c +pbutil.obj : pbutil.c +pbdemo.obj : pbdemo.c +wincopy.obj : wincopy.c +xdemo.obj : xdemo.c +xfont.obj :xfont.c diff --git a/progs/xdemos/glthreads.c b/progs/xdemos/glthreads.c new file mode 100644 index 00000000000..83413383dd4 --- /dev/null +++ b/progs/xdemos/glthreads.c @@ -0,0 +1,544 @@ +/* + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * This program tests GLX thread safety. + * Command line options: + * -p Open a display connection for each thread + * -n <num threads> Number of threads to create (default is 2) + * -display <display name> Specify X display (default is :0.0) + * + * Brian Paul 20 July 2000 + */ + + +#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */ + +#include <assert.h> +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <pthread.h> + + +/* + * Each window/thread/context: + */ +struct winthread { + Display *Dpy; + int Index; + pthread_t Thread; + Window Win; + GLXContext Context; + float Angle; + int WinWidth, WinHeight; + GLboolean NewSize; +}; + + +#define MAX_WINTHREADS 100 +static struct winthread WinThreads[MAX_WINTHREADS]; +static int NumWinThreads = 0; +static volatile GLboolean ExitFlag = GL_FALSE; + +static GLboolean MultiDisplays = 0; +static GLboolean Locking = 0; + +static pthread_mutex_t Mutex; + + +static void +Error(const char *msg) +{ + fprintf(stderr, "Error: %s\n", msg); + exit(1); +} + + +/* draw a colored cube */ +static void +draw_object(void) +{ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + glBegin(GL_POLYGON); + glVertex3f(1, -1, -1); + glVertex3f(1, 1, -1); + glVertex3f(1, 1, 1); + glVertex3f(1, -1, 1); + glEnd(); + + glColor3f(0, 1, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f(-1, 1, -1); + glVertex3f(-1, 1, 1); + glVertex3f(-1, -1, 1); + glEnd(); + + glColor3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, 1, -1); + glVertex3f( 1, 1, -1); + glVertex3f( 1, 1, 1); + glVertex3f(-1, 1, 1); + glEnd(); + + glColor3f(1, 0, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f( 1, -1, -1); + glVertex3f( 1, -1, 1); + glVertex3f(-1, -1, 1); + glEnd(); + + glColor3f(0, 0, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 1); + glVertex3f( 1, -1, 1); + glVertex3f( 1, 1, 1); + glVertex3f(-1, 1, 1); + glEnd(); + + glColor3f(1, 1, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f( 1, -1, -1); + glVertex3f( 1, 1, -1); + glVertex3f(-1, 1, -1); + glEnd(); + glPopMatrix(); +} + + +/* signal resize of given window */ +static void +resize(struct winthread *wt, int w, int h) +{ + wt->NewSize = GL_TRUE; + wt->WinWidth = w; + wt->WinHeight = h; +} + + +/* + * We have an instance of this for each thread. + */ +static void +draw_loop(struct winthread *wt) +{ + GLboolean firstIter = GL_TRUE; + + while (!ExitFlag) { + + if (Locking) + pthread_mutex_lock(&Mutex); + + glXMakeCurrent(wt->Dpy, wt->Win, wt->Context); + if (firstIter) { + printf("glthreads: %d: GL_RENDERER = %s\n", wt->Index, + (char *) glGetString(GL_RENDERER)); + firstIter = GL_FALSE; + } + + if (Locking) + pthread_mutex_unlock(&Mutex); + + glEnable(GL_DEPTH_TEST); + + if (wt->NewSize) { + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; + glViewport(0, 0, wt->WinWidth, wt->WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-w, w, -1.0, 1.0, 1.5, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2.5); + wt->NewSize = GL_FALSE; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(wt->Angle, 0, 0, 1); + glRotatef(wt->Angle, 1, 0, 0); + glScalef(0.7, 0.7, 0.7); + draw_object(); + glPopMatrix(); + + if (Locking) + pthread_mutex_lock(&Mutex); + + glXSwapBuffers(wt->Dpy, wt->Win); + + if (Locking) + pthread_mutex_unlock(&Mutex); + + usleep(5000); + wt->Angle += 1.0; + } +} + + +/* + * The main process thread runs this loop. + * Single display connection for all threads. + */ +static void +event_loop(Display *dpy) +{ + XEvent event; + int i; + + assert(!MultiDisplays); + + while (!ExitFlag) { + + if (Locking) { + while (1) { + int k; + pthread_mutex_lock(&Mutex); + k = XPending(dpy); + if (k) { + XNextEvent(dpy, &event); + pthread_mutex_unlock(&Mutex); + break; + } + pthread_mutex_unlock(&Mutex); + usleep(5000); + } + } + else { + XNextEvent(dpy, &event); + } + + switch (event.type) { + case ConfigureNotify: + /* Find winthread for this event's window */ + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + if (event.xconfigure.window == wt->Win) { + resize(wt, event.xconfigure.width, + event.xconfigure.height); + break; + } + } + break; + case KeyPress: + /* tell all threads to exit */ + ExitFlag = GL_TRUE; + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + default: + /*no-op*/ ; + } + } +} + + +/* + * Separate display connection for each thread. + */ +static void +event_loop_multi(void) +{ + XEvent event; + int w = 0; + + assert(MultiDisplays); + + while (!ExitFlag) { + struct winthread *wt = &WinThreads[w]; + if (XPending(wt->Dpy)) { + XNextEvent(wt->Dpy, &event); + switch (event.type) { + case ConfigureNotify: + resize(wt, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + /* tell all threads to exit */ + ExitFlag = GL_TRUE; + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + default: + /*no-op*/ ; + } + } + w = (w + 1) % NumWinThreads; + usleep(5000); + } +} + + + +/* + * we'll call this once for each thread, before the threads are created. + */ +static void +create_window(struct winthread *wt) +{ + Window win; + GLXContext ctx; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo; + int width = 80, height = 80; + int xpos = (wt->Index % 10) * 90; + int ypos = (wt->Index / 10) * 100; + + scrnum = DefaultScreen(wt->Dpy); + root = RootWindow(wt->Dpy, scrnum); + + visinfo = glXChooseVisual(wt->Dpy, scrnum, attrib); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error("Couldn't create window"); + } + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(wt->Dpy, win, &sizehints); + XSetStandardProperties(wt->Dpy, win, "glthreads", "glthreads", + None, (char **)NULL, 0, &sizehints); + } + + + ctx = glXCreateContext(wt->Dpy, visinfo, NULL, True); + if (!ctx) { + Error("Couldn't create GLX context"); + } + + XMapWindow(wt->Dpy, win); + XSync(wt->Dpy, 0); + + /* save the info for this window/context */ + wt->Win = win; + wt->Context = ctx; + wt->Angle = 0.0; + wt->WinWidth = width; + wt->WinHeight = height; + wt->NewSize = GL_TRUE; +} + + +/* + * Called by pthread_create() + */ +static void * +thread_function(void *p) +{ + struct winthread *wt = (struct winthread *) p; + draw_loop(wt); + return NULL; +} + + +/* + * called before exit to wait for all threads to finish + */ +static void +clean_up(void) +{ + int i; + + /* wait for threads to finish */ + for (i = 0; i < NumWinThreads; i++) { + pthread_join(WinThreads[i].Thread, NULL); + } + + for (i = 0; i < NumWinThreads; i++) { + glXDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context); + XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win); + } +} + + + +int +main(int argc, char *argv[]) +{ + char *displayName = ":0.0"; + int numThreads = 2; + Display *dpy = NULL; + int i; + Status threadStat; + + if (argc == 1) { + printf("glthreads: test of GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" glthreads [-display dpyName] [-n numthreads]\n"); + } + else { + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + displayName = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "-p") == 0) { + MultiDisplays = 1; + } + else if (strcmp(argv[i], "-l") == 0) { + Locking = 1; + } + else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { + numThreads = atoi(argv[i + 1]); + if (numThreads < 1) + numThreads = 1; + else if (numThreads > MAX_WINTHREADS) + numThreads = MAX_WINTHREADS; + i++; + } + else { + fprintf(stderr, "glthreads: unexpected flag: %s\n", argv[i]); + } + } + } + + if (Locking) + printf("glthreads: Using explict locks around Xlib calls.\n"); + else + printf("glthreads: No explict locking.\n"); + + if (MultiDisplays) + printf("glthreads: Per-thread display connections.\n"); + else + printf("glthreads: Single display connection.\n"); + + /* + * VERY IMPORTANT: call XInitThreads() before any other Xlib functions. + */ + if (!MultiDisplays) { + if (!Locking) { + threadStat = XInitThreads(); + if (threadStat) { + printf("XInitThreads() returned %d (success)\n", (int) threadStat); + } + else { + printf("XInitThreads() returned 0 (failure- this program may fail)\n"); + } + } + + dpy = XOpenDisplay(displayName); + if (!dpy) { + fprintf(stderr, "Unable to open display %s\n", displayName); + return -1; + } + } + + if (Locking) { + pthread_mutex_init(&Mutex, NULL); + } + + printf("glthreads: creating windows\n"); + + NumWinThreads = numThreads; + + /* Create the GLX windows and contexts */ + for (i = 0; i < numThreads; i++) { + if (MultiDisplays) { + WinThreads[i].Dpy = XOpenDisplay(displayName); + assert(WinThreads[i].Dpy); + } + else { + WinThreads[i].Dpy = dpy; + } + WinThreads[i].Index = i; + create_window(&WinThreads[i]); + } + + printf("glthreads: creating threads\n"); + + /* Create the threads */ + for (i = 0; i < numThreads; i++) { + pthread_create(&WinThreads[i].Thread, NULL, thread_function, + (void*) &WinThreads[i]); + printf("glthreads: Created thread %u\n", (unsigned int) WinThreads[i].Thread); + } + + if (MultiDisplays) + event_loop_multi(); + else + event_loop(dpy); + + clean_up(); + + if (MultiDisplays) { + for (i = 0; i < numThreads; i++) { + XCloseDisplay(WinThreads[i].Dpy); + } + } + else { + XCloseDisplay(dpy); + } + + return 0; +} + + +#else /* PTHREADS */ + + +#include <stdio.h> + +int +main(int argc, char *argv[]) +{ + printf("Sorry, this program wasn't compiled with PTHREADS defined.\n"); + return 0; +} + + +#endif /* PTHREADS */ diff --git a/progs/xdemos/glxcontexts.c b/progs/xdemos/glxcontexts.c new file mode 100644 index 00000000000..fbc296ef625 --- /dev/null +++ b/progs/xdemos/glxcontexts.c @@ -0,0 +1,609 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT) + * Port by Brian Paul 23 March 2001 + * + * Command line options: + * -info print GL implementation information + * -stereo use stereo enabled GLX visual + * + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <GL/glx.h> + + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include <sys/time.h> +#include <unistd.h> + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static double +current_time(void) +{ + /* update this function for other platforms! */ + static double t = 0.0; + static int warn = 1; + if (warn) { + fprintf(stderr, "Warning: current_time() not implemented!!\n"); + warn = 0; + } + return t += 1.0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +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 GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */ +static GLboolean stereo = GL_FALSE; /* Enable stereo. */ +static GLfloat eyesep = 5.0; /* Eye separation. */ +static GLfloat fix_point = 40.0; /* Fixation point distance. */ +static GLfloat left, right, asp; /* Stereo frustum params. */ + + XVisualInfo *visinfo; + + +/* + * + * 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 void +do_draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + glViewport(0, 0, (GLint) width, (GLint) height); + + if (stereo) { + GLfloat w; + + asp = (GLfloat) height / (GLfloat) width; + w = fix_point * (1.0 / 5.0); + + left = -5.0 * ((w - 0.5 * eyesep) / fix_point); + right = 5.0 * ((w + 0.5 * eyesep) / fix_point); + } else { + GLfloat h = (GLfloat) height / (GLfloat) width; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + } + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +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); +} + + +static void +draw( Display *dpy, Window win ) +{ + GLXContext ctx; + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + glXMakeCurrent(dpy, win, ctx); + + init(); + + if (stereo) { + /* First left eye. */ + glDrawBuffer(GL_BACK_LEFT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(left, right, -asp, asp, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + glTranslated(+0.5 * eyesep, 0.0, 0.0); + do_draw(); + glPopMatrix(); + + /* Then right eye. */ + glDrawBuffer(GL_BACK_RIGHT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-right, -left, -asp, asp, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + glTranslated(-0.5 * eyesep, 0.0, 0.0); + do_draw(); + glPopMatrix(); + } else + do_draw(); + + glXSwapBuffers(dpy, win); + glXDestroyContext(dpy, ctx); +} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet) +{ + int attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + int stereoAttribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + GLX_STEREO, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + if (fullscreen) { + x = 0; y = 0; + width = DisplayWidth( dpy, scrnum ); + height = DisplayHeight( dpy, scrnum ); + } + + if (stereo) + visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs ); + else + visinfo = glXChooseVisual( dpy, scrnum, attribs ); + if (!visinfo) { + if (stereo) { + printf("Error: couldn't get an RGB, " + "Double-buffered, Stereo visual\n"); + } else + 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 | KeyPressMask; + attr.override_redirect = fullscreen; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( dpy, root, x, y, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + *winRet = win; +} + + +static void +event_loop(Display *dpy) +{ + Window win; + make_window(dpy, "glxgears", 0, 0, 300, 300, &win); + XMapWindow(dpy, win); + + + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + { + static int frames = 0; + static double tRot0 = -1.0, tRate0 = -1.0; + double dt, t = current_time(); + if (tRot0 < 0.0) + tRot0 = t; + dt = t - tRot0; + tRot0 = t; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + draw( dpy, win ); + + frames++; + + if (tRate0 < 0.0) + tRate0 = t; + + if (t - tRate0 >= 1.0) { + GLfloat seconds = t - tRate0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + tRate0 = t; + + XDestroyWindow(dpy, win); + make_window(dpy, "glxgears", (int)(fps * 100) % 100, (int)(fps * 100) % 100, 300, 300, &win); + XMapWindow(dpy, win); + + frames = 0; + } + } + } +} + + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else if (strcmp(argv[i], "-stereo") == 0) { + stereo = GL_TRUE; + } + else if (strcmp(argv[i], "-fullscreen") == 0) { + fullscreen = GL_TRUE; + } + else + printf("Warrning: unknown parameter: %s\n", argv[i]); + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + + event_loop(dpy); + + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/glxdemo.c b/progs/xdemos/glxdemo.c new file mode 100644 index 00000000000..37df64ebee8 --- /dev/null +++ b/progs/xdemos/glxdemo.c @@ -0,0 +1,127 @@ + + +/* + * A demonstration of using the GLX functions. This program is in the + * public domain. + * + * Brian Paul + */ + +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> + + + +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 ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + 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/glxgears.c b/progs/xdemos/glxgears.c new file mode 100644 index 00000000000..75d63e51a2e --- /dev/null +++ b/progs/xdemos/glxgears.c @@ -0,0 +1,621 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT) + * Port by Brian Paul 23 March 2001 + * + * Command line options: + * -info print GL implementation information + * -stereo use stereo enabled GLX visual + * + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <GL/glx.h> + + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include <sys/time.h> +#include <unistd.h> + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static double +current_time(void) +{ + /* update this function for other platforms! */ + static double t = 0.0; + static int warn = 1; + if (warn) { + fprintf(stderr, "Warning: current_time() not implemented!!\n"); + warn = 0; + } + return t += 1.0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +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 GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */ +static GLboolean stereo = GL_FALSE; /* Enable stereo. */ +static GLfloat eyesep = 5.0; /* Eye separation. */ +static GLfloat fix_point = 40.0; /* Fixation point distance. */ +static GLfloat left, right, asp; /* Stereo frustum params. */ + + +/* + * + * 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 void +do_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(); +} + +static void +draw(void) +{ + if (stereo) { + /* First left eye. */ + glDrawBuffer(GL_BACK_LEFT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(left, right, -asp, asp, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + glTranslated(+0.5 * eyesep, 0.0, 0.0); + do_draw(); + glPopMatrix(); + + /* Then right eye. */ + glDrawBuffer(GL_BACK_RIGHT); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-right, -left, -asp, asp, 5.0, 60.0); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + glTranslated(-0.5 * eyesep, 0.0, 0.0); + do_draw(); + glPopMatrix(); + } else + do_draw(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + glViewport(0, 0, (GLint) width, (GLint) height); + + if (stereo) { + GLfloat w; + + asp = (GLfloat) height / (GLfloat) width; + w = fix_point * (1.0 / 5.0); + + left = -5.0 * ((w - 0.5 * eyesep) / fix_point); + right = 5.0 * ((w + 0.5 * eyesep) / fix_point); + } else { + GLfloat h = (GLfloat) height / (GLfloat) width; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + } + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + + + +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); +} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, GLXContext *ctxRet) +{ + int attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + int stereoAttribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + GLX_STEREO, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + GLXContext ctx; + XVisualInfo *visinfo; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + if (fullscreen) { + x = 0; y = 0; + width = DisplayWidth( dpy, scrnum ); + height = DisplayHeight( dpy, scrnum ); + } + + if (stereo) + visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs ); + else + visinfo = glXChooseVisual( dpy, scrnum, attribs ); + if (!visinfo) { + if (stereo) { + printf("Error: couldn't get an RGB, " + "Double-buffered, Stereo visual\n"); + } else + 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 | KeyPressMask; + attr.override_redirect = fullscreen; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win) +{ + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + { + static int frames = 0; + static double tRot0 = -1.0, tRate0 = -1.0; + double dt, t = current_time(); + if (tRot0 < 0.0) + tRot0 = t; + dt = t - tRot0; + tRot0 = t; + + /* advance rotation for next frame */ + angle += 70.0 * dt; /* 70 degrees per second */ + if (angle > 3600.0) + angle -= 3600.0; + + draw(); + glXSwapBuffers(dpy, win); + + frames++; + + if (tRate0 < 0.0) + tRate0 = t; + if (t - tRate0 >= 5.0) { + GLfloat seconds = t - tRate0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + tRate0 = t; + frames = 0; + } + } + } +} + + +static void +usage(void) +{ + printf("Usage:\n"); + printf(" -display <displayname> set the display to run on\n"); + printf(" -stereo run in stereo mode\n"); + printf(" -fullscreen run in fullscreen mode\n"); + printf(" -info display OpenGL renderer info\n"); +} + + +int +main(int argc, char *argv[]) +{ + const int winWidth = 300, winHeight = 300; + Display *dpy; + Window win; + GLXContext ctx; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else if (strcmp(argv[i], "-stereo") == 0) { + stereo = GL_TRUE; + } + else if (strcmp(argv[i], "-fullscreen") == 0) { + fullscreen = GL_TRUE; + } + else { + usage(); + return -1; + } + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + make_window(dpy, "glxgears", 0, 0, winWidth, winHeight, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + + /* Set initial projection/viewing transformation. + * We can't be sure we'll get a ConfigureNotify event when the window + * first appears. + */ + reshape(winWidth, winHeight); + + event_loop(dpy, win); + + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/glxgears2.c b/progs/xdemos/glxgears2.c new file mode 100644 index 00000000000..5de5601240e --- /dev/null +++ b/progs/xdemos/glxgears2.c @@ -0,0 +1,522 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT) + * Port by Brian Paul 23 March 2001 + * + * Command line options: + * -info print GL implementation information + * + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <GL/glx.h> + + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include <sys/time.h> +#include <unistd.h> + +/* return current time (in seconds) */ +static int +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (int) tv.tv_sec; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static int +current_time(void) +{ + return 0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +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 GLint WinWidth = 300, WinHeight = 300; + +/* + * + * 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 void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +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); + WinWidth = width; + WinHeight = height; +} + + +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 }; + + glClearColor(1, 0, 0, 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); +} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, GLXContext *ctxRet) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + 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 | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win) +{ + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + /* next frame */ + angle += 2.0; + + draw(); + +#if 0 + glXSwapBuffers(dpy, win); +#else + { + GLfloat c[4]; + + glReadBuffer(GL_BACK); + + glReadPixels(WinWidth-1, 0, 1, 1, GL_RGB, GL_FLOAT, c); + printf("Bottom right pixel color: %g, %g, %g\n", c[0], c[1], c[2]); + + glDrawBuffer(GL_FRONT); + glWindowPos2iARB(0,0); + glCopyPixels(WinWidth/2, 0, WinWidth/2, WinHeight, GL_COLOR); + glDrawBuffer(GL_BACK); + } +#endif + + /* calc framerate */ + { + static int t0 = -1; + static int frames = 0; + int t = current_time(); + + if (t0 < 0) + t0 = t; + + frames++; + + if (t - t0 >= 5.0) { + GLfloat seconds = t - t0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + t0 = t; + frames = 0; + } + } + } +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + Window win; + GLXContext ctx; + char *dpyName = ":0"; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", dpyName); + return -1; + } + + make_window(dpy, "glxgears", 0, 0, WinWidth, WinHeight, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + + event_loop(dpy, win); + + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/glxgears_fbconfig.c b/progs/xdemos/glxgears_fbconfig.c new file mode 100644 index 00000000000..acbadd21ac5 --- /dev/null +++ b/progs/xdemos/glxgears_fbconfig.c @@ -0,0 +1,602 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file glxgears_fbconfig.c + * Yet-another-version of gears. Originally ported to GLX by Brian Paul on + * 23 March 2001. Modified to use fbconfigs by Ian Romanick on 10 Feb 2004. + * + * Command line options: + * -info print GL implementation information + * + * \author Brian Paul + * \author Ian Romanick <[email protected]> + */ + + +#define GLX_GLXEXT_PROTOTYPES + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <GL/gl.h> +#include <GL/glx.h> +#include <GL/glxext.h> +#include <assert.h> +#include "pbutil.h" + +/* I had to use the SGIX versions of these because for some reason glxext.h + * doesn't define the core versions if GLX_VERSION_1_3 is defined, and glx.h + * doesn't define them at all. One or both header files is clearly broken. + */ +static PFNGLXCHOOSEFBCONFIGSGIXPROC choose_fbconfig = NULL; +static PFNGLXGETVISUALFROMFBCONFIGSGIXPROC get_visual_from_fbconfig = NULL; +static PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC create_new_context = NULL; + +#define BENCHMARK + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include <sys/time.h> +#include <unistd.h> + +/* return current time (in seconds) */ +static int +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (int) tv.tv_sec; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static int +current_time(void) +{ + return 0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.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 void +draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +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); +} + + +/** + * Initialize fbconfig related function pointers. + */ +static void +init_fbconfig_functions(Display *dpy, int scrnum) +{ + const char * glx_extensions; + const char * match; + static const char ext_name[] = "GLX_SGIX_fbconfig"; + const size_t len = strlen( ext_name ); + int major; + int minor; + GLboolean ext_version_supported; + GLboolean glx_1_3_supported; + + + /* Determine if GLX 1.3 or greater is supported. + */ + glXQueryVersion(dpy, & major, & minor); + glx_1_3_supported = (major == 1) && (minor >= 3); + + /* Determine if GLX_SGIX_fbconfig is supported. + */ + glx_extensions = glXQueryExtensionsString(dpy, scrnum); + match = strstr( glx_extensions, ext_name ); + + ext_version_supported = (match != NULL) + && ((match[len] == '\0') || (match[len] == ' ')); + + printf( "GLX 1.3 is %ssupported.\n", + (glx_1_3_supported) ? "" : "not " ); + printf( "%s is %ssupported.\n", + ext_name, (ext_version_supported) ? "" : "not " ); + + if ( glx_1_3_supported ) { + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXChooseFBConfig"); + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXGetVisualFromFBConfig"); + create_new_context = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXCreateNewContext"); + } + else if ( ext_version_supported ) { + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXChooseFBConfigSGIX"); + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXGetVisualFromFBConfigSGIX"); + create_new_context = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB( + (GLubyte *) "glXCreateContextWithConfigSGIX"); + } + else { + printf( "This demo requires either GLX 1.3 or %s be supported.\n", + ext_name ); + exit(1); + } + + if ( choose_fbconfig == NULL ) { + printf( "glXChooseFBConfig not found!\n" ); + exit(1); + } + + if ( get_visual_from_fbconfig == NULL ) { + printf( "glXGetVisualFromFBConfig not found!\n" ); + exit(1); + } + + if ( create_new_context == NULL ) { + printf( "glXCreateNewContext not found!\n" ); + exit(1); + } +} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, GLXContext *ctxRet) +{ + int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, GL_TRUE, + GLX_DEPTH_SIZE, 1, + None }; + GLXFBConfig * fbconfig; + int num_configs; + int scrnum; + int i; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + GLXContext ctx; + XVisualInfo *visinfo; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + init_fbconfig_functions(dpy, scrnum); + fbconfig = (*choose_fbconfig)(dpy, scrnum, attrib, & num_configs); + if (fbconfig == NULL) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + printf("\nThe following fbconfigs meet the requirements. The first one " + "will be used.\n\n"); + for ( i = 0 ; i < num_configs ; i++ ) { + PrintFBConfigInfo(dpy, scrnum, fbconfig[i], GL_TRUE); + } + + /* window attributes */ + visinfo = (*get_visual_from_fbconfig)(dpy, fbconfig[0]); + assert(visinfo != NULL); + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = (*create_new_context)(dpy, fbconfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE); + if (!ctx) { + printf("Error: glXCreateNewContext failed\n"); + exit(1); + } + + XFree(fbconfig); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win) +{ + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + /* next frame */ + angle += 2.0; + + draw(); + glXSwapBuffers(dpy, win); + + /* calc framerate */ + { + static int t0 = -1; + static int frames = 0; + int t = current_time(); + + if (t0 < 0) + t0 = t; + + frames++; + + if (t - t0 >= 5.0) { + GLfloat seconds = t - t0; + GLfloat fps = frames / seconds; + printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, + fps); + t0 = t; + frames = 0; + } + } + } +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + Window win; + GLXContext ctx; + const char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", dpyName); + return -1; + } + + make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + init(); + + event_loop(dpy, win); + + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/glxheads.c b/progs/xdemos/glxheads.c new file mode 100644 index 00000000000..0145a70e91c --- /dev/null +++ b/progs/xdemos/glxheads.c @@ -0,0 +1,286 @@ + +/* + * Exercise multiple GLX connections on multiple X displays. + * Direct GLX contexts are attempted first, then indirect. + * Each window will display a spinning green triangle. + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + + + +/* + * Each display/window/context: + */ +struct head { + char DisplayName[1000]; + Display *Dpy; + Window Win; + GLXContext Context; + float Angle; + char Renderer[1000]; + char Vendor[1000]; + char Version[1000]; +}; + + +#define MAX_HEADS 20 +static struct head Heads[MAX_HEADS]; +static int NumHeads = 0; + + +static void +Error(const char *display, const char *msg) +{ + fprintf(stderr, "Error on display %s - %s\n", display, msg); + exit(1); +} + + +static struct head * +AddHead(const char *displayName) +{ + Display *dpy; + Window win; + GLXContext ctx; + 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; + XVisualInfo *visinfo; + int width = 300, height = 300; + int xpos = 10, ypos = 10; + + if (NumHeads >= MAX_HEADS) + return NULL; + + dpy = XOpenDisplay(displayName); + if (!dpy) { + Error(displayName, "Unable to open display"); + return NULL; + } + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, attrib); + if (!visinfo) { + Error(displayName, "Unable to find RGB, double-buffered visual"); + return NULL; + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error(displayName, "Couldn't create window"); + return NULL; + } + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, displayName, displayName, + None, (char **)NULL, 0, &sizehints); + } + + + ctx = glXCreateContext(dpy, visinfo, NULL, True); + if (!ctx) { + Error(displayName, "Couldn't create GLX context"); + return NULL; + } + + XMapWindow(dpy, win); + + if (!glXMakeCurrent(dpy, win, ctx)) { + Error(displayName, "glXMakeCurrent failed"); + printf("glXMakeCurrent failed in Redraw()\n"); + return NULL; + } + + /* save the info for this head */ + { + struct head *h = &Heads[NumHeads]; + strcpy(h->DisplayName, displayName); + h->Dpy = dpy; + h->Win = win; + h->Context = ctx; + h->Angle = 0.0; + strcpy(h->Version, (char *) glGetString(GL_VERSION)); + strcpy(h->Vendor, (char *) glGetString(GL_VENDOR)); + strcpy(h->Renderer, (char *) glGetString(GL_RENDERER)); + NumHeads++; + return &Heads[NumHeads-1]; + } + +} + + +static void +Redraw(struct head *h) +{ + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed"); + printf("glXMakeCurrent failed in Redraw()\n"); + return; + } + + h->Angle += 1.0; + + glShadeModel(GL_FLAT); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* draw green triangle */ + glColor3f(0.0, 1.0, 0.0); + glPushMatrix(); + glRotatef(h->Angle, 0, 0, 1); + glBegin(GL_TRIANGLES); + glVertex2f(0, 0.8); + glVertex2f(-0.8, -0.7); + glVertex2f(0.8, -0.7); + glEnd(); + glPopMatrix(); + + glXSwapBuffers(h->Dpy, h->Win); +} + + + +static void +Resize(const struct head *h, unsigned int width, unsigned int height) +{ + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed in Resize()"); + return; + } + glFlush(); + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); +} + + + +static void +EventLoop(void) +{ + while (1) { + int i; + for (i = 0; i < NumHeads; i++) { + struct head *h = &Heads[i]; + while (XPending(h->Dpy) > 0) { + XEvent event; + XNextEvent(h->Dpy, &event); + if (event.xany.window == h->Win) { + switch (event.type) { + case Expose: + Redraw(h); + break; + case ConfigureNotify: + Resize(h, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + return; + default: + /*no-op*/ ; + } + } + else { + printf("window mismatch\n"); + } + } + Redraw(h); + } + usleep(1); + } +} + + + +static void +PrintInfo(const struct head *h) +{ + printf("Name: %s\n", h->DisplayName); + printf(" Display: %p\n", (void *) h->Dpy); + printf(" Window: 0x%x\n", (int) h->Win); + printf(" Context: 0x%lx\n", (long) h->Context); + printf(" GL_VERSION: %s\n", h->Version); + printf(" GL_VENDOR: %s\n", h->Vendor); + printf(" GL_RENDERER: %s\n", h->Renderer); +} + + +int +main(int argc, char *argv[]) +{ + int i; + if (argc == 1) { + struct head *h; + printf("glxheads: exercise multiple GLX connections (any key = exit)\n"); + printf("Usage:\n"); + printf(" glxheads xdisplayname ...\n"); + printf("Example:\n"); + printf(" glxheads :0 mars:0 venus:1\n"); + h = AddHead(":0"); + if (h) + PrintInfo(h); + } + else { + for (i = 1; i < argc; i++) { + const char *name = argv[i]; + struct head *h = AddHead(name); + if (h) { + PrintInfo(h); + } + } + } + + EventLoop(); + return 0; +} diff --git a/progs/xdemos/glxinfo.c b/progs/xdemos/glxinfo.c new file mode 100644 index 00000000000..fdd1c0523f6 --- /dev/null +++ b/progs/xdemos/glxinfo.c @@ -0,0 +1,956 @@ +/* + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * This program is a work-alike of the IRIX glxinfo program. + * Command line options: + * -t print wide table + * -v print verbose information + * -display DisplayName specify the X display to interogate + * -b only print ID of "best" visual on screen 0 + * -i use indirect rendering connection only + * -l print interesting OpenGL limits (added 5 Sep 2002) + * + * Brian Paul 26 January 2000 + */ + +#define GLX_GLXEXT_PROTOTYPES + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +#ifndef GLX_NONE_EXT +#define GLX_NONE_EXT 0x8000 +#endif + +#ifndef GLX_TRANSPARENT_RGB +#define GLX_TRANSPARENT_RGB 0x8008 +#endif + + +typedef enum +{ + Normal, + Wide, + Verbose +} InfoMode; + + +struct visual_attribs +{ + /* X visual attribs */ + int id; + int klass; + int depth; + int redMask, greenMask, blueMask; + int colormapSize; + int bitsPerRGB; + + /* GL visual attribs */ + int supportsGL; + int transparentType; + int transparentRedValue; + int transparentGreenValue; + int transparentBlueValue; + int transparentAlphaValue; + int transparentIndexValue; + int bufferSize; + int level; + int rgba; + int doubleBuffer; + int stereo; + int auxBuffers; + int redSize, greenSize, blueSize, alphaSize; + int depthSize; + int stencilSize; + int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize; + int numSamples, numMultisample; + int visualCaveat; +}; + + +/* + * Print a list of extensions, with word-wrapping. + */ +static void +print_extension_list(const char *ext) +{ + const char *indentString = " "; + const int indent = 4; + const int max = 79; + int width, i, j; + + if (!ext || !ext[0]) + return; + + width = indent; + printf(indentString); + i = j = 0; + while (1) { + if (ext[j] == ' ' || ext[j] == 0) { + /* found end of an extension name */ + const int len = j - i; + if (width + len > max) { + /* start a new line */ + printf("\n"); + width = indent; + printf(indentString); + } + /* print the extension name between ext[i] and ext[j] */ + while (i < j) { + printf("%c", ext[i]); + i++; + } + /* either we're all done, or we'll continue with next extension */ + width += len + 1; + if (ext[j] == 0) { + break; + } + else { + i++; + j++; + if (ext[j] == 0) + break; + printf(", "); + width += 2; + } + } + j++; + } + printf("\n"); +} + + +static void +print_display_info(Display *dpy) +{ + printf("name of display: %s\n", DisplayString(dpy)); +} + + +/** + * Print interesting limits for vertex/fragment programs. + */ +static void +print_program_limits(GLenum target) +{ +#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) + struct token_name { + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" }, + { (GLenum) 0, NULL } + }; + PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC) + glXGetProcAddressARB((GLubyte *) "glGetProgramivARB"); + GLint max[1]; + int i; + + if (target == GL_VERTEX_PROGRAM_ARB) { + printf(" GL_VERTEX_PROGRAM_ARB:\n"); + } + else if (target == GL_FRAGMENT_PROGRAM_ARB) { + printf(" GL_FRAGMENT_PROGRAM_ARB:\n"); + } + else { + return; /* something's wrong */ + } + + for (i = 0; limits[i].token; i++) { + GetProgramivARB_func(target, limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", limits[i].name, max[0]); + } + } +#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */ +} + + +/** + * Print interesting limits for vertex/fragment shaders. + */ +static void +print_shader_limits(GLenum target) +{ + struct token_name { + GLenum token; + const char *name; + }; +#if defined(GL_ARB_vertex_shader) + static const struct token_name vertex_limits[] = { + { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" }, + { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif +#if defined(GL_ARB_fragment_shader) + static const struct token_name fragment_limits[] = { + { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif + GLint max[1]; + int i; + +#if defined(GL_ARB_vertex_shader) + if (target == GL_VERTEX_SHADER_ARB) { + printf(" GL_VERTEX_SHADER_ARB:\n"); + for (i = 0; vertex_limits[i].token; i++) { + glGetIntegerv(vertex_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", vertex_limits[i].name, max[0]); + } + } + } +#endif +#if defined(GL_ARB_fragment_shader) + if (target == GL_FRAGMENT_SHADER_ARB) { + printf(" GL_FRAGMENT_SHADER_ARB:\n"); + for (i = 0; fragment_limits[i].token; i++) { + glGetIntegerv(fragment_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", fragment_limits[i].name, max[0]); + } + } + } +#endif +} + + +/** + * Print interesting OpenGL implementation limits. + */ +static void +print_limits(const char *extensions) +{ + struct token_name { + GLuint count; + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" }, + { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" }, + { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" }, + { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" }, + { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" }, + { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" }, + { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" }, + { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" }, + { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" }, + { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" }, + { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" }, + { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" }, + { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" }, + { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" }, + { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" }, + { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" }, + { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" }, +#if defined(GL_ARB_texture_cube_map) + { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" }, +#endif +#if defined(GLX_NV_texture_rectangle) + { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" }, +#endif +#if defined(GL_ARB_texture_compression) + { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" }, +#endif +#if defined(GL_ARB_multitexture) + { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" }, +#endif +#if defined(GL_EXT_texture_lod_bias) + { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" }, +#endif +#if defined(GL_EXT_texture_filter_anisotropic) + { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" }, +#endif +#if defined(GL_ARB_draw_buffers) + { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" }, +#endif + { 0, (GLenum) 0, NULL } + }; + GLint i, max[2]; + + printf("OpenGL limits:\n"); + for (i = 0; limits[i].count; i++) { + glGetIntegerv(limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + if (limits[i].count == 1) + printf(" %s = %d\n", limits[i].name, max[0]); + else /* XXX fix if we ever query something with more than 2 values */ + printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]); + } + } + + /* these don't fit into the above mechanism, unfortunately */ + glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max); + glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1); + if (glGetError() == GL_NONE) { + printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]); + } + +#if defined(GL_ARB_vertex_program) + if (strstr(extensions, "GL_ARB_vertex_program")) { + print_program_limits(GL_VERTEX_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_fragment_program) + if (strstr(extensions, "GL_ARB_fragment_program")) { + print_program_limits(GL_FRAGMENT_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_vertex_shader) + if (strstr(extensions, "GL_ARB_vertex_shader")) { + print_shader_limits(GL_VERTEX_SHADER_ARB); + } +#endif +#if defined(GL_ARB_fragment_shader) + if (strstr(extensions, "GL_ARB_fragment_shader")) { + print_shader_limits(GL_FRAGMENT_SHADER_ARB); + } +#endif +} + + +static void +print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits) +{ + Window win; + int attribSingle[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + int attribDouble[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + + XSetWindowAttributes attr; + unsigned long mask; + Window root; + GLXContext ctx; + XVisualInfo *visinfo; + int width = 100, height = 100; + + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, attribSingle); + if (!visinfo) { + visinfo = glXChooseVisual(dpy, scrnum, attribDouble); + if (!visinfo) { + fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); + return; + } + } + + 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, allowDirect ); + if (!ctx) { + fprintf(stderr, "Error: glXCreateContext failed\n"); + XFree(visinfo); + XDestroyWindow(dpy, win); + return; + } + + if (glXMakeCurrent(dpy, win, ctx)) { + const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); + const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); + const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); + const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); + const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); + const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); + const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); + const char *glVendor = (const char *) glGetString(GL_VENDOR); + const char *glRenderer = (const char *) glGetString(GL_RENDERER); + const char *glVersion = (const char *) glGetString(GL_VERSION); + const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); + int glxVersionMajor; + int glxVersionMinor; + char *displayName = NULL; + char *colon = NULL, *period = NULL; + + if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) { + fprintf(stderr, "Error: glXQueryVersion failed\n"); + exit(1); + } + + /* Strip the screen number from the display name, if present. */ + if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { + fprintf(stderr, "Error: malloc() failed\n"); + exit(1); + } + strcpy(displayName, DisplayString(dpy)); + colon = strrchr(displayName, ':'); + if (colon) { + period = strchr(colon, '.'); + if (period) + *period = '\0'; + } + printf("display: %s screen: %d\n", displayName, scrnum); + free(displayName); + printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); + printf("server glx vendor string: %s\n", serverVendor); + printf("server glx version string: %s\n", serverVersion); + printf("server glx extensions:\n"); + print_extension_list(serverExtensions); + printf("client glx vendor string: %s\n", clientVendor); + printf("client glx version string: %s\n", clientVersion); + printf("client glx extensions:\n"); + print_extension_list(clientExtensions); + printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor); + printf("GLX extensions:\n"); + print_extension_list(glxExtensions); + printf("OpenGL vendor string: %s\n", glVendor); + printf("OpenGL renderer string: %s\n", glRenderer); + printf("OpenGL version string: %s\n", glVersion); + printf("OpenGL extensions:\n"); + print_extension_list(glExtensions); + if (limits) + print_limits(glExtensions); + } + else { + fprintf(stderr, "Error: glXMakeCurrent failed\n"); + } + + glXDestroyContext(dpy, ctx); + XFree(visinfo); + XDestroyWindow(dpy, win); +} + + +static const char * +visual_class_name(int cls) +{ + switch (cls) { + case StaticColor: + return "StaticColor"; + case PseudoColor: + return "PseudoColor"; + case StaticGray: + return "StaticGray"; + case GrayScale: + return "GrayScale"; + case TrueColor: + return "TrueColor"; + case DirectColor: + return "DirectColor"; + default: + return ""; + } +} + + +static const char * +visual_class_abbrev(int cls) +{ + switch (cls) { + case StaticColor: + return "sc"; + case PseudoColor: + return "pc"; + case StaticGray: + return "sg"; + case GrayScale: + return "gs"; + case TrueColor: + return "tc"; + case DirectColor: + return "dc"; + default: + return ""; + } +} + + +static void +get_visual_attribs(Display *dpy, XVisualInfo *vInfo, + struct visual_attribs *attribs) +{ + const char *ext = glXQueryExtensionsString(dpy, vInfo->screen); + + memset(attribs, 0, sizeof(struct visual_attribs)); + + attribs->id = vInfo->visualid; +#if defined(__cplusplus) || defined(c_plusplus) + attribs->klass = vInfo->c_class; +#else + attribs->klass = vInfo->class; +#endif + attribs->depth = vInfo->depth; + attribs->redMask = vInfo->red_mask; + attribs->greenMask = vInfo->green_mask; + attribs->blueMask = vInfo->blue_mask; + attribs->colormapSize = vInfo->colormap_size; + attribs->bitsPerRGB = vInfo->bits_per_rgb; + + if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0) + return; + glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize); + glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level); + glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba); + glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer); + glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo); + glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers); + glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize); + glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize); + glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize); + glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize); + glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize); + glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize); + glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize); + glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize); + glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize); + glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize); + + /* get transparent pixel stuff */ + glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType); + if (attribs->transparentType == GLX_TRANSPARENT_RGB) { + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue); + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue); + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue); + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue); + } + else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) { + glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue); + } + + /* multisample attribs */ +#ifdef GLX_ARB_multisample + if (ext && strstr(ext, "GLX_ARB_multisample") == 0) { + glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample); + glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples); + } +#endif + else { + attribs->numSamples = 0; + attribs->numMultisample = 0; + } + +#if defined(GLX_EXT_visual_rating) + if (ext && strstr(ext, "GLX_EXT_visual_rating")) { + glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat); + } + else { + attribs->visualCaveat = GLX_NONE_EXT; + } +#else + attribs->visualCaveat = 0; +#endif +} + + +static void +print_visual_attribs_verbose(const struct visual_attribs *attribs) +{ + printf("Visual ID: %x depth=%d class=%s\n", + attribs->id, attribs->depth, visual_class_name(attribs->klass)); + printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", + attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci", + attribs->doubleBuffer, attribs->stereo); + printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", + attribs->redSize, attribs->greenSize, + attribs->blueSize, attribs->alphaSize); + printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n", + attribs->auxBuffers, attribs->depthSize, attribs->stencilSize); + printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", + attribs->accumRedSize, attribs->accumGreenSize, + attribs->accumBlueSize, attribs->accumAlphaSize); + printf(" multiSample=%d multiSampleBuffers=%d\n", + attribs->numSamples, attribs->numMultisample); +#ifdef GLX_EXT_visual_rating + if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) + printf(" visualCaveat=None\n"); + else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) + printf(" visualCaveat=Slow\n"); + else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) + printf(" visualCaveat=Nonconformant\n"); +#endif + if (attribs->transparentType == GLX_NONE) { + printf(" Opaque.\n"); + } + else if (attribs->transparentType == GLX_TRANSPARENT_RGB) { + printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue); + } + else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) { + printf(" Transparent index=%d\n",attribs->transparentIndexValue); + } +} + + +static void +print_visual_attribs_short_header(void) +{ + printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); + printf(" id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n"); + printf("----------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_short(const struct visual_attribs *attribs) +{ + char *caveat = NULL; +#ifdef GLX_EXT_visual_rating + if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) + caveat = "None"; + else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) + caveat = "Slow"; + else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) + caveat = "Ncon"; + else + caveat = "None"; +#else + caveat = "None"; +#endif + + printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d", + attribs->id, + attribs->depth, + visual_class_abbrev(attribs->klass), + attribs->transparentType != GLX_NONE, + attribs->bufferSize, + attribs->level, + attribs->rgba ? "r" : "c", + attribs->doubleBuffer ? "y" : ".", + attribs->stereo ? "y" : ".", + attribs->redSize, attribs->greenSize, + attribs->blueSize, attribs->alphaSize, + attribs->auxBuffers, + attribs->depthSize, + attribs->stencilSize + ); + + printf(" %2d %2d %2d %2d %2d %1d %s\n", + attribs->accumRedSize, attribs->accumGreenSize, + attribs->accumBlueSize, attribs->accumAlphaSize, + attribs->numSamples, attribs->numMultisample, + caveat + ); +} + + +static void +print_visual_attribs_long_header(void) +{ + printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); + printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); + printf("----------------------------------------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_long(const struct visual_attribs *attribs) +{ + printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", + attribs->id, + attribs->depth, + visual_class_name(attribs->klass), + attribs->transparentType != GLX_NONE, + attribs->bufferSize, + attribs->level, + attribs->rgba ? "rgba" : "ci ", + attribs->doubleBuffer, + attribs->stereo, + attribs->redSize, attribs->greenSize, + attribs->blueSize, attribs->alphaSize + ); + + printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", + attribs->auxBuffers, + attribs->depthSize, + attribs->stencilSize, + attribs->accumRedSize, attribs->accumGreenSize, + attribs->accumBlueSize, attribs->accumAlphaSize, + attribs->numSamples, attribs->numMultisample + ); +} + + +static void +print_visual_info(Display *dpy, int scrnum, InfoMode mode) +{ + XVisualInfo theTemplate; + XVisualInfo *visuals; + int numVisuals; + long mask; + int i; + + /* get list of all visuals on this screen */ + theTemplate.screen = scrnum; + mask = VisualScreenMask; + visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); + + if (mode == Verbose) { + for (i = 0; i < numVisuals; i++) { + struct visual_attribs attribs; + get_visual_attribs(dpy, &visuals[i], &attribs); + print_visual_attribs_verbose(&attribs); + } + } + else if (mode == Normal) { + print_visual_attribs_short_header(); + for (i = 0; i < numVisuals; i++) { + struct visual_attribs attribs; + get_visual_attribs(dpy, &visuals[i], &attribs); + print_visual_attribs_short(&attribs); + } + } + else if (mode == Wide) { + print_visual_attribs_long_header(); + for (i = 0; i < numVisuals; i++) { + struct visual_attribs attribs; + get_visual_attribs(dpy, &visuals[i], &attribs); + print_visual_attribs_long(&attribs); + } + } + + XFree(visuals); +} + + +/* + * Stand-alone Mesa doesn't really implement the GLX protocol so it + * doesn't really know the GLX attributes associated with an X visual. + * The first time a visual is presented to Mesa's pseudo-GLX it + * attaches ancilliary buffers to it (like depth and stencil). + * But that usually only works if glXChooseVisual is used. + * This function calls glXChooseVisual() to sort of "prime the pump" + * for Mesa's GLX so that the visuals that get reported actually + * reflect what applications will see. + * This has no effect when using true GLX. + */ +static void +mesa_hack(Display *dpy, int scrnum) +{ + static int attribs[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 1, + GLX_STENCIL_SIZE, 1, + GLX_ACCUM_RED_SIZE, 1, + GLX_ACCUM_GREEN_SIZE, 1, + GLX_ACCUM_BLUE_SIZE, 1, + GLX_ACCUM_ALPHA_SIZE, 1, + GLX_DOUBLEBUFFER, + None + }; + XVisualInfo *visinfo; + + visinfo = glXChooseVisual(dpy, scrnum, attribs); + if (visinfo) + XFree(visinfo); +} + + +/* + * Examine all visuals to find the so-called best one. + * We prefer deepest RGBA buffer with depth, stencil and accum + * that has no caveats. + */ +static int +find_best_visual(Display *dpy, int scrnum) +{ + XVisualInfo theTemplate; + XVisualInfo *visuals; + int numVisuals; + long mask; + int i; + struct visual_attribs bestVis; + + /* get list of all visuals on this screen */ + theTemplate.screen = scrnum; + mask = VisualScreenMask; + visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); + + /* init bestVis with first visual info */ + get_visual_attribs(dpy, &visuals[0], &bestVis); + + /* try to find a "better" visual */ + for (i = 1; i < numVisuals; i++) { + struct visual_attribs vis; + + get_visual_attribs(dpy, &visuals[i], &vis); + + /* always skip visuals with caveats */ + if (vis.visualCaveat != GLX_NONE_EXT) + continue; + + /* see if this vis is better than bestVis */ + if ((!bestVis.supportsGL && vis.supportsGL) || + (bestVis.visualCaveat != GLX_NONE_EXT) || + (!bestVis.rgba && vis.rgba) || + (!bestVis.doubleBuffer && vis.doubleBuffer) || + (bestVis.redSize < vis.redSize) || + (bestVis.greenSize < vis.greenSize) || + (bestVis.blueSize < vis.blueSize) || + (bestVis.alphaSize < vis.alphaSize) || + (bestVis.depthSize < vis.depthSize) || + (bestVis.stencilSize < vis.stencilSize) || + (bestVis.accumRedSize < vis.accumRedSize)) { + /* found a better visual */ + bestVis = vis; + } + } + + XFree(visuals); + + return bestVis.id; +} + + +static void +usage(void) +{ + printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n"); + printf("\t-v: Print visuals info in verbose form.\n"); + printf("\t-t: Print verbose table.\n"); + printf("\t-display <dname>: Print GLX visuals on specified server.\n"); + printf("\t-h: This information.\n"); + printf("\t-i: Force an indirect rendering context.\n"); + printf("\t-b: Find the 'best' visual and print it's number.\n"); + printf("\t-l: Print interesting OpenGL limits.\n"); +} + + +int +main(int argc, char *argv[]) +{ + char *displayName = NULL; + Display *dpy; + int numScreens, scrnum; + InfoMode mode = Normal; + GLboolean findBest = GL_FALSE; + GLboolean limits = GL_FALSE; + Bool allowDirect = True; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + displayName = argv[i + 1]; + i++; + } + else if (strcmp(argv[i], "-t") == 0) { + mode = Wide; + } + else if (strcmp(argv[i], "-v") == 0) { + mode = Verbose; + } + else if (strcmp(argv[i], "-b") == 0) { + findBest = GL_TRUE; + } + else if (strcmp(argv[i], "-i") == 0) { + allowDirect = False; + } + else if (strcmp(argv[i], "-l") == 0) { + limits = GL_TRUE; + } + else if (strcmp(argv[i], "-h") == 0) { + usage(); + return 0; + } + else { + printf("Unknown option `%s'\n", argv[i]); + usage(); + return 0; + } + } + + dpy = XOpenDisplay(displayName); + if (!dpy) { + fprintf(stderr, "Error: unable to open display %s\n", displayName); + return -1; + } + + if (findBest) { + int b; + mesa_hack(dpy, 0); + b = find_best_visual(dpy, 0); + printf("%d\n", b); + } + else { + numScreens = ScreenCount(dpy); + print_display_info(dpy); + for (scrnum = 0; scrnum < numScreens; scrnum++) { + mesa_hack(dpy, scrnum); + print_screen_info(dpy, scrnum, allowDirect, limits); + printf("\n"); + print_visual_info(dpy, scrnum, mode); + if (scrnum + 1 < numScreens) + printf("\n\n"); + } + } + + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/glxpbdemo.c b/progs/xdemos/glxpbdemo.c new file mode 100644 index 00000000000..91fd30dcaa6 --- /dev/null +++ b/progs/xdemos/glxpbdemo.c @@ -0,0 +1,430 @@ + +/* + * This program demonstrates how to do "off-screen" rendering using + * the GLX pixel buffer extension. + * + * Written by Brian Paul for the "OpenGL and Window System Integration" + * course presented at SIGGRAPH '97. Updated on 5 October 2002. + * + * Updated on 31 January 2004 to use native GLX by + * Andrew P. Lentvorski, Jr. <[email protected]> + * + * Usage: + * glxpbdemo width height imgfile + * Where: + * width is the width, in pixels, of the image to generate. + * height is the height, in pixels, of the image to generate. + * imgfile is the name of the PPM image file to write. + * + * + * This demo draws 3-D boxes with random orientation. + * + * On machines such as the SGI Indigo you may have to reconfigure your + * display/X server to enable pbuffers. Look in the /usr/gfx/ucode/MGRAS/vof/ + * directory for display configurations with the _pbuf suffix. Use + * setmon -x <vof> to configure your X server and display for pbuffers. + * + * O2 systems seem to support pbuffers well. + * + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <GL/glx.h> + +/* Some ugly global vars */ +static GLXFBConfig gFBconfig = 0; +static Display *gDpy = NULL; +static int gScreen = 0; +static GLXPbuffer gPBuffer = 0; +static int gWidth, gHeight; + + +/* + * Test for appropriate version of GLX to run this program + * Input: dpy - the X display + * screen - screen number + * Return: 0 = GLX not available. + * 1 = GLX available. + */ +static int +RuntimeQueryGLXVersion(Display *dpy, int screen) +{ +#if defined(GLX_VERSION_1_3) || defined(GLX_VERSION_1_4) + char *glxversion; + + glxversion = (char *) glXGetClientString(dpy, GLX_VERSION); + if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) + return 0; + + glxversion = (char *) glXQueryServerString(dpy, screen, GLX_VERSION); + if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) + return 0; + + return 1; +#else + return 0; +#endif +} + + + +/* + * Create the pbuffer and return a GLXPbuffer handle. + */ +static GLXPbuffer +MakePbuffer( Display *dpy, int screen, int width, int height ) +{ + GLXFBConfig *fbConfigs; + GLXFBConfig chosenFBConfig; + GLXPbuffer pBuffer = None; + + int nConfigs; + int fbconfigid; + + int fbAttribs[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DEPTH_SIZE, 1, + GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_PBUFFER_BIT, + None + }; + + int pbAttribs[] = { + GLX_PBUFFER_WIDTH, 0, + GLX_PBUFFER_HEIGHT, 0, + GLX_LARGEST_PBUFFER, False, + GLX_PRESERVED_CONTENTS, False, + None + }; + + pbAttribs[1] = width; + pbAttribs[3] = height; + + fbConfigs = glXChooseFBConfig(dpy, screen, fbAttribs, &nConfigs); + + if (0 == nConfigs || !fbConfigs) { + printf("Error: glxChooseFBConfig failed\n"); + XCloseDisplay(dpy); + return 0; + } + + chosenFBConfig = fbConfigs[0]; + + glXGetFBConfigAttrib(dpy, chosenFBConfig, GLX_FBCONFIG_ID, &fbconfigid); + printf("Chose 0x%x as fbconfigid\n", fbconfigid); + + /* Create the pbuffer using first fbConfig in the list that works. */ + pBuffer = glXCreatePbuffer(dpy, chosenFBConfig, pbAttribs); + + if (pBuffer) { + gFBconfig = chosenFBConfig; + gWidth = width; + gHeight = height; + } + + XFree(fbConfigs); + + return pBuffer; +} + + + +/* + * Do all the X / GLX setup stuff. + */ +static int +Setup(int width, int height) +{ +#if defined(GLX_VERSION_1_3) || defined(GLX_VERSION_1_4) + GLXContext glCtx; + + /* Open the X display */ + gDpy = XOpenDisplay(NULL); + if (!gDpy) { + printf("Error: couldn't open default X display.\n"); + return 0; + } + + /* Get default screen */ + gScreen = DefaultScreen(gDpy); + + /* Test that GLX is available */ + if (!RuntimeQueryGLXVersion(gDpy, gScreen)) { + printf("Error: GLX 1.3 or 1.4 not available\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Create Pbuffer */ + gPBuffer = MakePbuffer( gDpy, gScreen, width, height ); + if (gPBuffer==None) { + printf("Error: couldn't create pbuffer\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Create GLX context */ + glCtx = glXCreateNewContext(gDpy, gFBconfig, GLX_RGBA_TYPE, NULL, True); + if (glCtx) { + if (!glXIsDirect(gDpy, glCtx)) { + printf("Warning: using indirect GLXContext\n"); + } + } + else { + printf("Error: Couldn't create GLXContext\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Bind context to pbuffer */ + if (!glXMakeCurrent(gDpy, gPBuffer, glCtx)) { + printf("Error: glXMakeCurrent failed\n"); + XCloseDisplay(gDpy); + return 0; + } + + return 1; /* Success!! */ +#else + printf("Error: GLX version 1.3 or 1.4 not available at compile time\n"); + return 0; +#endif +} + + + +/* One-time GL setup */ +static void +InitGL(void) +{ + static GLfloat pos[4] = {0.0, 0.0, 10.0, 0.0}; + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_NORMALIZE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + + glViewport(0, 0, gWidth, gHeight); + 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 ); + +} + + +/* Return random float in [0,1] */ +static float +Random(void) +{ + int i = rand(); + return (float) (i % 1000) / 1000.0; +} + + +static void +RandomColor(void) +{ + GLfloat c[4]; + c[0] = Random(); + c[1] = Random(); + c[2] = Random(); + c[3] = 1.0; + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c); +} + + +/* This function borrowed from Mark Kilgard's GLUT */ +static void +drawBox(GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1, + GLfloat z0, GLfloat z1, GLenum type) +{ + static GLfloat n[6][3] = + { + {-1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {1.0, 0.0, 0.0}, + {0.0, -1.0, 0.0}, + {0.0, 0.0, 1.0}, + {0.0, 0.0, -1.0} + }; + static GLint faces[6][4] = + { + {0, 1, 2, 3}, + {3, 2, 6, 7}, + {7, 6, 5, 4}, + {4, 5, 1, 0}, + {5, 6, 2, 1}, + {7, 4, 0, 3} + }; + GLfloat v[8][3], tmp; + GLint i; + + if (x0 > x1) { + tmp = x0; + x0 = x1; + x1 = tmp; + } + if (y0 > y1) { + tmp = y0; + y0 = y1; + y1 = tmp; + } + if (z0 > z1) { + tmp = z0; + z0 = z1; + z1 = tmp; + } + v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0; + v[4][0] = v[5][0] = v[6][0] = v[7][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[3][2] = v[4][2] = v[7][2] = z0; + v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1; + + for (i = 0; i < 6; i++) { + glBegin(type); + glNormal3fv(&n[i][0]); + glVertex3fv(&v[faces[i][0]][0]); + glVertex3fv(&v[faces[i][1]][0]); + glVertex3fv(&v[faces[i][2]][0]); + glVertex3fv(&v[faces[i][3]][0]); + glEnd(); + } +} + + + +/* Render a scene */ +static void +Render(void) +{ + int NumBoxes = 100; + int i; + + InitGL(); + glClearColor(0.2, 0.2, 0.9, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + for (i=0;i<NumBoxes;i++) { + float tx = -2.0 + 4.0 * Random(); + float ty = -2.0 + 4.0 * Random(); + float tz = 4.0 - 16.0 * Random(); + float sx = 0.1 + Random() * 0.4; + float sy = 0.1 + Random() * 0.4; + float sz = 0.1 + Random() * 0.4; + float rx = Random(); + float ry = Random(); + float rz = Random(); + float ra = Random() * 360.0; + glPushMatrix(); + glTranslatef(tx, ty, tz); + glRotatef(ra, rx, ry, rz); + glScalef(sx, sy, sz); + RandomColor(); + drawBox(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, GL_POLYGON); + glPopMatrix(); + } + + glFinish(); +} + + + +static void +WriteFile(const char *filename) +{ + FILE *f; + GLubyte *image; + int i; + + image = malloc(gWidth * gHeight * 3 * sizeof(GLubyte)); + if (!image) { + printf("Error: couldn't allocate image buffer\n"); + return; + } + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, gWidth, gHeight, GL_RGB, GL_UNSIGNED_BYTE, image); + + f = fopen(filename, "w"); + if (!f) { + printf("Couldn't open image file: %s\n", filename); + return; + } + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by %s\n", "trdemo2"); + fprintf(f,"%i %i\n", gWidth, gHeight); + fprintf(f,"255\n"); + fclose(f); + f = fopen(filename, "ab"); /* now append binary data */ + if (!f) { + printf("Couldn't append to image file: %s\n", filename); + return; + } + + for (i=0;i<gHeight;i++) { + GLubyte *rowPtr; + /* Remember, OpenGL images are bottom to top. Have to reverse. */ + rowPtr = image + (gHeight-1-i) * gWidth*3; + fwrite(rowPtr, 1, gWidth*3, f); + } + + fclose(f); + free(image); + + printf("Wrote %d by %d image file: %s\n", gWidth, gHeight, filename); +} + + + +/* + * Print message describing command line parameters. + */ +static void +Usage(const char *appName) +{ + printf("Usage:\n"); + printf(" %s width height imgfile\n", appName); + printf("Where imgfile is a ppm file\n"); +} + + + +int +main(int argc, char *argv[]) +{ + if (argc!=4) { + Usage(argv[0]); + } + else { + int width = atoi(argv[1]); + int height = atoi(argv[2]); + char *fileName = argv[3]; + if (width<=0) { + printf("Error: width parameter must be at least 1.\n"); + return 1; + } + if (height<=0) { + printf("Error: height parameter must be at least 1.\n"); + return 1; + } + if (!Setup(width, height)) { + return 1; + } + + printf("Setup completed\n"); + Render(); + printf("Render completed.\n"); + WriteFile(fileName); + printf("File write completed.\n"); + + glXDestroyPbuffer( gDpy, gPBuffer ); + } + return 0; +} + diff --git a/progs/xdemos/glxpixmap.c b/progs/xdemos/glxpixmap.c new file mode 100644 index 00000000000..9db4df2c8b8 --- /dev/null +++ b/progs/xdemos/glxpixmap.c @@ -0,0 +1,186 @@ + + +/* + * A demonstration of using the GLXPixmap functions. This program is in + * the public domain. + * + * Brian Paul + */ + + +#include <GL/gl.h> +#define GLX_GLXEXT_PROTOTYPES +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +static GLXContext ctx; +static XVisualInfo *visinfo; +static GC gc; + + + +static Window make_rgb_window( Display *dpy, + unsigned int width, unsigned int height ) +{ + const int sbAttrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + const int dbAttrib[] = { 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; + + scrnum = DefaultScreen( dpy ); + root = RootWindow( dpy, scrnum ); + + visinfo = glXChooseVisual( dpy, scrnum, (int *) sbAttrib ); + if (!visinfo) { + visinfo = glXChooseVisual( dpy, scrnum, (int *) dbAttrib ); + if (!visinfo) { + printf("Error: couldn't get an RGB 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 ); + + /* need indirect context */ + ctx = glXCreateContext( dpy, visinfo, NULL, False ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(-1); + } + + printf("Direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); + + return win; +} + + +static GLXPixmap make_pixmap( Display *dpy, Window win, + unsigned int width, unsigned int height, + Pixmap *pixmap) +{ + Pixmap pm; + GLXPixmap glxpm; + XWindowAttributes attr; + + pm = XCreatePixmap( dpy, win, width, height, visinfo->depth ); + if (!pm) { + printf("Error: XCreatePixmap failed\n"); + exit(-1); + } + + 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 + if (strstr(glXQueryExtensionsString(dpy, 0), "GLX_MESA_pixmap_colormap")) { + /* stand-alone Mesa, specify the colormap */ + glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap ); + } + else { + glxpm = glXCreateGLXPixmap( dpy, visinfo, pm ); + } +#else + /* This will work with Mesa too if the visual is TrueColor or DirectColor */ + glxpm = glXCreateGLXPixmap( dpy, visinfo, pm ); +#endif + + if (!glxpm) { + printf("Error: GLXCreateGLXPixmap failed\n"); + exit(-1); + } + + *pixmap = pm; + + 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; + Pixmap pm; + GLXPixmap glxpm; + + dpy = XOpenDisplay(NULL); + + win = make_rgb_window( dpy, 300, 300 ); + glxpm = make_pixmap( dpy, win, 300, 300, &pm ); + + glXMakeCurrent( dpy, glxpm, ctx ); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* 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(); + + XMapWindow( dpy, win ); + + event_loop( dpy, pm ); + return 0; +} diff --git a/progs/xdemos/glxswapcontrol.c b/progs/xdemos/glxswapcontrol.c new file mode 100644 index 00000000000..0ed5ebe4722 --- /dev/null +++ b/progs/xdemos/glxswapcontrol.c @@ -0,0 +1,824 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT) + * Port by Brian Paul 23 March 2001 + * + * Modified by Ian Romanick <[email protected]> 09 April 2003 to support + * GLX_{MESA,SGI}_swap_control and GLX_OML_sync_control. + * + * Command line options: + * -display Name of the display to use. + * -info print GL implementation information + * -swap N Attempt to set the swap interval to 1/N second + * -forcegetrate Get the display refresh rate even if the required GLX + * extension is not supported. + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#ifndef __VMS +/*# include <stdint.h>*/ +#endif +# define GLX_GLXEXT_PROTOTYPES +#include <GL/gl.h> +#include <GL/glx.h> + +#ifndef GLX_MESA_swap_control +typedef GLint ( * PFNGLXSWAPINTERVALMESAPROC) (unsigned interval); +typedef GLint ( * PFNGLXGETSWAPINTERVALMESAPROC) ( void ); +#endif + +#if !defined( GLX_OML_sync_control ) && defined( _STDINT_H ) +#define GLX_OML_sync_control 1 +typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); +#endif + +#ifndef GLX_MESA_swap_frame_usage +#define GLX_MESA_swap_frame_usage 1 +typedef int ( * PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float * usage ); +#endif + +#define BENCHMARK + +PFNGLXGETFRAMEUSAGEMESAPROC get_frame_usage = NULL; + +#ifdef BENCHMARK + +/* XXX this probably isn't very portable */ + +#include <sys/time.h> +#include <unistd.h> + +#define NUL '\0' + +/* return current time (in seconds) */ +static int +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (int) tv.tv_sec; +} + +#else /*BENCHMARK*/ + +/* dummy */ +static int +current_time(void) +{ + return 0; +} + +#endif /*BENCHMARK*/ + + + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + + +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 GLboolean has_OML_sync_control = GL_FALSE; +static GLboolean has_SGI_swap_control = GL_FALSE; +static GLboolean has_MESA_swap_control = GL_FALSE; +static GLboolean has_MESA_swap_frame_usage = GL_FALSE; + +static char ** extension_table = NULL; +static unsigned num_extensions; + +static GLboolean use_ztrick = GL_FALSE; +static GLfloat aspect; + +/* + * + * 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 void +draw(void) +{ + if ( use_ztrick ) { + static GLboolean flip = GL_FALSE; + static const GLfloat vert[4][3] = { + { -1, -1, -0.999 }, + { 1, -1, -0.999 }, + { 1, 1, -0.999 }, + { -1, 1, -0.999 } + }; + static const GLfloat col[4][3] = { + { 1.0, 0.6, 0.0 }, + { 1.0, 0.6, 0.0 }, + { 0.0, 0.0, 0.0 }, + { 0.0, 0.0, 0.0 }, + }; + + if ( flip ) { + glDepthRange(0, 0.5); + glDepthFunc(GL_LEQUAL); + } + else { + glDepthRange(1.0, 0.4999); + glDepthFunc(GL_GEQUAL); + } + + flip = !flip; + + /* The famous Quake "Z trick" only works when the whole screen is + * re-drawn each frame. + */ + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 1); + glDisable(GL_LIGHTING); + glShadeModel(GL_SMOOTH); + + glEnable( GL_VERTEX_ARRAY ); + glEnable( GL_COLOR_ARRAY ); + glVertexPointer( 3, GL_FLOAT, 0, vert ); + glColorPointer( 3, GL_FLOAT, 0, col ); + glDrawArrays( GL_POLYGON, 0, 4 ); + glDisable( GL_COLOR_ARRAY ); + glDisable( GL_VERTEX_ARRAY ); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -aspect, aspect, 5.0, 60.0); + + glEnable(GL_LIGHTING); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); + } + else { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); +} + + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + aspect = (GLfloat) height / (GLfloat) width; + + + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glFrustum(-1.0, 1.0, -aspect, aspect, 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); +} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, GLXContext *ctxRet) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + 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 | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win) +{ + float frame_usage = 0.0; + + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + if (code == XK_Left) { + view_roty += 5.0; + } + else if (code == XK_Right) { + view_roty -= 5.0; + } + else if (code == XK_Up) { + view_rotx += 5.0; + } + else if (code == XK_Down) { + view_rotx -= 5.0; + } + else { + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + } + } + } + } + + /* next frame */ + angle += 2.0; + + draw(); + if ( get_frame_usage != NULL ) { + GLfloat temp; + + (*get_frame_usage)( dpy, win, & temp ); + frame_usage += temp; + } + + glXSwapBuffers(dpy, win); + + /* calc framerate */ + { + static int t0 = -1; + static int frames = 0; + int t = current_time(); + + if (t0 < 0) + t0 = t; + + frames++; + + if (t - t0 >= 5.0) { + GLfloat seconds = t - t0; + GLfloat fps = frames / seconds; + if ( get_frame_usage != NULL ) { + printf("%d frames in %3.1f seconds = %6.3f FPS (%3.1f%% usage)\n", + frames, seconds, fps, + (frame_usage * 100.0) / (float) frames ); + } + else { + printf("%d frames in %3.1f seconds = %6.3f FPS\n", + frames, seconds, fps); + } + + t0 = t; + frames = 0; + frame_usage = 0.0; + } + } + } +} + + +/** + * Display the refresh rate of the display using the GLX_OML_sync_control + * extension. + */ + +static void +show_refresh_rate( Display * dpy ) +{ +#if defined(GLX_OML_sync_control) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) + PFNGLXGETMSCRATEOMLPROC get_msc_rate; + int32_t n; + int32_t d; + + get_msc_rate = (PFNGLXGETMSCRATEOMLPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetMscRateOML" ); + if ( get_msc_rate != NULL ) { + (*get_msc_rate)( dpy, glXGetCurrentDrawable(), &n, &d ); + printf( "refresh rate: %.1fHz\n", (float) n / d ); + return; + } +#endif + printf( "glXGetMscRateOML not supported.\n" ); +} + + +/** + * Fill in the table of extension strings from a supplied extensions string + * (as returned by glXQueryExtensionsString). + * + * \param string String of GLX extensions. + * \sa is_extension_supported + */ + +static void +make_extension_table( const char * string ) +{ + char ** string_tab; + unsigned num_strings; + unsigned base; + unsigned idx; + unsigned i; + + /* Count the number of spaces in the string. That gives a base-line + * figure for the number of extension in the string. + */ + + num_strings = 1; + for ( i = 0 ; string[i] != NUL ; i++ ) { + if ( string[i] == ' ' ) { + num_strings++; + } + } + + string_tab = (char **) malloc( sizeof( char * ) * num_strings ); + if ( string_tab == NULL ) { + return; + } + + base = 0; + idx = 0; + + while ( string[ base ] != NUL ) { + /* Determine the length of the next extension string. + */ + + for ( i = 0 + ; (string[ base + i ] != NUL) && (string[ base + i ] != ' ') + ; i++ ) { + /* empty */ ; + } + + if ( i > 0 ) { + /* If the string was non-zero length, add it to the table. We + * can get zero length strings if there is a space at the end of + * the string or if there are two (or more) spaces next to each + * other in the string. + */ + + string_tab[ idx ] = malloc( sizeof( char ) * (i + 1) ); + if ( string_tab[ idx ] == NULL ) { + return; + } + + (void) memcpy( string_tab[ idx ], & string[ base ], i ); + string_tab[ idx ][i] = NUL; + idx++; + } + + + /* Skip to the start of the next extension string. + */ + + for ( base += i + ; (string[ base ] == ' ') && (string[ base ] != NUL) + ; base++ ) { + /* empty */ ; + } + } + + extension_table = string_tab; + num_extensions = idx; +} + + +/** + * Determine of an extension is supported. The extension string table + * must have already be initialized by calling \c make_extension_table. + * + * \praram ext Extension to be tested. + * \return GL_TRUE of the extension is supported, GL_FALSE otherwise. + * \sa make_extension_table + */ + +static GLboolean +is_extension_supported( const char * ext ) +{ + unsigned i; + + for ( i = 0 ; i < num_extensions ; i++ ) { + if ( strcmp( ext, extension_table[i] ) == 0 ) { + return GL_TRUE; + } + } + + return GL_FALSE; +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + Window win; + GLXContext ctx; + char *dpyName = ":0"; + int swap_interval = 1; + GLboolean do_swap_interval = GL_FALSE; + GLboolean force_get_rate = GL_FALSE; + GLboolean printInfo = GL_FALSE; + int i; + PFNGLXSWAPINTERVALMESAPROC set_swap_interval = NULL; + PFNGLXGETSWAPINTERVALMESAPROC get_swap_interval = NULL; + + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else if (strcmp(argv[i], "-swap") == 0 && i + 1 < argc) { + swap_interval = atoi( argv[i+1] ); + do_swap_interval = GL_TRUE; + i++; + } + else if (strcmp(argv[i], "-forcegetrate") == 0) { + /* This option was put in because some DRI drivers don't support the + * full GLX_OML_sync_control extension, but they do support + * glXGetMscRateOML. + */ + force_get_rate = GL_TRUE; + } + else if (strcmp(argv[i], "-ztrick") == 0) { + use_ztrick = GL_TRUE; + } + else if (strcmp(argv[i], "-help") == 0) { + printf("Usage:\n"); + printf(" gears [options]\n"); + printf("Options:\n"); + printf(" -help Print this information\n"); + printf(" -display displayName Specify X display\n"); + printf(" -info Display GL information\n"); + printf(" -swap N Swap no more than once per N vertical refreshes\n"); + printf(" -forcegetrate Try to use glXGetMscRateOML function\n"); + return 0; + } + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", dpyName); + return -1; + } + + make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + make_extension_table( (char *) glXQueryExtensionsString(dpy,DefaultScreen(dpy)) ); + has_OML_sync_control = is_extension_supported( "GLX_OML_sync_control" ); + has_SGI_swap_control = is_extension_supported( "GLX_SGI_swap_control" ); + has_MESA_swap_control = is_extension_supported( "GLX_MESA_swap_control" ); + has_MESA_swap_frame_usage = is_extension_supported( "GLX_MESA_swap_frame_usage" ); + + if ( has_MESA_swap_control ) { + set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalMESA" ); + get_swap_interval = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetSwapIntervalMESA" ); + } + else if ( has_SGI_swap_control ) { + set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalSGI" ); + } + + + if ( has_MESA_swap_frame_usage ) { + get_frame_usage = (PFNGLXGETFRAMEUSAGEMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetFrameUsageMESA" ); + } + + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + if ( has_OML_sync_control || force_get_rate ) { + show_refresh_rate( dpy ); + } + + if ( get_swap_interval != NULL ) { + printf("Default swap interval = %d\n", (*get_swap_interval)() ); + } + } + + if ( do_swap_interval ) { + if ( set_swap_interval != NULL ) { + if ( ((swap_interval == 0) && !has_MESA_swap_control) + || (swap_interval < 0) ) { + printf( "Swap interval must be non-negative or greater than zero " + "if GLX_MESA_swap_control is not supported.\n" ); + } + else { + (*set_swap_interval)( swap_interval ); + } + + if ( printInfo && (get_swap_interval != NULL) ) { + printf("Current swap interval = %d\n", (*get_swap_interval)() ); + } + } + else { + printf("Unable to set swap-interval. Neither GLX_SGI_swap_control " + "nor GLX_MESA_swap_control are supported.\n" ); + } + } + + init(); + + event_loop(dpy, win); + + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} diff --git a/progs/xdemos/manywin.c b/progs/xdemos/manywin.c new file mode 100644 index 00000000000..c9cca751341 --- /dev/null +++ b/progs/xdemos/manywin.c @@ -0,0 +1,393 @@ +/* + * Create N GLX windows/contexts and render to them in round-robin order. + * Also, have the contexts share all texture objects. + * Press 'd' to delete a texture, 'u' to unbind it. + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include <GL/gl.h> +#include <GL/glx.h> +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <X11/keysym.h> + + +/* + * Each display/window/context: + */ +struct head { + char DisplayName[1000]; + Display *Dpy; + Window Win; + GLXContext Context; + float Angle; + char Renderer[1000]; + char Vendor[1000]; + char Version[1000]; +}; + + +#define MAX_HEADS 200 +static struct head Heads[MAX_HEADS]; +static int NumHeads = 0; +static GLboolean SwapSeparate = GL_TRUE; +static GLuint TexObj = 0; + + +static void +Error(const char *display, const char *msg) +{ + fprintf(stderr, "Error on display %s - %s\n", display, msg); + exit(1); +} + + +static struct head * +AddHead(const char *displayName, const char *name) +{ + Display *dpy; + Window win; + GLXContext ctx; + 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; + XVisualInfo *visinfo; + int width = 90, height = 90; + int xpos = 0, ypos = 0; + + if (NumHeads >= MAX_HEADS) + return NULL; + + dpy = XOpenDisplay(displayName); + if (!dpy) { + Error(displayName, "Unable to open display"); + return NULL; + } + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, attrib); + if (!visinfo) { + Error(displayName, "Unable to find RGB, double-buffered visual"); + return NULL; + } + + /* window attributes */ + xpos = (NumHeads % 10) * 100; + ypos = (NumHeads / 10) * 100; + printf("%d, %d\n", xpos, ypos); + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error(displayName, "Couldn't create window"); + return NULL; + } + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + if (NumHeads == 0) { + ctx = glXCreateContext(dpy, visinfo, NULL, True); + } + else { + /* share textures & dlists with 0th context */ + printf("sharing\n"); + ctx = glXCreateContext(dpy, visinfo, Heads[0].Context, True); + } + if (!ctx) { + Error(displayName, "Couldn't create GLX context"); + return NULL; + } + + XMapWindow(dpy, win); + + if (!glXMakeCurrent(dpy, win, ctx)) { + Error(displayName, "glXMakeCurrent failed"); + printf("glXMakeCurrent failed in Redraw()\n"); + return NULL; + } + + if (NumHeads == 0) { + /* create texture object now */ + static const GLubyte checker[2][2][4] = { + { {255, 255, 255, 255}, { 0, 0, 0, 255} }, + { { 0, 0, 0, 0}, {255, 255, 255, 255} } + }; + glGenTextures(1, &TexObj); + assert(TexObj); + glBindTexture(GL_TEXTURE_2D, TexObj); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGB, + GL_UNSIGNED_BYTE, checker); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + else { + /* bind 0th context's texture in this context too */ + assert(TexObj); + glBindTexture(GL_TEXTURE_2D, TexObj); + } + glEnable(GL_TEXTURE_2D); + + /* save the info for this head */ + { + struct head *h = &Heads[NumHeads]; + strcpy(h->DisplayName, name); + h->Dpy = dpy; + h->Win = win; + h->Context = ctx; + h->Angle = 0.0; + strcpy(h->Version, (char *) glGetString(GL_VERSION)); + strcpy(h->Vendor, (char *) glGetString(GL_VENDOR)); + strcpy(h->Renderer, (char *) glGetString(GL_RENDERER)); + NumHeads++; + return &Heads[NumHeads-1]; + } + +} + + +static void +DestroyHeads(void) +{ + int i; + for (i = 0; i < NumHeads; i++) { + XDestroyWindow(Heads[i].Dpy, Heads[i].Win); + glXDestroyContext(Heads[i].Dpy, Heads[i].Context); + XCloseDisplay(Heads[i].Dpy); + } +} + + +static void +Redraw(struct head *h) +{ + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed"); + printf("glXMakeCurrent failed in Redraw()\n"); + return; + } + + h->Angle += 1.0; + + glShadeModel(GL_FLAT); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* draw green triangle */ + glColor3f(0.0, 1.0, 0.0); + glPushMatrix(); + glRotatef(h->Angle, 0, 0, 1); + glBegin(GL_TRIANGLES); + glTexCoord2f(0.5, 1.0); glVertex2f(0, 0.8); + glTexCoord2f(0.0, 0.0); glVertex2f(-0.8, -0.7); + glTexCoord2f(1.0, 0.0); glVertex2f(0.8, -0.7); + glEnd(); + glPopMatrix(); + + if (!SwapSeparate) + glXSwapBuffers(h->Dpy, h->Win); +} + + +static void +Swap(struct head *h) +{ + glXSwapBuffers(h->Dpy, h->Win); +} + + +static void +Resize(const struct head *h, unsigned int width, unsigned int height) +{ + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed in Resize()"); + return; + } + glFlush(); + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); +} + + + +static void +EventLoop(void) +{ + while (1) { + int i; + for (i = 0; i < NumHeads; i++) { + struct head *h = &Heads[i]; + while (XPending(h->Dpy) > 0) { + XEvent event; + XNextEvent(h->Dpy, &event); + if (event.xany.window == h->Win) { + switch (event.type) { + case Expose: + Redraw(h); + if (SwapSeparate) + Swap(h); + break; + case ConfigureNotify: + Resize(h, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buf[100]; + KeySym keySym; + XComposeStatus stat; + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat); + switch (keySym) { + case XK_Escape: + exit(0); + break; + case XK_d: + case XK_D: + printf("Delete Texture in window %d\n", i); + glXMakeCurrent(h->Dpy, h->Win, h->Context); + glDeleteTextures(1, &TexObj); + break; + case XK_u: + case XK_U: + printf("Unbind Texture in window %d\n", i); + glXMakeCurrent(h->Dpy, h->Win, h->Context); + glBindTexture(GL_TEXTURE_2D, 0); + break; + } + } + break; + default: + /*no-op*/ ; + } + } + else { + printf("window mismatch\n"); + } + } + } + + /* redraw all windows */ + for (i = 0; i < NumHeads; i++) { + Redraw(&Heads[i]); + } + /* swapbuffers on all windows, if not already done */ + if (SwapSeparate) { + for (i = 0; i < NumHeads; i++) { + Swap(&Heads[i]); + } + } + usleep(1); + } +} + + + +static void +PrintInfo(const struct head *h) +{ + printf("Name: %s\n", h->DisplayName); + printf(" Display: %p\n", (void *) h->Dpy); + printf(" Window: 0x%x\n", (int) h->Win); + printf(" Context: 0x%lx\n", (long) h->Context); + printf(" GL_VERSION: %s\n", h->Version); + printf(" GL_VENDOR: %s\n", h->Vendor); + printf(" GL_RENDERER: %s\n", h->Renderer); +} + + +int +main(int argc, char *argv[]) +{ + char *dpyName = NULL; + int i; + + if (argc == 1) { + printf("manywin: open N simultaneous glx windows\n"); + printf("Usage:\n"); + printf(" manywin [-s] numWindows\n"); + printf("Options:\n"); + printf(" -s = swap immediately after drawing (see src code)\n"); + printf("Example:\n"); + printf(" manywin 10\n"); + return 0; + } + else { + int n = 3; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-s") == 0) { + SwapSeparate = GL_FALSE; + } + else if (strcmp(argv[i], "-display") == 0 && i < argc) { + dpyName = argv[i+1]; + i++; + } + else { + n = atoi(argv[i]); + } + } + if (n < 1) + n = 1; + + printf("%d windows\n", n); + for (i = 0; i < n; i++) { + char name[100]; + struct head *h; + sprintf(name, "%d", i); + h = AddHead(dpyName, name); + if (h) { + PrintInfo(h); + } + } + } + + EventLoop(); + DestroyHeads(); + return 0; +} diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c new file mode 100644 index 00000000000..3e92e68daa7 --- /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 <GL/glx.h> +#include <GL/glu.h> +#include <X11/keysym.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#undef GL_EXT_polygon_offset /* use GL 1.1 version instead of extension */ + + +#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/opencloseopen.c b/progs/xdemos/opencloseopen.c new file mode 100644 index 00000000000..2e4de24c71d --- /dev/null +++ b/progs/xdemos/opencloseopen.c @@ -0,0 +1,189 @@ +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2003 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <X11/Xlib.h> +#include <GL/gl.h> +#include <GL/glx.h> + +/** \file opencloseopen.c + * Simple test for Mesa bug #508473. Create a window and rendering context. + * Draw a single frame. Close the window, destroy the context, and close + * the display. Re-open the display, create a new window and context. This + * should work, but, at least as of Mesa 5.1, it segfaults. See the bug + * report for more details. + * + * Most of the code here was lifed from various other Mesa xdemos. + */ + +static void +draw(void) +{ + glViewport(0, 0, 300, 300); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_FLAT); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* draw blue quad */ + glLoadIdentity(); + glColor3f(0.3, 0.3, 1.0); + glPushMatrix(); + glRotatef(0, 0, 0, 1); + glBegin(GL_POLYGON); + glVertex2f(-0.5, -0.25); + glVertex2f( 0.5, -0.25); + glVertex2f( 0.5, 0.25); + glVertex2f(-0.5, 0.25); + glEnd(); + glPopMatrix();} + + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( const char * dpyName, const char *name, + int x, int y, int width, int height, + Display **dpyRet, Window *winRet, GLXContext *ctxRet) +{ + 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; + Display *dpy; + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", dpyName); + exit(1); + } + + *dpyRet = dpy; + 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 | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +destroy_window( Display *dpy, Window win, GLXContext ctx ) +{ + glXMakeCurrent(dpy, None, NULL); + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + Window win; + GLXContext ctx; + char *dpyName = ":0"; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + } + + printf("If this program segfaults, then Mesa bug #508473 is probably " + "back.\n"); + make_window(dpyName, "Open-close-open", 0, 0, 300, 300, &dpy, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + draw(); + glXSwapBuffers(dpy, win); + sleep(2); + + destroy_window(dpy, win, ctx); + + make_window(dpyName, "Open-close-open", 0, 0, 300, 300, &dpy, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + destroy_window(dpy, win, ctx); + + return 0; +} diff --git a/progs/xdemos/overlay.c b/progs/xdemos/overlay.c new file mode 100644 index 00000000000..4c425b64d46 --- /dev/null +++ b/progs/xdemos/overlay.c @@ -0,0 +1,245 @@ +/* + * GLX overlay test/demo. + * + * Brian Paul + * 18 July 2005 + */ + +#include <GL/gl.h> +#include <GL/glx.h> +#include <X11/keysym.h> +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +static int WinWidth = 300, WinHeight = 300; +static Window NormalWindow = 0; +static Window OverlayWindow = 0; +static GLXContext NormalContext = 0; +static GLXContext OverlayContext = 0; +static GLboolean RGBOverlay = GL_FALSE; +static GLfloat Angle = 0.0; + + +static void +RedrawNormal(Display *dpy) +{ + glXMakeCurrent(dpy, NormalWindow, NormalContext); + glViewport(0, 0, WinWidth, WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + glColor3f(1.0, 1.0, 0.0); + glPushMatrix(); + glRotatef(Angle, 0, 0, 1); + glRectf(-0.8, -0.8, 0.8, 0.8); + glPopMatrix(); + glXSwapBuffers(dpy, NormalWindow); +} + + +static void +RedrawOverlay(Display *dpy) +{ + glXMakeCurrent(dpy, OverlayWindow, OverlayContext); + glViewport(0, 0, WinWidth, WinHeight); + 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); + if (RGBOverlay) { + glColor3f(0.0, 1.0, 1.0); + } + else { + glIndexi(2); + } + glBegin(GL_LINES); + glVertex2f(-1, -1); + glVertex2f(1, 1); + glVertex2f(1, -1); + glVertex2f(-1, 1); + glEnd(); + glXSwapBuffers(dpy, OverlayWindow); +} + + +static Window +MakeWindow(Display *dpy, XVisualInfo *visinfo, Window parent, + unsigned int width, unsigned int height) +{ + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + Window win; + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, parent, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + return win; +} + + +static void +MakeNormalWindow(Display *dpy) +{ + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + int scrnum; + Window root; + 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); + } + + NormalWindow = MakeWindow(dpy, visinfo, root, WinWidth, WinHeight); + assert(NormalWindow); + + NormalContext = glXCreateContext(dpy, visinfo, NULL, True); + assert(NormalContext); +} + + +static void +MakeOverlayWindow(Display *dpy) +{ + int rgbAttribs[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_LEVEL, 1, + None + }; + int indexAttribs[] = { + /*GLX_RGBA, leave this out */ + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_LEVEL, 1, + None + }; + int scrnum; + Window root; + XVisualInfo *visinfo; + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, rgbAttribs); + if (visinfo) { + printf("Found RGB overlay visual 0x%x\n", (int) visinfo->visualid); + RGBOverlay = GL_TRUE; + } + else { + visinfo = glXChooseVisual(dpy, scrnum, indexAttribs); + if (visinfo) { + printf("Found Color Index overlay visual 0x%x\n", + (int) visinfo->visualid); + /* XXX setup the colormap entries! */ + } + else { + printf("Error: couldn't get an overlay visual!\n"); + exit(1); + } + } + + OverlayWindow = MakeWindow(dpy, visinfo, NormalWindow, WinWidth, WinHeight); + assert(OverlayWindow); + + OverlayContext = glXCreateContext(dpy, visinfo, NULL, True); + assert(OverlayContext); +} + + +static void +EventLoop(Display *dpy) +{ + XEvent event; + + while (1) { + XNextEvent(dpy, &event); + + switch (event.type) { + case Expose: + RedrawNormal(dpy); + RedrawOverlay(dpy); + break; + case ConfigureNotify: + WinWidth = event.xconfigure.width; + WinHeight = event.xconfigure.height; + if (event.xconfigure.window == NormalWindow) + XResizeWindow(dpy, OverlayWindow, WinWidth, WinHeight); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + } + else if (buffer[0] == ' ') { + Angle += 5.0; + RedrawNormal(dpy); + } + } + break; + default: + ; /* nothing */ + } + } +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy = XOpenDisplay(NULL); + + assert(dpy); + + MakeNormalWindow(dpy); + MakeOverlayWindow(dpy); + + XMapWindow(dpy, NormalWindow); + XMapWindow(dpy, OverlayWindow); + + EventLoop(dpy); + + glXDestroyContext(dpy, OverlayContext); + glXDestroyContext(dpy, NormalContext); + XDestroyWindow(dpy, OverlayWindow); + XDestroyWindow(dpy, NormalWindow); + + return 0; +} diff --git a/progs/xdemos/pbdemo.c b/progs/xdemos/pbdemo.c new file mode 100644 index 00000000000..efdfdfa4522 --- /dev/null +++ b/progs/xdemos/pbdemo.c @@ -0,0 +1,478 @@ + +/* + * This program demonstrates how to do "off-screen" rendering using + * the GLX pixel buffer extension. + * + * Written by Brian Paul for the "OpenGL and Window System Integration" + * course presented at SIGGRAPH '97. Updated on 5 October 2002. + * + * Usage: + * pbuffers width height imgfile + * Where: + * width is the width, in pixels, of the image to generate. + * height is the height, in pixels, of the image to generate. + * imgfile is the name of the PPM image file to write. + * + * + * This demo draws 3-D boxes with random orientation. A pbuffer with + * a depth (Z) buffer is prefered but if such a pbuffer can't be created + * we use a non-depth-buffered config. + * + * On machines such as the SGI Indigo you may have to reconfigure your + * display/X server to enable pbuffers. Look in the /usr/gfx/ucode/MGRAS/vof/ + * directory for display configurationswith the _pbuf suffix. Use + * setmon -x <vof> to configure your X server and display for pbuffers. + * + * O2 systems seem to support pbuffers well. + * + * IR systems (at least 1RM systems) don't have single-buffered, RGBA, + * Z-buffered pbuffer configs. BUT, they DO have DOUBLE-buffered, RGBA, + * Z-buffered pbuffers. Note how we try four different fbconfig attribute + * lists below! + */ + + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include "pbutil.h" + + +/* Some ugly global vars */ +static Display *gDpy = NULL; +static int gScreen = 0; +static FBCONFIG gFBconfig = 0; +static PBUFFER gPBuffer = 0; +static int gWidth, gHeight; +static GLXContext glCtx; + + + +/* + * Create the pbuffer and return a GLXPbuffer handle. + * + * We loop over a list of fbconfigs trying to create + * a pixel buffer. We return the first pixel buffer which we successfully + * create. + */ +static PBUFFER +MakePbuffer( Display *dpy, int screen, int width, int height ) +{ +#define NUM_FB_CONFIGS 4 + const char fbString[NUM_FB_CONFIGS][100] = { + "Single Buffered, depth buffer", + "Double Buffered, depth buffer", + "Single Buffered, no depth buffer", + "Double Buffered, no depth buffer" + }; + int fbAttribs[NUM_FB_CONFIGS][100] = { + { + /* Single buffered, with depth buffer */ + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 1, + GLX_DOUBLEBUFFER, 0, + GLX_STENCIL_SIZE, 0, + None + }, + { + /* Double buffered, with depth buffer */ + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 1, + GLX_DOUBLEBUFFER, 1, + GLX_STENCIL_SIZE, 0, + None + }, + { + /* Single bufferd, without depth buffer */ + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 0, + GLX_DOUBLEBUFFER, 0, + GLX_STENCIL_SIZE, 0, + None + }, + { + /* Double bufferd, without depth buffer */ + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE, 0, + GLX_DOUBLEBUFFER, 1, + GLX_STENCIL_SIZE, 0, + None + } + }; + Bool largest = True; + Bool preserve = False; + FBCONFIG *fbConfigs; + PBUFFER pBuffer = None; + int nConfigs; + int i; + int attempt; + + for (attempt=0; attempt<NUM_FB_CONFIGS; attempt++) { + + /* Get list of possible frame buffer configurations */ + fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs[attempt], &nConfigs); + if (nConfigs==0 || !fbConfigs) { + printf("Error: glXChooseFBConfig failed\n"); + XCloseDisplay(dpy); + return 0; + } + +#if 0 /*DEBUG*/ + for (i=0;i<nConfigs;i++) { + printf("Config %d\n", i); + PrintFBConfigInfo(dpy, screen, fbConfigs[i], 0); + } +#endif + + /* Create the pbuffer using first fbConfig in the list that works. */ + for (i=0;i<nConfigs;i++) { + pBuffer = CreatePbuffer(dpy, screen, fbConfigs[i], width, height, preserve, largest); + if (pBuffer) { + gFBconfig = fbConfigs[i]; + gWidth = width; + gHeight = height; + break; + } + } + + if (pBuffer!=None) { + break; + } + } + + if (pBuffer) { + printf("Using: %s\n", fbString[attempt]); + } + + XFree(fbConfigs); + + return pBuffer; +#undef NUM_FB_CONFIGS +} + + + +/* + * Do all the X / GLX setup stuff. + */ +static int +Setup(int width, int height) +{ + int pbSupport; + XVisualInfo *visInfo; + + /* Open the X display */ + gDpy = XOpenDisplay(NULL); + if (!gDpy) { + printf("Error: couldn't open default X display.\n"); + return 0; + } + + /* Get default screen */ + gScreen = DefaultScreen(gDpy); + + /* Test that pbuffers are available */ + pbSupport = QueryPbuffers(gDpy, gScreen); + if (pbSupport == 1) { + printf("Using GLX 1.3 Pbuffers\n"); + } + else if (pbSupport == 2) { + printf("Using SGIX Pbuffers\n"); + } + else { + printf("Error: pbuffers not available on this screen\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Create Pbuffer */ + gPBuffer = MakePbuffer( gDpy, gScreen, width, height ); + if (gPBuffer==None) { + printf("Error: couldn't create pbuffer\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Get corresponding XVisualInfo */ + visInfo = GetVisualFromFBConfig(gDpy, gScreen, gFBconfig); + if (!visInfo) { + printf("Error: can't get XVisualInfo from FBconfig\n"); + XCloseDisplay(gDpy); + return 0; + } + + /* Create GLX context */ + glCtx = glXCreateContext(gDpy, visInfo, NULL, True); + if (!glCtx) { + /* try indirect */ + glCtx = glXCreateContext(gDpy, visInfo, NULL, False); + if (!glCtx) { + printf("Error: Couldn't create GLXContext\n"); + XFree(visInfo); + XCloseDisplay(gDpy); + return 0; + } + else { + printf("Warning: using indirect GLXContext\n"); + } + } + + /* Bind context to pbuffer */ + if (!glXMakeCurrent(gDpy, gPBuffer, glCtx)) { + printf("Error: glXMakeCurrent failed\n"); + XFree(visInfo); + XCloseDisplay(gDpy); + return 0; + } + + return 1; /* Success!! */ +} + + + +/* One-time GL setup */ +static void +InitGL(void) +{ + static GLfloat pos[4] = {0.0, 0.0, 10.0, 0.0}; + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_NORMALIZE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + + glViewport(0, 0, gWidth, gHeight); + 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 ); +} + + +/* Return random float in [0,1] */ +static float +Random(void) +{ + int i = rand(); + return (float) (i % 1000) / 1000.0; +} + + +static void +RandomColor(void) +{ + GLfloat c[4]; + c[0] = Random(); + c[1] = Random(); + c[2] = Random(); + c[3] = 1.0; + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c); +} + + +/* This function borrowed from Mark Kilgard's GLUT */ +static void +drawBox(GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1, + GLfloat z0, GLfloat z1, GLenum type) +{ + static GLfloat n[6][3] = + { + {-1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {1.0, 0.0, 0.0}, + {0.0, -1.0, 0.0}, + {0.0, 0.0, 1.0}, + {0.0, 0.0, -1.0} + }; + static GLint faces[6][4] = + { + {0, 1, 2, 3}, + {3, 2, 6, 7}, + {7, 6, 5, 4}, + {4, 5, 1, 0}, + {5, 6, 2, 1}, + {7, 4, 0, 3} + }; + GLfloat v[8][3], tmp; + GLint i; + + if (x0 > x1) { + tmp = x0; + x0 = x1; + x1 = tmp; + } + if (y0 > y1) { + tmp = y0; + y0 = y1; + y1 = tmp; + } + if (z0 > z1) { + tmp = z0; + z0 = z1; + z1 = tmp; + } + v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0; + v[4][0] = v[5][0] = v[6][0] = v[7][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[3][2] = v[4][2] = v[7][2] = z0; + v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1; + + for (i = 0; i < 6; i++) { + glBegin(type); + glNormal3fv(&n[i][0]); + glVertex3fv(&v[faces[i][0]][0]); + glVertex3fv(&v[faces[i][1]][0]); + glVertex3fv(&v[faces[i][2]][0]); + glVertex3fv(&v[faces[i][3]][0]); + glEnd(); + } +} + + + +/* Render a scene */ +static void +Render(void) +{ + int NumBoxes = 100; + int i; + + glClearColor(0.2, 0.2, 0.9, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + for (i=0;i<NumBoxes;i++) { + float tx = -2.0 + 4.0 * Random(); + float ty = -2.0 + 4.0 * Random(); + float tz = 4.0 - 16.0 * Random(); + float sx = 0.1 + Random() * 0.4; + float sy = 0.1 + Random() * 0.4; + float sz = 0.1 + Random() * 0.4; + float rx = Random(); + float ry = Random(); + float rz = Random(); + float ra = Random() * 360.0; + glPushMatrix(); + glTranslatef(tx, ty, tz); + glRotatef(ra, rx, ry, rz); + glScalef(sx, sy, sz); + RandomColor(); + drawBox(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, GL_POLYGON); + glPopMatrix(); + } + + glFinish(); +} + + + +static void +WriteFile(const char *filename) +{ + FILE *f; + GLubyte *image; + int i; + + image = malloc(gWidth * gHeight * 3 * sizeof(GLubyte)); + if (!image) { + printf("Error: couldn't allocate image buffer\n"); + return; + } + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, gWidth, gHeight, GL_RGB, GL_UNSIGNED_BYTE, image); + + f = fopen(filename, "w"); + if (!f) { + printf("Couldn't open image file: %s\n", filename); + return; + } + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by %s\n", "trdemo2"); + fprintf(f,"%i %i\n", gWidth, gHeight); + fprintf(f,"255\n"); + fclose(f); + f = fopen(filename, "ab"); /* now append binary data */ + if (!f) { + printf("Couldn't append to image file: %s\n", filename); + return; + } + + for (i=0;i<gHeight;i++) { + GLubyte *rowPtr; + /* Remember, OpenGL images are bottom to top. Have to reverse. */ + rowPtr = image + (gHeight-1-i) * gWidth*3; + fwrite(rowPtr, 1, gWidth*3, f); + } + + fclose(f); + free(image); + + printf("Wrote %d by %d image file: %s\n", gWidth, gHeight, filename); +} + + + +/* + * Print message describing command line parameters. + */ +static void +Usage(const char *appName) +{ + printf("Usage:\n"); + printf(" %s width height imgfile\n", appName); + printf("Where imgfile is a ppm file\n"); +} + + + +int +main(int argc, char *argv[]) +{ + if (argc!=4) { + Usage(argv[0]); + } + else { + int width = atoi(argv[1]); + int height = atoi(argv[2]); + char *fileName = argv[3]; + if (width<=0) { + printf("Error: width parameter must be at least 1.\n"); + return 1; + } + if (height<=0) { + printf("Error: height parameter must be at least 1.\n"); + return 1; + } + if (!Setup(width, height)) { + return 1; + } + InitGL(); + Render(); + WriteFile(fileName); + DestroyPbuffer(gDpy, gScreen, gPBuffer); + } + return 0; +} + diff --git a/progs/xdemos/pbinfo.c b/progs/xdemos/pbinfo.c new file mode 100644 index 00000000000..88d93c8da62 --- /dev/null +++ b/progs/xdemos/pbinfo.c @@ -0,0 +1,106 @@ + +/* + * Print list of fbconfigs and test each to see if a pbuffer can be created + * for that config. + * + * Brian Paul + * April 1997 + * Updated on 5 October 2002. + */ + + +#include <X11/Xlib.h> +#include <stdio.h> +#include <string.h> +#include "pbutil.h" + + + + +static void +PrintConfigs(Display *dpy, int screen, Bool horizFormat) +{ + FBCONFIG *fbConfigs; + int nConfigs; + int i; + + fbConfigs = GetAllFBConfigs(dpy, screen, &nConfigs); + if (!nConfigs || !fbConfigs) { + printf("Error: glxGetFBConfigs failed\n"); + return; + } + + printf("Number of fbconfigs: %d\n", nConfigs); + + if (horizFormat) { + printf(" ID VisualType Depth Lvl RGB CI DB Stereo R G B A"); + printf(" Z S AR AG AB AA MSbufs MSnum Pbuffer Float\n"); + } + + /* Print config info */ + for (i = 0; i < nConfigs; i++) { + PrintFBConfigInfo(dpy, screen, fbConfigs[i], horizFormat); + } + + /* free the list */ + XFree(fbConfigs); +} + + + +static void +PrintUsage(void) +{ + printf("Options:\n"); + printf(" -display <display-name> specify X display name\n"); + printf(" -t print in tabular format\n"); + printf(" -v print in verbose format\n"); + printf(" -help print this information\n"); +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + int scrn; + char *dpyName = NULL; + Bool horizFormat = True; + int i; + + for (i=1; i<argc; i++) { + if (strcmp(argv[i],"-display")==0) { + if (i+1<argc) { + dpyName = argv[i+1]; + i++; + } + } + else if (strcmp(argv[i],"-t")==0) { + /* tabular format */ + horizFormat = True; + } + else if (strcmp(argv[i],"-v")==0) { + /* verbose format */ + horizFormat = False; + } + else if (strcmp(argv[i],"-help")==0) { + PrintUsage(); + return 0; + } + else { + printf("Unknown option: %s\n", argv[i]); + } + } + + dpy = XOpenDisplay(dpyName); + + if (!dpy) { + printf("Error: couldn't open display %s\n", dpyName ? dpyName : ":0"); + return 1; + } + + scrn = DefaultScreen(dpy); + PrintConfigs(dpy, scrn, horizFormat); + XCloseDisplay(dpy); + return 0; +} diff --git a/progs/xdemos/pbutil.c b/progs/xdemos/pbutil.c new file mode 100644 index 00000000000..d0bbd1b0fce --- /dev/null +++ b/progs/xdemos/pbutil.c @@ -0,0 +1,426 @@ + +/* + * OpenGL pbuffers utility functions. + * + * Brian Paul + * Original code: April 1997 + * Updated on 5 October 2002 + * Updated again on 3 January 2005 to use GLX 1.3 functions in preference + * to the GLX_SGIX_fbconfig/pbuffer extensions. + */ + +#include <stdio.h> +#include <string.h> +#include "pbutil.h" + + +/** + * Test if we pixel buffers are available for a particular X screen. + * Input: dpy - the X display + * screen - screen number + * Return: 0 = pixel buffers not available. + * 1 = pixel buffers are available via GLX 1.3. + * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer. + */ +int +QueryPbuffers(Display *dpy, int screen) +{ +#if defined(GLX_VERSION_1_3) + { + /* GLX 1.3 supports pbuffers */ + int glxVersionMajor, glxVersionMinor; + if (!glXQueryVersion(dpy, &glxVersionMajor, &glxVersionMinor)) { + /* GLX not available! */ + return 0; + } + if (glxVersionMajor * 100 + glxVersionMinor >= 103) { + return 1; + } + /* fall-through */ + } +#endif + +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + /* Try the SGIX extensions */ + { + char *extensions; + extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS); + if (!extensions || + !strstr(extensions,"GLX_SGIX_fbconfig") || + !strstr(extensions,"GLX_SGIX_pbuffer")) { + return 0; + } + return 2; + } +#endif + + return 0; +} + + + +FBCONFIG * +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + return glXChooseFBConfig(dpy, screen, attribs, nConfigs); + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs); + } +#endif + return NULL; +} + + +FBCONFIG * +GetAllFBConfigs(Display *dpy, int screen, int *nConfigs) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + return glXGetFBConfigs(dpy, screen, nConfigs); + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + /* The GLX_SGIX_fbconfig extensions says to pass NULL to get list + * of all available configurations. + */ + return glXChooseFBConfigSGIX(dpy, screen, NULL, nConfigs); + } +#endif + return NULL; +} + + +XVisualInfo * +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + return glXGetVisualFromFBConfig(dpy, config); + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + return glXGetVisualFromFBConfigSGIX(dpy, config); + } +#endif + return NULL; +} + + +/** + * Either use glXGetFBConfigAttrib() or glXGetFBConfigAttribSGIX() + * to query an fbconfig attribute. + */ +static int +GetFBConfigAttrib(Display *dpy, int screen, +#if defined(GLX_VERSION_1_3) + const GLXFBConfig config, +#elif defined(GLX_SGIX_fbconfig) + const GLXFBConfigSGIX config, +#endif + int attrib + ) +{ + int pbSupport = QueryPbuffers(dpy, screen); + int value = 0; + +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + /* ok */ + if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) { + value = 0; + } + return value; + } + /* fall-through */ +#endif + +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) { + value = 0; + } + return value; + } +#endif + + return value; +} + + + +/** + * Print parameters for a GLXFBConfig to stdout. + * Input: dpy - the X display + * screen - the X screen number + * fbConfig - the fbconfig handle + * horizFormat - if true, print in horizontal format + */ +void +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat) +{ + PBUFFER pBuffer; + int width=2, height=2; + int bufferSize, level, doubleBuffer, stereo, auxBuffers; + int redSize, greenSize, blueSize, alphaSize; + int depthSize, stencilSize; + int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize; + int sampleBuffers, samples; + int drawableType, renderType, xRenderable, xVisual, id; + int maxWidth, maxHeight, maxPixels; + int optWidth, optHeight; + int floatComponents = 0; + + /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */ + bufferSize = GetFBConfigAttrib(dpy, screen, config, GLX_BUFFER_SIZE); + level = GetFBConfigAttrib(dpy, screen, config, GLX_LEVEL); + doubleBuffer = GetFBConfigAttrib(dpy, screen, config, GLX_DOUBLEBUFFER); + stereo = GetFBConfigAttrib(dpy, screen, config, GLX_STEREO); + auxBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_AUX_BUFFERS); + redSize = GetFBConfigAttrib(dpy, screen, config, GLX_RED_SIZE); + greenSize = GetFBConfigAttrib(dpy, screen, config, GLX_GREEN_SIZE); + blueSize = GetFBConfigAttrib(dpy, screen, config, GLX_BLUE_SIZE); + alphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ALPHA_SIZE); + depthSize = GetFBConfigAttrib(dpy, screen, config, GLX_DEPTH_SIZE); + stencilSize = GetFBConfigAttrib(dpy, screen, config, GLX_STENCIL_SIZE); + accumRedSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_RED_SIZE); + accumGreenSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_GREEN_SIZE); + accumBlueSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_BLUE_SIZE); + accumAlphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_ALPHA_SIZE); + sampleBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLE_BUFFERS); + samples = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLES); + drawableType = GetFBConfigAttrib(dpy, screen, config, GLX_DRAWABLE_TYPE); + renderType = GetFBConfigAttrib(dpy, screen, config, GLX_RENDER_TYPE); + xRenderable = GetFBConfigAttrib(dpy, screen, config, GLX_X_RENDERABLE); + xVisual = GetFBConfigAttrib(dpy, screen, config, GLX_X_VISUAL_TYPE); + if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX)) + xVisual = -1; + + id = GetFBConfigAttrib(dpy, screen, config, GLX_FBCONFIG_ID); + maxWidth = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_WIDTH); + maxHeight = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_HEIGHT); + maxPixels = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_PIXELS); +#if defined(GLX_SGIX_pbuffer) + optWidth = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX); + optHeight = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX); +#else + optWidth = optHeight = 0; +#endif +#if defined(GLX_NV_float_buffer) + floatComponents = GetFBConfigAttrib(dpy, screen, config, GLX_FLOAT_COMPONENTS_NV); +#endif + + /* See if we can create a pbuffer with this config */ + pBuffer = CreatePbuffer(dpy, screen, config, width, height, False, False); + + if (horizFormat) { + printf("0x%-9x ", id); + if (xVisual==GLX_STATIC_GRAY) printf("StaticGray "); + else if (xVisual==GLX_GRAY_SCALE) printf("GrayScale "); + else if (xVisual==GLX_STATIC_COLOR) printf("StaticColor "); + else if (xVisual==GLX_PSEUDO_COLOR) printf("PseudoColor "); + else if (xVisual==GLX_TRUE_COLOR) printf("TrueColor "); + else if (xVisual==GLX_DIRECT_COLOR) printf("DirectColor "); + else printf(" -none- "); + printf(" %3d %3d %s %s %s %2s ", bufferSize, level, + (renderType & GLX_RGBA_BIT_SGIX) ? "y" : ".", + (renderType & GLX_COLOR_INDEX_BIT_SGIX) ? "y" : ".", + doubleBuffer ? "y" : ".", + stereo ? "y" : "."); + printf("%2d %2d %2d %2d ", redSize, greenSize, blueSize, alphaSize); + printf("%2d %2d ", depthSize, stencilSize); + printf("%2d %2d %2d %2d", accumRedSize, accumGreenSize, accumBlueSize, + accumAlphaSize); + printf(" %2d %2d", sampleBuffers, samples); + printf(" %s %c", pBuffer ? "y" : ".", + ".y"[floatComponents]); + printf("\n"); + } + else { + printf("Id 0x%x\n", id); + printf(" Buffer Size: %d\n", bufferSize); + printf(" Level: %d\n", level); + printf(" Double Buffer: %s\n", doubleBuffer ? "yes" : "no"); + printf(" Stereo: %s\n", stereo ? "yes" : "no"); + printf(" Aux Buffers: %d\n", auxBuffers); + printf(" Red Size: %d\n", redSize); + printf(" Green Size: %d\n", greenSize); + printf(" Blue Size: %d\n", blueSize); + printf(" Alpha Size: %d\n", alphaSize); + printf(" Depth Size: %d\n", depthSize); + printf(" Stencil Size: %d\n", stencilSize); + printf(" Accum Red Size: %d\n", accumRedSize); + printf(" Accum Green Size: %d\n", accumGreenSize); + printf(" Accum Blue Size: %d\n", accumBlueSize); + printf(" Accum Alpha Size: %d\n", accumAlphaSize); + printf(" Sample Buffers: %d\n", sampleBuffers); + printf(" Samples/Pixel: %d\n", samples); + printf(" Drawable Types: "); + if (drawableType & GLX_WINDOW_BIT) printf("Window "); + if (drawableType & GLX_PIXMAP_BIT) printf("Pixmap "); + if (drawableType & GLX_PBUFFER_BIT) printf("PBuffer"); + printf("\n"); + printf(" Render Types: "); + if (renderType & GLX_RGBA_BIT_SGIX) printf("RGBA "); + if (renderType & GLX_COLOR_INDEX_BIT_SGIX) printf("CI "); + printf("\n"); + printf(" X Renderable: %s\n", xRenderable ? "yes" : "no"); + + printf(" Pbuffer: %s\n", pBuffer ? "yes" : "no"); + printf(" Max Pbuffer width: %d\n", maxWidth); + printf(" Max Pbuffer height: %d\n", maxHeight); + printf(" Max Pbuffer pixels: %d\n", maxPixels); + printf(" Optimum Pbuffer width: %d\n", optWidth); + printf(" Optimum Pbuffer height: %d\n", optHeight); + + printf(" Float Components: %s\n", floatComponents ? "yes" : "no"); + } + + if (pBuffer) { + DestroyPbuffer(dpy, screen, pBuffer); + } +} + + + +GLXContext +CreateContext(Display *dpy, int screen, FBCONFIG config) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + /* GLX 1.3 */ + GLXContext c; + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True); + if (!c) { + /* try indirect */ + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, False); + } + return c; + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + GLXContext c; + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True); + if (!c) { + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, False); + } + return c; + } +#endif + return 0; +} + + +void +DestroyContext(Display *dpy, GLXContext ctx) +{ + glXDestroyContext(dpy, ctx); +} + + +/* This is only used by CreatePbuffer() */ +static int XErrorFlag = 0; +static int HandleXError(Display *dpy, XErrorEvent *event) +{ + XErrorFlag = 1; + return 0; +} + + +/** + * Create a Pbuffer. Use an X error handler to deal with potential + * BadAlloc errors. + * + * Input: dpy - the X display + * fbConfig - an FBConfig as returned by glXChooseFBConfigSGIX(). + * width, height - size of pixel buffer to request, in pixels. + * pbAttribs - list of optional pixel buffer attributes + * Return: a Pbuffer or None. + */ +PBUFFER +CreatePbuffer(Display *dpy, int screen, FBCONFIG config, + int width, int height, Bool largest, Bool preserve) +{ + int (*oldHandler)(Display *, XErrorEvent *); + PBUFFER pBuffer = None; + int pbSupport = QueryPbuffers(dpy, screen); + + /* Catch X protocol errors with our own error handler */ + oldHandler = XSetErrorHandler(HandleXError); + XErrorFlag = 0; + +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + /* GLX 1.3 */ + int attribs[100], i = 0; + attribs[i++] = GLX_PBUFFER_WIDTH; + attribs[i++] = width; + attribs[i++] = GLX_PBUFFER_HEIGHT; + attribs[i++] = height; + attribs[i++] = GLX_PRESERVED_CONTENTS; + attribs[i++] = preserve; + attribs[i++] = GLX_LARGEST_PBUFFER; + attribs[i++] = largest; + attribs[i++] = 0; + pBuffer = glXCreatePbuffer(dpy, config, attribs); + } + else +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + int attribs[100], i = 0; + attribs[i++] = GLX_PRESERVED_CONTENTS; + attribs[i++] = preserve; + attribs[i++] = GLX_LARGEST_PBUFFER; + attribs[i++] = largest; + attribs[i++] = 0; + pBuffer = glXCreateGLXPbufferSGIX(dpy, config, width, height, attribs); + } + else +#endif + { + pBuffer = None; + } + + /* Restore original X error handler */ + (void) XSetErrorHandler(oldHandler); + + /* Return pbuffer (may be None) */ + if (!XErrorFlag && pBuffer != None) { + /*printf("config %d worked!\n", i);*/ + return pBuffer; + } + else { + return None; + } +} + + +void +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + glXDestroyPbuffer(dpy, pbuffer); + return; + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + glXDestroyGLXPbufferSGIX(dpy, pbuffer); + return; + } +#endif +} diff --git a/progs/xdemos/pbutil.h b/progs/xdemos/pbutil.h new file mode 100644 index 00000000000..e95b2565a23 --- /dev/null +++ b/progs/xdemos/pbutil.h @@ -0,0 +1,66 @@ +/* + * OpenGL pbuffers utility functions. + * + * Brian Paul + * April 1997 + */ + + +#ifndef PBUTIL_H +#define PBUTIL_H + + +#define GLX_GLXEXT_PROTOTYPES +#include <GL/glx.h> + + +#if defined(GLX_VERSION_1_3) +#define PBUFFER GLXPbuffer +#define FBCONFIG GLXFBConfig +#elif defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) +#define PBUFFER GLXPbufferSGIX +#define FBCONFIG GLXFBConfigSGIX +#else +#define PBUFFER int +#define FBCONFIG int +#endif + + +extern int +QueryPbuffers(Display *dpy, int screen); + + +extern void +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat); + + +extern FBCONFIG * +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs); + + +extern FBCONFIG * +GetAllFBConfigs(Display *dpy, int screen, int *nConfigs); + + +extern XVisualInfo * +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config); + + +extern GLXContext +CreateContext(Display *dpy, int screen, FBCONFIG config); + + +extern void +DestroyContext(Display *dpy, GLXContext ctx); + + +extern PBUFFER +CreatePbuffer(Display *dpy, int screen, FBCONFIG config, + int width, int height, Bool preserve, Bool largest); + + +extern void +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer); + + +#endif /*PBUTIL_H*/ diff --git a/progs/xdemos/shape.c b/progs/xdemos/shape.c new file mode 100644 index 00000000000..dbbc0b4ff72 --- /dev/null +++ b/progs/xdemos/shape.c @@ -0,0 +1,394 @@ + +/* + * 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 <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <X11/extensions/shape.h> +#include <GL/glx.h> + +#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; + + +/* return current time (in seconds) */ +static double +current_time(void) +{ + struct timeval tv; +#ifdef __VMS + (void) gettimeofday(&tv, NULL ); +#else + struct timezone tz; + (void) gettimeofday(&tv, &tz); +#endif + return (double) tv.tv_sec + tv.tv_usec / 1000000.0; +} + + +/* + * Draw the OpenGL stuff and do a SwapBuffers. + */ +static void display(Display *dpy, Window win) +{ + float scale = 1.7; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glScalef(scale, scale, scale); + glRotatef(Xangle, 1.0, 0.0, 0.0); + glRotatef(Yangle, 0.0, 1.0, 0.0); + + /* + * wireframe box + */ + 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(); + + /* + * Solid box + */ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + glBegin(GL_POLYGON); + glVertex3f(1, -1, -1); + glVertex3f(1, 1, -1); + glVertex3f(1, 1, 1); + glVertex3f(1, -1, 1); + glEnd(); + + glColor3f(0, 1, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f(-1, 1, -1); + glVertex3f(-1, 1, 1); + glVertex3f(-1, -1, 1); + glEnd(); + + glColor3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, 1, -1); + glVertex3f( 1, 1, -1); + glVertex3f( 1, 1, 1); + glVertex3f(-1, 1, 1); + glEnd(); + + glColor3f(1, 0, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f( 1, -1, -1); + glVertex3f( 1, -1, 1); + glVertex3f(-1, -1, 1); + glEnd(); + + glColor3f(0, 0, 1); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 1); + glVertex3f( 1, -1, 1); + glVertex3f( 1, 1, 1); + glVertex3f(-1, 1, 1); + glEnd(); + + glColor3f(1, 1, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, -1); + glVertex3f( 1, -1, -1); + glVertex3f( 1, 1, -1); + glVertex3f(-1, 1, -1); + glEnd(); + glPopMatrix(); + + + glPopMatrix(); + + glXSwapBuffers(dpy, win); +} + + +/* + * 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;i<sides;i++) { + int x = cx + radius * sin(angle); + int y = cy - radius * cos(angle); + points[i].x = x; + points[i].y = y; + angle += step; + } + XFillPolygon(dpy, shapeMask, gc, points, sides, Convex, CoordModeOrigin); + } + + /* This is the only SHAPE extension call- simple! */ + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shapeMask, ShapeSet); + + XFreeGC(dpy, gc); + XFreePixmap(dpy, shapeMask); +} + + +/* + * Called when window is resized. Do OpenGL viewport and projection stuff. + */ +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, 3.0, 20.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); + + glEnable(GL_DEPTH_TEST); +} + + +/* + * Process X events. + */ +static void event_loop(Display *dpy, Window win) +{ + while (1) { + XEvent event; + if (XPending(dpy)) { + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + display(dpy, event.xexpose.window); + break; + case ConfigureNotify: + Width = event.xconfigure.width; + Height = event.xconfigure.height, + make_shape_mask(dpy, win, Width, Height, Sides); + reshape(Width, Height); + break; + case KeyPress: + { + char buf[100]; + KeySym keySym; + XComposeStatus stat; + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat); + switch (keySym) { + case XK_Escape: + exit(0); + break; + case XK_Up: + Sides++; + if (Sides>MaxSides) Sides = MaxSides; + make_shape_mask(dpy, win, Width, Height, Sides); + break; + case XK_Down: + Sides--; + if (Sides<MinSides) Sides = MinSides; + make_shape_mask(dpy, win, Width, Height, Sides); + break; + } + } + break; + default: + ;; + } + } + else { + static double t0 = -1.0; + double dt, t = current_time(); + if (t0 < 0.0) + t0 = t; + dt = t - t0; + Xangle += 90.0 * dt; /* 90 degrees per second */ + Yangle += 70.0 * dt; + t0 = t; + display(dpy, win); + } + } +} + + +/* + * Allocate a "nice" colormap. This could be better (HP-CR support, etc). + */ +static Colormap alloc_colormap(Display *dpy, Window parent, Visual *vis) +{ + Screen *scr = DefaultScreenOfDisplay(dpy); + int scrnum = DefaultScreen(dpy); + + if (MaxCmapsOfScreen(scr)==1 && vis==DefaultVisual(dpy, scrnum)) { + /* The window and root are of the same visual type so */ + /* share the root colormap. */ + return DefaultColormap(dpy, scrnum); + } + else { + return XCreateColormap(dpy, parent, vis, AllocNone); + } +} + + +int main(int argc, char *argv[]) +{ + static int glAttribs[] = { + GLX_DOUBLEBUFFER, + GLX_RGBA, + GLX_DEPTH_SIZE, 1, + None + }; + Display *dpy; + XVisualInfo *visInfo; + int scrn; + Window root; + Colormap cmap; + Window win; + XSetWindowAttributes winAttribs; + unsigned long winAttribsMask; + GLXContext glCtx; + int ignore; + const char *name = "OpenGL in a Shaped Window"; + + dpy = XOpenDisplay(NULL); + if (!dpy) { + fprintf(stderr, "Couldn't open default display\n"); + return 1; + } + + /* check that we can use the shape extension */ + if (!XQueryExtension(dpy, "SHAPE", &ignore, &ignore, &ignore )) { + fprintf(stderr, "Display doesn't support shape extension\n"); + return 1; + } + + scrn = DefaultScreen(dpy); + + root = RootWindow(dpy, scrn); + + visInfo = glXChooseVisual(dpy, scrn, glAttribs); + if (!visInfo) { + fprintf(stderr, "Couldn't get RGB, DB, Z visual\n"); + return 1; + } + + glCtx = glXCreateContext(dpy, visInfo, 0, True); + if (!glCtx) { + fprintf(stderr, "Couldn't create GL context\n"); + return 1; + } + + cmap = alloc_colormap(dpy, root, visInfo->visual); + 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); + + { + XSizeHints sizehints; + /* + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + */ + sizehints.flags = 0; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + + XMapWindow(dpy, win); + + glXMakeCurrent(dpy, win, glCtx); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + 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 00000000000..13d030a8bef --- /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 <vga.h> +#include <math.h> +#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;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 ); + 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 GLuint limit; +static GLuint count = 1; + + +static void draw( void ) +{ + angle += 2.0; + + 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(); + + SVGAMesaSwapBuffers(); +} + + +static void init( void ) +{ + static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.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 }; + + GLfloat w = (float) width / (float) height; + GLfloat h = 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 ); + + + glViewport( 0, 0, width, height ); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (width>height) { + 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 00000000000..991fce2a591 --- /dev/null +++ b/progs/xdemos/vindex.c @@ -0,0 +1,65 @@ + +/* + * 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 <vga.h> +#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 00000000000..e322fbc5c80 --- /dev/null +++ b/progs/xdemos/vtest.c @@ -0,0 +1,82 @@ + +/* + * 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 <vga.h> +#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/wincopy.c b/progs/xdemos/wincopy.c new file mode 100644 index 00000000000..3ec67dc6724 --- /dev/null +++ b/progs/xdemos/wincopy.c @@ -0,0 +1,329 @@ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * This program opens two GLX windows, renders into one and uses + * glCopyPixels to copy the image from the first window into the + * second by means of the GLX 1.3 function glxMakeContextCurrent(). + * This function works just like the glXMakeCurrentReadSGI() function + * in the GLX_SGI_make_current_read extension. + */ + + +#define GLX_GLXEXT_PROTOTYPES +#include <GL/gl.h> +#include <GL/glx.h> +#include <X11/keysym.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + + +#ifdef GLX_VERSION_1_3 + + +static Display *Dpy; +static int ScrNum; +static GLXContext Context; +static Window Win[2]; /* Win[0] = source, Win[1] = dest */ +static GLint Width[2], Height[2]; + +static GLfloat Angle = 0.0; + +static GLboolean DrawFront = GL_FALSE; + +PFNGLXMAKECURRENTREADSGIPROC make_context_current = NULL; + +static Window +CreateWindow(Display *dpy, int scrnum, XVisualInfo *visinfo, + int xpos, int ypos, int width, int height, + const char *name) +{ + Window win; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + + root = RootWindow(dpy, scrnum); + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (win) { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + + XMapWindow(dpy, win); + } + return win; +} + + +static void +Redraw(void) +{ + /* make the first window the current one */ + if (! (*make_context_current)(Dpy, Win[0], Win[0], Context)) { + printf("glXMakeContextCurrent failed in Redraw()\n"); + return; + } + + Angle += 1.0; + + if (DrawFront) { + glDrawBuffer(GL_FRONT); + glReadBuffer(GL_FRONT); + } + else { + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + } + + glViewport(0, 0, Width[0], Height[0]); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + + glShadeModel(GL_FLAT); + glClearColor(0.5, 0.5, 0.5, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* draw blue quad */ + glColor3f(0.3, 0.3, 1.0); + glPushMatrix(); + glRotatef(Angle, 0, 0, 1); + glBegin(GL_POLYGON); + glVertex2f(-0.5, -0.25); + glVertex2f( 0.5, -0.25); + glVertex2f( 0.5, 0.25); + glVertex2f(-0.5, 0.25); + glEnd(); + glPopMatrix(); + + if (DrawFront) + glFinish(); + else + glXSwapBuffers(Dpy, Win[0]); + + + /* copy image from window 0 to window 1 */ + if (!(*make_context_current)(Dpy, Win[1], Win[0], Context)) { + printf("glXMakeContextCurrent failed in Redraw()\n"); + return; + } + + /* raster pos setup */ + glViewport(0, 0, Width[1], Height[1]); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 1); + glRasterPos2f(-1, -1); + + /* copy the image between windows */ + glCopyPixels(0, 0, Width[0], Height[0], GL_COLOR); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + if (DrawFront) + glFinish(); + else + glXSwapBuffers(Dpy, Win[1]); +} + + + +static void +Resize(Window win, unsigned int width, unsigned int height) +{ + int i; + if (win == Win[0]) { + i = 0; + } + else { + i = 1; + } + Width[i] = width; + Height[i] = height; + if (!glXMakeCurrent(Dpy, Win[i], Context)) { + printf("glXMakeCurrent failed in Resize()\n"); + return; + } +} + + + +static void +EventLoop(void) +{ + XEvent event; + while (1) { + if (XPending(Dpy) > 0) { + XNextEvent( Dpy, &event ); + switch (event.type) { + case Expose: + Redraw(); + break; + case ConfigureNotify: + Resize(event.xany.window, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buf[100]; + KeySym keySym; + XComposeStatus stat; + XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat); + if (keySym == XK_Escape) { + /* exit */ + return; + } + else if (buf[0] == 'f') { + DrawFront = !DrawFront; + printf("Drawing to %s buffer\n", + DrawFront ? "GL_FRONT" : "GL_BACK"); + } + } + break; + default: + /*no-op*/ ; + } + } + else { + /* animate */ + Redraw(); + } + } +} + + +static void +Init(void) +{ + XVisualInfo *visinfo; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + int major, minor; + + Dpy = XOpenDisplay(NULL); + if (!Dpy) { + printf("Couldn't open default display!\n"); + exit(1); + } + + ScrNum = DefaultScreen(Dpy); + + glXQueryVersion(Dpy, &major, &minor); + + if (major * 100 + minor >= 103) { + make_context_current = (PFNGLXMAKECURRENTREADSGIPROC) + glXGetProcAddressARB( (GLubyte *) "glXMakeContextCurrent" ); + } + else { + const char * const glxExtensions = glXQueryExtensionsString(Dpy, ScrNum); + const char * ext = strstr( glxExtensions, "GLX_SGI_make_current_read" ); + const size_t len = strlen( "GLX_SGI_make_current_read" ); + + if ( (ext != NULL) + && ((ext[len] == ' ') || (ext[len] == '\0')) ) { + make_context_current = (PFNGLXMAKECURRENTREADSGIPROC) + glXGetProcAddressARB( (GLubyte *) "glXMakeCurrentReadSGI" ); + } + } + + if (make_context_current == NULL) { + fprintf(stderr, "Sorry, this program requires either GLX 1.3 " + "or GLX_SGI_make_current_read.\n"); + exit(1); + } + + visinfo = glXChooseVisual(Dpy, ScrNum, attrib); + if (!visinfo) { + printf("Unable to find RGB, double-buffered visual\n"); + exit(1); + } + + Context = glXCreateContext(Dpy, visinfo, NULL, True); + if (!Context) { + printf("Couldn't create GLX context\n"); + exit(1); + } + + + Win[0] = CreateWindow(Dpy, ScrNum, visinfo, + 0, 0, 300, 300, "source window"); + + Win[1] = CreateWindow(Dpy, ScrNum, visinfo, + 350, 0, 300, 300, "dest window"); + + printf("Press Esc to exit\n"); + printf("Press 'f' to toggle front/back buffer drawing\n"); +} + + +int +main(int argc, char *argv[]) +{ + Init(); + EventLoop(); + return 0; +} + + +#else + + +int +main(int argc, char *argv[]) +{ + printf("This program requires GLX 1.3!\n"); + return 0; +} + + +#endif /* GLX_VERSION_1_3 */ diff --git a/progs/xdemos/xdemo.c b/progs/xdemos/xdemo.c new file mode 100644 index 00000000000..52039cb6424 --- /dev/null +++ b/progs/xdemos/xdemo.c @@ -0,0 +1,334 @@ + +/* + * 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 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#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,0,0,0, /* accum_size */ + 0, /* num samples */ + 0, /* level */ + 0 /* caveat */ + ); + 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 00000000000..2585aa6447c --- /dev/null +++ b/progs/xdemos/xfont.c @@ -0,0 +1,206 @@ + +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * Example of using glXUseXFont(). + * 5 November 1999 + * Brian Paul + */ + + +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +static const char *ProgramName = "xfont"; + +static const char *FontName = "fixed"; + +static GLuint FontBase = 0; + + + +static void redraw( Display *dpy, Window w ) +{ + static const char *text = "This is glXUseXFont()"; + + glClear( GL_COLOR_BUFFER_BIT ); + + /* triangle */ + glColor3f( 0.2, 0.2, 1.0 ); + glBegin(GL_TRIANGLES); + glVertex2f( 0, 0.8 ); + glVertex2f( -0.8, -0.7 ); + glVertex2f( 0.8, -0.7 ); + glEnd(); + + /* text */ + glColor3f( 1, 1, 1 ); + glRasterPos2f(-0.8, 0); + glListBase(FontBase); + glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text); + + glXSwapBuffers( dpy, w ); +} + + + +static void resize( unsigned int width, unsigned int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); +} + + + +static void setup_font( Display *dpy ) +{ + XFontStruct *fontInfo; + Font id; + unsigned int first, last; + + fontInfo = XLoadQueryFont(dpy, FontName); + if (!fontInfo) { + printf("Error: font %s not found\n", FontName); + exit(0); + } + + id = fontInfo->fid; + first = fontInfo->min_char_or_byte2; + last = fontInfo->max_char_or_byte2; + + FontBase = glGenLists((GLuint) last + 1); + if (!FontBase) { + printf("Error: unable to allocate display lists\n"); + exit(0); + } + glXUseXFont(id, first, last - first + 1, FontBase + first); +} + +static Window make_rgb_db_window( Display *dpy, int xpos, int ypos, + 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 | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, ProgramName, ProgramName, + None, (char **)NULL, 0, &sizehints); + } + + + 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; + case KeyPress: + exit(0); + default: + ; /* no-op */ + } + } +} + + + +int main( int argc, char *argv[] ) +{ + Display *dpy; + Window win; + + dpy = XOpenDisplay(NULL); + + win = make_rgb_db_window( dpy, 0, 0, 300, 300 ); + setup_font( dpy ); + + glShadeModel( GL_FLAT ); + glClearColor( 0.5, 0.5, 1.0, 1.0 ); + + XMapWindow( dpy, win ); + + event_loop( dpy ); + return 0; +} diff --git a/progs/xdemos/xrotfontdemo.c b/progs/xdemos/xrotfontdemo.c new file mode 100644 index 00000000000..58cd0286cc6 --- /dev/null +++ b/progs/xdemos/xrotfontdemo.c @@ -0,0 +1,220 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * Example of using glXUseRotatedXFontMESA(). + * 24 Jan 2004 + * Brian Paul + */ + + +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "xuserotfont.h" + + +static const char *ProgramName = "xfont"; + +static const char *FontName = "fixed"; + +static GLuint FontBase[4]; + + +static void redraw( Display *dpy, Window w ) +{ + static const char *text = " Rotated bitmap text"; + int i; + + glClear( GL_COLOR_BUFFER_BIT ); + + /* triangle */ + glColor3f( 0.2, 0.2, 1.0 ); + glBegin(GL_TRIANGLES); + glVertex2f( -0.8, 0.7 ); + glVertex2f( -0.8, -0.7 ); + glVertex2f( 0.8, 0.0 ); + glEnd(); + + /* marker */ + glColor3f( 0, 1, 0 ); + glBegin(GL_POINTS); + glVertex2f(0, 0); + glEnd(); + + /* text */ + glColor3f( 1, 1, 1 ); + + for (i = 0; i < 4; i++) { + glRasterPos2f(0, 0); + glListBase(FontBase[i]); + glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text); + } + + glXSwapBuffers( dpy, w ); +} + + + +static void resize( unsigned int width, unsigned int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); +} + + + +static void setup_font( Display *dpy ) +{ + XFontStruct *fontInfo; + Font id; + unsigned int first, last; + int i; + + fontInfo = XLoadQueryFont(dpy, FontName); + if (!fontInfo) { + printf("Error: font %s not found\n", FontName); + exit(0); + } + + id = fontInfo->fid; + first = fontInfo->min_char_or_byte2; + last = fontInfo->max_char_or_byte2; + + for (i = 0; i < 4; i++) { + FontBase[i] = glGenLists((GLuint) last + 1); + if (!FontBase[i]) { + printf("Error: unable to allocate display lists\n"); + exit(0); + } + glXUseRotatedXFontMESA(id, first, last - first + 1, FontBase[i] + first, + i * 90); + } +} + + +static Window make_rgb_db_window( Display *dpy, int xpos, int ypos, + 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 | KeyPressMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, ProgramName, ProgramName, + None, (char **)NULL, 0, &sizehints); + } + + + 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; + case KeyPress: + exit(0); + default: + ; /* no-op */ + } + } +} + + + +int main( int argc, char *argv[] ) +{ + Display *dpy; + Window win; + + dpy = XOpenDisplay(NULL); + + win = make_rgb_db_window( dpy, 0, 0, 300, 300 ); + setup_font( dpy ); + + glShadeModel( GL_FLAT ); + glClearColor( 0.5, 0.5, 1.0, 1.0 ); + + XMapWindow( dpy, win ); + + event_loop( dpy ); + return 0; +} diff --git a/progs/xdemos/xuserotfont.c b/progs/xdemos/xuserotfont.c new file mode 100644 index 00000000000..adb849511d8 --- /dev/null +++ b/progs/xdemos/xuserotfont.c @@ -0,0 +1,399 @@ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* \file xuserotfont.c + * + * A function like glXUseXFont() but takes a 0, 90, 180 or 270 degree + * rotation angle for rotated text display. + * + * Based on Mesa's glXUseXFont implementation written by Thorsten Ohl. + */ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glx.h> +#include "xuserotfont.h" + + +/** + * Generate OpenGL-compatible bitmap by drawing an X character glyph + * to an off-screen pixmap, then getting the image and testing pixels. + * \param width bitmap width in pixels + * \param height bitmap height in pixels + */ +static void +fill_bitmap(Display *dpy, Pixmap pixmap, GC gc, + unsigned int bitmapWidth, unsigned int bitmapHeight, + unsigned int charWidth, unsigned int charHeight, + int xPos, int yPos, unsigned int c, GLubyte * bitmap, + int rotation) +{ + const int bytesPerRow = (bitmapWidth + 7) / 8; + XImage *image; + XChar2b char2b; + + /* clear pixmap to 0 */ + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, pixmap, gc, 0, 0, charWidth, charHeight); + + /* The glyph is drawn snug up against the left/top edges of the pixmap */ + XSetForeground(dpy, gc, 1); + char2b.byte1 = (c >> 8) & 0xff; + char2b.byte2 = (c & 0xff); + XDrawString16(dpy, pixmap, gc, xPos, yPos, &char2b, 1); + + /* initialize GL bitmap */ + memset(bitmap, 0, bytesPerRow * bitmapHeight); + + image = XGetImage(dpy, pixmap, 0, 0, charWidth, charHeight, 1, XYPixmap); + if (image) { + /* Set appropriate bits in the GL bitmap. + * Note: X11 and OpenGL are upside down wrt each other). + */ + unsigned int x, y; + if (rotation == 0) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int y2 = bitmapHeight - y - 1; + bitmap[bytesPerRow * y2 + x / 8] |= (1 << (7 - (x % 8))); + } + } + } + } + else if (rotation == 90) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = y; + int y2 = x; + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + else if (rotation == 180) { + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = charWidth - x - 1; + bitmap[bytesPerRow * y + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + else { + assert(rotation == 270); + for (y = 0; y < charHeight; y++) { + for (x = 0; x < charWidth; x++) { + if (XGetPixel(image, x, y)) { + int x2 = charHeight - y - 1; + int y2 = charWidth - x - 1; + bitmap[bytesPerRow * y2 + x2 / 8] |= (1 << (7 - (x2 % 8))); + } + } + } + } + XDestroyImage(image); + } +} + + +/* + * Determine if a given glyph is valid and return the + * corresponding XCharStruct. + */ +static const XCharStruct * +isvalid(const XFontStruct * fs, unsigned int which) +{ + unsigned int rows, pages; + unsigned int byte1 = 0, byte2 = 0; + int i, valid = 1; + + rows = fs->max_byte1 - fs->min_byte1 + 1; + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + + if (rows == 1) { + /* "linear" fonts */ + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) + valid = 0; + } + else { + /* "matrix" fonts */ + byte2 = which & 0xff; + byte1 = which >> 8; + if ((fs->min_char_or_byte2 > byte2) || + (fs->max_char_or_byte2 < byte2) || + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) + valid = 0; + } + + if (valid) { + if (fs->per_char) { + if (rows == 1) { + /* "linear" fonts */ + return fs->per_char + (which - fs->min_char_or_byte2); + } + else { + /* "matrix" fonts */ + i = ((byte1 - fs->min_byte1) * pages) + + (byte2 - fs->min_char_or_byte2); + return fs->per_char + i; + } + } + else { + return &fs->min_bounds; + } + } + return NULL; +} + + +void +glXUseRotatedXFontMESA(Font font, int first, int count, int listbase, + int rotation) +{ + Display *dpy; + Window win; + Pixmap pixmap; + GC gc; + XFontStruct *fs; + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + unsigned int maxCharWidth, maxCharHeight; + GLubyte *bm; + int i; + + if (rotation != 0 && + rotation != 90 && + rotation != 180 && + rotation != 270) + return; + + dpy = glXGetCurrentDisplay(); + if (!dpy) + return; /* I guess glXMakeCurrent wasn't called */ + win = RootWindow(dpy, DefaultScreen(dpy)); + + fs = XQueryFont(dpy, font); + if (!fs) { + /* + _mesa_error(NULL, GL_INVALID_VALUE, + "Couldn't get font structure information"); + */ + return; + } + + /* Allocate a GL bitmap that can fit any character */ + maxCharWidth = fs->max_bounds.rbearing - fs->min_bounds.lbearing; + maxCharHeight = fs->max_bounds.ascent + fs->max_bounds.descent; + /* use max, in case we're rotating */ + if (rotation == 90 || rotation == 270) { + /* swap width/height */ + bm = (GLubyte *) malloc((maxCharHeight + 7) / 8 * maxCharWidth); + } + else { + /* normal or upside down */ + bm = (GLubyte *) malloc((maxCharWidth + 7) / 8 * maxCharHeight); + } + if (!bm) { + XFreeFontInfo(NULL, fs, 1); + /* + _mesa_error(NULL, GL_OUT_OF_MEMORY, + "Couldn't allocate bitmap in glXUseXFont()"); + */ + return; + } + +#if 0 + /* get the page info */ + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; + lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; + rows = fs->max_byte1 - fs->min_byte1 + 1; + unsigned int first_char, last_char, pages, rows; +#endif + + /* Save the current packing mode for bitmaps. */ + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + + /* Enforce a standard packing mode which is compatible with + fill_bitmap() from above. This is actually the default mode, + except for the (non)alignment. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + /* Create pixmap and GC */ + pixmap = XCreatePixmap(dpy, win, maxCharWidth, maxCharHeight, 1); + { + XGCValues values; + unsigned long valuemask; + values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); + values.background = WhitePixel(dpy, DefaultScreen(dpy)); + values.font = fs->fid; + valuemask = GCForeground | GCBackground | GCFont; + gc = XCreateGC(dpy, pixmap, valuemask, &values); + } + +#ifdef DEBUG_XROT + if (debug_xfonts) + dump_font_struct(fs); +#endif + + for (i = 0; i < count; i++) { + const unsigned int c = first + i; + const int list = listbase + i; + unsigned int charWidth, charHeight; + unsigned int bitmapWidth = 0, bitmapHeight = 0; + GLfloat xOrig, yOrig, xStep, yStep, dtemp; + const XCharStruct *ch; + int xPos, yPos; + int valid; + + /* check on index validity and get the bounds */ + ch = isvalid(fs, c); + if (!ch) { + ch = &fs->max_bounds; + valid = 0; + } + else { + valid = 1; + } + +#ifdef DEBUG_XROT + if (debug_xfonts) { + char s[7]; + sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c); + dump_char_struct(ch, s); + } +#endif + + /* glBitmap()' parameters: + straight from the glXUseXFont(3) manpage. */ + charWidth = ch->rbearing - ch->lbearing; + charHeight = ch->ascent + ch->descent; + xOrig = -ch->lbearing; + yOrig = ch->descent; + xStep = ch->width; + yStep = 0; + + /* X11's starting point. */ + xPos = -ch->lbearing; + yPos = ch->ascent; + + /* Apply rotation */ + switch (rotation) { + case 0: + /* nothing */ + bitmapWidth = charWidth; + bitmapHeight = charHeight; + break; + case 90: + /* xStep, yStep */ + dtemp = xStep; + xStep = -yStep; + yStep = dtemp; + /* xOrig, yOrig */ + yOrig = xOrig; + xOrig = charHeight - (charHeight - yPos); + /* width, height */ + bitmapWidth = charHeight; + bitmapHeight = charWidth; + break; + case 180: + /* xStep, yStep */ + xStep = -xStep; + yStep = -yStep; + /* xOrig, yOrig */ + xOrig = charWidth - xOrig - 1; + yOrig = charHeight - yOrig - 1; + bitmapWidth = charWidth; + bitmapHeight = charHeight; + break; + case 270: + /* xStep, yStep */ + dtemp = xStep; + xStep = yStep; + yStep = -dtemp; + /* xOrig, yOrig */ + dtemp = yOrig; + yOrig = charWidth - xOrig; + xOrig = dtemp; + /* width, height */ + bitmapWidth = charHeight; + bitmapHeight = charWidth; + break; + default: + /* should never get here */ + ; + } + + glNewList(list, GL_COMPILE); + if (valid && bitmapWidth > 0 && bitmapHeight > 0) { + + fill_bitmap(dpy, pixmap, gc, bitmapWidth, bitmapHeight, + charWidth, charHeight, + xPos, yPos, c, bm, rotation); + + glBitmap(bitmapWidth, bitmapHeight, xOrig, yOrig, xStep, yStep, bm); + +#ifdef DEBUG_XROT + if (debug_xfonts) { + printf("width/height = %u/%u\n", bitmapWidth, bitmapHeight); + dump_bitmap(bitmapWidth, bitmapHeight, bm); + } +#endif + } + else { + glBitmap(0, 0, 0.0, 0.0, xStep, yStep, NULL); + } + glEndList(); + } + + free(bm); + XFreeFontInfo(NULL, fs, 1); + XFreePixmap(dpy, pixmap); + XFreeGC(dpy, gc); + + /* Restore saved packing modes. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); + glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); + glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} + + diff --git a/progs/xdemos/xuserotfont.h b/progs/xdemos/xuserotfont.h new file mode 100644 index 00000000000..ea49203b7b9 --- /dev/null +++ b/progs/xdemos/xuserotfont.h @@ -0,0 +1,12 @@ +#ifndef XUSEROTFONT_H +#define XUSEROTFONT_H + +#include <X11/Xlib.h> + + +extern void +glXUseRotatedXFontMESA(Font font, int first, int count, int listbase, + int rotation); + + +#endif diff --git a/progs/xdemos/yuvrect_client.c b/progs/xdemos/yuvrect_client.c new file mode 100644 index 00000000000..48f82cb7599 --- /dev/null +++ b/progs/xdemos/yuvrect_client.c @@ -0,0 +1,326 @@ +/* + * Test the GL_NV_texture_rectangle and GL_MESA_ycrcb_texture extensions and GLX_MESA_allocate-memory + * + * Dave Airlie - Feb 2005 + */ + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/glx.h> + +#include "../util/readtex.c" /* I know, this is a hack. */ + +#define TEXTURE_FILE "../images/girl2.rgb" + +static GLfloat Xrot = 0, Yrot = 0, Zrot = 0; +static GLint ImgWidth, ImgHeight; +static GLushort *ImageYUV = NULL; +static void *glx_memory; + +static void DrawObject(void) +{ + glBegin(GL_QUADS); + + glTexCoord2f(0, 0); + glVertex2f(-1.0, -1.0); + + glTexCoord2f(ImgWidth, 0); + glVertex2f(1.0, -1.0); + + glTexCoord2f(ImgWidth, ImgHeight); + glVertex2f(1.0, 1.0); + + glTexCoord2f(0, ImgHeight); + glVertex2f(-1.0, 1.0); + + glEnd(); +} + + +static void scr_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); + DrawObject(); + glPopMatrix(); + +} + + +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, -15.0 ); +} + +static int queryClient(Display *dpy, int screen) +{ +#ifdef GLX_MESA_allocate_memory + char *extensions; + + extensions = (char *)glXQueryExtensionsString(dpy, screen); + if (!extensions || !strstr(extensions,"GLX_MESA_allocate_memory")) { + return 0; + } + + return 1; +#else + return 0; +#endif +} + +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; +} + +static void Init( int argc, char *argv[] , Display *dpy, int screen, Window win) +{ + GLuint texObj = 100; + const char *file; + void *glx_memory; + + if (!query_extension("GL_NV_texture_rectangle")) { + printf("Sorry, GL_NV_texture_rectangle is required\n"); + exit(0); + } + + if (!query_extension("GL_MESA_ycbcr_texture")) { + printf("Sorry, GL_MESA_ycbcr_texture is required\n"); + exit(0); + } + + if (!queryClient(dpy, screen)) { + printf("Sorry, GLX_MESA_allocate_memory is required\n"); + exit(0); + } + + glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1); + glBindTexture(GL_TEXTURE_RECTANGLE_NV, texObj); +#ifdef LINEAR_FILTER + /* linear filtering looks much nicer but is much slower for Mesa */ + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#else + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +#endif + + if (argc > 1) + file = argv[1]; + else + file = TEXTURE_FILE; + + ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight); + if (!ImageYUV) { + printf("Couldn't read %s\n", TEXTURE_FILE); + exit(0); + } + + glx_memory = glXAllocateMemoryMESA(dpy, screen, ImgWidth * ImgHeight * 2, 0, 0 ,0); + if (!glx_memory) + { + fprintf(stderr,"Failed to allocate MESA memory\n"); + exit(-1); + } + + memcpy(glx_memory, ImageYUV, ImgWidth * ImgHeight * 2); + + printf("Image: %dx%d\n", ImgWidth, ImgHeight); + + glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, + GL_YCBCR_MESA, ImgWidth, ImgHeight, 0, + GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_APPLE, glx_memory); + + assert(glGetError() == GL_NO_ERROR); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glEnable(GL_TEXTURE_RECTANGLE_NV); + + glShadeModel(GL_FLAT); + glClearColor(0.3, 0.3, 0.4, 1.0); + +} + +/* + * Create an RGB, double-buffered window. + * Return the window and context handles. + */ +static void +make_window( Display *dpy, const char *name, + int x, int y, int width, int height, + Window *winRet, GLXContext *ctxRet) +{ + int attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + 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, attribs ); + 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 | KeyPressMask; + attr.override_redirect = 0; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; + + win = XCreateWindow( dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + /* set hints and properties */ + { + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + exit(1); + } + + XFree(visinfo); + + *winRet = win; + *ctxRet = ctx; +} + + +static void +event_loop(Display *dpy, Window win) +{ + while (1) { + while (XPending(dpy) > 0) { + XEvent event; + XNextEvent(dpy, &event); + switch (event.type) { + case Expose: + /* we'll redraw below */ + break; + case ConfigureNotify: + Reshape(event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + { + char buffer[10]; + int r, code; + code = XLookupKeysym(&event.xkey, 0); + r = XLookupString(&event.xkey, buffer, sizeof(buffer), + NULL, NULL); + if (buffer[0] == 27) { + /* escape */ + return; + + } + } + } + } + + } +} + + +int +main(int argc, char *argv[]) +{ + Display *dpy; + Window win; + GLXContext ctx; + char *dpyName = NULL; + GLboolean printInfo = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + dpyName = argv[i+1]; + i++; + } + else if (strcmp(argv[i], "-info") == 0) { + printInfo = GL_TRUE; + } + else + printf("Warrning: unknown parameter: %s\n", argv[i]); + } + + dpy = XOpenDisplay(dpyName); + if (!dpy) { + printf("Error: couldn't open display %s\n", + dpyName ? dpyName : getenv("DISPLAY")); + return -1; + } + + make_window(dpy, "yuvrect_client", 0, 0, 300, 300, &win, &ctx); + XMapWindow(dpy, win); + glXMakeCurrent(dpy, win, ctx); + + if (printInfo) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } + + Init(argc, argv, dpy, DefaultScreen(dpy), win); + + scr_Display(); + glXSwapBuffers(dpy, win); + event_loop(dpy, win); + + glXFreeMemoryMESA(dpy, DefaultScreen(dpy), glx_memory); + glXDestroyContext(dpy, ctx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return 0; +} |