Initial revision

This commit is contained in:
jtg 1999-08-19 00:55:39 +00:00
parent f2544d4920
commit afb833d4e8
359 changed files with 145077 additions and 0 deletions

1265
Make-config Normal file

File diff suppressed because it is too large Load diff

521
Makefile.X11 Normal file
View file

@ -0,0 +1,521 @@
# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:39 jtg Exp $
# Mesa 3-D graphics library
# Version: 3.1
#
# Copyright (C) 1999 Brian Paul All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Top-level makefile for Mesa
# To add a new configuration for your system add it to the list below
# then update the Make-config file.
SHELL = /bin/sh
default:
@echo "Type one of the following:"
@echo " make aix for IBM RS/6000 with AIX"
@echo " make aix-sl for IBM RS/6000, make shared libs"
@echo " make amiwin for Amiga with SAS/C and AmiWin"
@echo " make amix for Amiga 3000 UX SVR4 v2.1 systems"
@echo " make beos-r4 for BeOS R4"
@echo " make bsdos for BSD/OS from BSDI using GCC"
@echo " make bsdos4 for BSD/OS 4.x, dynamic libraries"
@echo " make cygnus for Win95/NT using Cygnus-Win32"
@echo " make cygnus-linux for Win95/NT using Cygnus-Win32 under Linux"
@echo " make dgux for Data General"
@echo " make freebsd for FreeBSD systems with GCC"
@echo " make freebsd-386 for FreeBSD systems with GCC, w/ Intel assembly"
@echo " make gcc for a generic system with GCC"
@echo " make hpux9 for HP systems with HPUX 9.x"
@echo " make hpux9-sl for HP systems with HPUX 9.x, make shared libs"
@echo " make hpux9-gcc for HP systems with HPUX 9.x using GCC"
@echo " make hpux9-gcc-sl for HP systems with HPUX 9.x, GCC, make shared libs"
@echo " make hpux10 for HP systems with HPUX 10.x"
@echo " make hpux10-sl for HP systems with HPUX 10.x, shared libs"
@echo " make hpux10-gcc for HP systems with HPUX 10.x w/ GCC"
@echo " make hpux10-gcc-sl for HP systems with HPUX 10.x w/ GCC, shared libs"
@echo " make irix4 for SGI systems with IRIX 4.x"
@echo " make irix5 for SGI systems with IRIX 5.x"
@echo " make irix5-gcc for SGI systems with IRIX 5.x using GCC"
@echo " make irix5-dso for SGI systems with IRIX 5.x, make DSOs"
@echo " make irix6-o32 for SGI systems with IRIX 6.x, make o32-bit libs"
@echo " make irix6-o32-dso for SGI systems with IRIX 6.x, make o32-bit DSOs"
@echo " make irix6-n32 for SGI systems with IRIX 6.x, make n32-bit libs"
@echo " make irix6-n32-dso for SGI systems with IRIX 6.x, make n32-bit DSOs"
@echo " make irix6-gcc-n32-sl for SGI systems with IRIX 6.x, GCC, make n32 DSOs"
@echo " make irix6-64 for SGI systems with IRIX 6.x, make 64-bit libs"
@echo " make irix6-64-dso for SGI systems with IRIX 6.x, make 64-bit DSOs"
@echo " make linux for Linux systems, make static .a libs"
@echo " make linux-elf for Linux systems, make ELF shared libs"
@echo " make linux-386 for Linux w/ Intel assembly"
@echo " make linux-386-elf for Linux w/ Intel assembly, make ELF shared libs"
@echo " make linux-ggi for Linux systems with libggi"
@echo " make linux-386-ggi for Linux systems with libggi w/ Intel assembly"
@echo " make linux-alpha for Linux on Alpha systems"
@echo " make linux-alpha-elf for Linux on Alpha systems, make ELF shared libs"
@echo " make linux-ppc for Linux on PowerPC systems"
@echo " make linux-ppc-so for Linux on PowerPC systems, make shared libs"
@echo " make linux-glide for Linux w/ 3Dfx Glide driver"
@echo " make linux-386-glide for Linux w/ 3Dfx Glide driver, Intel assembly"
@echo " make linux-386-opt-glide for Linux with 3Dfx Voodoo1 for GLQuake"
@echo " make linux-386-opt-V2-glide for Linux with 3Dfx Voodoo2 for GLQuake"
@echo " make linux-3dnow for Linux on AMD w/ 3DNow!"
@echo " make linux-3dnow-glide for Linux on AMD w/ 3DNow! for Glide"
@echo " make linux-386-pthread for Linux w/ Intel assembly and linuxthreads"
@echo " make linux-386-pthread-shared for Linux w/ Intel assembly and linuxthreads"
@echo " make linux-sparc for Linux on Sparc systems"
@echo " make linux-sparc5-elf for Sparc5 systems, make ELF shared libs"
@echo " make linux-sparc-ultra for UltraSparc systems, make ELF shared libs"
@echo " make lynxos for LynxOS systems with GCC"
@echo " make macintosh for Macintosh"
@echo " make machten-2.2 for Macs w/ MachTen 2.2 (68k w/ FPU)"
@echo " make machten-4.0 for Macs w/ MachTen 4.0.1 or newer with GNU make"
@echo " make mklinux for Linux on Power Macintosh"
@echo " make netbsd for NetBSD 1.0 systems with GCC"
@echo " make next for NeXT systems with NEXTSTEP 3.3"
@echo " make openbsd for OpenBSD systems"
@echo " make openstep for OpenStep/MacOSX Server systems"
@echo " make os2-x11 for OS/2 with XFree86"
@echo " make osf1 for DEC Alpha systems with OSF/1"
@echo " make osf1-sl for DEC Alpha systems with OSF/1, make shared libs"
@echo " make pgi-cygnus for Cygnus with Portland Group, Inc. compiler"
@echo " make pgi-mingw32 for mingW32 with Portland Group, Inc. compiler"
@echo " make qnx for QNX V4 systems with Watcom compiler"
@echo " make sco for SCO Unix systems with ODT"
@echo " make solaris-x86 for PCs with Solaris"
@echo " make solaris-x86-gcc for PCs with Solaris using GCC"
@echo " make sunos4 for Suns with SunOS 4.x"
@echo " make sunos4-sl for Suns with SunOS 4.x, make shared libs"
@echo " make sunos4-gcc for Suns with SunOS 4.x and GCC"
@echo " make sunos4-gcc-sl for Suns with SunOS 4.x, GCC, make shared libs"
@echo " make sunos5 for Suns with SunOS 5.x"
@echo " make sunos5-sl for Suns with SunOS 5.x, make shared libs"
@echo " make sunos5-ultra for Sun UltraSPARCs with SunOS 5.x"
@echo " make sunos5-ultra-sl for Sun UltraSPARCs with SunOS 5.x, make shared libs"
@echo " make sunos5-thread for Suns with SunOS 5.x, using Solaris threads"
@echo " make sunos5-pthread for Suns with SunOS 5.[56] using POSIX threads"
@echo " make sunos5-gcc-thread for Suns with SunOS 5.x and GCC, using Solaris threads"
@echo " make sunos5-gcc-pthread for Suns with SunOS 5.[56] and GCC, using POSIX threads"
@echo " make sunos5-gcc for Suns with SunOS 5.x and GCC"
@echo " make sunos5-gcc-sl for Suns with SunOS 5.x, GCC, make shared libs"
@echo " make sunos5-x11r6-gcc-sl for Suns with X11R6, GCC, make shared libs"
@echo " make sunos5-gcc-thread for Suns with SunOS 5.x and GCC, using Solaris threads"
@echo " make sunos5-gcc-pthread for Suns with SunOS 5.[56] and GCC, using POSIX threads"
@echo " make sunSolaris-CC for Solaris using C++ compiler"
@echo " make ultrix-gcc for DEC systems with Ultrix and GCC"
@echo " make unicos for Cray C90 (and other?) systems"
@echo " make unixware for PCs running UnixWare"
@echo " make unixware-shared for PCs running UnixWare, shared libs"
@echo " make uwin for Windows NT with AT&T/Wipro UWIN"
@echo " make vistra for Stardent Vistra systems"
@echo " make clean remove .o files"
@echo " make realclean remove .o, library and executable files"
aix aix-sl amix bsdos bsdos4 dgux freebsd freebsd-386 gcc \
hpux9 hpux9-sl hpux9-gcc hpux9-gcc-sl \
hpux10 hpux10-sl hpux10-gcc hpux10-gcc-sl \
irix-debug irix4 irix5 irix5-gcc irix5-dso irix6-o32 irix6-o32-dso \
linux linux-debug linux-prof linux-elf linux-elf-debug \
linux-glide linux-386-glide linux-386-opt-glide \
linux-386-opt-V2-glide \
linux-386 linux-386-elf \
linux-3dnow linux-3dnow-glide \
linux-alpha linux-alpha-elf \
linux-ppc linux-ppc-so \
linux-386-pthread linux-386-pthread-shared \
linux-sparc \
linux-sparc5-elf \
linux-sparc-ultra \
lynxos machten-2.2 machten-4.0 \
mklinux netbsd osf1 osf1-sl openbsd qnx sco \
solaris-x86 solaris-x86-gcc sunSolaris-CC \
sunos4 sunos4-sl sunos4-gcc sunos4-gcc-sl sunos4-gcc-x11r6-sl \
sunos5 sunos5-sl sunos5-ultra sunos5-ultra-sl sunos5-gcc sunos5-gcc-sl \
sunos5-thread sunos5-pthread sunos5-gcc-thread sunos5-gcc-pthread \
sunos5-x11r6-gcc-sl ultrix-gcc unicos unixware uwin vistra:
-mkdir lib
touch src/depend
touch src-glu/depend
if [ -d src-glut ] ; then touch src-glut/depend ; fi
cd src ; $(MAKE) -f Makefile.X11 $@
cd src-glu ; $(MAKE) -f Makefile.X11 $@
if [ -d src-glut ] ; then cd src-glut ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d demos ] ; then cd demos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d xdemos ] ; then cd xdemos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d samples ] ; then cd samples ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d book ] ; then cd book ; $(MAKE) -f Makefile.X11 $@ ; fi
irix6-n32 irix6-n32-dso irix6-gcc-n32-sl:
-mkdir lib32
touch src/depend
touch src-glu/depend
if [ -d src-glut ] ; then touch src-glut/depend ; fi
cd src ; $(MAKE) -f Makefile.X11 $@
cd src-glu ; $(MAKE) -f Makefile.X11 $@
if [ -d src-glut ] ; then cd src-glut ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d demos ] ; then cd demos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d xdemos ] ; then cd xdemos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d samples ] ; then cd samples ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d book ] ; then cd book ; $(MAKE) -f Makefile.X11 $@ ; fi
irix6-64 irix6-64-dso:
-mkdir lib64
touch src/depend
touch src-glu/depend
if [ -d src-glut ] ; then touch src-glut/depend ; fi
cd src ; $(MAKE) -f Makefile.X11 $@
cd src-glu ; $(MAKE) -f Makefile.X11 $@
if [ -d src-glut ] ; then cd src-glut ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d demos ] ; then cd demos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d xdemos ] ; then cd xdemos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d samples ] ; then cd samples ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d book ] ; then cd book ; $(MAKE) -f Makefile.X11 $@ ; fi
amiwin:
bin/mklib.amiwin
beos-r4:
-mkdir lib
-rm src/depend
touch src/depend
-rm src-glu/depend
touch src-glu/depend
cd src ; $(MAKE) -f Makefile.BeOS-R4 $@
cd src-glu ; $(MAKE) -f Makefile.BeOS-R4 $@
if [ -d BeOS ] ; then cd BeOS ; $(MAKE) ; fi
if [ -d src-glut.beos ] ; then cd src-glut.beos ; $(MAKE) ; fi
if [ -d src-glut.beos ] ; then cp src-glut.beos/obj*/libglut.so lib ; fi
if [ -d demos ] ; then cd demos ; $(MAKE) -f Makefile.BeOS-R4 $@ ; fi
if [ -d samples ] ; then cd samples ; $(MAKE) -f Makefile.BeOS-R4 $@ ; fi
if [ -d book ] ; then cd book ; $(MAKE) -f Makefile.BeOS-R4 $@ ; fi
pgi-cygnus pgi-mingw32 \
cygnus cygnus-linux:
-mkdir lib
touch src/depend
touch src-glu/depend
cd src ; $(MAKE) -f Makefile.X11 $@
cd src-glu ; $(MAKE) -f Makefile.X11 $@
cd src-glut ; $(MAKE) -f Makefile.X11 $@
cd demos ; $(MAKE) -f Makefile.X11 $@
if [ -d xdemos ] ; then cd xdemos ; $(MAKE) -f Makefile.X11 $@ ; fi
macintosh:
@echo "See the README file for Macintosh intallation information"
next:
-mkdir lib
cd src ; $(MAKE) -f Makefile.X11 "MYCC=${CC}" $@
cd src-glu ; $(MAKE) -f Makefile.X11 "MYCC=${CC}" $@
openstep:
-mkdir lib
cd src ; $(MAKE) -f Makefile.X11 "MYCC=${CC}" $@
cd src-glu ; $(MAKE) -f Makefile.X11 "MYCC=${CC}" $@
os2-x11:
if not EXIST .\lib md lib
touch src/depend
touch src-glu/depend
if exist src-glut touch src-glut/depend
cd src & make -f Makefile.X11 $@
cd src-glu & make -f Makefile.X11 $@
if exist src-glut cd src-glut & make -f Makefile.X11 $@
if exist demos cd demos & make -f Makefile.X11 $@
if exist xdemos cd xdemos & make -f Makefile.X11 $@
if exist samples cd samples & make -f Makefile.X11 $@
if exist book cd book & make -f Makefile.X11 $@
linux-ggi linux-386-ggi:
-mkdir lib
touch src/depend
touch src-glu/depend
if [ -d src-glut ] ; then touch src-glut/depend ; fi
if [ -d ggi ] ; then touch ggi/depend ; fi
cd src ; $(MAKE) -f Makefile.X11 $@
cd src/GGI/default ; $(MAKE)
cd src/GGI/display ; $(MAKE)
cd src-glu ; $(MAKE) -f Makefile.X11 $@
# if [ -d src-glut ] ; then cd src-glut ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d ggi ] ; then cd ggi ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d ggi ] ; then cd ggi/demos; $(MAKE) ; fi
if [ -d demos ] ; then cd demos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d xdemos ] ; then cd xdemos ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d samples ] ; then cd samples ; $(MAKE) -f Makefile.X11 $@ ; fi
if [ -d book ] ; then cd book ; $(MAKE) -f Makefile.X11 $@ ; fi
# if you change GGI_DEST please change it in ggimesa.conf, too.
DESTDIR=/usr/local
GGI_DEST=lib/ggi/mesa
linux-ggi-install linux-386-ggi-install:
install -d $(DESTDIR)/$(GGI_DEST)/default $(DESTDIR)/$(GGI_DEST)/display $(DESTDIR)/etc/ggi
install -m 0755 src/GGI/default/*.so $(DESTDIR)/$(GGI_DEST)/default
install -m 0755 src/GGI/display/*.so $(DESTDIR)/$(GGI_DEST)/display
install -m 0644 src/GGI/ggimesa.conf $(DESTDIR)/etc/ggi
# if [ -z "`grep ggimesa $(DESTDIR)/etc/ggi/libggi.conf`" ]; then \
# echo ".include $(DESTDIR)/etc/ggi/ggimesa.conf" >> $(DESTDIR)/etc/ggi/libggi.conf ; \
# fi
# Remove .o files, emacs backup files, etc.
clean:
-rm -f ggi/*~ *.o
-rm -f src/GGI/default/*~ *.so
-rm -f src/GGI/display/*~ *.so
-rm -f include/*~
-rm -f include/GL/*~
-rm -f src/*.o src/*~ src/*.a src/*/*.o src/*/*~
-rm -f src-glu/*.o src-glu/*~ src-glu/*.a
-rm -f src-glut/*.o
-rm -f demos/*.o
-rm -f book/*.o book/*~
-rm -f xdemos/*.o xdemos/*~
-rm -f samples/*.o samples/*~
-rm -f ggi/*.o ggi/demos/*.o ggi/*.a
# Remove everything that can be remade
realclean: clean
-rm -f lib/*
cd demos && $(MAKE) -f Makefile.X11 realclean || true
cd xdemos && $(MAKE) -f Makefile.X11 realclean || true
cd book && $(MAKE) -f Makefile.X11 realclean || true
cd samples && $(MAKE) -f Makefile.X11 realclean || true
cd ggi/demos && ($MAKE) -f Makefile.X11 realclean || true
cd src/GGI/default && $(MAKE) -f Makefile.X11 realclean || true
DIRECTORY = Mesa-3.1
LIB_NAME = MesaLib-3.1beta2
DEMO_NAME = MesaDemos-3.1beta2
LIB_FILES = \
$(DIRECTORY)/Makefile* \
$(DIRECTORY)/Make-config \
$(DIRECTORY)/acconfig.h \
$(DIRECTORY)/acinclude.m4 \
$(DIRECTORY)/aclocal.m4 \
$(DIRECTORY)/conf.h.in \
$(DIRECTORY)/config.guess \
$(DIRECTORY)/config.sub \
$(DIRECTORY)/configure \
$(DIRECTORY)/configure.in \
$(DIRECTORY)/install-sh \
$(DIRECTORY)/ltconfig \
$(DIRECTORY)/ltmain.sh \
$(DIRECTORY)/missing \
$(DIRECTORY)/mkinstalldirs \
$(DIRECTORY)/stamp-h.in \
$(DIRECTORY)/INSTALL \
$(DIRECTORY)/INSTALL.GNU \
$(DIRECTORY)/configure \
$(DIRECTORY)/docs/CONFIG \
$(DIRECTORY)/docs/CONFORM \
$(DIRECTORY)/docs/COPYRIGHT \
$(DIRECTORY)/docs/IAFA-PACKAGE \
$(DIRECTORY)/docs/LICENSE \
$(DIRECTORY)/docs/README \
$(DIRECTORY)/docs/README.* \
$(DIRECTORY)/docs/RELNOTES \
$(DIRECTORY)/docs/VERSIONS \
$(DIRECTORY)/bin/mklib* \
$(DIRECTORY)/*.BAT \
$(DIRECTORY)/*.bat \
$(DIRECTORY)/descrip.mms \
$(DIRECTORY)/mms-config \
$(DIRECTORY)/xlib.opt \
$(DIRECTORY)/STARTUP.MK \
$(DIRECTORY)/mesawin32.mak \
$(DIRECTORY)/Names.win \
$(DIRECTORY)/win32-openstep.sh \
$(DIRECTORY)/*.dja \
$(DIRECTORY)/include/GL/dosmesa.h \
$(DIRECTORY)/include/GL/foomesa.h \
$(DIRECTORY)/include/GL/fxmesa.h \
$(DIRECTORY)/include/GL/ggimesa.h \
$(DIRECTORY)/include/GL/gl.h \
$(DIRECTORY)/include/GL/gl_mangle.h \
$(DIRECTORY)/include/GL/glu.h \
$(DIRECTORY)/include/GL/glu_mangle.h \
$(DIRECTORY)/include/GL/glx.h \
$(DIRECTORY)/include/GL/glx_mangle.h \
$(DIRECTORY)/include/GL/mglmesa.h \
$(DIRECTORY)/include/GL/osmesa.h \
$(DIRECTORY)/include/GL/svgamesa.h \
$(DIRECTORY)/include/GL/wmesa.h \
$(DIRECTORY)/include/GL/xmesa.h \
$(DIRECTORY)/include/GL/xmesa_x.h \
$(DIRECTORY)/include/GL/xmesa_xf86.h \
$(DIRECTORY)/include/GLView.h \
$(DIRECTORY)/src/Makefile* \
$(DIRECTORY)/src/descrip.mms \
$(DIRECTORY)/src/mms_depend \
$(DIRECTORY)/src/*.def \
$(DIRECTORY)/src/depend \
$(DIRECTORY)/src/*.[chS] \
$(DIRECTORY)/src/Allegro/*.[ch] \
$(DIRECTORY)/src/BeOS/*.cpp \
$(DIRECTORY)/src/D3D/*.cpp \
$(DIRECTORY)/src/D3D/*.CPP \
$(DIRECTORY)/src/D3D/*.h \
$(DIRECTORY)/src/D3D/*.H \
$(DIRECTORY)/src/D3D/*.c \
$(DIRECTORY)/src/D3D/*.C \
$(DIRECTORY)/src/D3D/MAKEFILE \
$(DIRECTORY)/src/D3D/*bat \
$(DIRECTORY)/src/D3D/*DEF \
$(DIRECTORY)/src/DOS/DEPEND.DOS \
$(DIRECTORY)/src/DOS/*.c \
$(DIRECTORY)/src/FX/*.[ch] \
$(DIRECTORY)/src/FX/*.def \
$(DIRECTORY)/src/GGI/*.[ch] \
$(DIRECTORY)/src/GGI/ggimesa.conf \
$(DIRECTORY)/src/GGI/default/*.c \
$(DIRECTORY)/src/GGI/default/Makefile \
$(DIRECTORY)/src/GGI/display/*.c \
$(DIRECTORY)/src/GGI/display/Makefile \
$(DIRECTORY)/src/KNOWN_BUGS \
$(DIRECTORY)/src/MGL/*.[ch] \
$(DIRECTORY)/src/MGL/*.txt \
$(DIRECTORY)/src/OSmesa/*.[ch] \
$(DIRECTORY)/src/S3/*.[ch] \
$(DIRECTORY)/src/S3/*.def \
$(DIRECTORY)/src/S3/*.mak \
$(DIRECTORY)/src/S3/*.rc \
$(DIRECTORY)/src/SVGA/*.[ch] \
$(DIRECTORY)/src/Windows/*.[ch] \
$(DIRECTORY)/src/Windows/*.def \
$(DIRECTORY)/src/X/*.[ch] \
$(DIRECTORY)/src/X86/*.[ch] \
$(DIRECTORY)/src/X86/Makefile \
$(DIRECTORY)/src/X86/*.m4 \
$(DIRECTORY)/src/X86/*.S \
$(DIRECTORY)/src/*.dja \
$(DIRECTORY)/src-glu/README[12] \
$(DIRECTORY)/src-glu/Makefile* \
$(DIRECTORY)/src-glu/descrip.mms \
$(DIRECTORY)/src-glu/mms_depend \
$(DIRECTORY)/src-glu/*.def \
$(DIRECTORY)/src-glu/*.dja \
$(DIRECTORY)/src-glu/depend \
$(DIRECTORY)/src-glu/*.[ch] \
$(DIRECTORY)/widgets-mesa \
$(DIRECTORY)/widgets-sgi \
$(DIRECTORY)/util/README \
$(DIRECTORY)/util/*.[ch] \
$(DIRECTORY)/util/sampleMakefile \
$(DIRECTORY)/BeOS/Makefile \
$(DIRECTORY)/BeOS/*.cpp
# old stuff
# $(DIRECTORY)/Win32 \
# $(DIRECTORY)/win32
# $(DIRECTORY)/OpenStep \
#
#
DEMO_FILES = \
$(DIRECTORY)/include/GL/glut.h \
$(DIRECTORY)/include/GL/glutf90.h \
$(DIRECTORY)/include/GL/glut_h.dja \
$(DIRECTORY)/src-glut/Makefile* \
$(DIRECTORY)/src-glut/depend \
$(DIRECTORY)/src-glut/*def \
$(DIRECTORY)/src-glut/descrip.mms \
$(DIRECTORY)/src-glut/mms_depend \
$(DIRECTORY)/src-glut/*.[ch] \
$(DIRECTORY)/src-glut.dja/* \
$(DIRECTORY)/src-glut.beos/Makefile \
$(DIRECTORY)/src-glut.beos/*.cpp \
$(DIRECTORY)/src-glut.beos/*.h \
$(DIRECTORY)/images/* \
$(DIRECTORY)/demos/Makefile* \
$(DIRECTORY)/demos/descrip.mms \
$(DIRECTORY)/demos/*.[ch] \
$(DIRECTORY)/demos/*.dat \
$(DIRECTORY)/xdemos/Makefile* \
$(DIRECTORY)/xdemos/descrip.mms \
$(DIRECTORY)/xdemos/*.[cf] \
$(DIRECTORY)/book/Makefile* \
$(DIRECTORY)/book/README \
$(DIRECTORY)/book/*.[ch] \
$(DIRECTORY)/samples/Makefile* \
$(DIRECTORY)/samples/README \
$(DIRECTORY)/samples/*.c \
$(DIRECTORY)/samples/*.dja \
$(DIRECTORY)/3Dfx \
$(DIRECTORY)/mtdemos \
$(DIRECTORY)/ggi
lib_tar:
cd .. ; \
tar -cvf $(LIB_NAME).tar $(LIB_FILES) ; \
gzip $(LIB_NAME).tar ; \
mv $(LIB_NAME).tar.gz $(DIRECTORY)
demo_tar:
cd .. ; \
tar -cvf $(DEMO_NAME).tar $(DEMO_FILES) ; \
gzip $(DEMO_NAME).tar ; \
mv $(DEMO_NAME).tar.gz $(DIRECTORY)
lib_zip:
-rm $(LIB_NAME).zip
cd .. ; \
zip -r $(LIB_NAME).zip $(LIB_FILES) ; \
mv $(LIB_NAME).zip $(DIRECTORY)
demo_zip:
-rm $(DEMO_NAME).zip
cd .. ; \
zip -r $(DEMO_NAME).zip $(DEMO_FILES) ; \
mv $(DEMO_NAME).zip $(DIRECTORY)
SRC_FILES = \
RELNOTES \
src/Makefile* \
src/depend \
src/*.[chS] \
src/*/*.[ch] \
include/GL/*.h
srctar:
tar -cvf src.tar $(SRC_FILES) ; \
gzip src.tar
srctar.zip:
-rm src.zip
zip -r src.zip $(SRC_FILES) ; \

30
include/GL/Makefile.am Normal file
View file

@ -0,0 +1,30 @@
## Process this file with automake to produce Makefile.in
GLincludedir = $(includedir)/GL
if HAVE_FX
INC_FX = fxmesa.h
endif
if HAVE_GGI
INC_GGI = ggimesa.h
endif
if HAVE_OSMESA
INC_OSMESA = osmesa.h
endif
if HAVE_SVGA
INC_SVGA = svgamesa.h
endif
if HAVE_X11
INC_X11 = glx.h glx_mangle.h xmesa.h xmesa_x.h xmesa_xf86.h
endif
EXTRA_DIST = fxmesa.h ggimesa.h osmesa.h svgamesa.h \
glx.h glx_mangle.h xmesa.h xmesa_x.h xmesa_xf86.h
GLinclude_HEADERS = gl.h gl_mangle.h glu.h glu_mangle.h \
$(INC_FX) $(INC_GGI) $(INC_OSMESA) $(INC_SVGA) $(INC_X11)

75
include/GL/amesa.h Normal file
View file

@ -0,0 +1,75 @@
/* $Id: amesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* $Log: amesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.1 1999/03/16 01:24:13 brianp
* initial check-in
*
*/
/* Allegro (DJGPP) driver by Bernhard Tschirren (bernie-t@geocities.com) */
#ifndef AMESA_H
#define AMESA_H
typedef struct amesa_visual *AMesaVisual;
typedef struct amesa_buffer *AMesaBuffer;
typedef struct amesa_context *AMesaContext;
extern AMesaVisual AMesaCreateVisual(GLboolean dbFlag, GLint depth,
GLint depthSize,
GLint stencilSize,
GLint accumSize);
extern void AMesaDestroyVisual(AMesaVisual visual);
extern AMesaBuffer AMesaCreateBuffer(AMesaVisual visual,
GLint width, GLint height);
extern void AMesaDestroyBuffer(AMesaBuffer buffer);
extern AMesaContext AMesaCreateContext(AMesaVisual visual,
AMesaContext sharelist);
extern void AMesaDestroyContext(AMesaContext context);
extern GLboolean AMesaMakeCurrent(AMesaContext context, AMesaBuffer buffer);
extern void AMesaSwapBuffers(AMesaBuffer buffer);
#endif /* AMESA_H */

89
include/GL/foomesa.h Normal file
View file

@ -0,0 +1,89 @@
/* $Id: foomesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.0
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: foomesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.1 1998/06/02 01:34:18 brianp
* Initial revision
*
*/
/*
* Example Foo/Mesa interface. See src/ddsample.c for more info.
*/
#ifndef FOOMESA_H
#define FOOMESA_H
typedef struct foo_mesa_visual *FooMesaVisual;
typedef struct foo_mesa_buffer *FooMesaBuffer;
typedef struct foo_mesa_context *FooMesaContext;
#ifdef BEOS
#pragma export on
#endif
extern FooMesaVisual FooMesaChooseVisual( /* your params */ );
extern void FooMesaDestroyVisual( FooMesaVisual visual );
extern FooMesaBuffer FooMesaCreateBuffer( FooMesaVisual visual,
void *your_window_id );
extern void FooMesaDestroyBuffer( FooMesaBuffer buffer );
extern FooMesaContext FooMesaCreateContext( FooMesaVisual visual,
FooMesaContext sharelist );
extern void FooMesaDestroyContext( FooMesaContext context );
extern void FooMesaMakeCurrent( FooMesaContext context, FooMesaBuffer buffer );
extern void FooMesaSwapBuffers( FooMesaBuffer buffer );
/* Probably some more functions... */
#ifdef BEOS
#pragma export off
#endif
#endif

120
include/GL/fxmesa.h Normal file
View file

@ -0,0 +1,120 @@
/* $Id: fxmesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
* Copyright (C) 1995-1999 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: fxmesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/01/03 02:46:31 brianp
* now using GLAPI and GLAPIENTRY keywords (Ted Jump)
*
* Revision 3.1 1998/04/01 03:00:28 brianp
* updated for v0.24 of 3Dfx/Glide driver
*
* Revision 3.0 1998/02/20 05:04:45 brianp
* initial rev
*
*/
/*
* FXMesa - 3Dfx Glide driver for Mesa. Contributed by David Bucciarelli
*
* NOTE: This version requires Glide 2.3 or later.
*/
#ifndef FXMESA_H
#define FXMESA_H
#include <glide.h>
#ifdef __cplusplus
extern "C" {
#endif
#define FXMESA_MAJOR_VERSION 3
#define FXMESA_MINOR_VERSION 0
/*
* Values for attribList parameter to fxMesaCreateContext():
*/
#define FXMESA_NONE 0 /* to terminate attribList */
#define FXMESA_DOUBLEBUFFER 10
#define FXMESA_ALPHA_SIZE 11 /* followed by an integer */
#define FXMESA_DEPTH_SIZE 12 /* followed by an integer */
#define FXMESA_STENCIL_SIZE 13 /* followed by an integer */
#define FXMESA_ACCUM_SIZE 14 /* followed by an integer */
typedef struct tfxMesaContext *fxMesaContext;
#if defined (__BEOS__)
#pragma export on
#endif
GLAPI fxMesaContext GLAPIENTRY fxMesaCreateContext(GLuint win, GrScreenResolution_t,
GrScreenRefresh_t,
const GLint attribList[]);
GLAPI fxMesaContext GLAPIENTRY fxMesaCreateBestContext(GLuint win,
GLint width, GLint height,
const GLint attribList[]);
GLAPI void GLAPIENTRY fxMesaDestroyContext(fxMesaContext ctx);
GLAPI GLboolean GLAPIENTRY fxMesaSelectCurrentBoard(int n);
GLAPI void GLAPIENTRY fxMesaMakeCurrent(fxMesaContext ctx);
GLAPI fxMesaContext GLAPIENTRY fxMesaGetCurrentContext(void);
GLAPI void GLAPIENTRY fxMesaSwapBuffers(void);
GLAPI void GLAPIENTRY fxMesaSetNearFar(GLfloat nearVal, GLfloat farVal);
GLAPI void GLAPIENTRY fxMesaUpdateScreenSize(fxMesaContext ctx);
GLAPI int GLAPIENTRY fxQueryHardware(void);
GLAPI void GLAPIENTRY fxCloseHardware(void);
#if defined (__BEOS__)
#pragma export off
#endif
#ifdef __cplusplus
}
#endif
#endif

67
include/GL/ggimesa.h Normal file
View file

@ -0,0 +1,67 @@
/* $Id: ggimesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
* Copyright (C) 1995-1998 Brian Paul
* Copyright (C) 1998 Uwe Maurer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: ggimesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.2 1998/09/29 01:46:40 brianp
* applied Emmanuel Marty's patches for latest GGI
*
*/
#ifndef GGIMESA_H
#define GGIMESA_H
#ifdef __cplusplus
extern "C" {
#endif
#include "GL/gl.h"
typedef struct ggi_mesa_context *GGIMesaContext;
#include <ggi/ggi.h>
extern GGIMesaContext GGIMesaCreateContext(void);
extern void GGIMesaDestroyContext( GGIMesaContext ctx );
extern void GGIMesaMakeCurrent(GGIMesaContext ctx );
extern GGIMesaContext GGIMesaGetCurrentContext( void );
extern void GGIMesaSwapBuffers( void );
extern int GGIMesaSetVisual(GGIMesaContext ctx,ggi_visual_t vis,
GLboolean rgb_flag,GLboolean db_flag);
#ifdef __cplusplus
}
#endif
#endif

2235
include/GL/gl.h Normal file

File diff suppressed because it is too large Load diff

531
include/GL/gl_mangle.h Normal file
View file

@ -0,0 +1,531 @@
/* $Id: gl_mangle.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* If you compile Mesa with USE_MGL_NAMESPACE defined then you can link
* your application both with OpenGL and Mesa. The Mesa functions will
* be redefined so they are prefixed with "mgl" instead of "gl".
* Contributed by Randy Frank (rfrank@rsinc.com)
*/
#ifndef GL_MANGLE_H
#define GL_MANGLE_H
#define glClearIndex mglClearIndex
#define glClearColor mglClearColor
#define glClear mglClear
#define glIndexMask mglIndexMask
#define glColorMask mglColorMask
#define glAlphaFunc mglAlphaFunc
#define glBlendFunc mglBlendFunc
#define glLogicOp mglLogicOp
#define glCullFace mglCullFace
#define glFrontFace mglFrontFace
#define glPointSize mglPointSize
#define glLineWidth mglLineWidth
#define glLineStipple mglLineStipple
#define glPolygonMode mglPolygonMode
#define glPolygonOffset mglPolygonOffset
#define glPolygonStipple mglPolygonStipple
#define glGetPolygonStipple mglGetPolygonStipple
#define glEdgeFlag mglEdgeFlag
#define glEdgeFlagv mglEdgeFlagv
#define glScissor mglScissor
#define glClipPlane mglClipPlane
#define glGetClipPlane mglGetClipPlane
#define glDrawBuffer mglDrawBuffer
#define glReadBuffer mglReadBuffer
#define glEnable mglEnable
#define glDisable mglDisable
#define glIsEnabled mglIsEnabled
#define glEnableClientState mglEnableClientState
#define glDisableClientState mglDisableClientState
#define glGetBooleanv mglGetBooleanv
#define glGetDoublev mglGetDoublev
#define glGetFloatv mglGetFloatv
#define glGetIntegerv mglGetIntegerv
#define glPushAttrib mglPushAttrib
#define glPopAttrib mglPopAttrib
#define glPushClientAttrib mglPushClientAttrib
#define glPopClientAttrib mglPopClientAttrib
#define glRenderMode mglRenderMode
#define glGetError mglGetError
#define glGetString mglGetString
#define glFinish mglFinish
#define glFlush mglFlush
#define glHint mglHint
#define glClearDepth mglClearDepth
#define glDepthFunc mglDepthFunc
#define glDepthMask mglDepthMask
#define glDepthRange mglDepthRange
#define glClearAccum mglClearAccum
#define glAccum mglAccum
#define glMatrixMode mglMatrixMode
#define glOrtho mglOrtho
#define glFrustum mglFrustum
#define glViewport mglViewport
#define glPushMatrix mglPushMatrix
#define glPopMatrix mglPopMatrix
#define glLoadIdentity mglLoadIdentity
#define glLoadMatrixd mglLoadMatrixd
#define glLoadMatrixf mglLoadMatrixf
#define glMultMatrixd mglMultMatrixd
#define glMultMatrixf mglMultMatrixf
#define glRotated mglRotated
#define glRotatef mglRotatef
#define glScaled mglScaled
#define glScalef mglScalef
#define glTranslated mglTranslated
#define glTranslatef mglTranslatef
#define glIsList mglIsList
#define glDeleteLists mglDeleteLists
#define glGenLists mglGenLists
#define glNewList mglNewList
#define glEndList mglEndList
#define glCallList mglCallList
#define glCallLists mglCallLists
#define glListBase mglListBase
#define glBegin mglBegin
#define glEnd mglEnd
#define glVertex2d mglVertex2d
#define glVertex2f mglVertex2f
#define glVertex2i mglVertex2i
#define glVertex2s mglVertex2s
#define glVertex3d mglVertex3d
#define glVertex3f mglVertex3f
#define glVertex3i mglVertex3i
#define glVertex3s mglVertex3s
#define glVertex4d mglVertex4d
#define glVertex4f mglVertex4f
#define glVertex4i mglVertex4i
#define glVertex4s mglVertex4s
#define glVertex2dv mglVertex2dv
#define glVertex2fv mglVertex2fv
#define glVertex2iv mglVertex2iv
#define glVertex2sv mglVertex2sv
#define glVertex3dv mglVertex3dv
#define glVertex3fv mglVertex3fv
#define glVertex3iv mglVertex3iv
#define glVertex3sv mglVertex3sv
#define glVertex4dv mglVertex4dv
#define glVertex4fv mglVertex4fv
#define glVertex4iv mglVertex4iv
#define glVertex4sv mglVertex4sv
#define glNormal3b mglNormal3b
#define glNormal3d mglNormal3d
#define glNormal3f mglNormal3f
#define glNormal3i mglNormal3i
#define glNormal3s mglNormal3s
#define glNormal3bv mglNormal3bv
#define glNormal3dv mglNormal3dv
#define glNormal3fv mglNormal3fv
#define glNormal3iv mglNormal3iv
#define glNormal3sv mglNormal3sv
#define glIndexd mglIndexd
#define glIndexf mglIndexf
#define glIndexi mglIndexi
#define glIndexs mglIndexs
#define glIndexub mglIndexub
#define glIndexdv mglIndexdv
#define glIndexfv mglIndexfv
#define glIndexiv mglIndexiv
#define glIndexsv mglIndexsv
#define glIndexubv mglIndexubv
#define glColor3b mglColor3b
#define glColor3d mglColor3d
#define glColor3f mglColor3f
#define glColor3i mglColor3i
#define glColor3s mglColor3s
#define glColor3ub mglColor3ub
#define glColor3ui mglColor3ui
#define glColor3us mglColor3us
#define glColor4b mglColor4b
#define glColor4d mglColor4d
#define glColor4f mglColor4f
#define glColor4i mglColor4i
#define glColor4s mglColor4s
#define glColor4ub mglColor4ub
#define glColor4ui mglColor4ui
#define glColor4us mglColor4us
#define glColor3bv mglColor3bv
#define glColor3dv mglColor3dv
#define glColor3fv mglColor3fv
#define glColor3iv mglColor3iv
#define glColor3sv mglColor3sv
#define glColor3ubv mglColor3ubv
#define glColor3uiv mglColor3uiv
#define glColor3usv mglColor3usv
#define glColor4bv mglColor4bv
#define glColor4dv mglColor4dv
#define glColor4fv mglColor4fv
#define glColor4iv mglColor4iv
#define glColor4sv mglColor4sv
#define glColor4ubv mglColor4ubv
#define glColor4uiv mglColor4uiv
#define glColor4usv mglColor4usv
#define glTexCoord1d mglTexCoord1d
#define glTexCoord1f mglTexCoord1f
#define glTexCoord1i mglTexCoord1i
#define glTexCoord1s mglTexCoord1s
#define glTexCoord2d mglTexCoord2d
#define glTexCoord2f mglTexCoord2f
#define glTexCoord2i mglTexCoord2i
#define glTexCoord2s mglTexCoord2s
#define glTexCoord3d mglTexCoord3d
#define glTexCoord3f mglTexCoord3f
#define glTexCoord3i mglTexCoord3i
#define glTexCoord3s mglTexCoord3s
#define glTexCoord4d mglTexCoord4d
#define glTexCoord4f mglTexCoord4f
#define glTexCoord4i mglTexCoord4i
#define glTexCoord4s mglTexCoord4s
#define glTexCoord1dv mglTexCoord1dv
#define glTexCoord1fv mglTexCoord1fv
#define glTexCoord1iv mglTexCoord1iv
#define glTexCoord1sv mglTexCoord1sv
#define glTexCoord2dv mglTexCoord2dv
#define glTexCoord2fv mglTexCoord2fv
#define glTexCoord2iv mglTexCoord2iv
#define glTexCoord2sv mglTexCoord2sv
#define glTexCoord3dv mglTexCoord3dv
#define glTexCoord3fv mglTexCoord3fv
#define glTexCoord3iv mglTexCoord3iv
#define glTexCoord3sv mglTexCoord3sv
#define glTexCoord4dv mglTexCoord4dv
#define glTexCoord4fv mglTexCoord4fv
#define glTexCoord4iv mglTexCoord4iv
#define glTexCoord4sv mglTexCoord4sv
#define glRasterPos2d mglRasterPos2d
#define glRasterPos2f mglRasterPos2f
#define glRasterPos2i mglRasterPos2i
#define glRasterPos2s mglRasterPos2s
#define glRasterPos3d mglRasterPos3d
#define glRasterPos3f mglRasterPos3f
#define glRasterPos3i mglRasterPos3i
#define glRasterPos3s mglRasterPos3s
#define glRasterPos4d mglRasterPos4d
#define glRasterPos4f mglRasterPos4f
#define glRasterPos4i mglRasterPos4i
#define glRasterPos4s mglRasterPos4s
#define glRasterPos2dv mglRasterPos2dv
#define glRasterPos2fv mglRasterPos2fv
#define glRasterPos2iv mglRasterPos2iv
#define glRasterPos2sv mglRasterPos2sv
#define glRasterPos3dv mglRasterPos3dv
#define glRasterPos3fv mglRasterPos3fv
#define glRasterPos3iv mglRasterPos3iv
#define glRasterPos3sv mglRasterPos3sv
#define glRasterPos4dv mglRasterPos4dv
#define glRasterPos4fv mglRasterPos4fv
#define glRasterPos4iv mglRasterPos4iv
#define glRasterPos4sv mglRasterPos4sv
#define glRectd mglRectd
#define glRectf mglRectf
#define glRecti mglRecti
#define glRects mglRects
#define glRectdv mglRectdv
#define glRectfv mglRectfv
#define glRectiv mglRectiv
#define glRectsv mglRectsv
#define glVertexPointer mglVertexPointer
#define glNormalPointer mglNormalPointer
#define glColorPointer mglColorPointer
#define glIndexPointer mglIndexPointer
#define glTexCoordPointer mglTexCoordPointer
#define glEdgeFlagPointer mglEdgeFlagPointer
#define glGetPointerv mglGetPointerv
#define glArrayElement mglArrayElement
#define glDrawArrays mglDrawArrays
#define glDrawElements mglDrawElements
#define glInterleavedArrays mglInterleavedArrays
#define glShadeModel mglShadeModel
#define glLightf mglLightf
#define glLighti mglLighti
#define glLightfv mglLightfv
#define glLightiv mglLightiv
#define glGetLightfv mglGetLightfv
#define glGetLightiv mglGetLightiv
#define glLightModelf mglLightModelf
#define glLightModeli mglLightModeli
#define glLightModelfv mglLightModelfv
#define glLightModeliv mglLightModeliv
#define glMaterialf mglMaterialf
#define glMateriali mglMateriali
#define glMaterialfv mglMaterialfv
#define glMaterialiv mglMaterialiv
#define glGetMaterialfv mglGetMaterialfv
#define glGetMaterialiv mglGetMaterialiv
#define glColorMaterial mglColorMaterial
#define glPixelZoom mglPixelZoom
#define glPixelStoref mglPixelStoref
#define glPixelStorei mglPixelStorei
#define glPixelTransferf mglPixelTransferf
#define glPixelTransferi mglPixelTransferi
#define glPixelMapfv mglPixelMapfv
#define glPixelMapuiv mglPixelMapuiv
#define glPixelMapusv mglPixelMapusv
#define glGetPixelMapfv mglGetPixelMapfv
#define glGetPixelMapuiv mglGetPixelMapuiv
#define glGetPixelMapusv mglGetPixelMapusv
#define glBitmap mglBitmap
#define glReadPixels mglReadPixels
#define glDrawPixels mglDrawPixels
#define glCopyPixels mglCopyPixels
#define glStencilFunc mglStencilFunc
#define glStencilMask mglStencilMask
#define glStencilOp mglStencilOp
#define glClearStencil mglClearStencil
#define glTexGend mglTexGend
#define glTexGenf mglTexGenf
#define glTexGeni mglTexGeni
#define glTexGendv mglTexGendv
#define glTexGenfv mglTexGenfv
#define glTexGeniv mglTexGeniv
#define glGetTexGendv mglGetTexGendv
#define glGetTexGenfv mglGetTexGenfv
#define glGetTexGeniv mglGetTexGeniv
#define glTexEnvf mglTexEnvf
#define glTexEnvi mglTexEnvi
#define glTexEnvfv mglTexEnvfv
#define glTexEnviv mglTexEnviv
#define glGetTexEnvfv mglGetTexEnvfv
#define glGetTexEnviv mglGetTexEnviv
#define glTexParameterf mglTexParameterf
#define glTexParameteri mglTexParameteri
#define glTexParameterfv mglTexParameterfv
#define glTexParameteriv mglTexParameteriv
#define glGetTexParameterfv mglGetTexParameterfv
#define glGetTexParameteriv mglGetTexParameteriv
#define glGetTexLevelParameterfv mglGetTexLevelParameterfv
#define glGetTexLevelParameteriv mglGetTexLevelParameteriv
#define glTexImage1D mglTexImage1D
#define glTexImage2D mglTexImage2D
#define glGetTexImage mglGetTexImage
#define glGenTextures mglGenTextures
#define glDeleteTextures mglDeleteTextures
#define glBindTexture mglBindTexture
#define glPrioritizeTextures mglPrioritizeTextures
#define glAreTexturesResident mglAreTexturesResident
#define glIsTexture mglIsTexture
#define glTexSubImage1D mglTexSubImage1D
#define glTexSubImage2D mglTexSubImage2D
#define glCopyTexImage1D mglCopyTexImage1D
#define glCopyTexImage2D mglCopyTexImage2D
#define glCopyTexSubImage1D mglCopyTexSubImage1D
#define glCopyTexSubImage2D mglCopyTexSubImage2D
#define glMap1d mglMap1d
#define glMap1f mglMap1f
#define glMap2d mglMap2d
#define glMap2f mglMap2f
#define glGetMapdv mglGetMapdv
#define glGetMapfv mglGetMapfv
#define glGetMapiv mglGetMapiv
#define glEvalCoord1d mglEvalCoord1d
#define glEvalCoord1f mglEvalCoord1f
#define glEvalCoord1dv mglEvalCoord1dv
#define glEvalCoord1fv mglEvalCoord1fv
#define glEvalCoord2d mglEvalCoord2d
#define glEvalCoord2f mglEvalCoord2f
#define glEvalCoord2dv mglEvalCoord2dv
#define glEvalCoord2fv mglEvalCoord2fv
#define glMapGrid1d mglMapGrid1d
#define glMapGrid1f mglMapGrid1f
#define glMapGrid2d mglMapGrid2d
#define glMapGrid2f mglMapGrid2f
#define glEvalPoint1 mglEvalPoint1
#define glEvalPoint2 mglEvalPoint2
#define glEvalMesh1 mglEvalMesh1
#define glEvalMesh2 mglEvalMesh2
#define glFogf mglFogf
#define glFogi mglFogi
#define glFogfv mglFogfv
#define glFogiv mglFogiv
#define glFeedbackBuffer mglFeedbackBuffer
#define glPassThrough mglPassThrough
#define glSelectBuffer mglSelectBuffer
#define glInitNames mglInitNames
#define glLoadName mglLoadName
#define glPushName mglPushName
#define glPopName mglPopName
#define glBlendEquation mglBlendEquation
#define glBlendEquationEXT mglBlendEquationEXT
#define glBlendColor mglBlendColor
#define glBlendColorEXT mglBlendColorEXT
#define glPolygonOffsetEXT mglPolygonOffsetEXT
#define glVertexPointerEXT mglVertexPointerEXT
#define glNormalPointerEXT mglNormalPointerEXT
#define glColorPointerEXT mglColorPointerEXT
#define glIndexPointerEXT mglIndexPointerEXT
#define glTexCoordPointerEXT mglTexCoordPointerEXT
#define glEdgeFlagPointerEXT mglEdgeFlagPointerEXT
#define glGetPointervEXT mglGetPointervEXT
#define glArrayElementEXT mglArrayElementEXT
#define glDrawArraysEXT mglDrawArraysEXT
#define glGenTexturesEXT mglGenTexturesEXT
#define glDeleteTexturesEXT mglDeleteTexturesEXT
#define glBindTextureEXT mglBindTextureEXT
#define glPrioritizeTexturesEXT mglPrioritizeTexturesEXT
#define glAreTexturesResidentEXT mglAreTexturesResidentEXT
#define glIsTextureEXT mglIsTextureEXT
#define glTexImage3DEXT mglTexImage3DEXT
#define glTexSubImage3DEXT mglTexSubImage3DEXT
#define glCopyTexSubImage3DEXT mglCopyTexSubImage3DEXT
#define glColorTableEXT mglColorTableEXT
#define glColorSubTableEXT mglColorSubTableEXT
#define glGetColorTableEXT mglGetColorTableEXT
#define glGetColorTableParameterfvEXT mglGetColorTableParameterfvEXT
#define glGetColorTableParameterivEXT mglGetColorTableParameterivEXT
#define glGetMinMax mglGetMinMax
#define glMultiTexCoord1dSGIS mglMultiTexCoord1dSGIS
#define glMultiTexCoord1dvSGIS mglMultiTexCoord1dvSGIS
#define glMultiTexCoord1fSGIS mglMultiTexCoord1fSGIS
#define glMultiTexCoord1fvSGIS mglMultiTexCoord1fvSGIS
#define glMultiTexCoord1iSGIS mglMultiTexCoord1iSGIS
#define glMultiTexCoord1ivSGIS mglMultiTexCoord1ivSGIS
#define glMultiTexCoord1sSGIS mglMultiTexCoord1sSGIS
#define glMultiTexCoord1svSGIS mglMultiTexCoord1svSGIS
#define glMultiTexCoord2dSGIS mglMultiTexCoord2dSGIS
#define glMultiTexCoord2dvSGIS mglMultiTexCoord2dvSGIS
#define glMultiTexCoord2fSGIS mglMultiTexCoord2fSGIS
#define glMultiTexCoord2fvSGIS mglMultiTexCoord2fvSGIS
#define glMultiTexCoord2iSGIS mglMultiTexCoord2iSGIS
#define glMultiTexCoord2ivSGIS mglMultiTexCoord2ivSGIS
#define glMultiTexCoord2sSGIS mglMultiTexCoord2sSGIS
#define glMultiTexCoord2svSGIS mglMultiTexCoord2svSGIS
#define glMultiTexCoord3dSGIS mglMultiTexCoord3dSGIS
#define glMultiTexCoord3dvSGIS mglMultiTexCoord3dvSGIS
#define glMultiTexCoord3fSGIS mglMultiTexCoord3fSGIS
#define glMultiTexCoord3fvSGIS mglMultiTexCoord3fvSGIS
#define glMultiTexCoord3iSGIS mglMultiTexCoord3iSGIS
#define glMultiTexCoord3ivSGIS mglMultiTexCoord3ivSGIS
#define glMultiTexCoord3sSGIS mglMultiTexCoord3sSGIS
#define glMultiTexCoord3svSGIS mglMultiTexCoord3svSGIS
#define glMultiTexCoord4dSGIS mglMultiTexCoord4dSGIS
#define glMultiTexCoord4dvSGIS mglMultiTexCoord4dvSGIS
#define glMultiTexCoord4fSGIS mglMultiTexCoord4fSGIS
#define glMultiTexCoord4fvSGIS mglMultiTexCoord4fvSGIS
#define glMultiTexCoord4iSGIS mglMultiTexCoord4iSGIS
#define glMultiTexCoord4ivSGIS mglMultiTexCoord4ivSGIS
#define glMultiTexCoord4sSGIS mglMultiTexCoord4sSGIS
#define glMultiTexCoord4svSGIS mglMultiTexCoord4svSGIS
#define glMultiTexCoordPointerSGIS mglMultiTexCoordPointerSGIS
#define glSelectTextureSGIS mglSelectTextureSGIS
#define glSelectTextureCoordSetSGIS mglSelectTextureCoordSetSGIS
#define glActiveTextureARB mglActiveTextureARB
#define glClientActiveTextureARB mglClientActiveTextureARB
#define glMultiTexCoord1dARB mglMultiTexCoord1dARB
#define glMultiTexCoord1dvARB mglMultiTexCoord1dvARB
#define glMultiTexCoord1fARB mglMultiTexCoord1fARB
#define glMultiTexCoord1fvARB mglMultiTexCoord1fvARB
#define glMultiTexCoord1iARB mglMultiTexCoord1iARB
#define glMultiTexCoord1ivARB mglMultiTexCoord1ivARB
#define glMultiTexCoord1sARB mglMultiTexCoord1sARB
#define glMultiTexCoord1svARB mglMultiTexCoord1svARB
#define glMultiTexCoord2dARB mglMultiTexCoord2dARB
#define glMultiTexCoord2dvARB mglMultiTexCoord2dvARB
#define glMultiTexCoord2fARB mglMultiTexCoord2fARB
#define glMultiTexCoord2fvARB mglMultiTexCoord2fvARB
#define glMultiTexCoord2iARB mglMultiTexCoord2iARB
#define glMultiTexCoord2ivARB mglMultiTexCoord2ivARB
#define glMultiTexCoord2sARB mglMultiTexCoord2sARB
#define glMultiTexCoord2svARB mglMultiTexCoord2svARB
#define glMultiTexCoord3dARB mglMultiTexCoord3dARB
#define glMultiTexCoord3dvARB mglMultiTexCoord3dvARB
#define glMultiTexCoord3fARB mglMultiTexCoord3fARB
#define glMultiTexCoord3fvARB mglMultiTexCoord3fvARB
#define glMultiTexCoord3iARB mglMultiTexCoord3iARB
#define glMultiTexCoord3ivARB mglMultiTexCoord3ivARB
#define glMultiTexCoord3sARB mglMultiTexCoord3sARB
#define glMultiTexCoord3svARB mglMultiTexCoord3svARB
#define glMultiTexCoord4dARB mglMultiTexCoord4dARB
#define glMultiTexCoord4dvARB mglMultiTexCoord4dvARB
#define glMultiTexCoord4fARB mglMultiTexCoord4fARB
#define glMultiTexCoord4fvARB mglMultiTexCoord4fvARB
#define glMultiTexCoord4iARB mglMultiTexCoord4iARB
#define glMultiTexCoord4ivARB mglMultiTexCoord4ivARB
#define glMultiTexCoord4sARB mglMultiTexCoord4sARB
#define glMultiTexCoord4svARB mglMultiTexCoord4svARB
#define glPointParameterfEXT mglPointParameterfEXT
#define glPointParameterfvEXT mglPointParameterfvEXT
#define glBlendFuncSeparateINGR mglBlendFuncSeparateINGR
#define glWindowPos2iMESA mglWindowPos2iMESA
#define glWindowPos2sMESA mglWindowPos2sMESA
#define glWindowPos2fMESA mglWindowPos2fMESA
#define glWindowPos2dMESA mglWindowPos2dMESA
#define glWindowPos2ivMESA mglWindowPos2ivMESA
#define glWindowPos2svMESA mglWindowPos2svMESA
#define glWindowPos2fvMESA mglWindowPos2fvMESA
#define glWindowPos2dvMESA mglWindowPos2dvMESA
#define glWindowPos3iMESA mglWindowPos3iMESA
#define glWindowPos3sMESA mglWindowPos3sMESA
#define glWindowPos3fMESA mglWindowPos3fMESA
#define glWindowPos3dMESA mglWindowPos3dMESA
#define glWindowPos3ivMESA mglWindowPos3ivMESA
#define glWindowPos3svMESA mglWindowPos3svMESA
#define glWindowPos3fvMESA mglWindowPos3fvMESA
#define glWindowPos3dvMESA mglWindowPos3dvMESA
#define glWindowPos4iMESA mglWindowPos4iMESA
#define glWindowPos4sMESA mglWindowPos4sMESA
#define glWindowPos4fMESA mglWindowPos4fMESA
#define glWindowPos4dMESA mglWindowPos4dMESA
#define glWindowPos4ivMESA mglWindowPos4ivMESA
#define glWindowPos4svMESA mglWindowPos4svMESA
#define glWindowPos4fvMESA mglWindowPos4fvMESA
#define glWindowPos4dvMESA mglWindowPos4dvMESA
#define glResizeBuffersMESA mglResizeBuffersMESA
#define glDrawRangeElements mglDrawRangeElements
#define glTexImage3D mglTexImage3D
#define glTexSubImage3D mglTexSubImage3D
#define glCopyTexSubImage3D mglCopyTexSubImage3D
#define glHistogram mglHistogram
#define glResetHistogram mglResetHistogram
#define glGetHistogram mglGetHistogram
#define glGetHistogramParameterfv mglGetHistogramParameterfv
#define glGetHistogramParameteriv mglGetHistogramParameteriv
#define glMinmax mglMinmax
#define glResetMinmax mglResetMinmax
#define glGetMinmaxParameterfv mglGetMinmaxParameterfv
#define glGetMinmaxParameteriv mglGetMinmaxParameteriv
#define glConvolutionFilter1D mglConvolutionFilter1D
#define glConvolutionFilter2D mglConvolutionFilter2D
#define glConvolutionParameterf mglConvolutionParameterf
#define glConvolutionParameterfv mglConvolutionParameterfv
#define glConvolutionParameteri mglConvolutionParameteri
#define glConvolutionParameteriv mglConvolutionParameteriv
#define glCopyConvolutionFilter1D mglCopyConvolutionFilter1D
#define glCopyConvolutionFilter2D mglCopyConvolutionFilter2D
#define glGetConvolutionFilter mglGetConvolutionFilter
#define glGetConvolutionParameterfv mglGetConvolutionParameterfv
#define glGetConvolutionParameteriv mglGetConvolutionParameteriv
#define glSeparableFilter2D mglSeparableFilter2D
#define glGetSeparableFilter mglGetSeparableFilter
#define glCopyColorSubTable mglCopyColorSubTable
#define glCopyColorTable mglCopyColorTable
#define glLockArraysEXT mglLockArraysEXT
#define glUnlockArraysEXT mglUnlockArraysEXT
#endif

444
include/GL/glu.h Normal file
View file

@ -0,0 +1,444 @@
/* $Id: glu.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
* Copyright (C) 1995-1999 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: glu.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.6 1999/02/14 03:39:45 brianp
* updated for BeOS R4
*
* Revision 3.5 1999/01/03 03:02:55 brianp
* now using GLAPI and GLAPIENTRY keywords, misc Windows changes (Ted Jump)
*
* Revision 3.4 1998/12/01 02:34:27 brianp
* applied Mark Kilgard's patches from November 30, 1998
*
* Revision 3.3 1998/11/17 01:14:02 brianp
* minor changes for OpenStep compilation (pete@ohm.york.ac.uk)
*
* Revision 3.2 1998/07/26 01:36:27 brianp
* changes for Windows compilation per Ted Jump
*
* Revision 3.1 1998/06/23 00:33:08 brianp
* added some WIN32 APIENTRY, CALLBACK stuff (Eric Lassauge)
*
* Revision 3.0 1998/02/20 05:06:01 brianp
* initial rev
*
*/
#ifndef GLU_H
#define GLU_H
#if defined(USE_MGL_NAMESPACE)
#include "glu_mangle.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include "GL/gl.h"
/* to facilitate clean DLL building ... */
#if !defined(OPENSTEP) && (defined(__WIN32__) || defined(__CYGWIN32__))
# if defined(_MSC_VER) && defined(BUILD_GLU32) /* tag specify we're building mesa as a DLL */
# define GLUAPI __declspec(dllexport)
# elif defined(_MSC_VER) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
# define GLUAPI __declspec(dllimport)
# else /* for use with static link lib build of Win32 edition only */
# define GLUAPI extern
# endif /* _STATIC_MESA support */
#else
# define GLUAPI extern
#endif /* WIN32 / CYGWIN32 bracket */
#ifdef macintosh
#pragma enumsalwaysint on
#if PRAGMA_IMPORT_SUPPORTED
#pragma import on
#endif
#endif
#define GLU_VERSION_1_1 1
#define GLU_TRUE GL_TRUE
#define GLU_FALSE GL_FALSE
enum {
/* Normal vectors */
GLU_SMOOTH = 100000,
GLU_FLAT = 100001,
GLU_NONE = 100002,
/* Quadric draw styles */
GLU_POINT = 100010,
GLU_LINE = 100011,
GLU_FILL = 100012,
GLU_SILHOUETTE = 100013,
/* Quadric orientation */
GLU_OUTSIDE = 100020,
GLU_INSIDE = 100021,
/* Tesselator */
GLU_BEGIN = 100100,
GLU_VERTEX = 100101,
GLU_END = 100102,
GLU_ERROR = 100103,
GLU_EDGE_FLAG = 100104,
/* Contour types */
GLU_CW = 100120,
GLU_CCW = 100121,
GLU_INTERIOR = 100122,
GLU_EXTERIOR = 100123,
GLU_UNKNOWN = 100124,
/* Tesselation errors */
GLU_TESS_ERROR1 = 100151, /* missing gluEndPolygon */
GLU_TESS_ERROR2 = 100152, /* missing gluBeginPolygon */
GLU_TESS_ERROR3 = 100153, /* misoriented contour */
GLU_TESS_ERROR4 = 100154, /* vertex/edge intersection */
GLU_TESS_ERROR5 = 100155, /* misoriented or self-intersecting loops */
GLU_TESS_ERROR6 = 100156, /* coincident vertices */
GLU_TESS_ERROR7 = 100157, /* all vertices collinear */
GLU_TESS_ERROR8 = 100158, /* intersecting edges */
GLU_TESS_ERROR9 = 100159, /* not coplanar contours */
/* NURBS */
GLU_AUTO_LOAD_MATRIX = 100200,
GLU_CULLING = 100201,
GLU_PARAMETRIC_TOLERANCE= 100202,
GLU_SAMPLING_TOLERANCE = 100203,
GLU_DISPLAY_MODE = 100204,
GLU_SAMPLING_METHOD = 100205,
GLU_U_STEP = 100206,
GLU_V_STEP = 100207,
GLU_PATH_LENGTH = 100215,
GLU_PARAMETRIC_ERROR = 100216,
GLU_DOMAIN_DISTANCE = 100217,
GLU_MAP1_TRIM_2 = 100210,
GLU_MAP1_TRIM_3 = 100211,
GLU_OUTLINE_POLYGON = 100240,
GLU_OUTLINE_PATCH = 100241,
GLU_NURBS_ERROR1 = 100251, /* spline order un-supported */
GLU_NURBS_ERROR2 = 100252, /* too few knots */
GLU_NURBS_ERROR3 = 100253, /* valid knot range is empty */
GLU_NURBS_ERROR4 = 100254, /* decreasing knot sequence */
GLU_NURBS_ERROR5 = 100255, /* knot multiplicity > spline order */
GLU_NURBS_ERROR6 = 100256, /* endcurve() must follow bgncurve() */
GLU_NURBS_ERROR7 = 100257, /* bgncurve() must precede endcurve() */
GLU_NURBS_ERROR8 = 100258, /* ctrlarray or knot vector is NULL */
GLU_NURBS_ERROR9 = 100259, /* can't draw pwlcurves */
GLU_NURBS_ERROR10 = 100260, /* missing gluNurbsCurve() */
GLU_NURBS_ERROR11 = 100261, /* missing gluNurbsSurface() */
GLU_NURBS_ERROR12 = 100262, /* endtrim() must precede endsurface() */
GLU_NURBS_ERROR13 = 100263, /* bgnsurface() must precede endsurface() */
GLU_NURBS_ERROR14 = 100264, /* curve of improper type passed as trim curve */
GLU_NURBS_ERROR15 = 100265, /* bgnsurface() must precede bgntrim() */
GLU_NURBS_ERROR16 = 100266, /* endtrim() must follow bgntrim() */
GLU_NURBS_ERROR17 = 100267, /* bgntrim() must precede endtrim()*/
GLU_NURBS_ERROR18 = 100268, /* invalid or missing trim curve*/
GLU_NURBS_ERROR19 = 100269, /* bgntrim() must precede pwlcurve() */
GLU_NURBS_ERROR20 = 100270, /* pwlcurve referenced twice*/
GLU_NURBS_ERROR21 = 100271, /* pwlcurve and nurbscurve mixed */
GLU_NURBS_ERROR22 = 100272, /* improper usage of trim data type */
GLU_NURBS_ERROR23 = 100273, /* nurbscurve referenced twice */
GLU_NURBS_ERROR24 = 100274, /* nurbscurve and pwlcurve mixed */
GLU_NURBS_ERROR25 = 100275, /* nurbssurface referenced twice */
GLU_NURBS_ERROR26 = 100276, /* invalid property */
GLU_NURBS_ERROR27 = 100277, /* endsurface() must follow bgnsurface() */
GLU_NURBS_ERROR28 = 100278, /* intersecting or misoriented trim curves */
GLU_NURBS_ERROR29 = 100279, /* intersecting trim curves */
GLU_NURBS_ERROR30 = 100280, /* UNUSED */
GLU_NURBS_ERROR31 = 100281, /* unconnected trim curves */
GLU_NURBS_ERROR32 = 100282, /* unknown knot error */
GLU_NURBS_ERROR33 = 100283, /* negative vertex count encountered */
GLU_NURBS_ERROR34 = 100284, /* negative byte-stride */
GLU_NURBS_ERROR35 = 100285, /* unknown type descriptor */
GLU_NURBS_ERROR36 = 100286, /* null control point reference */
GLU_NURBS_ERROR37 = 100287, /* duplicate point on pwlcurve */
/* Errors */
GLU_INVALID_ENUM = 100900,
GLU_INVALID_VALUE = 100901,
GLU_OUT_OF_MEMORY = 100902,
GLU_INCOMPATIBLE_GL_VERSION = 100903,
/* New in GLU 1.1 */
GLU_VERSION = 100800,
GLU_EXTENSIONS = 100801
};
/*
* These are the GLU 1.1 typedefs. GLU 1.2 has different ones!
*/
#if defined(__BEOS__)
/* The BeOS does something funky and makes these typedefs in one
* of its system headers.
*/
#else
typedef struct GLUquadric GLUquadricObj;
typedef struct GLUtesselator GLUtriangulatorObj;
typedef struct GLUnurbs GLUnurbsObj;
#endif
#if defined(__BEOS__) || defined(__QUICKDRAW__)
#pragma export on
#endif
/*
*
* Miscellaneous functions
*
*/
GLUAPI void GLAPIENTRY gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery,
GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz );
GLUAPI void GLAPIENTRY gluOrtho2D( GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top );
GLUAPI void GLAPIENTRY gluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar );
GLUAPI void GLAPIENTRY gluPickMatrix( GLdouble x, GLdouble y,
GLdouble width, GLdouble height,
const GLint viewport[4] );
GLUAPI GLint GLAPIENTRY gluProject( GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy,
GLdouble *winz );
GLUAPI GLint GLAPIENTRY gluUnProject( GLdouble winx, GLdouble winy,
GLdouble winz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *objx, GLdouble *objy,
GLdouble *objz );
GLUAPI const GLubyte* GLAPIENTRY gluErrorString( GLenum errorCode );
/*
*
* Mipmapping and image scaling
*
*/
GLUAPI GLint GLAPIENTRY gluScaleImage( GLenum format,
GLint widthin, GLint heightin,
GLenum typein, const void *datain,
GLint widthout, GLint heightout,
GLenum typeout, void *dataout );
GLUAPI GLint GLAPIENTRY gluBuild1DMipmaps( GLenum target, GLint components,
GLint width, GLenum format,
GLenum type, const void *data );
GLUAPI GLint GLAPIENTRY gluBuild2DMipmaps( GLenum target, GLint components,
GLint width, GLint height,
GLenum format,
GLenum type, const void *data );
/*
*
* Quadrics
*
*/
GLUAPI GLUquadricObj* GLAPIENTRY gluNewQuadric( void );
GLUAPI void GLAPIENTRY gluDeleteQuadric( GLUquadricObj *state );
GLUAPI void GLAPIENTRY gluQuadricDrawStyle( GLUquadricObj *quadObject,
GLenum drawStyle );
GLUAPI void GLAPIENTRY gluQuadricOrientation( GLUquadricObj *quadObject,
GLenum orientation );
GLUAPI void GLAPIENTRY gluQuadricNormals( GLUquadricObj *quadObject,
GLenum normals );
GLUAPI void GLAPIENTRY gluQuadricTexture( GLUquadricObj *quadObject,
GLboolean textureCoords );
GLUAPI void GLAPIENTRY gluQuadricCallback( GLUquadricObj *qobj,
GLenum which, void (GLCALLBACK *fn)() );
GLUAPI void GLAPIENTRY gluCylinder( GLUquadricObj *qobj,
GLdouble baseRadius,
GLdouble topRadius,
GLdouble height,
GLint slices, GLint stacks );
GLUAPI void GLAPIENTRY gluSphere( GLUquadricObj *qobj,
GLdouble radius, GLint slices, GLint stacks );
GLUAPI void GLAPIENTRY gluDisk( GLUquadricObj *qobj,
GLdouble innerRadius, GLdouble outerRadius,
GLint slices, GLint loops );
GLUAPI void GLAPIENTRY gluPartialDisk( GLUquadricObj *qobj, GLdouble innerRadius,
GLdouble outerRadius, GLint slices,
GLint loops, GLdouble startAngle,
GLdouble sweepAngle );
/*
*
* Nurbs
*
*/
GLUAPI GLUnurbsObj* GLAPIENTRY gluNewNurbsRenderer( void );
GLUAPI void GLAPIENTRY gluDeleteNurbsRenderer( GLUnurbsObj *nobj );
GLUAPI void GLAPIENTRY gluLoadSamplingMatrices( GLUnurbsObj *nobj,
const GLfloat modelMatrix[16],
const GLfloat projMatrix[16],
const GLint viewport[4] );
GLUAPI void GLAPIENTRY gluNurbsProperty( GLUnurbsObj *nobj, GLenum property,
GLfloat value );
GLUAPI void GLAPIENTRY gluGetNurbsProperty( GLUnurbsObj *nobj, GLenum property,
GLfloat *value );
GLUAPI void GLAPIENTRY gluBeginCurve( GLUnurbsObj *nobj );
GLUAPI void GLAPIENTRY gluEndCurve( GLUnurbsObj * nobj );
GLUAPI void GLAPIENTRY gluNurbsCurve( GLUnurbsObj *nobj, GLint nknots,
GLfloat *knot, GLint stride,
GLfloat *ctlarray, GLint order,
GLenum type );
GLUAPI void GLAPIENTRY gluBeginSurface( GLUnurbsObj *nobj );
GLUAPI void GLAPIENTRY gluEndSurface( GLUnurbsObj * nobj );
GLUAPI void GLAPIENTRY gluNurbsSurface( GLUnurbsObj *nobj,
GLint sknot_count, GLfloat *sknot,
GLint tknot_count, GLfloat *tknot,
GLint s_stride, GLint t_stride,
GLfloat *ctlarray,
GLint sorder, GLint torder,
GLenum type );
GLUAPI void GLAPIENTRY gluBeginTrim( GLUnurbsObj *nobj );
GLUAPI void GLAPIENTRY gluEndTrim( GLUnurbsObj *nobj );
GLUAPI void GLAPIENTRY gluPwlCurve( GLUnurbsObj *nobj, GLint count,
GLfloat *array, GLint stride, GLenum type );
GLUAPI void GLAPIENTRY gluNurbsCallback( GLUnurbsObj *nobj, GLenum which,
void (GLCALLBACK *fn)() );
/*
*
* Polygon tesselation
*
*/
GLUAPI GLUtriangulatorObj* GLAPIENTRY gluNewTess( void );
GLUAPI void GLAPIENTRY gluTessCallback( GLUtriangulatorObj *tobj, GLenum which,
void (GLCALLBACK *fn)() );
GLUAPI void GLAPIENTRY gluDeleteTess( GLUtriangulatorObj *tobj );
GLUAPI void GLAPIENTRY gluBeginPolygon( GLUtriangulatorObj *tobj );
GLUAPI void GLAPIENTRY gluEndPolygon( GLUtriangulatorObj *tobj );
GLUAPI void GLAPIENTRY gluNextContour( GLUtriangulatorObj *tobj, GLenum type );
GLUAPI void GLAPIENTRY gluTessVertex( GLUtriangulatorObj *tobj, GLdouble v[3],
void *data );
/*
*
* New functions in GLU 1.1
*
*/
GLUAPI const GLubyte* GLAPIENTRY gluGetString( GLenum name );
#if defined(__BEOS__) || defined(__QUICKDRAW__)
#pragma export off
#endif
#ifdef macintosh
#pragma enumsalwaysint reset
#if PRAGMA_IMPORT_SUPPORTED
#pragma import off
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif

86
include/GL/glu_mangle.h Normal file
View file

@ -0,0 +1,86 @@
/* $Id: glu_mangle.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.0
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: glu_mangle.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1999/06/21 22:00:42 brianp
* added #ifndef GLU_MANGLE_H stuff
*
* Revision 3.0 1998/02/20 05:04:45 brianp
* initial rev
*
*/
#ifndef GLU_MANGLE_H
#define GLU_MANGLE_H
#define gluLookAt mgluLookAt
#define gluOrtho2D mgluOrtho2D
#define gluPerspective mgluPerspective
#define gluPickMatrix mgluPickMatrix
#define gluProject mgluProject
#define gluUnProject mgluUnProject
#define gluErrorString mgluErrorString
#define gluScaleImage mgluScaleImage
#define gluBuild1DMipmaps mgluBuild1DMipmaps
#define gluBuild2DMipmaps mgluBuild2DMipmaps
#define gluNewQuadric mgluNewQuadric
#define gluDeleteQuadric mgluDeleteQuadric
#define gluQuadricDrawStyle mgluQuadricDrawStyle
#define gluQuadricOrientation mgluQuadricOrientation
#define gluQuadricNormals mgluQuadricNormals
#define gluQuadricTexture mgluQuadricTexture
#define gluQuadricCallback mgluQuadricCallback
#define gluCylinder mgluCylinder
#define gluSphere mgluSphere
#define gluDisk mgluDisk
#define gluPartialDisk mgluPartialDisk
#define gluNewNurbsRenderer mgluNewNurbsRenderer
#define gluDeleteNurbsRenderer mgluDeleteNurbsRenderer
#define gluLoadSamplingMatrices mgluLoadSamplingMatrices
#define gluNurbsProperty mgluNurbsProperty
#define gluGetNurbsProperty mgluGetNurbsProperty
#define gluBeginCurve mgluBeginCurve
#define gluEndCurve mgluEndCurve
#define gluNurbsCurve mgluNurbsCurve
#define gluBeginSurface mgluBeginSurface
#define gluEndSurface mgluEndSurface
#define gluNurbsSurface mgluNurbsSurface
#define gluBeginTrim mgluBeginTrim
#define gluEndTrim mgluEndTrim
#define gluPwlCurve mgluPwlCurve
#define gluNurbsCallback mgluNurbsCallback
#define gluNewTess mgluNewTess
#define gluTessCallback mgluTessCallback
#define gluDeleteTess mgluDeleteTess
#define gluBeginPolygon mgluBeginPolygon
#define gluEndPolygon mgluEndPolygon
#define gluNextContour mgluNextContour
#define gluTessVertex mgluTessVertex
#define gluGetString mgluGetString
#endif

751
include/GL/glut.h Normal file
View file

@ -0,0 +1,751 @@
#ifndef __glut_h__
#define __glut_h__
/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */
/* This program is freely distributable without licensing fees and is
provided without guarantee or warrantee expressed or implied. This
program is -not- in the public domain. */
#include <GL/gl.h>
#include <GL/glu.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32)
/* GLUT 3.7 now tries to avoid including <windows.h>
to avoid name space pollution, but Win32's <GL/gl.h>
needs APIENTRY and WINGDIAPI defined properly.
tjump@spgs.com contributes:
If users are building glut code on MS Windows, then they should
make sure they include windows.h early, let's not get into a
header definitions war since MS has proven it's capability to
change header dependencies w/o publishing they have done so.
So, let's not include windows.h here, as it's not really required and
MS own gl/gl.h *should* include it if the dependency is there. */
/* To disable automatic library usage for GLUT, define GLUT_NO_LIB_PRAGMA
in your compile preprocessor options. */
# if !defined(GLUT_BUILDING_LIB) && !defined(GLUT_NO_LIB_PRAGMA)
# pragma comment (lib, "winmm.lib") /* link with Windows MultiMedia lib */
/* To enable automatic SGI OpenGL for Windows library usage for GLUT,
define GLUT_USE_SGI_OPENGL in your compile preprocessor options. */
# ifdef GLUT_USE_SGI_OPENGL
# pragma comment (lib, "opengl.lib") /* link with SGI OpenGL for Windows lib */
# pragma comment (lib, "glu.lib") /* link with SGI OpenGL Utility lib */
# pragma comment (lib, "glut.lib") /* link with Win32 GLUT for SGI OpenGL lib */
# else
# pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */
# pragma comment (lib, "glu32.lib") /* link with Microsoft OpenGL Utility lib */
# pragma comment (lib, "glut32.lib") /* link with Win32 GLUT lib */
# endif
# endif
/* To disable supression of annoying warnings about floats being promoted
to doubles, define GLUT_NO_WARNING_DISABLE in your compile preprocessor
options. */
# ifndef GLUT_NO_WARNING_DISABLE
# pragma warning (disable:4244) /* Disable bogus VC++ 4.2 conversion warnings. */
# pragma warning (disable:4305) /* VC++ 5.0 version of above warning. */
# endif
/* Win32 has an annoying issue where there are multiple C run-time
libraries (CRTs). If the executable is linked with a different CRT
from the GLUT DLL, the GLUT DLL will not share the same CRT static
data seen by the executable. In particular, atexit callbacks registered
in the executable will not be called if GLUT calls its (different)
exit routine). GLUT is typically built with the
"/MD" option (the CRT with multithreading DLL support), but the Visual
C++ linker default is "/ML" (the single threaded CRT).
One workaround to this issue is requiring users to always link with
the same CRT as GLUT is compiled with. That requires users supply a
non-standard option. GLUT 3.7 has its own built-in workaround where
the executable's "exit" function pointer is covertly passed to GLUT.
GLUT then calls the executable's exit function pointer to ensure that
any "atexit" calls registered by the application are called if GLUT
needs to exit.
Note that the __glut*WithExit routines should NEVER be called directly.
To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
/* XXX This is from Win32's <process.h> */
# if !defined(_MSC_VER) && !defined(__cdecl)
/* Define __cdecl for non-Microsoft compilers. */
# define __cdecl
# define GLUT_DEFINED___CDECL
# endif
# ifndef _CRTIMP
# ifdef _NTSDK
/* Definition compatible with NT SDK */
# define _CRTIMP
# else
/* Current definition */
# ifdef _DLL
# define _CRTIMP __declspec(dllimport)
# else
# define _CRTIMP
# endif
# endif
# define GLUT_DEFINED__CRTIMP
# endif
# ifndef GLUT_BUILDING_LIB
extern _CRTIMP void __cdecl exit(int);
# endif
/* GLUT callback calling convention for Win32. */
# define GLUTCALLBACK __cdecl
/* for callback/function pointer defs */
# define GLUTAPIENTRYV __cdecl
/* glut-win32 specific macros, defined to prevent collision with
and redifinition of Windows system defs, also removes requirement of
pretty much any standard windows header from this file */
#if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
# define GLUTAPIENTRY __stdcall
#else
# define GLUTAPIENTRY
#endif
/* GLUT API entry point declarations for Win32. */
#if defined(GLUT_BUILDING_LIB) && defined(_DLL)
# define GLUTAPI __declspec(dllexport)
#elif defined(_DLL)
# define GLUTAPI __declspec(dllimport)
#else
# define GLUTAPI extern
#endif
#if defined(_WIN32) && !defined(_WINDEF_) && !defined(MESA)
# if !defined(MESA_MINWARN)
# pragma message( "note: WINDOWS.H not included, providing Mesa definition of CALLBACK macro" )
# pragma message( "----: and PROC typedef. If you receive compiler warnings about either ")
# pragma message( "----: being multiply defined you should include WINDOWS.H priot to gl/glut.h" )
# endif
# define CALLBACK __stdcall
typedef int (GLUTAPIENTRY *PROC)();
typedef void *HGLRC;
typedef void *HDC;
typedef unsigned long COLORREF;
#endif
#if defined(_WIN32) && !defined(_WINGDI_) && !defined(MESA)
# if !defined(MESA_MINWARN)
# pragma message( "note: WINDOWS.H not included, providing Mesa definition of wgl functions" )
# pragma message( "----: and macros. If you receive compiler warnings about any being multiply ")
# pragma message( "----: defined you should include WINDOWS.H priot to gl/glut.h" )
# endif
# define WGL_FONT_LINES 0
# define WGL_FONT_POLYGONS 1
# ifdef UNICODE
# define wglUseFontBitmaps wglUseFontBitmapsW
# define wglUseFontOutlines wglUseFontOutlinesW
# else
# define wglUseFontBitmaps wglUseFontBitmapsA
# define wglUseFontOutlines wglUseFontOutlinesA
# endif /* !UNICODE */
typedef struct tagLAYERPLANEDESCRIPTOR LAYERPLANEDESCRIPTOR, *PLAYERPLANEDESCRIPTOR, *LPLAYERPLANEDESCRIPTOR;
typedef struct _GLYPHMETRICSFLOAT GLYPHMETRICSFLOAT, *PGLYPHMETRICSFLOAT, *LPGLYPHMETRICSFLOAT;
GLUTAPI int GLUTAPIENTRY wglCopyContext(HGLRC, HGLRC, unsigned int);
GLUTAPI HGLRC GLUTAPIENTRY wglCreateContext(HDC);
GLUTAPI HGLRC GLUTAPIENTRY wglCreateLayerContext(HDC, int);
GLUTAPI int GLUTAPIENTRY wglDeleteContext(HGLRC);
GLUTAPI HGLRC GLUTAPIENTRY wglGetCurrentContext(void);
GLUTAPI HDC GLUTAPIENTRY wglGetCurrentDC(void);
GLUTAPI PROC GLUTAPIENTRY wglGetProcAddress(char*);
GLUTAPI int GLUTAPIENTRY wglMakeCurrent(HDC, HGLRC);
GLUTAPI int GLUTAPIENTRY wglShareLists(HGLRC, HGLRC);
GLUTAPI int GLUTAPIENTRY wglUseFontBitmapsA(HDC, unsigned long, unsigned long, unsigned long);
GLUTAPI int GLUTAPIENTRY wglUseFontBitmapsW(HDC, unsigned long, unsigned long, unsigned long);
GLUTAPI int GLUTAPIENTRY wglUseFontOutlinesA(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT);
GLUTAPI int GLUTAPIENTRY wglUseFontOutlinesW(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT);
GLUTAPI int GLUTAPIENTRY wglDescribeLayerPlane(HDC, int, int, unsigned int,LPLAYERPLANEDESCRIPTOR);
GLUTAPI int GLUTAPIENTRY wglSetLayerPaletteEntries(HDC, int, int, int,const COLORREF *);
GLUTAPI int GLUTAPIENTRY wglGetLayerPaletteEntries(HDC, int, int, int,COLORREF *);
GLUTAPI int GLUTAPIENTRY wglRealizeLayerPalette(HDC, int, int);
GLUTAPI int GLUTAPIENTRY wglSwapLayerBuffers(HDC, unsigned int);
GLUTAPI int GLUTAPIENTRY SwapBuffers(HDC);
#endif
#else /* _WIN32 not defined */
/* Define GLUTAPIENTRY and GLUTCALLBACK to nothing if we aren't on Win32. */
# define GLUTAPIENTRY
# define GLUTAPIENTRYV
# define GLUT_APIENTRY_DEFINED
# define GLUTCALLBACK
# define GLUTAPI extern
/* Prototype exit for the non-Win32 case (see above). */
extern void exit(int);
#endif
/**
GLUT API revision history:
GLUT_API_VERSION is updated to reflect incompatible GLUT
API changes (interface changes, semantic changes, deletions,
or additions).
GLUT_API_VERSION=1 First public release of GLUT. 11/29/94
GLUT_API_VERSION=2 Added support for OpenGL/GLX multisampling,
extension. Supports new input devices like tablet, dial and button
box, and Spaceball. Easy to query OpenGL extensions.
GLUT_API_VERSION=3 glutMenuStatus added.
GLUT_API_VERSION=4 glutInitDisplayString, glutWarpPointer,
glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic
video resize subAPI, glutPostWindowRedisplay, glutKeyboardUpFunc,
glutSpecialUpFunc, glutIgnoreKeyRepeat, glutSetKeyRepeat,
glutJoystickFunc, glutForceJoystickFunc (NOT FINALIZED!).
**/
#ifndef GLUT_API_VERSION /* allow this to be overriden */
#define GLUT_API_VERSION 3
#endif
/**
GLUT implementation revision history:
GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT
API revisions and implementation revisions (ie, bug fixes).
GLUT_XLIB_IMPLEMENTATION=1 mjk's first public release of
GLUT Xlib-based implementation. 11/29/94
GLUT_XLIB_IMPLEMENTATION=2 mjk's second public release of
GLUT Xlib-based implementation providing GLUT version 2
interfaces.
GLUT_XLIB_IMPLEMENTATION=3 mjk's GLUT 2.2 images. 4/17/95
GLUT_XLIB_IMPLEMENTATION=4 mjk's GLUT 2.3 images. 6/?/95
GLUT_XLIB_IMPLEMENTATION=5 mjk's GLUT 3.0 images. 10/?/95
GLUT_XLIB_IMPLEMENTATION=7 mjk's GLUT 3.1+ with glutWarpPoitner. 7/24/96
GLUT_XLIB_IMPLEMENTATION=8 mjk's GLUT 3.1+ with glutWarpPoitner
and video resize. 1/3/97
GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines.
GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release.
GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling.
GLUT_XLIB_IMPLEMENTATION=13 mjk's GLUT 3.7 beta with GameGLUT support.
GLUT_XLIB_IMPLEMENTATION=14 mjk's GLUT 3.7 beta with f90gl friend interface.
GLUT_XLIB_IMPLEMENTATION=15 mjk's GLUT 3.7 beta sync'ed with Mesa <GL/glut.h>
**/
#ifndef GLUT_XLIB_IMPLEMENTATION /* Allow this to be overriden. */
#define GLUT_XLIB_IMPLEMENTATION 15
#endif
/* Display mode bit masks. */
#define GLUT_RGB 0
#define GLUT_RGBA GLUT_RGB
#define GLUT_INDEX 1
#define GLUT_SINGLE 0
#define GLUT_DOUBLE 2
#define GLUT_ACCUM 4
#define GLUT_ALPHA 8
#define GLUT_DEPTH 16
#define GLUT_STENCIL 32
#if (GLUT_API_VERSION >= 2)
#define GLUT_MULTISAMPLE 128
#define GLUT_STEREO 256
#endif
#if (GLUT_API_VERSION >= 3)
#define GLUT_LUMINANCE 512
#endif
/* Mouse buttons. */
#define GLUT_LEFT_BUTTON 0
#define GLUT_MIDDLE_BUTTON 1
#define GLUT_RIGHT_BUTTON 2
/* Mouse button state. */
#define GLUT_DOWN 0
#define GLUT_UP 1
#if (GLUT_API_VERSION >= 2)
/* function keys */
#define GLUT_KEY_F1 1
#define GLUT_KEY_F2 2
#define GLUT_KEY_F3 3
#define GLUT_KEY_F4 4
#define GLUT_KEY_F5 5
#define GLUT_KEY_F6 6
#define GLUT_KEY_F7 7
#define GLUT_KEY_F8 8
#define GLUT_KEY_F9 9
#define GLUT_KEY_F10 10
#define GLUT_KEY_F11 11
#define GLUT_KEY_F12 12
/* directional keys */
#define GLUT_KEY_LEFT 100
#define GLUT_KEY_UP 101
#define GLUT_KEY_RIGHT 102
#define GLUT_KEY_DOWN 103
#define GLUT_KEY_PAGE_UP 104
#define GLUT_KEY_PAGE_DOWN 105
#define GLUT_KEY_HOME 106
#define GLUT_KEY_END 107
#define GLUT_KEY_INSERT 108
#endif
/* Entry/exit state. */
#define GLUT_LEFT 0
#define GLUT_ENTERED 1
/* Menu usage state. */
#define GLUT_MENU_NOT_IN_USE 0
#define GLUT_MENU_IN_USE 1
/* Visibility state. */
#define GLUT_NOT_VISIBLE 0
#define GLUT_VISIBLE 1
/* Window status state. */
#define GLUT_HIDDEN 0
#define GLUT_FULLY_RETAINED 1
#define GLUT_PARTIALLY_RETAINED 2
#define GLUT_FULLY_COVERED 3
/* Color index component selection values. */
#define GLUT_RED 0
#define GLUT_GREEN 1
#define GLUT_BLUE 2
/* Layers for use. */
#define GLUT_NORMAL 0
#define GLUT_OVERLAY 1
#if defined(_WIN32)
/* Stroke font constants (use these in GLUT program). */
#define GLUT_STROKE_ROMAN ((void*)0)
#define GLUT_STROKE_MONO_ROMAN ((void*)1)
/* Bitmap font constants (use these in GLUT program). */
#define GLUT_BITMAP_9_BY_15 ((void*)2)
#define GLUT_BITMAP_8_BY_13 ((void*)3)
#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4)
#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5)
#if (GLUT_API_VERSION >= 3)
#define GLUT_BITMAP_HELVETICA_10 ((void*)6)
#define GLUT_BITMAP_HELVETICA_12 ((void*)7)
#define GLUT_BITMAP_HELVETICA_18 ((void*)8)
#endif
#else
/* Stroke font opaque addresses (use constants instead in source code). */
GLUTAPI void *glutStrokeRoman;
GLUTAPI void *glutStrokeMonoRoman;
/* Stroke font constants (use these in GLUT program). */
#define GLUT_STROKE_ROMAN (&glutStrokeRoman)
#define GLUT_STROKE_MONO_ROMAN (&glutStrokeMonoRoman)
/* Bitmap font opaque addresses (use constants instead in source code). */
GLUTAPI void *glutBitmap9By15;
GLUTAPI void *glutBitmap8By13;
GLUTAPI void *glutBitmapTimesRoman10;
GLUTAPI void *glutBitmapTimesRoman24;
GLUTAPI void *glutBitmapHelvetica10;
GLUTAPI void *glutBitmapHelvetica12;
GLUTAPI void *glutBitmapHelvetica18;
/* Bitmap font constants (use these in GLUT program). */
#define GLUT_BITMAP_9_BY_15 (&glutBitmap9By15)
#define GLUT_BITMAP_8_BY_13 (&glutBitmap8By13)
#define GLUT_BITMAP_TIMES_ROMAN_10 (&glutBitmapTimesRoman10)
#define GLUT_BITMAP_TIMES_ROMAN_24 (&glutBitmapTimesRoman24)
#if (GLUT_API_VERSION >= 3)
#define GLUT_BITMAP_HELVETICA_10 (&glutBitmapHelvetica10)
#define GLUT_BITMAP_HELVETICA_12 (&glutBitmapHelvetica12)
#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18)
#endif
#endif
/* glutGet parameters. */
#define GLUT_WINDOW_X 100
#define GLUT_WINDOW_Y 101
#define GLUT_WINDOW_WIDTH 102
#define GLUT_WINDOW_HEIGHT 103
#define GLUT_WINDOW_BUFFER_SIZE 104
#define GLUT_WINDOW_STENCIL_SIZE 105
#define GLUT_WINDOW_DEPTH_SIZE 106
#define GLUT_WINDOW_RED_SIZE 107
#define GLUT_WINDOW_GREEN_SIZE 108
#define GLUT_WINDOW_BLUE_SIZE 109
#define GLUT_WINDOW_ALPHA_SIZE 110
#define GLUT_WINDOW_ACCUM_RED_SIZE 111
#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112
#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113
#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114
#define GLUT_WINDOW_DOUBLEBUFFER 115
#define GLUT_WINDOW_RGBA 116
#define GLUT_WINDOW_PARENT 117
#define GLUT_WINDOW_NUM_CHILDREN 118
#define GLUT_WINDOW_COLORMAP_SIZE 119
#if (GLUT_API_VERSION >= 2)
#define GLUT_WINDOW_NUM_SAMPLES 120
#define GLUT_WINDOW_STEREO 121
#endif
#if (GLUT_API_VERSION >= 3)
#define GLUT_WINDOW_CURSOR 122
#endif
#define GLUT_SCREEN_WIDTH 200
#define GLUT_SCREEN_HEIGHT 201
#define GLUT_SCREEN_WIDTH_MM 202
#define GLUT_SCREEN_HEIGHT_MM 203
#define GLUT_MENU_NUM_ITEMS 300
#define GLUT_DISPLAY_MODE_POSSIBLE 400
#define GLUT_INIT_WINDOW_X 500
#define GLUT_INIT_WINDOW_Y 501
#define GLUT_INIT_WINDOW_WIDTH 502
#define GLUT_INIT_WINDOW_HEIGHT 503
#define GLUT_INIT_DISPLAY_MODE 504
#if (GLUT_API_VERSION >= 2)
#define GLUT_ELAPSED_TIME 700
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
#define GLUT_WINDOW_FORMAT_ID 123
#endif
#if (GLUT_API_VERSION >= 2)
/* glutDeviceGet parameters. */
#define GLUT_HAS_KEYBOARD 600
#define GLUT_HAS_MOUSE 601
#define GLUT_HAS_SPACEBALL 602
#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603
#define GLUT_HAS_TABLET 604
#define GLUT_NUM_MOUSE_BUTTONS 605
#define GLUT_NUM_SPACEBALL_BUTTONS 606
#define GLUT_NUM_BUTTON_BOX_BUTTONS 607
#define GLUT_NUM_DIALS 608
#define GLUT_NUM_TABLET_BUTTONS 609
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
#define GLUT_DEVICE_IGNORE_KEY_REPEAT 610
#define GLUT_DEVICE_KEY_REPEAT 611
#define GLUT_HAS_JOYSTICK 612
#define GLUT_OWNS_JOYSTICK 613
#define GLUT_JOYSTICK_BUTTONS 614
#define GLUT_JOYSTICK_AXES 615
#define GLUT_JOYSTICK_POLL_RATE 616
#endif
#if (GLUT_API_VERSION >= 3)
/* glutLayerGet parameters. */
#define GLUT_OVERLAY_POSSIBLE 800
#define GLUT_LAYER_IN_USE 801
#define GLUT_HAS_OVERLAY 802
#define GLUT_TRANSPARENT_INDEX 803
#define GLUT_NORMAL_DAMAGED 804
#define GLUT_OVERLAY_DAMAGED 805
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
/* glutVideoResizeGet parameters. */
#define GLUT_VIDEO_RESIZE_POSSIBLE 900
#define GLUT_VIDEO_RESIZE_IN_USE 901
#define GLUT_VIDEO_RESIZE_X_DELTA 902
#define GLUT_VIDEO_RESIZE_Y_DELTA 903
#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
#define GLUT_VIDEO_RESIZE_X 906
#define GLUT_VIDEO_RESIZE_Y 907
#define GLUT_VIDEO_RESIZE_WIDTH 908
#define GLUT_VIDEO_RESIZE_HEIGHT 909
#endif
/* glutUseLayer parameters. */
#define GLUT_NORMAL 0
#define GLUT_OVERLAY 1
/* glutGetModifiers return mask. */
#define GLUT_ACTIVE_SHIFT 1
#define GLUT_ACTIVE_CTRL 2
#define GLUT_ACTIVE_ALT 4
/* glutSetCursor parameters. */
/* Basic arrows. */
#define GLUT_CURSOR_RIGHT_ARROW 0
#define GLUT_CURSOR_LEFT_ARROW 1
/* Symbolic cursor shapes. */
#define GLUT_CURSOR_INFO 2
#define GLUT_CURSOR_DESTROY 3
#define GLUT_CURSOR_HELP 4
#define GLUT_CURSOR_CYCLE 5
#define GLUT_CURSOR_SPRAY 6
#define GLUT_CURSOR_WAIT 7
#define GLUT_CURSOR_TEXT 8
#define GLUT_CURSOR_CROSSHAIR 9
/* Directional cursors. */
#define GLUT_CURSOR_UP_DOWN 10
#define GLUT_CURSOR_LEFT_RIGHT 11
/* Sizing cursors. */
#define GLUT_CURSOR_TOP_SIDE 12
#define GLUT_CURSOR_BOTTOM_SIDE 13
#define GLUT_CURSOR_LEFT_SIDE 14
#define GLUT_CURSOR_RIGHT_SIDE 15
#define GLUT_CURSOR_TOP_LEFT_CORNER 16
#define GLUT_CURSOR_TOP_RIGHT_CORNER 17
#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18
#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19
/* Inherit from parent window. */
#define GLUT_CURSOR_INHERIT 100
/* Blank cursor. */
#define GLUT_CURSOR_NONE 101
/* Fullscreen crosshair (if available). */
#define GLUT_CURSOR_FULL_CROSSHAIR 102
#endif
/* GLUT initialization sub-API. */
GLUTAPI void GLUTAPIENTRY glutInit(int *argcp, char **argv);
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI void GLUTAPIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static void GLUTAPIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
#define glutInit glutInit_ATEXIT_HACK
#endif
#endif
GLUTAPI void GLUTAPIENTRY glutInitDisplayMode(unsigned int mode);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void GLUTAPIENTRY glutInitDisplayString(const char *string);
#endif
GLUTAPI void GLUTAPIENTRY glutInitWindowPosition(int x, int y);
GLUTAPI void GLUTAPIENTRY glutInitWindowSize(int width, int height);
GLUTAPI void GLUTAPIENTRY glutMainLoop(void);
/* GLUT window sub-API. */
GLUTAPI int GLUTAPIENTRY glutCreateWindow(const char *title);
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI int GLUTAPIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static int GLUTAPIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
#endif
#endif
GLUTAPI int GLUTAPIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
GLUTAPI void GLUTAPIENTRY glutDestroyWindow(int win);
GLUTAPI void GLUTAPIENTRY glutPostRedisplay(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
GLUTAPI void GLUTAPIENTRY glutPostWindowRedisplay(int win);
#endif
GLUTAPI void GLUTAPIENTRY glutSwapBuffers(void);
GLUTAPI int GLUTAPIENTRY glutGetWindow(void);
GLUTAPI void GLUTAPIENTRY glutSetWindow(int win);
GLUTAPI void GLUTAPIENTRY glutSetWindowTitle(const char *title);
GLUTAPI void GLUTAPIENTRY glutSetIconTitle(const char *title);
GLUTAPI void GLUTAPIENTRY glutPositionWindow(int x, int y);
GLUTAPI void GLUTAPIENTRY glutReshapeWindow(int width, int height);
GLUTAPI void GLUTAPIENTRY glutPopWindow(void);
GLUTAPI void GLUTAPIENTRY glutPushWindow(void);
GLUTAPI void GLUTAPIENTRY glutIconifyWindow(void);
GLUTAPI void GLUTAPIENTRY glutShowWindow(void);
GLUTAPI void GLUTAPIENTRY glutHideWindow(void);
#if (GLUT_API_VERSION >= 3)
GLUTAPI void GLUTAPIENTRY glutFullScreen(void);
GLUTAPI void GLUTAPIENTRY glutSetCursor(int cursor);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void GLUTAPIENTRY glutWarpPointer(int x, int y);
#endif
/* GLUT overlay sub-API. */
GLUTAPI void GLUTAPIENTRY glutEstablishOverlay(void);
GLUTAPI void GLUTAPIENTRY glutRemoveOverlay(void);
GLUTAPI void GLUTAPIENTRY glutUseLayer(GLenum layer);
GLUTAPI void GLUTAPIENTRY glutPostOverlayRedisplay(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
GLUTAPI void GLUTAPIENTRY glutPostWindowOverlayRedisplay(int win);
#endif
GLUTAPI void GLUTAPIENTRY glutShowOverlay(void);
GLUTAPI void GLUTAPIENTRY glutHideOverlay(void);
#endif
/* GLUT menu sub-API. */
GLUTAPI int GLUTAPIENTRY glutCreateMenu(void (GLUTCALLBACK *func)(int));
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI int GLUTAPIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static int GLUTAPIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); }
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
#endif
#endif
GLUTAPI void GLUTAPIENTRY glutDestroyMenu(int menu);
GLUTAPI int GLUTAPIENTRY glutGetMenu(void);
GLUTAPI void GLUTAPIENTRY glutSetMenu(int menu);
GLUTAPI void GLUTAPIENTRY glutAddMenuEntry(const char *label, int value);
GLUTAPI void GLUTAPIENTRY glutAddSubMenu(const char *label, int submenu);
GLUTAPI void GLUTAPIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
GLUTAPI void GLUTAPIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
GLUTAPI void GLUTAPIENTRY glutRemoveMenuItem(int item);
GLUTAPI void GLUTAPIENTRY glutAttachMenu(int button);
GLUTAPI void GLUTAPIENTRY glutDetachMenu(int button);
/* GLUT window callback sub-API. */
GLUTAPI void GLUTAPIENTRY glutDisplayFunc(void (GLUTCALLBACK *func)(void));
GLUTAPI void GLUTAPIENTRY glutReshapeFunc(void (GLUTCALLBACK *func)(int width, int height));
GLUTAPI void GLUTAPIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
GLUTAPI void GLUTAPIENTRY glutMouseFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
GLUTAPI void GLUTAPIENTRY glutMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void GLUTAPIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void GLUTAPIENTRY glutEntryFunc(void (GLUTCALLBACK *func)(int state));
GLUTAPI void GLUTAPIENTRY glutVisibilityFunc(void (GLUTCALLBACK *func)(int state));
GLUTAPI void GLUTAPIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void));
GLUTAPI void GLUTAPIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value);
GLUTAPI void GLUTAPIENTRY glutMenuStateFunc(void (GLUTCALLBACK *func)(int state));
#if (GLUT_API_VERSION >= 2)
GLUTAPI void GLUTAPIENTRY glutSpecialFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
GLUTAPI void GLUTAPIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
GLUTAPI void GLUTAPIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
GLUTAPI void GLUTAPIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK *func)(int button, int state));
GLUTAPI void GLUTAPIENTRY glutButtonBoxFunc(void (GLUTCALLBACK *func)(int button, int state));
GLUTAPI void GLUTAPIENTRY glutDialsFunc(void (GLUTCALLBACK *func)(int dial, int value));
GLUTAPI void GLUTAPIENTRY glutTabletMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
GLUTAPI void GLUTAPIENTRY glutTabletButtonFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
#if (GLUT_API_VERSION >= 3)
GLUTAPI void GLUTAPIENTRY glutMenuStatusFunc(void (GLUTCALLBACK *func)(int status, int x, int y));
GLUTAPI void GLUTAPIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK *func)(void));
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI void GLUTAPIENTRY glutWindowStatusFunc(void (GLUTCALLBACK *func)(int state));
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
GLUTAPI void GLUTAPIENTRY glutKeyboardUpFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
GLUTAPI void GLUTAPIENTRY glutSpecialUpFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
GLUTAPI void GLUTAPIENTRY glutJoystickFunc(void (GLUTCALLBACK *func)(unsigned int buttonMask, int x, int y, int z), int pollInterval);
#endif
#endif
#endif
/* GLUT color index sub-API. */
GLUTAPI void GLUTAPIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
GLUTAPI GLfloat GLUTAPIENTRY glutGetColor(int ndx, int component);
GLUTAPI void GLUTAPIENTRY glutCopyColormap(int win);
/* GLUT state retrieval sub-API. */
GLUTAPI int GLUTAPIENTRY glutGet(GLenum type);
GLUTAPI int GLUTAPIENTRY glutDeviceGet(GLenum type);
#if (GLUT_API_VERSION >= 2)
/* GLUT extension support sub-API */
GLUTAPI int GLUTAPIENTRY glutExtensionSupported(const char *name);
#endif
#if (GLUT_API_VERSION >= 3)
GLUTAPI int GLUTAPIENTRY glutGetModifiers(void);
GLUTAPI int GLUTAPIENTRY glutLayerGet(GLenum type);
#endif
/* GLUT font sub-API */
GLUTAPI void GLUTAPIENTRY glutBitmapCharacter(void *font, int character);
GLUTAPI int GLUTAPIENTRY glutBitmapWidth(void *font, int character);
GLUTAPI void GLUTAPIENTRY glutStrokeCharacter(void *font, int character);
GLUTAPI int GLUTAPIENTRY glutStrokeWidth(void *font, int character);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
GLUTAPI int GLUTAPIENTRY glutBitmapLength(void *font, const unsigned char *string);
GLUTAPI int GLUTAPIENTRY glutStrokeLength(void *font, const unsigned char *string);
#endif
/* GLUT pre-built models sub-API */
GLUTAPI void GLUTAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void GLUTAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void GLUTAPIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void GLUTAPIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void GLUTAPIENTRY glutWireCube(GLdouble size);
GLUTAPI void GLUTAPIENTRY glutSolidCube(GLdouble size);
GLUTAPI void GLUTAPIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void GLUTAPIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void GLUTAPIENTRY glutWireDodecahedron(void);
GLUTAPI void GLUTAPIENTRY glutSolidDodecahedron(void);
GLUTAPI void GLUTAPIENTRY glutWireTeapot(GLdouble size);
GLUTAPI void GLUTAPIENTRY glutSolidTeapot(GLdouble size);
GLUTAPI void GLUTAPIENTRY glutWireOctahedron(void);
GLUTAPI void GLUTAPIENTRY glutSolidOctahedron(void);
GLUTAPI void GLUTAPIENTRY glutWireTetrahedron(void);
GLUTAPI void GLUTAPIENTRY glutSolidTetrahedron(void);
GLUTAPI void GLUTAPIENTRY glutWireIcosahedron(void);
GLUTAPI void GLUTAPIENTRY glutSolidIcosahedron(void);
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
/* GLUT video resize sub-API. */
GLUTAPI int GLUTAPIENTRY glutVideoResizeGet(GLenum param);
GLUTAPI void GLUTAPIENTRY glutSetupVideoResizing(void);
GLUTAPI void GLUTAPIENTRY glutStopVideoResizing(void);
GLUTAPI void GLUTAPIENTRY glutVideoResize(int x, int y, int width, int height);
GLUTAPI void GLUTAPIENTRY glutVideoPan(int x, int y, int width, int height);
/* GLUT debugging sub-API. */
GLUTAPI void GLUTAPIENTRY glutReportErrors(void);
#endif
#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
/* GLUT device control sub-API. */
/* glutSetKeyRepeat modes. */
#define GLUT_KEY_REPEAT_OFF 0
#define GLUT_KEY_REPEAT_ON 1
#define GLUT_KEY_REPEAT_DEFAULT 2
/* Joystick button masks. */
#define GLUT_JOYSTICK_BUTTON_A 1
#define GLUT_JOYSTICK_BUTTON_B 2
#define GLUT_JOYSTICK_BUTTON_C 4
#define GLUT_JOYSTICK_BUTTON_D 8
GLUTAPI void GLUTAPIENTRY glutIgnoreKeyRepeat(int ignore);
GLUTAPI void GLUTAPIENTRY glutSetKeyRepeat(int repeatMode);
GLUTAPI void GLUTAPIENTRY glutForceJoystickFunc(void);
/* GLUT game mode sub-API. */
/* glutGameModeGet. */
#define GLUT_GAME_MODE_ACTIVE 0
#define GLUT_GAME_MODE_POSSIBLE 1
#define GLUT_GAME_MODE_WIDTH 2
#define GLUT_GAME_MODE_HEIGHT 3
#define GLUT_GAME_MODE_PIXEL_DEPTH 4
#define GLUT_GAME_MODE_REFRESH_RATE 5
#define GLUT_GAME_MODE_DISPLAY_CHANGED 6
GLUTAPI void GLUTAPIENTRY glutGameModeString(const char *string);
GLUTAPI int GLUTAPIENTRY glutEnterGameMode(void);
GLUTAPI void GLUTAPIENTRY glutLeaveGameMode(void);
GLUTAPI int GLUTAPIENTRY glutGameModeGet(GLenum mode);
#endif
#ifdef __cplusplus
}
#endif
#if 0
#ifdef GLUT_APIENTRY_DEFINED
# undef GLUT_APIENTRY_DEFINED
# undef APIENTRY
#endif
#ifdef GLUT_WINGDIAPI_DEFINED
# undef GLUT_WINGDIAPI_DEFINED
# undef WINGDIAPI
#endif
#ifdef GLUT_DEFINED___CDECL
# undef GLUT_DEFINED___CDECL
# undef __cdecl
#endif
#ifdef GLUT_DEFINED__CRTIMP
# undef GLUT_DEFINED__CRTIMP
# undef _CRTIMP
#endif
#endif
#endif /* __glut_h__ */

352
include/GL/glut_h.dja Normal file
View file

@ -0,0 +1,352 @@
/* $Id*/
/*
* Mesa 3-D graphics library
* Version: 3.1
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: glut_h.dja,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.1 1999/06/23 00:51:27 brianp
* initial check-in
*
*/
/*
* This header file is based on the REAL glut.h by Mark J. Kilgard.
*
* The DJGPP/ALLEGRO (DJA) GLUT implementation was written by
* Bernhard Tschirren (bernie-t@geocities.com) for the sole purpose
* of compiling all the sample programs (which use GLUT). Therefore,
* is NOT AT ALL a complete version of GLUT!
*/
#ifndef __AGLUT_H__
#define __AGLUT_H__
#include <GL/gl.h>
#include <GL/glu.h>
#define GLUTCALLBACK
#define APIENTRY
#define GLUTAPI extern
#define GLUT_RGB 0
#define GLUT_RGBA GLUT_RGB
#define GLUT_INDEX 1
#define GLUT_SINGLE 0
#define GLUT_DOUBLE 2
#define GLUT_ACCUM 4
#define GLUT_ALPHA 8
#define GLUT_DEPTH 16
#define GLUT_STENCIL 32
/* Mouse buttons. */
#define GLUT_LEFT_BUTTON 0
#define GLUT_MIDDLE_BUTTON 1
#define GLUT_RIGHT_BUTTON 2
/* Mouse button state. */
#define GLUT_DOWN 0
#define GLUT_UP 1
/* function keys */
#define GLUT_KEY_F1 1
#define GLUT_KEY_F2 2
#define GLUT_KEY_F3 3
#define GLUT_KEY_F4 4
#define GLUT_KEY_F5 5
#define GLUT_KEY_F6 6
#define GLUT_KEY_F7 7
#define GLUT_KEY_F8 8
#define GLUT_KEY_F9 9
#define GLUT_KEY_F10 10
#define GLUT_KEY_F11 11
#define GLUT_KEY_F12 12
/* directional keys */
#define GLUT_KEY_LEFT 100
#define GLUT_KEY_UP 101
#define GLUT_KEY_RIGHT 102
#define GLUT_KEY_DOWN 103
#define GLUT_KEY_PAGE_UP 104
#define GLUT_KEY_PAGE_DOWN 105
#define GLUT_KEY_HOME 106
#define GLUT_KEY_END 107
#define GLUT_KEY_INSERT 108
/* Entry/exit state. */
#define GLUT_LEFT 0
#define GLUT_ENTERED 1
/* Visibility state. */
#define GLUT_NOT_VISIBLE 0
#define GLUT_VISIBLE 1
/* Color index component selection values. */
#define GLUT_RED 0
#define GLUT_GREEN 1
#define GLUT_BLUE 2
/* Layers for use. */
#define GLUT_NORMAL 0
#define GLUT_OVERLAY 1
/* Stroke font constants (use these in GLUT program). */
#define GLUT_STROKE_ROMAN ((void*)0)
#define GLUT_STROKE_MONO_ROMAN ((void*)1)
/* Bitmap font constants (use these in GLUT program). */
#define GLUT_BITMAP_9_BY_15 ((void*)2)
#define GLUT_BITMAP_8_BY_13 ((void*)3)
#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4)
#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5)
#define GLUT_BITMAP_HELVETICA_10 ((void*)6)
#define GLUT_BITMAP_HELVETICA_12 ((void*)7)
#define GLUT_BITMAP_HELVETICA_18 ((void*)8)
/* glutGet parameters. */
#define GLUT_WINDOW_X 100
#define GLUT_WINDOW_Y 101
#define GLUT_WINDOW_WIDTH 102
#define GLUT_WINDOW_HEIGHT 103
#define GLUT_WINDOW_BUFFER_SIZE 104
#define GLUT_WINDOW_STENCIL_SIZE 105
#define GLUT_WINDOW_DEPTH_SIZE 106
#define GLUT_WINDOW_RED_SIZE 107
#define GLUT_WINDOW_GREEN_SIZE 108
#define GLUT_WINDOW_BLUE_SIZE 109
#define GLUT_WINDOW_ALPHA_SIZE 110
#define GLUT_WINDOW_ACCUM_RED_SIZE 111
#define GLUT_WINDOW_ACCUM_GREEN_SIZE 112
#define GLUT_WINDOW_ACCUM_BLUE_SIZE 113
#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 114
#define GLUT_WINDOW_DOUBLEBUFFER 115
#define GLUT_WINDOW_RGBA 116
#define GLUT_WINDOW_PARENT 117
#define GLUT_WINDOW_NUM_CHILDREN 118
#define GLUT_WINDOW_COLORMAP_SIZE 119
#define GLUT_WINDOW_NUM_SAMPLES 120
#define GLUT_WINDOW_STEREO 121
#define GLUT_WINDOW_CURSOR 122
#define GLUT_SCREEN_WIDTH 200
#define GLUT_SCREEN_HEIGHT 201
#define GLUT_SCREEN_WIDTH_MM 202
#define GLUT_SCREEN_HEIGHT_MM 203
#define GLUT_MENU_NUM_ITEMS 300
#define GLUT_DISPLAY_MODE_POSSIBLE 400
#define GLUT_INIT_WINDOW_X 500
#define GLUT_INIT_WINDOW_Y 501
#define GLUT_INIT_WINDOW_WIDTH 502
#define GLUT_INIT_WINDOW_HEIGHT 503
#define GLUT_INIT_DISPLAY_MODE 504
#define GLUT_ELAPSED_TIME 700
#define GLUT_WINDOW_FORMAT_ID 123
/* glutDeviceGet parameters. */
#define GLUT_HAS_KEYBOARD 600
#define GLUT_HAS_MOUSE 601
#define GLUT_HAS_SPACEBALL 602
#define GLUT_HAS_DIAL_AND_BUTTON_BOX 603
#define GLUT_HAS_TABLET 604
#define GLUT_NUM_MOUSE_BUTTONS 605
#define GLUT_NUM_SPACEBALL_BUTTONS 606
#define GLUT_NUM_BUTTON_BOX_BUTTONS 607
#define GLUT_NUM_DIALS 608
#define GLUT_NUM_TABLET_BUTTONS 609
#define GLUT_DEVICE_IGNORE_KEY_REPEAT 610
#define GLUT_DEVICE_KEY_REPEAT 611
#define GLUT_HAS_JOYSTICK 612
#define GLUT_OWNS_JOYSTICK 613
#define GLUT_JOYSTICK_BUTTONS 614
#define GLUT_JOYSTICK_AXES 615
#define GLUT_JOYSTICK_POLL_RATE 616
/* glutLayerGet parameters. */
#define GLUT_OVERLAY_POSSIBLE 800
#define GLUT_LAYER_IN_USE 801
#define GLUT_HAS_OVERLAY 802
#define GLUT_TRANSPARENT_INDEX 803
#define GLUT_NORMAL_DAMAGED 804
#define GLUT_OVERLAY_DAMAGED 805
/* glutVideoResizeGet parameters. */
#define GLUT_VIDEO_RESIZE_POSSIBLE 900
#define GLUT_VIDEO_RESIZE_IN_USE 901
#define GLUT_VIDEO_RESIZE_X_DELTA 902
#define GLUT_VIDEO_RESIZE_Y_DELTA 903
#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 904
#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 905
#define GLUT_VIDEO_RESIZE_X 906
#define GLUT_VIDEO_RESIZE_Y 907
#define GLUT_VIDEO_RESIZE_WIDTH 908
#define GLUT_VIDEO_RESIZE_HEIGHT 909
/* glutUseLayer parameters. */
#define GLUT_NORMAL 0
#define GLUT_OVERLAY 1
/* glutGetModifiers return mask. */
#define GLUT_ACTIVE_SHIFT 1
#define GLUT_ACTIVE_CTRL 2
#define GLUT_ACTIVE_ALT 4
/* glutSetCursor parameters. */
/* Basic arrows. */
#define GLUT_CURSOR_RIGHT_ARROW 0
#define GLUT_CURSOR_LEFT_ARROW 1
/* Symbolic cursor shapes. */
#define GLUT_CURSOR_INFO 2
#define GLUT_CURSOR_DESTROY 3
#define GLUT_CURSOR_HELP 4
#define GLUT_CURSOR_CYCLE 5
#define GLUT_CURSOR_SPRAY 6
#define GLUT_CURSOR_WAIT 7
#define GLUT_CURSOR_TEXT 8
#define GLUT_CURSOR_CROSSHAIR 9
/* Directional cursors. */
#define GLUT_CURSOR_UP_DOWN 10
#define GLUT_CURSOR_LEFT_RIGHT 11
/* Sizing cursors. */
#define GLUT_CURSOR_TOP_SIDE 12
#define GLUT_CURSOR_BOTTOM_SIDE 13
#define GLUT_CURSOR_LEFT_SIDE 14
#define GLUT_CURSOR_RIGHT_SIDE 15
#define GLUT_CURSOR_TOP_LEFT_CORNER 16
#define GLUT_CURSOR_TOP_RIGHT_CORNER 17
#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18
#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 19
/* Inherit from parent window. */
#define GLUT_CURSOR_INHERIT 100
/* Blank cursor. */
#define GLUT_CURSOR_NONE 101
/* Fullscreen crosshair (if available). */
#define GLUT_CURSOR_FULL_CROSSHAIR 102
/* GLUT initialization sub-API. */
GLUTAPI void APIENTRY glutInit(int *argcp, char **argv);
GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode);
GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y);
GLUTAPI void APIENTRY glutInitWindowSize(int width, int height);
GLUTAPI void APIENTRY glutMainLoop(void);
/* GLUT window sub-API. */
GLUTAPI int APIENTRY glutCreateWindow(const char *title);
GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
GLUTAPI void APIENTRY glutDestroyWindow(int win);
GLUTAPI void APIENTRY glutPostRedisplay(void);
GLUTAPI void APIENTRY glutSwapBuffers(void);
GLUTAPI int APIENTRY glutGetWindow(void);
GLUTAPI void APIENTRY glutSetWindow(int win);
GLUTAPI void APIENTRY glutSetWindowTitle(const char *title);
GLUTAPI void APIENTRY glutSetIconTitle(const char *title);
GLUTAPI void APIENTRY glutPositionWindow(int x, int y);
GLUTAPI void APIENTRY glutReshapeWindow(int width, int height);
GLUTAPI void APIENTRY glutPopWindow(void);
GLUTAPI void APIENTRY glutPushWindow(void);
GLUTAPI void APIENTRY glutIconifyWindow(void);
GLUTAPI void APIENTRY glutShowWindow(void);
GLUTAPI void APIENTRY glutHideWindow(void);
/* GLUT overlay sub-API. */
GLUTAPI void APIENTRY glutEstablishOverlay(void);
GLUTAPI void APIENTRY glutRemoveOverlay(void);
GLUTAPI void APIENTRY glutUseLayer(GLenum layer);
GLUTAPI void APIENTRY glutPostOverlayRedisplay(void);
GLUTAPI void APIENTRY glutShowOverlay(void);
GLUTAPI void APIENTRY glutHideOverlay(void);
/* GLUT menu sub-API. */
GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *)(int));
GLUTAPI void APIENTRY glutDestroyMenu(int menu);
GLUTAPI int APIENTRY glutGetMenu(void);
GLUTAPI void APIENTRY glutSetMenu(int menu);
GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value);
GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu);
GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
GLUTAPI void APIENTRY glutRemoveMenuItem(int item);
GLUTAPI void APIENTRY glutAttachMenu(int button);
GLUTAPI void APIENTRY glutDetachMenu(int button);
/* GLUT window callback sub-API. */
GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK * func)(void));
GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK * func)(int width, int height));
GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK * func)(unsigned char key, int x, int y));
GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y));
GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK * func)(int state));
GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK * func)(int state));
GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK * func)(void));
GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK * func)(int value), int value);
GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK * func)(int state));
GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK * func)(int key, int x, int y));
GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK * func)(int x, int y, int z));
GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK * func)(int x, int y, int z));
GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK * func)(int button, int state));
GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK * func)(int button, int state));
GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK * func)(int dial, int value));
GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK * func)(int x, int y));
GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK * func)(int button, int state, int x, int y));
GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK * func)(int status, int x, int y));
GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK * func)(void));
GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK * func)(int state));
/* GLUT color index sub-API. */
GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component);
GLUTAPI void APIENTRY glutCopyColormap(int win);
/* GLUT state retrieval sub-API. */
GLUTAPI int APIENTRY glutGet(GLenum type);
GLUTAPI int APIENTRY glutDeviceGet(GLenum type);
/* GLUT font sub-API */
GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character);
GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character);
GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character);
/* GLUT pre-built models sub-API */
GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
GLUTAPI void APIENTRY glutWireCube(GLdouble size);
GLUTAPI void APIENTRY glutSolidCube(GLdouble size);
GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
GLUTAPI void APIENTRY glutWireDodecahedron(void);
GLUTAPI void APIENTRY glutSolidDodecahedron(void);
GLUTAPI void APIENTRY glutWireTeapot(GLdouble size);
GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size);
GLUTAPI void APIENTRY glutWireOctahedron(void);
GLUTAPI void APIENTRY glutSolidOctahedron(void);
GLUTAPI void APIENTRY glutWireTetrahedron(void);
GLUTAPI void APIENTRY glutSolidTetrahedron(void);
GLUTAPI void APIENTRY glutWireIcosahedron(void);
GLUTAPI void APIENTRY glutSolidIcosahedron(void);
#endif /* __AGLUT_H__ */

81
include/GL/glutf90.h Normal file
View file

@ -0,0 +1,81 @@
#ifndef __glutf90_h__
#define __glutf90_h__
/* Copyright (c) Mark J. Kilgard & Willam F. Mitchell, 1998. */
/* This program is freely distributable without licensing fees
and is provided without guarantee or warrantee expressed or
implied. This program is -not- in the public domain. */
/* This header provides the binding interface for William Mitchell's
f90gl Fortran 90 GLUT binding. Other GLUT language bindings
can and should use this interace. */
/* I appreciate the guidance from William Mitchell
(mitchell@cam.nist.gov) in developing this friend interface
for use by the f90gl package. See ../../README.fortran */
#include <GL/glut.h>
/* Which callback enumerants for the __glutSetFCB/__glutGetFCB routines. */
/* NOTE These values are part of a binary interface for the f90gl Fortran
90 binding and so must NOT changes (additions are allowed). */
/* GLUTwindow callbacks. */
#define GLUT_FCB_DISPLAY 0 /* GLUTdisplayFCB */
#define GLUT_FCB_RESHAPE 1 /* GLUTreshapeFCB */
#define GLUT_FCB_MOUSE 2 /* GLUTmouseFCB */
#define GLUT_FCB_MOTION 3 /* GLUTmotionFCB */
#define GLUT_FCB_PASSIVE 4 /* GLUTpassiveFCB */
#define GLUT_FCB_ENTRY 5 /* GLUTentryFCB */
#define GLUT_FCB_KEYBOARD 6 /* GLUTkeyboardFCB */
#define GLUT_FCB_KEYBOARD_UP 7 /* GLUTkeyboardFCB */
#define GLUT_FCB_WINDOW_STATUS 8 /* GLUTwindowStatusFCB */
#define GLUT_FCB_VISIBILITY 9 /* GLUTvisibilityFCB */
#define GLUT_FCB_SPECIAL 10 /* GLUTspecialFCB */
#define GLUT_FCB_SPECIAL_UP 11 /* GLUTspecialFCB */
#define GLUT_FCB_BUTTON_BOX 12 /* GLUTbuttonBoxFCB */
#define GLUT_FCB_DIALS 13 /* GLUTdialsFCB */
#define GLUT_FCB_SPACE_MOTION 14 /* GLUTspaceMotionFCB */
#define GLUT_FCB_SPACE_ROTATE 15 /* GLUTspaceRotateFCB */
#define GLUT_FCB_SPACE_BUTTON 16 /* GLUTspaceButtonFCB */
#define GLUT_FCB_TABLET_MOTION 17 /* GLUTtabletMotionFCB */
#define GLUT_FCB_TABLET_BUTTON 18 /* GLUTtabletButtonFCB */
#define GLUT_FCB_JOYSTICK 19 /* GLUTjoystickFCB */
/* Non-GLUTwindow callbacks. */
#define GLUT_FCB_OVERLAY_DISPLAY 100 /* GLUTdisplayFCB */
#define GLUT_FCB_SELECT 101 /* GLUTselectFCB */
#define GLUT_FCB_TIMER 102 /* GLUTtimerFCB */
/* GLUT Fortran callback function types. */
typedef void (GLUTCALLBACK *GLUTdisplayFCB) (void);
typedef void (GLUTCALLBACK *GLUTreshapeFCB) (int *, int *);
/* NOTE the pressed key is int, not unsigned char for Fortran! */
typedef void (GLUTCALLBACK *GLUTkeyboardFCB) (int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTmouseFCB) (int *, int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTmotionFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTpassiveFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTentryFCB) (int *);
typedef void (GLUTCALLBACK *GLUTwindowStatusFCB) (int *);
typedef void (GLUTCALLBACK *GLUTvisibilityFCB) (int *);
typedef void (GLUTCALLBACK *GLUTspecialFCB) (int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTbuttonBoxFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTdialsFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTspaceMotionFCB) (int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTspaceRotateFCB) (int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTspaceButtonFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTtabletMotionFCB) (int *, int *);
typedef void (GLUTCALLBACK *GLUTtabletButtonFCB) (int *, int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTjoystickFCB) (unsigned int *buttonMask, int *x, int *y, int *z);
typedef void (GLUTCALLBACK *GLUTselectFCB) (int *);
typedef void (GLUTCALLBACK *GLUTtimerFCB) (int *);
typedef void (GLUTCALLBACK *GLUTmenuStateFCB) (int *); /* DEPRICATED. */
typedef void (GLUTCALLBACK *GLUTmenuStatusFCB) (int *, int *, int *);
typedef void (GLUTCALLBACK *GLUTidleFCB) (void);
/* Functions that set and return Fortran callback functions. */
extern void* GLUTAPIENTRY __glutGetFCB(int which);
extern void GLUTAPIENTRY __glutSetFCB(int which, void *func);
#endif /* __glutf90_h__ */

261
include/GL/glx.h Normal file
View file

@ -0,0 +1,261 @@
/* $Id: glx.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* $Log: glx.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/02/14 03:39:09 brianp
* new copyright
*
* Revision 3.2 1998/06/18 03:44:00 brianp
* replaced "uint" with "unsigned int"
*
* Revision 3.1 1998/06/01 00:00:17 brianp
* added GLX_SGI_video_sync extension
*
* Revision 3.0 1998/02/20 05:06:01 brianp
* initial rev
*
*/
#ifndef GLX_H
#define GLX_H
/*
* A pseudo-GLX implementation to allow GLX-based OpenGL programs to
* work with Mesa.
*
* Notes:
* 1. If the visual passed to glXGetConfig was not one returned by
* glXChooseVisual then the GLX_RGBA and GLX_DOUBLEBUFFER queries
* will always return True and the GLX_DEPTH_SIZE query will always
* return non-zero.
* 2. The glXIsDirect() function always returns True.
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "GL/gl.h"
#ifdef MESA
#include "GL/xmesa.h"
#endif
#if defined(USE_MGL_NAMESPACE)
#include "glx_mangle.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define GLX_VERSION_1_1 1
/*
* Tokens for glXChooseVisual and glXGetConfig:
*/
enum _GLX_CONFIGS {
GLX_USE_GL = 1,
GLX_BUFFER_SIZE = 2,
GLX_LEVEL = 3,
GLX_RGBA = 4,
GLX_DOUBLEBUFFER = 5,
GLX_STEREO = 6,
GLX_AUX_BUFFERS = 7,
GLX_RED_SIZE = 8,
GLX_GREEN_SIZE = 9,
GLX_BLUE_SIZE = 10,
GLX_ALPHA_SIZE = 11,
GLX_DEPTH_SIZE = 12,
GLX_STENCIL_SIZE = 13,
GLX_ACCUM_RED_SIZE = 14,
GLX_ACCUM_GREEN_SIZE = 15,
GLX_ACCUM_BLUE_SIZE = 16,
GLX_ACCUM_ALPHA_SIZE = 17,
/* GLX_EXT_visual_info extension */
GLX_X_VISUAL_TYPE_EXT = 0x22,
GLX_TRANSPARENT_TYPE_EXT = 0x23,
GLX_TRANSPARENT_INDEX_VALUE_EXT = 0x24,
GLX_TRANSPARENT_RED_VALUE_EXT = 0x25,
GLX_TRANSPARENT_GREEN_VALUE_EXT = 0x26,
GLX_TRANSPARENT_BLUE_VALUE_EXT = 0x27,
GLX_TRANSPARENT_ALPHA_VALUE_EXT = 0x28
};
/*
* Error codes returned by glXGetConfig:
*/
#define GLX_BAD_SCREEN 1
#define GLX_BAD_ATTRIBUTE 2
#define GLX_NO_EXTENSION 3
#define GLX_BAD_VISUAL 4
#define GLX_BAD_CONTEXT 5
#define GLX_BAD_VALUE 6
#define GLX_BAD_ENUM 7
/*
* GLX 1.1 and later:
*/
#define GLX_VENDOR 1
#define GLX_VERSION 2
#define GLX_EXTENSIONS 3
/*
* GLX_visual_info extension
*/
#define GLX_TRUE_COLOR_EXT 0x8002
#define GLX_DIRECT_COLOR_EXT 0x8003
#define GLX_PSEUDO_COLOR_EXT 0x8004
#define GLX_STATIC_COLOR_EXT 0x8005
#define GLX_GRAY_SCALE_EXT 0x8006
#define GLX_STATIC_GRAY_EXT 0x8007
#define GLX_NONE_EXT 0x8000
#define GLX_TRANSPARENT_RGB_EXT 0x8008
#define GLX_TRANSPARENT_INDEX_EXT 0x8009
/*
* Compile-time extension tests
*/
#ifdef MESA
#define GLX_EXT_visual_info 1
#define GLX_MESA_pixmap_colormap 1
#define GLX_MESA_release_buffers 1
#define GLX_MESA_copy_sub_buffer 1
#define GLX_SGI_video_sync 1
#endif
#ifdef MESA
typedef XMesaContext GLXContext;
typedef Pixmap GLXPixmap;
typedef Drawable GLXDrawable;
#else
typedef void * GLXContext;
typedef XID GLXPixmap;
typedef XID GLXDrawable;
#endif
typedef XID GLXContextID;
extern XVisualInfo* glXChooseVisual( Display *dpy, int screen,
int *attribList );
extern GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
GLXContext shareList, Bool direct );
extern void glXDestroyContext( Display *dpy, GLXContext ctx );
extern Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable,
GLXContext ctx);
extern void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
GLuint mask );
extern void glXSwapBuffers( Display *dpy, GLXDrawable drawable );
extern GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visual,
Pixmap pixmap );
extern void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap );
extern Bool glXQueryExtension( Display *dpy, int *errorb, int *event );
extern Bool glXQueryVersion( Display *dpy, int *maj, int *min );
extern Bool glXIsDirect( Display *dpy, GLXContext ctx );
extern int glXGetConfig( Display *dpy, XVisualInfo *visual,
int attrib, int *value );
extern GLXContext glXGetCurrentContext( void );
extern GLXDrawable glXGetCurrentDrawable( void );
extern void glXWaitGL( void );
extern void glXWaitX( void );
extern void glXUseXFont( Font font, int first, int count, int list );
/* GLX 1.1 and later */
extern const char *glXQueryExtensionsString( Display *dpy, int screen );
extern const char *glXQueryServerString( Display *dpy, int screen, int name );
extern const char *glXGetClientString( Display *dpy, int name );
/*
* Mesa GLX Extensions
*/
#ifdef GLX_MESA_pixmap_colormap
extern GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
Pixmap pixmap, Colormap cmap );
#endif
#ifdef GLX_MESA_release_buffers
extern Bool glXReleaseBuffersMESA( Display *dpy, GLXDrawable d );
#endif
#ifdef GLX_MESA_copy_sub_buffer
extern void glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
int x, int y, int width, int height );
#endif
#ifdef GLX_SGI_video_sync
extern int glXGetVideoSyncSGI(unsigned int *count);
extern int glXWaitVideoSyncSGI(int divisor, int remainder,
unsigned int *count);
#endif
#ifdef __cplusplus
}
#endif
#endif

72
include/GL/glx_mangle.h Normal file
View file

@ -0,0 +1,72 @@
/* $Id: glx_mangle.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.0
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: glx_mangle.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/06/21 22:01:00 brianp
* added #ifndef GLX_MANGLE_H stuff, video sync extension functions
*
* Revision 3.2 1998/03/26 02:44:53 brianp
* removed ^M characters
*
* Revision 3.1 1998/03/17 02:41:19 brianp
* updated by Randy Frank
*
* Revision 3.0 1998/02/20 05:04:45 brianp
* initial rev
*
*/
#ifndef GLX_MANGLE_H
#define GLX_MANGLE_H
#define glXChooseVisual mglXChooseVisual
#define glXCreateContext mglXCreateContext
#define glXDestroyContext mglXDestroyContext
#define glXMakeCurrent mglXMakeCurrent
#define glXCopyContext mglXCopyContext
#define glXSwapBuffers mglXSwapBuffers
#define glXCreateGLXPixmap mglXCreateGLXPixmap
#define glXDestroyGLXPixmap mglXDestroyGLXPixmap
#define glXQueryExtension mglXQueryExtension
#define glXQueryVersion mglXQueryVersion
#define glXIsDirect mglXIsDirect
#define glXGetConfig mglXGetConfig
#define glXGetCurrentContext mglXGetCurrentContext
#define glXGetCurrentDrawable mglXGetCurrentDrawable
#define glXWaitGL mglXWaitGL
#define glXWaitX mglXWaitX
#define glXUseXFont mglXUseXFont
#define glXQueryExtensionsString mglXQueryExtensionsString
#define glXQueryServerString mglXQueryServerString
#define glXGetClientString mglXGetClientString
#define glXCreateGLXPixmapMESA mglXCreateGLXPixmapMESA
#define glXReleaseBuffersMESA mglXReleaseBuffersMESA
#define glXCopySubBufferMESA mglXCopySubBufferMESA
#define glXGetVideoSyncSGI mglXGetVideoSyncSGI
#define glXWaitVideoSyncSGI mglXWaitVideoSyncSGI
#endif

80
include/GL/mglmesa.h Normal file
View file

@ -0,0 +1,80 @@
/****************************************************************************
*
* Mesa bindings for SciTech MGL
*
* Copyright (C) 1996 SciTech Software.
* All rights reserved.
*
* Filename: $Workfile: mglmesa.h $
* Version: $Revision: 1.1 $
*
* Language: ANSI C
* Environment: Any
*
* Description: Header file for the Mesa/OpenGL interface bindings for the
* SciTech MGL graphics library. Uses the MGL internal
* device context structures to get direct access to the
* high performance MGL rasterization functions for maximum
* performance. Utilizes the VESA VBE/AF Accelerator Functions
* via the MGL's accelerated device driver functions, as well
* as basic DirectDraw accelerated functions provided by the
* MGL.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Date: 1999/08/19 00:55:40 $ $Author: jtg $
*
****************************************************************************/
#ifndef __MGLMESA_H
#define __MGLMESA_H
#include "mgraph.h"
/*------------------------- Function Prototypes ---------------------------*/
#ifdef __cplusplus
extern "C" { /* Use "C" linkage when in C++ mode */
#endif
#ifndef __WINDOWS__
#define GLAPIENTRY
#endif
#ifdef __WINDOWS__
bool GLAPIENTRY MGLMesaInitDLL(MGLCallbacks *cb,char *version);
#endif
void GLAPIENTRY MGLMesaChooseVisual(MGLDC *dc,MGLVisual *visual);
bool GLAPIENTRY MGLMesaSetVisual(MGLDC *dc,MGLVisual *visual);
bool GLAPIENTRY MGLMesaCreateContext(MGLDC *dc,bool forceMemDC);
void GLAPIENTRY MGLMesaDestroyContext(MGLDC *dc);
void GLAPIENTRY MGLMesaMakeCurrent(MGLDC *dc);
void GLAPIENTRY MGLMesaSwapBuffers(MGLDC *dc,bool waitVRT);
/* Palette manipulation support. The reason we provide palette manipulation
* routines is so that when rendering in double buffered modes with a
* software backbuffer, the palette for the backbuffer is kept consistent
* with the hardware front buffer.
*/
void GLAPIENTRY MGLMesaSetPaletteEntry(MGLDC *dc,int entry,uchar red,uchar green,uchar blue);
void GLAPIENTRY MGLMesaSetPalette(MGLDC *dc,palette_t *pal,int numColors,int startIndex);
void GLAPIENTRY MGLMesaRealizePalette(MGLDC *dc,int numColors,int startIndex,int waitVRT);
#ifdef __cplusplus
} /* End of "C" linkage for C++ */
#endif /* __cplusplus */
#endif /* __MGLMESA_H */

256
include/GL/osmesa.h Normal file
View file

@ -0,0 +1,256 @@
/* $Id: osmesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* $Log: osmesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.4 1999/02/14 03:39:09 brianp
* new copyright
*
* Revision 1.3 1999/01/03 02:52:30 brianp
* now using GLAPI and GLAPIENTRY keywords (Ted Jump)
*
* Revision 1.2 1998/07/26 01:33:51 brianp
* added WINGDIAPI and APIENTRY keywords per Ted Jump
*
* Revision 1.1 1998/02/13 03:17:50 brianp
* Initial revision
*
*/
/*
* Mesa Off-Screen rendering interface.
*
* This is an operating system and window system independent interface to
* Mesa which allows one to render images into a client-supplied buffer in
* main memory. Such images may manipulated or saved in whatever way the
* client wants.
*
* These are the API functions:
* OSMesaCreateContext - create a new Off-Screen Mesa rendering context
* OSMesaMakeCurrent - bind an OSMesaContext to a client's image buffer
* and make the specified context the current one.
* OSMesaDestroyContext - destroy an OSMesaContext
* OSMesaGetCurrentContext - return thread's current context ID
* OSMesaPixelStore - controls how pixels are stored in image buffer
* OSMesaGetIntegerv - return OSMesa state parameters
*
*
* The limits on the width and height of an image buffer are MAX_WIDTH and
* MAX_HEIGHT as defined in Mesa/src/config.h. Defaults are 1280 and 1024.
* You can increase them as needed but beware that many temporary arrays in
* Mesa are dimensioned by MAX_WIDTH or MAX_HEIGHT.
*/
#ifndef OSMESA_H
#define OSMESA_H
#ifdef __cplusplus
extern "C" {
#endif
#include "GL/gl.h"
#define OSMESA_MAJOR_VERSION 3
#define OSMESA_MINOR_VERSION 0
/*
* Values for the format parameter of OSMesaCreateContext()
* New in version 2.0.
*/
#define OSMESA_COLOR_INDEX GL_COLOR_INDEX
#define OSMESA_RGBA GL_RGBA
#define OSMESA_BGRA 0x1
#define OSMESA_ARGB 0x2
#define OSMESA_RGB GL_RGB
#define OSMESA_BGR 0x4
/*
* OSMesaPixelStore() parameters:
* New in version 2.0.
*/
#define OSMESA_ROW_LENGTH 0x10
#define OSMESA_Y_UP 0x11
/*
* Accepted by OSMesaGetIntegerv:
*/
#define OSMESA_WIDTH 0x20
#define OSMESA_HEIGHT 0x21
#define OSMESA_FORMAT 0x22
#define OSMESA_TYPE 0x23
typedef struct osmesa_context *OSMesaContext;
#if defined(__BEOS__) || defined(__QUICKDRAW__)
#pragma export on
#endif
/*
* Create an Off-Screen Mesa rendering context. The only attribute needed is
* an RGBA vs Color-Index mode flag.
*
* Input: format - one of OSMESA_COLOR_INDEX, OSMESA_RGBA, OSMESA_BGRA,
* OSMESA_ARGB, OSMESA_RGB, or OSMESA_BGR.
* sharelist - specifies another OSMesaContext with which to share
* display lists. NULL indicates no sharing.
* Return: an OSMesaContext or 0 if error
*/
GLAPI OSMesaContext GLAPIENTRY OSMesaCreateContext( GLenum format,
OSMesaContext sharelist );
/*
* Destroy an Off-Screen Mesa rendering context.
*
* Input: ctx - the context to destroy
*/
GLAPI void GLAPIENTRY OSMesaDestroyContext( OSMesaContext ctx );
/*
* Bind an OSMesaContext to an image buffer. The image buffer is just a
* block of memory which the client provides. Its size must be at least
* as large as width*height*sizeof(type). Its address should be a multiple
* of 4 if using RGBA mode.
*
* Image data is stored in the order of glDrawPixels: row-major order
* with the lower-left image pixel stored in the first array position
* (ie. bottom-to-top).
*
* Since the only type initially supported is GL_UNSIGNED_BYTE, if the
* context is in RGBA mode, each pixel will be stored as a 4-byte RGBA
* value. If the context is in color indexed mode, each pixel will be
* stored as a 1-byte value.
*
* If the context's viewport hasn't been initialized yet, it will now be
* initialized to (0,0,width,height).
*
* Input: ctx - the rendering context
* buffer - the image buffer memory
* type - data type for pixel components, only GL_UNSIGNED_BYTE
* supported now
* width, height - size of image buffer in pixels, at least 1
* Return: GL_TRUE if success, GL_FALSE if error because of invalid ctx,
* invalid buffer address, type!=GL_UNSIGNED_BYTE, width<1, height<1,
* width>internal limit or height>internal limit.
*/
GLAPI GLboolean GLAPIENTRY OSMesaMakeCurrent( OSMesaContext ctx,
void *buffer, GLenum type,
GLsizei width, GLsizei height );
/*
* Return the current Off-Screen Mesa rendering context handle.
*/
GLAPI OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void );
/*
* Set pixel store/packing parameters for the current context.
* This is similar to glPixelStore.
* Input: pname - OSMESA_ROW_LENGTH
* specify actual pixels per row in image buffer
* 0 = same as image width (default)
* OSMESA_Y_UP
* zero = Y coordinates increase downward
* non-zero = Y coordinates increase upward (default)
* value - the value for the parameter pname
*
* New in version 2.0.
*/
GLAPI void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value );
/*
* Return context info. This is like glGetIntegerv.
* Input: pname -
* OSMESA_WIDTH return current image width
* OSMESA_HEIGHT return current image height
* OSMESA_FORMAT return image format
* OSMESA_TYPE return color component data type
* OSMESA_ROW_LENGTH return row length in pixels
* OSMESA_Y_UP returns 1 or 0 to indicate Y axis direction
* value - pointer to integer in which to return result.
*/
GLAPI void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value );
/*
* Return the depth buffer associated with an OSMesa context.
* Input: c - the OSMesa context
* Output: width, height - size of buffer in pixels
* bytesPerValue - bytes per depth value (2 or 4)
* buffer - pointer to depth buffer values
* Return: GL_TRUE or GL_FALSE to indicate success or failure.
*
* New in Mesa 2.4.
*/
GLAPI GLboolean GLAPIENTRY OSMesaGetDepthBuffer( OSMesaContext c,
GLint *width, GLint *height,
GLint *bytesPerValue, void **buffer );
#if defined(__BEOS__) || defined(__QUICKDRAW__)
#pragma export off
#endif
#ifdef __cplusplus
}
#endif
#endif

106
include/GL/svgamesa.h Normal file
View file

@ -0,0 +1,106 @@
/* $Id: svgamesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.0
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Log: svgamesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.0 1998/02/20 05:07:24 brianp
* initial rev
*
*/
/*
* SVGA/Mesa interface for Linux.
*/
/*
* Intro to using the VGA/Mesa interface
*
* 1. #include the <vga.h> file
* 2. Call vga_init() to initialize the SVGA library.
* 3. Call vga_setmode() to specify the screen size and color depth.
* 4. Call SVGAMesaCreateContext() to setup a Mesa context. If using 8-bit
* color Mesa assumes color index mode, if using 16-bit or deeper color
* Mesa assumes RGB mode.
* 5. Call SVGAMesaMakeCurrent() to activate the Mesa context.
* 6. You can now use the Mesa API functions.
* 7. Before exiting, call SVGAMesaDestroyContext() then vga_setmode(TEXT)
* to restore the original text screen.
*
* Notes
* 1. You must run your executable as root (or use the set UID-bit) because
* the SVGA library requires it.
* 2. The SVGA driver is not fully implemented yet. See svgamesa.c for what
* has to be done yet.
*/
#ifndef SVGAMESA_H
#define SVGAMESA_H
#define SVGAMESA_MAJOR_VERSION 3
#define SVGAMESA_MINOR_VERSION 0
#ifdef __cplusplus
extern "C" {
#endif
#include "GL/gl.h"
/*
* This is the SVGAMesa context 'handle':
*/
typedef struct svgamesa_context *SVGAMesaContext;
/*
* doubleBuffer flag new in version 2.4
*/
extern SVGAMesaContext SVGAMesaCreateContext( GLboolean doubleBuffer );
extern void SVGAMesaDestroyContext( SVGAMesaContext ctx );
extern void SVGAMesaMakeCurrent( SVGAMesaContext ctx );
extern SVGAMesaContext SVGAMesaGetCurrentContext( void );
extern void SVGAMesaSwapBuffers( void );
#ifdef __cplusplus
}
#endif
#endif

155
include/GL/wmesa.h Normal file
View file

@ -0,0 +1,155 @@
/* $Id: wmesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.0
* Copyright (C) 1995-1998 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* $Log: wmesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/01/03 02:54:45 brianp
* updated per Ted Jump
*
* Revision 3.1 1998/12/01 02:34:27 brianp
* applied Mark Kilgard's patches from November 30, 1998
*
* Revision 3.0 1998/02/20 05:06:59 brianp
* initial rev
*
*/
/*
* Windows driver by: Mark E. Peterson (markp@ic.mankato.mn.us)
* Updated by Li Wei (liwei@aiar.xjtu.edu.cn)
*
*
***************************************************************
* WMesa *
* version 2.3 *
* *
* By *
* Li Wei *
* Institute of Artificial Intelligence & Robotics *
* Xi'an Jiaotong University *
* Email: liwei@aiar.xjtu.edu.cn *
* Web page: http://sun.aiar.xjtu.edu.cn *
* *
* July 7th, 1997 *
***************************************************************
*/
#ifndef WMESA_H
#define WMESA_H
#ifdef __cplusplus
extern "C" {
#endif
#include "gl\gl.h"
#pragma warning (disable:4273)
#pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */
#pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */
#pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */
#pragma warning( disable : 4013 ) /* 'function' undefined; assuming extern returning int */
#pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */
#pragma warning( disable : 4273 ) /* 'identifier' : inconsistent DLL linkage. dllexport assumed */
#if (MESA_WARNQUIET>1)
# pragma warning( disable : 4146 ) /* unary minus operator applied to unsigned type, result still unsigned */
#endif
/*
* This is the WMesa context 'handle':
*/
typedef struct wmesa_context *WMesaContext;
/*
* Create a new WMesaContext for rendering into a window. You must
* have already created the window of correct visual type and with an
* appropriate colormap.
*
* Input:
* hWnd - Window handle
* Pal - Palette to use
* rgb_flag - GL_TRUE = RGB mode,
* GL_FALSE = color index mode
* db_flag - GL_TRUE = double-buffered,
* GL_FALSE = single buffered
*
* Note: Indexed mode requires double buffering under Windows.
*
* Return: a WMesa_context or NULL if error.
*/
extern WMesaContext WMesaCreateContext(HWND hWnd,HPALETTE* pPal,
GLboolean rgb_flag,GLboolean db_flag);
/*
* Destroy a rendering context as returned by WMesaCreateContext()
*/
/*extern void WMesaDestroyContext( WMesaContext ctx );*/
extern void WMesaDestroyContext( void );
/*
* Make the specified context the current one.
*/
extern void WMesaMakeCurrent( WMesaContext ctx );
/*
* Return a handle to the current context.
*/
extern WMesaContext WMesaGetCurrentContext( void );
/*
* Swap the front and back buffers for the current context. No action
* taken if the context is not double buffered.
*/
extern void WMesaSwapBuffers(void);
/*
* In indexed color mode we need to know when the palette changes.
*/
extern void WMesaPaletteChange(HPALETTE Pal);
extern void WMesaMove(void);
#ifdef __cplusplus
}
#endif
#endif

357
include/GL/xmesa.h Normal file
View file

@ -0,0 +1,357 @@
/* $Id: xmesa.h,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.1
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* $Log: xmesa.h,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.3 1999/02/24 22:43:27 jens
* Name changes to get XMesa to compile standalone inside XFree86
*
* Revision 1.2 1999/02/14 03:39:09 brianp
* new copyright
*
* Revision 1.1 1998/02/13 03:17:32 brianp
* Initial revision
*
*/
/*
* Mesa/X11 interface. This header file serves as the documentation for
* the Mesa/X11 interface functions.
*
* Note: this interface isn't intended for user programs. It's primarily
* just for implementing the pseudo-GLX interface.
*/
/* Sample Usage:
In addition to the usual X calls to select a visual, create a colormap
and create a window, you must do the following to use the X/Mesa interface:
1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo.
2. Call XMesaCreateContext() to create an X/Mesa rendering context, given
the XMesaVisual.
3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window
and XMesaVisual.
4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and
to make the context the current one.
5. Make gl* calls to render your graphics.
6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers.
7. Before the X window is destroyed, call XMesaDestroyBuffer().
8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext.
See the demos/xdemo.c and xmesa1.c files for examples.
*/
#ifndef XMESA_H
#define XMESA_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef XFree86Server
#include "xmesa_xf86.h"
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "xmesa_x.h"
#endif
#include "GL/gl.h"
#ifdef AMIWIN
#include <pragmas/xlib_pragmas.h>
extern struct Library *XLibBase;
#endif
#define XMESA_MAJOR_VERSION 3
#define XMESA_MINOR_VERSION 0
/*
* Values passed to XMesaGetString:
*/
#define XMESA_VERSION 1
#define XMESA_EXTENSIONS 2
/*
* Values passed to XMesaSetFXmode:
*/
#define XMESA_FX_WINDOW 1
#define XMESA_FX_FULLSCREEN 2
typedef struct xmesa_context *XMesaContext;
typedef struct xmesa_visual *XMesaVisual;
typedef struct xmesa_buffer *XMesaBuffer;
/*
* Create a new X/Mesa visual.
* Input: display - X11 display
* visinfo - an XVisualInfo pointer
* rgb_flag - GL_TRUE = RGB mode,
* GL_FALSE = color index mode
* alpha_flag - alpha buffer requested?
* db_flag - GL_TRUE = double-buffered,
* GL_FALSE = single buffered
* stereo_flag - stereo visual?
* depth_size - requested bits/depth values, or zero
* stencil_size - requested bits/stencil values, or zero
* accum_size - requested bits/component values, or zero
* ximage_flag - GL_TRUE = use an XImage for back buffer,
* GL_FALSE = use an off-screen pixmap for back buffer
* Return; a new XMesaVisual or 0 if error.
*/
extern XMesaVisual XMesaCreateVisual( XMesaDisplay *display,
XMesaVisualInfo visinfo,
GLboolean rgb_flag,
GLboolean alpha_flag,
GLboolean db_flag,
GLboolean stereo_flag,
GLboolean ximage_flag,
GLint depth_size,
GLint stencil_size,
GLint accum_size,
GLint level );
/*
* Destroy an XMesaVisual, but not the associated XVisualInfo.
*/
extern void XMesaDestroyVisual( XMesaVisual v );
/*
* Create a new XMesaContext for rendering into an X11 window.
*
* Input: visual - an XMesaVisual
* share_list - another XMesaContext with which to share display
* lists or NULL if no sharing is wanted.
* Return: an XMesaContext or NULL if error.
*/
extern XMesaContext XMesaCreateContext( XMesaVisual v,
XMesaContext share_list );
/*
* Destroy a rendering context as returned by XMesaCreateContext()
*/
extern void XMesaDestroyContext( XMesaContext c );
/*
* Create an XMesaBuffer from an X window.
*/
extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v,
XMesaWindow w );
/*
* Create an XMesaBuffer from an X pixmap.
*/
extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v,
XMesaPixmap p,
XMesaColormap cmap );
/*
* Destroy an XMesaBuffer, but not the corresponding window or pixmap.
*/
extern void XMesaDestroyBuffer( XMesaBuffer b );
/*
* Return the XMesaBuffer handle which corresponds to an X drawable, if any.
*
* New in Mesa 2.3.
*/
extern XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy,
XMesaDrawable d );
/*
* Bind a buffer to a context and make the context the current one.
*/
extern GLboolean XMesaMakeCurrent( XMesaContext c,
XMesaBuffer b );
/*
* Return a handle to the current context.
*/
extern XMesaContext XMesaGetCurrentContext( void );
/*
* Return handle to the current buffer.
*/
extern XMesaBuffer XMesaGetCurrentBuffer( void );
/*
* Swap the front and back buffers for the given buffer. No action is
* taken if the buffer is not double buffered.
*/
extern void XMesaSwapBuffers( XMesaBuffer b );
/*
* Copy a sub-region of the back buffer to the front buffer.
*
* New in Mesa 2.6
*/
extern void XMesaCopySubBuffer( XMesaBuffer b,
int x,
int y,
int width,
int height );
/*
* Return a pointer to the the Pixmap or XImage being used as the back
* color buffer of an XMesaBuffer. This function is a way to get "under
* the hood" of X/Mesa so one can manipulate the back buffer directly.
* Input: b - the XMesaBuffer
* Output: pixmap - pointer to back buffer's Pixmap, or 0
* ximage - pointer to back buffer's XImage, or NULL
* Return: GL_TRUE = context is double buffered
* GL_FALSE = context is single buffered
*/
extern GLboolean XMesaGetBackBuffer( XMesaBuffer b,
XMesaPixmap *pixmap,
XMesaImage **ximage );
/*
* Return the depth buffer associated with an XMesaBuffer.
* Input: b - the XMesa buffer handle
* Output: width, height - size of buffer in pixels
* bytesPerValue - bytes per depth value (2 or 4)
* buffer - pointer to depth buffer values
* Return: GL_TRUE or GL_FALSE to indicate success or failure.
*
* New in Mesa 2.4.
*/
extern GLboolean XMesaGetDepthBuffer( XMesaBuffer b,
GLint *width,
GLint *height,
GLint *bytesPerValue,
void **buffer );
/*
* Flush/sync a context
*/
extern void XMesaFlush( XMesaContext c );
/*
* Get an X/Mesa-specific string.
* Input: name - either XMESA_VERSION or XMESA_EXTENSIONS
*/
extern const char *XMesaGetString( XMesaContext c, int name );
/*
* Scan for XMesaBuffers whose window/pixmap has been destroyed, then free
* any memory used by that buffer.
*
* New in Mesa 2.3.
*/
extern void XMesaGarbageCollect( void );
/*
* Return a dithered pixel value.
* Input: c - XMesaContext
* x, y - window coordinate
* red, green, blue, alpha - color components in [0,1]
* Return: pixel value
*
* New in Mesa 2.3.
*/
extern unsigned long XMesaDitherColor( XMesaContext xmesa,
GLint x,
GLint y,
GLfloat red,
GLfloat green,
GLfloat blue,
GLfloat alpha );
/*
* 3Dfx Glide driver only!
* Set 3Dfx/Glide full-screen or window rendering mode.
* Input: mode - either XMESA_FX_WINDOW (window rendering mode) or
* XMESA_FX_FULLSCREEN (full-screen rendering mode)
* Return: GL_TRUE if success
* GL_FALSE if invalid mode or if not using 3Dfx driver
*
* New in Mesa 2.6.
*/
extern GLboolean XMesaSetFXmode( GLint mode );
#ifdef __cplusplus
}
#endif
#endif

92
include/GL/xmesa_x.h Normal file
View file

@ -0,0 +1,92 @@
/**************************************************************************
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Kevin E. Martin <kevin@precisioninsight.com>
*
* $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/include/GL/xmesa_x.h,v 1.1 1999/08/19 00:55:40 jtg Exp $
*/
#ifndef _XMESA_X_H_
#define _XMESA_X_H_
typedef Display XMesaDisplay;
typedef Pixmap XMesaPixmap;
typedef Colormap XMesaColormap;
typedef Drawable XMesaDrawable;
typedef Window XMesaWindow;
typedef GC XMesaGC;
typedef XVisualInfo *XMesaVisualInfo;
typedef XImage XMesaImage;
typedef XPoint XMesaPoint;
typedef XColor XMesaColor;
#define XMesaDestroyImage XDestroyImage
#define XMesaPutPixel XPutPixel
#define XMesaGetPixel XGetPixel
#define XMesaSetForeground XSetForeground
#define XMesaSetBackground XSetBackground
#define XMesaSetPlaneMask XSetPlaneMask
#define XMesaSetFunction XSetFunction
#define XMesaSetDashes XSetDashes
#define XMesaSetLineAttributes XSetLineAttributes
#define XMesaSetFillStyle XSetFillStyle
#define XMesaSetTile XSetTile
#define XMesaSetStipple XSetStipple
#define XMesaDrawPoint XDrawPoint
#define XMesaDrawPoints XDrawPoints
#define XMesaDrawLine XDrawLine
#define XMesaFillRectangle XFillRectangle
#define XMesaPutImage XPutImage
#define XMesaCopyArea XCopyArea
#define XMesaFillPolygon XFillPolygon
#define XMesaCreatePixmap XCreatePixmap
#define XMesaFreePixmap XFreePixmap
#define XMesaFreeGC XFreeGC
#define GET_COLORMAP_SIZE(__v) __v->visinfo->colormap_size
#define GET_REDMASK(__v) __v->visinfo->red_mask
#define GET_GREENMASK(__v) __v->visinfo->green_mask
#define GET_BLUEMASK(__v) __v->visinfo->blue_mask
#define GET_BITS_PER_PIXEL(__v) bits_per_pixel(__v->display, __v->visinfo)
#if defined(__cplusplus) || defined(c_plusplus)
#define GET_VISUAL_CLASS(__v) __v->visinfo->c_class
#else
#define GET_VISUAL_CLASS(__v) __v->visinfo->class
#endif
#define GET_VISUAL_DEPTH(__v) __v->visinfo->depth
#define GET_BLACK_PIXEL(__v) BlackPixel(__v->display, __v->visinfo->screen)
#define CHECK_BYTE_ORDER(__v) host_byte_order()==ImageByteOrder(__v->display)
#define CHECK_FOR_HPCR(__v) XInternAtom(__v->display, "_HP_RGB_SMOOTH_MAP_LIST", True)
#endif

189
include/GL/xmesa_xf86.h Normal file
View file

@ -0,0 +1,189 @@
/**************************************************************************
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Kevin E. Martin <kevin@precisioninsight.com>
*
* $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/include/GL/xmesa_xf86.h,v 1.1 1999/08/19 00:55:40 jtg Exp $
*/
#ifndef _XMESA_XF86_H_
#define _XMESA_XF86_H_
#include "scrnintstr.h"
#include "pixmapstr.h"
typedef struct _XMesaImageRec XMesaImage;
typedef ScreenRec XMesaDisplay;
typedef PixmapPtr XMesaPixmap;
typedef ColormapPtr XMesaColormap;
typedef DrawablePtr XMesaDrawable;
typedef WindowPtr XMesaWindow;
typedef GCPtr XMesaGC;
typedef VisualPtr XMesaVisualInfo;
typedef DDXPointRec XMesaPoint;
typedef xColorItem XMesaColor;
#define XMesaSetGeneric(__d,__gc,__val,__mask) \
{ \
CARD32 __v[1]; \
(void) __d; \
__v[0] = __val; \
dixChangeGC(NullClient, __gc, __mask, __v, NULL); \
}
#define XMesaSetGenericPtr(__d,__gc,__pval,__mask) \
{ \
ChangeGCVal __v[1]; \
(void) __d; \
__v[0].ptr = __pval; \
dixChangeGC(NullClient, __gc, __mask, NULL, __v); \
}
#define XMesaSetDashes(__d,__gc,__do,__dl,__n) \
{ \
(void) __d; \
SetDashes(__gc, __do, __n, (unsigned char *)__dl); \
}
#define XMesaSetLineAttributes(__d,__gc,__lw,__ls,__cs,__js) \
{ \
CARD32 __v[4]; \
(void) __d; \
__v[0] = __lw; \
__v[1] = __ls; \
__v[2] = __cs; \
__v[3] = __js; \
dixChangeGC(NullClient, __gc, \
GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle, \
__v, NULL); \
}
#define XMesaSetForeground(d,gc,v) XMesaSetGeneric(d,gc,v,GCForeground)
#define XMesaSetBackground(d,gc,v) XMesaSetGeneric(d,gc,v,GCBackground)
#define XMesaSetPlaneMask(d,gc,v) XMesaSetGeneric(d,gc,v,GCPlaneMask)
#define XMesaSetFunction(d,gc,v) XMesaSetGeneric(d,gc,v,GCFunction)
#define XMesaSetFillStyle(d,gc,v) XMesaSetGeneric(d,gc,v,GCFillStyle)
#define XMesaSetTile(d,gc,v) XMesaSetGenericPtr(d,gc,v,GCTile)
#define XMesaSetStipple(d,gc,v) XMesaSetGenericPtr(d,gc,v,GCStipple)
#define XMesaDrawPoint(__d,__b,__gc,__x,__y) \
{ \
XMesaPoint __p[1]; \
(void) __d; \
__p[0].x = __x; \
__p[0].y = __y; \
ValidateGC(__b, __gc); \
(*gc->ops->PolyPoint)(__b, __gc, CoordModeOrigin, 1, __p); \
}
#define XMesaDrawPoints(__d,__b,__gc,__p,__n,__m) \
{ \
(void) __d; \
ValidateGC(__b, __gc); \
(*gc->ops->PolyPoint)(__b, __gc, __m, __n, __p); \
}
#define XMesaDrawLine(__d,__b,__gc,__x0,__y0,__x1,__y1) \
{ \
XMesaPoint __p[2]; \
(void) __d; \
ValidateGC(__b, __gc); \
__p[0].x = __x0; \
__p[0].y = __y0; \
__p[1].x = __x1; \
__p[1].y = __y1; \
(*__gc->ops->Polylines)(__b, __gc, CoordModeOrigin, 2, __p); \
}
#define XMesaFillRectangle(__d,__b,__gc,__x,__y,__w,__h) \
{ \
xRectangle __r[1]; \
(void) __d; \
ValidateGC(__b, __gc); \
__r[0].x = __x; \
__r[0].y = __y; \
__r[0].width = __w; \
__r[0].height = __h; \
(*__gc->ops->PolyFillRect)(__b, __gc, 1, __r); \
}
#define XMesaPutImage(__d,__b,__gc,__i,__sx,__sy,__x,__y,__w,__h) \
{ \
/* Assumes: Images are always in ZPixmap format */ \
(void) __d; \
if (__sx || __sy) /* The non-trivial case */ \
XMesaPutImageHelper(__d,__b,__gc,__i,__sx,__sy,__x,__y,__w,__h); \
ValidateGC(__b, __gc); \
(*__gc->ops->PutImage)(__b, __gc, ((XMesaDrawable)(__b))->depth, \
__x, __y, __w, __h, 0, ZPixmap, \
((XMesaImage *)(__i))->data); \
}
#define XMesaCopyArea(__d,__sb,__db,__gc,__sx,__sy,__w,__h,__x,__y) \
{ \
(void) __d; \
ValidateGC(__db, __gc); \
(*__gc->ops->CopyArea)((DrawablePtr)__sb, __db, __gc, \
__sx, __sy, __w, __h, __x, __y); \
}
#define XMesaFillPolygon(__d,__b,__gc,__p,__n,__s,__m) \
{ \
(void) __d; \
ValidateGC(__b, __gc); \
(*__gc->ops->FillPolygon)(__b, __gc, __s, __m, __n, __p); \
}
/* CreatePixmap returns a PixmapPtr; so, it cannot be inside braces */
#define XMesaCreatePixmap(__d,__b,__w,__h,__depth) \
(*__d->CreatePixmap)(__d, __w, __h, __depth)
#define XMesaFreePixmap(__d,__b) \
(*__d->DestroyPixmap)(__b)
#define XMesaFreeGC(__d,__gc) \
{ \
(void) __d; \
FreeScratchGC(__gc); \
}
#define GET_COLORMAP_SIZE(__v) __v->visinfo->ColormapEntries
#define GET_REDMASK(__v) __v->visinfo->redMask
#define GET_GREENMASK(__v) __v->visinfo->greenMask
#define GET_BLUEMASK(__v) __v->visinfo->blueMask
#define GET_BITS_PER_PIXEL(__v) __v->visinfo->bitsPerRGBValue
#define GET_VISUAL_CLASS(__v) __v->visinfo->class
#define GET_VISUAL_DEPTH(__v) __v->visinfo->nplanes
#define GET_BLACK_PIXEL(__v) __v->display->blackPixel
#define CHECK_BYTE_ORDER(__v) GL_TRUE
#define CHECK_FOR_HPCR(__v) GL_FALSE
#endif

42
progs/beos/Makefile Normal file
View file

@ -0,0 +1,42 @@
# $Id: Makefile,v 1.1 1999/08/19 00:55:40 jtg Exp $
# Makefile for BeOS demos
# Written by Brian Paul
# This file is in the public domain.
CC = g++
# Use Mesa:
CFLAGS = -I../include -c -g
LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lMesaGL
# Use BeOS OpenGL:
#CFLAGS = -I/boot/develop/headers/be/opengl -c -g
#LFLAGS = -L../lib -Xlinker -rpath ../lib -lbe -lGL
PROGRAMS = demo sample
default: $(PROGRAMS)
clean:
rm -f demo sample
rm -f *.o
demo: demo.o
$(CC) demo.o $(LFLAGS) -o $@
demo.o: demo.cpp
$(CC) $(CFLAGS) demo.cpp
sample: sample.o
$(CC) sample.o $(LFLAGS) -o $@
sample.o: sample.cpp
$(CC) $(CFLAGS) sample.cpp

153
progs/beos/demo.cpp Normal file
View file

@ -0,0 +1,153 @@
// $Id: demo.cpp,v 1.1 1999/08/19 00:55:40 jtg Exp $
// Simple BeOS GLView demo
// Written by Brian Paul
// This file is in the public domain.
#include <stdio.h>
#include <Application.h>
#include <Window.h>
#include <GLView.h>
class MyWindow : public BWindow
{
public:
MyWindow(BRect frame);
virtual bool QuitRequested();
};
MyWindow::MyWindow(BRect frame)
: BWindow(frame, "demo", B_TITLED_WINDOW, B_NOT_ZOOMABLE)
{
// no-op
}
bool MyWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
class MyGL : public BGLView
{
public:
MyGL(BRect rect, char *name, ulong options);
// virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
virtual void Pulse();
virtual void FrameResized(float w, float h);
private:
float mAngle;
};
MyGL::MyGL(BRect rect, char *name, ulong options)
: BGLView(rect, name, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, options)
{
mAngle = 0.0;
}
#if 0
void MyGL::AttachedToWindow()
{
BGLView::AttachedToWindow();
LockGL();
glClearColor(.7, .7, 0, 0);
UnlockGL();
}
#endif
void MyGL::FrameResized(float w, float h)
{
BGLView::FrameResized(w, h);
printf("FrameResized\n");
LockGL();
BGLView::FrameResized(w,h);
glViewport(0, 0, (int) (w + 1), (int) (h + 1));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 10, 30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -18);
UnlockGL();
}
void MyGL::Draw(BRect r)
{
printf("MyGL::Draw\n");
BGLView::Draw(r);
LockGL();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(mAngle, 0, 0, 1);
glColor3f(0, 0, 1);
glBegin(GL_POLYGON);
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
glVertex2f(-1, 1);
glEnd();
SwapBuffers();
UnlockGL();
}
void MyGL::Pulse()
{
printf("pulse\n");
BGLView::Pulse();
mAngle += 1.0;
LockGL();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(mAngle, 0, 0, 1);
glColor3f(0, 0, 1);
glBegin(GL_POLYGON);
glVertex2f(-1, -1);
glVertex2f( 1, -1);
glVertex2f( 1, 1);
glVertex2f(-1, 1);
glEnd();
SwapBuffers();
UnlockGL();
}
int main(int argc, char *argv[])
{
BApplication *app = new BApplication("application/demo");
// make top-level window
int x = 500, y = 500;
int w = 400, h = 400;
MyWindow *win = new MyWindow(BRect(x, y, x + w, y + h));
// win->Lock();
// win->Unlock();
win->Show();
// Make OpenGL view and put it in the window
MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB | BGL_DOUBLE);
// MyGL *gl = new MyGL(BRect(5, 5, w-10, h-10), "GL", BGL_RGB );
win->AddChild(gl);
printf("calling app->Run\n");
app->Run();
delete app;
return 0;
}

212
progs/beos/sample.cpp Normal file
View file

@ -0,0 +1,212 @@
// sample BGLView app from the Be Book
#include <stdio.h>
#include <Application.h>
#include <Window.h>
#include <GLView.h>
class SampleGLView : public BGLView
{
public:
SampleGLView(BRect frame, uint32 type);
virtual void AttachedToWindow(void);
virtual void FrameResized(float newWidth, float newHeight);
virtual void ErrorCallback(GLenum which);
void Render(void);
private:
void gInit(void);
void gDraw(void);
void gReshape(int width, int height);
float width;
float height;
};
class SampleGLWindow : public BWindow
{
public:
SampleGLWindow(BRect frame, uint32 type);
virtual bool QuitRequested() { return true; }
private:
SampleGLView *theView;
};
class SampleGLApp : public BApplication
{
public:
SampleGLApp();
private:
SampleGLWindow *theWindow;
};
SampleGLApp::SampleGLApp()
: BApplication("application/x-vnd.sample")
{
BRect windowRect;
uint32 type = BGL_RGB|BGL_DOUBLE;
windowRect.Set(50, 50, 350, 350);
theWindow = new SampleGLWindow(windowRect, type);
}
SampleGLWindow::SampleGLWindow(BRect frame, uint32 type)
: BWindow(frame, "OpenGL Test", B_TITLED_WINDOW, 0)
{
theView = new SampleGLView(Bounds(), type);
AddChild(theView);
Show();
theView->Render();
}
SampleGLView::SampleGLView(BRect frame, uint32 type)
: BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type)
{
width = frame.right-frame.left;
height = frame.bottom-frame.top;
}
void SampleGLView::AttachedToWindow(void)
{
LockGL();
BGLView::AttachedToWindow();
gInit();
gReshape(width, height);
UnlockGL();
}
void SampleGLView::FrameResized(float newWidth, float newHeight)
{
LockGL();
BGLView::FrameResized(width, height);
width = newWidth;
height = newHeight;
gReshape(width,height);
UnlockGL();
Render();
}
void SampleGLView::ErrorCallback(GLenum whichError)
{
// fprintf(stderr, "Unexpected error occured (%d):\\n", whichError);
// fprintf(stderr, " %s\\n", gluErrorString(whichError));
}
// globals
GLenum use_stipple_mode; // GL_TRUE to use dashed lines
GLenum use_smooth_mode; // GL_TRUE to use anti-aliased lines
GLint linesize; // Line width
GLint pointsize; // Point diameter
float pntA[3] = {
-160.0, 0.0, 0.0
};
float pntB[3] = {
-130.0, 0.0, 0.0
};
void SampleGLView::gInit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glLineStipple(1, 0xF0E0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
use_stipple_mode = GL_FALSE;
use_smooth_mode = GL_TRUE;
linesize = 2;
pointsize = 4;
}
void SampleGLView::gDraw(void)
{
GLint i;
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(linesize);
if (use_stipple_mode) {
glEnable(GL_LINE_STIPPLE);
} else {
glDisable(GL_LINE_STIPPLE);
}
if (use_smooth_mode) {
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
} else {
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
glPushMatrix();
for (i = 0; i < 360; i += 5) {
glRotatef(5.0, 0,0,1); // Rotate right 5 degrees
glColor3f(1.0, 1.0, 0.0); // Set color for line
glBegin(GL_LINE_STRIP); // And create the line
glVertex3fv(pntA);
glVertex3fv(pntB);
glEnd();
glPointSize(pointsize); // Set size for point
glColor3f(0.0, 1.0, 0.0); // Set color for point
glBegin(GL_POINTS);
glVertex3fv(pntA); // Draw point at one end
glVertex3fv(pntB); // Draw point at other end
glEnd();
}
glPopMatrix(); // Done with matrix
}
void SampleGLView::gReshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-175, 175, -175, 175, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
void SampleGLView::Render(void)
{
LockGL();
gDraw();
SwapBuffers();
UnlockGL();
}
int main(int argc, char *argv[])
{
SampleGLApp *app = new SampleGLApp;
app->Run();
delete app;
return 0;
}

View file

@ -0,0 +1,96 @@
# $Id: Makefile.BeOS-R4,v 1.1 1999/08/19 00:55:40 jtg Exp $
# Mesa 3-D graphics library
# Version: 3.1
# Copyright (C) 1995-1999 Brian Paul
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Makefile for GLUT-based demo programs for BeOS R4
# $Log: Makefile.BeOS-R4,v $
# Revision 1.1 1999/08/19 00:55:40 jtg
# Initial revision
#
# Revision 1.5 1999/06/22 12:50:11 brianp
# removed multitex demo
#
# Revision 1.4 1999/02/03 03:57:26 brianp
# replace multiext with multiarb
#
# Revision 1.3 1999/02/02 04:47:45 brianp
# removed glutfx from targets
#
# Revision 1.2 1999/02/02 04:46:23 brianp
# removed tessdemo from targets
#
# Revision 1.1 1999/02/02 04:43:27 brianp
# Initial revision
#
##### MACROS #####
INCDIR = ../include
LIBDIR = ../lib
GL_LIBS = -L$(LIBDIR) -L/boot/home/config/lib -Xlinker -rpath $(LIBDIR) -lbe -lglut -lMesaGLU -lMesaGL $(XLIBS)
LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
PROGS = bounce clearspd drawpix gamma gears glinfo isosurf \
morph3d multiarb osdemo paltex pointblast reflect \
renormal spectex stex3d texcyl texobj trispd winpos
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c: $(LIB_DEP)
$(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
##### TARGETS #####
default:
@echo "Specify a target configuration"
clean:
-rm *.o *~
realclean:
-rm $(PROGS)
-rm *.o *~
targets: $(PROGS)
# execute all programs
exec: $(PROGS)
@for prog in $(PROGS) ; \
do \
echo -n "Running $$prog ..." ; \
$$prog ; \
echo ; \
done
include ../Make-config

60
progs/demos/Makefile.X11 Normal file
View file

@ -0,0 +1,60 @@
# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:40 jtg Exp $
# Mesa 3-D graphics library
# Version: 3.1
# Copyright (C) 1995-1998 Brian Paul
# Makefile for GLUT-based demo programs for Unix/X11
##### MACROS #####
INCDIR = ../include
LIBDIR = ../lib
GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS)
LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
PROGS = bounce clearspd drawpix gamma gears glinfo glutfx isosurf \
morph3d multiarb osdemo paltex pointblast reflect \
renormal spectex stex3d tessdemo texcyl texobj trispd winpos
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c: $(LIB_DEP)
$(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
##### TARGETS #####
default:
@echo "Specify a target configuration"
clean:
-rm *.o *~
realclean:
-rm $(PROGS)
-rm *.o *~
targets: $(PROGS)
# execute all programs
exec: $(PROGS)
@for prog in $(PROGS) ; \
do \
echo -n "Running $$prog ..." ; \
$$prog ; \
echo ; \
done
include ../Make-config

View file

@ -0,0 +1,76 @@
# Makefile for demo programs
# Stephane Rehel (rehel@worldnet.fr) April 13 1997
# Mesa 3-D graphics library
# Version: 3.0
# Copyright (C) 1995-1998 Brian Paul
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# $Id: Makefile.cygnus,v 1.1 1999/08/19 00:55:40 jtg Exp $
# $Log: Makefile.cygnus,v $
# Revision 1.1 1999/08/19 00:55:40 jtg
# Initial revision
#
# Revision 3.1 1999/06/22 12:50:29 brianp
# removed multitex demo
#
# Revision 3.0 1998/06/10 02:55:51 brianp
# initial revision
#
##### MACROS #####
INCDIR = ../include
LIBDIR = ../lib
GL_LIBS = -L$(LIBDIR) -lglut -lMesaGLU -lMesaGL -lm $(WLIBS)
LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
PROGS = clearspd drawpix gamma gears glinfo glutfx isosurf \
morph3d multiext osdemo paltex pointblast reflect \
renormal spectex stex3d tessdemo texcyl texobj trispd winpos
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c: $(LIB_DEP)
$(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
##### TARGETS #####
default:
@echo "Specify a target configuration"
clean:
-rm *.o *~
realclean:
-rm $(PROGS:=.exe)
-rm *.o *~
targets: $(PROGS)
include ../Make-config

240
progs/demos/bounce.c Normal file
View file

@ -0,0 +1,240 @@
/* $Id: bounce.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Bouncing ball demo. Color index mode only!
*
* This program is in the public domain
*
* Brian Paul
*/
/* Conversion to GLUT by Mark J. Kilgard */
/*
* $Log: bounce.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/03/18 08:16:14 joukj
*
* cmpstr needs string.h to included to avoid warnings
*
* Revision 3.2 1998/11/28 01:13:02 brianp
* now sets an initial window position and size
*
* Revision 3.1 1998/11/28 01:06:57 brianp
* now works in RGB mode by default
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
#define COS(X) cos( (X) * 3.14159/180.0 )
#define SIN(X) sin( (X) * 3.14159/180.0 )
#define RED 1
#define WHITE 2
#define CYAN 3
GLboolean IndexMode = GL_FALSE;
GLuint Ball;
GLenum Mode;
GLfloat Zrot = 0.0, Zstep = 6.0;
GLfloat Xpos = 0.0, Ypos = 1.0;
GLfloat Xvel = 0.2, Yvel = 0.0;
GLfloat Xmin = -4.0, Xmax = 4.0;
GLfloat Ymin = -3.8, Ymax = 4.0;
GLfloat G = -0.1;
static GLuint
make_ball(void)
{
GLuint list;
GLfloat a, b;
GLfloat da = 18.0, db = 18.0;
GLfloat radius = 1.0;
GLuint color;
GLfloat x, y, z;
list = glGenLists(1);
glNewList(list, GL_COMPILE);
color = 0;
for (a = -90.0; a + da <= 90.0; a += da) {
glBegin(GL_QUAD_STRIP);
for (b = 0.0; b <= 360.0; b += db) {
if (color) {
glIndexi(RED);
glColor3f(1, 0, 0);
} else {
glIndexi(WHITE);
glColor3f(1, 1, 1);
}
x = COS(b) * COS(a);
y = SIN(b) * COS(a);
z = SIN(a);
glVertex3f(x, y, z);
x = radius * COS(b) * COS(a + da);
y = radius * SIN(b) * COS(a + da);
z = radius * SIN(a + da);
glVertex3f(x, y, z);
color = 1 - color;
}
glEnd();
}
glEndList();
return list;
}
static void
reshape(int width, int height)
{
float aspect = (float) width / (float) height;
glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-6.0 * aspect, 6.0 * aspect, -6.0, 6.0, -6.0, 6.0);
glMatrixMode(GL_MODELVIEW);
}
/* ARGSUSED1 */
static void
key(unsigned char k, int x, int y)
{
switch (k) {
case 27: /* Escape */
exit(0);
}
}
static void
draw(void)
{
GLint i;
glClear(GL_COLOR_BUFFER_BIT);
glIndexi(CYAN);
glColor3f(0, 1, 1);
glBegin(GL_LINES);
for (i = -5; i <= 5; i++) {
glVertex2i(i, -5);
glVertex2i(i, 5);
}
for (i = -5; i <= 5; i++) {
glVertex2i(-5, i);
glVertex2i(5, i);
}
for (i = -5; i <= 5; i++) {
glVertex2i(i, -5);
glVertex2f(i * 1.15, -5.9);
}
glVertex2f(-5.3, -5.35);
glVertex2f(5.3, -5.35);
glVertex2f(-5.75, -5.9);
glVertex2f(5.75, -5.9);
glEnd();
glPushMatrix();
glTranslatef(Xpos, Ypos, 0.0);
glScalef(2.0, 2.0, 2.0);
glRotatef(8.0, 0.0, 0.0, 1.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
glRotatef(Zrot, 0.0, 0.0, 1.0);
glCallList(Ball);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
static void
idle(void)
{
static float vel0 = -100.0;
Zrot += Zstep;
Xpos += Xvel;
if (Xpos >= Xmax) {
Xpos = Xmax;
Xvel = -Xvel;
Zstep = -Zstep;
}
if (Xpos <= Xmin) {
Xpos = Xmin;
Xvel = -Xvel;
Zstep = -Zstep;
}
Ypos += Yvel;
Yvel += G;
if (Ypos < Ymin) {
Ypos = Ymin;
if (vel0 == -100.0)
vel0 = fabs(Yvel);
Yvel = vel0;
}
glutPostRedisplay();
}
void
visible(int vis)
{
if (vis == GLUT_VISIBLE)
glutIdleFunc(idle);
else
glutIdleFunc(NULL);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 450);
IndexMode = argc > 1 && strcmp(argv[1], "-ci") == 0;
if (IndexMode)
glutInitDisplayMode(GLUT_INDEX | GLUT_DOUBLE);
else
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Bounce");
Ball = make_ball();
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_DITHER);
glShadeModel(GL_FLAT);
glutDisplayFunc(draw);
glutReshapeFunc(reshape);
glutVisibilityFunc(visible);
glutKeyboardFunc(key);
if (IndexMode) {
glutSetColor(RED, 1.0, 0.0, 0.0);
glutSetColor(WHITE, 1.0, 1.0, 1.0);
glutSetColor(CYAN, 0.0, 1.0, 1.0);
}
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

221
progs/demos/clearspd.c Normal file
View file

@ -0,0 +1,221 @@
/* $Id: clearspd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Simple GLUT program to measure glClear() and glutSwapBuffers() speed.
* Brian Paul February 15, 1997 This file in public domain.
*/
/*
* $Log: clearspd.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/03/28 18:18:33 brianp
* minor clean-up
*
* Revision 3.2 1999/03/18 08:16:34 joukj
*
* cmpstr needs string.h to included to avoid warnings
*
* Revision 3.1 1998/06/29 02:38:30 brianp
* removed unneeded includes
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <GL/glut.h>
static float MinPeriod = 2.0; /* 2 seconds */
static int ColorMode = GLUT_RGB;
static int Width = 400.0;
static int Height = 400.0;
static int Loops = 100;
static float ClearColor = 0.0;
static GLbitfield BufferMask = GL_COLOR_BUFFER_BIT;
static GLboolean SwapFlag = GL_FALSE;
static void Idle( void )
{
glutPostRedisplay();
}
static void Display( void )
{
double t0, t1;
double clearRate;
double pixelRate;
int i;
glClearColor( ClearColor, ClearColor, ClearColor, 0.0 );
ClearColor += 0.1;
if (ClearColor>1.0)
ClearColor = 0.0;
if (SwapFlag) {
t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
for (i=0;i<Loops;i++) {
glClear( BufferMask );
glutSwapBuffers();
}
t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
}
else {
t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
for (i=0;i<Loops;i++) {
glClear( BufferMask );
}
t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
glutSwapBuffers();
}
if (t1-t0 < MinPeriod) {
/* Next time do more clears to get longer elapsed time */
Loops *= 2;
return;
}
clearRate = Loops / (t1-t0);
pixelRate = clearRate * Width * Height;
if (SwapFlag) {
printf("Rate: %d clears+swaps in %gs = %g clears+swaps/s %d pixels/s\n",
Loops, t1-t0, clearRate, (int)pixelRate );
}
else {
printf("Rate: %d clears in %gs = %g clears/s %d pixels/s\n",
Loops, t1-t0, clearRate, (int)pixelRate);
}
}
static void Reshape( int width, int height )
{
Width = width;
Height = height;
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void Init( int argc, char *argv[] )
{
int i;
for (i=1; i<argc; i++) {
if (strcmp(argv[i],"+rgb")==0)
ColorMode = GLUT_RGB;
else if (strcmp(argv[i],"+ci")==0)
ColorMode = GLUT_INDEX;
else if (strcmp(argv[i],"-color")==0)
BufferMask = 0;
else if (strcmp(argv[i],"+depth")==0)
BufferMask |= GL_DEPTH_BUFFER_BIT;
else if (strcmp(argv[i],"+alpha")==0)
ColorMode = GLUT_RGB | GLUT_ALPHA;
else if (strcmp(argv[i],"+stencil")==0)
BufferMask |= GL_STENCIL_BUFFER_BIT;
else if (strcmp(argv[i],"+accum")==0)
BufferMask |= GL_ACCUM_BUFFER_BIT;
else if (strcmp(argv[i],"-width")==0) {
Width = atoi(argv[i+1]);
i++;
}
else if (strcmp(argv[i],"-height")==0) {
Height = atoi(argv[i+1]);
i++;
}
else if (strcmp(argv[i],"+swap")==0) {
SwapFlag = GL_TRUE;
}
else if (strcmp(argv[i],"-swap")==0) {
SwapFlag = GL_FALSE;
}
else
printf("Unknown option: %s\n", argv[i]);
}
if (ColorMode & GLUT_ALPHA)
printf("Mode: RGB + Alpha\n");
else if (ColorMode==GLUT_RGB)
printf("Mode: RGB\n");
else
printf("Mode: Color Index\n");
printf("SwapBuffers: %s\n", SwapFlag ? "yes" : "no" );
printf("Size: %d x %d\n", Width, Height);
printf("Buffers: ");
if (BufferMask & GL_COLOR_BUFFER_BIT) printf("color ");
if (BufferMask & GL_DEPTH_BUFFER_BIT) printf("depth ");
if (BufferMask & GL_STENCIL_BUFFER_BIT) printf("stencil ");
if (BufferMask & GL_ACCUM_BUFFER_BIT) printf("accum ");
printf("\n");
}
static void Help( const char *program )
{
printf("%s options:\n", program);
printf(" +rgb RGB mode\n");
printf(" +ci color index mode\n");
printf(" -color don't clear color buffer\n");
printf(" +alpha clear alpha buffer\n");
printf(" +depth clear depth buffer\n");
printf(" +stencil clear stencil buffer\n");
printf(" +accum clear accum buffer\n");
printf(" +swap also do SwapBuffers\n");
printf(" -swap don't do SwapBuffers\n");
}
int main( int argc, char *argv[] )
{
printf("For options: %s -help\n", argv[0]);
Init( argc, argv );
glutInit( &argc, argv );
glutInitWindowSize( (int) Width, (int) Height );
glutInitWindowPosition( 0, 0 );
glutInitDisplayMode( ColorMode | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_ACCUM );
glutCreateWindow( argv[0] );
if (argc==2 && strcmp(argv[1],"-help")==0) {
Help(argv[0]);
return 0;
}
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutMainLoop();
return 0;
}

63
progs/demos/descrip.mms Normal file
View file

@ -0,0 +1,63 @@
# Makefile for GLUT-based demo programs for VMS
# contributed by Jouk Jansen joukj@crys.chem.uva.nl
.first
define gl [-.include.gl]
.include [-]mms-config.
##### MACROS #####
INCDIR = [-.include]
CFLAGS = /include=$(INCDIR)/prefix=all
.ifdef SHARE
GL_LIBS = $(XLIBS)
.else
GL_LIBS = [-.lib]libGLUT/l,libMesaGLU/l,libMesaGL/l,$(XLIBS)
.endif
LIB_DEP = [-.lib]$(GL_LIB) [-.lib]$(GLU_LIB) [-.lib]$(GLUT_LIB)
PROGS = bounce.exe;,clearspd.exe;,drawpix.exe;,gamma.exe;,gears.exe;,\
glinfo.exe;,glutfx.exe;,isosurf.exe;,morph3d.exe;,osdemo.exe;,\
paltex.exe;,pointblast.exe;,reflect.exe;,spectex.exe;,stex3d.exe;,\
tessdemo.exe;,texcyl.exe;,texobj.exe;,trispd.exe;,winpos.exe;
##### RULES #####
.obj.exe :
link $(MMS$TARGET_NAME),$(GL_LIBS)
##### TARGETS #####
default :
$(MMS)$(MMSQUALIFIERS) $(PROGS)
clean :
delete *.obj;*
realclean :
delete $(PROGS)
delete *.obj;*
bounce.exe; : bounce.obj $(LIB_DEP)
clearspd.exe; : clearspd.obj $(LIB_DEP)
drawpix.exe; : drawpix.obj $(LIB_DEP)
gamma.exe; : gamma.obj $(LIB_DEP)
gears.exe; : gears.obj $(LIB_DEP)
glinfo.exe; : glinfo.obj $(LIB_DEP)
glutfx.exe; : glutfx.obj $(LIB_DEP)
isosurf.exe; : isosurf.obj $(LIB_DEP)
morph3d.exe; : morph3d.obj $(LIB_DEP)
osdemo.exe; : osdemo.obj $(LIB_DEP)
paltex.exe; : paltex.obj $(LIB_DEP)
pointblast.exe; : pointblast.obj $(LIB_DEP)
reflect.exe; : reflect.obj $(LIB_DEP)
spectex.exe; : spectex.obj $(LIB_DEP)
stex3d.exe; : stex3d.obj $(LIB_DEP)
tessdemo.exe; : tessdemo.obj $(LIB_DEP)
texcyl.exe; : texcyl.obj $(LIB_DEP)
texobj.exe; : texobj.obj $(LIB_DEP)
trispd.exe; : trispd.obj $(LIB_DEP)
winpos.exe; : winpos.obj $(LIB_DEP)

307
progs/demos/drawpix.c Normal file
View file

@ -0,0 +1,307 @@
/* $Id: drawpix.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* glDrawPixels demo/test/benchmark
*
* Brian Paul September 25, 1997 This file is in the public domain.
*/
/*
* $Log: drawpix.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/03/28 18:18:33 brianp
* minor clean-up
*
* Revision 3.2 1998/11/05 04:34:04 brianp
* moved image files to ../images/ directory
*
* Revision 3.1 1998/02/22 16:43:17 brianp
* added a few casts to silence compiler warnings
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include "../util/readtex.c" /* a hack, I know */
#define IMAGE_FILE "../images/girl.rgb"
static int ImgWidth, ImgHeight;
static GLenum ImgFormat;
static GLubyte *Image = NULL;
static int Xpos, Ypos;
static int SkipPixels, SkipRows;
static int DrawWidth, DrawHeight;
static int Scissor = 0;
static float Xzoom, Yzoom;
static void Reset( void )
{
Xpos = Ypos = 20;
DrawWidth = ImgWidth;
DrawHeight = ImgHeight;
SkipPixels = SkipRows = 0;
Scissor = 0;
Xzoom = Yzoom = 1.0;
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
#if 0
glRasterPos2i(Xpos, Ypos);
#else
/* This allows negative raster positions: */
glRasterPos2i(0, 0);
glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL);
#endif
glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels);
glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows);
glPixelZoom( Xzoom, Yzoom );
if (Scissor)
glEnable(GL_SCISSOR_TEST);
glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
glDisable(GL_SCISSOR_TEST);
glutSwapBuffers();
}
static void Benchmark( void )
{
int startTime, endTime;
int draws = 500;
double seconds, pixelsPerSecond;
printf("Benchmarking...\n");
/* GL set-up */
glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels);
glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows);
glPixelZoom( Xzoom, Yzoom );
if (Scissor)
glEnable(GL_SCISSOR_TEST);
/* Run timing test */
draws = 0;
startTime = glutGet(GLUT_ELAPSED_TIME);
do {
glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image);
draws++;
endTime = glutGet(GLUT_ELAPSED_TIME);
} while (endTime - startTime < 4000); /* 4 seconds */
/* GL clean-up */
glDisable(GL_SCISSOR_TEST);
/* Results */
seconds = (double) (endTime - startTime) / 1000.0;
pixelsPerSecond = draws * DrawWidth * DrawHeight / seconds;
printf("Result: %d draws in %f seconds = %f pixels/sec\n",
draws, seconds, pixelsPerSecond);
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glScissor(width/4, height/4, width/2, height/2);
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case ' ':
Reset();
break;
case 'w':
if (DrawWidth > 0)
DrawWidth--;
break;
case 'W':
DrawWidth++;
break;
case 'h':
if (DrawHeight > 0)
DrawHeight--;
break;
case 'H':
DrawHeight++;
break;
case 'p':
if (SkipPixels > 0)
SkipPixels--;
break;
case 'P':
SkipPixels++;
break;
case 'r':
if (SkipRows > 0)
SkipRows--;
break;
case 'R':
SkipRows++;
break;
case 's':
Scissor = !Scissor;
break;
case 'x':
Xzoom -= 0.1;
break;
case 'X':
Xzoom += 0.1;
break;
case 'y':
Yzoom -= 0.1;
break;
case 'Y':
Yzoom += 0.1;
break;
case 'b':
Benchmark();
break;
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
Ypos += 1;
break;
case GLUT_KEY_DOWN:
Ypos -= 1;
break;
case GLUT_KEY_LEFT:
Xpos -= 1;
break;
case GLUT_KEY_RIGHT:
Xpos += 1;
break;
}
glutPostRedisplay();
}
static void Init( GLboolean ciMode )
{
printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
if (!Image) {
printf("Couldn't read %s\n", IMAGE_FILE);
exit(0);
}
if (ciMode) {
/* Convert RGB image to grayscale */
GLubyte *indexImage = malloc( ImgWidth * ImgHeight );
GLint i;
for (i=0; i<ImgWidth*ImgHeight; i++) {
int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2];
indexImage[i] = gray / 3;
}
free(Image);
Image = indexImage;
ImgFormat = GL_COLOR_INDEX;
for (i=0;i<255;i++) {
float g = i / 255.0;
glutSetColor(i, g, g, g);
}
}
printf("Loaded %d by %d image\n", ImgWidth, ImgHeight );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth);
Reset();
}
static void Usage(void)
{
printf("Keys:\n");
printf(" SPACE Reset\n");
printf(" Up/Down Move image up/down\n");
printf(" Left/Right Move image left/right\n");
printf(" w Decrease glDrawPixels width\n");
printf(" W Increase glDrawPixels width\n");
printf(" h Decrease glDrawPixels height\n");
printf(" H Increase glDrawPixels height\n");
printf(" p Decrease GL_UNPACK_SKIP_PIXELS\n");
printf(" P Increase GL_UNPACK_SKIP_PIXELS\n");
printf(" r Decrease GL_UNPACK_SKIP_ROWS\n");
printf(" R Increase GL_UNPACK_SKIP_ROWS\n");
printf(" s Toggle GL_SCISSOR_TEST\n");
printf(" b Benchmark test\n");
printf(" ESC Exit\n");
}
int main( int argc, char *argv[] )
{
GLboolean ciMode = GL_FALSE;
if (argc > 1 && strcmp(argv[1], "-ci")==0) {
ciMode = GL_TRUE;
}
glutInit( &argc, argv );
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 500, 400 );
if (ciMode)
glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE );
else
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0]);
Init(ciMode);
Usage();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutMainLoop();
return 0;
}

176
progs/demos/gamma.c Normal file
View file

@ -0,0 +1,176 @@
/* $Id: gamma.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/* Draw test patterns to help determine correct gamma value for a display.
When the intensities of the inner squares nearly match the intensities
of their frames (from some distance the borders should disappear) then
you've found the right gamma value.
You can set Mesa's gamma values (for red, green and blue) with the
MESA_GAMMA environment variable. But only on X windows!
For example:
setenv MESA_GAMMA 1.5 1.6 1.4
Sets the red gamma value to 1.5, green to 1.6 and blue to 1.4.
See the main README file for more information.
For more info about gamma correction see:
http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html
This program is in the public domain
Brian Paul 19 Oct 1995
Kai Schuetz 05 Jun 1999 */
/* Conversion to GLUT by Mark J. Kilgard */
/*
* $Log: gamma.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1999/06/19 01:35:38 brianp
* merged in Kai Schuetz's RGB changes
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
static void
Reshape(int width, int height)
{
glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_FLAT);
}
/* ARGSUSED1 */
static void
key_esc(unsigned char key, int x, int y)
{
if(key == 27) exit(0); /* Exit on Escape */
}
static GLubyte p25[] = {
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
};
static GLubyte p50[] = {
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
};
static GLubyte p75[] = {
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
};
static GLubyte *stippletab[4] = {NULL, p25, p50, p75};
static void
gamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b)
{
GLint d;
glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */
glRectf(-1.0, yoffs, -0.6, yoffs + 0.5);
for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */
GLfloat xcoord = (-1.0 + d*0.4);
glColor3f(r*d / 5.0, g*d / 5.0, b*d / 5.0); /* draw outer rect */
glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5);
glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */
glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
glColor3f(r, g, b); /* draw stippled inner rect */
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(stippletab[d]);
glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
glDisable(GL_POLYGON_STIPPLE);
}
glColor3f(r, g, b); /* solid color, no stipple */
glRectf(0.6, yoffs, 1.0, yoffs + 0.5);
}
static void
display(void)
{
gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */
gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */
gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */
gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */
glFlush();
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 400);
glutCreateWindow("gamma test patterns");
glutReshapeFunc(Reshape);
glutDisplayFunc(display);
glutKeyboardFunc(key_esc);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

356
progs/demos/gears.c Normal file
View file

@ -0,0 +1,356 @@
/* $Id: gears.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* 3-D gear wheels. This program is in the public domain.
*
* Brian Paul
*/
/* Conversion to GLUT by Mark J. Kilgard */
/*
* $Log: gears.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/06/03 17:07:36 brianp
* an extra quad was being drawn in front and back faces
*
* Revision 3.1 1998/11/03 02:49:10 brianp
* added fps output
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
static GLint T0 = 0;
static GLint Frames = 0;
/**
Draw a gear wheel. You'll probably want to call this function when
building a display list since we do a lot of trig here.
Input: inner_radius - radius of hole at center
outer_radius - radius at center of teeth
width - width of gear
teeth - number of teeth
tooth_depth - depth of tooth
**/
static void
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
GLint teeth, GLfloat tooth_depth)
{
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
GLfloat u, v, len;
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0;
r2 = outer_radius + tooth_depth / 2.0;
da = 2.0 * M_PI / teeth / 4.0;
glShadeModel(GL_FLAT);
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
if (i < teeth) {
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
}
}
glEnd();
/* draw front sides of teeth */
glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
}
glEnd();
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
if (i < teeth) {
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
}
}
glEnd();
/* draw back sides of teeth */
glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
}
glEnd();
/* draw outward faces of teeth */
glBegin(GL_QUAD_STRIP);
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
u = r2 * cos(angle + da) - r1 * cos(angle);
v = r2 * sin(angle + da) - r1 * sin(angle);
len = sqrt(u * u + v * v);
u /= len;
v /= len;
glNormal3f(v, -u, 0.0);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
glNormal3f(v, -u, 0.0);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
}
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
glEnd();
glShadeModel(GL_SMOOTH);
/* draw inside radius cylinder */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glNormal3f(-cos(angle), -sin(angle), 0.0);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
}
glEnd();
}
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
static void
draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(view_rotx, 1.0, 0.0, 0.0);
glRotatef(view_roty, 0.0, 1.0, 0.0);
glRotatef(view_rotz, 0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(-3.0, -2.0, 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
glCallList(gear1);
glPopMatrix();
glPushMatrix();
glTranslatef(3.1, -2.0, 0.0);
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
glCallList(gear2);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.1, 4.2, 0.0);
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
glCallList(gear3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
Frames++;
{
GLint t = glutGet(GLUT_ELAPSED_TIME);
if (t - T0 >= 5000) {
GLfloat seconds = (t - T0) / 1000.0;
GLfloat fps = Frames / seconds;
printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
T0 = t;
Frames = 0;
}
}
}
static void
idle(void)
{
angle += 2.0;
glutPostRedisplay();
}
/* change view angle, exit upon ESC */
/* ARGSUSED1 */
static void
key(unsigned char k, int x, int y)
{
switch (k) {
case 'z':
view_rotz += 5.0;
break;
case 'Z':
view_rotz -= 5.0;
break;
case 27: /* Escape */
exit(0);
break;
default:
return;
}
glutPostRedisplay();
}
/* change view angle */
/* ARGSUSED1 */
static void
special(int k, int x, int y)
{
switch (k) {
case GLUT_KEY_UP:
view_rotx += 5.0;
break;
case GLUT_KEY_DOWN:
view_rotx -= 5.0;
break;
case GLUT_KEY_LEFT:
view_roty += 5.0;
break;
case GLUT_KEY_RIGHT:
view_roty -= 5.0;
break;
default:
return;
}
glutPostRedisplay();
}
/* new window size or exposure */
static void
reshape(int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;
glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
}
static void
init(void)
{
static GLfloat pos[4] =
{5.0, 5.0, 10.0, 0.0};
static GLfloat red[4] =
{0.8, 0.1, 0.0, 1.0};
static GLfloat green[4] =
{0.0, 0.8, 0.2, 1.0};
static GLfloat blue[4] =
{0.2, 0.2, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
/* make the gears */
gear1 = glGenLists(1);
glNewList(gear1, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
gear(1.0, 4.0, 1.0, 20, 0.7);
glEndList();
gear2 = glGenLists(1);
glNewList(gear2, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
gear(0.5, 2.0, 2.0, 10, 0.7);
glEndList();
gear3 = glGenLists(1);
glNewList(gear3, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
gear(1.3, 2.0, 0.5, 10, 0.7);
glEndList();
glEnable(GL_NORMALIZE);
}
void
visible(int vis)
{
if (vis == GLUT_VISIBLE)
glutIdleFunc(idle);
else
glutIdleFunc(NULL);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
glutCreateWindow("Gears");
init();
glutDisplayFunc(draw);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutSpecialFunc(special);
glutVisibilityFunc(visible);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

50
progs/demos/glinfo.c Normal file
View file

@ -0,0 +1,50 @@
/* $Id: glinfo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Print GL, GLU and GLUT version and extension info
*
* Brian Paul This file in public domain.
* October 3, 1997
*/
/*
* $Log: glinfo.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/02/02 04:45:49 brianp
* include stdio.h before glut.h
*
* Revision 3.1 1998/02/22 16:42:54 brianp
* added casts to prevent compiler warnings
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <GL/glut.h>
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB );
glutCreateWindow(argv[0]);
printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
printf("GL_EXTENSIONS: %s\n", (char *) glGetString(GL_EXTENSIONS));
printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR));
printf("GLU_VERSION: %s\n", (char *) gluGetString(GLU_VERSION));
printf("GLU_EXTENSIONS: %s\n", (char *) gluGetString(GLU_EXTENSIONS));
printf("GLUT_API_VERSION: %d\n", GLUT_API_VERSION);
#ifdef GLUT_XLIB_IMPLEMENTATION
printf("GLUT_XLIB_IMPLEMENTATION: %d\n", GLUT_XLIB_IMPLEMENTATION);
#endif
return 0;
}

207
progs/demos/glutfx.c Normal file
View file

@ -0,0 +1,207 @@
/* $Id: glutfx.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Example of how one might use GLUT with the 3Dfx driver in full-screen mode.
* Note: this only works with X since we're using Mesa's GLX "hack" for
* using Glide.
*
* Goals:
* easy setup and input event handling with GLUT
* use 3Dfx hardware
* automatically set MESA environment variables
* don't lose mouse input focus
*
* Brian Paul This file is in the public domain.
*/
/*
* $Log: glutfx.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/03/28 18:18:33 brianp
* minor clean-up
*
* Revision 3.1 1998/06/29 02:37:30 brianp
* minor changes for Windows (Ted Jump)
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#define WIDTH 640
#define HEIGHT 480
static int Window = 0;
static int ScreenWidth, ScreenHeight;
static GLuint Torus = 0;
static GLfloat Xrot = 0.0, Yrot = 0.0;
static void Display( void )
{
static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
static GLfloat red[4] = {1.0, 0.2, 0.2, 1.0};
static GLfloat green[4] = {0.2, 1.0, 0.2, 1.0};
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef(Xrot, 1, 0, 0);
glRotatef(Yrot, 0, 1, 0);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
glCallList(Torus);
glRotatef(90.0, 1, 0, 0);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
glCallList(Torus);
glRotatef(90.0, 0, 1, 0);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
glCallList(Torus);
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
float ratio = (float) width / (float) height;
ScreenWidth = width;
ScreenHeight = height;
/*
* The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
* Enforce that here.
*/
if (width > WIDTH)
width = WIDTH;
if (height > HEIGHT)
height = HEIGHT;
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -20.0 );
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
glutDestroyWindow(Window);
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
case GLUT_KEY_LEFT:
break;
case GLUT_KEY_RIGHT:
break;
}
glutPostRedisplay();
}
static void MouseMove( int x, int y )
{
Xrot = y - ScreenWidth / 2;
Yrot = x - ScreenHeight / 2;
glutPostRedisplay();
}
static void Init( void )
{
Torus = glGenLists(1);
glNewList(Torus, GL_COMPILE);
glutSolidTorus(0.5, 2.0, 10, 20);
glEndList();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
int main( int argc, char *argv[] )
{
#ifndef _WIN32
printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this");
printf(" program as root.\n\n");
printf("Move the mouse. Press ESC to exit.\n\n");
sleep(2);
#endif
/* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */
putenv("MESA_GLX_FX=fullscreen");
/* Disable 3Dfx Glide splash screen */
putenv("FX_GLIDE_NO_SPLASH=");
/* Give an initial size and position so user doesn't have to place window */
glutInitWindowPosition(0, 0);
glutInitWindowSize(WIDTH, HEIGHT);
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
Window = glutCreateWindow(argv[0]);
if (!Window) {
printf("Error, couldn't open window\n");
exit(1);
}
/*
* Want the X window to fill the screen so that we don't have to
* worry about losing the mouse input focus.
* Note that we won't actually see the X window since we never draw
* to it, hence, the original X screen's contents aren't disturbed.
*/
glutFullScreen();
Init();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutPassiveMotionFunc( MouseMove );
glutMainLoop();
return 0;
}

821
progs/demos/isosurf.c Normal file
View file

@ -0,0 +1,821 @@
/* $Id: isosurf.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Display an isosurface of 3-D wind speed volume. Use arrow keys to
* rotate, S toggles smooth shading, L toggles lighting
* Brian Paul This file in public domain.
*/
/*
* $Log: isosurf.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.4 1999/04/24 01:10:47 keithw
* clip planes, materials
*
* Revision 3.3 1999/03/31 19:42:14 keithw
* support for cva
*
* Revision 3.1 1998/11/01 20:30:20 brianp
* added benchmark feature (b key)
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "GL/glut.h"
#include "../util/readtex.c" /* I know, this is a hack. KW: me too. */
#define TEXTURE_FILE "../images/reflect.rgb"
#define LIT 0x1
#define UNLIT 0x2
#define TEXTURE 0x4
#define NO_TEXTURE 0x8
#define REFLECT 0x10
#define NO_REFLECT 0x20
#define POINT_FILTER 0x40
#define LINEAR_FILTER 0x80
#define IMMEDIATE 0x100
#define DRAW_ARRAYS 0x200 /* or draw_elts, if compiled */
#define ARRAY_ELT 0x400
#define COMPILED 0x800
#define NOT_COMPILED 0x1000
#define SHADE_SMOOTH 0x2000
#define SHADE_FLAT 0x4000
#define TRIANGLES 0x8000
#define STRIPS 0x10000
#define USER_CLIP 0x20000
#define NO_USER_CLIP 0x40000
#define MATERIALS 0x80000
#define NO_MATERIALS 0x100000
#define QUIT 0x800000
#define LIGHT_MASK (LIT|UNLIT)
#define TEXTURE_MASK (TEXTURE|NO_TEXTURE)
#define REFLECT_MASK (REFLECT|NO_REFLECT)
#define FILTER_MASK (POINT_FILTER|LINEAR_FILTER)
#define RENDER_STYLE_MASK (IMMEDIATE|DRAW_ARRAYS|ARRAY_ELT)
#define COMPILED_MASK (COMPILED|NOT_COMPILED)
#define MATERIAL_MASK (MATERIALS|NO_MATERIALS)
#define PRIMITIVE_MASK (TRIANGLES|STRIPS)
#define CLIP_MASK (USER_CLIP|NO_USER_CLIP)
#define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT)
#define MAXVERTS 10000
static float data[MAXVERTS][6];
static float compressed_data[MAXVERTS][6];
static GLuint indices[MAXVERTS];
static GLuint tri_indices[MAXVERTS*3];
static GLfloat col[100][4];
static GLint numverts, num_tri_verts, numuniq;
static GLfloat xrot;
static GLfloat yrot;
static GLint state, allowed = ~0;
static GLboolean doubleBuffer = GL_TRUE;
static GLdouble plane[4] = {1.0, 0.0, -1.0, 0.0};
static void read_surface( char *filename )
{
FILE *f;
f = fopen(filename,"r");
if (!f) {
printf("couldn't read %s\n", filename);
exit(1);
}
numverts = 0;
while (!feof(f) && numverts<MAXVERTS) {
fscanf( f, "%f %f %f %f %f %f",
&data[numverts][0], &data[numverts][1], &data[numverts][2],
&data[numverts][3], &data[numverts][4], &data[numverts][5] );
numverts++;
}
numverts--;
printf("%d vertices, %d triangles\n", numverts, numverts-2);
fclose(f);
}
struct data_idx {
float *data;
int idx;
int uniq_idx;
};
#define COMPARE_FUNC( AXIS ) \
int compare_axis_##AXIS( const void *a, const void *b ) \
{ \
float t = ( (*(struct data_idx *)a).data[AXIS] - \
(*(struct data_idx *)b).data[AXIS] ); \
\
if (t < 0) return -1; \
if (t > 0) return 1; \
return 0; \
}
COMPARE_FUNC(0)
COMPARE_FUNC(1)
COMPARE_FUNC(2)
COMPARE_FUNC(3)
COMPARE_FUNC(4)
COMPARE_FUNC(5)
COMPARE_FUNC(6)
int (*(compare[7]))( const void *a, const void *b ) =
{
compare_axis_0,
compare_axis_1,
compare_axis_2,
compare_axis_3,
compare_axis_4,
compare_axis_5,
compare_axis_6,
};
#define VEC_ELT(f, s, i) (float *)(((char *)f) + s * i)
static int sort_axis( int axis,
int vec_size,
int vec_stride,
struct data_idx *indices,
int start,
int finish,
float *out,
int uniq,
const float fudge )
{
int i;
if (finish-start > 2)
{
qsort( indices+start, finish-start, sizeof(*indices), compare[axis] );
}
else if (indices[start].data[axis] > indices[start+1].data[axis])
{
struct data_idx tmp = indices[start];
indices[start] = indices[start+1];
indices[start+1] = tmp;
}
if (axis == vec_size-1) {
for (i = start ; i < finish ; ) {
float max = indices[i].data[axis] + fudge;
float *dest = VEC_ELT(out, vec_stride, uniq);
int j;
for (j = 0 ; j < vec_size ; j++)
dest[j] = indices[i].data[j];
for ( ; i < finish && max >= indices[i].data[axis]; i++)
indices[i].uniq_idx = uniq;
uniq++;
}
} else {
for (i = start ; i < finish ; ) {
int j = i + 1;
float max = indices[i].data[axis] + fudge;
while (j < finish && max >= indices[j].data[axis]) j++;
if (j == i+1) {
float *dest = VEC_ELT(out, vec_stride, uniq);
int k;
indices[i].uniq_idx = uniq;
for (k = 0 ; k < vec_size ; k++)
dest[k] = indices[i].data[k];
uniq++;
} else {
uniq = sort_axis( axis+1, vec_size, vec_stride,
indices, i, j, out, uniq, fudge );
}
i = j;
}
}
return uniq;
}
static void extract_indices1( const struct data_idx *in, unsigned int *out,
int n )
{
int i;
for ( i = 0 ; i < n ; i++ ) {
out[in[i].idx] = in[i].uniq_idx;
}
}
static void compactify_arrays()
{
int i;
struct data_idx *ind;
ind = (struct data_idx *) malloc( sizeof(struct data_idx) * numverts );
for (i = 0 ; i < numverts ; i++) {
ind[i].idx = i;
ind[i].data = data[i];
}
numuniq = sort_axis(0,
sizeof(compressed_data[0])/sizeof(float),
sizeof(compressed_data[0]),
ind,
0,
numverts,
(float *)compressed_data,
0,
1e-6);
printf("Nr unique vertex/normal pairs: %d\n", numuniq);
extract_indices1( ind, indices, numverts );
free( ind );
}
static float myrand( float max )
{
return max*rand()/(RAND_MAX+1.0);
}
static void make_tri_indices( void )
{
unsigned int *v = tri_indices;
unsigned int parity = 0;
unsigned int i, j;
for (j=2;j<numverts;j++,parity^=1) {
if (parity) {
*v++ = indices[j-1];
*v++ = indices[j-2];
*v++ = indices[j];
} else {
*v++ = indices[j-2];
*v++ = indices[j-1];
*v++ = indices[j];
}
}
num_tri_verts = v - tri_indices;
printf("num_tri_verts: %d\n", num_tri_verts);
for (i = j = 0 ; i < num_tri_verts ; i += 600, j++) {
col[j][3] = 1;
col[j][2] = myrand(1);
col[j][1] = myrand(1);
col[j][0] = myrand(1);
}
}
#define MIN(x,y) (x < y) ? x : y
static void draw_surface( void )
{
GLuint i, j;
switch (state & (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)) {
#ifdef GL_EXT_vertex_array
case (COMPILED|DRAW_ARRAYS|STRIPS):
glDrawElements( GL_TRIANGLE_STRIP, numverts, GL_UNSIGNED_INT, indices );
break;
case (COMPILED|ARRAY_ELT|STRIPS):
glBegin( GL_TRIANGLE_STRIP );
for (i = 0 ; i < numverts ; i++)
glArrayElement( indices[i] );
glEnd();
break;
case (COMPILED|DRAW_ARRAYS|TRIANGLES):
case (NOT_COMPILED|DRAW_ARRAYS|TRIANGLES):
if (state & MATERIALS) {
for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
GLuint nr = MIN(num_tri_verts-i, 600);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i );
}
} else {
glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT,
tri_indices );
}
break;
/* Uses the original arrays (including duplicate elements):
*/
case (NOT_COMPILED|DRAW_ARRAYS|STRIPS):
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
break;
/* Uses the original arrays (including duplicate elements):
*/
case (NOT_COMPILED|ARRAY_ELT|STRIPS):
glBegin( GL_TRIANGLE_STRIP );
for (i = 0 ; i < numverts ; i++)
glArrayElement( i );
glEnd();
break;
case (NOT_COMPILED|ARRAY_ELT|TRIANGLES):
case (COMPILED|ARRAY_ELT|TRIANGLES):
if (state & MATERIALS) {
for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
GLuint nr = MIN(num_tri_verts-i, 600);
GLuint k;
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
glBegin( GL_TRIANGLES );
for (k = 0 ; k < nr ; k++)
glArrayElement( tri_indices[i+k] );
glEnd();
}
} else {
glBegin( GL_TRIANGLES );
for (i = 0 ; i < num_tri_verts ; i++)
glArrayElement( tri_indices[i] );
glEnd();
}
break;
case (NOT_COMPILED|IMMEDIATE|TRIANGLES):
if (state & MATERIALS) {
for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
GLuint nr = MIN(num_tri_verts-i, 600);
GLuint k;
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
glBegin( GL_TRIANGLES );
for (k = 0 ; k < nr ; k++) {
glNormal3fv( &compressed_data[tri_indices[i+k]][3] );
glVertex3fv( &compressed_data[tri_indices[i+k]][0] );
}
glEnd();
}
} else {
glBegin( GL_TRIANGLES );
for (i = 0 ; i < num_tri_verts ; i++) {
glNormal3fv( &compressed_data[tri_indices[i]][3] );
glVertex3fv( &compressed_data[tri_indices[i]][0] );
}
glEnd();
}
break;
#endif
/* Uses the original arrays (including duplicate elements):
*/
default:
glBegin( GL_TRIANGLE_STRIP );
for (i=0;i<numverts;i++) {
glNormal3fv( &data[i][3] );
glVertex3fv( &data[i][0] );
}
glEnd();
}
}
static void Display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
draw_surface();
glFlush();
if (doubleBuffer) glutSwapBuffers();
}
/* KW: only do this when necessary, so CVA can re-use results.
*/
static void set_matrix( void )
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef( 0.0, 0.0, -6.0 );
glRotatef( yrot, 0.0, 1.0, 0.0 );
glRotatef( xrot, 1.0, 0.0, 0.0 );
}
static void Benchmark( float xdiff, float ydiff )
{
int startTime, endTime;
int draws;
double seconds, fps, triPerSecond;
printf("Benchmarking...\n");
draws = 0;
startTime = glutGet(GLUT_ELAPSED_TIME);
xrot = 0.0;
do {
xrot += xdiff;
yrot += ydiff;
set_matrix();
Display();
draws++;
endTime = glutGet(GLUT_ELAPSED_TIME);
} while (endTime - startTime < 5000); /* 5 seconds */
/* Results */
seconds = (double) (endTime - startTime) / 1000.0;
triPerSecond = (numverts - 2) * draws / seconds;
fps = draws / seconds;
printf("Result: triangles/sec: %g fps: %g\n", triPerSecond, fps);
}
static void InitMaterials(void)
{
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
static float position0[] = {0.0, 0.0, 20.0, 0.0};
static float position1[] = {0.0, 0.0, -20.0, 0.0};
static float front_mat_shininess[] = {60.0};
static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
/*
static float back_mat_shininess[] = {60.0};
static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
*/
static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
static float lmodel_twoside[] = {GL_FALSE};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glEnable(GL_LIGHT1);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse);
}
#define UPDATE(o,n,mask) (o&=~mask, o|=n&mask)
#define CHANGED(o,n,mask) ((n&mask) && \
(n&mask) != (o&mask) ? UPDATE(o,n,mask) : 0)
static void ModeMenu(int m)
{
m &= allowed;
if (!m) return;
if (m==QUIT)
exit(0);
if (CHANGED(state, m, FILTER_MASK)) {
if (m & LINEAR_FILTER) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
}
if (CHANGED(state, m, LIGHT_MASK)) {
if (m & LIT)
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
}
if (CHANGED(state, m, SHADE_MASK)) {
if (m & SHADE_SMOOTH)
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
}
if (CHANGED(state, m, TEXTURE_MASK)) {
if (m & TEXTURE)
glEnable(GL_TEXTURE_2D);
else
glDisable(GL_TEXTURE_2D);
}
if (CHANGED(state, m, REFLECT_MASK)) {
if (m & REFLECT) {
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
} else {
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
}
}
if (CHANGED(state, m, CLIP_MASK)) {
if (m & USER_CLIP) {
glEnable(GL_CLIP_PLANE0);
} else {
glDisable(GL_CLIP_PLANE0);
}
}
#ifdef GL_EXT_vertex_array
if (CHANGED(state, m, (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)))
{
if ((m & (COMPILED_MASK|PRIMITIVE_MASK)) == (NOT_COMPILED|STRIPS))
{
glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numverts, data );
glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numverts, &data[0][3]);
}
else
{
glVertexPointerEXT( 3, GL_FLOAT, sizeof(data[0]), numuniq,
compressed_data );
glNormalPointerEXT( GL_FLOAT, sizeof(data[0]), numuniq,
&compressed_data[0][3]);
}
#ifdef GL_EXT_compiled_vertex_array
if (m & COMPILED) {
glLockArraysEXT( 0, numuniq );
} else {
glUnlockArraysEXT();
}
#endif
}
#endif
if (m & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) {
UPDATE(state, m, (RENDER_STYLE_MASK|PRIMITIVE_MASK));
}
if (m & MATERIAL_MASK) {
UPDATE(state, m, MATERIAL_MASK);
}
glutPostRedisplay();
}
static void Init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable( GL_DEPTH_TEST );
glEnable( GL_VERTEX_ARRAY_EXT );
glEnable( GL_NORMAL_ARRAY_EXT );
InitMaterials();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClipPlane(GL_CLIP_PLANE0, plane);
set_matrix();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
printf("Error: couldn't load texture image\n");
exit(1);
}
if (allowed & COMPILED) {
compactify_arrays();
make_tri_indices();
}
ModeMenu(SHADE_SMOOTH|
LIT|
NO_TEXTURE|
NO_REFLECT|
POINT_FILTER|
NOT_COMPILED|
NO_USER_CLIP|
NO_MATERIALS|
IMMEDIATE);
}
static void Reshape(int width, int height)
{
glViewport(0, 0, (GLint)width, (GLint)height);
}
static void Key( unsigned char key, int x, int y )
{
switch (key) {
case 27:
exit(0);
case 's':
ModeMenu((state ^ SHADE_MASK) & SHADE_MASK);
break;
case 'l':
ModeMenu((state ^ LIGHT_MASK) & LIGHT_MASK);
break;
case 'm':
ModeMenu((state ^ MATERIAL_MASK) & MATERIAL_MASK);
break;
case 'c':
ModeMenu((state ^ CLIP_MASK) & CLIP_MASK);
break;
case 'b':
Benchmark(5.0, 0);
break;
case 'B':
Benchmark(0, 5.0);
break;
case '-':
case '_':
plane[3] += 2.0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClipPlane(GL_CLIP_PLANE0, plane);
set_matrix();
glutPostRedisplay();
break;
case '+':
case '=':
plane[3] -= 2.0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClipPlane(GL_CLIP_PLANE0, plane);
set_matrix();
glutPostRedisplay();
break;
}
}
static void SpecialKey( int key, int x, int y )
{
switch (key) {
case GLUT_KEY_LEFT:
yrot -= 15.0;
break;
case GLUT_KEY_RIGHT:
yrot += 15.0;
break;
case GLUT_KEY_UP:
xrot += 15.0;
break;
case GLUT_KEY_DOWN:
xrot -= 15.0;
break;
default:
return;
}
set_matrix();
glutPostRedisplay();
}
static GLint Args(int argc, char **argv)
{
GLint i;
GLint mode = 0;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-sb") == 0) {
doubleBuffer = GL_FALSE;
}
else if (strcmp(argv[i], "-db") == 0) {
doubleBuffer = GL_TRUE;
}
else {
printf("%s (Bad option).\n", argv[i]);
return QUIT;
}
}
return mode;
}
int main(int argc, char **argv)
{
GLenum type;
char *extensions;
GLuint arg_mode = Args(argc, argv);
if (arg_mode & QUIT)
exit(0);
read_surface( "isosurf.dat" );
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
type = GLUT_DEPTH;
type |= GLUT_RGB;
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
if (glutCreateWindow("Isosurface") <= 0) {
exit(0);
}
/* Make sure server supports the vertex array extension */
extensions = (char *) glGetString( GL_EXTENSIONS );
if (!strstr( extensions, "GL_EXT_vertex_array" ))
{
printf("Vertex arrays not supported by this renderer\n");
allowed &= ~(COMPILED|DRAW_ARRAYS|ARRAY_ELT);
}
else if (!strstr( extensions, "GL_EXT_compiled_vertex_array" ))
{
printf("Compiled vertex arrays not supported by this renderer\n");
allowed &= ~COMPILED;
}
Init();
ModeMenu(arg_mode);
glutCreateMenu(ModeMenu);
glutAddMenuEntry("Lit", LIT|NO_TEXTURE|NO_REFLECT);
glutAddMenuEntry("Unlit", UNLIT|NO_TEXTURE|NO_REFLECT);
/* glutAddMenuEntry("Textured", TEXTURE); */
glutAddMenuEntry("Reflect", TEXTURE|REFLECT);
glutAddMenuEntry("", 0);
glutAddMenuEntry("Smooth", SHADE_SMOOTH);
glutAddMenuEntry("Flat", SHADE_FLAT);
glutAddMenuEntry("", 0);
glutAddMenuEntry("Point Filtered", POINT_FILTER);
glutAddMenuEntry("Linear Filtered", LINEAR_FILTER);
glutAddMenuEntry("", 0);
glutAddMenuEntry("Immediate (STRIPS)", NOT_COMPILED|IMMEDIATE|STRIPS);
glutAddMenuEntry("Immediate (TRIANGLES)", NOT_COMPILED|IMMEDIATE|TRIANGLES);
glutAddMenuEntry("", 0);
if (allowed & DRAW_ARRAYS) {
glutAddMenuEntry("DrawArrays (STRIPS)",
NOT_COMPILED|DRAW_ARRAYS|STRIPS);
glutAddMenuEntry("ArrayElement (STRIPS)",
NOT_COMPILED|ARRAY_ELT|STRIPS);
glutAddMenuEntry("DrawElements (TRIANGLES)",
NOT_COMPILED|DRAW_ARRAYS|TRIANGLES);
glutAddMenuEntry("ArrayElement (TRIANGLES)",
NOT_COMPILED|ARRAY_ELT|TRIANGLES);
glutAddMenuEntry("", 0);
}
if (allowed & COMPILED) {
glutAddMenuEntry("Compiled DrawElements (TRIANGLES)",
COMPILED|DRAW_ARRAYS|TRIANGLES);
glutAddMenuEntry("Compiled DrawElements (STRIPS)",
COMPILED|DRAW_ARRAYS|STRIPS);
glutAddMenuEntry("Compiled ArrayElement",
COMPILED|ARRAY_ELT|STRIPS);
glutAddMenuEntry("", 0);
}
glutAddMenuEntry("Quit", QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey);
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}

7179
progs/demos/isosurf.dat Normal file

File diff suppressed because it is too large Load diff

892
progs/demos/morph3d.c Normal file
View file

@ -0,0 +1,892 @@
/* $Id: morph3d.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* $Log: morph3d.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1998/06/29 02:37:30 brianp
* minor changes for Windows (Ted Jump)
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
/*-
* morph3d.c - Shows 3D morphing objects
*
* Converted to GLUT by brianp on 1/1/98
*
* This program was inspired on a WindowsNT(R)'s screen saver. It was written
* from scratch and it was not based on any other source code.
*
* Porting it to xlock (the final objective of this code since the moment I
* decided to create it) was possible by comparing the original Mesa's gear
* demo with it's ported version, so thanks for Danny Sung for his indirect
* help (look at gear.c in xlock source tree). NOTE: At the moment this code
* was sent to Brian Paul for package inclusion, the XLock Version was not
* available. In fact, I'll wait it to appear on the next Mesa release (If you
* are reading this, it means THIS release) to send it for xlock package
* inclusion). It will probably there be a GLUT version too.
*
* Thanks goes also to Brian Paul for making it possible and inexpensive
* to use OpenGL at home.
*
* Since I'm not a native english speaker, my apologies for any gramatical
* mistake.
*
* My e-mail addresses are
*
* vianna@cat.cbpf.br
* and
* marcelo@venus.rdc.puc-rio.br
*
* Marcelo F. Vianna (Feb-13-1997)
*/
/*
This document is VERY incomplete, but tries to describe the mathematics used
in the program. At this moment it just describes how the polyhedra are
generated. On futhurer versions, this document will be probabbly improved.
Since I'm not a native english speaker, my apologies for any gramatical
mistake.
Marcelo Fernandes Vianna
- Undergraduate in Computer Engeneering at Catholic Pontifical University
- of Rio de Janeiro (PUC-Rio) Brasil.
- e-mail: vianna@cat.cbpf.br or marcelo@venus.rdc.puc-rio.br
- Feb-13-1997
POLYHEDRA GENERATION
For the purpose of this program it's not sufficient to know the polyhedra
vertexes coordinates. Since the morphing algorithm applies a nonlinear
transformation over the surfaces (faces) of the polyhedron, each face has
to be divided into smaller ones. The morphing algorithm needs to transform
each vertex of these smaller faces individually. It's a very time consoming
task.
In order to reduce calculation overload, and since all the macro faces of
the polyhedron are transformed by the same way, the generation is made by
creating only one face of the polyhedron, morphing it and then rotating it
around the polyhedron center.
What we need to know is the face radius of the polyhedron (the radius of
the inscribed sphere) and the angle between the center of two adjacent
faces using the center of the sphere as the angle's vertex.
The face radius of the regular polyhedra are known values which I decided
to not waste my time calculating. Following is a table of face radius for
the regular polyhedra with edge length = 1:
TETRAHEDRON : 1/(2*sqrt(2))/sqrt(3)
CUBE : 1/2
OCTAHEDRON : 1/sqrt(6)
DODECAHEDRON : T^2 * sqrt((T+2)/5) / 2 -> where T=(sqrt(5)+1)/2
ICOSAHEDRON : (3*sqrt(3)+sqrt(15))/12
I've not found any reference about the mentioned angles, so I needed to
calculate them, not a trivial task until I figured out how :)
Curiously these angles are the same for the tetrahedron and octahedron.
A way to obtain this value is inscribing the tetrahedron inside the cube
by matching their vertexes. So you'll notice that the remaining unmatched
vertexes are in the same straight line starting in the cube/tetrahedron
center and crossing the center of each tetrahedron's face. At this point
it's easy to obtain the bigger angle of the isosceles triangle formed by
the center of the cube and two opposite vertexes on the same cube face.
The edges of this triangle have the following lenghts: sqrt(2) for the base
and sqrt(3)/2 for the other two other edges. So the angle we want is:
+-----------------------------------------------------------+
| 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees |
+-----------------------------------------------------------+
For the cube this angle is obvious, but just for formality it can be
easily obtained because we also know it's isosceles edge lenghts:
sqrt(2)/2 for the base and 1/2 for the other two edges. So the angle we
want is:
+-----------------------------------------------------------+
| 2*ARCSIN((sqrt(2)/2)/1) = 90.000000000000000000 degrees |
+-----------------------------------------------------------+
For the octahedron we use the same idea used for the tetrahedron, but now
we inscribe the cube inside the octahedron so that all cubes's vertexes
matches excatly the center of each octahedron's face. It's now clear that
this angle is the same of the thetrahedron one:
+-----------------------------------------------------------+
| 2*ARCSIN(sqrt(2)/sqrt(3)) = 109.47122063449069174 degrees |
+-----------------------------------------------------------+
For the dodecahedron it's a little bit harder because it's only relationship
with the cube is useless to us. So we need to solve the problem by another
way. The concept of Face radius also exists on 2D polygons with the name
Edge radius:
Edge Radius For Pentagon (ERp)
ERp = (1/2)/TAN(36 degrees) * VRp = 0.6881909602355867905
(VRp is the pentagon's vertex radio).
Face Radius For Dodecahedron
FRd = T^2 * sqrt((T+2)/5) / 2 = 1.1135163644116068404
Why we need ERp? Well, ERp and FRd segments forms a 90 degrees angle,
completing this triangle, the lesser angle is a half of the angle we are
looking for, so this angle is:
+-----------------------------------------------------------+
| 2*ARCTAN(ERp/FRd) = 63.434948822922009981 degrees |
+-----------------------------------------------------------+
For the icosahedron we can use the same method used for dodecahedron (well
the method used for dodecahedron may be used for all regular polyhedra)
Edge Radius For Triangle (this one is well known: 1/3 of the triangle height)
ERt = sin(60)/3 = sqrt(3)/6 = 0.2886751345948128655
Face Radius For Icosahedron
FRi= (3*sqrt(3)+sqrt(15))/12 = 0.7557613140761707538
So the angle is:
+-----------------------------------------------------------+
| 2*ARCTAN(ERt/FRi) = 41.810314895778596167 degrees |
+-----------------------------------------------------------+
*/
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <GL/glut.h>
#include <math.h>
#include <string.h>
#define Scale 0.3
#define VectMul(X1,Y1,Z1,X2,Y2,Z2) (Y1)*(Z2)-(Z1)*(Y2),(Z1)*(X2)-(X1)*(Z2),(X1)*(Y2)-(Y1)*(X2)
#define sqr(A) ((A)*(A))
/* Increasing this values produces better image quality, the price is speed. */
/* Very low values produces erroneous/incorrect plotting */
#define tetradivisions 23
#define cubedivisions 20
#define octadivisions 21
#define dodecadivisions 10
#define icodivisions 15
#define tetraangle 109.47122063449069174
#define cubeangle 90.000000000000000000
#define octaangle 109.47122063449069174
#define dodecaangle 63.434948822922009981
#define icoangle 41.810314895778596167
#ifndef Pi
#define Pi 3.1415926535897932385
#endif
#define SQRT2 1.4142135623730951455
#define SQRT3 1.7320508075688771932
#define SQRT5 2.2360679774997898051
#define SQRT6 2.4494897427831778813
#define SQRT15 3.8729833462074170214
#define cossec36_2 0.8506508083520399322
#define cos72 0.3090169943749474241
#define sin72 0.9510565162951535721
#define cos36 0.8090169943749474241
#define sin36 0.5877852522924731292
/*************************************************************************/
static int mono=0;
static int smooth=1;
static GLint WindH, WindW;
static GLfloat step=0;
static GLfloat seno;
static int object;
static int edgedivisions;
static void (*draw_object)( void );
static float Magnitude;
static float *MaterialColor[20];
static float front_shininess[] = {60.0};
static float front_specular[] = { 0.7, 0.7, 0.7, 1.0 };
static float ambient[] = { 0.0, 0.0, 0.0, 1.0 };
static float diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
static float position0[] = { 1.0, 1.0, 1.0, 0.0 };
static float position1[] = {-1.0,-1.0, 1.0, 0.0 };
static float lmodel_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
static float lmodel_twoside[] = {GL_TRUE};
static float MaterialRed[] = { 0.7, 0.0, 0.0, 1.0 };
static float MaterialGreen[] = { 0.1, 0.5, 0.2, 1.0 };
static float MaterialBlue[] = { 0.0, 0.0, 0.7, 1.0 };
static float MaterialCyan[] = { 0.2, 0.5, 0.7, 1.0 };
static float MaterialYellow[] = { 0.7, 0.7, 0.0, 1.0 };
static float MaterialMagenta[] = { 0.6, 0.2, 0.5, 1.0 };
static float MaterialWhite[] = { 0.7, 0.7, 0.7, 1.0 };
static float MaterialGray[] = { 0.2, 0.2, 0.2, 1.0 };
#define TRIANGLE(Edge, Amp, Divisions, Z) \
{ \
GLfloat Xf,Yf,Xa,Yb,Xf2,Yf2; \
GLfloat Factor,Factor1,Factor2; \
GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \
GLfloat Ax,Ay,Bx; \
int Ri,Ti; \
GLfloat Vr=(Edge)*SQRT3/3; \
GLfloat AmpVr2=(Amp)/sqr(Vr); \
GLfloat Zf=(Edge)*(Z); \
\
Ax=(Edge)*(+0.5/(Divisions)), Ay=(Edge)*(-SQRT3/(2*Divisions)); \
Bx=(Edge)*(-0.5/(Divisions)); \
\
for (Ri=1; Ri<=(Divisions); Ri++) { \
glBegin(GL_TRIANGLE_STRIP); \
for (Ti=0; Ti<Ri; Ti++) { \
Xf=(float)(Ri-Ti)*Ax + (float)Ti*Bx; \
Yf=Vr+(float)(Ri-Ti)*Ay + (float)Ti*Ay; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
\
Xf=(float)(Ri-Ti-1)*Ax + (float)Ti*Bx; \
Yf=Vr+(float)(Ri-Ti-1)*Ay + (float)Ti*Ay; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
\
} \
Xf=(float)Ri*Bx; \
Yf=Vr+(float)Ri*Ay; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
glEnd(); \
} \
}
#define SQUARE(Edge, Amp, Divisions, Z) \
{ \
int Xi,Yi; \
GLfloat Xf,Yf,Y,Xf2,Yf2,Y2,Xa,Yb; \
GLfloat Factor,Factor1,Factor2; \
GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \
GLfloat Zf=(Edge)*(Z); \
GLfloat AmpVr2=(Amp)/sqr((Edge)*SQRT2/2); \
\
for (Yi=0; Yi<(Divisions); Yi++) { \
Yf=-((Edge)/2.0) + ((float)Yi)/(Divisions)*(Edge); \
Yf2=sqr(Yf); \
Y=Yf+1.0/(Divisions)*(Edge); \
Y2=sqr(Y); \
glBegin(GL_QUAD_STRIP); \
for (Xi=0; Xi<=(Divisions); Xi++) { \
Xf=-((Edge)/2.0) + ((float)Xi)/(Divisions)*(Edge); \
Xf2=sqr(Xf); \
\
Xa=Xf+0.001; Yb=Y+0.001; \
Factor=1-((Xf2+Y2)*AmpVr2); \
Factor1=1-((sqr(Xa)+Y2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Y; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Y-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
\
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-((Xf2+Yf2)*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
} \
glEnd(); \
} \
}
#define PENTAGON(Edge, Amp, Divisions, Z) \
{ \
int Ri,Ti,Fi; \
GLfloat Xf,Yf,Xa,Yb,Xf2,Yf2; \
GLfloat x[6],y[6]; \
GLfloat Factor,Factor1,Factor2; \
GLfloat VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ; \
GLfloat Zf=(Edge)*(Z); \
GLfloat AmpVr2=(Amp)/sqr((Edge)*cossec36_2); \
\
for(Fi=0;Fi<6;Fi++) { \
x[Fi]=-cos( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge); \
y[Fi]=sin( Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge); \
} \
\
for (Ri=1; Ri<=(Divisions); Ri++) { \
for (Fi=0; Fi<5; Fi++) { \
glBegin(GL_TRIANGLE_STRIP); \
for (Ti=0; Ti<Ri; Ti++) { \
Xf=(float)(Ri-Ti)*x[Fi] + (float)Ti*x[Fi+1]; \
Yf=(float)(Ri-Ti)*y[Fi] + (float)Ti*y[Fi+1]; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
\
Xf=(float)(Ri-Ti-1)*x[Fi] + (float)Ti*x[Fi+1]; \
Yf=(float)(Ri-Ti-1)*y[Fi] + (float)Ti*y[Fi+1]; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
\
} \
Xf=(float)Ri*x[Fi+1]; \
Yf=(float)Ri*y[Fi+1]; \
Xa=Xf+0.001; Yb=Yf+0.001; \
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2); \
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2); \
Factor2=1-((Xf2+sqr(Yb))*AmpVr2); \
VertX=Factor*Xf; VertY=Factor*Yf; VertZ=Factor*Zf; \
NeiAX=Factor1*Xa-VertX; NeiAY=Factor1*Yf-VertY; NeiAZ=Factor1*Zf-VertZ; \
NeiBX=Factor2*Xf-VertX; NeiBY=Factor2*Yb-VertY; NeiBZ=Factor2*Zf-VertZ; \
glNormal3f(VectMul(NeiAX, NeiAY, NeiAZ, NeiBX, NeiBY, NeiBZ)); \
glVertex3f(VertX, VertY, VertZ); \
glEnd(); \
} \
} \
}
static void draw_tetra( void )
{
GLuint list;
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
TRIANGLE(2,seno,edgedivisions,0.5/SQRT6);
glEndList();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-tetraangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+tetraangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+tetraangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
glCallList(list);
glDeleteLists(list,1);
}
static void draw_cube( void )
{
GLuint list;
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
SQUARE(2, seno, edgedivisions, 0.5)
glEndList();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
glCallList(list);
glRotatef(cubeangle,0,1,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
glCallList(list);
glRotatef(2*cubeangle,0,1,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
glCallList(list);
glDeleteLists(list,1);
}
static void draw_octa( void )
{
GLuint list;
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
TRIANGLE(2,seno,edgedivisions,1/SQRT6);
glEndList();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-180+octaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
glCallList(list);
glPopMatrix();
glRotatef(180,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-180+octaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
glCallList(list);
glDeleteLists(list,1);
}
static void draw_dodeca( void )
{
GLuint list;
#define TAU ((SQRT5+1)/2)
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
PENTAGON(1,seno,edgedivisions,sqr(TAU) * sqrt((TAU+2)/5) / 2);
glEndList();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
glCallList(list);
glRotatef(180,0,0,1);
glPushMatrix();
glRotatef(-dodecaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,sin72,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,-sin72,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(dodecaangle,cos36,-sin36,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
glCallList(list);
glPopMatrix();
glRotatef(dodecaangle,cos36,sin36,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
glCallList(list);
glPopMatrix();
glRotatef(180,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
glCallList(list);
glRotatef(180,0,0,1);
glPushMatrix();
glRotatef(-dodecaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,sin72,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,-sin72,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(dodecaangle,cos36,-sin36,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
glCallList(list);
glPopMatrix();
glRotatef(dodecaangle,cos36,sin36,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
glCallList(list);
glDeleteLists(list,1);
}
static void draw_ico( void )
{
GLuint list;
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
TRIANGLE(1.5,seno,edgedivisions,(3*SQRT3+SQRT15)/12);
glEndList();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
glCallList(list);
glPopMatrix();
glRotatef(180,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[12]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[13]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[14]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[15]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[16]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[17]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[18]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,0,1);
glRotatef(-icoangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[19]);
glCallList(list);
glDeleteLists(list,1);
}
static void draw ( void ) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glTranslatef( 0.0, 0.0, -10.0 );
glScalef( Scale*WindH/WindW, Scale, Scale );
glTranslatef(2.5*WindW/WindH*sin(step*1.11),2.5*cos(step*1.25*1.11),0);
glRotatef(step*100,1,0,0);
glRotatef(step*95,0,1,0);
glRotatef(step*90,0,0,1);
seno=(sin(step)+1.0/3.0)*(4.0/5.0)*Magnitude;
draw_object();
glPopMatrix();
glFlush();
glutSwapBuffers();
step+=0.05;
}
static void idle_( void )
{
glutPostRedisplay();
}
static void reshape( int width, int height )
{
glViewport(0, 0, WindW=(GLint)width, WindH=(GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
glMatrixMode(GL_MODELVIEW);
}
static void pinit(void);
static void key( unsigned char k, int x, int y )
{
switch (k) {
case '1': object=1; break;
case '2': object=2; break;
case '3': object=3; break;
case '4': object=4; break;
case '5': object=5; break;
case ' ': mono^=1; break;
case 13: smooth^=1; break;
case 27:
exit(0);
}
pinit();
}
static void pinit(void)
{
switch(object) {
case 1:
draw_object=draw_tetra;
MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialBlue;
MaterialColor[3]=MaterialWhite;
edgedivisions=tetradivisions;
Magnitude=2.5;
break;
case 2:
draw_object=draw_cube;
MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialCyan;
MaterialColor[3]=MaterialMagenta;
MaterialColor[4]=MaterialYellow;
MaterialColor[5]=MaterialBlue;
edgedivisions=cubedivisions;
Magnitude=2.0;
break;
case 3:
draw_object=draw_octa;
MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialBlue;
MaterialColor[3]=MaterialWhite;
MaterialColor[4]=MaterialCyan;
MaterialColor[5]=MaterialMagenta;
MaterialColor[6]=MaterialGray;
MaterialColor[7]=MaterialYellow;
edgedivisions=octadivisions;
Magnitude=2.5;
break;
case 4:
draw_object=draw_dodeca;
MaterialColor[ 0]=MaterialRed;
MaterialColor[ 1]=MaterialGreen;
MaterialColor[ 2]=MaterialCyan;
MaterialColor[ 3]=MaterialBlue;
MaterialColor[ 4]=MaterialMagenta;
MaterialColor[ 5]=MaterialYellow;
MaterialColor[ 6]=MaterialGreen;
MaterialColor[ 7]=MaterialCyan;
MaterialColor[ 8]=MaterialRed;
MaterialColor[ 9]=MaterialMagenta;
MaterialColor[10]=MaterialBlue;
MaterialColor[11]=MaterialYellow;
edgedivisions=dodecadivisions;
Magnitude=2.0;
break;
case 5:
draw_object=draw_ico;
MaterialColor[ 0]=MaterialRed;
MaterialColor[ 1]=MaterialGreen;
MaterialColor[ 2]=MaterialBlue;
MaterialColor[ 3]=MaterialCyan;
MaterialColor[ 4]=MaterialYellow;
MaterialColor[ 5]=MaterialMagenta;
MaterialColor[ 6]=MaterialRed;
MaterialColor[ 7]=MaterialGreen;
MaterialColor[ 8]=MaterialBlue;
MaterialColor[ 9]=MaterialWhite;
MaterialColor[10]=MaterialCyan;
MaterialColor[11]=MaterialYellow;
MaterialColor[12]=MaterialMagenta;
MaterialColor[13]=MaterialRed;
MaterialColor[14]=MaterialGreen;
MaterialColor[15]=MaterialBlue;
MaterialColor[16]=MaterialCyan;
MaterialColor[17]=MaterialYellow;
MaterialColor[18]=MaterialMagenta;
MaterialColor[19]=MaterialGray;
edgedivisions=icodivisions;
Magnitude=2.5;
break;
}
if (mono) {
int loop;
for (loop=0; loop<20; loop++) MaterialColor[loop]=MaterialGray;
}
if (smooth) {
glShadeModel( GL_SMOOTH );
} else {
glShadeModel( GL_FLAT );
}
}
void INIT(void)
{
printf("Morph 3D - Shows morphing platonic polyhedra\n");
printf("Author: Marcelo Fernandes Vianna (vianna@cat.cbpf.br)\n\n");
printf(" [1] - Tetrahedron\n");
printf(" [2] - Hexahedron (Cube)\n");
printf(" [3] - Octahedron\n");
printf(" [4] - Dodecahedron\n");
printf(" [5] - Icosahedron\n");
printf("[SPACE] - Toggle colored faces\n");
printf("[RETURN] - Toggle smooth/flat shading\n");
printf(" [ESC] - Quit\n");
object=1;
glutInitWindowPosition(0,0);
glutInitWindowSize(640,480);
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB );
if (glutCreateWindow("Morph 3D - Shows morphing platonic polyhedra") <= 0) {
exit(0);
}
glClearDepth(1.0);
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glColor3f( 1.0, 1.0, 1.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glFlush();
glutSwapBuffers();
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
glHint(GL_FOG_HINT, GL_FASTEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
pinit();
glutReshapeFunc( reshape );
glutKeyboardFunc( key );
glutIdleFunc( idle_ );
glutDisplayFunc( draw );
glutMainLoop();
}
int main(int argc, char **argv)
{
INIT();
return(0);
}

307
progs/demos/multiarb.c Normal file
View file

@ -0,0 +1,307 @@
/* $Id: multiarb.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* GL_ARB_multitexture demo
* Brian Paul November 1998 This program is in the public domain.
*/
/*
* $Log: multiarb.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 1.3 1999/03/28 18:20:49 brianp
* minor clean-up
*
* Revision 1.2 1998/11/05 04:34:04 brianp
* moved image files to ../images/ directory
*
* Revision 1.1 1998/11/03 01:36:33 brianp
* Initial revision
*
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
#include "../util/readtex.c" /* I know, this is a hack. */
#define TEXTURE_1_FILE "../images/girl.rgb"
#define TEXTURE_2_FILE "../images/reflect.rgb"
#define TEX0 1
#define TEX1 2
#define TEXBOTH 3
#define ANIMATE 10
#define QUIT 100
static GLboolean Animate = GL_TRUE;
static GLfloat Drift = 0.0;
static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0;
static void Idle( void )
{
if (Animate) {
Drift += 0.05;
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE0_ARB);
#endif
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(Drift, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE1_ARB);
#endif
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.0, Drift, 0.0);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
}
static void DrawObject(void)
{
glBegin(GL_QUADS);
#ifdef GL_ARB_multitexture
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex2f(-1.0, -1.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glVertex2f(1.0, -1.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2.0, 2.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glVertex2f(1.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 2.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glVertex2f(-1.0, 1.0);
#else
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0, 1.0);
#endif
glEnd();
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glRotatef(Xrot, 1.0, 0.0, 0.0);
glRotatef(Yrot, 0.0, 1.0, 0.0);
glRotatef(Zrot, 0.0, 0.0, 1.0);
glScalef(5.0, 5.0, 5.0);
DrawObject();
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
/*glOrtho( -6.0, 6.0, -6.0, 6.0, 10.0, 100.0 );*/
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -70.0 );
}
static void ModeMenu(int entry)
{
GLboolean enable0 = GL_FALSE, enable1 = GL_FALSE;
if (entry==TEX0) {
enable0 = GL_TRUE;
}
else if (entry==TEX1) {
enable1 = GL_TRUE;
}
else if (entry==TEXBOTH) {
enable0 = GL_TRUE;
enable1 = GL_TRUE;
}
else if (entry==ANIMATE) {
Animate = !Animate;
}
else if (entry==QUIT) {
exit(0);
}
if (entry != ANIMATE) {
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE0_ARB);
#endif
if (enable0) {
glEnable(GL_TEXTURE_2D);
}
else
glDisable(GL_TEXTURE_2D);
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE1_ARB);
#endif
if (enable1) {
glEnable(GL_TEXTURE_2D);
}
else
glDisable(GL_TEXTURE_2D);
}
glutPostRedisplay();
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
float step = 3.0;
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
Xrot += step;
break;
case GLUT_KEY_DOWN:
Xrot -= step;
break;
case GLUT_KEY_LEFT:
Yrot += step;
break;
case GLUT_KEY_RIGHT:
Yrot -= step;
break;
}
glutPostRedisplay();
}
static void Init( void )
{
const char *exten = (const char *) glGetString(GL_EXTENSIONS);
if (!strstr(exten, "GL_ARB_multitexture")) {
printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n");
exit(1);
}
/* setup texture env 0 */
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE0_ARB);
#endif
#ifdef LINEAR_FILTER
/* linear filtering looks much nicer but is much slower for Mesa */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
#endif
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) {
printf("Error: couldn't load texture image\n");
exit(1);
}
/* setup texture env 1 */
#ifdef GL_ARB_multitexture
glActiveTextureARB(GL_TEXTURE1_ARB);
#endif
#ifdef LINEAR_FILTER
/* linear filtering looks much nicer but is much slower for Mesa */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
#endif
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) {
printf("Error: couldn't load texture image\n");
exit(1);
}
glShadeModel(GL_FLAT);
glClearColor(0.3, 0.3, 0.4, 1.0);
ModeMenu(TEXBOTH);
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowSize( 300, 300 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0] );
Init();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutCreateMenu(ModeMenu);
glutAddMenuEntry("Texture 0", TEX0);
glutAddMenuEntry("Texture 1", TEX1);
glutAddMenuEntry("Multi-texture", TEXBOTH);
glutAddMenuEntry("Toggle Animation", ANIMATE);
glutAddMenuEntry("Quit", QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

169
progs/demos/osdemo.c Normal file
View file

@ -0,0 +1,169 @@
/* $Id: osdemo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Demo of off-screen Mesa rendering
*
* See Mesa/include/GL/osmesa.h for documentation of the OSMesa functions.
*
* If you want to render BIG images you'll probably have to increase
* MAX_WIDTH and MAX_HEIGHT in src/config.h.
*
* This program is in the public domain.
*
* Brian Paul
*
* PPM output provided by Joerg Schmalzl.
* ASCII PPM output added by Brian Paul.
*/
/*
* $Log: osdemo.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "GL/osmesa.h"
#include "GL/glut.h"
#define WIDTH 400
#define HEIGHT 400
static void render_image( void )
{
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat red_mat[] = { 1.0, 0.2, 0.2, 1.0 };
GLfloat green_mat[] = { 0.2, 1.0, 0.2, 1.0 };
GLfloat blue_mat[] = { 0.2, 0.2, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.5, 2.5, -2.5, 2.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef(20.0, 1.0, 0.0, 0.0);
glPushMatrix();
glTranslatef(-0.75, 0.5, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
glutSolidTorus(0.275, 0.85, 20, 20);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75, -0.5, 0.0);
glRotatef(270.0, 1.0, 0.0, 0.0);
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
glutSolidCone(1.0, 2.0, 16, 1);
glPopMatrix();
glPushMatrix();
glTranslatef(0.75, 0.0, -1.0);
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
glutSolidSphere(1.0, 20, 20);
glPopMatrix();
glPopMatrix();
}
int main( int argc, char *argv[] )
{
OSMesaContext ctx;
void *buffer;
/* Create an RGBA-mode context */
ctx = OSMesaCreateContext( GL_RGBA, NULL );
/* Allocate the image buffer */
buffer = malloc( WIDTH * HEIGHT * 4 );
/* Bind the buffer to the context and make it current */
OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, WIDTH, HEIGHT );
render_image();
if (argc>1) {
/* write PPM file */
FILE *f = fopen( argv[1], "w" );
if (f) {
int i, x, y;
GLubyte *ptr = (GLubyte *) buffer;
#define BINARY 0
#if BINARY
fprintf(f,"P6\n");
fprintf(f,"# ppm-file created by %s\n", argv[0]);
fprintf(f,"%i %i\n", WIDTH,HEIGHT);
fprintf(f,"255\n");
fclose(f);
f = fopen( argv[1], "ab" ); /* reopen in binary append mode */
for (y=HEIGHT-1; y>=0; y--) {
for (x=0; x<WIDTH; x++) {
i = (y*WIDTH + x) * 4;
fputc(ptr[i], f); /* write red */
fputc(ptr[i+1], f); /* write green */
fputc(ptr[i+2], f); /* write blue */
}
}
#else /*ASCII*/
int counter = 0;
fprintf(f,"P3\n");
fprintf(f,"# ascii ppm file created by %s\n", argv[0]);
fprintf(f,"%i %i\n", WIDTH, HEIGHT);
fprintf(f,"255\n");
for (y=HEIGHT-1; y>=0; y--) {
for (x=0; x<WIDTH; x++) {
i = (y*WIDTH + x) * 4;
fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]);
counter++;
if (counter % 5 == 0)
fprintf(f, "\n");
}
}
#endif
fclose(f);
}
}
else {
printf("Specify a filename if you want to make a ppm file\n");
}
printf("all done\n");
/* free the image buffer */
free( buffer );
/* destroy the context */
OSMesaDestroyContext( ctx );
return 0;
}

186
progs/demos/paltex.c Normal file
View file

@ -0,0 +1,186 @@
/* $Id: paltex.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Paletted texture demo. Written by Brian Paul. This file in public domain.
*/
/*
* $Log: paltex.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1999/03/28 18:20:49 brianp
* minor clean-up
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
static float Rot = 0.0;
static void Idle( void )
{
Rot += 5.0;
glutPostRedisplay();
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glRotatef(Rot, 0, 0, 1);
glBegin(GL_POLYGON);
glTexCoord2f(0, 1); glVertex2f(-1, -1);
glTexCoord2f(1, 1); glVertex2f( 1, -1);
glTexCoord2f(1, 0); glVertex2f( 1, 1);
glTexCoord2f(0, 0); glVertex2f(-1, 1);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
case GLUT_KEY_LEFT:
break;
case GLUT_KEY_RIGHT:
break;
}
glutPostRedisplay();
}
static void Init( void )
{
GLubyte texture[8][8] = { /* PT = Paletted Texture! */
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 100, 100, 100, 0, 180, 180, 180},
{ 0, 100, 0, 100, 0, 0, 180, 0},
{ 0, 100, 0, 100, 0, 0, 180, 0},
{ 0, 100, 100, 100, 0, 0, 180, 0},
{ 0, 100, 0, 0, 0, 0, 180, 0},
{ 0, 100, 0, 0, 0, 0, 180, 0},
{ 0, 100, 255, 0, 0, 0, 180, 250},
};
GLubyte table[256][4];
int i;
if (!glutExtensionSupported("GL_EXT_paletted_texture")) {
printf("Sorry, GL_EXT_paletted_texture not supported\n");
exit(0);
}
/* put some wacky colors into the texture palette */
for (i=0;i<256;i++) {
table[i][0] = i;
table[i][1] = 0;
table[i][2] = 127 + i / 2;
table[i][3] = 255;
}
#ifdef GL_EXT_paletted_texture
#if defined(GL_EXT_shared_texture_palette) && defined(SHARED_PALETTE)
printf("Using shared palette\n");
glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, /* target */
GL_RGBA, /* internal format */
256, /* table size */
GL_RGBA, /* table format */
GL_UNSIGNED_BYTE, /* table type */
table); /* the color table */
glEnable(GL_SHARED_TEXTURE_PALETTE_EXT);
#else
glColorTableEXT(GL_TEXTURE_2D, /* target */
GL_RGBA, /* internal format */
256, /* table size */
GL_RGBA, /* table format */
GL_UNSIGNED_BYTE, /* table type */
table); /* the color table */
#endif
glTexImage2D(GL_TEXTURE_2D, /* target */
0, /* level */
GL_COLOR_INDEX8_EXT, /* internal format */
8, 8, /* width, height */
0, /* border */
GL_COLOR_INDEX, /* texture format */
GL_UNSIGNED_BYTE, /* texture type */
texture); /* teh texture */
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 400, 400 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0]);
Init();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutMainLoop();
return 0;
}

506
progs/demos/pointblast.c Normal file
View file

@ -0,0 +1,506 @@
/* Copyright (c) Mark J. Kilgard, 1997. */
/* This program is freely distributable without licensing fees
and is provided without guarantee or warrantee expressed or
implied. This program is -not- in the public domain. */
/* This example demonstrates how to render particle effects
with OpenGL. A cloud of pinkish/orange particles explodes with the
particles bouncing off the ground. When the EXT_point_parameters
is present , the particle size is attenuated based on eye distance. */
/*
* $Log: pointblast.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1998/07/26 01:24:27 brianp
* removed include of gl.h
*
* Revision 3.2 1998/02/14 18:51:46 brianp
* fixed a small compiler warning
*
* Revision 3.1 1998/02/14 18:45:25 brianp
* optimized to use flat shading, don't blend ground polygon
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* for cos(), sin(), and sqrt() */
#include <GL/glut.h>
/* Some <math.h> files do not define M_PI... */
#ifndef M_PI
#define M_PI 3.14159265
#endif
#if 0 /* For debugging. */
#undef GL_EXT_point_parameters
#endif
static GLfloat angle = -150; /* in degrees */
static int spin = 0;
static int moving, begin;
static int newModel = 1;
static float theTime;
static int repeat = 1;
static int blend = 1;
int useMipmaps = 1;
int linearFiltering = 1;
static GLfloat constant[3] = { 1/5.0, 0.0, 0.0 };
static GLfloat linear[3] = { 0.0, 1/5.0, 0.0 };
static GLfloat theQuad[3] = { 0.25, 0.0, 1/60.0 };
#define MAX_POINTS 2000
static int numPoints = 200;
static GLfloat pointList[MAX_POINTS][3];
static GLfloat pointTime[MAX_POINTS];
static GLfloat pointVelocity[MAX_POINTS][2];
static GLfloat pointDirection[MAX_POINTS][2];
static int colorList[MAX_POINTS];
static int animate = 1, motion = 0;
static GLfloat colorSet[][4] = {
/* Shades of red. */
{ 0.7, 0.2, 0.4, 0.5 },
{ 0.8, 0.0, 0.7, 0.5 },
{ 1.0, 0.0, 0.0, 0.5 },
{ 0.9, 0.3, 0.6, 0.5 },
{ 1.0, 0.4, 0.0, 0.5 },
{ 1.0, 0.0, 0.5, 0.5 },
};
#define NUM_COLORS (sizeof(colorSet)/sizeof(colorSet[0]))
#define DEAD (NUM_COLORS+1)
#if 0 /* drand48 might be better on Unix machines */
#define RANDOM_RANGE(lo, hi) ((lo) + (hi - lo) * drand48())
#else
static float float_rand(void) { return rand() / (float) RAND_MAX; }
#define RANDOM_RANGE(lo, hi) ((lo) + (hi - lo) * float_rand())
#endif
#define MEAN_VELOCITY 3.0
#define GRAVITY 2.0
#define TIME_DELTA 0.025 /* The speed of time. */
/* Modeling units of ground extent in each X and Z direction. */
#define EDGE 12
void
makePointList(void)
{
float angle, velocity, direction;
int i;
motion = 1;
for (i=0; i<numPoints; i++) {
pointList[i][0] = 0.0;
pointList[i][1] = 0.0;
pointList[i][2] = 0.0;
pointTime[i] = 0.0;
angle = (RANDOM_RANGE(60.0, 70.0)) * M_PI/180.0;
direction = RANDOM_RANGE(0.0, 360.0) * M_PI/180.0;
pointDirection[i][0] = cos(direction);
pointDirection[i][1] = sin(direction);
velocity = MEAN_VELOCITY + RANDOM_RANGE(-0.8, 1.0);
pointVelocity[i][0] = velocity * cos(angle);
pointVelocity[i][1] = velocity * sin(angle);
colorList[i] = rand() % NUM_COLORS;
}
theTime = 0.0;
}
void
updatePointList(void)
{
float distance;
int i;
motion = 0;
for (i=0; i<numPoints; i++) {
distance = pointVelocity[i][0] * theTime;
/* X and Z */
pointList[i][0] = pointDirection[i][0] * distance;
pointList[i][2] = pointDirection[i][1] * distance;
/* Z */
pointList[i][1] =
(pointVelocity[i][1] - 0.5 * GRAVITY * pointTime[i])*pointTime[i];
/* If we hit the ground, bounce the point upward again. */
if (pointList[i][1] <= 0.0) {
if (distance > EDGE) {
/* Particle has hit ground past the distance duration of
the particles. Mark particle as dead. */
colorList[i] = NUM_COLORS; /* Not moving. */
continue;
}
pointVelocity[i][1] *= 0.8; /* 80% of previous up velocity. */
pointTime[i] = 0.0; /* Reset the particles sense of up time. */
}
motion = 1;
pointTime[i] += TIME_DELTA;
}
theTime += TIME_DELTA;
if (!motion && !spin) {
if (repeat) {
makePointList();
} else {
glutIdleFunc(NULL);
}
}
}
void
idle(void)
{
updatePointList();
if (spin) {
angle += 0.3;
newModel = 1;
}
glutPostRedisplay();
}
void
visible(int vis)
{
if (vis == GLUT_VISIBLE) {
if (animate && (motion || spin)) {
glutIdleFunc(idle);
}
} else {
glutIdleFunc(NULL);
}
}
void
recalcModelView(void)
{
glPopMatrix();
glPushMatrix();
glRotatef(angle, 0.0, 1.0, 0.0);
newModel = 0;
}
void
redraw(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (newModel)
recalcModelView();
glDepthMask(GL_FALSE);
/* Draw the floor. */
/* glEnable(GL_TEXTURE_2D);*/
glColor3f(0.5, 1.0, 0.5);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-EDGE, -0.05, -EDGE);
glTexCoord2f(20.0, 0.0);
glVertex3f(EDGE, -0.05, -EDGE);
glTexCoord2f(20.0, 20.0);
glVertex3f(EDGE, -0.05, EDGE);
glTexCoord2f(0.0, 20.0);
glVertex3f(-EDGE, -0.05, EDGE);
glEnd();
/* Allow particles to blend with each other. */
glDepthMask(GL_TRUE);
if (blend)
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBegin(GL_POINTS);
for (i=0; i<numPoints; i++) {
/* Draw alive particles. */
if (colorList[i] != DEAD) {
glColor4fv(colorSet[colorList[i]]);
glVertex3fv(pointList[i]);
}
}
glEnd();
glDisable(GL_BLEND);
glutSwapBuffers();
}
/* ARGSUSED2 */
void
mouse(int button, int state, int x, int y)
{
/* Scene can be spun around Y axis using left
mouse button movement. */
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
moving = 1;
begin = x;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
moving = 0;
}
}
/* ARGSUSED1 */
void
mouseMotion(int x, int y)
{
if (moving) {
angle = angle + (x - begin);
begin = x;
newModel = 1;
glutPostRedisplay();
}
}
void
menu(int option)
{
switch (option) {
case 0:
makePointList();
break;
#if GL_EXT_point_parameters
case 1:
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, constant);
break;
case 2:
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, linear);
break;
case 3:
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, theQuad);
break;
#endif
case 4:
blend = 1;
break;
case 5:
blend = 0;
break;
#if GL_EXT_point_parameters
case 6:
glPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0);
break;
case 7:
glPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 10.0);
break;
#endif
case 8:
glEnable(GL_POINT_SMOOTH);
break;
case 9:
glDisable(GL_POINT_SMOOTH);
break;
case 10:
glPointSize(2.0);
break;
case 11:
glPointSize(4.0);
break;
case 12:
glPointSize(8.0);
break;
case 13:
spin = 1 - spin;
if (animate && (spin || motion)) {
glutIdleFunc(idle);
} else {
glutIdleFunc(NULL);
}
break;
case 14:
numPoints = 200;
break;
case 15:
numPoints = 500;
break;
case 16:
numPoints = 1000;
break;
case 17:
numPoints = 2000;
break;
case 666:
exit(0);
}
glutPostRedisplay();
}
/* ARGSUSED1 */
void
key(unsigned char c, int x, int y)
{
switch (c) {
case 13:
animate = 1 - animate; /* toggle. */
if (animate && (motion || spin)) {
glutIdleFunc(idle);
} else {
glutIdleFunc(NULL);
}
break;
case ' ':
animate = 1;
makePointList();
glutIdleFunc(idle);
break;
case 27:
exit(0);
}
}
/* Nice floor texture tiling pattern. */
static char *circles[] = {
"....xxxx........",
"..xxxxxxxx......",
".xxxxxxxxxx.....",
".xxx....xxx.....",
"xxx......xxx....",
"xxx......xxx....",
"xxx......xxx....",
"xxx......xxx....",
".xxx....xxx.....",
".xxxxxxxxxx.....",
"..xxxxxxxx......",
"....xxxx........",
"................",
"................",
"................",
"................",
};
static void
makeFloorTexture(void)
{
GLubyte floorTexture[16][16][3];
GLubyte *loc;
int s, t;
/* Setup RGB image for the texture. */
loc = (GLubyte*) floorTexture;
for (t = 0; t < 16; t++) {
for (s = 0; s < 16; s++) {
if (circles[t][s] == 'x') {
/* Nice blue. */
loc[0] = 0x1f;
loc[1] = 0x1f;
loc[2] = 0x8f;
} else {
/* Light gray. */
loc[0] = 0xca;
loc[1] = 0xca;
loc[2] = 0xca;
}
loc += 3;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (useMipmaps) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16,
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
} else {
if (linearFiltering) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
}
}
int
main(int argc, char **argv)
{
int i;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
for (i=1; i<argc; i++) {
if(!strcmp("-noms", argv[i])) {
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
printf("forcing no multisampling\n");
} else if(!strcmp("-nomipmaps", argv[i])) {
useMipmaps = 0;
} else if(!strcmp("-nearest", argv[i])) {
linearFiltering = 0;
}
}
glutCreateWindow("point burst");
glutDisplayFunc(redraw);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutVisibilityFunc(visible);
glutKeyboardFunc(key);
glutCreateMenu(menu);
glutAddMenuEntry("Reset time", 0);
glutAddMenuEntry("Constant", 1);
glutAddMenuEntry("Linear", 2);
glutAddMenuEntry("Quadratic", 3);
glutAddMenuEntry("Blend on", 4);
glutAddMenuEntry("Blend off", 5);
glutAddMenuEntry("Threshold 1", 6);
glutAddMenuEntry("Threshold 10", 7);
glutAddMenuEntry("Point smooth on", 8);
glutAddMenuEntry("Point smooth off", 9);
glutAddMenuEntry("Point size 2", 10);
glutAddMenuEntry("Point size 4", 11);
glutAddMenuEntry("Point size 8", 12);
glutAddMenuEntry("Toggle spin", 13);
glutAddMenuEntry("200 points ", 14);
glutAddMenuEntry("500 points ", 15);
glutAddMenuEntry("1000 points ", 16);
glutAddMenuEntry("2000 points ", 17);
glutAddMenuEntry("Quit", 666);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_POINT_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPointSize(8.0);
#if GL_EXT_point_parameters
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, theQuad);
#endif
glMatrixMode(GL_PROJECTION);
gluPerspective( /* field of view in degree */ 40.0,
/* aspect ratio */ 1.0,
/* Z near */ 0.5, /* Z far */ 40.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 1.0, 8.0, /* eye location */
0.0, 1.0, 0.0, /* center is at (0,0,0) */
0.0, 1.0, 0.); /* up is in postivie Y direction */
glPushMatrix(); /* dummy push so we can pop on model
recalc */
makePointList();
makeFloorTexture();
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

435
progs/demos/reflect.c Normal file
View file

@ -0,0 +1,435 @@
/* $Id: reflect.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Demo of a reflective, texture-mapped surface with OpenGL.
* Brian Paul August 14, 1995 This file is in the public domain.
*
* Hardware texture mapping is highly recommended!
*
* The basic steps are:
* 1. Render the reflective object (a polygon) from the normal viewpoint,
* setting the stencil planes = 1.
* 2. Render the scene from a special viewpoint: the viewpoint which
* is on the opposite side of the reflective plane. Only draw where
* stencil = 1. This draws the objects in the reflective surface.
* 3. Render the scene from the original viewpoint. This draws the
* objects in the normal fashion. Use blending when drawing
* the reflective, textured surface.
*
* This is a very crude demo. It could be much better.
*/
/*
* Dirk Reiners (reiners@igd.fhg.de) made some modifications to this code.
*
* August 1996 - A few optimizations by Brian
*/
/*
* April, 1997 - Added Mark Kilgard's changes.
*/
/*
* $Log: reflect.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.4 1999/03/28 18:22:05 brianp
* minor clean-up
*
* Revision 3.3 1998/11/22 02:54:29 brianp
* only draw one stack for gluCylinders
*
* Revision 3.2 1998/11/19 02:53:48 brianp
* changed texture image and background color
*
* Revision 3.1 1998/11/05 04:34:04 brianp
* moved image files to ../images/ directory
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#define USE_ZBUFFER
/* OK, without hardware support this is overkill. */
#define USE_TEXTURE
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "GL/glut.h"
#include "../util/readtex.c" /* a hack, I know */
#define DEG2RAD (3.14159/180.0)
#define TABLE_TEXTURE "../images/tile.rgb"
static int ImgWidth, ImgHeight;
static GLenum ImgFormat;
static GLubyte *Image = NULL;
#define MAX_OBJECTS 2
static GLint table_list;
static GLint objects_list[MAX_OBJECTS];
static GLfloat xrot, yrot;
static GLfloat spin;
static void make_table( void )
{
static GLfloat table_mat[] = { 1.0, 1.0, 1.0, 0.6 };
static GLfloat gray[] = { 0.4, 0.4, 0.4, 1.0 };
table_list = glGenLists(1);
glNewList( table_list, GL_COMPILE );
/* load table's texture */
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, table_mat );
/* glMaterialfv( GL_FRONT, GL_EMISSION, gray );*/
glMaterialfv( GL_FRONT, GL_DIFFUSE, table_mat );
glMaterialfv( GL_FRONT, GL_AMBIENT, gray );
/* draw textured square for the table */
glPushMatrix();
glScalef( 4.0, 4.0, 4.0 );
glBegin( GL_POLYGON );
glNormal3f( 0.0, 1.0, 0.0 );
glTexCoord2f( 0.0, 0.0 ); glVertex3f( -1.0, 0.0, 1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( 1.0, 0.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( 1.0, 0.0, -1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -1.0, 0.0, -1.0 );
glEnd();
glPopMatrix();
glDisable( GL_TEXTURE_2D );
glEndList();
}
static void make_objects( void )
{
GLUquadricObj *q;
static GLfloat cyan[] = { 0.0, 1.0, 1.0, 1.0 };
static GLfloat green[] = { 0.2, 1.0, 0.2, 1.0 };
static GLfloat black[] = { 0.0, 0.0, 0.0, 0.0 };
q = gluNewQuadric();
gluQuadricDrawStyle( q, GLU_FILL );
gluQuadricNormals( q, GLU_SMOOTH );
objects_list[0] = glGenLists(1);
glNewList( objects_list[0], GL_COMPILE );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 0.5, 0.5, 1.0, 15, 1 );
glEndList();
objects_list[1] = glGenLists(1);
glNewList( objects_list[1], GL_COMPILE );
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
glMaterialfv( GL_FRONT, GL_EMISSION, black );
gluCylinder( q, 1.5, 0.0, 2.5, 15, 1 );
glEndList();
}
static GLfloat light_pos[] = { 0.0, 20.0, 0.0, 1.0 };
static void init( void )
{
make_table();
make_objects();
/* Setup texture */
#ifdef USE_TEXTURE
Image = LoadRGBImage( TABLE_TEXTURE, &ImgWidth, &ImgHeight, &ImgFormat );
if (!Image) {
printf("Couldn't read %s\n", TABLE_TEXTURE);
exit(0);
}
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ImgWidth, ImgHeight,
ImgFormat, GL_UNSIGNED_BYTE, Image);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
#endif
xrot = 30.0;
yrot = 50.0;
spin = 0.0;
#ifndef USE_ZBUFFER
glEnable( GL_CULL_FACE );
#endif
glShadeModel( GL_FLAT );
glEnable( GL_LIGHT0 );
glEnable( GL_LIGHTING );
glClearColor( 0.5, 0.5, 0.9, 1.0 );
glEnable( GL_NORMALIZE );
}
static void reshape(int w, int h)
{
GLfloat aspect = (float) w / (float) h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -aspect, aspect, -1.0, 1.0, 4.0, 300.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
static void draw_objects( GLfloat eyex, GLfloat eyey, GLfloat eyez )
{
(void) eyex;
(void) eyey;
(void) eyez;
#ifndef USE_ZBUFFER
if (eyex<0.5)
{
#endif
glPushMatrix();
glTranslatef( 1.0, 1.5, 0.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glCallList( objects_list[0] );
glPopMatrix();
glPushMatrix();
glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*spin) ), 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glScalef( 0.5, 0.5, 0.5 );
glCallList( objects_list[1] );
glPopMatrix();
#ifndef USE_ZBUFFER
}
else
{
glPushMatrix();
glTranslatef( -1.0, 0.85+3.0*fabs( cos(0.01*spin) ), 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glScalef( 0.5, 0.5, 0.5 );
glCallList( objects_list[1] );
glPopMatrix();
glPushMatrix();
glTranslatef( 1.0, 1.5, 0.0 );
glRotatef( spin, 1.0, 0.5, 0.0 );
glRotatef( 0.5*spin, 0.0, 0.5, 1.0 );
glCallList( objects_list[0] );
glPopMatrix();
}
#endif
}
static void draw_table( void )
{
glCallList( table_list );
}
static void draw_scene( void )
{
GLfloat dist = 20.0;
GLfloat eyex, eyey, eyez;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
eyex = dist * cos(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyez = dist * sin(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyey = dist * sin(xrot*DEG2RAD);
/* view from top */
glPushMatrix();
gluLookAt( eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
glLightfv( GL_LIGHT0, GL_POSITION, light_pos );
/* draw table into stencil planes */
glEnable( GL_STENCIL_TEST );
#ifdef USE_ZBUFFER
glDisable( GL_DEPTH_TEST );
#endif
glStencilFunc( GL_ALWAYS, 1, 0xffffffff );
glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
draw_table();
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
#ifdef USE_ZBUFFER
glEnable( GL_DEPTH_TEST );
#endif
/* render view from below (reflected viewport) */
/* only draw where stencil==1 */
if (eyey>0.0) {
glPushMatrix();
glStencilFunc( GL_EQUAL, 1, 0xffffffff ); /* draw if ==1 */
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
glScalef( 1.0, -1.0, 1.0 );
/* Reposition light in reflected space. */
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
draw_objects(eyex, eyey, eyez);
glPopMatrix();
/* Restore light's original unreflected position. */
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
}
glDisable( GL_STENCIL_TEST );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
#ifdef USE_TEXTURE
glEnable( GL_TEXTURE_2D );
#endif
draw_table();
glDisable( GL_TEXTURE_2D );
glDisable( GL_BLEND );
/* view from top */
glPushMatrix();
draw_objects(eyex, eyey, eyez);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
#if 0
void draw_scene(void)
{
GLfloat dist = 20.0;
GLfloat eyex, eyey, eyez;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
eyex = dist * cos(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyez = dist * sin(yrot*DEG2RAD) * cos(xrot*DEG2RAD);
eyey = dist * sin(xrot*DEG2RAD);
/* view from top */
glPushMatrix();
gluLookAt( eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
draw_table();
glPopMatrix();
glutSwapBuffers();
}
#endif
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
if (key==27)
exit(0);
}
static void SpecialKey( int key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
xrot += 3.0;
#ifndef USE_ZBUFFER
if ( xrot > 180 ) xrot = 180;
#endif
break;
case GLUT_KEY_DOWN:
xrot -= 3.0;
#ifndef USE_ZBUFFER
if ( xrot < 0 ) xrot = 0;
#endif
break;
case GLUT_KEY_LEFT:
yrot += 3.0;
break;
case GLUT_KEY_RIGHT:
yrot -= 3.0;
break;
}
glutPostRedisplay();
}
static void idle( void )
{
spin += 2.0;
yrot += 3.0;
glutPostRedisplay();
}
int main( int argc, char *argv[] )
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB
#ifdef USE_ZBUFFER
| GLUT_DEPTH
#endif
| GLUT_STENCIL);
glutInitWindowPosition( 0, 0 );
glutInitWindowSize(400, 300 );
glutCreateWindow(argv[0]);
glutReshapeFunc(reshape);
glutDisplayFunc(draw_scene);
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey);
glutIdleFunc(idle);
init();
glutMainLoop();
return 0;
}

123
progs/demos/renormal.c Normal file
View file

@ -0,0 +1,123 @@
/* $Id: renormal.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Test GL_EXT_rescale_normal extension
* Brian Paul January 1998 This program is in the public domain.
*/
/*
* $Id: renormal.c,v 1.1 1999/08/19 00:55:40 jtg Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
static GLfloat Phi = 0.0;
static void Idle(void)
{
Phi += 0.1;
glutPostRedisplay();
}
static void Display( void )
{
GLfloat scale = 0.6 + 0.5 * sin(Phi);
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glScalef(scale, scale, scale);
glutSolidSphere(2.0, 20, 20);
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}
static void Init( void )
{
static GLfloat mat[4] = { 0.8, 0.8, 0.0, 1.0 };
static GLfloat pos[4] = { -1.0, 1.0, 1.0, 0.0 };
/* setup lighting, etc */
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glDisable(GL_RESCALE_NORMAL_EXT);
glDisable(GL_NORMALIZE);
}
#define UNSCALED 1
#define NORMALIZE 2
#define RESCALE 3
#define QUIT 4
static void ModeMenu(int entry)
{
if (entry==UNSCALED) {
glDisable(GL_RESCALE_NORMAL_EXT);
glDisable(GL_NORMALIZE);
}
else if (entry==NORMALIZE) {
glEnable(GL_NORMALIZE);
glDisable(GL_RESCALE_NORMAL_EXT);
}
else if (entry==RESCALE) {
glDisable(GL_NORMALIZE);
glEnable(GL_RESCALE_NORMAL_EXT);
}
else if (entry==QUIT) {
exit(0);
}
glutPostRedisplay();
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowSize( 400, 400 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0]);
Init();
glutIdleFunc( Idle );
glutReshapeFunc( Reshape );
glutDisplayFunc( Display );
glutCreateMenu(ModeMenu);
glutAddMenuEntry("Unscaled", UNSCALED);
glutAddMenuEntry("Normalize", NORMALIZE);
glutAddMenuEntry("Rescale EXT", RESCALE);
glutAddMenuEntry("Quit", QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

277
progs/demos/spectex.c Normal file
View file

@ -0,0 +1,277 @@
/* $Id: spectex.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* GLUT demonstration of texturing with specular highlights.
*
* When drawing a lit, textured surface one usually wants the specular
* highlight to override the texture colors. However, OpenGL applies
* texturing after lighting so the specular highlight is modulated by
* the texture.
*
* The solution here shown here is a two-pass algorithm:
* 1. Draw the textured surface without specular lighting.
* 2. Enable blending to add the next pass:
* 3. Redraw the surface with a matte white material and only the
* specular components of light sources enabled.
*
* Brian Paul February 1997
*/
/*
* $Log: spectex.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.2 1999/03/28 18:22:05 brianp
* minor clean-up
*
* Revision 3.1 1998/02/14 18:47:48 brianp
* added OpenGL 1.2 separate specular interpolation support
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
static GLUquadricObj *Quadric;
static GLuint Sphere;
static GLfloat LightPos[4] = {10.0, 10.0, 10.0, 1.0};
static GLfloat Delta = 1.0;
static GLint Mode = 0;
/*static GLfloat Blue[4] = {0.0, 0.0, 1.0, 1.0};*/
/*static GLfloat Gray[4] = {0.5, 0.5, 0.5, 1.0};*/
static GLfloat Black[4] = {0.0, 0.0, 0.0, 1.0};
static GLfloat White[4] = {1.0, 1.0, 1.0, 1.0};
static void Idle( void )
{
LightPos[0] += Delta;
if (LightPos[0]>15.0)
Delta = -1.0;
else if (LightPos[0]<-15.0)
Delta = 1.0;
glutPostRedisplay();
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
glPushMatrix();
glRotatef(90.0, 1.0, 0.0, 0.0);
if (Mode==0) {
/* Typical method: diffuse + specular + texture */
glEnable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */
#ifdef GL_VERSION_1_2
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
#endif
glCallList(Sphere);
}
else if (Mode==1) {
/* just specular highlight */
glDisable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_DIFFUSE, Black); /* disable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */
#ifdef GL_VERSION_1_2
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
#endif
glCallList(Sphere);
}
else if (Mode==2) {
/* diffuse textured */
glEnable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, Black); /* disable specular */
#ifdef GL_VERSION_1_2
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
#endif
glCallList(Sphere);
}
else if (Mode==3) {
/* 2-pass: diffuse textured then add specular highlight*/
glEnable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, Black); /* disable specular */
#ifdef GL_VERSION_1_2
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
#endif
glCallList(Sphere);
/* specular highlight */
glDepthFunc(GL_EQUAL); /* redraw same pixels */
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND); /* add */
glLightfv(GL_LIGHT0, GL_DIFFUSE, Black); /* disable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */
glCallList(Sphere);
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
}
else if (Mode==4) {
/* OpenGL 1.2's separate diffuse and specular color */
glEnable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_DIFFUSE, White); /* enable diffuse */
glLightfv(GL_LIGHT0, GL_SPECULAR, White); /* enable specular */
#ifdef GL_VERSION_1_2
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
#endif
glCallList(Sphere);
}
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -12.0 );
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
}
glutPostRedisplay();
}
static void Init( void )
{
int i, j;
GLubyte texImage[64][64][3];
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Black);
glMaterialfv(GL_FRONT, GL_DIFFUSE, White);
glMaterialfv(GL_FRONT, GL_SPECULAR, White);
glMaterialf(GL_FRONT, GL_SHININESS, 20.0);
/* Actually, these are set again later */
glLightfv(GL_LIGHT0, GL_DIFFUSE, White);
glLightfv(GL_LIGHT0, GL_SPECULAR, White);
Quadric = gluNewQuadric();
gluQuadricTexture( Quadric, GL_TRUE );
Sphere= glGenLists(1);
glNewList( Sphere, GL_COMPILE );
gluSphere( Quadric, 1.0, 24, 24 );
glEndList();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
for (i=0;i<64;i++) {
for (j=0;j<64;j++) {
int k = ((i>>3)&1) ^ ((j>>3)&1);
texImage[i][j][0] = 255*k;
texImage[i][j][1] = 255*(1-k);
texImage[i][j][2] = 0;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D( GL_TEXTURE_2D,
0,
3,
64, 64,
0,
GL_RGB, GL_UNSIGNED_BYTE,
texImage );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE);
}
static void ModeMenu(int entry)
{
if (entry==99)
exit(0);
Mode = entry;
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 300, 300 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "spectex" );
Init();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutCreateMenu( ModeMenu );
glutAddMenuEntry("1-pass lighting + texturing", 0);
glutAddMenuEntry("specular lighting", 1);
glutAddMenuEntry("diffuse lighting + texturing", 2);
glutAddMenuEntry("2-pass lighting + texturing", 3);
#ifdef GL_VERSION_1_2
glutAddMenuEntry("OpenGL 1.2 separate specular", 4);
#endif
glutAddMenuEntry("Quit", 99);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

578
progs/demos/stex3d.c Normal file
View file

@ -0,0 +1,578 @@
/* $Id: stex3d.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*-----------------------------
* stex3d.c GL example of the mesa 3d-texture extention to simulate procedural
* texturing, it uses a perlin noise and turbulence functions.
*
* Author: Daniel Barrero
* barrero@irit.fr
* dbarrero@pegasus.uniandes.edu.co
*
* Converted to GLUT by brianp on 1/1/98
*
*
* cc stex3d.c -o stex3d -lglut -lMesaGLU -lMesaGL -lX11 -lXext -lm
*
*---------------------------- */
/*
* $Log: stex3d.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1998/06/09 01:53:49 brianp
* main() should return an int
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
/* function declarations */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void init(void),
printHelp(void),
create3Dtexture(void),
setDefaults(void),
drawScene(void),
resize(int w, int h),
buildFigure(void),
initNoise(void);
float turbulence(float point[3], float lofreq, float hifreq);
int isExtSupported(char *ext);
void KeyHandler( unsigned char key, int x, int y );
GLenum parseCmdLine(int argc, char **argv);
float noise3(float vec[3]);
/* global variables */
GLenum rgb, doubleBuffer, directRender, windType; /* visualization state*/
float tex_width,tex_height,tex_depth; /* texture volume dimensions */
unsigned char *voxels; /* texture data ptr */
int angx,angy,angz;
GLuint figure;
/*function definitions */
int main(int argc, char **argv)
{
if (parseCmdLine(argc, argv) == GL_FALSE) {
exit(0);
}
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
windType |= GLUT_DEPTH;
glutInitDisplayMode(windType);
if (glutCreateWindow("stex3d") <= 0) {
exit(0);
}
/* init all */
init();
glutReshapeFunc(resize);
glutKeyboardFunc(KeyHandler);
glutDisplayFunc(drawScene);
glutMainLoop();
return 0;
}
void init()
{
/* init light */
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 25.0 };
GLfloat gray[] = { 0.6, 0.6, 0.6, 0.0 };
GLfloat white[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
glLightfv(GL_LIGHT1, GL_AMBIENT, gray);
glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
glLightfv(GL_LIGHT1, GL_SPECULAR, white);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
/* create torus for texturing */
figure=glGenLists(1);
buildFigure();
/* tkSolidTorus(figure,0.3,1.2);*/
/* start the noise function variables */
initNoise();
/* see if the texture 3d extention is supported */
if (!isExtSupported("GL_EXT_texture3D")) {
printf("Sorry this GL implementation (%s) does not support 3d texture extentions\n",
(char *)(glGetString(GL_RENDERER)));
/* tkQuit();*/
}
/* if texture is supported then generate the texture */
create3Dtexture();
glEnable(GL_TEXTURE_3D_EXT);
/*
glBlendFunc(GL_SRC_COLOR, GL_SRC_ALPHA);
glEnable(GL_BLEND);
*/
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glColor3f(0.6,0.7,0.8);
}
void buildFigure(void)
{ GLint i, j;
float theta1, phi1, theta2, phi2, rings, sides;
float v0[03], v1[3], v2[3], v3[3];
float t0[03], t1[3], t2[3], t3[3];
float n0[3], n1[3], n2[3], n3[3];
float innerRadius=0.4;
float outerRadius=0.8;
float scalFac;
rings = 8;
sides = 10;
scalFac=1/(outerRadius*2);
glNewList(figure, GL_COMPILE);
for (i = 0; i < rings; i++) {
theta1 = (float)i * 2.0 * M_PI / rings;
theta2 = (float)(i + 1) * 2.0 * M_PI / rings;
for (j = 0; j < sides; j++) {
phi1 = (float)j * 2.0 * M_PI / sides;
phi2 = (float)(j + 1) * 2.0 * M_PI / sides;
v0[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi1));
v0[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi1));
v0[2] = innerRadius * sin(phi1);
v1[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi1));
v1[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi1));
v1[2] = innerRadius * sin(phi1);
v2[0] = cos(theta2) * (outerRadius + innerRadius * cos(phi2));
v2[1] = -sin(theta2) * (outerRadius + innerRadius * cos(phi2));
v2[2] = innerRadius * sin(phi2);
v3[0] = cos(theta1) * (outerRadius + innerRadius * cos(phi2));
v3[1] = -sin(theta1) * (outerRadius + innerRadius * cos(phi2));
v3[2] = innerRadius * sin(phi2);
n0[0] = cos(theta1) * (cos(phi1));
n0[1] = -sin(theta1) * (cos(phi1));
n0[2] = sin(phi1);
n1[0] = cos(theta2) * (cos(phi1));
n1[1] = -sin(theta2) * (cos(phi1));
n1[2] = sin(phi1);
n2[0] = cos(theta2) * (cos(phi2));
n2[1] = -sin(theta2) * (cos(phi2));
n2[2] = sin(phi2);
n3[0] = cos(theta1) * (cos(phi2));
n3[1] = -sin(theta1) * (cos(phi2));
n3[2] = sin(phi2);
t0[0] = v0[0]*scalFac + 0.5;
t0[1] = v0[1]*scalFac + 0.5;
t0[2] = v0[2]*scalFac + 0.5;
t1[0] = v1[0]*scalFac + 0.5;
t1[1] = v1[1]*scalFac + 0.5;
t1[2] = v1[2]*scalFac + 0.5;
t2[0] = v2[0]*scalFac + 0.5;
t2[1] = v2[1]*scalFac + 0.5;
t2[2] = v2[2]*scalFac + 0.5;
t3[0] = v3[0]*scalFac + 0.5;
t3[1] = v3[1]*scalFac + 0.5;
t3[2] = v3[2]*scalFac + 0.5;
glBegin(GL_POLYGON);
glNormal3fv(n3); glTexCoord3fv(t3); glVertex3fv(v3);
glNormal3fv(n2); glTexCoord3fv(t2); glVertex3fv(v2);
glNormal3fv(n1); glTexCoord3fv(t1); glVertex3fv(v1);
glNormal3fv(n0); glTexCoord3fv(t0); glVertex3fv(v0);
glEnd();
}
}
glEndList();
}
void create3Dtexture()
{
int i,j,k;
unsigned char *vp;
float vec[3];
int tmp;
printf("creating 3d textures...\n");
voxels = (unsigned char *) malloc((4*tex_width*tex_height*tex_depth));
vp=voxels;
for (i=0;i<tex_width;i++){
vec[0]=i;
for (j=0;j<tex_height;j++) {
vec[1]=j;
for (k=0;k<tex_depth;k++) {
vec[2]=k;
tmp=(sin(k*i*j+turbulence(vec,0.01,1))+1)*127.5;
*vp++=0;
*vp++=0;
*vp++=tmp;
*vp++=tmp+128;
}
}
}
printf("setting up 3d texture...\n");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R_EXT, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_RGBA,
tex_width, tex_height, tex_depth,
0, GL_RGBA, GL_UNSIGNED_BYTE, voxels);
printf("finished setting up 3d texture image...\n");
}
int isExtSupported(char *ext)
{
/* routine to find whether a specified OpenGL extension is supported */
char *c;
int len;
char *allext = (char *)(glGetString(GL_EXTENSIONS));
len = strlen(ext);
if (len <= 0) return 0;
c = allext;
while (c) {
if (!strncmp(c,ext,len)) return 1;
c = strchr(c+1,'G');
}
return 0;
}
void printHelp()
{
printf("\nUsage: stex3d <cmd line options>\n");
printf(" cmd line options:\n");
printf(" -help print this help!\n");
printf(" -rgb RGBA mode. (Default)\n");
printf(" -ci Color index mode.\n");
printf(" -sb Single buffer mode. (Default)\n");
printf(" -db Double buffer mode. \n");
printf(" -dr Direct render mode.\n");
printf(" -ir Indirect render mode. (Default)\n");
printf(" -wxxx Width of the texture (Default=64)\n");
printf(" -hxxx Height of the texture (Default=64)\n");
printf(" -dxxx Depth of the texture (Default=64)\n");
printf(" Keyboard Options:\n");
printf(" 1 Object Texture coordinates (Default)\n");
printf(" 2 Eye Texture coordinates \n");
printf(" x rotate around x clockwise\n");
printf(" X rotate around x counter clockwise\n");
printf(" y rotate around y clockwise\n");
printf(" Y rotate around y counter clockwise\n");
printf(" z rotate around z clockwise\n");
printf(" Z rotate around z counter clockwise\n");
printf(" t enable 3-D texuring (Default)\n");
printf(" T disable 3-D texuring\n");
printf(" s smooth shading \n");
printf(" S flat shading (Default)\n");
}
void setDefaults()
{
/* visualization defaults */
rgb = GL_TRUE;
doubleBuffer = GL_FALSE;
directRender = GL_TRUE;
angx=130;
angy=30;
angz=0;
/* texture values */
tex_width=64;
tex_height=64;
tex_depth=64;
}
GLenum parseCmdLine(int argc, char **argv)
{
GLint i;
setDefaults();
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ci") == 0) {
rgb = GL_FALSE;
} else if (strcmp(argv[i], "-rgb") == 0) {
rgb = GL_TRUE;
} else if (strcmp(argv[i], "-sb") == 0) {
doubleBuffer = GL_FALSE;
} else if (strcmp(argv[i], "-db") == 0) {
doubleBuffer = GL_TRUE;
} else if (strcmp(argv[i], "-dr") == 0) {
directRender = GL_TRUE;
} else if (strcmp(argv[i], "-ir") == 0) {
directRender = GL_FALSE;
} else if (strstr(argv[i], "-w") == 0) {
tex_width=atoi((argv[i])+2);
} else if (strstr(argv[i], "-h") == 0) {
tex_height=atoi((argv[i])+2);
} else if (strstr(argv[i], "-d") == 0) {
tex_depth=atoi((argv[i])+2);
} else if (strcmp(argv[i], "-help") == 0) {
printHelp();
return GL_FALSE;
} else {
printf("%s (Bad option).\n", argv[i]);
printHelp();
return GL_FALSE;
}
}
if(tex_width==0 || tex_height==0 || tex_depth==0) {
printf("%s (Bad option).\n", "size parameters can't be 0");
printHelp();
return GL_FALSE;
}
return GL_TRUE;
}
void drawScene()
{
/* clear background, z buffer etc */
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angx,1.0,0.0,0.0);
glRotatef(angy,0.0,1.0,0.0);
glRotatef(angz,0.0,0.0,1.0);
glCallList(figure);
glPopMatrix();
glFlush();
if(doubleBuffer)
glutSwapBuffers();
;
}
void resize(int w, int h)
{
glViewport(0, 0, (GLint)w, (GLint)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-5,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0,0,-5);
}
void cleanEverything(void)
{
/* free(voxels); */
}
void KeyHandler( unsigned char key, int x, int y )
{
switch(key) {
case 27:
case 'q':
case 'Q': /* quit game. */
cleanEverything();
exit(0);
break;
case 'x':
angx+=10;
break;
case 'X':
angx-=10;
break;
case 'y':
angy+=10;
break;
case 'Y':
angy-=10;
break;
case 'z':
angz+=10;
break;
case 'Z':
angz-=10;
break;
case 't':
glEnable(GL_TEXTURE_3D_EXT);
break;
case 'T':
glDisable(GL_TEXTURE_3D_EXT);
break;
case 's':
glShadeModel(GL_SMOOTH);
break;
case 'S':
glShadeModel(GL_FLAT);
break;
case '1':
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
break;
case '2':
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
break;
default:
break;
}
glutPostRedisplay();
}
/*--------------------------------------------------------------------
noise function over R3 - implemented by a pseudorandom tricubic spline
EXCERPTED FROM SIGGRAPH 92, COURSE 23
PROCEDURAL MODELING
Ken Perlin
New York University
----------------------------------------------------------------------*/
#define DOT(a,b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2])
#define B 256
static int p[B + B + 2];
static float g[B + B + 2][3];
#define setup(i,b0,b1,r0,r1) \
t = vec[i] + 10000.; \
b0 = ((int)t) & (B-1); \
b1 = (b0+1) & (B-1); \
r0 = t - (int)t; \
r1 = r0 - 1.;
float noise3(float vec[3])
{
int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v;
register int i, j;
setup(0, bx0,bx1, rx0,rx1);
setup(1, by0,by1, ry0,ry1);
setup(2, bz0,bz1, rz0,rz1);
i = p[ bx0 ];
j = p[ bx1 ];
b00 = p[ i + by0 ];
b10 = p[ j + by0 ];
b01 = p[ i + by1 ];
b11 = p[ j + by1 ];
#define at(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
#define surve(t) ( t * t * (3. - 2. * t) )
#define lerp(t, a, b) ( a + t * (b - a) )
sx = surve(rx0);
sy = surve(ry0);
sz = surve(rz0);
q = g[ b00 + bz0 ] ; u = at(rx0,ry0,rz0);
q = g[ b10 + bz0 ] ; v = at(rx1,ry0,rz0);
a = lerp(sx, u, v);
q = g[ b01 + bz0 ] ; u = at(rx0,ry1,rz0);
q = g[ b11 + bz0 ] ; v = at(rx1,ry1,rz0);
b = lerp(sx, u, v);
c = lerp(sy, a, b); /* interpolate in y at lo x */
q = g[ b00 + bz1 ] ; u = at(rx0,ry0,rz1);
q = g[ b10 + bz1 ] ; v = at(rx1,ry0,rz1);
a = lerp(sx, u, v);
q = g[ b01 + bz1 ] ; u = at(rx0,ry1,rz1);
q = g[ b11 + bz1 ] ; v = at(rx1,ry1,rz1);
b = lerp(sx, u, v);
d = lerp(sy, a, b); /* interpolate in y at hi x */
return 1.5 * lerp(sz, c, d); /* interpolate in z */
}
void initNoise()
{
/*long random();*/
int i, j, k;
float v[3], s;
/* Create an array of random gradient vectors uniformly on the unit sphere */
/*srandom(1);*/
srand(1);
for (i = 0 ; i < B ; i++) {
do { /* Choose uniformly in a cube */ for (j=0 ; j<3 ; j++)
v[j] = (float)((rand() % (B + B)) - B) / B;
s = DOT(v,v);
} while (s > 1.0); /* If not in sphere try again */ s = sqrt(s);
for (j = 0 ; j < 3 ; j++) /* Else normalize */
g[i][j] = v[j] / s;
}
/* Create a pseudorandom permutation of [1..B] */
for (i = 0 ; i < B ; i++)
p[i] = i;
for (i = B ; i > 0 ; i -= 2) {
k = p[i];
p[i] = p[j = rand() % B];
p[j] = k;
}
/* Extend g and p arrays to allow for faster indexing */
for (i = 0 ; i < B + 2 ; i++) {
p[B + i] = p[i];
for (j = 0 ; j < 3 ; j++)
g[B + i][j] = g[i][j];
}
}
float turbulence(float point[3], float lofreq, float hifreq)
{
float freq, t, p[3];
p[0] = point[0] + 123.456;
p[1] = point[1];
p[2] = point[2];
t = 0;
for (freq = lofreq ; freq < hifreq ; freq *= 2.) {
t += fabs(noise3(p)) / freq;
p[0] *= 2.;
p[1] *= 2.;
p[2] *= 2.;
}
return t - 0.3; /* readjust to make mean value = 0.0 */
}

439
progs/demos/tessdemo.c Normal file
View file

@ -0,0 +1,439 @@
/* $Id: tessdemo.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* A demo of the GLU polygon tesselation functions written by Bogdan Sikorski.
* This demo isn't built by the Makefile because it needs GLUT. After you've
* installed GLUT you can try this demo.
* Here's the command for IRIX, for example:
cc -g -ansi -prototypes -fullwarn -float -I../include -DSHM tess_demo.c -L../lib -lglut -lMesaGLU -lMesaGL -lm -lX11 -lXext -lXmu -lfpe -lXext -o tess_demo
*/
/*
* $Log: tessdemo.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.5 1999/03/28 18:24:37 brianp
* minor clean-up
*
* Revision 3.4 1999/02/14 03:37:07 brianp
* fixed callback problem
*
* Revision 3.3 1998/07/26 01:25:26 brianp
* removed include of gl.h and glu.h
*
* Revision 3.2 1998/06/29 02:37:30 brianp
* minor changes for Windows (Ted Jump)
*
* Revision 3.1 1998/06/09 01:53:49 brianp
* main() should return an int
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_POINTS 200
#define MAX_CONTOURS 50
int menu;
typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries;
typedef enum{ DEFINE, TESSELATED } mode_type;
struct
{
GLint p[MAX_POINTS][2];
GLuint point_cnt;
} contours[MAX_CONTOURS];
GLuint contour_cnt;
GLsizei width,height;
mode_type mode;
struct
{
GLsizei no;
GLfloat color[3];
GLint p[3][2];
GLclampf p_color[3][3];
} triangle;
#ifndef GLCALLBACK
#ifdef CALLBACK
#define GLCALLBACK CALLBACK
#else
#define GLCALLBACK
#endif
#endif
void GLCALLBACK my_error(GLenum err)
{
int len,i;
char const *str;
glColor3f(0.9,0.9,0.9);
glRasterPos2i(5,5);
str=(const char *)gluErrorString(err);
len=strlen(str);
for(i=0;i<len;i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,str[i]);
}
void GLCALLBACK begin_callback(GLenum mode)
{
triangle.no=0;
}
void GLCALLBACK edge_callback(GLenum flag)
{
if(flag==GL_TRUE)
{
triangle.color[0]=1.0;
triangle.color[1]=1.0;
triangle.color[2]=0.5;
}
else
{
triangle.color[0]=1.0;
triangle.color[1]=0.0;
triangle.color[2]=0.0;
}
}
void GLCALLBACK end_callback()
{
glBegin(GL_LINES);
glColor3f(triangle.p_color[0][0],triangle.p_color[0][1],
triangle.p_color[0][2]);
glVertex2i(triangle.p[0][0],triangle.p[0][1]);
glVertex2i(triangle.p[1][0],triangle.p[1][1]);
glColor3f(triangle.p_color[1][0],triangle.p_color[1][1],
triangle.p_color[1][2]);
glVertex2i(triangle.p[1][0],triangle.p[1][1]);
glVertex2i(triangle.p[2][0],triangle.p[2][1]);
glColor3f(triangle.p_color[2][0],triangle.p_color[2][1],
triangle.p_color[2][2]);
glVertex2i(triangle.p[2][0],triangle.p[2][1]);
glVertex2i(triangle.p[0][0],triangle.p[0][1]);
glEnd();
}
void GLCALLBACK vertex_callback(void *data)
{
GLsizei no;
GLint *p;
p=(GLint *)data;
no=triangle.no;
triangle.p[no][0]=p[0];
triangle.p[no][1]=p[1];
triangle.p_color[no][0]=triangle.color[0];
triangle.p_color[no][1]=triangle.color[1];
triangle.p_color[no][2]=triangle.color[2];
++(triangle.no);
}
void set_screen_wh(GLsizei w, GLsizei h)
{
width=w;
height=h;
}
void tesse(void)
{
GLUtriangulatorObj *tobj;
GLdouble data[3];
GLuint i,j,point_cnt;
tobj=gluNewTess();
if(tobj!=NULL)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (0.7, 0.7, 0.0);
gluTessCallback(tobj,GLU_BEGIN,glBegin);
gluTessCallback(tobj,GLU_END,glEnd);
gluTessCallback(tobj,GLU_ERROR,my_error);
gluTessCallback(tobj,GLU_VERTEX,glVertex2iv);
gluBeginPolygon(tobj);
for(j=0;j<=contour_cnt;j++)
{
point_cnt=contours[j].point_cnt;
gluNextContour(tobj,GLU_UNKNOWN);
for(i=0;i<point_cnt;i++)
{
data[0]=(GLdouble)(contours[j].p[i][0]);
data[1]=(GLdouble)(contours[j].p[i][1]);
data[2]=0.0;
gluTessVertex(tobj,data,contours[j].p[i]);
}
}
gluEndPolygon(tobj);
glLineWidth(2.0);
gluTessCallback(tobj,GLU_BEGIN,begin_callback);
gluTessCallback(tobj,GLU_END,end_callback);
gluTessCallback(tobj,GLU_VERTEX,vertex_callback);
gluTessCallback(tobj,GLU_EDGE_FLAG,edge_callback);
gluBeginPolygon(tobj);
for(j=0;j<=contour_cnt;j++)
{
point_cnt=contours[j].point_cnt;
gluNextContour(tobj,GLU_UNKNOWN);
for(i=0;i<point_cnt;i++)
{
data[0]=(GLdouble)(contours[j].p[i][0]);
data[1]=(GLdouble)(contours[j].p[i][1]);
data[2]=0.0;
gluTessVertex(tobj,data,contours[j].p[i]);
}
}
gluEndPolygon(tobj);
gluDeleteTess(tobj);
glutMouseFunc(NULL);
glColor3f (1.0, 1.0, 0.0);
glLineWidth(1.0);
mode=TESSELATED;
}
}
void left_down(int x1,int y1)
{
GLint P[2];
GLuint point_cnt;
/* translate GLUT into GL coordinates */
P[0]=x1;
P[1]=height-y1;
point_cnt=contours[contour_cnt].point_cnt;
contours[contour_cnt].p[point_cnt][0]=P[0];
contours[contour_cnt].p[point_cnt][1]=P[1];
glBegin(GL_LINES);
if(point_cnt)
{
glVertex2iv(contours[contour_cnt].p[point_cnt-1]);
glVertex2iv(P);
}
else
{
glVertex2iv(P);
glVertex2iv(P);
}
glEnd();
glFinish();
++(contours[contour_cnt].point_cnt);
}
void middle_down(int x1, int y1)
{
GLuint point_cnt;
(void) x1;
(void) y1;
point_cnt=contours[contour_cnt].point_cnt;
if(point_cnt>2)
{
glBegin(GL_LINES);
glVertex2iv(contours[contour_cnt].p[0]);
glVertex2iv(contours[contour_cnt].p[point_cnt-1]);
contours[contour_cnt].p[point_cnt][0]= -1;
glEnd();
glFinish();
contour_cnt++;
contours[contour_cnt].point_cnt=0;
}
}
void mouse_clicked(int button,int state,int x,int y)
{
x-= x%10;
y-= y%10;
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN)
left_down(x,y);
break;
case GLUT_MIDDLE_BUTTON:
if(state==GLUT_DOWN)
middle_down(x,y);
break;
}
}
void display(void)
{
GLuint i,j;
GLuint point_cnt;
glClear(GL_COLOR_BUFFER_BIT);
switch(mode)
{
case DEFINE:
/* draw grid */
glColor3f (0.6,0.5,0.5);
glBegin(GL_LINES);
for(i=0;i<width;i+=10)
for(j=0;j<height;j+=10)
{
glVertex2i(0,j);
glVertex2i(width,j);
glVertex2i(i,height);
glVertex2i(i,0);
}
glColor3f (1.0, 1.0, 0.0);
for(i=0;i<=contour_cnt;i++)
{
point_cnt=contours[i].point_cnt;
glBegin(GL_LINES);
switch(point_cnt)
{
case 0:
break;
case 1:
glVertex2iv(contours[i].p[0]);
glVertex2iv(contours[i].p[0]);
break;
case 2:
glVertex2iv(contours[i].p[0]);
glVertex2iv(contours[i].p[1]);
break;
default:
--point_cnt;
for(j=0;j<point_cnt;j++)
{
glVertex2iv(contours[i].p[j]);
glVertex2iv(contours[i].p[j+1]);
}
if(contours[i].p[j+1][0]== -1)
{
glVertex2iv(contours[i].p[0]);
glVertex2iv(contours[i].p[j]);
}
break;
}
glEnd();
}
glFinish();
break;
case TESSELATED:
/* draw lines */
tesse();
break;
}
glColor3f (1.0, 1.0, 0.0);
}
void clear( void )
{
contour_cnt=0;
contours[0].point_cnt=0;
glutMouseFunc(mouse_clicked);
mode=DEFINE;
display();
}
void quit( void )
{
exit(0);
}
void menu_selected(int entry)
{
switch(entry)
{
case CLEAR:
clear();
break;
case TESSELATE:
tesse();
break;
case QUIT:
quit();
break;
}
}
void key_pressed(unsigned char key,int x,int y)
{
(void) x;
(void) y;
switch(key)
{
case 't':
case 'T':
tesse();
glFinish();
break;
case 'q':
case 'Q':
quit();
break;
case 'c':
case 'C':
clear();
break;
}
}
void myinit (void)
{
/* clear background to gray */
glClearColor (0.4, 0.4, 0.4, 0.0);
glShadeModel (GL_FLAT);
menu=glutCreateMenu(menu_selected);
glutAddMenuEntry("clear",CLEAR);
glutAddMenuEntry("tesselate",TESSELATE);
glutAddMenuEntry("quit",QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMouseFunc(mouse_clicked);
glutKeyboardFunc(key_pressed);
contour_cnt=0;
glPolygonMode(GL_FRONT,GL_FILL);
mode=DEFINE;
}
static void reshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
set_screen_wh(w,h);
}
static void usage( void )
{
printf("Use left mouse button to place vertices.\n");
printf("Press middle mouse button when done.\n");
printf("Select tesselate from the pop-up menu.\n");
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
usage();
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (400, 400);
glutCreateWindow (argv[0]);
myinit ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

261
progs/demos/texcyl.c Normal file
View file

@ -0,0 +1,261 @@
/* $Id: texcyl.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Textured cylinder demo: lighting, texturing, reflection mapping.
* Brian Paul May 1997 This program is in the public domain.
*/
/*
* $Log: texcyl.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/03/28 18:24:37 brianp
* minor clean-up
*
* Revision 3.2 1998/11/05 04:34:04 brianp
* moved image files to ../images/ directory
*
* Revision 3.1 1998/06/23 03:16:51 brianp
* added Point/Linear sampling menu items
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include "../util/readtex.c" /* I know, this is a hack. */
#define TEXTURE_FILE "../images/reflect.rgb"
#define LIT 1
#define TEXTURED 2
#define REFLECT 3
#define ANIMATE 10
#define POINT_FILTER 20
#define LINEAR_FILTER 21
#define QUIT 100
static GLuint CylinderObj = 0;
static GLboolean Animate = GL_TRUE;
static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
static GLfloat DXrot = 1.0, DYrot = 2.5;
static void Idle( void )
{
if (Animate) {
Xrot += DXrot;
Yrot += DYrot;
glutPostRedisplay();
}
}
static void Display( void )
{
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glRotatef(Xrot, 1.0, 0.0, 0.0);
glRotatef(Yrot, 0.0, 1.0, 0.0);
glRotatef(Zrot, 0.0, 0.0, 1.0);
glScalef(5.0, 5.0, 5.0);
glCallList(CylinderObj);
glPopMatrix();
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -70.0 );
}
static void SetMode(GLuint m)
{
/* disable everything */
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
/* enable what's needed */
if (m==LIT) {
glEnable(GL_LIGHTING);
}
else if (m==TEXTURED) {
glEnable(GL_TEXTURE_2D);
}
else if (m==REFLECT) {
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
}
}
static void ModeMenu(int entry)
{
if (entry==ANIMATE) {
Animate = !Animate;
}
else if (entry==POINT_FILTER) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
else if (entry==LINEAR_FILTER) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else if (entry==QUIT) {
exit(0);
}
else {
SetMode(entry);
}
glutPostRedisplay();
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void SpecialKey( int key, int x, int y )
{
float step = 3.0;
(void) x;
(void) y;
switch (key) {
case GLUT_KEY_UP:
Xrot += step;
break;
case GLUT_KEY_DOWN:
Xrot -= step;
break;
case GLUT_KEY_LEFT:
Yrot += step;
break;
case GLUT_KEY_RIGHT:
Yrot -= step;
break;
}
glutPostRedisplay();
}
static void Init( void )
{
GLUquadricObj *q = gluNewQuadric();
CylinderObj = glGenLists(1);
glNewList(CylinderObj, GL_COMPILE);
glTranslatef(0.0, 0.0, -1.0);
/* cylinder */
gluQuadricNormals(q, GL_SMOOTH);
gluQuadricTexture(q, GL_TRUE);
gluCylinder(q, 0.6, 0.6, 2.0, 24, 1);
/* end cap */
glTranslatef(0.0, 0.0, 2.0);
gluDisk(q, 0.0, 0.6, 24, 1);
/* other end cap */
glTranslatef(0.0, 0.0, -2.0);
gluQuadricOrientation(q, GLU_INSIDE);
gluDisk(q, 0.0, 0.6, 24, 1);
glEndList();
gluDeleteQuadric(q);
/* lighting */
glEnable(GL_LIGHTING);
{
GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0};
GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
GLfloat teal[4] = { 0.0, 1.0, 0.8, 1.0 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, teal);
glLightfv(GL_LIGHT0, GL_AMBIENT, gray);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glEnable(GL_LIGHT0);
}
/* fitering = nearest, initially */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
printf("Error: couldn't load texture image\n");
exit(1);
}
glEnable(GL_CULL_FACE); /* don't need Z testing for convex objects */
SetMode(LIT);
}
int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowSize( 400, 400 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0] );
Init();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutCreateMenu(ModeMenu);
glutAddMenuEntry("Lit", LIT);
glutAddMenuEntry("Textured", TEXTURED);
glutAddMenuEntry("Reflect", REFLECT);
glutAddMenuEntry("Point Filtered", POINT_FILTER);
glutAddMenuEntry("Linear Filtered", LINEAR_FILTER);
glutAddMenuEntry("Toggle Animation", ANIMATE);
glutAddMenuEntry("Quit", QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

289
progs/demos/texobj.c Normal file
View file

@ -0,0 +1,289 @@
/* $Id: texobj.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Example of using the 1.1 texture object functions.
* Also, this demo utilizes Mesa's fast texture map path.
*
* Brian Paul June 1996 This file is in the public domain.
*/
/*
* $Log: texobj.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.1 1999/03/28 18:24:37 brianp
* minor clean-up
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "GL/glut.h"
static GLuint Window = 0;
static GLuint TexObj[2];
static GLfloat Angle = 0.0f;
static GLboolean HaveTexObj = GL_FALSE;
#if defined(GL_VERSION_1_1)
# define TEXTURE_OBJECT 1
#elif defined(GL_EXT_texture_object)
# define TEXTURE_OBJECT 1
# define glBindTexture(A,B) glBindTextureEXT(A,B)
# define glGenTextures(A,B) glGenTexturesEXT(A,B)
# define glDeleteTextures(A,B) glDeleteTexturesEXT(A,B)
#endif
static void draw( void )
{
glDepthFunc(GL_EQUAL);
/* glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );*/
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 1.0, 1.0 );
/* draw first polygon */
glPushMatrix();
glTranslatef( -1.0, 0.0, 0.0 );
glRotatef( Angle, 0.0, 0.0, 1.0 );
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture( GL_TEXTURE_2D, TexObj[0] );
#endif
}
else {
glCallList( TexObj[0] );
}
glBegin( GL_POLYGON );
glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
glEnd();
glPopMatrix();
/* draw second polygon */
glPushMatrix();
glTranslatef( 1.0, 0.0, 0.0 );
glRotatef( Angle-90.0, 0.0, 1.0, 0.0 );
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture( GL_TEXTURE_2D, TexObj[1] );
#endif
}
else {
glCallList( TexObj[0] );
}
glBegin( GL_POLYGON );
glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
glEnd();
glPopMatrix();
glutSwapBuffers();
}
static void idle( void )
{
Angle += 2.0;
glutPostRedisplay();
}
/* change view Angle, exit upon ESC */
static void key(unsigned char k, int x, int y)
{
(void) x;
(void) y;
switch (k) {
case 27:
#ifdef TEXTURE_OBJECT
glDeleteTextures( 2, TexObj );
#endif
glutDestroyWindow(Window);
exit(0);
}
}
/* new window size or exposure */
static void reshape( int width, int height )
{
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef( 0.0, 0.0, -8.0 );
}
static void init( void )
{
static int width=8, height=8;
static GLubyte tex1[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
static GLubyte tex2[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2, 2, 0, 0, 0,
0, 0, 2, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 2, 0, 0, 0, 0,
0, 0, 2, 2, 2, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
GLubyte tex[64][3];
GLint i, j;
glDisable( GL_DITHER );
/* Setup texturing */
glEnable( GL_TEXTURE_2D );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
/* generate texture object IDs */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glGenTextures( 2, TexObj );
#endif
}
else {
TexObj[0] = glGenLists(2);
TexObj[1] = TexObj[0]+1;
}
/* setup first texture object */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture( GL_TEXTURE_2D, TexObj[0] );
#endif
}
else {
glNewList( TexObj[0], GL_COMPILE );
}
/* red on white */
for (i=0;i<height;i++) {
for (j=0;j<width;j++) {
int p = i*width+j;
if (tex1[(height-i-1)*width+j]) {
tex[p][0] = 255; tex[p][1] = 0; tex[p][2] = 0;
}
else {
tex[p][0] = 255; tex[p][1] = 255; tex[p][2] = 255;
}
}
}
glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
if (!HaveTexObj) {
glEndList();
}
/* end of texture object */
/* setup second texture object */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture( GL_TEXTURE_2D, TexObj[1] );
#endif
}
else {
glNewList( TexObj[1], GL_COMPILE );
}
/* green on blue */
for (i=0;i<height;i++) {
for (j=0;j<width;j++) {
int p = i*width+j;
if (tex2[(height-i-1)*width+j]) {
tex[p][0] = 0; tex[p][1] = 255; tex[p][2] = 0;
}
else {
tex[p][0] = 0; tex[p][1] = 0; tex[p][2] = 255;
}
}
}
glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
if (!HaveTexObj) {
glEndList();
}
/* end texture object */
}
int main( int argc, char *argv[] )
{
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
Window = glutCreateWindow("Texture Objects");
if (!Window) {
exit(1);
}
/* check that renderer has the GL_EXT_texture_object extension
* or supports OpenGL 1.1
*/
#ifdef TEXTURE_OBJECT
{
char *exten = (char *) glGetString( GL_EXTENSIONS );
char *version = (char *) glGetString( GL_VERSION );
if ( strstr( exten, "GL_EXT_texture_object" )
|| strncmp( version, "1.1", 3 )==0 ) {
HaveTexObj = GL_TRUE;
}
}
#endif
init();
glutReshapeFunc( reshape );
glutKeyboardFunc( key );
glutIdleFunc( idle );
glutDisplayFunc( draw );
glutMainLoop();
return 0;
}

277
progs/demos/trispd.c Normal file
View file

@ -0,0 +1,277 @@
/* $Id: trispd.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Simple GLUT program to measure triangle strip rendering speed.
* Brian Paul February 15, 1997 This file is in the public domain.
*/
/*
* $Log: trispd.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.4 1999/03/28 18:24:37 brianp
* minor clean-up
*
* Revision 3.3 1999/03/18 08:16:52 joukj
*
* cmpstr needs string.h to included to avoid warnings
*
* Revision 3.2 1998/07/08 03:02:00 brianp
* added Marten Stromberg's texture options
*
* Revision 3.1 1998/06/29 02:36:58 brianp
* removed unneeded includes
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <GL/glut.h>
static float MinPeriod = 2.0; /* 2 seconds */
static float Width = 400.0;
static float Height = 400.0;
static int Loops = 1;
static int Size = 50;
static int Texture = 0;
static void Idle( void )
{
glutPostRedisplay();
}
static void Display( void )
{
float x, y;
float xStep;
float yStep;
double t0, t1;
double triRate;
double pixelRate;
int triCount;
int i;
float red[3] = { 1.0, 0.0, 0.0 };
float blue[3] = { 0.0, 0.0, 1.0 };
xStep = yStep = sqrt( 2.0 * Size );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
triCount = 0;
t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
if (Texture) {
float uStep = xStep / Width;
float vStep = yStep / Height;
float u, v;
for (i=0; i<Loops; i++) {
for (y=1.0, v=0.0f; y<Height-yStep; y+=yStep, v+=vStep) {
glBegin(GL_TRIANGLE_STRIP);
for (x=1.0, u=0.0f; x<Width; x+=xStep, u+=uStep) {
glColor3fv(red);
glTexCoord2f(u, v);
glVertex2f(x, y);
glColor3fv(blue);
glTexCoord2f(u, v+vStep);
glVertex2f(x, y+yStep);
triCount += 2;
}
glEnd();
triCount -= 2;
}
}
}
else {
for (i=0; i<Loops; i++) {
for (y=1.0; y<Height-yStep; y+=yStep) {
glBegin(GL_TRIANGLE_STRIP);
for (x=1.0; x<Width; x+=xStep) {
glColor3fv(red);
glVertex2f(x, y);
glColor3fv(blue);
glVertex2f(x, y+yStep);
triCount += 2;
}
glEnd();
triCount -= 2;
}
}
}
t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
if (t1-t0 < MinPeriod) {
/* Next time draw more triangles to get longer elapsed time */
Loops *= 2;
return;
}
triRate = triCount / (t1-t0);
pixelRate = triRate * Size;
printf("Rate: %d tri in %gs = %g tri/s %d pixels/s\n",
triCount, t1-t0, triRate, (int)pixelRate);
glutSwapBuffers();
}
static void Reshape( int width, int height )
{
Width = width;
Height = height;
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
static void Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
static void LoadTex(int comp, int filter)
{
GLubyte *pixels;
int x, y;
pixels = malloc(4*256*256);
for (y = 0; y < 256; ++y)
for (x = 0; x < 256; ++x) {
pixels[(y*256+x)*4+0] = (int)(128.5 + 127.0 * cos(0.024544 * x));
pixels[(y*256+x)*4+1] = 255;
pixels[(y*256+x)*4+2] = (int)(128.5 + 127.0 * cos(0.024544 * y));
pixels[(y*256+x)*4+3] = 255;
}
glEnable(GL_TEXTURE_2D);
glTexImage2D(GL_TEXTURE_2D, 0, comp, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
printf("Texture: GL_MODULATE, %d comps, %s\n", comp, filter == GL_NEAREST ? "GL_NEAREST" : "GL_LINEAR");
}
static void Init( int argc, char *argv[] )
{
GLint shade;
GLint rBits, gBits, bBits;
int filter = GL_NEAREST, comp = 3;
int i;
for (i=1; i<argc; i++) {
if (strcmp(argv[i],"-dither")==0)
glDisable(GL_DITHER);
else if (strcmp(argv[i],"+dither")==0)
glEnable(GL_DITHER);
else if (strcmp(argv[i],"+smooth")==0)
glShadeModel(GL_SMOOTH);
else if (strcmp(argv[i],"+flat")==0)
glShadeModel(GL_FLAT);
else if (strcmp(argv[i],"+depth")==0)
glEnable(GL_DEPTH_TEST);
else if (strcmp(argv[i],"-depth")==0)
glDisable(GL_DEPTH_TEST);
else if (strcmp(argv[i],"-size")==0) {
Size = atoi(argv[i+1]);
i++;
}
else if (strcmp(argv[i],"-texture")==0)
Texture = 0;
else if (strcmp(argv[i],"+texture")==0)
Texture = 1;
else if (strcmp(argv[i],"-linear")==0)
filter = GL_NEAREST;
else if (strcmp(argv[i],"+linear")==0)
filter = GL_LINEAR;
else if (strcmp(argv[i],"-persp")==0)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
else if (strcmp(argv[i],"+persp")==0)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
else if (strcmp(argv[i],"-comp")==0) {
comp = atoi(argv[i+1]);
i++;
}
else
printf("Unknown option: %s\n", argv[i]);
}
glGetIntegerv(GL_SHADE_MODEL, &shade);
printf("Dither: %s\n", glIsEnabled(GL_DITHER) ? "on" : "off");
printf("ShadeModel: %s\n", (shade==GL_FLAT) ? "flat" : "smooth");
printf("DepthTest: %s\n", glIsEnabled(GL_DEPTH_TEST) ? "on" : "off");
printf("Size: %d pixels\n", Size);
if (Texture)
LoadTex(comp, filter);
glGetIntegerv(GL_RED_BITS, &rBits);
glGetIntegerv(GL_GREEN_BITS, &gBits);
glGetIntegerv(GL_BLUE_BITS, &bBits);
printf("RedBits: %d GreenBits: %d BlueBits: %d\n", rBits, gBits, bBits);
}
static void Help( const char *program )
{
printf("%s options:\n", program);
printf(" +/-dither enable/disable dithering\n");
printf(" +/-depth enable/disable depth test\n");
printf(" +flat flat shading\n");
printf(" +smooth smooth shading\n");
printf(" -size pixels specify pixels/triangle\n");
printf(" +/-texture enable/disable texture\n");
printf(" -comp n texture format\n");
printf(" +/-linear bilinear texture filter\n");
printf(" +/-persp perspective correction hint\n");
}
int main( int argc, char *argv[] )
{
printf("For options: %s -help\n", argv[0]);
glutInit( &argc, argv );
glutInitWindowSize( (int) Width, (int) Height );
glutInitWindowPosition( 0, 0 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( argv[0] );
if (argc==2 && strcmp(argv[1],"-help")==0) {
Help(argv[0]);
return 0;
}
Init( argc, argv );
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutDisplayFunc( Display );
glutIdleFunc( Idle );
glutMainLoop();
return 0;
}

128
progs/demos/winpos.c Normal file
View file

@ -0,0 +1,128 @@
/* $Id: winpos.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
* Example of how to use the GL_MESA_window_pos extension.
* Brian Paul This file is in the public domain.
*/
/*
* $Log: winpos.c,v $
* Revision 1.1 1999/08/19 00:55:40 jtg
* Initial revision
*
* Revision 3.3 1999/03/28 18:24:37 brianp
* minor clean-up
*
* Revision 3.2 1998/11/05 04:34:04 brianp
* moved image files to ../images/ directory
*
* Revision 3.1 1998/02/22 16:36:10 brianp
* changed image file and set unpack alignment to 1
*
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "GL/glut.h"
#include "../util/readtex.c" /* a hack, I know */
#define IMAGE_FILE "../images/girl.rgb"
#ifndef M_PI
# define M_PI 3.14159265
#endif
static GLubyte *Image;
static int ImgWidth, ImgHeight;
static GLenum ImgFormat;
static void draw( void )
{
GLfloat angle;
char *extensions;
extensions = (char *) glGetString( GL_EXTENSIONS );
if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
printf("Sorry, GL_MESA_window_pos extension not available.\n");
return;
}
glClear( GL_COLOR_BUFFER_BIT );
for (angle = -45.0; angle <= 135.0; angle += 10.0) {
GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
/* Don't need to worry about the modelview or projection matrices!!! */
#ifdef GL_MESA_window_pos
glWindowPos2fMESA( x, y );
#endif
glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
}
}
static void key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
case 27:
exit(0);
}
}
/* new window size or exposure */
static void reshape( int width, int height )
{
glViewport(0, 0, (GLint)width, (GLint)height);
}
static void init( void )
{
Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat );
if (!Image) {
printf("Couldn't read %s\n", IMAGE_FILE);
exit(0);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
int main( int argc, char *argv[] )
{
glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
glutInitDisplayMode( GLUT_RGB );
if (glutCreateWindow("winpos") <= 0) {
exit(0);
}
init();
glutReshapeFunc( reshape );
glutKeyboardFunc( key );
glutDisplayFunc( draw );
glutMainLoop();
return 0;
}

BIN
progs/images/girl.rgb Normal file

Binary file not shown.

BIN
progs/images/reflect.rgb Normal file

Binary file not shown.

BIN
progs/images/tile.rgb Normal file

Binary file not shown.

222
progs/redbook/Imakefile Normal file
View file

@ -0,0 +1,222 @@
LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\Mesaaux.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a
INCLUDES = -I$(TOP)\include
SRCS = accanti.c \
accnot.c \
accpersp.c \
accum.c \
aim.c \
alpha.c \
alpha3D.c \
anti.c \
antiindex.c \
antipindex.c \
antipoint.c \
antipoly.c \
bezcurve.c \
bezmesh.c \
bezsurf.c \
checker.c \
checker2.c \
chess.c \
clip.c \
colormat.c \
cone.c \
cube.c \
curve.c \
depthcue.c \
disk.c \
dof.c \
dofnot.c \
double.c \
drawf.c \
feedback.c \
fog.c \
fogindex.c \
font.c \
light.c \
linelist.c \
lines.c \
list.c \
list2.c \
maplight.c \
material.c \
mipmap.c \
model.c \
movelight.c \
nurbs.c \
pickdepth.c \
pickline.c \
picksquare.c \
plane.c \
planet.c \
planetup.c \
polys.c \
robot.c \
sccolorlight.c \
scene.c \
scenebamb.c \
sceneflat.c \
select.c \
simple.c \
smooth.c \
sphere.c \
stencil.c \
stroke.c \
surface.c \
tea.c \
teaambient.c \
teapots.c \
texgen.c \
texturesurf.c \
trim.c \
xfont.c
PROGRAMS = ProgramTargetName(accanti) \
ProgramTargetName(accnot) \
ProgramTargetName(accpersp) \
ProgramTargetName(accum) \
ProgramTargetName(aim) \
ProgramTargetName(alpha) \
ProgramTargetName(alpha3D) \
ProgramTargetName(anti) \
ProgramTargetName(antiindex) \
ProgramTargetName(antipindex) \
ProgramTargetName(antipoint) \
ProgramTargetName(antipoly) \
ProgramTargetName(bezcurve) \
ProgramTargetName(bezmesh) \
ProgramTargetName(bezsurf) \
ProgramTargetName(checker) \
ProgramTargetName(checker2) \
ProgramTargetName(chess) \
ProgramTargetName(clip) \
ProgramTargetName(colormat) \
ProgramTargetName(cone) \
ProgramTargetName(cube) \
ProgramTargetName(curve) \
ProgramTargetName(depthcue) \
ProgramTargetName(disk) \
ProgramTargetName(dof) \
ProgramTargetName(dofnot) \
ProgramTargetName(double) \
ProgramTargetName(drawf) \
ProgramTargetName(feedback) \
ProgramTargetName(fog) \
ProgramTargetName(fogindex) \
ProgramTargetName(font) \
ProgramTargetName(light) \
ProgramTargetName(linelist) \
ProgramTargetName(lines) \
ProgramTargetName(list) \
ProgramTargetName(list2) \
ProgramTargetName(maplight) \
ProgramTargetName(material) \
ProgramTargetName(mipmap) \
ProgramTargetName(model) \
ProgramTargetName(movelight) \
ProgramTargetName(nurbs) \
ProgramTargetName(pickdepth) \
ProgramTargetName(pickline) \
ProgramTargetName(picksquare) \
ProgramTargetName(plane) \
ProgramTargetName(planet) \
ProgramTargetName(planetup) \
ProgramTargetName(polys) \
ProgramTargetName(robot) \
ProgramTargetName(sccolorlight) \
ProgramTargetName(scene) \
ProgramTargetName(scenebamb) \
ProgramTargetName(sceneflat) \
ProgramTargetName(select) \
ProgramTargetName(simple) \
ProgramTargetName(smooth) \
ProgramTargetName(sphere) \
ProgramTargetName(stencil) \
ProgramTargetName(stroke) \
ProgramTargetName(surface) \
ProgramTargetName(tea) \
ProgramTargetName(teaambient) \
ProgramTargetName(teapots) \
ProgramTargetName(texgen) \
ProgramTargetName(texturesurf) \
ProgramTargetName(trim) \
ProgramTargetName(xfont)
AllTarget($(PROGRAMS))
NormalProgramTarget(accanti,accanti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(accnot,accnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(accpersp,accpersp.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(aim,aim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(alpha,alpha.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(alpha3D,alpha3D.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(anti,anti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(antiindex,antiindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(antipindex,antipindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(antipoint,antipoint.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(antipoly,antipoly.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(bezcurve,bezcurve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(bezmesh,bezmesh.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(bezsurf,bezsurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(checker,checker.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(checker2,checker2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(chess,chess.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(clip,clip.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(colormat,colormat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(cone,cone.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(cube,cube.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(curve,curve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(depthcue,depthcue.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(disk,disk.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(dof,dof.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(dofnot,dofnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(double,double.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(drawf,drawf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(feedback,feedback.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(fogindex,fogindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(light,light.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(linelist,linelist.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(lines,lines.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(list,list.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(list2,list2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(maplight,maplight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(material,material.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(mipmap,mipmap.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(model,model.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(movelight,movelight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(nurbs,nurbs.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(pickdepth,pickdepth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(pickline,pickline.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(picksquare,picksquare.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(plane,plane.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(planet,planet.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(planetup,planetup.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(polys,polys.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(robot,robot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(sccolorlight,sccolorlight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(scene,scene.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(scenebamb,scenebamb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(sceneflat,sceneflat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(simple,simple.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(smooth,smooth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(stroke,stroke.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(surface,surface.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(tea,tea.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(teaambient,teaambient.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(teapots,teapots.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(texgen,texgen.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(texturesurf,texturesurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(trim,trim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
NormalProgramTarget(xfont,xfont.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
DependTarget()


View file

@ -0,0 +1,70 @@
# $Id: Makefile.BeOS-R4,v 1.1 1999/08/19 00:55:40 jtg Exp $
# Makefile for OpenGL Programming Guide programs for BeOS R4
# This file is in the public domain.
# $Log: Makefile.BeOS-R4,v $
# Revision 1.1 1999/08/19 00:55:40 jtg
# Initial revision
#
# Revision 1.1 1999/02/25 02:13:06 brianp
# initial check-in
#
##### MACROS #####
INCDIR = ../include
LIBDIR = ../lib
GL_LIBS = -L$(LIBDIR) -L/boot/home/config/lib -Xlinker -rpath $(LIBDIR) -lbe -lglut -lMesaGLU -lMesaGL $(XLIBS)
LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
PROGS = aaindex aapoly aargb accanti accpersp alpha alpha3D anti \
bezcurve bezmesh checker clip colormat cube depthcue dof \
double drawf feedback fog fogindex font hello image light \
lines list material mipmap model movelight nurbs pickdepth \
picksquare plane planet polyoff polys robot sccolorlight \
scene scenebamb sceneflat select smooth stencil stroke surface \
teaambient teapots tess tesswind texbind texgen texprox texsub \
texturesurf torus unproject varray wrap
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c: $(LIB_DEP)
$(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
##### TARGETS #####
default:
@echo "Specify a target configuration"
clean:
-rm *.o *~
realclean:
-rm $(PROGS)
-rm *.o *~
targets: $(PROGS)
# execute all programs
exec: $(PROGS)
@for prog in $(PROGS) ; \
do \
echo -n "Running $$prog ..." ; \
$$prog ; \
echo ; \
done
include ../Make-config

View file

@ -0,0 +1,64 @@
# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:40 jtg Exp $
# Mesa 3-D graphics library
# Version: 3.1
# Copyright (C) 1995-1998 Brian Paul
# Makefile for programs from the OpenGL Programming Guide
##### MACROS #####
INCDIR = ../include
LIBDIR = ../lib
GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS)
LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
PROGS = aaindex aapoly aargb accanti accpersp alpha alpha3D anti \
bezcurve bezmesh checker clip colormat cube depthcue dof \
double drawf feedback fog fogindex font hello image light \
lines list material mipmap model movelight nurbs pickdepth \
picksquare plane planet polyoff polys quadric robot sccolorlight \
scene scenebamb sceneflat select smooth stencil stroke surface \
teaambient teapots tess tesswind texbind texgen texprox texsub \
texturesurf torus trim unproject varray wrap
##### RULES #####
.SUFFIXES:
.SUFFIXES: .c
.c: $(LIB_DEP)
$(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
##### TARGETS ######
default:
@echo "Specify a target configuration"
clean:
-rm *.o *~
realclean:
-rm $(PROGS)
-rm *.o *~
targets: $(PROGS)
# execute all programs
exec: $(PROGS)
@for prog in $(PROGS) ; \
do \
echo -n "Running $$prog ..." ; \
$$prog ; \
echo ; \
done
include ../Make-config

View file

@ -0,0 +1,81 @@
# Makefile for Win32
TOP = ..
!include "$(TOP)/names.win"
!include <win32.mak>
SRCS= \
accanti.c \
accnot.c \
accum.c \
aim.c \
alpha.c \
alpha3D.c \
anti.c \
antiindex.c \
antipindex.c \
antipoint.c \
antipoly.c \
bezcurve.c \
bezmesh.c \
bezsurf.c \
checker.c \
checker2.c \
chess.c \
clip.c \
colormat.c \
cone.c \
cube.c \
curve.c \
depthcue.c \
disk.c \
dof.c \
dofnot.c \
double.c \
drawf.c \
feedback.c \
fog.c \
fogindex.c \
font.c \
light.c \
linelist.c \
lines.c \
list.c \
list2.c \
maplight.c \
material.c \
mipmap.c \
model.c \
movelight.c \
nurbs.c \
pickdepth.c \
pickline.c \
picksquare.c \
plane.c \
planet.c \
planetup.c \
polys.c \
robot.c \
sccolorlight.c \
scene.c \
scenebamb.c \
sceneflat.c \
select.c \
smooth.c \
sphere.c \
stencil.c \
stroke.c \
surface.c \
tea.c \
teaambient.c \
teapots.c \
texgen.c \
texturesurf.c \
trim.c
EXTRALIBS = $(MESAGL).lib $(MESAGLU).lib $(MESATK).lib $(MESAAUX).lib
!include "$(TOP)/mesawin32.mak"

41
progs/redbook/README Normal file
View file

@ -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.

153
progs/redbook/aaindex.c Normal file
View file

@ -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;
}

172
progs/redbook/aapoly.c Normal file
View file

@ -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;
}

149
progs/redbook/aargb.c Normal file
View file

@ -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;
}

168
progs/redbook/accanti.c Normal file
View file

@ -0,0 +1,168 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/* accanti.c
*/
#include <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);
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB
| GLUT_ACCUM | GLUT_DEPTH);
glutInitWindowSize (250, 250);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

240
progs/redbook/accpersp.c Normal file
View file

@ -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;
}

143
progs/redbook/alpha.c Normal file
View file

@ -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;
}

175
progs/redbook/alpha3D.c Normal file
View file

@ -0,0 +1,175 @@
/*
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* alpha3D.c
* This program demonstrates how to intermix opaque and
* alpha blended polygons in the same scene, by using
* glDepthMask. Press the 'a' key to animate moving the
* transparent object through the opaque object. Press
* the 'r' key to reset the scene.
*/
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#define MAXZ 8.0
#define MINZ -8.0
#define ZINC 0.4
static float solidZ = MAXZ;
static float transparentZ = MINZ;
static GLuint sphereList, cubeList;
static void init(void)
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 0.15 };
GLfloat mat_shininess[] = { 100.0 };
GLfloat position[] = { 0.5, 0.5, 1.0, 0.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
sphereList = glGenLists(1);
glNewList(sphereList, GL_COMPILE);
glutSolidSphere (0.4, 16, 16);
glEndList();
cubeList = glGenLists(1);
glNewList(cubeList, GL_COMPILE);
glutSolidCube (0.6);
glEndList();
}
void display(void)
{
GLfloat mat_solid[] = { 0.75, 0.75, 0.0, 1.0 };
GLfloat mat_zero[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_transparent[] = { 0.0, 0.8, 0.8, 0.6 };
GLfloat mat_emission[] = { 0.0, 0.3, 0.3, 0.6 };
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (-0.15, -0.15, solidZ);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid);
glCallList (sphereList);
glPopMatrix ();
glPushMatrix ();
glTranslatef (0.15, 0.15, transparentZ);
glRotatef (15.0, 1.0, 1.0, 0.0);
glRotatef (30.0, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_transparent);
glEnable (GL_BLEND);
glDepthMask (GL_FALSE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
glCallList (cubeList);
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
glPopMatrix ();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else
glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void animate(void)
{
if (solidZ <= MINZ || transparentZ >= MAXZ)
glutIdleFunc(NULL);
else {
solidZ -= ZINC;
transparentZ += ZINC;
glutPostRedisplay();
}
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'a':
case 'A':
solidZ = MAXZ;
transparentZ = MINZ;
glutIdleFunc(animate);
break;
case 'r':
case 'R':
solidZ = MAXZ;
transparentZ = MINZ;
glutPostRedisplay();
break;
case 27:
exit(0);
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

111
progs/redbook/anti.c Normal file
View file

@ -0,0 +1,111 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* anti.c
* This program draws antialiased lines in RGBA mode.
*/
#include <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 */
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

114
progs/redbook/bezcurve.c Normal file
View file

@ -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;
}

148
progs/redbook/bezmesh.c Normal file
View file

@ -0,0 +1,148 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/**
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/* bezsurf.c
* This program renders a lighted, filled Bezier surface,
* using two-dimensional evaluators.
*/
#include <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();
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

125
progs/redbook/checker.c Normal file
View file

@ -0,0 +1,125 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/* checker.c
* This program texture maps a checkerboard image onto
* two rectangles. This program clamps the texture, if
* the texture coordinates fall outside 0.0 and 1.0.
*/
#include <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);
}
int
main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("checker");
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

108
progs/redbook/clip.c Normal file
View file

@ -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;
}

153
progs/redbook/colormat.c Normal file
View file

@ -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;
}

97
progs/redbook/cube.c Normal file
View file

@ -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;
}

102
progs/redbook/depthcue.c Normal file
View file

@ -0,0 +1,102 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* depthcue.c
* This program draws a wireframe model, which uses
* intensity (brightness) to give clues to distance.
* Fog is used to achieve this effect.
*/
#include <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 */
}
/* Main Loop
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

238
progs/redbook/dof.c Normal file
View file

@ -0,0 +1,238 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* dof.c
* This program demonstrates use of the accumulation buffer to
* create an out-of-focus depth-of-field effect. The teapots
* are drawn several times into the accumulation buffer. The
* viewing volume is jittered, except at the focal point, where
* the viewing volume is at the same position, each time. In
* this case, the gold teapot remains in focus.
*/
#include <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);
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, depth buffer, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB
| GLUT_ACCUM | GLUT_DEPTH);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

119
progs/redbook/double.c Normal file
View file

@ -0,0 +1,119 @@
/*
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* double.c
* This is a simple double buffered program.
* Pressing the left mouse button rotates the rectangle.
* Pressing the middle mouse button stops the rotation.
*/
#include <GL/glut.h>
#include <stdlib.h>
static GLfloat spin = 0.0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
}
void spinDisplay(void)
{
spin = spin + 2.0;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* ARGSUSED2 */
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay);
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(NULL);
break;
default:
break;
}
}
/*
* Request double buffer display mode.
* Register mouse input callback functions
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

103
progs/redbook/drawf.c Normal file
View file

@ -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;
}

171
progs/redbook/feedback.c Normal file
View file

@ -0,0 +1,171 @@
/*
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* feedback.c
* This program demonstrates use of OpenGL feedback. First,
* a lighting environment is set up and a few lines are drawn.
* Then feedback mode is entered, and the same lines are
* drawn. The results in the feedback buffer are printed.
*/
#include <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);
}
/* 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;
}

186
progs/redbook/fog.c Normal file
View file

@ -0,0 +1,186 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/**
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* fog.c
* This program draws 5 red teapots, each at a different
* z distance from the eye, in different types of fog.
* Pressing the left mouse button chooses between 3 types of
* fog: exponential, exponential squared, and linear.
* In this program, there is a fixed density value, as well
* as fixed start and end values for the linear fog.
*/
#include <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();
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, depth buffer, and handle input events.
*/
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(450, 150);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutCreateMenu(selectFog);
glutAddMenuEntry("Fog EXP", GL_EXP);
glutAddMenuEntry("Fog EXP2", GL_EXP2);
glutAddMenuEntry("Fog LINEAR", GL_LINEAR);
glutAddMenuEntry("Quit", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

138
progs/redbook/fogindex.c Normal file
View file

@ -0,0 +1,138 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* fogindex.c
* This program demonstrates fog in color index mode.
* Three cones are drawn at different z values in a linear
* fog. 32 contiguous colors (from 16 to 47) are loaded
* with a color ramp.
*/
#include <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();
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, depth buffer, and handle input events.
*/
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX | GLUT_DEPTH);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

167
progs/redbook/font.c Normal file
View file

@ -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;
}

95
progs/redbook/hello.c Normal file
View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* hello.c
* This is a simple, introductory OpenGL program.
*/
#include <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);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

159
progs/redbook/image.c Normal file
View file

@ -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;
}

222
progs/redbook/jitter.h Normal file
View file

@ -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}
};

113
progs/redbook/light.c Normal file
View file

@ -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;
}

138
progs/redbook/lines.c Normal file
View file

@ -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;
}

125
progs/redbook/list.c Normal file
View file

@ -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;
}

293
progs/redbook/material.c Normal file
View file

@ -0,0 +1,293 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* material.c
* This program demonstrates the use of the GL lighting model.
* Several objects are drawn using different material characteristics.
* A single light source illuminates the objects.
*/
#include <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);
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (600, 450);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

165
progs/redbook/mipmap.c Normal file
View file

@ -0,0 +1,165 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/* mipmap.c
* This program demonstrates using mipmaps for texture maps.
* To overtly show the effect of mipmaps, each mipmap reduction
* level has a solidly colored, contrasting texture image.
* Thus, the quadrilateral which is drawn is drawn with several
* different colors.
*/
#include <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();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

126
progs/redbook/model.c Normal file
View file

@ -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;
}

148
progs/redbook/movelight.c Normal file
View file

@ -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;
}

176
progs/redbook/nurbs.c Normal file
View file

@ -0,0 +1,176 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* nurbs.c
* This program shows a NURBS (Non-uniform rational B-splines)
* surface, shaped like a heart.
*/
#include <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);
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

203
progs/redbook/pickdepth.c Normal file
View file

@ -0,0 +1,203 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* pickdepth.c
* Picking is demonstrated in this program. In
* rendering mode, three overlapping rectangles are
* drawn. When the left mouse button is pressed,
* selection mode is entered with the picking matrix.
* Rectangles which are drawn under the cursor position
* are "picked." Pay special attention to the depth
* value range, which is returned.
*/
#include <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[])
{
unsigned int i, j;
GLuint names, *ptr;
printf("hits = %d\n", hits);
ptr = (GLuint *) buffer;
for (i = 0; i < hits; i++) { /* for each hit */
names = *ptr;
printf(" number of names for hit = %d\n", names);
ptr++;
printf(" z1 is %g;", (float) *ptr/0xffffffff);
ptr++;
printf(" z2 is %g\n", (float) *ptr/0xffffffff);
ptr++;
printf(" the name is ");
for (j = 0; j < names; j++) { /* for each name */
printf("%d ", *ptr);
ptr++;
}
printf("\n");
}
}
/* pickRects() sets up selection mode, name stack,
* and projection matrix for picking. Then the objects
* are drawn.
*/
#define BUFSIZE 512
void
pickRects(int button, int state, int x, int y)
{
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
return;
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFSIZE, selectBuf);
(void) glRenderMode(GL_SELECT);
glInitNames();
glPushName(-1);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),
5.0, 5.0, viewport);
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
drawRects(GL_SELECT);
glPopMatrix();
glFlush();
hits = glRenderMode(GL_RENDER);
processHits(hits, selectBuf);
}
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawRects(GL_RENDER);
glutSwapBuffers();
}
void
myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, depth buffer, and handle input events.
*/
int
main(int argc, char **argv)
{
glutInitWindowSize(200, 200);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInit(&argc, argv);
glutCreateWindow(argv[0]);
myinit();
glutMouseFunc(pickRects);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

197
progs/redbook/picksquare.c Normal file
View file

@ -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[])
{
unsigned int i, j;
GLuint ii, jj, names, *ptr;
printf ("hits = %d\n", hits);
ptr = (GLuint *) buffer;
for (i = 0; i < hits; i++) { /* for each hit */
names = *ptr;
printf (" number of names for this hit = %d\n", names); ptr++;
printf(" z1 is %g;", (float) *ptr/0x7fffffff); ptr++;
printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++;
printf (" names are ");
for (j = 0; j < names; j++) { /* for each name */
printf ("%d ", *ptr);
if (j == 0) /* set row and column */
ii = *ptr;
else if (j == 1)
jj = *ptr;
ptr++;
}
printf ("\n");
board[ii][jj] = (board[ii][jj] + 1) % 3;
}
}
/* pickSquares() sets up selection mode, name stack,
* and projection matrix for picking. Then the
* objects are drawn.
*/
#define BUFSIZE 512
void pickSquares(int button, int state, int x, int y)
{
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
return;
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (BUFSIZE, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
5.0, 5.0, viewport);
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
drawSquares (GL_SELECT);
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glFlush ();
hits = glRenderMode (GL_RENDER);
processHits (hits, selectBuf);
glutPostRedisplay();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
drawSquares (GL_RENDER);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
/* Main Loop */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (100, 100);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutReshapeFunc (reshape);
glutDisplayFunc(display);
glutMouseFunc (pickSquares);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}

157
progs/redbook/plane.c Normal file
View file

@ -0,0 +1,157 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* plane.c
* This program demonstrates the use of local versus
* infinite lighting on a flat plane.
*/
#include <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);
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 200);
glutCreateWindow (argv[0]);
myinit();
glutReshapeFunc (myReshape);
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

123
progs/redbook/planet.c Normal file
View file

@ -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;
}

237
progs/redbook/polyoff.c Normal file
View file

@ -0,0 +1,237 @@
/*
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* polyoff.c
* This program demonstrates polygon offset to draw a shaded
* polygon and its wireframe counterpart without ugly visual
* artifacts ("stitching").
*/
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef GL_VERSION_1_1
GLuint list;
GLint spinx = 0;
GLint spiny = 0;
GLfloat tdist = 0.0;
GLfloat polyfactor = 1.0;
GLfloat polyunits = 1.0;
/* display() draws two spheres, one with a gray, diffuse material,
* the other sphere with a magenta material with a specular highlight.
*/
void display (void)
{
GLfloat gray[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat black[] = { 0.0, 0.0, 0.0, 1.0 };
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (0.0, 0.0, tdist);
glRotatef ((GLfloat) spinx, 1.0, 0.0, 0.0);
glRotatef ((GLfloat) spiny, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
glMaterialfv(GL_FRONT, GL_SPECULAR, black);
glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(polyfactor, polyunits);
glCallList (list);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glColor3f (1.0, 1.0, 1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glCallList (list);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPopMatrix ();
glFlush ();
}
/* specify initial properties
* create display list with sphere
* initialize lighting and depth buffer
*/
void gfxinit (void)
{
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat global_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
glClearColor (0.0, 0.0, 0.0, 1.0);
list = glGenLists(1);
glNewList (list, GL_COMPILE);
glutSolidSphere(1.0, 20, 12);
glEndList ();
glEnable(GL_DEPTH_TEST);
glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv (GL_LIGHT0, GL_POSITION, light_position);
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, global_ambient);
}
/* call when window is resized */
void reshape(int width, int height)
{
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(45.0, (GLdouble)width/(GLdouble)height,
1.0, 10.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
/* call when mouse button is pressed */
/* ARGSUSED2 */
void mouse(int button, int state, int x, int y) {
switch (button) {
case GLUT_LEFT_BUTTON:
switch (state) {
case GLUT_DOWN:
spinx = (spinx + 5) % 360;
glutPostRedisplay();
break;
default:
break;
}
break;
case GLUT_MIDDLE_BUTTON:
switch (state) {
case GLUT_DOWN:
spiny = (spiny + 5) % 360;
glutPostRedisplay();
break;
default:
break;
}
break;
case GLUT_RIGHT_BUTTON:
switch (state) {
case GLUT_UP:
exit(0);
break;
default:
break;
}
break;
default:
break;
}
}
/* ARGSUSED1 */
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 't':
if (tdist < 4.0) {
tdist = (tdist + 0.5);
glutPostRedisplay();
}
break;
case 'T':
if (tdist > -5.0) {
tdist = (tdist - 0.5);
glutPostRedisplay();
}
break;
case 'F':
polyfactor = polyfactor + 0.1;
printf ("polyfactor is %f\n", polyfactor);
glutPostRedisplay();
break;
case 'f':
polyfactor = polyfactor - 0.1;
printf ("polyfactor is %f\n", polyfactor);
glutPostRedisplay();
break;
case 'U':
polyunits = polyunits + 1.0;
printf ("polyunits is %f\n", polyunits);
glutPostRedisplay();
break;
case 'u':
polyunits = polyunits - 1.0;
printf ("polyunits is %f\n", polyunits);
glutPostRedisplay();
break;
default:
break;
}
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow(argv[0]);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
gfxinit();
glutMainLoop();
return 0;
}
#else
int main(int argc, char** argv)
{
fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
fprintf (stderr, "you may be able to modify this program to make it run.\n");
return 0;
}
#endif

124
progs/redbook/polys.c Normal file
View file

@ -0,0 +1,124 @@
/* Copyright (c) Mark J. Kilgard, 1994. */
/*
* (c) Copyright 1993, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* polys.c
* This program demonstrates polygon stippling.
*/
#include <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();
}
/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (350, 150);
glutCreateWindow (argv[0]);
myinit ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

Some files were not shown because too many files have changed in this diff Show more