The MASM Forum
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 09, 2010, 02:25:19 am

Login with username, password and session length
Search:     Advanced search
117346 Posts in 14003 Topics by 1654 Members
Latest Member: road_hog
* Home Help Search Login Register
+  The MASM Forum
|-+  Project Support Forums
| |-+  OpenGL Forum (Moderator: hitchhikr)
| | |-+  [OPENGL] render mesh/lighting
« previous next »
Pages: [1] Print
Author Topic: [OPENGL] render mesh/lighting  (Read 698 times)
yakovm
New Member
*
Posts: 2


[OPENGL] render mesh/lighting
« 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();

            }
         }
Logged
yakovm
New Member
*
Posts: 2


Re: [OPENGL] render mesh/lighting
« Reply #1 on: February 09, 2010, 07:16:29 am »

and i get this:

Why this happening
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!