From 55c1894d0a03a76fcdaed61528ea7e5c74237e38 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Dec 2007 13:21:45 -0500 Subject: Add the new test program for fp's. --- progs/fp/fp-tri.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 progs/fp/fp-tri.c (limited to 'progs/fp/fp-tri.c') diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c new file mode 100644 index 0000000000..cb991f803e --- /dev/null +++ b/progs/fp/fp-tri.c @@ -0,0 +1,169 @@ + +#include +#include +#include +#define GL_GLEXT_PROTOTYPES +#include +#include +#include + +unsigned show_fps = 0; +unsigned int frame_cnt = 0; +void alarmhandler(int); +static const char *filename = NULL; + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); + fprintf(stderr, "\n" ); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -fps show frames per second\n"); +} + +void alarmhandler (int sig) +{ + if (sig == SIGALRM) { + printf("%d frames in 5.0 seconds = %.3f FPS\n", frame_cnt, + frame_cnt / 5.0); + + frame_cnt = 0; + } + signal(SIGALRM, alarmhandler); + alarm(5); +} + +static void args(int argc, char *argv[]) +{ + GLint i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + } + else if (i == argc - 1) { + filename = argv[i]; + } + else { + usage(argv[0]); + exit(1); + } + } + + if (!filename) { + usage(argv[0]); + exit(1); + } +} + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + char buf[4096]; + GLuint sz; + FILE *f; + + if ((f = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Couldn't open %s\n", filename); + exit(1); + } + + sz = fread(buf, 1, sizeof(buf), f); + if (!feof(f)) { + fprintf(stderr, "file too long\n"); + exit(1); + } + fprintf(stderr, "%.*s\n", sz, buf); + + if (!glutExtensionSupported("GL_ARB_fragment_program")) { + printf("Error: GL_ARB_fragment_program not supported!\n"); + exit(1); + } + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* Setup the fragment program */ + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prognum); + glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + sz, (const GLubyte *)buf); + + errno = glGetError(); + printf("glGetError = 0x%x\n", errno); + if (errno != GL_NO_ERROR) { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n", + (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + glEnable(GL_FRAGMENT_PROGRAM_ARB); + + glClearColor(.3, .3, .3, 0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,1); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(1,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,1,0); + glVertex3f(-0.9, 0.0, -30.0); + glEnd(); + + glFlush(); + + if (show_fps) { + ++frame_cnt; + glutPostRedisplay(); + } +} + + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(250, 250); + glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); + glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + args(argc, argv); + Init(); + if (show_fps) { + signal(SIGALRM, alarmhandler); + alarm(5); + } + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 1f135456795adfb1d739a6fb66ab9540aa79b461 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 12 Sep 2008 10:28:36 +0100 Subject: fp: put test name in window title, add run script --- progs/fp/fp-tri.c | 4 ++-- progs/fp/run.sh | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100755 progs/fp/run.sh (limited to 'progs/fp/fp-tri.c') diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index cb991f803e..c07cfa2076 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -154,11 +154,11 @@ int main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize(250, 250); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); - glutCreateWindow(argv[0]); + args(argc, argv); + glutCreateWindow(filename); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); - args(argc, argv); Init(); if (show_fps) { signal(SIGALRM, alarmhandler); diff --git a/progs/fp/run.sh b/progs/fp/run.sh new file mode 100755 index 0000000000..480f8108a3 --- /dev/null +++ b/progs/fp/run.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +for i in *.txt ; do +echo $i +./fp-tri $i +done + -- cgit v1.2.3 From fa7529335c38d4c139e5b1fc17a518f7e5fa1d82 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 18 Sep 2008 14:14:56 +0200 Subject: progs/fp: Add a bit of local variable testing to fp-tri --- progs/fp/fp-tri.c | 2 ++ progs/fp/local.txt | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 progs/fp/local.txt (limited to 'progs/fp/fp-tri.c') diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index cb991f803e..2512e824ee 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -130,6 +130,8 @@ static void Display(void) { glClear(GL_COLOR_BUFFER_BIT); + glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, 1.0, 1.0, 0.0, 0.0); + glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, 0.0, 0.0, 1.0, 1.0); glBegin(GL_TRIANGLES); glColor3f(0,0,1); glVertex3f( 0.9, -0.9, -30.0); diff --git a/progs/fp/local.txt b/progs/fp/local.txt new file mode 100644 index 0000000000..6cb2a2f13c --- /dev/null +++ b/progs/fp/local.txt @@ -0,0 +1,11 @@ +!!ARBfp1.0 +TEMP R0; +PARAM c[4] = { { 0, 0, 0, 0 }, + program.local[0..1], + { 1, 1, 1, 1 } }; +MOV R0, c[1]; +SUB R0, R0, c[0]; +ADD R0, R0, c[2]; +MUL R0, R0, c[3]; +MOV result.color, R0; +END -- cgit v1.2.3