diff options
author | Michal Krol <mjkrol@gmail.org> | 2006-04-25 10:11:59 +0000 |
---|---|---|
committer | Michal Krol <mjkrol@gmail.org> | 2006-04-25 10:11:59 +0000 |
commit | 6acf1e93a291511cfb20b0e2aeda6e71ceb62a62 (patch) | |
tree | 9c959b0fc2c5e6f49f5625813294d2048d48959c /progs/demos | |
parent | cb0ae25a4efd85128f47aa30b772abb7245d53f6 (diff) |
Remove carriage returns.
Diffstat (limited to 'progs/demos')
-rw-r--r-- | progs/demos/arbfslight.c | 212 |
1 files changed, 106 insertions, 106 deletions
diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c index 1164f2d660..30332a3f64 100644 --- a/progs/demos/arbfslight.c +++ b/progs/demos/arbfslight.c @@ -1,30 +1,30 @@ /* * Use GL_ARB_fragment_shader and GL_ARB_vertex_shader to implement - * simple per-pixel lighting.
- *
- * Michal Krol
+ * simple per-pixel lighting. + * + * Michal Krol * 20 February 2006 - *
+ * * Based on the original demo by: * Brian Paul * 17 April 2003 - */
-
-#ifdef WIN32
-#include <windows.h>
+ */ + +#ifdef WIN32 +#include <windows.h> #endif #include <stdio.h> -#include <stdlib.h>
+#include <stdlib.h> #include <GL/gl.h> -#include <GL/glut.h>
-#include <GL/glext.h>
-
-#ifdef WIN32
-#define GETPROCADDRESS wglGetProcAddress
-#else
-#define GETPROCADDRESS glutGetProcAddress
-#endif
+#include <GL/glut.h> +#include <GL/glext.h> + +#ifdef WIN32 +#define GETPROCADDRESS wglGetProcAddress +#else +#define GETPROCADDRESS glutGetProcAddress +#endif static GLfloat diffuse[4] = { 0.5f, 0.5f, 1.0f, 1.0f }; static GLfloat specular[4] = { 0.8f, 0.8f, 0.8f, 1.0f }; @@ -32,12 +32,12 @@ static GLfloat lightPos[4] = { 0.0f, 10.0f, 20.0f, 1.0f }; static GLfloat delta = 1.0f; static GLhandleARB fragShader; -static GLhandleARB vertShader;
-static GLhandleARB program;
-
-static GLint uLightPos;
-static GLint uDiffuse;
-static GLint uSpecular;
+static GLhandleARB vertShader; +static GLhandleARB program; + +static GLint uLightPos; +static GLint uDiffuse; +static GLint uSpecular; static GLboolean anim = GL_TRUE; static GLboolean wire = GL_FALSE; @@ -46,30 +46,30 @@ static GLboolean pixelLight = GL_TRUE; static GLint t0 = 0; static GLint frames = 0; -static GLfloat xRot = 0.0f, yRot = 0.0f;
-
-static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
-static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
-static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
-static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
-static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
-static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
-static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
+static GLfloat xRot = 0.0f, yRot = 0.0f; + +static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; +static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; +static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; +static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; static PFNGLUNIFORM4FVARBPROC glUniform4fvARB = NULL; static void Redisplay (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if (pixelLight)
- {
- glUseProgramObjectARB (program);
+ if (pixelLight) + { + glUseProgramObjectARB (program); glUniform4fvARB (uLightPos, 1, lightPos); glDisable(GL_LIGHTING); } - else
- {
+ else + { glUseProgramObjectARB (0); glLightfv (GL_LIGHT0, GL_POSITION, lightPos); glEnable(GL_LIGHTING); @@ -78,16 +78,16 @@ static void Redisplay (void) glPushMatrix (); glRotatef (xRot, 1.0f, 0.0f, 0.0f); glRotatef (yRot, 0.0f, 1.0f, 0.0f); - glutSolidSphere (2.0, 10, 5);
+ glutSolidSphere (2.0, 10, 5); glPopMatrix (); glutSwapBuffers(); frames++; - if (anim)
+ if (anim) { GLint t = glutGet (GLUT_ELAPSED_TIME); - if (t - t0 >= 5000)
+ if (t - t0 >= 5000) { GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; GLfloat fps = frames / seconds; @@ -120,9 +120,9 @@ static void Reshape (int width, int height) static void Key (unsigned char key, int x, int y) { (void) x; - (void) y;
+ (void) y; - switch (key)
+ switch (key) { case ' ': case 'a': @@ -161,12 +161,12 @@ static void Key (unsigned char key, int x, int y) static void SpecialKey (int key, int x, int y) { - const GLfloat step = 3.0f;
+ const GLfloat step = 3.0f; (void) x; - (void) y;
+ (void) y; - switch (key)
+ switch (key) { case GLUT_KEY_UP: xRot -= step; @@ -186,80 +186,80 @@ static void SpecialKey (int key, int x, int y) static void Init (void) { - static const char *fragShaderText =
- "uniform vec4 lightPos;\n"
- "uniform vec4 diffuse;\n"
+ static const char *fragShaderText = + "uniform vec4 lightPos;\n" + "uniform vec4 diffuse;\n" "uniform vec4 specular;\n" - "void main () {\n"
- " // Compute dot product of light direction and normal vector\n"
- " float dotProd;\n"
- " dotProd = clamp (dot (normalize (lightPos).xyz, normalize (gl_TexCoord[0]).xyz), 0.0, 1.0);\n"
- " // Compute diffuse and specular contributions\n"
- " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n"
+ "void main () {\n" + " // Compute dot product of light direction and normal vector\n" + " float dotProd;\n" + " dotProd = clamp (dot (normalize (lightPos).xyz, normalize (gl_TexCoord[0]).xyz), 0.0, 1.0);\n" + " // Compute diffuse and specular contributions\n" + " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n" "}\n" ; static const char *vertShaderText = - "void main () {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_TexCoord[0] = vec4 (gl_NormalMatrix * gl_Normal, 1.0);\n"
+ "void main () {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " gl_TexCoord[0] = vec4 (gl_NormalMatrix * gl_Normal, 1.0);\n" "}\n" ; -
- if (!glutExtensionSupported ("GL_ARB_fragment_shader"))
+ + if (!glutExtensionSupported ("GL_ARB_fragment_shader")) { printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); exit(1); - }
- if (!glutExtensionSupported ("GL_ARB_shader_objects"))
- {
- printf ("Sorry, this demo requires GL_ARB_shader_objects\n");
- exit(1);
- }
- if (!glutExtensionSupported ("GL_ARB_shading_language_100"))
- {
- printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");
- exit(1);
- }
- if (!glutExtensionSupported ("GL_ARB_vertex_shader"))
- {
- printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");
- exit(1);
+ } + if (!glutExtensionSupported ("GL_ARB_shader_objects")) + { + printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shading_language_100")) + { + printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_vertex_shader")) + { + printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); + exit(1); } - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB");
- glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB");
- glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB");
- glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB");
- glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB");
- glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB");
- glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB");
- glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB");
- glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GETPROCADDRESS ("glUniform4fvARB");
-
- fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
- glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
+ glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB"); + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB"); + glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GETPROCADDRESS ("glUniform4fvARB"); + + fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); + glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); glCompileShaderARB (fragShader); -
- vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);
- glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);
- glCompileShaderARB (vertShader);
-
- program = glCreateProgramObjectARB ();
- glAttachObjectARB (program, fragShader);
- glAttachObjectARB (program, vertShader);
- glLinkProgramARB (program);
- glUseProgramObjectARB (program);
-
- uLightPos = glGetUniformLocationARB (program, "lightPos");
- uDiffuse = glGetUniformLocationARB (program, "diffuse");
- uSpecular = glGetUniformLocationARB (program, "specular");
-
- glUniform4fvARB (uDiffuse, 1, diffuse);
- glUniform4fvARB (uSpecular, 1, specular);
+ + vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); + glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); + glCompileShaderARB (vertShader); + + program = glCreateProgramObjectARB (); + glAttachObjectARB (program, fragShader); + glAttachObjectARB (program, vertShader); + glLinkProgramARB (program); + glUseProgramObjectARB (program); + + uLightPos = glGetUniformLocationARB (program, "lightPos"); + uDiffuse = glGetUniformLocationARB (program, "diffuse"); + uSpecular = glGetUniformLocationARB (program, "specular"); + + glUniform4fvARB (uDiffuse, 1, diffuse); + glUniform4fvARB (uSpecular, 1, specular); glClearColor (0.3f, 0.3f, 0.3f, 0.0f); glEnable (GL_DEPTH_TEST); - glEnable (GL_LIGHT0);
+ glEnable (GL_LIGHT0); glEnable (GL_LIGHTING); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, specular); @@ -286,4 +286,4 @@ int main (int argc, char *argv[]) glutMainLoop (); return 0; } -
+ |