Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1.  
  2. #ifdef _OPT_MARBLE
  3. osmGdi->bindFbo();
  4. glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
  5. glLoadIdentity();
  6. int width = osmGdi->m_fbo->width(), height =osmGdi->m_fbo->height();// Reset The Projection Matrix
  7. glViewport(0, 0, width, height);
  8. // Calculate The Aspect Ratio Of The Window
  9. gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
  10. glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
  11. glLoadIdentity();
  12. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
  13.  
  14. /* glShadeModel(GL_SMOOTH);
  15. glEnable(GL_LIGHTING);
  16. glEnable(GL_LIGHT0);
  17. glColor3d( 0.5, 0.6, 0.4 );
  18. //glEnable(GL_DEPTH_TEST);
  19. GLfloat lmodel_ambient[]={0.2,0.2,0.2,1.0};
  20. float spec[] = {0.5f, 0.0f, 0.0f, 0.5f};
  21. float diff[] = {0.5f, 0.4f, 0.3f, 1.0f};
  22. float shiness[] = { 90.0f };
  23. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  24. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
  25. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff);
  26. glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shiness);
  27. glEnable( GL_NORMALIZE );
  28. glPushMatrix();
  29. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  30. /* glTranslated( _x, _y, _z );*/
  31. glScaled( 0.02, 0.02, 0.02 );
  32.  
  33. // glMultMatrixd(m);
  34. // glEnable(GL_LIGHTING);
  35.  
  36. /*
  37. GLfloat white_light[]={0.5,0.5,0.5,0.5};
  38. GLfloat green_light[]={0.0,0.5,0.0,0.5};
  39. GLfloat blue_light[]={0.0,0.0,0.5,0.5};
  40. glLightfv(GL_LIGHT0,GL_DIFFUSE,blue_light);
  41. glLightfv(GL_LIGHT0,GL_AMBIENT,green_light);
  42. glEnable(GL_LIGHT0);*/
  43.  
  44. /* GLfloat light_position[4];
  45. light_position[0] = gdi()->camera()->pos().x();
  46. light_position[1] = gdi()->camera()->pos().y();
  47. light_position[2] = gdi()->camera()->pos().z();
  48. light_position[3] = 0.0;
  49.  
  50. glLightfv(GL_LIGHT0,GL_POSITION,light_position);
  51. */
  52.  
  53. for ( int i = 0; i < faces_.size(); ++i ) {
  54. // The current face might be a quad, polygon, or a triangle so we must
  55. // begin rendering based on the number of vertex points there are.
  56. if ( faces_[i].v_indices.size() == 3 ) glBegin( GL_TRIANGLES );
  57. else if ( faces_[i].v_indices.size() == 4 ) glBegin( GL_QUADS );
  58. else glBegin(GL_POLYGON);
  59.  
  60. // Loop through all the points and draw.
  61. for ( int j = 0; j < faces_[i].v_indices.size(); ++j ) {
  62. if ( !faces_[i].n_indices.empty() )
  63. glNormal3d( normals_[faces_[i].n_indices[j]].x(),
  64. normals_[faces_[i].n_indices[j]].y(),
  65. normals_[faces_[i].n_indices[j]].z() );
  66.  
  67. glVertex3d( vertices_[faces_[i].v_indices[j]].x(),
  68. vertices_[faces_[i].v_indices[j]].y(),
  69. vertices_[faces_[i].v_indices[j]].z() );
  70. }
  71.  
  72. glEnd();
  73. }
  74.  
  75. glPopMatrix();
  76. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  77. // glDisable(GL_LIGHTING);
  78.  
  79. // Reset The View
  80. /* glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
  81. glBegin(GL_TRIANGLES); // Drawing Using Triangles
  82. glVertex3f( 0.0f, 1.0f, 0.0f); // Top
  83. glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
  84. glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
  85. glEnd(); // Finished Drawing The Triangle
  86. glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
  87. glBegin(GL_QUADS); // Draw A Quad
  88. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  89. glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
  90. glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
  91. glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
  92. glEnd(); */ // Done Drawing The Quad
  93. osmGdi->fbo2Image().save("cap.png");
  94. osmGdi->releaseFbo();
  95. #else
  96. for ( int i = 0; i < faces_.size(); ++i ) {
  97. // The current face might be a quad, polygon, or a triangle so we must
  98. // begin rendering based on the number of vertex points there are.
  99. if ( faces_[i].v_indices.size() == 3 ) glBegin( GL_TRIANGLES );
  100. else if ( faces_[i].v_indices.size() == 4 ) glBegin( GL_QUADS );
  101. else glBegin(GL_POLYGON);
  102.  
  103. // Loop through all the points and draw.
  104. for ( int j = 0; j < faces_[i].v_indices.size(); ++j ) {
  105. if ( !faces_[i].n_indices.empty() )
  106. glNormal3d( normals_[faces_[i].n_indices[j]].x(),
  107. normals_[faces_[i].n_indices[j]].y(),
  108. normals_[faces_[i].n_indices[j]].z() );
  109.  
  110. glVertex3d( vertices_[faces_[i].v_indices[j]].x(),
  111. vertices_[faces_[i].v_indices[j]].y(),
  112. vertices_[faces_[i].v_indices[j]].z() );
  113. }
  114.  
  115. glEnd();
  116. }
  117. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement