The MASM Forum Archive 2004 to 2012

Project Support Forums => OpenGL Forum => Topic started by: yakovm on February 09, 2010, 07:15:40 AM

Title: [OPENGL] render mesh/lighting
Post by: yakovm on February 09, 2010, 07:15:40 AM
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 light source has to be placed at the same place.
I use this code:
Quote//Projection
                        glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
           

         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;

           
         glFrustum(left,right,bottom,top,diam,diam*3.5);           
           
//Model
                         glMatrixMode(GL_MODELVIEW);
                         glLoadIdentity();
          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);

//Lighting
         GLfloat light_position[] = {0.0, 0.0,0.0, 1.0 };
         GLfloat white_light[] = { 0.7, 0.3, 0.2, 1.0 };
         glEnable(GL_DEPTH_TEST);
         
         
         glEnable(GL_LIGHTING);
         glLightfv(GL_LIGHT1, GL_POSITION, light_position);
         glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light);
         glEnable(GL_LIGHT1);
                        glShadeModel(GL_FLAT);
         
//Draw
         glEnable(GL_NORMALIZE);
                        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//render here
for(unsigned int modelIdx = 0;modelIdx < m_allModels.zise();++modelIdx)
         {
            model curModel = m_allModels.getModel(modelIdx);
            for(unsigned int modelSurfIdx = 0;modelSurfIdx <curModel.surfNum();
               ++modelSurfIdx)
            {
               surface curSurf = curModel.getSurface(modelSurfIdx);
               glLineWidth(2);
               glBegin( GL_POLYGON );

               
               glNormal3f(curSurf.getN_x(),curSurf.getN_y(),curSurf.getN_z());
               for(unsigned int vertIdx = 0;vertIdx< curSurf.size();++vertIdx)
               {
                  unsigned int curVertIdx = curSurf.getSurfVertices()[vertIdx];
                  vertex curVert = curModel.getVertex(curVertIdx);
                  glVertex3f((GLfloat)curVert.getX(),(GLfloat)curVert.getY(),(GLfloat)curVert.getZ());
               }   
               glEnd();

            }
         }
Title: Re: [OPENGL] render mesh/lighting
Post by: yakovm on February 09, 2010, 07:16:29 AM
and i get this:
(http://img17.imageshack.us/img17/1103/64347046.png)
Why this happening