summaryrefslogtreecommitdiff
path: root/progs/demos
diff options
context:
space:
mode:
authorMichal Krol <mjkrol@gmail.org>2006-02-21 12:35:06 +0000
committerMichal Krol <mjkrol@gmail.org>2006-02-21 12:35:06 +0000
commitcc1591667d55a6dbfafbd3d6a7afa9f9288c625d (patch)
treea3ef92d3a8667e830c94db9441089dbadb45e31a /progs/demos
parent8986e36f368d11bcf3f1938d77b5df69aa2ee11b (diff)
More GLSL code:
- uniforms (only GetLocation, Uniform1f and Uniform4fv for now for demos); - fix bugs and optimize array size handling; - 2D texture sampling (needs Enable(TEXTURE_2D) to work); - decrease built-in library assembly size by 30%.
Diffstat (limited to 'progs/demos')
-rw-r--r--progs/demos/arbfslight.c43
-rwxr-xr-xprogs/demos/glslnoise.c31
2 files changed, 37 insertions, 37 deletions
diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c
index 2e91139bdd..1164f2d660 100644
--- a/progs/demos/arbfslight.c
+++ b/progs/demos/arbfslight.c
@@ -3,7 +3,7 @@
* simple per-pixel lighting.
*
* Michal Krol
- * 17 February 2006
+ * 20 February 2006
*
* Based on the original demo by:
* Brian Paul
@@ -34,6 +34,10 @@ static GLfloat delta = 1.0f;
static GLhandleARB fragShader;
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;
@@ -50,7 +54,9 @@ static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
+static PFNGLUNIFORM4FVARBPROC glUniform4fvARB = NULL;
static void Redisplay (void)
{
@@ -59,8 +65,7 @@ static void Redisplay (void)
if (pixelLight)
{
glUseProgramObjectARB (program);
- /* XXX source from uniform lightPos */
- glTexCoord4fv (lightPos);
+ glUniform4fvARB (uLightPos, 1, lightPos);
glDisable(GL_LIGHTING);
}
else
@@ -181,21 +186,11 @@ static void SpecialKey (int key, int x, int y)
static void Init (void)
{
- static const char *fragShaderText =
+ static const char *fragShaderText =
+ "uniform vec4 lightPos;\n"
+ "uniform vec4 diffuse;\n"
+ "uniform vec4 specular;\n"
"void main () {\n"
-
- /* XXX source from uniform lightPos */
- " vec4 lightPos;\n"
- " lightPos = gl_TexCoord[1];\n"
-
- /* XXX source from uniform diffuse */
- " vec4 diffuse;\n"
- " diffuse = vec4 (0.5, 0.5, 1.0, 1.0);\n"
-
- /* XXX source from uniform specular */
- " vec4 specular;\n"
- " specular = vec4 (0.8, 0.8, 0.8, 1.0);\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"
@@ -207,9 +202,6 @@ static void Init (void)
"void main () {\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" gl_TexCoord[0] = vec4 (gl_NormalMatrix * gl_Normal, 1.0);\n"
-
- /* XXX source from uniform lightPos */
- " gl_TexCoord[1] = gl_MultiTexCoord0;\n"
"}\n"
;
@@ -241,6 +233,8 @@ static void Init (void)
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);
@@ -255,6 +249,13 @@ static void Init (void)
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);
diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c
index 1041439337..463af12897 100755
--- a/progs/demos/glslnoise.c
+++ b/progs/demos/glslnoise.c
@@ -2,7 +2,7 @@
* GLSL noise demo.
*
* Michal Krol
- * 17 February 2006
+ * 20 February 2006
*
* Based on the original demo by:
* Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
@@ -28,6 +28,8 @@ static GLhandleARB fragShader;
static GLhandleARB vertShader;
static GLhandleARB program;
+static GLint uTime;
+
static GLfloat u_time = 0.0f;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
@@ -36,14 +38,15 @@ static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
+static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
static void Redisplay (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- /* XXX source from uniform time */
- glTexCoord1f (u_time);
+ glUniform1fARB (uTime, u_time);
glPushMatrix ();
glutSolidSphere (2.0, 20, 10);
@@ -85,16 +88,11 @@ static void Key (unsigned char key, int x, int y)
static void Init (void)
{
- static const char *fragShaderText =
+ static const char *fragShaderText =
+ "uniform float time;\n"
"void main () {\n"
-
- /* XXX source from uniform time */
- " float time;\n"
- " time = gl_TexCoord[1].x;\n"
-
- " vec4 v;\n"
- " v = vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time);\n"
- " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (v))), 1.0);\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 =
@@ -102,9 +100,6 @@ static void Init (void)
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" gl_TexCoord[0] = gl_Vertex;\n"
" gl_FrontColor = gl_Color;\n"
-
- /* XXX source from uniform time */
- " gl_TexCoord[1] = gl_MultiTexCoord0;\n"
"}\n"
;
@@ -136,6 +131,8 @@ static void Init (void)
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress ("glAttachObjectARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress ("glLinkProgramARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glUseProgramObjectARB");
+ glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB");
+ glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GETPROCADDRESS ("glUniform1fARB");
fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
@@ -150,6 +147,8 @@ static void Init (void)
glAttachObjectARB (program, vertShader);
glLinkProgramARB (program);
glUseProgramObjectARB (program);
+
+ uTime = glGetUniformLocationARB (program, "time");
glClearColor (0.0f, 0.1f, 0.3f, 1.0f);
glEnable (GL_CULL_FACE);