Jump to content
  • Advertisement
Sign in to follow this  
Guy Meh

See-through Teapot with GLSL shaders (solved)

This topic is 3637 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!