diff options
Diffstat (limited to 'progs/fp')
-rwxr-xr-x | progs/fp/Makefile | 2 | ||||
-rw-r--r-- | progs/fp/SConscript | 17 | ||||
-rw-r--r-- | progs/fp/fp-tri.c | 87 | ||||
-rw-r--r-- | progs/fp/kill-pos.txt | 9 | ||||
-rw-r--r-- | progs/fp/position.txt | 3 | ||||
-rw-r--r-- | progs/fp/tex-pos-kil-1.txt | 7 | ||||
-rw-r--r-- | progs/fp/tex-pos-kil.txt | 8 | ||||
-rw-r--r-- | progs/fp/tex-pos.txt | 6 | ||||
-rw-r--r-- | progs/fp/tex.txt | 3 |
9 files changed, 136 insertions, 6 deletions
diff --git a/progs/fp/Makefile b/progs/fp/Makefile index ef6644cce27..681928cf260 100755 --- a/progs/fp/Makefile +++ b/progs/fp/Makefile @@ -8,7 +8,7 @@ TOP = ../.. include $(TOP)/configs/current -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$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ tri-tex.c \ diff --git a/progs/fp/SConscript b/progs/fp/SConscript new file mode 100644 index 00000000000..553799758b0 --- /dev/null +++ b/progs/fp/SConscript @@ -0,0 +1,17 @@ +Import('env') + +if not env['GLUT']: + Return() + +env = env.Clone() + +env.Prepend(CPPPATH = [ + '../util', +]) + +env.Prepend(LIBS = ['$GLUT_LIB']) + +env.Program( + target = 'fp-tri', + source = ['fp-tri.c'], + ) diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index 843f897871b..bc490c05201 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -2,10 +2,19 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/glut.h> + +#ifndef WIN32 #include <unistd.h> #include <signal.h> +#endif + +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.c" + + +#define TEXTURE_FILE "../images/bw.rgb" unsigned show_fps = 0; unsigned int frame_cnt = 0; @@ -15,11 +24,14 @@ static const char *filename = NULL; static void usage(char *name) { fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 fprintf(stderr, "\n" ); fprintf(stderr, "options:\n"); fprintf(stderr, " -fps show frames per second\n"); +#endif } +#ifndef WIN32 void alarmhandler (int sig) { if (sig == SIGALRM) { @@ -31,6 +43,7 @@ void alarmhandler (int sig) signal(SIGALRM, alarmhandler); alarm(5); } +#endif static void args(int argc, char *argv[]) { @@ -57,6 +70,7 @@ static void args(int argc, char *argv[]) static void Init( void ) { + GLuint Texture; GLint errno; GLuint prognum; char buf[4096]; @@ -99,7 +113,70 @@ static void Init( void ) } glEnable(GL_FRAGMENT_PROGRAM_ARB); - glClearColor(.3, .3, .3, 0); + + /* Load texture */ + glGenTextures(1, &Texture); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + + + glGenTextures(1, &Texture); + glActiveTextureARB(GL_TEXTURE0_ARB + 1); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + { + GLubyte data[32][32]; + int width = 32; + int height = 32; + int i; + int j; + + for (i = 0; i < 32; i++) + for (j = 0; j < 32; j++) + { + /** + ** +-----------+ + ** | W | + ** | +-----+ | + ** | | | | + ** | | B | | + ** | | | | + ** | +-----+ | + ** | | + ** +-----------+ + **/ + int i2 = i - height / 2; + int j2 = j - width / 2; + int h8 = height / 8; + int w8 = width / 8; + if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) { + data[i][j] = 0x00; + } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) { + data[i][j] = 0x55; + } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) { + data[i][j] = 0xaa; + } else { + data[i][j] = 0xff; + } + } + + glTexImage2D( GL_TEXTURE_2D, 0, + GL_ALPHA8, + 32, 32, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, data ); + } + + + glClearColor(.1, .3, .5, 0); } static void Reshape(int width, int height) @@ -142,7 +219,6 @@ static void Display(void) glEnd(); glFlush(); - if (show_fps) { ++frame_cnt; glutPostRedisplay(); @@ -158,14 +234,17 @@ int main(int argc, char **argv) glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); args(argc, argv); glutCreateWindow(filename); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); Init(); +#ifndef WIN32 if (show_fps) { signal(SIGALRM, alarmhandler); alarm(5); } +#endif glutMainLoop(); return 0; } diff --git a/progs/fp/kill-pos.txt b/progs/fp/kill-pos.txt new file mode 100644 index 00000000000..5ff4f6f2c84 --- /dev/null +++ b/progs/fp/kill-pos.txt @@ -0,0 +1,9 @@ +!!ARBfp1.0 +TEMP R0; +SUB R0.xy, fragment.position, {125}.x; +MOV R0.zw, {0}.x; +DP3 R0, R0, R0; +SUB R0.x, R0, {10000}.x; +KIL -R0.x; +MOV result.color, fragment.color; +END diff --git a/progs/fp/position.txt b/progs/fp/position.txt index 27fac12a3a5..1875897d781 100644 --- a/progs/fp/position.txt +++ b/progs/fp/position.txt @@ -1,3 +1,4 @@ !!ARBfp1.0 -MUL result.color, fragment.position, {.005}.x; +MOV result.color, {0}.x; +MUL result.color.xy, fragment.position, {.005}.x; END diff --git a/progs/fp/tex-pos-kil-1.txt b/progs/fp/tex-pos-kil-1.txt new file mode 100644 index 00000000000..3f01e79ffe7 --- /dev/null +++ b/progs/fp/tex-pos-kil-1.txt @@ -0,0 +1,7 @@ +!!ARBfp1.0 +TEMP R0; +MUL R0, fragment.position, {0.03125}.x; +TEX R0, R0, texture[1], 2D; +KIL -R0; +MOV result.color, fragment.color; +END diff --git a/progs/fp/tex-pos-kil.txt b/progs/fp/tex-pos-kil.txt new file mode 100644 index 00000000000..b7aaa9f7c88 --- /dev/null +++ b/progs/fp/tex-pos-kil.txt @@ -0,0 +1,8 @@ +!!ARBfp1.0 +TEMP R0; +MUL R0, fragment.position, {0.008}.x; +TEX R0, R0, texture[0], 2D; +SUB R0, R0, {0.25}.x; +KIL R0.xyzz; +MOV result.color, fragment.color; +END diff --git a/progs/fp/tex-pos.txt b/progs/fp/tex-pos.txt new file mode 100644 index 00000000000..b969f423f57 --- /dev/null +++ b/progs/fp/tex-pos.txt @@ -0,0 +1,6 @@ +!!ARBfp1.0 +TEMP R0; +MOV R0, {0.0}.x; +MUL R0.xy, fragment.position, {0.008}.x; +TEX result.color, R0, texture[0], 2D; +END diff --git a/progs/fp/tex.txt b/progs/fp/tex.txt new file mode 100644 index 00000000000..b3a885d9e07 --- /dev/null +++ b/progs/fp/tex.txt @@ -0,0 +1,3 @@ +!!ARBfp1.0 +TEX result.color, fragment.color, texture[0], 2D; +END |