void CGL_Light3D::Init ( int light ) {
LIGHT = light;
// set all members to OpenGL defaults
// all values comply with the OpenGL 1.2.1 Specification
ambient[0] = 0.0f;
ambient[1] = 0.0f;
ambient[2] = 0.0f;
ambient[3] = 1.0f;
if ( light == GL_LIGHT0 ) {
diffuse[0] = 5.0f;
diffuse[1] = 1.0f;
diffuse[2] = 2.0f;
diffuse[3] = 1.0f;
} else {
diffuse[0] = 0.0f;
diffuse[1] = 0.0f;
diffuse[2] = 0.0f;
diffuse[3] = 1.0f;
}
if ( light == GL_LIGHT0 ) {
specular[0] = 1.0f;
specular[1] = 1.0f;
specular[2] = 1.0f;
specular[3] = 1.0f;
} else {
specular[0] = 0.0f;
specular[1] = 0.0f;
specular[2] = 0.0f;
specular[3] = 1.0f;
}
position[0] = 0.0f;
position[1] = 1.0f;
position[2] = 0.0f;
position[3] = 0.0f;
spot_direction[0] = 0.0f;
spot_direction[1] = 0.0f;
spot_direction[2] = -1.0f;
spot_exponent = 0.0f;
spot_cutoff = 180.0f;
constant_attenuation = 1.0f;
linear_attenuation = 0.0f;
quadratic_attenuation = 0.0f;
TurnOn(LIGHT);
}
void CGL_Light3D::TurnOn ( int light ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LIGHT=light;
glEnable(LIGHT);
glLightfv(LIGHT, GL_AMBIENT, ambient);
glLightfv(LIGHT, GL_DIFFUSE, diffuse);
glLightfv(LIGHT, GL_SPECULAR, specular);
}
void CGL_Light3D::TurnOff ( int light ) {
LIGHT=light;
glDisable(LIGHT);
}
void CGL_Light3D::TurnOffAllLights () {
glDisable(GL_LIGHTING);
}
🔒 Locked
Lighting = black window?
Advertisement
Original Post
hi all ! Im trying to enable lighting in my scene in opengl. The thing is that when I enable it all I get is a black window (if I disable the lightning then I can see my model). Here is the code that Im usingç And yes Im enabling GL_LIGHTING when I Initiate the engine. THanks for the help!
1) did u send the light position?. if yes is the light facing the polygons
correctly ?.
2) did u calculate the normals for every polygon in the scene?. if yes are the normals recalculating after Scaling/... etc?.
not sure but if opengl normalize the lighting color but i guess
it should be between [0,1]. =\
take care.
correctly ?.
2) did u calculate the normals for every polygon in the scene?. if yes are the normals recalculating after Scaling/... etc?.
not sure but if opengl normalize the lighting color but i guess
it should be between [0,1]. =\
take care.
Well I use the light position that I wrote in last entry in this case
position[0] = 0.0f;
position[1] = 1.0f;
position[2] = 0.0f;
position[3] = 0.0f;
Dont know if thats correct tho...
And yes the polygons are normalized, but Im not rescaling or moving anything, I just have a model loaded into a space and a moving camera, now I want to setup the lights...
Sorry but Im very new into this
Thanks!
position[0] = 0.0f;
position[1] = 1.0f;
position[2] = 0.0f;
position[3] = 0.0f;
Dont know if thats correct tho...
And yes the polygons are normalized, but Im not rescaling or moving anything, I just have a model loaded into a space and a moving camera, now I want to setup the lights...
Sorry but Im very new into this
Thanks!
yes I did both, still see a black window :(
same result
You need to assign normals... they can be calculated to each polygon, google it, and you need to use glNormal3f for it
if I dont use lighting I can see the model with the texture, and yes I do normalize the faces, here is the code that does the trick.
void ASE::draw() { outs("ASE::draw",0); if (loaded) { if (currentScale != desiredScale) setScale(desiredScale); // Since we know how many objects our model has, go through each of them. for (int i=0; i < ASEModel.numOfObjects; i++) { // Make sure we have valid objects just in case. (size() is in the vector class) if (ASEModel.pObject.size() <= 0) break; // Get the current object that we are displaying tASEObject *pObject = &ASEModel.pObject // Check to see if this object has a texture map, if so bind the texture to it. if (pObject->bHasTexture) { // Turn on texture mapping and turn off color glEnable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); // Bind the texture map to the object by it's materialID bindTexture2D(ASEModel.pMaterials[pObject->materialID].texureId); } else { // Turn off texture mapping and turn on color glDisable(GL_TEXTURE_2D); glEnable(GL_COLOR); glEnable(GL_COLOR_MATERIAL); // Reset the color to normal again glColor3ub(255, 255, 255); } // glTranslatef(10.0, -1.0, -80.0f); glBegin(GL_TRIANGLES); // Begin drawing with our selected mode (triangles or lines) // Go through all of the faces (polygons) of the object and draw them for (int j=0; j < pObject->numOfFaces; j++) { // Go through each corner of the triangle and draw it. for (int whichVertex=0; whichVertex < 3; whichVertex++) { // Get the vertex index for each point of the face int vertIndex = pObject->pFaces[j].vertIndex[whichVertex]; // Give OpenGL the normal for this vertex. glNormal3f(pObject->pNormals[ vertIndex ].x, pObject->pNormals[ vertIndex ].y, pObject->pNormals[ vertIndex ].z); // If the object has a texture associated with it, give it a texture coordinate. if (pObject->bHasTexture) { // Make sure there was a UVW map applied to the object or else it won't have tex coords. if (pObject->pTexVerts) { // Get the texture coordinate index int coordIndex = pObject->pFaces[j].coordIndex[whichVertex]; // Assign the UV coordinates to the current vertex being rendered glTexCoord2f(pObject->pTexVerts[ coordIndex ].x, pObject->pTexVerts[ coordIndex ].y); } } else { // Make sure there is a valid material/color assigned to this object if (ASEModel.pMaterials.size() && pObject->materialID >= 0) { // Get and set the color that the object is, since it must not have a texture float *pColor = ASEModel.pMaterials[pObject->materialID].fColor; // Assign the current color to this model glColor3f(pColor[0], pColor[1], pColor[2]); } } // Pass in the current vertex of the object (Corner of current face) glVertex3f(pObject->pVerts[ vertIndex ].x, pObject->pVerts[ vertIndex ].y, pObject->pVerts[ vertIndex ].z); } } glEnd(); // End the drawing glColor3f(0,0,0); glDisable(GL_TEXTURE_2D); glDisable(GL_COLOR_MATERIAL); } } outs("OUT OF ASE::draw",0); }Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement