Skip to main content
gamedev.net
🔒 Locked

OGL lighting problem

Started by markvdh Mar 11, 2003 at 7:45 PM 0 replies 250+ views
Original Post
markvdh
markvdh
Alright, I have been working on this for about 3hrs with no luck, I am extreamly frustrated right now. My OGL seen with not respond to diffuse light only ambient (so my scene is pitch black if I dont add ambient.) Here is the relevent code. If someone could help that would be great! ---GLOBAL VARS---- GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 0.0, 0.0, -15.0, 0.0 }; --------CODE------ int initGL(GLvoid) { resizeGLScene(GLWin.width, GLWin.height); initTextures(); initLights(); glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); camera.PositionCamera(0, 0, 0, 0, 0, -1, 0, 1, 0); glFlush(); return True; } void initLights() { glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHT0); } int drawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glLightfv(GL_LIGHT0, GL_POSITION, light_position); gluLookAt(camera.m_vPosition.x, camera.m_vPosition.y, camera.m_vPosition.z, camera.m_vView.x, camera.m_vView.y, camera.m_vView.z, camera.m_vUpVector.x, camera.m_vUpVector.y, camera.m_vUpVector.z); renderWorld(); glXSwapBuffers(GLWin.dpy, GLWin.win); return True; } void renderWorld() { GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glNormal3f(0.0, 0.0, -1.0); glTexCoord2f(-7.0, -7.0); glVertex3f(-20.0f, -6.0f, 0.0f); glTexCoord2f(-7.0, 7.0); glVertex3f(-20.0f, 6.0f, 0.0f); glTexCoord2f(7.0, 7.0); glVertex3f(20.0f, 6.0f, 0.0f); glTexCoord2f(7.0, -7.0); glVertex3f(20.0f, -6.0f, 0.0f); glEnd(); //front glBegin(GL_QUADS); glNormal3f(0.0, 0.0, 1.0); glTexCoord2f(-7.0, -7.0); glVertex3f(-20.0f, -6.0f, -30.0f); glTexCoord2f(7.0, -7.0); glVertex3f(20.0f, -6.0f, -30.0f); glTexCoord2f(7.0, 7.0); glVertex3f(20.0f, 6.0f, -30.0f); glTexCoord2f(-7.0, 7.0); glVertex3f(-20.0f, 6.0f, -30.0f); glEnd(); //left glBegin(GL_QUADS); glNormal3f(1.0, 0.0, 0.0); glTexCoord2f(-7.0, 7.0); glVertex3f(-20.0f, 6.0f, -30.0f); glTexCoord2f(7.0, 7.0); glVertex3f(-20.0f, 6.0f, 0.0f); glTexCoord2f(7.0, -7.0); glVertex3f(-20.0f, -6.0f, 0.0f); glTexCoord2f(-7.0, -7.0); glVertex3f(-20.0f, -6.0f, -30.0f); glEnd(); //right glBegin(GL_QUADS); glNormal3f(-1.0, 0.0, 0.0); glTexCoord2f(7.0, -7.0); glVertex3f(20.0f, 6.0f, -30.0f); glTexCoord2f(7.0, 7.0); glVertex3f(20.0f, -6.0f, -30.0f); glTexCoord2f(-7.0, 7.0); glVertex3f(20.0f, -6.0f, 0.0f); glTexCoord2f(-7.0, -7.0); glVertex3f(20.0f, 6.0f, 0.0f); glEnd(); //floor glBindTexture(GL_TEXTURE_2D, texture[1]); glBegin(GL_QUADS); glNormal3f(0.0, 1.0, 0.0); glTexCoord2f(-4.0, -4.0); glVertex3f(-20.0f, -6.0f, -30.0f); glTexCoord2f(-4.0, 4.0); glVertex3f(-20.0f, -6.0f, 0.0f); glTexCoord2f(4.0, 4.0); glVertex3f(20.0f, -6.0f, 0.0f); glTexCoord2f(4.0, -4.0); glVertex3f(20.0f, -6.0f, -30.0f); glEnd(); //roof glBindTexture(GL_TEXTURE_2D, texture[2]); glBegin(GL_QUADS); glNormal3f(0.0, -1.0, 0.0); glTexCoord2f(-4.0, -4.0); glVertex3f(-20.0f, 6.0f, -30.0f); glTexCoord2f(4.0, -4.0); glVertex3f(20.0f, 6.0f, -30.0f); glTexCoord2f(4.0, 4.0); glVertex3f(20.0f, 6.0f, 0.0f); glTexCoord2f(-4.0, 4.0); glVertex3f(-20.0f, 6.0f, 0.0f); glEnd(); } -------------AND JUST IN CASE THERE IS SOMETHING WRONG WITH THE TEXTURES (I DONT THINK SO)------------------------------- void initTextures() { TGAFILE *wall; TGAFILE *floor; TGAFILE *roof; wall = (TGAFILE*)malloc(sizeof(TGAFILE)); LoadTGAFile("./wall.tga", wall); floor = (TGAFILE*)malloc(sizeof(TGAFILE)); LoadTGAFile("./floor.tga", floor); roof = (TGAFILE*)malloc(sizeof(TGAFILE)); LoadTGAFile("./roof.tga", roof); glGenTextures(3, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, wall->imageWidth, wall->imageHeight, GL_RGB, GL_UNSIGNED_BYTE, wall->imageData); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, floor->imageWidth, floor->imageHeight, GL_RGB, GL_UNSIGNED_BYTE, floor->imageData); glBindTexture(GL_TEXTURE_2D, texture[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, roof->imageWidth, roof->imageHeight, GL_RGB, GL_UNSIGNED_BYTE, roof->imageData); }
sjelkjd
sjelkjd
did you glEnable(GL_LIGHT0) ?
edit: nm, didn't read all the code

You're probably saturating your colors, because your ambient material is (1,1,1,1). Try making it (0.2,0.2,0.2,1) and see what happens.

[edited by - sjelkjd on March 11, 2003 9:23:41 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.