diff options
Diffstat (limited to 'progs/redbook')
71 files changed, 11431 insertions, 0 deletions
diff --git a/progs/redbook/.cvsignore b/progs/redbook/.cvsignore new file mode 100644 index 00000000000..8ed3efe3e23 --- /dev/null +++ b/progs/redbook/.cvsignore @@ -0,0 +1,64 @@ +.cvsignore +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 diff --git a/progs/redbook/Imakefile b/progs/redbook/Imakefile new file mode 100644 index 00000000000..ab3b6d7f793 --- /dev/null +++ b/progs/redbook/Imakefile @@ -0,0 +1,221 @@ +LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\Mesaaux.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a
+
+INCLUDES = -I$(TOP)\include
+
+SRCS = accanti.c \
+ accnot.c \
+ accpersp.c \
+ accum.c \
+ aim.c \
+ alpha.c \
+ alpha3D.c \
+ anti.c \
+ antiindex.c \
+ antipindex.c \
+ antipoint.c \
+ antipoly.c \
+ bezcurve.c \
+ bezmesh.c \
+ bezsurf.c \
+ checker.c \
+ checker2.c \
+ chess.c \
+ clip.c \
+ colormat.c \
+ cone.c \
+ cube.c \
+ curve.c \
+ depthcue.c \
+ disk.c \
+ dof.c \
+ dofnot.c \
+ double.c \
+ drawf.c \
+ feedback.c \
+ fog.c \
+ fogindex.c \
+ font.c \
+ light.c \
+ linelist.c \
+ lines.c \
+ list.c \
+ list2.c \
+ maplight.c \
+ material.c \
+ mipmap.c \
+ model.c \
+ movelight.c \
+ nurbs.c \
+ pickdepth.c \
+ pickline.c \
+ picksquare.c \
+ plane.c \
+ planet.c \
+ planetup.c \
+ polys.c \
+ robot.c \
+ sccolorlight.c \
+ scene.c \
+ scenebamb.c \
+ sceneflat.c \
+ select.c \
+ simple.c \
+ smooth.c \
+ sphere.c \
+ stencil.c \
+ stroke.c \
+ surface.c \
+ tea.c \
+ teaambient.c \
+ teapots.c \
+ texgen.c \
+ texturesurf.c \
+ trim.c \
+ xfont.c
+
+PROGRAMS = ProgramTargetName(accanti) \
+ ProgramTargetName(accnot) \
+ ProgramTargetName(accpersp) \
+ ProgramTargetName(accum) \
+ ProgramTargetName(aim) \
+ ProgramTargetName(alpha) \
+ ProgramTargetName(alpha3D) \
+ ProgramTargetName(anti) \
+ ProgramTargetName(antiindex) \
+ ProgramTargetName(antipindex) \
+ ProgramTargetName(antipoint) \
+ ProgramTargetName(antipoly) \
+ ProgramTargetName(bezcurve) \
+ ProgramTargetName(bezmesh) \
+ ProgramTargetName(bezsurf) \
+ ProgramTargetName(checker) \
+ ProgramTargetName(checker2) \
+ ProgramTargetName(chess) \
+ ProgramTargetName(clip) \
+ ProgramTargetName(colormat) \
+ ProgramTargetName(cone) \
+ ProgramTargetName(cube) \
+ ProgramTargetName(curve) \
+ ProgramTargetName(depthcue) \
+ ProgramTargetName(disk) \
+ ProgramTargetName(dof) \
+ ProgramTargetName(dofnot) \
+ ProgramTargetName(double) \
+ ProgramTargetName(drawf) \
+ ProgramTargetName(feedback) \
+ ProgramTargetName(fog) \
+ ProgramTargetName(fogindex) \
+ ProgramTargetName(font) \
+ ProgramTargetName(light) \
+ ProgramTargetName(linelist) \
+ ProgramTargetName(lines) \
+ ProgramTargetName(list) \
+ ProgramTargetName(list2) \
+ ProgramTargetName(maplight) \
+ ProgramTargetName(material) \
+ ProgramTargetName(mipmap) \
+ ProgramTargetName(model) \
+ ProgramTargetName(movelight) \
+ ProgramTargetName(nurbs) \
+ ProgramTargetName(pickdepth) \
+ ProgramTargetName(pickline) \
+ ProgramTargetName(picksquare) \
+ ProgramTargetName(plane) \
+ ProgramTargetName(planet) \
+ ProgramTargetName(planetup) \
+ ProgramTargetName(polys) \
+ ProgramTargetName(robot) \
+ ProgramTargetName(sccolorlight) \
+ ProgramTargetName(scene) \
+ ProgramTargetName(scenebamb) \
+ ProgramTargetName(sceneflat) \
+ ProgramTargetName(select) \
+ ProgramTargetName(simple) \
+ ProgramTargetName(smooth) \
+ ProgramTargetName(sphere) \
+ ProgramTargetName(stencil) \
+ ProgramTargetName(stroke) \
+ ProgramTargetName(surface) \
+ ProgramTargetName(tea) \
+ ProgramTargetName(teaambient) \
+ ProgramTargetName(teapots) \
+ ProgramTargetName(texgen) \
+ ProgramTargetName(texturesurf) \
+ ProgramTargetName(trim) \
+ ProgramTargetName(xfont)
+
+AllTarget($(PROGRAMS))
+
+NormalProgramTarget(accanti,accanti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(accnot,accnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(accpersp,accpersp.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(aim,aim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(alpha,alpha.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(alpha3D,alpha3D.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(anti,anti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(antiindex,antiindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(antipindex,antipindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(antipoint,antipoint.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(antipoly,antipoly.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(bezcurve,bezcurve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(bezmesh,bezmesh.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(bezsurf,bezsurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(checker,checker.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(checker2,checker2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(chess,chess.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(clip,clip.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(colormat,colormat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(cone,cone.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(cube,cube.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(curve,curve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(depthcue,depthcue.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(disk,disk.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(dof,dof.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(dofnot,dofnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(double,double.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(drawf,drawf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(feedback,feedback.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(fogindex,fogindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(light,light.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(linelist,linelist.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(lines,lines.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(list,list.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(list2,list2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(maplight,maplight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(material,material.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(mipmap,mipmap.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(model,model.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(movelight,movelight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(nurbs,nurbs.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(pickdepth,pickdepth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(pickline,pickline.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(picksquare,picksquare.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(plane,plane.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(planet,planet.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(planetup,planetup.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(polys,polys.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(robot,robot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(sccolorlight,sccolorlight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(scene,scene.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(scenebamb,scenebamb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(sceneflat,sceneflat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(simple,simple.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(smooth,smooth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(stroke,stroke.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(surface,surface.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(tea,tea.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(teaambient,teaambient.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(teapots,teapots.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(texgen,texgen.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(texturesurf,texturesurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(trim,trim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+NormalProgramTarget(xfont,xfont.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
+
+DependTarget()
+
diff --git a/progs/redbook/Makefile b/progs/redbook/Makefile new file mode 100644 index 00000000000..4cfbb9aeacd --- /dev/null +++ b/progs/redbook/Makefile @@ -0,0 +1,39 @@ +# progs/redbook/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCDIR = $(TOP)/include + +LIB_DEP = $(LIB_DIR)/$(GL_LIB_NAME) $(LIB_DIR)/$(GLU_LIB_NAME) $(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/Windows/redbook.dsw b/progs/redbook/Windows/redbook.dsw new file mode 100644 index 00000000000..71ba7e89e3e --- /dev/null +++ b/progs/redbook/Windows/redbook.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "teapots"=".\teapots.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/progs/redbook/Windows/teapots.dsp b/progs/redbook/Windows/teapots.dsp new file mode 100644 index 00000000000..4d39865810c --- /dev/null +++ b/progs/redbook/Windows/teapots.dsp @@ -0,0 +1,112 @@ +# Microsoft Developer Studio Project File - Name="teapots" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=teapots - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "teapots.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "teapots.mak" CFG="teapots - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "teapots - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "teapots - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "teapots - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../../lib/GLUT32.LIB ../../../lib/GLU32.LIB ../../../lib/OPENGL32.LIB /nologo /subsystem:console /machine:I386 /out:"../teapots.exe"
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Desc=Copy DLLs
+PostBuild_Cmds=copy ..\..\..\lib\*.dll ..
+# End Special Build Tool
+
+!ELSEIF "$(CFG)" == "teapots - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../../lib/GLUT32.LIB ../../../lib/GLU32.LIB ../../../lib/OPENGL32.LIB /nologo /subsystem:console /debug /machine:I386 /out:"../teapots.exe" /pdbtype:sept
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Desc=Copy DLLs
+PostBuild_Cmds=copy ..\..\..\lib\*.dll ..
+# End Special Build Tool
+
+!ENDIF
+
+# Begin Target
+
+# Name "teapots - Win32 Release"
+# Name "teapots - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\teapots.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
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; +} |