summaryrefslogtreecommitdiff
path: root/progs/vp/vp-tris.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/vp/vp-tris.c')
-rw-r--r--progs/vp/vp-tris.c85
1 files changed, 73 insertions, 12 deletions
diff --git a/progs/vp/vp-tris.c b/progs/vp/vp-tris.c
index 5dbe5ac835..87cb12b984 100644
--- a/progs/vp/vp-tris.c
+++ b/progs/vp/vp-tris.c
@@ -5,7 +5,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
-#define GL_GLEXT_PROTOTYPES
+
+#ifndef WIN32
+#include <unistd.h>
+#include <signal.h>
+#endif
+
+#include <GL/glew.h>
#include <GL/glut.h>
static const char *filename = NULL;
@@ -18,8 +24,29 @@ static void usage( char *name )
fprintf( stderr, "options:\n" );
fprintf( stderr, " -f flat shaded\n" );
fprintf( stderr, " -nNr subdivision steps\n" );
+ fprintf( stderr, " -fps show frames per second\n" );
+}
+
+unsigned show_fps = 0;
+unsigned int frame_cnt = 0;
+
+#ifndef WIN32
+
+void alarmhandler(int);
+
+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);
}
+#endif
static void args(int argc, char *argv[])
{
@@ -32,6 +59,9 @@ static void args(int argc, char *argv[])
else if (strcmp(argv[i], "-f") == 0) {
glShadeModel(GL_FLAT);
}
+ else if (strcmp(argv[i], "-fps") == 0) {
+ show_fps = 1;
+ }
else if (i == argc - 1) {
filename = argv[i];
}
@@ -62,19 +92,31 @@ static void Init( void )
exit(1);
}
- sz = fread(buf, 1, sizeof(buf), f);
+ sz = (GLuint) fread(buf, 1, sizeof(buf), f);
if (!feof(f)) {
fprintf(stderr, "file too long\n");
exit(1);
}
fprintf(stderr, "%.*s\n", sz, buf);
-
- glGenProgramsARB(1, &prognum);
- glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
- glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
- sz, (const GLubyte *) buf);
+ if (strncmp( buf, "!!VP", 4 ) == 0) {
+ glEnable( GL_VERTEX_PROGRAM_NV );
+ glGenProgramsNV( 1, &prognum );
+ glBindProgramNV( GL_VERTEX_PROGRAM_NV, prognum );
+ glLoadProgramNV( GL_VERTEX_PROGRAM_NV, prognum, sz, (const GLubyte *) buf );
+ assert( glIsProgramNV( prognum ) );
+ }
+ else {
+ glEnable(GL_VERTEX_PROGRAM_ARB);
+
+ glGenProgramsARB(1, &prognum);
+
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
+ glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ sz, (const GLubyte *) buf);
+ assert(glIsProgramARB(prognum));
+ }
errno = glGetError();
printf("glGetError = %d\n", errno);
@@ -86,7 +128,17 @@ static void Init( void )
printf("errorpos: %d\n", errorpos);
printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
}
- assert(glIsProgramARB(prognum));
+
+ {
+ const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
+ const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
+ const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
+ const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
+ }
}
@@ -147,8 +199,6 @@ static void Display( void )
glClearColor(0.3, 0.3, 0.3, 1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glEnable(GL_VERTEX_PROGRAM_NV);
-
glBegin(GL_TRIANGLES);
@@ -168,7 +218,11 @@ static void Display( void )
glEnd();
- glFlush();
+ glFlush();
+ if (show_fps) {
+ ++frame_cnt;
+ glutPostRedisplay();
+ }
}
@@ -205,12 +259,19 @@ int main( int argc, char *argv[] )
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 250, 250 );
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
- glutCreateWindow(argv[0]);
+ glutCreateWindow(argv[argc-1]);
+ glewInit();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutDisplayFunc( Display );
args( argc, argv );
Init();
+#ifndef WIN32
+ if (show_fps) {
+ signal(SIGALRM, alarmhandler);
+ alarm(5);
+ }
+#endif
glutMainLoop();
return 0;
}