943,106 Members | Top Members by Rank

Ad:
Feb 8th, 2010
0

[OPENGL]render mesh/lighting

Expand Post »
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:
c++ Syntax (Toggle Plain Text)
  1. //Projection
  2. glMatrixMode(GL_PROJECTION);
  3. glLoadIdentity();
  4.  
  5.  
  6. GLdouble diam = m_allModels.getDiam();
  7. GLdouble left = m_allModels.getCenter()[0] - diam;
  8. GLdouble right = m_allModels.getCenter()[0] + diam;
  9. GLdouble bottom = m_allModels.getCenter()[1] - diam;
  10. GLdouble top = m_allModels.getCenter()[1] + diam;
  11.  
  12.  
  13. glFrustum(left,right,bottom,top,diam,diam*3.5);
  14.  
  15. //Model
  16. glMatrixMode(GL_MODELVIEW);
  17. glLoadIdentity();
  18. gluLookAt (0.0, 0.0,2*m_allModels.getDiam(),
  19. m_allModels.getCenter()[0],m_allModels.getCenter()[1],m_allModels.getCenter()[2],
  20. 0.0, 1.0, 0.0);
  21.  
  22. //Lighting
  23. GLfloat light_position[] = {0.0, 0.0,0.0, 1.0 };
  24. GLfloat white_light[] = { 0.7, 0.3, 0.2, 1.0 };
  25. glEnable(GL_DEPTH_TEST);
  26.  
  27.  
  28. glEnable(GL_LIGHTING);
  29. glLightfv(GL_LIGHT1, GL_POSITION, light_position);
  30. glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light);
  31. glEnable(GL_LIGHT1);
  32. glShadeModel(GL_FLAT);
  33.  
  34. //Draw
  35. glEnable(GL_NORMALIZE);
  36. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  37. //render here
  38. for(unsigned int modelIdx = 0;modelIdx < m_allModels.zise();++modelIdx)
  39. {
  40. model curModel = m_allModels.getModel(modelIdx);
  41. for(unsigned int modelSurfIdx = 0;modelSurfIdx <curModel.surfNum();
  42. ++modelSurfIdx)
  43. {
  44. surface curSurf = curModel.getSurface(modelSurfIdx);
  45. glLineWidth(2);
  46. glBegin( GL_POLYGON );
  47.  
  48.  
  49. glNormal3f(curSurf.getN_x(),curSurf.getN_y(),curSurf.getN_z());
  50. for(unsigned int vertIdx = 0;vertIdx< curSurf.size();++vertIdx)
  51. {
  52. unsigned int curVertIdx = curSurf.getSurfVertices()[vertIdx];
  53. vertex curVert = curModel.getVertex(curVertIdx);
  54. glVertex3f((GLfloat)curVert.getX(),(GLfloat)curVert.getY(),(GLfloat)curVert.getZ());
  55. }
  56. glEnd();
  57.  
  58. }
  59. }
And I get this
http://img17.imageshack.us/img17/1103/64347046.png
What I am doing wrong?
Similar Threads
Reputation Points: 46
Solved Threads: 0
Light Poster
yakovm is offline Offline
27 posts
since May 2009
Feb 9th, 2010
0
Re: [OPENGL]render mesh/lighting
Looks like your vertices are not correct. Have you tried to load
a simple mesh first?
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,859 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: Screen scrolling.. ?
Next Thread in Game Development Forum Timeline: Finding any tangent vector (3D)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC