diff options
author | Julien Cristau <[email protected]> | 2008-07-01 13:17:44 +0200 |
---|---|---|
committer | Julien Cristau <[email protected]> | 2008-07-01 13:18:27 +0200 |
commit | 374be37dd904b8dc7b91b4b782a6b7b46b00afba (patch) | |
tree | 2562d5fcf4183bdc67d6c418513e1f562dddfe20 /progs/demos | |
parent | 2b831e73f5027850837e613636915c7dd6c7078a (diff) | |
parent | d3f7b463c3975c070503053e4ad70af99016a756 (diff) |
Merge branch 'master' of git.freedesktop.org:/git/mesa/mesa into debian-experimental
Conflicts:
.gitignore
Makefile
bin/mklib
configs/.gitignore
configs/default
configs/freebsd
configs/freebsd-dri
configs/linux-osmesa
configs/linux-osmesa16
configs/linux-osmesa16-static
configs/linux-osmesa32
docs/download.html
docs/install.html
docs/news.html
docs/relnotes.html
doxygen/Makefile
doxygen/doxy.bat
doxygen/header.html
doxygen/header_subset.html
include/GL/internal/dri_interface.h
progs/demos/.gitignore
progs/directfb/Makefile
progs/egl/Makefile
progs/fbdev/Makefile
progs/fbdev/glfbdevtest.c
progs/fp/Makefile
progs/glsl/.gitignore
progs/glsl/Makefile
progs/glsl/bump.c
progs/glsl/mandelbrot.c
progs/glsl/noise.c
progs/glsl/toyball.c
progs/miniglx/Makefile
progs/samples/.gitignore
progs/slang/Makefile
progs/tests/.gitignore
progs/tests/Makefile
progs/tests/arbnpot.c
progs/tests/cva.c
progs/tests/dinoshade.c
progs/tests/drawbuffers.c
progs/tests/fbotest2.c
progs/tests/fbotexture.c
progs/tests/getprocaddress.c
progs/tests/mipmap_limits.c
progs/tests/multipal.c
progs/tests/texline.c
progs/tools/trace/Makefile
progs/trivial/Makefile
progs/trivial/dlist-edgeflag-dangling.c
progs/trivial/dlist-edgeflag.c
progs/trivial/point-param.c
progs/trivial/quad-clip-nearplane.c
progs/trivial/tri.c
progs/vp/Makefile
progs/xdemos/.gitignore
progs/xdemos/Makefile
progs/xdemos/glthreads.c
src/egl/Makefile
src/egl/drivers/demo/Makefile
src/egl/drivers/dri/Makefile
src/egl/main/Makefile
src/glu/mesa/Makefile
src/glu/mesa/Makefile.m32
src/glu/mesa/project.c
src/glu/mini/project.c
src/glut/directfb/Makefile
src/glut/directfb/callback.c
src/glut/directfb/events.c
src/glut/directfb/internal.h
src/glut/directfb/window.c
src/glut/os2/Makefile
src/glut/os2/WarpWin.cpp
src/glut/os2/glutOverlay.cpp
src/glut/os2/glut_8x13.cpp
src/glut/os2/glut_9x15.cpp
src/glut/os2/glut_bitmap.cpp
src/glut/os2/glut_cindex.cpp
src/glut/os2/glut_cmap.cpp
src/glut/os2/glut_cursor.cpp
src/glut/os2/glut_event.cpp
src/glut/os2/glut_ext.cpp
src/glut/os2/glut_fullscrn.cpp
src/glut/os2/glut_gamemode.cpp
src/glut/os2/glut_get.cpp
src/glut/os2/glut_hel10.cpp
src/glut/os2/glut_hel12.cpp
src/glut/os2/glut_hel18.cpp
src/glut/os2/glut_init.cpp
src/glut/os2/glut_input.cpp
src/glut/os2/glut_key.cpp
src/glut/os2/glut_keyctrl.cpp
src/glut/os2/glut_keyup.cpp
src/glut/os2/glut_mesa.cpp
src/glut/os2/glut_modifier.cpp
src/glut/os2/glut_roman.cpp
src/glut/os2/glut_shapes.cpp
src/glut/os2/glut_stroke.cpp
src/glut/os2/glut_swap.cpp
src/glut/os2/glut_teapot.cpp
src/glut/os2/glut_tr24.cpp
src/glut/os2/glut_util.cpp
src/glut/os2/glut_vidresize.cpp
src/glut/os2/glut_warp.cpp
src/glut/os2/glut_win.cpp
src/glut/os2/glut_winmisc.cpp
src/glut/os2/glutbitmap.h
src/glut/os2/glutstroke.h
src/glut/os2/layerutil.h
src/glut/os2/libGlut.DEF
src/glut/os2/os2_glx.cpp
src/glut/os2/os2_menu.cpp
src/glut/os2/os2_winproc.cpp
src/glw/Makefile
src/glx/mini/Makefile
src/glx/mini/miniglx.c
src/glx/x11/glxext.c
src/mesa/Makefile
src/mesa/drivers/allegro/amesa.c
src/mesa/drivers/allegro/direct.h
src/mesa/drivers/allegro/generic.h
src/mesa/drivers/d3d/D3DCAPS.CPP
src/mesa/drivers/d3d/D3DHAL.H
src/mesa/drivers/d3d/D3DInit.cpp
src/mesa/drivers/d3d/D3DMESA.H
src/mesa/drivers/d3d/D3DRaster.cpp
src/mesa/drivers/d3d/D3DTEXT.CPP
src/mesa/drivers/d3d/D3DTextureMgr.cpp
src/mesa/drivers/d3d/D3DTextureMgr.h
src/mesa/drivers/d3d/D3DUTILS.CPP
src/mesa/drivers/d3d/DDrawPROCS.c
src/mesa/drivers/d3d/DEBUG.C
src/mesa/drivers/d3d/DEBUG.H
src/mesa/drivers/d3d/DbgEnv.bat
src/mesa/drivers/d3d/MAKEFILE
src/mesa/drivers/d3d/OPENGL32.DEF
src/mesa/drivers/d3d/WGL.C
src/mesa/drivers/dri/Makefile.template
src/mesa/drivers/dri/common/dri_bufmgr.c
src/mesa/drivers/dri/common/dri_drmpool.c
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/common/dri_util.h
src/mesa/drivers/dri/common/xmlconfig.c
src/mesa/drivers/dri/glcore/Makefile
src/mesa/drivers/dri/i915/i915_fragprog.c
src/mesa/drivers/dri/i915/i915_program.h
src/mesa/drivers/dri/i915/i915_texprog.c
src/mesa/drivers/dri/i915/i915_texstate.c
src/mesa/drivers/dri/i915/i915_vtbl.c
src/mesa/drivers/dri/i915/intel_context.c
src/mesa/drivers/dri/i915/intel_context.h
src/mesa/drivers/dri/i915/intel_pixel.c
src/mesa/drivers/dri/i915/intel_render.c
src/mesa/drivers/dri/i915/intel_screen.c
src/mesa/drivers/dri/i915/intel_state.c
src/mesa/drivers/dri/i915/intel_tex.c
src/mesa/drivers/dri/i915/intel_tris.c
src/mesa/drivers/dri/i915tex/i830_reg.h
src/mesa/drivers/dri/i915tex/i830_texstate.c
src/mesa/drivers/dri/i915tex/i830_vtbl.c
src/mesa/drivers/dri/i915tex/i915_fragprog.c
src/mesa/drivers/dri/i915tex/i915_metaops.c
src/mesa/drivers/dri/i915tex/i915_tex_layout.c
src/mesa/drivers/dri/i915tex/i915_texstate.c
src/mesa/drivers/dri/i915tex/i915_vtbl.c
src/mesa/drivers/dri/i915tex/intel_render.c
src/mesa/drivers/dri/i915tex/intel_screen.c
src/mesa/drivers/dri/i915tex/intel_tris.c
src/mesa/drivers/dri/i965/brw_aub.c
src/mesa/drivers/dri/i965/brw_aub_playback.c
src/mesa/drivers/dri/i965/brw_cc.c
src/mesa/drivers/dri/i965/brw_clip.c
src/mesa/drivers/dri/i965/brw_clip_state.c
src/mesa/drivers/dri/i965/brw_clip_util.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_curbe.c
src/mesa/drivers/dri/i965/brw_defines.h
src/mesa/drivers/dri/i965/brw_draw.c
src/mesa/drivers/dri/i965/brw_draw_upload.c
src/mesa/drivers/dri/i965/brw_eu.h
src/mesa/drivers/dri/i965/brw_eu_emit.c
src/mesa/drivers/dri/i965/brw_gs_state.c
src/mesa/drivers/dri/i965/brw_misc_state.c
src/mesa/drivers/dri/i965/brw_sf_emit.c
src/mesa/drivers/dri/i965/brw_sf_state.c
src/mesa/drivers/dri/i965/brw_state_cache.c
src/mesa/drivers/dri/i965/brw_state_pool.c
src/mesa/drivers/dri/i965/brw_tex.c
src/mesa/drivers/dri/i965/brw_tex_layout.c
src/mesa/drivers/dri/i965/brw_vs_state.c
src/mesa/drivers/dri/i965/brw_vs_tnl.c
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm.h
src/mesa/drivers/dri/i965/brw_wm_glsl.c
src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
src/mesa/drivers/dri/i965/brw_wm_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/bufmgr_fake.c
src/mesa/drivers/dri/i965/intel_batchbuffer.c
src/mesa/drivers/dri/i965/intel_batchbuffer.h
src/mesa/drivers/dri/i965/intel_blit.c
src/mesa/drivers/dri/i965/intel_blit.h
src/mesa/drivers/dri/i965/intel_buffers.c
src/mesa/drivers/dri/i965/intel_context.c
src/mesa/drivers/dri/i965/intel_context.h
src/mesa/drivers/dri/i965/intel_mipmap_tree.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.h
src/mesa/drivers/dri/i965/intel_pixel_bitmap.c
src/mesa/drivers/dri/i965/intel_pixel_copy.c
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/drivers/dri/i965/intel_tex_validate.c
src/mesa/drivers/dri/i965/server/i830_common.h
src/mesa/drivers/dri/intel/intel_batchbuffer.c
src/mesa/drivers/dri/intel/intel_batchbuffer.h
src/mesa/drivers/dri/intel/intel_blit.c
src/mesa/drivers/dri/intel/intel_buffers.c
src/mesa/drivers/dri/intel/intel_context.c
src/mesa/drivers/dri/intel/intel_context.h
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.h
src/mesa/drivers/dri/intel/intel_screen.h
src/mesa/drivers/dri/r200/r200_texstate.c
src/mesa/drivers/dri/r300/r300_cmdbuf.c
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_ioctl.c
src/mesa/drivers/dri/r300/r300_reg.h
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_tex.h
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/windows/gdi/wmesa.c
src/mesa/drivers/x11/fakeglx.c
src/mesa/drivers/x11/xm_dd.c
src/mesa/glapi/Makefile
src/mesa/glapi/dispatch.h
src/mesa/glapi/glapioffsets.h
src/mesa/glapi/glapitable.h
src/mesa/glapi/glapitemp.h
src/mesa/glapi/glprocs.h
src/mesa/main/api_validate.c
src/mesa/main/attrib.c
src/mesa/main/config.h
src/mesa/main/context.c
src/mesa/main/context.h
src/mesa/main/dlist.c
src/mesa/main/drawpix.c
src/mesa/main/enums.c
src/mesa/main/fbobject.c
src/mesa/main/image.c
src/mesa/main/imports.h
src/mesa/main/mtypes.h
src/mesa/main/points.c
src/mesa/main/state.c
src/mesa/main/texcompress_fxt1.c
src/mesa/main/texenvprogram.c
src/mesa/main/teximage.c
src/mesa/main/texobj.c
src/mesa/main/texstate.c
src/mesa/main/version.h
src/mesa/shader/prog_execute.c
src/mesa/shader/program.c
src/mesa/shader/shader_api.c
src/mesa/shader/slang/library/slang_core.gc
src/mesa/shader/slang/library/slang_core_gc.h
src/mesa/shader/slang/slang_codegen.c
src/mesa/sources
src/mesa/sparc/glapi_sparc.S
src/mesa/swrast/s_aalinetemp.h
src/mesa/swrast/s_aatriangle.c
src/mesa/swrast/s_aatritemp.h
src/mesa/swrast/s_context.c
src/mesa/swrast/s_copypix.c
src/mesa/swrast/s_drawpix.c
src/mesa/swrast/s_fragprog.c
src/mesa/swrast/s_pointtemp.h
src/mesa/swrast/s_readpix.c
src/mesa/swrast/s_span.c
src/mesa/swrast/s_texfilter.c
src/mesa/swrast/s_tritemp.h
src/mesa/swrast/s_zoom.c
src/mesa/tnl/t_draw.c
src/mesa/tnl/t_vb_fog.c
src/mesa/tnl/t_vb_program.c
src/mesa/tnl/t_vp_build.c
src/mesa/vbo/vbo_split_copy.c
src/mesa/x86-64/xform4.S
src/mesa/x86/common_x86.c
src/mesa/x86/glapi_x86.S
windows/VC6/mesa/mesa/mesa.dsp
Diffstat (limited to 'progs/demos')
-rw-r--r-- | progs/demos/.gitignore | 63 | ||||
-rw-r--r-- | progs/demos/Makefile | 22 | ||||
-rw-r--r-- | progs/demos/copypix.c | 248 | ||||
-rw-r--r-- | progs/demos/cubemap.c | 51 | ||||
-rw-r--r-- | progs/demos/descrip.mms | 52 | ||||
-rw-r--r-- | progs/demos/engine.c | 19 | ||||
-rw-r--r-- | progs/demos/gears.c | 37 | ||||
-rw-r--r-- | progs/demos/geartrain.dat | 238 | ||||
-rw-r--r--[-rwxr-xr-x] | progs/demos/glslnoise.c | 0 | ||||
-rw-r--r-- | progs/demos/lodbias.c | 12 | ||||
-rw-r--r-- | progs/demos/multiarb.c | 123 | ||||
-rw-r--r-- | progs/demos/rain.cxx | 1 | ||||
-rw-r--r-- | progs/demos/readtex.c | 454 | ||||
-rw-r--r-- | progs/demos/readtex.h | 26 | ||||
-rw-r--r-- | progs/demos/shadowtex.c | 373 | ||||
-rw-r--r-- | progs/demos/showbuffer.c | 192 | ||||
-rw-r--r-- | progs/demos/showbuffer.h | 36 | ||||
-rw-r--r-- | progs/demos/spriteblast.c | 22 | ||||
-rw-r--r-- | progs/demos/streaming_rect.c | 25 | ||||
-rw-r--r-- | progs/demos/texenv.c | 4 | ||||
-rw-r--r-- | progs/demos/trackball.c | 338 | ||||
-rw-r--r-- | progs/demos/trackball.h | 84 |
22 files changed, 983 insertions, 1437 deletions
diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore new file mode 100644 index 00000000000..ab836eb8340 --- /dev/null +++ b/progs/demos/.gitignore @@ -0,0 +1,63 @@ +.cvsignore +arbfplight +arbfslight +arbocclude +bounce +clearspd +copypix +cubemap +drawpix +engine +extfuncs.h +fire +fogcoord +fplight +fslight +gamma +gearbox +gears +geartrain +glinfo +gloss +glslnoise +gltestperf +glutfx +ipers +isosurf +lodbias +morph3d +multiarb +occlude +osdemo +paltex +pixeltex +pointblast +rain +ray +readpix +readtex.c +readtex.h +reflect +renormal +shadowtex +showbuffer.c +showbuffer.h +singlebuffer +spectex +spriteblast +stex3d +streaming_rect +teapot +terrain +tessdemo +texcyl +texdown +texenv +texobj +trackball.c +trackball.h +trispd +tunnel +tunnel2 +vao_demo +winpos diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 1014ccce893..7fde77f0b41 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -11,9 +11,11 @@ OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa16 -lGLU -lGL $(APP_LIB_DEPS) OSMESA32_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa32 -lGLU -lGL $(APP_LIB_DEPS) -LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) +LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) \ + $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) \ + $(APP_LIB_DEPS) PROGS = \ arbfplight \ @@ -21,6 +23,7 @@ PROGS = \ arbocclude \ bounce \ clearspd \ + copypix \ cubemap \ drawpix \ engine \ @@ -44,6 +47,7 @@ PROGS = \ multiarb \ paltex \ pointblast \ + rain \ ray \ readpix \ reflect \ @@ -72,7 +76,7 @@ PROGS = \ .SUFFIXES: .SUFFIXES: .c - +.SUFFIXES: .cxx # make executable from .c file: .c: $(LIB_DEP) readtex.o @@ -153,6 +157,18 @@ fslight: fslight.o fslight.o: fslight.c extfuncs.h $(CC) -c -I$(INCDIR) $(CFLAGS) fslight.c +rain: particles.o rain.o readtex.o + $(CXX) $(LDFLAGS) $^ $(LIBS) -o $@ + +rain.o: rain.cxx readtex.h + $(CXX) -c -I$(INCDIR) $(CXXFLAGS) $< + +particles.o: particles.cxx + $(CXX) -c -I$(INCDIR) $(CXXFLAGS) $< + + +viewdds: viewdds.c + $(CC) -I$(INCDIR) $(CFLAGS) $< readtex.o $(LIBS) -L. -lgltc -o $@ clean: diff --git a/progs/demos/copypix.c b/progs/demos/copypix.c new file mode 100644 index 00000000000..15001e851be --- /dev/null +++ b/progs/demos/copypix.c @@ -0,0 +1,248 @@ +/** + * glCopyPixels test + * + * Brian Paul + * 14 Sep 2007 + */ + + +#define GL_GLEXT_PROTOTYPES + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define IMAGE_FILE "../images/arch.rgb" + +static int ImgWidth, ImgHeight; +static GLenum ImgFormat; +static GLubyte *Image = NULL; + +static int WinWidth = 800, WinHeight = 800; +static int Xpos, Ypos; +static int Scissor = 0; +static float Xzoom, Yzoom; +static GLboolean DrawFront = GL_FALSE; +static GLboolean Dither = GL_TRUE; + + +static void Reset( void ) +{ + Xpos = Ypos = 20; + Scissor = 0; + Xzoom = Yzoom = 1.0; +} + + +static void Display( void ) +{ + const int dx = (WinWidth - ImgWidth) / 2; + const int dy = (WinHeight - ImgHeight) / 2; + + if (DrawFront) { + glDrawBuffer(GL_FRONT); + glReadBuffer(GL_FRONT); + } + else { + glDrawBuffer(GL_BACK); + glReadBuffer(GL_BACK); + } + + glClear( GL_COLOR_BUFFER_BIT ); + + /* draw original image */ + glWindowPos2iARB(dx, dy); + glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + + if (Scissor) + glEnable(GL_SCISSOR_TEST); + + /* draw copy */ + glPixelZoom(Xzoom, Yzoom); + glWindowPos2iARB(Xpos, Ypos); + glCopyPixels(dx, dy, ImgWidth, ImgHeight, GL_COLOR); + glPixelZoom(1, 1); + + glDisable(GL_SCISSOR_TEST); + + if (DrawFront) + glFinish(); + else + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + WinWidth = width; + WinHeight = height; + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, width, 0.0, height, 0.0, 2.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glScissor(width/4, height/4, width/2, height/2); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case ' ': + Reset(); + break; + case 'd': + Dither = !Dither; + if (Dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); + break; + case '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 'f': + DrawFront = !DrawFront; + printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const int step = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? 10 : 1; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + Ypos += step; + break; + case GLUT_KEY_DOWN: + Ypos -= step; + break; + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( GLboolean ciMode, const char *filename ) +{ + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat ); + if (!Image) { + printf("Couldn't read %s\n", filename); + exit(0); + } + + if (ciMode) { + /* Convert RGB image to grayscale */ + GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i<ImgWidth*ImgHeight; i++) { + int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; + indexImage[i] = gray / 3; + } + free(Image); + Image = indexImage; + ImgFormat = GL_COLOR_INDEX; + + for (i=0;i<255;i++) { + float g = i / 255.0; + glutSetColor(i, g, g, g); + } + } + + printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); + + Reset(); +} + + +static void Usage(void) +{ + printf("Keys:\n"); + printf(" SPACE Reset Parameters\n"); + printf(" Up/Down Move image up/down (SHIFT for large step)\n"); + printf(" Left/Right Move image left/right (SHIFT for large step)\n"); + printf(" x Decrease X-axis PixelZoom\n"); + printf(" X Increase X-axis PixelZoom\n"); + printf(" y Decrease Y-axis PixelZoom\n"); + printf(" Y Increase Y-axis PixelZoom\n"); + printf(" s Toggle GL_SCISSOR_TEST\n"); + printf(" f Toggle front/back buffer drawing\n"); + printf(" ESC Exit\n"); +} + + +int main( int argc, char *argv[] ) +{ + GLboolean ciMode = GL_FALSE; + const char *filename = IMAGE_FILE; + int i = 1; + + if (argc > i && strcmp(argv[i], "-ci")==0) { + ciMode = GL_TRUE; + i++; + } + if (argc > i) { + filename = argv[i]; + } + + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( WinWidth, WinHeight ); + + if (ciMode) + glutInitDisplayMode( GLUT_INDEX | GLUT_DOUBLE ); + else + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE); + + glutCreateWindow(argv[0]); + + Init(ciMode, filename); + Usage(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + + glutMainLoop(); + return 0; +} diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c index ef5d2355509..b3bdd64f68d 100644 --- a/progs/demos/cubemap.c +++ b/progs/demos/cubemap.c @@ -47,6 +47,8 @@ static GLfloat Xrot = 0, Yrot = 0; static GLfloat EyeDist = 10; static GLboolean use_vertex_arrays = GL_FALSE; static GLboolean anim = GL_TRUE; +static GLboolean NoClear = GL_FALSE; +static GLint FrameParity = 0; #define eps1 0.99 #define br 20.0 /* box radius */ @@ -156,7 +158,30 @@ static void draw_skybox( void ) static void draw( void ) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if (NoClear) { + /* This demonstrates how we can avoid calling glClear. + * This method only works if every pixel in the window is painted for + * every frame. + * We can simply skip clearing of the color buffer in this case. + * For the depth buffer, we alternately use a different subrange of + * the depth buffer for each frame. For the odd frame use the range + * [0, 0.5] with GL_LESS. For the even frames, use the range [1, 0.5] + * with GL_GREATER. + */ + FrameParity = 1 - FrameParity; + if (FrameParity) { + glDepthRange(0.0, 0.5); + glDepthFunc(GL_LESS); + } + else { + glDepthRange(1.0, 0.5); + glDepthFunc(GL_GREATER); + } + } + else { + /* ordinary clearing */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } glPushMatrix(); /*MODELVIEW*/ glTranslatef( 0.0, 0.0, -EyeDist ); @@ -452,6 +477,24 @@ static void usage(void) } +static void parse_args(int argc, char *argv[]) +{ + int initFlag = 0; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-i") == 0) + initFlag = 1; + else if (strcmp(argv[i], "--noclear") == 0) + NoClear = GL_TRUE; + else { + fprintf(stderr, "Bad option: %s\n", argv[i]); + exit(1); + } + } + init (initFlag); +} + int main( int argc, char *argv[] ) { glutInit(&argc, argv); @@ -459,17 +502,13 @@ int main( int argc, char *argv[] ) glutInitWindowSize(600, 500); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); glutCreateWindow("Texture Cube Mapping"); - - if (argc > 1 && strcmp(argv[1] , "-i") == 0) - init( 1 ); - else - init( 0 ); glutReshapeFunc( reshape ); glutKeyboardFunc( key ); glutSpecialFunc( specialkey ); glutDisplayFunc( draw ); if (anim) glutIdleFunc(idle); + parse_args(argc, argv); usage(); glutMainLoop(); return 0; diff --git a/progs/demos/descrip.mms b/progs/demos/descrip.mms index a374fdf13d0..d7a912133ac 100644 --- a/progs/demos/descrip.mms +++ b/progs/demos/descrip.mms @@ -1,6 +1,6 @@ # Makefile for GLUT-based demo programs for VMS -# contributed by Jouk Jansen [email protected] -# Last update : 20 May 2005 +# contributed by Jouk Jansen [email protected] +# Last update : 30 November 2007 .first define gl [--.include.gl] @@ -21,10 +21,10 @@ LIB_DEP = [--.lib]$(GL_LIB) [--.lib]$(GLU_LIB) [--.lib]$(GLUT_LIB) .endif -PROGS = bounce.exe;,clearspd.exe;,drawpix.exe;,gamma.exe;,gears.exe;,\ - glinfo.exe;,glutfx.exe;,isosurf.exe;,morph3d.exe;,\ - paltex.exe;,pointblast.exe;,reflect.exe;,spectex.exe;,stex3d.exe;,\ - tessdemo.exe;,texcyl.exe;,texobj.exe;,trispd.exe;,winpos.exe; +PROGS = bounce.exe,clearspd.exe,drawpix.exe,gamma.exe,gears.exe,\ + glinfo.exe,glutfx.exe,isosurf.exe,morph3d.exe,\ + paltex.exe,pointblast.exe,reflect.exe,spectex.exe,stex3d.exe,\ + tessdemo.exe,texcyl.exe,texobj.exe,trispd.exe,winpos.exe ##### RULES ##### @@ -39,33 +39,33 @@ clean : delete *.obj;* realclean : - delete $(PROGS) + delete *.exe;* delete *.obj;* -bounce.exe; : bounce.obj $(LIB_DEP) -clearspd.exe; : clearspd.obj $(LIB_DEP) -drawpix.exe; : drawpix.obj $(LIB_DEP) [-.util]readtex.obj +bounce.exe : bounce.obj $(LIB_DEP) +clearspd.exe : clearspd.obj $(LIB_DEP) +drawpix.exe : drawpix.obj $(LIB_DEP) [-.util]readtex.obj cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) -gamma.exe; : gamma.obj $(LIB_DEP) -gears.exe; : gears.obj $(LIB_DEP) -glinfo.exe; : glinfo.obj $(LIB_DEP) -glutfx.exe; : glutfx.obj $(LIB_DEP) -isosurf.exe; : isosurf.obj $(LIB_DEP) [-.util]readtex.obj +gamma.exe : gamma.obj $(LIB_DEP) +gears.exe : gears.obj $(LIB_DEP) +glinfo.exe : glinfo.obj $(LIB_DEP) +glutfx.exe : glutfx.obj $(LIB_DEP) +isosurf.exe : isosurf.obj $(LIB_DEP) [-.util]readtex.obj cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) -morph3d.exe; : morph3d.obj $(LIB_DEP) -paltex.exe; : paltex.obj $(LIB_DEP) -pointblast.exe; : pointblast.obj $(LIB_DEP) -reflect.exe; : reflect.obj [-.util]readtex.obj [-.util]showbuffer.obj\ +morph3d.exe : morph3d.obj $(LIB_DEP) +paltex.exe : paltex.obj $(LIB_DEP) +pointblast.exe : pointblast.obj $(LIB_DEP) +reflect.exe : reflect.obj [-.util]readtex.obj [-.util]showbuffer.obj\ $(LIB_DEP) cxxlink $(MMS$TARGET_NAME),[-.util]readtex,showbuffer,$(GL_LIBS) -spectex.exe; : spectex.obj $(LIB_DEP) -stex3d.exe; : stex3d.obj $(LIB_DEP) -tessdemo.exe; : tessdemo.obj $(LIB_DEP) -texcyl.exe; : texcyl.obj [-.util]readtex.obj $(LIB_DEP) +spectex.exe : spectex.obj $(LIB_DEP) +stex3d.exe : stex3d.obj $(LIB_DEP) +tessdemo.exe : tessdemo.obj $(LIB_DEP) +texcyl.exe : texcyl.obj [-.util]readtex.obj $(LIB_DEP) cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) -texobj.exe; : texobj.obj $(LIB_DEP) -trispd.exe; : trispd.obj $(LIB_DEP) -winpos.exe; : winpos.obj [-.util]readtex.obj $(LIB_DEP) +texobj.exe : texobj.obj $(LIB_DEP) +trispd.exe : trispd.obj $(LIB_DEP) +winpos.exe : winpos.obj [-.util]readtex.obj $(LIB_DEP) cxxlink $(MMS$TARGET_NAME),[-.util]readtex.obj,$(GL_LIBS) diff --git a/progs/demos/engine.c b/progs/demos/engine.c index 68c4d500dfa..6040a2f1030 100644 --- a/progs/demos/engine.c +++ b/progs/demos/engine.c @@ -445,8 +445,8 @@ DrawConnector(float length, float thickness, for (i = 0; i <= 36; i++) { const int j = i % 36; glNormal3f(normals[j][0], normals[j][1], 0); - glVertex3f(points[j][0], points[j][1], z0); glVertex3f(points[j][0], points[j][1], z1); + glVertex3f(points[j][0], points[j][1], z0); } glEnd(); } @@ -745,7 +745,7 @@ DrawEngine(const Engine *eng, float crankAngle) glTranslatef(0, 0, -0.5 * crankLen); /* crankshaft */ - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, CrankshaftColor); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, CrankshaftColor); glColor4fv(CrankshaftColor); DrawPositionedCrankshaft(eng, crankAngle); @@ -764,12 +764,12 @@ DrawEngine(const Engine *eng, float crankAngle) rot += k * eng->V_Angle; /* piston */ - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, PistonColor); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, PistonColor); glColor4fv(PistonColor); DrawPositionedPiston(eng, rot); /* connecting rod */ - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ConnRodColor); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ConnRodColor); glColor4fv(ConnRodColor); DrawPositionedConnectingRod(eng, rot); glPopMatrix(); @@ -784,7 +784,7 @@ DrawEngine(const Engine *eng, float crankAngle) } glEnable(GL_CULL_FACE); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, BlockColor); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlockColor); glColor4fv(BlockColor); if (eng->CrankList) glCallList(eng->BlockList); @@ -1254,6 +1254,7 @@ Init(void) { const GLfloat lightColor[4] = { 0.7, 0.7, 0.7, 1.0 }; const GLfloat specular[4] = { 0.8, 0.8, 0.8, 1.0 }; + const GLfloat backColor[4] = { 1, 1, 0, 0 }; Q = gluNewQuadric(); gluQuadricNormals(Q, GLU_SMOOTH); @@ -1265,10 +1266,14 @@ Init(void) glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glMaterialf(GL_FRONT, GL_SHININESS, 40); + glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glEnable(GL_NORMALIZE); + glMaterialfv(GL_BACK, GL_DIFFUSE, backColor); +#if 0 + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); +#endif glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); InitViewInfo(&View); diff --git a/progs/demos/gears.c b/progs/demos/gears.c index ab9bc007421..2a9fefefb53 100644 --- a/progs/demos/gears.c +++ b/progs/demos/gears.c @@ -27,6 +27,9 @@ static GLint T0 = 0; static GLint Frames = 0; static GLint autoexit = 0; static GLint win = 0; +static GLboolean Visible = GL_TRUE; +static GLboolean Animate = GL_TRUE; +static GLfloat viewDist = 40.0; /** @@ -179,6 +182,9 @@ draw(void) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); + + glTranslatef(0.0, 0.0, -viewDist); + 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); @@ -240,6 +246,15 @@ idle(void) glutPostRedisplay(); } +static void +update_idle_func(void) +{ + if (Visible && Animate) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); +} + /* change view angle, exit upon ESC */ /* ARGSUSED1 */ static void @@ -252,6 +267,16 @@ key(unsigned char k, int x, int y) case 'Z': view_rotz -= 5.0; break; + case 'd': + viewDist += 1.0; + break; + case 'D': + viewDist -= 1.0; + break; + case 'a': + Animate = !Animate; + update_idle_func(); + break; case 27: /* Escape */ cleanup(); exit(0); @@ -295,10 +320,8 @@ reshape(int width, int height) glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + glFrustum(-1.0, 1.0, -h, h, 5.0, 200.0); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -40.0); } static void @@ -351,13 +374,12 @@ init(int argc, char *argv[]) } } + static void visible(int vis) { - if (vis == GLUT_VISIBLE) - glutIdleFunc(idle); - else - glutIdleFunc(NULL); + Visible = vis; + update_idle_func(); } int main(int argc, char *argv[]) @@ -375,6 +397,7 @@ int main(int argc, char *argv[]) glutKeyboardFunc(key); glutSpecialFunc(special); glutVisibilityFunc(visible); + update_idle_func(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ diff --git a/progs/demos/geartrain.dat b/progs/demos/geartrain.dat index 374de48bd5e..09fe4c64c28 100644 --- a/progs/demos/geartrain.dat +++ b/progs/demos/geartrain.dat @@ -1,119 +1,119 @@ -BACKGROUND = 0.000 0.500 0.700
-
-ANAME = AXLE1
-ARADIUS = 1.000
-AAXIS = 2
-APOSITION = -7.000 0.000 0.000
-ACOLOR = 0.800 0.500 0.200
-ALENGTH = 6.000
-AMOTORED = 1
-AANGULARVELOCITY = 90.000
-ADIRECTION = 1
-
-ANAME = AXLE2
-ARADIUS = 1.000
-AAXIS = 2
-APOSITION = -3.000 0.000 0.000
-ACOLOR = 0.800 0.500 0.200
-ALENGTH = 12.000
-AMOTORED = 0
-
-ANAME = AXLE3
-ARADIUS = 1.000
-AAXIS = 2
-APOSITION = 1.000 0.000 0.000
-ACOLOR = 0.800 0.500 0.200
-ALENGTH = 6.000
-AMOTORED = 0
-
-ANAME = AXLE4
-ARADIUS = 1.000
-AAXIS = 2
-APOSITION = 8.000 0.000 0.000
-ACOLOR = 0.800 0.500 0.200
-ALENGTH = 18.000
-AMOTORED = 0
-
-ANAME = AXLE5
-ARADIUS = 1.000
-AAXIS = 1
-APOSITION = 8.000 -8.200 -7.400
-ACOLOR = 0.800 0.500 0.200
-ALENGTH = 12.000
-AMOTORED = 0
-
-GNAME = GEAR1
-GTYPE = NORMAL
-GRADIUS = 2.200
-GWIDTH = 3.000
-GTEETH = 40
-GTOOTHDEPTH = 0.500
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE1
-GPOSITION = 0.000
-
-GNAME = GEAR2
-GTYPE = NORMAL
-GRADIUS = 2.200
-GWIDTH = 3.000
-GTEETH = 30
-GTOOTHDEPTH = 0.500
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE2
-GPOSITION = 0.000
-
-GNAME = GEAR3
-GTYPE = NORMAL
-GRADIUS = 2.200
-GWIDTH = 3.000
-GTEETH = 20
-GTOOTHDEPTH = 0.500
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE3
-GPOSITION = 0.000
-
-GNAME = GEAR4
-GTYPE = NORMAL
-GRADIUS = 1.700
-GWIDTH = 1.000
-GTEETH = 20
-GTOOTHDEPTH = 0.500
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE2
-GPOSITION = 5.000
-
-GNAME = GEAR5
-GTYPE = NORMAL
-GRADIUS = 3.000
-GWIDTH = 1.000
-GTEETH = 20
-GTOOTHDEPTH = 0.500
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE4
-GPOSITION = 5.000
-
-GNAME = GEAR6
-GTYPE = BEVEL
-GFACE = 0
-GRADIUS = 4.000
-GWIDTH = 1.000
-GTEETH = 20
-GTOOTHDEPTH = 1.700
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE4
-GPOSITION = -4.000
-
-GNAME = GEAR7
-GTYPE = BEVEL
-GFACE = 0
-GRADIUS = 4.000
-GWIDTH = 1.000
-GTEETH = 20
-GTOOTHDEPTH = 1.700
-GCOLOR = 0.500 0.500 0.500
-GAXLE = AXLE5
-GPOSITION = 5.000
-
-BELTNAME = BELT1
-GEAR1NAME = GEAR5
-GEAR2NAME = GEAR4
+BACKGROUND = 0.000 0.500 0.700 + +ANAME = AXLE1 +ARADIUS = 1.000 +AAXIS = 2 +APOSITION = -7.000 0.000 0.000 +ACOLOR = 0.800 0.500 0.200 +ALENGTH = 6.000 +AMOTORED = 1 +AANGULARVELOCITY = 90.000 +ADIRECTION = 1 + +ANAME = AXLE2 +ARADIUS = 1.000 +AAXIS = 2 +APOSITION = -3.000 0.000 0.000 +ACOLOR = 0.800 0.500 0.200 +ALENGTH = 12.000 +AMOTORED = 0 + +ANAME = AXLE3 +ARADIUS = 1.000 +AAXIS = 2 +APOSITION = 1.000 0.000 0.000 +ACOLOR = 0.800 0.500 0.200 +ALENGTH = 6.000 +AMOTORED = 0 + +ANAME = AXLE4 +ARADIUS = 1.000 +AAXIS = 2 +APOSITION = 8.000 0.000 0.000 +ACOLOR = 0.800 0.500 0.200 +ALENGTH = 18.000 +AMOTORED = 0 + +ANAME = AXLE5 +ARADIUS = 1.000 +AAXIS = 1 +APOSITION = 8.000 -8.200 -7.400 +ACOLOR = 0.800 0.500 0.200 +ALENGTH = 12.000 +AMOTORED = 0 + +GNAME = GEAR1 +GTYPE = NORMAL +GRADIUS = 2.200 +GWIDTH = 3.000 +GTEETH = 40 +GTOOTHDEPTH = 0.500 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE1 +GPOSITION = 0.000 + +GNAME = GEAR2 +GTYPE = NORMAL +GRADIUS = 2.200 +GWIDTH = 3.000 +GTEETH = 30 +GTOOTHDEPTH = 0.500 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE2 +GPOSITION = 0.000 + +GNAME = GEAR3 +GTYPE = NORMAL +GRADIUS = 2.200 +GWIDTH = 3.000 +GTEETH = 20 +GTOOTHDEPTH = 0.500 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE3 +GPOSITION = 0.000 + +GNAME = GEAR4 +GTYPE = NORMAL +GRADIUS = 1.700 +GWIDTH = 1.000 +GTEETH = 20 +GTOOTHDEPTH = 0.500 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE2 +GPOSITION = 5.000 + +GNAME = GEAR5 +GTYPE = NORMAL +GRADIUS = 3.000 +GWIDTH = 1.000 +GTEETH = 20 +GTOOTHDEPTH = 0.500 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE4 +GPOSITION = 5.000 + +GNAME = GEAR6 +GTYPE = BEVEL +GFACE = 0 +GRADIUS = 4.000 +GWIDTH = 1.000 +GTEETH = 20 +GTOOTHDEPTH = 1.700 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE4 +GPOSITION = -4.000 + +GNAME = GEAR7 +GTYPE = BEVEL +GFACE = 0 +GRADIUS = 4.000 +GWIDTH = 1.000 +GTEETH = 20 +GTOOTHDEPTH = 1.700 +GCOLOR = 0.500 0.500 0.500 +GAXLE = AXLE5 +GPOSITION = 5.000 + +BELTNAME = BELT1 +GEAR1NAME = GEAR5 +GEAR2NAME = GEAR4 diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c index 4ee12928164..4ee12928164 100755..100644 --- a/progs/demos/glslnoise.c +++ b/progs/demos/glslnoise.c diff --git a/progs/demos/lodbias.c b/progs/demos/lodbias.c index a4db22e26e4..c5a2a1b4573 100644 --- a/progs/demos/lodbias.c +++ b/progs/demos/lodbias.c @@ -159,6 +159,18 @@ static void Key( unsigned char key, int x, int y ) case 'B': Bias += 10; break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + Bias = 100.0 * (key - '0'); + break; case 27: exit(0); break; diff --git a/progs/demos/multiarb.c b/progs/demos/multiarb.c index d963985c69d..451fd11efe1 100644 --- a/progs/demos/multiarb.c +++ b/progs/demos/multiarb.c @@ -1,4 +1,3 @@ - /* * GL_ARB_multitexture demo * @@ -32,7 +31,6 @@ static GLint NumUnits = 1; static GLboolean TexEnabled[8]; static GLfloat Drift = 0.0; -static GLfloat drift_increment = 0.005; static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0; @@ -41,9 +39,7 @@ static void Idle( void ) if (Animate) { GLint i; - Drift += drift_increment; - if (Drift >= 1.0) - Drift = 0.0; + Drift = glutGet(GLUT_ELAPSED_TIME) * 0.001; for (i = 0; i < NumUnits; i++) { glActiveTextureARB(GL_TEXTURE0_ARB + i); @@ -57,10 +53,11 @@ static void Idle( void ) glTranslatef(0.0, Drift, 0.0); } else { - glTranslatef(0.5, 0.5, 0.0); + float tx = 0.5, ty = 0.5; + glTranslatef(tx, ty, 0.0); glRotatef(180.0 * Drift, 0, 0, 1); glScalef(1.0/i, 1.0/i, 1.0/i); - glTranslatef(-0.5, -0.5, 0.0); + glTranslatef(-tx, -ty + i * 0.1, 0.0); } } glMatrixMode(GL_MODELVIEW); @@ -72,10 +69,9 @@ static void Idle( void ) static void DrawObject(void) { - GLint i; - GLint j; - static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; - static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; + static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; + static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; + GLint i, j; if (!TexEnabled[0] && !TexEnabled[1]) glColor3f(0.1, 0.1, 0.1); /* add onto this */ @@ -83,37 +79,20 @@ static void DrawObject(void) glColor3f(1, 1, 1); /* modulate this */ glBegin(GL_QUADS); - - /* Toggle between the vector and scalar entry points. This is done purely - * to hit multiple paths in the driver. - */ - if ( Drift > 0.49 ) { - for (j = 0; j < 4; j++ ) { - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, - tex_coords[j], tex_coords[j+1]); - glVertex2f( vtx_coords[j], vtx_coords[j+1] ); - } - } - else { - for (j = 0; j < 4; j++ ) { - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, & tex_coords[j]); - glVertex2fv( & vtx_coords[j] ); + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) { + if (TexEnabled[i]) + glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, + tex_coords[j], tex_coords[j+1]); } + glVertex2f( vtx_coords[j], vtx_coords[j+1] ); } - glEnd(); } - static void Display( void ) { - static GLint T0 = 0; - static GLint Frames = 0; - GLint t; - glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); @@ -125,16 +104,6 @@ static void Display( void ) glPopMatrix(); glutSwapBuffers(); - - Frames++; - - t = glutGet(GLUT_ELAPSED_TIME); - if (t - T0 >= 250) { - GLfloat seconds = (t - T0) / 1000.0; - drift_increment = 2.2 * seconds / Frames; - T0 = t; - Frames = 0; - } } @@ -151,24 +120,34 @@ static void Reshape( int width, int height ) } +static void ToggleUnit(int unit) +{ + TexEnabled[unit] = !TexEnabled[unit]; + glActiveTextureARB(GL_TEXTURE0_ARB + unit); + if (TexEnabled[unit]) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + printf("Enabled: "); + for (unit = 0; unit < NumUnits; unit++) + printf("%d ", (int) TexEnabled[unit]); + printf("\n"); +} + + static void ModeMenu(int entry) { if (entry >= TEX0 && entry <= TEX7) { /* toggle */ GLint i = entry - TEX0; - TexEnabled[i] = !TexEnabled[i]; - glActiveTextureARB(GL_TEXTURE0_ARB + i); - if (TexEnabled[i]) - glEnable(GL_TEXTURE_2D); - else - glDisable(GL_TEXTURE_2D); - printf("Enabled: "); - for (i = 0; i < NumUnits; i++) - printf("%d ", (int) TexEnabled[i]); - printf("\n"); + ToggleUnit(i); } else if (entry==ANIMATE) { Animate = !Animate; + if (Animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); } else if (entry==QUIT) { exit(0); @@ -183,9 +162,36 @@ static void Key( unsigned char key, int x, int y ) (void) x; (void) y; switch (key) { - case 27: - exit(0); - break; + case 'a': + Animate = !Animate; + break; + case '0': + ToggleUnit(0); + break; + case '1': + ToggleUnit(1); + break; + case '2': + ToggleUnit(2); + break; + case '3': + ToggleUnit(3); + break; + case '4': + ToggleUnit(4); + break; + case '5': + ToggleUnit(5); + break; + case '6': + ToggleUnit(6); + break; + case '7': + ToggleUnit(7); + break; + case 27: + exit(0); + break; } glutPostRedisplay(); } @@ -327,7 +333,8 @@ int main( int argc, char *argv[] ) glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); glutDisplayFunc( Display ); - glutIdleFunc( Idle ); + if (Animate) + glutIdleFunc(Idle); glutCreateMenu(ModeMenu); diff --git a/progs/demos/rain.cxx b/progs/demos/rain.cxx index d19f049c5f3..5c53d4248c5 100644 --- a/progs/demos/rain.cxx +++ b/progs/demos/rain.cxx @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <time.h> #include <GL/glut.h> diff --git a/progs/demos/readtex.c b/progs/demos/readtex.c deleted file mode 100644 index 37d5fcd0d3a..00000000000 --- a/progs/demos/readtex.c +++ /dev/null @@ -1,454 +0,0 @@ -/* readtex.c */ - -/* - * Read an SGI .rgb image file and generate a mipmap texture set. - * Much of this code was borrowed from SGI's tk OpenGL toolkit. - */ - - - -#include <GL/gl.h> -#include <GL/glu.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "readtex.h" - - -#ifndef SEEK_SET -# define SEEK_SET 0 -#endif - - -/* -** RGB Image Structure -*/ - -typedef struct _TK_RGBImageRec { - GLint sizeX, sizeY; - GLint components; - unsigned char *data; -} TK_RGBImageRec; - - - -/******************************************************************************/ - -typedef struct _rawImageRec { - unsigned short imagic; - unsigned short type; - unsigned short dim; - unsigned short sizeX, sizeY, sizeZ; - unsigned long min, max; - unsigned long wasteBytes; - char name[80]; - unsigned long colorMap; - FILE *file; - unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; - unsigned long rleEnd; - GLuint *rowStart; - GLint *rowSize; -} rawImageRec; - -/******************************************************************************/ - -static void ConvertShort(unsigned short *array, long length) -{ - unsigned long b1, b2; - unsigned char *ptr; - - ptr = (unsigned char *)array; - while (length--) { - b1 = *ptr++; - b2 = *ptr++; - *array++ = (unsigned short) ((b1 << 8) | (b2)); - } -} - -static void ConvertLong(GLuint *array, long length) -{ - unsigned long b1, b2, b3, b4; - unsigned char *ptr; - - ptr = (unsigned char *)array; - while (length--) { - b1 = *ptr++; - b2 = *ptr++; - b3 = *ptr++; - b4 = *ptr++; - *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); - } -} - -static rawImageRec *RawImageOpen(const char *fileName) -{ - union { - int testWord; - char testByte[4]; - } endianTest; - rawImageRec *raw; - GLenum swapFlag; - int x; - - endianTest.testWord = 1; - if (endianTest.testByte[0] == 1) { - swapFlag = GL_TRUE; - } else { - swapFlag = GL_FALSE; - } - - raw = (rawImageRec *)calloc(1, sizeof(rawImageRec)); - if (raw == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; - } - if ((raw->file = fopen(fileName, "rb")) == NULL) { - perror(fileName); - return NULL; - } - - fread(raw, 1, 12, raw->file); - - if (swapFlag) { - ConvertShort(&raw->imagic, 6); - } - - raw->tmp = (unsigned char *)malloc(raw->sizeX*256); - raw->tmpR = (unsigned char *)malloc(raw->sizeX*256); - raw->tmpG = (unsigned char *)malloc(raw->sizeX*256); - raw->tmpB = (unsigned char *)malloc(raw->sizeX*256); - if (raw->sizeZ==4) { - raw->tmpA = (unsigned char *)malloc(raw->sizeX*256); - } - if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || - raw->tmpB == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; - } - - if ((raw->type & 0xFF00) == 0x0100) { - x = raw->sizeY * raw->sizeZ * sizeof(GLuint); - raw->rowStart = (GLuint *)malloc(x); - raw->rowSize = (GLint *)malloc(x); - if (raw->rowStart == NULL || raw->rowSize == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; - } - raw->rleEnd = 512 + (2 * x); - fseek(raw->file, 512, SEEK_SET); - fread(raw->rowStart, 1, x, raw->file); - fread(raw->rowSize, 1, x, raw->file); - if (swapFlag) { - ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); - ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); - } - } - return raw; -} - -static void RawImageClose(rawImageRec *raw) -{ - fclose(raw->file); - free(raw->tmp); - free(raw->tmpR); - free(raw->tmpG); - free(raw->tmpB); - if (raw->rowStart) - free(raw->rowStart); - if (raw->rowSize) - free(raw->rowSize); - if (raw->sizeZ>3) { - free(raw->tmpA); - } - free(raw); -} - -static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) -{ - unsigned char *iPtr, *oPtr, pixel; - int count, done = 0; - - if ((raw->type & 0xFF00) == 0x0100) { - fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET); - fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], - raw->file); - - iPtr = raw->tmp; - oPtr = buf; - while (!done) { - pixel = *iPtr++; - count = (int)(pixel & 0x7F); - if (!count) { - done = 1; - return; - } - if (pixel & 0x80) { - while (count--) { - *oPtr++ = *iPtr++; - } - } else { - pixel = *iPtr++; - while (count--) { - *oPtr++ = pixel; - } - } - } - } else { - fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY), - SEEK_SET); - fread(buf, 1, raw->sizeX, raw->file); - } -} - - -static void RawImageGetData(rawImageRec *raw, TK_RGBImageRec *final) -{ - unsigned char *ptr; - int i, j; - - final->data = (unsigned char *)malloc((raw->sizeX+1)*(raw->sizeY+1)*4); - if (final->data == NULL) { - fprintf(stderr, "Out of memory!\n"); - } - - ptr = final->data; - for (i = 0; i < (int)(raw->sizeY); i++) { - RawImageGetRow(raw, raw->tmpR, i, 0); - RawImageGetRow(raw, raw->tmpG, i, 1); - RawImageGetRow(raw, raw->tmpB, i, 2); - if (raw->sizeZ>3) { - RawImageGetRow(raw, raw->tmpA, i, 3); - } - for (j = 0; j < (int)(raw->sizeX); j++) { - *ptr++ = *(raw->tmpR + j); - *ptr++ = *(raw->tmpG + j); - *ptr++ = *(raw->tmpB + j); - if (raw->sizeZ>3) { - *ptr++ = *(raw->tmpA + j); - } - } - } -} - - -static TK_RGBImageRec *tkRGBImageLoad(const char *fileName) -{ - rawImageRec *raw; - TK_RGBImageRec *final; - - raw = RawImageOpen(fileName); - if (!raw) { - fprintf(stderr, "File not found\n"); - return NULL; - } - final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec)); - if (final == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; - } - final->sizeX = raw->sizeX; - final->sizeY = raw->sizeY; - final->components = raw->sizeZ; - RawImageGetData(raw, final); - RawImageClose(raw); - return final; -} - - -static void FreeImage( TK_RGBImageRec *image ) -{ - free(image->data); - free(image); -} - - -/* - * Load an SGI .rgb file and generate a set of 2-D mipmaps from it. - * Input: imageFile - name of .rgb to read - * intFormat - internal texture format to use, or number of components - * Return: GL_TRUE if success, GL_FALSE if error. - */ -GLboolean LoadRGBMipmaps( const char *imageFile, GLint intFormat ) -{ - GLint w, h; - return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); -} - - - -GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, - GLint intFormat, GLint *width, GLint *height ) -{ - GLint error; - GLenum format; - TK_RGBImageRec *image; - - image = tkRGBImageLoad( imageFile ); - if (!image) { - return GL_FALSE; - } - - if (image->components==3) { - format = GL_RGB; - } - else if (image->components==4) { - format = GL_RGBA; - } - else { - /* not implemented */ - fprintf(stderr, - "Error in LoadRGBMipmaps %d-component images not implemented\n", - image->components ); - return GL_FALSE; - } - - error = gluBuild2DMipmaps( target, - intFormat, - image->sizeX, image->sizeY, - format, - GL_UNSIGNED_BYTE, - image->data ); - - *width = image->sizeX; - *height = image->sizeY; - - FreeImage(image); - - return error ? GL_FALSE : GL_TRUE; -} - - - -/* - * Load an SGI .rgb file and return a pointer to the image data. - * Input: imageFile - name of .rgb to read - * Output: width - width of image - * height - height of image - * format - format of image (GL_RGB or GL_RGBA) - * Return: pointer to image data or NULL if error - */ -GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, - GLenum *format ) -{ - TK_RGBImageRec *image; - GLint bytes; - GLubyte *buffer; - - image = tkRGBImageLoad( imageFile ); - if (!image) { - return NULL; - } - - if (image->components==3) { - *format = GL_RGB; - } - else if (image->components==4) { - *format = GL_RGBA; - } - else { - /* not implemented */ - fprintf(stderr, - "Error in LoadRGBImage %d-component images not implemented\n", - image->components ); - return NULL; - } - - *width = image->sizeX; - *height = image->sizeY; - - bytes = image->sizeX * image->sizeY * image->components; - buffer = (GLubyte *) malloc(bytes); - if (!buffer) - return NULL; - - memcpy( (void *) buffer, (void *) image->data, bytes ); - - FreeImage(image); - - return buffer; -} - -#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) - - -static void ConvertRGBtoYUV(GLint w, GLint h, GLint texel_bytes, - const GLubyte *src, - GLushort *dest) -{ - GLint i, j; - - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - const GLfloat r = (src[0]) / 255.0; - const GLfloat g = (src[1]) / 255.0; - const GLfloat b = (src[2]) / 255.0; - GLfloat y, cr, cb; - GLint iy, icr, icb; - - y = r * 65.481 + g * 128.553 + b * 24.966 + 16; - cb = r * -37.797 + g * -74.203 + b * 112.0 + 128; - cr = r * 112.0 + g * -93.786 + b * -18.214 + 128; - /*printf("%f %f %f -> %f %f %f\n", r, g, b, y, cb, cr);*/ - iy = (GLint) CLAMP(y, 0, 254); - icb = (GLint) CLAMP(cb, 0, 254); - icr = (GLint) CLAMP(cr, 0, 254); - - if (j & 1) { - /* odd */ - *dest = (iy << 8) | icr; - } - else { - /* even */ - *dest = (iy << 8) | icb; - } - dest++; - src += texel_bytes; - } - } -} - - -/* - * Load an SGI .rgb file and return a pointer to the image data, converted - * to 422 yuv. - * - * Input: imageFile - name of .rgb to read - * Output: width - width of image - * height - height of image - * Return: pointer to image data or NULL if error - */ -GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height ) -{ - TK_RGBImageRec *image; - GLushort *buffer; - - image = tkRGBImageLoad( imageFile ); - if (!image) { - return NULL; - } - - if (image->components != 3 && image->components !=4 ) { - /* not implemented */ - fprintf(stderr, - "Error in LoadYUVImage %d-component images not implemented\n", - image->components ); - return NULL; - } - - *width = image->sizeX; - *height = image->sizeY; - - buffer = (GLushort *) malloc( image->sizeX * image->sizeY * 2 ); - - if (buffer) - ConvertRGBtoYUV( image->sizeX, - image->sizeY, - image->components, - image->data, - buffer ); - - - FreeImage(image); - return buffer; -} - diff --git a/progs/demos/readtex.h b/progs/demos/readtex.h deleted file mode 100644 index 6c9a3828d38..00000000000 --- a/progs/demos/readtex.h +++ /dev/null @@ -1,26 +0,0 @@ -/* readtex.h */ - -#ifndef READTEX_H -#define READTEX_H - - -#include <GL/gl.h> - - -extern GLboolean -LoadRGBMipmaps( const char *imageFile, GLint intFormat ); - - -extern GLboolean -LoadRGBMipmaps2( const char *imageFile, GLenum target, - GLint intFormat, GLint *width, GLint *height ); - - -extern GLubyte * -LoadRGBImage( const char *imageFile, - GLint *width, GLint *height, GLenum *format ); - -extern GLushort * -LoadYUVImage( const char *imageFile, GLint *width, GLint *height ); - -#endif diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index b11c6f53630..4787f0f29d2 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -9,6 +9,7 @@ * Added GL_EXT_packed_depth_stencil support on 15 March 2006. * Added GL_EXT_framebuffer_object support on 27 March 2006. * Removed old SGIX extension support on 5 April 2006. + * Added vertex / fragment program support on 7 June 2007 (Ian Romanick). * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * @@ -34,6 +35,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <math.h> #include <GL/glut.h> #include "showbuffer.h" @@ -67,8 +69,28 @@ static GLboolean NeedNewShadowMap = GL_FALSE; static GLuint ShadowTexture, GrayTexture; static GLuint ShadowFBO; +static GLfloat lightModelview[16]; +static GLfloat lightProjection[16]; + +static GLuint vert_prog; +static GLuint frag_progs[3]; +static GLuint curr_frag = 0; +static GLuint max_frag = 1; + +#define NUM_FRAG_MODES 3 +static const char *FragProgNames[] = { + "fixed-function", + "program without \"OPTION ARB_fragment_program_shadow\"", + "program with \"OPTION ARB_fragment_program_shadow\"", +}; + +static GLboolean HaveShadow = GL_FALSE; static GLboolean HaveFBO = GL_FALSE; static GLboolean UseFBO = GL_FALSE; +static GLboolean HaveVP = GL_FALSE; +static GLboolean HaveFP = GL_FALSE; +static GLboolean HaveFP_Shadow = GL_FALSE; +static GLboolean UseVP = GL_FALSE; static GLboolean HavePackedDepthStencil = GL_FALSE; static GLboolean UsePackedDepthStencil = GL_FALSE; static GLboolean HaveEXTshadowFuncs = GL_FALSE; @@ -91,6 +113,103 @@ static GLuint DisplayMode; +#define MAT4_MUL(dest_vec, src_mat, src_vec) \ + "DP4 " dest_vec ".x, " src_mat "[0], " src_vec ";\n" \ + "DP4 " dest_vec ".y, " src_mat "[1], " src_vec ";\n" \ + "DP4 " dest_vec ".z, " src_mat "[2], " src_vec ";\n" \ + "DP4 " dest_vec ".w, " src_mat "[3], " src_vec ";\n" + +#define MAT3_MUL(dest_vec, src_mat, src_vec) \ + "DP3 " dest_vec ".x, " src_mat "[0], " src_vec ";\n" \ + "DP3 " dest_vec ".y, " src_mat "[1], " src_vec ";\n" \ + "DP3 " dest_vec ".z, " src_mat "[2], " src_vec ";\n" + +#define NORMALIZE(dest, src) \ + "DP3 " dest ".w, " src ", " src ";\n" \ + "RSQ " dest ".w, " dest ".w;\n" \ + "MUL " dest ", " src ", " dest ".w;\n" + +/** + * Vertex program for shadow mapping. + */ +static const char vert_code[] = + "!!ARBvp1.0\n" + "ATTRIB iPos = vertex.position;\n" + "ATTRIB iNorm = vertex.normal;\n" + + "PARAM mvinv[4] = { state.matrix.modelview.invtrans };\n" + "PARAM mvp[4] = { state.matrix.mvp };\n" + "PARAM mv[4] = { state.matrix.modelview };\n" + "PARAM texmat[4] = { state.matrix.texture[0] };\n" + "PARAM lightPos = state.light[0].position;\n" + "PARAM ambientCol = state.lightprod[0].ambient;\n" + "PARAM diffuseCol = state.lightprod[0].diffuse;\n" + + "TEMP n, lightVec;\n" + "ALIAS V = lightVec;\n" + "ALIAS NdotL = n;\n" + + "OUTPUT oPos = result.position;\n" + "OUTPUT oColor = result.color;\n" + "OUTPUT oTex = result.texcoord[0];\n" + + /* Transform the vertex to clip coordinates. */ + MAT4_MUL("oPos", "mvp", "iPos") + + /* Transform the vertex to eye coordinates. */ + MAT4_MUL("V", "mv", "iPos") + + /* Transform the vertex to projected light coordinates. */ + MAT4_MUL("oTex", "texmat", "iPos") + + /* Transform the normal to eye coordinates. */ + MAT3_MUL("n", "mvinv", "iNorm") + + /* Calculate the vector from the vertex to the light in eye + * coordinates. + */ + "SUB lightVec, lightPos, V;\n" + NORMALIZE("lightVec", "lightVec") + + /* Compute diffuse lighting coefficient. + */ + "DP3 NdotL.x, n, lightVec;\n" + "MAX NdotL.x, NdotL.x, {0.0};\n" + "MIN NdotL.x, NdotL.x, {1.0};\n" + + /* Accumulate color contributions. + */ + "MOV oColor, diffuseCol;\n" + "MAD oColor.xyz, NdotL.x, diffuseCol, ambientCol;\n" + "END\n" + ; + +static const char frag_code[] = + "!!ARBfp1.0\n" + + "TEMP shadow, temp;\n" + + "TXP shadow, fragment.texcoord[0], texture[0], 2D;\n" + "RCP temp.x, fragment.texcoord[0].w;\n" + "MUL temp.x, temp.x, fragment.texcoord[0].z;\n" + "SGE shadow, shadow.x, temp.x;\n" + "MUL result.color.rgb, fragment.color, shadow.x;\n" + "MOV result.color.a, fragment.color;\n" + "END\n" + ; + +static const char frag_shadow_code[] = + "!!ARBfp1.0\n" + "OPTION ARB_fragment_program_shadow;\n" + + "TEMP shadow;\n" + + "TXP shadow, fragment.texcoord[0], texture[0], SHADOW2D;\n" + "MUL result.color.rgb, fragment.color, shadow.x;\n" + "MOV result.color.a, fragment.color.a;\n" + "END\n" + ; + static void DrawScene(void) { @@ -134,27 +253,56 @@ DrawScene(void) } -/* - * Load the GL_TEXTURE matrix with the projection from the light - * source's point of view. +/** + * Calculate modelview and project matrices for the light + * + * Stores the results in \c lightProjection (projection matrix) and + * \c lightModelview (modelview matrix). */ static void MakeShadowMatrix(const GLfloat lightPos[4], const GLfloat spotDir[3], GLfloat spotAngle, GLfloat shadowNear, GLfloat shadowFar) { - GLfloat d; - - glMatrixMode(GL_TEXTURE); + /* compute frustum to enclose spot light cone */ + const GLfloat d = shadowNear * tan(spotAngle); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); glLoadIdentity(); - glTranslatef(0.5, 0.5, 0.5 + Bias); - glScalef(0.5, 0.5, 0.5); - d = shadowNear * tan(spotAngle); glFrustum(-d, d, -d, d, shadowNear, shadowFar); + glGetFloatv(GL_PROJECTION_MATRIX, lightProjection); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); gluLookAt(lightPos[0], lightPos[1], lightPos[2], lightPos[0] + spotDir[0], lightPos[1] + spotDir[1], lightPos[2] + spotDir[2], - 0, 1, 0); + 0.0, 1.0, 0.0); + glGetFloatv(GL_MODELVIEW_MATRIX, lightModelview); + glPopMatrix(); +} + + +/** + * Load \c GL_TEXTURE matrix with light's MVP matrix. + */ +static void SetShadowTextureMatrix(void) +{ + static const GLfloat biasMatrix[16] = { + 0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0, + }; + + glMatrixMode(GL_TEXTURE); + glLoadMatrixf(biasMatrix); + glTranslatef(0.0, 0.0, Bias); + glMultMatrixf(lightProjection); + glMultMatrixf(lightModelview); glMatrixMode(GL_MODELVIEW); } @@ -258,7 +406,6 @@ RenderShadowMap(void) { GLenum depthFormat; /* GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL_EXT */ GLenum depthType; /* GL_UNSIGNED_INT_24_8_EXT or GL_UNSIGNED_INT */ - float d; if (WindowWidth >= 1024 && WindowHeight >= 1024) { ShadowTexWidth = ShadowTexHeight = 1024; @@ -283,17 +430,11 @@ RenderShadowMap(void) depthType = GL_UNSIGNED_INT; } - /* compute frustum to enclose spot light cone */ - d = ShadowNear * tan(SpotAngle); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-d, d, -d, d, ShadowNear, ShadowFar); + glLoadMatrixf(lightProjection); + glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(LightPos[0], LightPos[1], LightPos[2], /* from */ - 0, 0, 0, /* target */ - 0, 1, 0); /* up */ + glLoadMatrixf(lightModelview); if (UseFBO) { GLenum fbo_status; @@ -389,10 +530,11 @@ ShowShadowMap(void) DisableTexgen(); /* interpret texture's depth values as luminance values */ -#if defined(GL_ARB_shadow) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); + if (HaveShadow) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); + } + glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE); -#endif glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_POLYGON); @@ -420,6 +562,7 @@ Display(void) LightPos, SpotDir); if (NeedNewShadowMap) { + MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar); RenderShadowMap(); NeedNewShadowMap = GL_FALSE; } @@ -457,12 +600,13 @@ Display(void) } if (DisplayMode == SHOW_DEPTH_MAPPING) { -#if defined(GL_ARB_shadow) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); -#endif + if (HaveShadow) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE); + } glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); - MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar); + + SetShadowTextureMatrix(); EnableIdentityTexgen(); } else if (DisplayMode == SHOW_DISTANCE) { @@ -476,19 +620,44 @@ Display(void) } else { assert(DisplayMode == SHOW_SHADOWS); -#if defined(GL_ARB_shadow) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, - GL_COMPARE_R_TO_TEXTURE_ARB); -#endif - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + if (HaveShadow) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + } + + if (curr_frag > 0) { + glEnable(GL_FRAGMENT_PROGRAM_ARB); + } + else { + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } glEnable(GL_TEXTURE_2D); - MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar); - EnableIdentityTexgen(); + + SetShadowTextureMatrix(); + + if (UseVP) { + glEnable(GL_VERTEX_PROGRAM_ARB); + } + else { + glEnable(GL_LIGHTING); + EnableIdentityTexgen(); + } } DrawScene(); - DisableTexgen(); + if (UseVP) { + glDisable(GL_VERTEX_PROGRAM_ARB); + } + else { + DisableTexgen(); + glDisable(GL_LIGHTING); + } + + if (curr_frag > 0) { + glDisable(GL_FRAGMENT_PROGRAM_ARB); + } + glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); } @@ -561,6 +730,18 @@ Key(unsigned char key, int x, int y) case 'm': DisplayMode = SHOW_DEPTH_MAPPING; break; + case 'M': + curr_frag = (1 + curr_frag) % max_frag; + if (!HaveShadow && (curr_frag == 0)) { + curr_frag = 1; + } + + printf("Using fragment %s\n", FragProgNames[curr_frag]); + + if (HaveFP) { + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_progs[curr_frag]); + } + break; case 'n': case 's': case ' ': @@ -572,10 +753,10 @@ Key(unsigned char key, int x, int y) if (Operator >= 8) Operator = 0; printf("Operator: %s\n", OperatorName[Operator]); -#if defined(GL_ARB_shadow) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, - OperatorFunc[Operator]); -#endif + if (HaveShadow) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, + OperatorFunc[Operator]); + } } break; case 'p': @@ -592,6 +773,11 @@ Key(unsigned char key, int x, int y) NeedNewShadowMap = GL_TRUE; } break; + case 'v': + UseVP = !UseVP && HaveVP; + printf("Using vertex %s mode.\n", + UseVP ? "program" : "fixed-function"); + break; case 'z': Zrot -= step; break; @@ -646,28 +832,76 @@ SpecialKey(int key, int x, int y) } +/* A helper for finding errors in program strings */ +static int FindLine( const char *program, int position ) +{ + int i, line = 1; + for (i = 0; i < position; i++) { + if (program[i] == '\n') + line++; + } + return line; +} + + +static GLuint +compile_program(GLenum target, const char *code) +{ + GLuint p; + GLint errorPos; + + + glGenProgramsARB(1, & p); + + glBindProgramARB(target, p); + glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(code), code); + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos); + if (glGetError() != GL_NO_ERROR || errorPos != -1) { + int l = FindLine(code, errorPos); + printf("Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l, + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + exit(0); + } + + glBindProgramARB(target, 0); + return p; +} + static void Init(void) { static const GLfloat borderColor[4] = {1.0, 0.0, 0.0, 0.0}; -#if defined(GL_ARB_depth_texture) && defined(GL_ARB_shadow) - if (!glutExtensionSupported("GL_ARB_depth_texture") || - !glutExtensionSupported("GL_ARB_shadow")) { -#else - if (1) { -#endif - printf("Sorry, this demo requires the GL_ARB_depth_texture and GL_ARB_shadow extensions\n"); + if (!glutExtensionSupported("GL_ARB_depth_texture")) { + printf("Sorry, this demo requires the GL_ARB_depth_texture extension\n"); + exit(1); + } + + HaveShadow = glutExtensionSupported("GL_ARB_shadow"); + HaveVP = glutExtensionSupported("GL_ARB_vertex_program"); + HaveFP = glutExtensionSupported("GL_ARB_fragment_program"); + HaveFP_Shadow = glutExtensionSupported("GL_ARB_fragment_program_shadow"); + + if (!HaveShadow && !HaveFP) { + printf("Sorry, this demo requires either the GL_ARB_shadow extension " + "or the GL_ARB_fragment_program extension\n"); exit(1); } - printf("Using GL_ARB_depth_texture and GL_ARB_shadow\n"); -#if defined(GL_ARB_shadow_ambient) + printf("Using GL_ARB_depth_texture\n"); + if (HaveShadow) { + printf("and GL_ARB_shadow\n"); + } + + if (HaveFP) { + printf("and GL_ARB_fragment_program\n"); + } + HaveShadowAmbient = glutExtensionSupported("GL_ARB_shadow_ambient"); if (HaveShadowAmbient) { printf("and GL_ARB_shadow_ambient\n"); } -#endif HaveEXTshadowFuncs = glutExtensionSupported("GL_EXT_shadow_funcs"); @@ -690,15 +924,15 @@ Init(void) glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); -#if defined(GL_ARB_shadow) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, - GL_COMPARE_R_TO_TEXTURE_ARB); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); -#endif + + if (HaveShadow) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); + } + if (HaveShadowAmbient) { -#if defined(GL_ARB_shadow_ambient) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.3); -#endif } #if defined(GL_EXT_framebuffer_object) @@ -721,7 +955,6 @@ Init(void) glGenTextures(1, &GrayTexture); glBindTexture(GL_TEXTURE_1D, GrayTexture); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { @@ -733,6 +966,30 @@ Init(void) 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image); } + if (HaveVP) { + vert_prog = compile_program(GL_VERTEX_PROGRAM_ARB, vert_code); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog); + } + + max_frag = 1; + frag_progs[0] = 0; + + if (HaveFP) { + frag_progs[1] = compile_program(GL_FRAGMENT_PROGRAM_ARB, frag_code); + max_frag = 2; + } + + if (HaveFP && HaveFP_Shadow) { + frag_progs[2] = compile_program(GL_FRAGMENT_PROGRAM_ARB, + frag_shadow_code); + max_frag = 3; + } + + if (!HaveShadow) { + curr_frag = 1; + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_progs[curr_frag]); + } + glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); @@ -751,6 +1008,8 @@ PrintHelp(void) printf(" f = toggle nearest/bilinear texture filtering\n"); printf(" b/B = decrease/increase shadow map Z bias\n"); printf(" p = toggle use of packed depth/stencil\n"); + printf(" M = cycle through fragment program modes\n"); + printf(" v = toggle vertex program modes\n"); printf(" cursor keys = rotate scene\n"); printf(" <shift> + cursor keys = rotate light source\n"); if (HaveEXTshadowFuncs) diff --git a/progs/demos/showbuffer.c b/progs/demos/showbuffer.c deleted file mode 100644 index 17f84dc62bd..00000000000 --- a/progs/demos/showbuffer.c +++ /dev/null @@ -1,192 +0,0 @@ -/* showbuffer.c */ - - -/* - * Copy the depth buffer to the color buffer as a grayscale image. - * Useful for inspecting the depth buffer values. - * - * This program is in the public domain. - * - * Brian Paul November 4, 1998 - */ - - -#include <assert.h> -#include <stdlib.h> -#include <GL/gl.h> -#include "showbuffer.h" - - - -/* - * Copy the depth buffer values into the current color buffer as a - * grayscale image. - * Input: winWidth, winHeight - size of the window - * zBlack - the Z value which should map to black (usually 1) - * zWhite - the Z value which should map to white (usually 0) - */ -void -ShowDepthBuffer( GLsizei winWidth, GLsizei winHeight, - GLfloat zBlack, GLfloat zWhite ) -{ - GLfloat *depthValues; - - assert(zBlack >= 0.0); - assert(zBlack <= 1.0); - assert(zWhite >= 0.0); - assert(zWhite <= 1.0); - assert(zBlack != zWhite); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - /* Read depth values */ - depthValues = (GLfloat *) malloc(winWidth * winHeight * sizeof(GLfloat)); - assert(depthValues); - glReadPixels(0, 0, winWidth, winHeight, GL_DEPTH_COMPONENT, - GL_FLOAT, depthValues); - - /* Map Z values from [zBlack, zWhite] to gray levels in [0, 1] */ - /* Not using glPixelTransfer() because it's broke on some systems! */ - if (zBlack != 0.0 || zWhite != 1.0) { - GLfloat scale = 1.0 / (zWhite - zBlack); - GLfloat bias = -zBlack * scale; - int n = winWidth * winHeight; - int i; - for (i = 0; i < n; i++) - depthValues[i] = depthValues[i] * scale + bias; - } - - /* save GL state */ - glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | - GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); - - /* setup raster pos for glDrawPixels */ - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - glRasterPos2f(0, 0); - - glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_FLOAT, depthValues); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - free(depthValues); - - glPopAttrib(); -} - - - - -/* - * Copy the alpha channel values into the current color buffer as a - * grayscale image. - * Input: winWidth, winHeight - size of the window - */ -void -ShowAlphaBuffer( GLsizei winWidth, GLsizei winHeight ) -{ - GLubyte *alphaValues; - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - /* Read alpha values */ - alphaValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte)); - assert(alphaValues); - glReadPixels(0, 0, winWidth, winHeight, GL_ALPHA, GL_UNSIGNED_BYTE, alphaValues); - - /* save GL state */ - glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL | - GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); - - /* setup raster pos for glDrawPixels */ - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - glRasterPos2f(0, 0); - - glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, alphaValues); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - free(alphaValues); - - glPopAttrib(); -} - - - -/* - * Copy the stencil buffer values into the current color buffer as a - * grayscale image. - * Input: winWidth, winHeight - size of the window - * scale, bias - scale and bias to apply to stencil values for display - */ -void -ShowStencilBuffer( GLsizei winWidth, GLsizei winHeight, - GLfloat scale, GLfloat bias ) -{ - GLubyte *stencilValues; - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - /* Read stencil values */ - stencilValues = (GLubyte *) malloc(winWidth * winHeight * sizeof(GLubyte)); - assert(stencilValues); - glReadPixels(0, 0, winWidth, winHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilValues); - - /* save GL state */ - glPushAttrib(GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | - GL_PIXEL_MODE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); - - /* setup raster pos for glDrawPixels */ - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glOrtho(0.0, (GLdouble) winWidth, 0.0, (GLdouble) winHeight, -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - glRasterPos2f(0, 0); - - glPixelTransferf(GL_RED_SCALE, scale); - glPixelTransferf(GL_RED_BIAS, bias); - glPixelTransferf(GL_GREEN_SCALE, scale); - glPixelTransferf(GL_GREEN_BIAS, bias); - glPixelTransferf(GL_BLUE_SCALE, scale); - glPixelTransferf(GL_BLUE_BIAS, bias); - - glDrawPixels(winWidth, winHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, stencilValues); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - free(stencilValues); - - glPopAttrib(); -} diff --git a/progs/demos/showbuffer.h b/progs/demos/showbuffer.h deleted file mode 100644 index 63533d8e9b5..00000000000 --- a/progs/demos/showbuffer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* showbuffer. h*/ - -/* - * Copy the depth buffer to the color buffer as a grayscale image. - * Useful for inspecting the depth buffer values. - * - * This program is in the public domain. - * - * Brian Paul November 4, 1998 - */ - - -#ifndef SHOWBUFFER_H -#define SHOWBUFFER_H - - -#include <GL/gl.h> - - - -extern void -ShowDepthBuffer( GLsizei winWidth, GLsizei winHeight, - GLfloat zBlack, GLfloat zWhite ); - - -extern void -ShowAlphaBuffer( GLsizei winWidth, GLsizei winHeight ); - - -extern void -ShowStencilBuffer( GLsizei winWidth, GLsizei winHeight, - GLfloat scale, GLfloat bias ); - - - -#endif diff --git a/progs/demos/spriteblast.c b/progs/demos/spriteblast.c index f0d3d0dfd41..5ad8e4d9a94 100644 --- a/progs/demos/spriteblast.c +++ b/progs/demos/spriteblast.c @@ -333,13 +333,13 @@ menu(int option) smooth = 0; break; case 10: - glPointSize(4.0); + glPointSize(16.0); break; case 11: - glPointSize(8.0); + glPointSize(32.0); break; case 12: - glPointSize(16.0); + glPointSize(64.0); break; case 13: spin = 1 - spin; @@ -411,19 +411,19 @@ key(unsigned char c, int x, int y) glutPostRedisplay(); break; case '1': - glPointSize(2.0); + glPointSize(16.0); glutPostRedisplay(); break; case '2': - glPointSize(4.0); + glPointSize(32.0); glutPostRedisplay(); break; case '3': - glPointSize(8.0); + glPointSize(64.0); glutPostRedisplay(); break; case '4': - glPointSize(16.0); + glPointSize(128.0); glutPostRedisplay(); break; case 27: @@ -526,9 +526,9 @@ main(int argc, char **argv) glutAddMenuEntry("Threshold 10", 7); glutAddMenuEntry("Point smooth on", 8); glutAddMenuEntry("Point smooth off", 9); - glutAddMenuEntry("Point size 4", 10); - glutAddMenuEntry("Point size 8", 11); - glutAddMenuEntry("Point size 16", 12); + glutAddMenuEntry("Point size 16", 10); + glutAddMenuEntry("Point size 32", 11); + glutAddMenuEntry("Point size 64", 12); glutAddMenuEntry("Toggle spin", 13); glutAddMenuEntry("200 points ", 14); glutAddMenuEntry("500 points ", 15); @@ -544,7 +544,7 @@ main(int argc, char **argv) glEnable(GL_DEPTH_TEST); glEnable(GL_POINT_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPointSize(16.0); + glPointSize(32.0); #ifdef GL_ARB_point_parameters glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); #endif diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c index 86e00803c01..4c1d8535fd7 100644 --- a/progs/demos/streaming_rect.c +++ b/progs/demos/streaming_rect.c @@ -1,13 +1,9 @@ - /* - * GL_ARB_multitexture demo + * GL_ARB_pixel_buffer_object test * * Command line options: - * -info print GL implementation information - * + * -w WIDTH -h HEIGHT sets window size * - * Brian Paul November 1998 This program is in the public domain. - * Modified on 12 Feb 2002 for > 2 texture units. */ #define GL_GLEXT_PROTOTYPES @@ -25,6 +21,8 @@ #define PBO 11 #define QUIT 100 +static GLuint DrawPBO; + static GLboolean Animate = GL_TRUE; static GLboolean use_pbo = 1; static GLboolean whole_rect = 1; @@ -49,7 +47,7 @@ static void Idle( void ) } } -static int max( int a, int b ) { return a > b ? a : b; } +/*static int max( int a, int b ) { return a > b ? a : b; }*/ static int min( int a, int b ) { return a < b ? a : b; } static void DrawObject() @@ -62,6 +60,7 @@ static void DrawObject() * release the old copy of the texture and allocate a new one * without waiting for outstanding rendering to complete. */ + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW_ARB); { @@ -69,7 +68,7 @@ static void DrawObject() printf("char %d\n", (unsigned char)(Drift * 255)); - memset(image, size, (unsigned char)(Drift * 255)); + memset(image, (unsigned char)(Drift * 255), size); glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT); } @@ -86,7 +85,9 @@ static void DrawObject() if (image == NULL) image = malloc(size); - memset(image, size, (unsigned char)(Drift * 255)); + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); + + memset(image, (unsigned char)(Drift * 255), size); /* BGRA should be the fast path for regular uploads as well. */ @@ -227,12 +228,12 @@ static void SpecialKey( int key, int x, int y ) static void Init( int argc, char *argv[] ) { const char *exten = (const char *) glGetString(GL_EXTENSIONS); - GLuint texObj, DrawPBO; + GLuint texObj; GLint size; - if (!strstr(exten, "GL_ARB_multitexture")) { - printf("Sorry, GL_ARB_multitexture not supported by this renderer.\n"); + if (!strstr(exten, "GL_ARB_pixel_buffer_object")) { + printf("Sorry, GL_ARB_pixel_buffer_object not supported by this renderer.\n"); exit(1); } diff --git a/progs/demos/texenv.c b/progs/demos/texenv.c index 590867b4945..c4174dc173d 100644 --- a/progs/demos/texenv.c +++ b/progs/demos/texenv.c @@ -76,6 +76,7 @@ int textureWidth = 64; int textureHeight = 64; int winWidth = 580, winHeight = 720; +int win; struct formatInfo { GLenum baseFormat; @@ -288,6 +289,7 @@ static void keyboard( unsigned char c, int x, int y ) displayLevelInfo = !displayLevelInfo; break; case 27: /* Escape key should force exit. */ + glutDestroyWindow(win); exit(0); break; default: @@ -785,7 +787,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( winWidth, winHeight ); glutInitWindowPosition( 0, 0 ); - glutCreateWindow( "Texture Environment Test" ); + win = glutCreateWindow( "Texture Environment Test" ); initialize(); instructions(); diff --git a/progs/demos/trackball.c b/progs/demos/trackball.c deleted file mode 100644 index a6c4c60d06b..00000000000 --- a/progs/demos/trackball.c +++ /dev/null @@ -1,338 +0,0 @@ -#include <stdio.h> -/* - * (c) Copyright 1993, 1994, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * Permission to use, copy, modify, and distribute this software for - * any purpose and without fee is hereby granted, provided that the above - * copyright notice appear in all copies and that both the copyright notice - * and this permission notice appear in supporting documentation, and that - * the name of Silicon Graphics, Inc. not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. - * - * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" - * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR - * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON - * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, - * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY - * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, - * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF - * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN - * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE - * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. - * - * US Government Users Restricted Rights - * Use, duplication, or disclosure by the Government is subject to - * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph - * (c)(1)(ii) of the Rights in Technical Data and Computer Software - * clause at DFARS 252.227-7013 and/or in similar or successor - * clauses in the FAR or the DOD or NASA FAR Supplement. - * Unpublished-- rights reserved under the copyright laws of the - * United States. Contractor/manufacturer is Silicon Graphics, - * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. - * - * OpenGL(TM) is a trademark of Silicon Graphics, Inc. - */ -/* - * Trackball code: - * - * Implementation of a virtual trackball. - * Implemented by Gavin Bell, lots of ideas from Thant Tessman and - * the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129. - * - * Vector manip code: - * - * Original code from: - * David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli - * - * Much mucking with by: - * Gavin Bell - */ -#if defined(_WIN32) -#pragma warning (disable:4244) /* disable bogus conversion warnings */ -#endif -#include <math.h> -#include "trackball.h" - -/* - * This size should really be based on the distance from the center of - * rotation to the point on the object underneath the mouse. That - * point would then track the mouse as closely as possible. This is a - * simple example, though, so that is left as an Exercise for the - * Programmer. - */ -#define TRACKBALLSIZE (0.8f) - -/* - * Local function prototypes (not defined in trackball.h) - */ -static float tb_project_to_sphere(float, float, float); -static void normalize_quat(float [4]); - -static void -vzero(float v[3]) -{ - v[0] = 0.0; - v[1] = 0.0; - v[2] = 0.0; -} - -static void -vset(float v[3], float x, float y, float z) -{ - v[0] = x; - v[1] = y; - v[2] = z; -} - -static void -vsub(const float src1[3], const float src2[3], float dst[3]) -{ - dst[0] = src1[0] - src2[0]; - dst[1] = src1[1] - src2[1]; - dst[2] = src1[2] - src2[2]; -} - -static void -vcopy(const float v1[3], float v2[3]) -{ - register int i; - for (i = 0 ; i < 3 ; i++) - v2[i] = v1[i]; -} - -static void -vcross(const float v1[3], const float v2[3], float cross[3]) -{ - float temp[3]; - - temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]); - temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]); - temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]); - vcopy(temp, cross); -} - -static float -vlength(const float v[3]) -{ - return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); -} - -static void -vscale(float v[3], float div) -{ - v[0] *= div; - v[1] *= div; - v[2] *= div; -} - -static void -vnormal(float v[3]) -{ - vscale(v,1.0/vlength(v)); -} - -static float -vdot(const float v1[3], const float v2[3]) -{ - return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; -} - -static void -vadd(const float src1[3], const float src2[3], float dst[3]) -{ - dst[0] = src1[0] + src2[0]; - dst[1] = src1[1] + src2[1]; - dst[2] = src1[2] + src2[2]; -} - -/* - * Ok, simulate a track-ball. Project the points onto the virtual - * trackball, then figure out the axis of rotation, which is the cross - * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0) - * Note: This is a deformed trackball-- is a trackball in the center, - * but is deformed into a hyperbolic sheet of rotation away from the - * center. This particular function was chosen after trying out - * several variations. - * - * It is assumed that the arguments to this routine are in the range - * (-1.0 ... 1.0) - */ -void -trackball(float q[4], float p1x, float p1y, float p2x, float p2y) -{ - float a[3]; /* Axis of rotation */ - float phi; /* how much to rotate about axis */ - float p1[3], p2[3], d[3]; - float t; - - if (p1x == p2x && p1y == p2y) { - /* Zero rotation */ - vzero(q); - q[3] = 1.0; - return; - } - - /* - * First, figure out z-coordinates for projection of P1 and P2 to - * deformed sphere - */ - vset(p1,p1x,p1y,tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y)); - vset(p2,p2x,p2y,tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y)); - - /* - * Now, we want the cross product of P1 and P2 - */ - vcross(p2,p1,a); - - /* - * Figure out how much to rotate around that axis. - */ - vsub(p1,p2,d); - t = vlength(d) / (2.0*TRACKBALLSIZE); - - /* - * Avoid problems with out-of-control values... - */ - if (t > 1.0) t = 1.0; - if (t < -1.0) t = -1.0; - phi = 2.0 * asin(t); - - axis_to_quat(a,phi,q); -} - -/* - * Given an axis and angle, compute quaternion. - */ -void -axis_to_quat(const float a[3], float phi, float q[4]) -{ - vcopy(a,q); - vnormal(q); - vscale(q, sin(phi/2.0)); - q[3] = cos(phi/2.0); -} - -/* - * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet - * if we are away from the center of the sphere. - */ -static float -tb_project_to_sphere(float r, float x, float y) -{ - float d, t, z; - - d = sqrt(x*x + y*y); - if (d < r * 0.70710678118654752440) { /* Inside sphere */ - z = sqrt(r*r - d*d); - } else { /* On hyperbola */ - t = r / 1.41421356237309504880; - z = t*t / d; - } - return z; -} - -/* - * Given two rotations, e1 and e2, expressed as quaternion rotations, - * figure out the equivalent single rotation and stuff it into dest. - * - * This routine also normalizes the result every RENORMCOUNT times it is - * called, to keep error from creeping in. - * - * NOTE: This routine is written so that q1 or q2 may be the same - * as dest (or each other). - */ - -#define RENORMCOUNT 97 - -void -add_quats(const float q1[4], const float q2[4], float dest[4]) -{ - static int count=0; - float t1[4], t2[4], t3[4]; - float tf[4]; - -#if 0 -printf("q1 = %f %f %f %f\n", q1[0], q1[1], q1[2], q1[3]); -printf("q2 = %f %f %f %f\n", q2[0], q2[1], q2[2], q2[3]); -#endif - - vcopy(q1,t1); - vscale(t1,q2[3]); - - vcopy(q2,t2); - vscale(t2,q1[3]); - - vcross(q2,q1,t3); - vadd(t1,t2,tf); - vadd(t3,tf,tf); - tf[3] = q1[3] * q2[3] - vdot(q1,q2); - -#if 0 -printf("tf = %f %f %f %f\n", tf[0], tf[1], tf[2], tf[3]); -#endif - - dest[0] = tf[0]; - dest[1] = tf[1]; - dest[2] = tf[2]; - dest[3] = tf[3]; - - if (++count > RENORMCOUNT) { - count = 0; - normalize_quat(dest); - } -} - -/* - * Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0 - * If they don't add up to 1.0, dividing by their magnitued will - * renormalize them. - * - * Note: See the following for more information on quaternions: - * - * - Shoemake, K., Animating rotation with quaternion curves, Computer - * Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985. - * - Pletinckx, D., Quaternion calculus as a basic tool in computer - * graphics, The Visual Computer 5, 2-13, 1989. - */ -static void -normalize_quat(float q[4]) -{ - int i; - float mag; - - mag = sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]); - for (i = 0; i < 4; i++) - q[i] /= mag; -} - -/* - * Build a rotation matrix, given a quaternion rotation. - * - */ -void -build_rotmatrix(float m[4][4], const float q[4]) -{ - m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]); - m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]); - m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]); - m[0][3] = 0.0; - - m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]); - m[1][1]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]); - m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]); - m[1][3] = 0.0; - - m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]); - m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]); - m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]); - m[2][3] = 0.0; - - m[3][0] = 0.0; - m[3][1] = 0.0; - m[3][2] = 0.0; - m[3][3] = 1.0; -} - diff --git a/progs/demos/trackball.h b/progs/demos/trackball.h deleted file mode 100644 index 9b278640e10..00000000000 --- a/progs/demos/trackball.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * (c) Copyright 1993, 1994, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * Permission to use, copy, modify, and distribute this software for - * any purpose and without fee is hereby granted, provided that the above - * copyright notice appear in all copies and that both the copyright notice - * and this permission notice appear in supporting documentation, and that - * the name of Silicon Graphics, Inc. not be used in advertising - * or publicity pertaining to distribution of the software without specific, - * written prior permission. - * - * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" - * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR - * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON - * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, - * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY - * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, - * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF - * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN - * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE - * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. - * - * US Government Users Restricted Rights - * Use, duplication, or disclosure by the Government is subject to - * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph - * (c)(1)(ii) of the Rights in Technical Data and Computer Software - * clause at DFARS 252.227-7013 and/or in similar or successor - * clauses in the FAR or the DOD or NASA FAR Supplement. - * Unpublished-- rights reserved under the copyright laws of the - * United States. Contractor/manufacturer is Silicon Graphics, - * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. - * - * OpenGL(TM) is a trademark of Silicon Graphics, Inc. - */ -/* - * trackball.h - * A virtual trackball implementation - * Written by Gavin Bell for Silicon Graphics, November 1988. - */ - -#ifndef TRACKBALL_H -#define TRACKBALL_H - - -/* - * Pass the x and y coordinates of the last and current positions of - * the mouse, scaled so they are from (-1.0 ... 1.0). - * - * The resulting rotation is returned as a quaternion rotation in the - * first paramater. - */ -void -trackball(float q[4], float p1x, float p1y, float p2x, float p2y); - -/* - * Given two quaternions, add them together to get a third quaternion. - * Adding quaternions to get a compound rotation is analagous to adding - * translations to get a compound translation. When incrementally - * adding rotations, the first argument here should be the new - * rotation, the second and third the total rotation (which will be - * over-written with the resulting new total rotation). - */ -void -add_quats(const float q1[4], const float q2[4], float dest[4]); - -/* - * A useful function, builds a rotation matrix in Matrix based on - * given quaternion. - */ -void -build_rotmatrix(float m[4][4], const float q[4]); - -/* - * This function computes a quaternion based on an axis (defined by - * the given vector) and an angle about which to rotate. The angle is - * expressed in radians. The result is put into the third argument. - */ -void -axis_to_quat(const float a[3], float phi, float q[4]); - - -#endif /* TRACKBALL_H */ |