Sign in to follow this  

render mesh/lighting

Recommended Posts

Hello, I need to render the mesh.It is given by set of its surfaces each surface is presented by its vertexes(x,y,z) The camera and lifgt sourse has to be placed at the same place. I try such a code:

   GLfloat light_position[] = {0.0,
                                 0.0,2*m_allModels.getDiam(), 1.0 };
   GLfloat white_light[] = { 0.7, 0.3, 0.2, 1.0 };

             GL_POSITION, light_position);
   glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light);

    GLdouble diam = m_allModels.getDiam();
   GLdouble left = m_allModels.getCenter()[0] - diam;
   GLdouble right = m_allModels.getCenter()[0] + diam;
   GLdouble bottom = m_allModels.getCenter()[1] - diam;
   GLdouble top = m_allModels.getCenter()[1] + diam;


 //Model view
    gluLookAt (0.0, 0.0,2*m_allModels.getDiam(),
    m_allModels.getCenter()[0],m_allModels.getCenter()[1],m_allModels.getCenter()[2], 0.0, 1.0, 0.0);

    //rener here

I get a strange results seems like the light is place by side (not at the same place as camera) result -- Thank you, Irena [Edited by - arbin on February 8, 2010 2:18:17 PM]

Share this post

Link to post
Share on other sites
First: GLfloat white_light[] = { 0.7, 0.3, 0.2, 1.0 }; this is red/brown rather than white ([smile])

Second: are your object's normals calculated correctly?

Third: Do you call this code every frame? You could move huge parts of the code you posted to an init() function if it doesn't change. Or you split it into pieces (like updateLight(), updateProjection(), ...) and call the respective function, when the data it updates has changed (i.e. light position/color, projection parameters etc.).

Share this post

Link to post
Share on other sites
Recall that the light position is stored in eye space - or in other words, glLightfv multiplies the position you pass in by the modelview matrix.

Thus, unless you set the modelview matrix to identity before setting the light position, your light position won't be in world space.

Share this post

Link to post
Share on other sites
If you are calling the code every frame and there's no glLoadIdentity(); before calling it, then what swiftcoder said would apply: in frame n you alter the modelview matrix while rendering your objects and if you don't reset it to identity in frame n+1 you'll multiply the light's position with the last value of the modelview matrix.

Thus, your light will be in the correct position in frame 0 and in the wrong position in all frames that follow. Provided that your camera and models don't move the light would stay stationary albeit in the wrong location.

Share this post

Link to post
Share on other sites
This is a part of function which is called only once
In its rendering section it goes in loop over all surfaces,
drawing in every iteration new surface.Is every such iteretation
considered as a new frame?

Surfaces draw code:

for(unsigned int modelIdx = 0;modelIdx < m_allModels.zise();++modelIdx)
model curModel = m_allModels.getModel(modelIdx);
for(unsigned int modelSurfIdx = 0;modelSurfIdx <curModel.surfNum();
surface curSurf = curModel.getSurface(modelSurfIdx);
glBegin( GL_POLYGON );

for(unsigned int vertIdx = 0;vertIdx< curSurf.size();++vertIdx)
unsigned int curVertIdx = curSurf.getSurfVertices()[vertIdx];
vertex curVert = curModel.getVertex(curVertIdx);


Share this post

Link to post
Share on other sites

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