diff options
Diffstat (limited to 'progs/demos')
-rw-r--r-- | progs/demos/.gitignore | 1 | ||||
-rw-r--r-- | progs/demos/Makefile | 8 | ||||
-rw-r--r-- | progs/demos/SConscript | 1 | ||||
-rw-r--r-- | progs/demos/dissolve.c | 158 | ||||
-rw-r--r-- | progs/demos/engine.c | 23 | ||||
-rw-r--r-- | progs/demos/fbotexture.c | 1 | ||||
-rw-r--r-- | progs/demos/fire.c | 8 | ||||
-rw-r--r-- | progs/demos/gloss.c | 7 | ||||
-rw-r--r-- | progs/demos/isosurf.c | 1 | ||||
-rw-r--r-- | progs/demos/morph3d.c | 1 | ||||
-rw-r--r-- | progs/demos/shadowtex.c | 1 |
11 files changed, 193 insertions, 17 deletions
diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore index 5dd974b63d..1b31866a85 100644 --- a/progs/demos/.gitignore +++ b/progs/demos/.gitignore @@ -6,6 +6,7 @@ clearspd copypix cubemap dinoshade +dissolve drawpix engine extfuncs.h diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 65fdbaaad8..5b1d2a0b65 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -20,6 +20,7 @@ PROGS = \ copypix \ cubemap \ dinoshade \ + dissolve \ drawpix \ engine \ fbo_firecube \ @@ -124,13 +125,6 @@ reflect.o: reflect.c showbuffer.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) reflect.c -shadowtex: shadowtex.o showbuffer.o - $(APP_CC) $(CFLAGS) $(LDFLAGS) shadowtex.o showbuffer.o $(LIBS) -o $@ - -shadowtex.o: shadowtex.c showbuffer.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) shadowtex.c - - gloss: gloss.o trackball.o readtex.o $(APP_CC) $(CFLAGS) $(LDFLAGS) gloss.o trackball.o readtex.o $(LIBS) -o $@ diff --git a/progs/demos/SConscript b/progs/demos/SConscript index 742dd66f36..10d53b50bf 100644 --- a/progs/demos/SConscript +++ b/progs/demos/SConscript @@ -8,6 +8,7 @@ progs = [ 'clearspd', 'copypix', 'cubemap', + 'dissolve', 'drawpix', 'engine', 'fbo_firecube', diff --git a/progs/demos/dissolve.c b/progs/demos/dissolve.c new file mode 100644 index 0000000000..0b8df1bb66 --- /dev/null +++ b/progs/demos/dissolve.c @@ -0,0 +1,158 @@ +/** + * Dissolve between two images using randomized stencil buffer + * and varying stencil ref. + * + * Brian Paul + * 29 Jan 2010 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glut.h> +#include "readtex.h" + +#define FILE1 "../images/bw.rgb" +#define FILE2 "../images/arch.rgb" + + +static int Win; +static int WinWidth = 400, WinHeight = 400; +static GLboolean Anim = GL_TRUE; + +static int ImgWidth[2], ImgHeight[2]; +static GLenum ImgFormat[2]; +static GLubyte *Image[2]; +static GLfloat ScaleX[2], ScaleY[2]; + +static GLubyte StencilRef = 0; + + +static void +Idle(void) +{ + StencilRef = (GLint) (glutGet(GLUT_ELAPSED_TIME) / 10); + glutPostRedisplay(); +} + + +static void +RandomizeStencilBuffer(void) +{ + GLubyte *b = malloc(WinWidth * WinHeight); + int i; + for (i = 0; i < WinWidth * WinHeight; i++) { + b[i] = rand() & 0xff; + } + + glStencilFunc(GL_ALWAYS, 0, ~0); + glPixelZoom(1.0, 1.0); + glDrawPixels(WinWidth, WinHeight, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, b); + + free(b); +} + + + +static void +Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glPixelZoom(ScaleX[0], ScaleY[0]); + glStencilFunc(GL_LESS, StencilRef, ~0); + glDrawPixels(ImgWidth[0], ImgHeight[0], ImgFormat[0], GL_UNSIGNED_BYTE, Image[0]); + + glPixelZoom(ScaleX[1], ScaleY[1]); + glStencilFunc(GL_GEQUAL, StencilRef, ~0); + glDrawPixels(ImgWidth[1], ImgHeight[1], ImgFormat[1], GL_UNSIGNED_BYTE, Image[1]); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + WinWidth = width; + WinHeight = 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); + + RandomizeStencilBuffer(); + + ScaleX[0] = (float) width / ImgWidth[0]; + ScaleY[0] = (float) height / ImgHeight[0]; + + ScaleX[1] = (float) width / ImgWidth[1]; + ScaleY[1] = (float) height / ImgHeight[1]; +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + + +static void +Init(void) +{ + Image[0] = LoadRGBImage(FILE1, &ImgWidth[0], &ImgHeight[0], &ImgFormat[0]); + if (!Image[0]) { + printf("Couldn't read %s\n", FILE1); + exit(0); + } + + Image[1] = LoadRGBImage(FILE2, &ImgWidth[1], &ImgHeight[1], &ImgFormat[1]); + if (!Image[1]) { + printf("Couldn't read %s\n", FILE2); + exit(0); + } + + glEnable(GL_STENCIL_TEST); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + if (Anim) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/engine.c b/progs/demos/engine.c index c54e3b8fb8..a4148357d4 100644 --- a/progs/demos/engine.c +++ b/progs/demos/engine.c @@ -26,6 +26,8 @@ /* Target engine speed: */ const int RPM = 100.0; +static int Win = 0; + /** * Engine description. @@ -120,7 +122,11 @@ static Engine Engines[NUM_ENGINES] = 0.3, /* CrankJournalRadius */ 0.4, /* CrankJournalLength */ 1.5, /* ConnectingRodLength */ - 0.1 /* ConnectingRodThickness */ + 0.1, /* ConnectingRodThickness */ + 0, /* CrankList */ + 0, /* ConnRodList */ + 0, /* PistonList */ + 0 /* BlockList */ }, { "Inline-4", @@ -136,7 +142,11 @@ static Engine Engines[NUM_ENGINES] = 0.3, /* CrankJournalRadius */ 0.4, /* CrankJournalLength */ 1.5, /* ConnectingRodLength */ - 0.1 /* ConnectingRodThickness */ + 0.1, /* ConnectingRodThickness */ + 0, /* CrankList */ + 0, /* ConnRodList */ + 0, /* PistonList */ + 0 /* BlockList */ }, { "Boxer-6", @@ -152,7 +162,11 @@ static Engine Engines[NUM_ENGINES] = 0.3, /* CrankJournalRadius */ 0.4, /* CrankJournalLength */ 1.5, /* ConnectingRodLength */ - 0.1 /* ConnectingRodThickness */ + 0.1, /* ConnectingRodThickness */ + 0, /* CrankList */ + 0, /* ConnRodList */ + 0, /* PistonList */ + 0 /* BlockList */ } }; @@ -1142,6 +1156,7 @@ OptRotate(void) static void OptExit(void) { + glutDestroyWindow(Win); exit(0); } @@ -1311,7 +1326,7 @@ main(int argc, char *argv[]) glutInitWindowSize(WinWidth, WinHeight); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); - glutCreateWindow("OpenGL Engine Demo"); + Win = glutCreateWindow("OpenGL Engine Demo"); glewInit(); glutReshapeFunc(Reshape); glutMouseFunc(Mouse); diff --git a/progs/demos/fbotexture.c b/progs/demos/fbotexture.c index 56482663dc..46bf1c5f6a 100644 --- a/progs/demos/fbotexture.c +++ b/progs/demos/fbotexture.c @@ -14,7 +14,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include "extfuncs.h" /* For debug */ diff --git a/progs/demos/fire.c b/progs/demos/fire.c index 9c351e80e5..bb912fb447 100644 --- a/progs/demos/fire.c +++ b/progs/demos/fire.c @@ -726,8 +726,13 @@ main(int ac, char **av) maxage = 1.0 / dt; - if (ac == 2) + if (ac == 2) { np = atoi(av[1]); + if (np <= 0 || np > 1000000) { + fprintf(stderr, "Invalid input.\n"); + exit(-1); + } + } if (ac == 4) { WIDTH = atoi(av[2]); @@ -761,6 +766,7 @@ main(int ac, char **av) assert(np > 0); p = (part *) malloc(sizeof(part) * np); + assert(p); for (i = 0; i < np; i++) setnewpart(&p[i]); diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c index 578736b4e2..450861e577 100644 --- a/progs/demos/gloss.c +++ b/progs/demos/gloss.c @@ -41,6 +41,7 @@ /* for convolution */ #define FILTER_SIZE 7 +static GLint Win; static GLint WinWidth = 500, WinHeight = 500; static GLuint CylinderObj = 0; static GLuint TeapotObj = 0; @@ -214,7 +215,11 @@ static void Key( unsigned char key, int x, int y ) case ' ': ToggleAnimate(); break; + case 'n': + Idle(); + break; case 27: + glutDestroyWindow(Win); exit(0); break; } @@ -439,7 +444,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize(WinWidth, WinHeight); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); - glutCreateWindow(argv[0] ); + Win = glutCreateWindow(argv[0] ); glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index dbe4d8d172..a5b21ffb5c 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -27,7 +27,6 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include <string.h> #include <math.h> #ifdef _WIN32 #include <windows.h> diff --git a/progs/demos/morph3d.c b/progs/demos/morph3d.c index 0f8ac426f3..07458eb156 100644 --- a/progs/demos/morph3d.c +++ b/progs/demos/morph3d.c @@ -137,7 +137,6 @@ So the angle is: #endif #include <GL/glut.h> #include <math.h> -#include <string.h> #define Scale 0.3 diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index 036f73d40b..677a42104f 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -38,7 +38,6 @@ #include <math.h> #include <GL/glew.h> #include <GL/glut.h> -#include "showbuffer.h" #define DEG_TO_RAD (3.14159 / 180.0) |