aboutsummaryrefslogtreecommitdiffstats
path: root/progs/demos
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2006-07-29 09:42:03 +0000
committerMichal Krol <[email protected]>2006-07-29 09:42:03 +0000
commit39dd5196e6fa126b5fd4bfd23b665c105ddbf95c (patch)
treec4c8e6f48cdfa130bf5ce0f77a15f86e05d77d83 /progs/demos
parent0e6ef1b1cdb546dfe6f36b7eb3e4a9223ec01ae4 (diff)
Optimize shaders.
Use frame counter.
Diffstat (limited to 'progs/demos')
-rwxr-xr-xprogs/demos/glslnoise.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c
index 2adb114e668..4ee12928164 100755
--- a/progs/demos/glslnoise.c
+++ b/progs/demos/glslnoise.c
@@ -30,6 +30,9 @@ static GLhandleARB program;
static GLint uTime;
+static GLint t0 = 0;
+static GLint frames = 0;
+
static GLfloat u_time = 0.0f;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
@@ -44,15 +47,27 @@ static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
static void Redisplay (void)
{
+ GLint t;
+
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glUniform1fARB (uTime, u_time);
+ glUniform1fARB (uTime, 0.5f * u_time);
glPushMatrix ();
glutSolidSphere (2.0, 20, 10);
glPopMatrix ();
glutSwapBuffers();
+ frames++;
+
+ t = glutGet (GLUT_ELAPSED_TIME);
+ if (t - t0 >= 5000) {
+ GLfloat seconds = (GLfloat) (t - t0) / 1000.0f;
+ GLfloat fps = frames / seconds;
+ printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps);
+ t0 = t;
+ frames = 0;
+ }
}
static void Idle (void)
@@ -88,20 +103,20 @@ static void Key (unsigned char key, int x, int y)
static void Init (void)
{
- static const char *fragShaderText =
- "uniform float time;\n"
- "void main () {\n"
- " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (\n"
- " vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time)))), 1.0);\n"
- "}\n"
- ;
- static const char *vertShaderText =
- "void main () {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_TexCoord[0] = gl_Vertex;\n"
- " gl_FrontColor = gl_Color;\n"
- "}\n"
- ;
+ static const char *fragShaderText =
+ "uniform float time;\n"
+ "varying vec3 position;\n"
+ "void main () {\n"
+ " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n"
+ "}\n"
+ ;
+ static const char *vertShaderText =
+ "varying vec3 position;\n"
+ "void main () {\n"
+ " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " position = 4.0 * gl_Vertex.xyz;\n"
+ "}\n"
+ ;
if (!glutExtensionSupported ("GL_ARB_fragment_shader"))
{