I've decided to try out GLSL, and wrote a demo that shows a rotating teapot. The problem is that the teapot is
"see-through."
My vertex shader:
varying vec3 normal;
varying vec3 vecToLight;
void main()
{
gl_Position = ftransform();
normal = normalize(gl_NormalMatrix * gl_Normal);
vecToLight = normalize(gl_LightSource[0].position.xyz);
}
My fragment shader:
varying vec3 normal;
varying vec3 vecToLight;
void main()
{
float intensity;
vec4 color;
intensity = dot(vecToLight, normal);
if (intensity > 0.95)
color = vec4(0.50, 0.50, 1.0, 1.0);
else if (intensity > 0.5)
color = vec4(0.3750, 0.3750, 0.750, 1.0);
else if (intensity > 0.25)
color = vec4(0.250, 0.250, 0.50, 1.0);
else
color = vec4(0.1250, 0.1250, 0.250, 1.0);
gl_FragColor = color;
}
My main program (at least, the parts I think are relevant):
#include "glut/glut.h"
...
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
/* ANGLE incremented in each GLUT update */
glRotatef((GLfloat)ANGLE, 0.0f, 1.0f, 0.0f);
glutSolidTeapot(1.0);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
float lightPos[] = {3.0f, 3.0f, 3.0f};
glutInit(&argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(SCR_WIDTH, SCR_HEIGHT);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(SCR_TITLE);
...
glutDisplayFunc(render);
initShaders(); /* Load, compile, and link my shaders */
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST | GL_LIGHTING | GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glutMainLoop();
return 0;
}
[Edited by - Guy Meh on December 26, 2008 8:17:19 PM]