Jump to content
  • Advertisement
Sign in to follow this  
kaizmpal

OpenGL lighting problems

This topic is 4038 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

this is the drawing method for a program i'm writing in c# using the Tao OpenGL wrapper private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e) { Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL); Gl.glLoadIdentity(); //set light Gl.glShadeModel(Gl.GL_SMOOTH); float[] position = { 0f, 0f, lightz, 1.0f }; float[] ambient = { 0.1f, 0.1f, 0.1f, 1.0f }; float[] diffuse = { 0.5f, 0.5f, 0.5f, 1.0f }; float[] specular = { 0.0f, 0.0f, 0.0f, 1.0f }; Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambient); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, diffuse); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, specular); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, position); Gl.glLightf(Gl.GL_LIGHT0, Gl.GL_CONSTANT_ATTENUATION, 1.0f); Gl.glLightf(Gl.GL_LIGHT0, Gl.GL_LINEAR_ATTENUATION, 1.0f); Gl.glLightf(Gl.GL_LIGHT0, Gl.GL_QUADRATIC_ATTENUATION, 1.0f); Gl.glEnable(Gl.GL_NORMALIZE); Gl.glEnable(Gl.GL_LIGHTING); Gl.glEnable(Gl.GL_LIGHT0); Gl.glEnable(Gl.GL_DEPTH_TEST); //set material float[] mat_ambient_color = { 1.0f, 0.10225f, 0.10225f, 1.0f }; float[] mat_diffuse = { 1.0f, 0.20754f, 0.20754f, 1.0f }; float[] mat_specular = { 1.0f, 0.5f, 0.5f, 1.0f }; Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT, mat_ambient_color); Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, mat_diffuse); //Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, mat_specular); //set perspective & view Glu.gluPerspective(60, (float)this.Width/(float)this.Height,1, 110); Glu.gluLookAt(0, 0, 0, 0, 0, 1, 0, 1, 0); //draw scene drawScene(); //draw paddle drawPaddle(); //draw light Gl.glDisable(Gl.GL_LIGHTING); Gl.glColor3f(1f, 1f, 1f); Gl.glPushMatrix(); Gl.glTranslatef((float)lightx, (float)lighty, (float)lightz); Glut.glutWireCube(5); Gl.glPopMatrix(); } drawScene just draws 5 glutSolidCubes to create a tunnel going into the screen and drawPaddle draws another glutSolidCube at the front (its 3d arkanoid). GL_LIGHT0 can also be moved in and out of the tunnel using the keyboard (by incremeting/decrementing lightz). for some reason which i can't figure out, the side walls turn out almost completely white, and the paddle and back wall are always lit the same (in fact they seem to be most brightly illuminated when lightz is 0, so the light is at the origin, which makes no sense since the camera is at the origin, the paddle has z coordinate 20 and the back wall has z coordinate 100) i have no idea whats going on. please help thank you =)

Share this post


Link to post
Share on other sites
Advertisement
heres a picture to help you see what i mean

Free Image Hosting at www.ImageShack.us

i've been playing around with the attenuation values, and the values for each component of light, with no success

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!