Sign in to follow this  

See-through Teapot with GLSL shaders (solved)

This topic is 3308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
I think so.

Here is what my initialization code looks like right now:

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

...

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST | GL_LIGHTING | GL_LIGHT0 | GL_CULL_FACE);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

glCullFace(GL_BACK);

Share this post


Link to post
Share on other sites
Quote:
Original post by Guy Meh
glEnable(GL_DEPTH_TEST | GL_LIGHTING | GL_LIGHT0 | GL_CULL_FACE);


I don't believe you can 'or' together the args for glEnable()

try doing them one at a time

glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
etc.

Share this post


Link to post
Share on other sites

This topic is 3308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this