Openmesh 读入off文件并用opengl显示,VS2008平台下遇到问题,急求帮助
我的代码如下:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
// ----------------------------------------------------------------------------
typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh;
float gWidth; // width of the render window
float gHeight; // height of the render window
GLfloat gLightDiffuse[] = {0.0, 0.0, 1.0, 1.0}; // light diffuse
GLfloat gLightPosition[] = {0.0, 0.0, 1.0, 1.0}; // light position
MyMesh mesh;
void shape(int aFill)
{
if(aFill)
{
for (MyMesh::FaceIter f_it=mesh.faces_begin();f_it != mesh.faces_end(); ++f_it)//遍历每个面
{
glBegin(GL_TRIANGLES);
glNormal3fv(mesh.normal(f_it).data());
for(MyMesh::FaceVertexIter fv_it=mesh.fv_iter(f_it); fv_it; ++fv_it)//当前面上的每个点。
{
glVertex3fv(mesh.point(fv_it).data());
}
glEnd();
}
}
else
{for (MyMesh::FaceIter f_it=mesh.faces_begin();f_it != mesh.faces_end(); ++f_it)//遍历每个面
{
glBegin(GL_LINE_LOOP);
for(MyMesh::FaceVertexIter fv_it=mesh.fv_iter(f_it); fv_it; ++fv_it)//当前面上的每个点。
{
glVertex3fv(mesh.point(fv_it).data());
}
glEnd();
}
}
}
void reshape(int aWidth, int aHeight)
{
// record the width and height of the current render window
gWidth = aWidth;
gHeight = aHeight;
}
void render(int aShape)
{
switch(aShape)
{
case 0:
{
glEnable(GL_LIGHTING);
shape(0); // wire shape
glDisable(GL_LIGHTING);
break;
}
case 1:
{
glEnable(GL_LIGHTING);
shape(1); // solid shape
glDisable(GL_LIGHTING);
break;
}
}
}
void display(void)
{
int row;
int col;
// clear the render window
glViewport(0, 0, gWidth, gHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(row = 0; row < 1; row++)
{
for(col = 0; col < 2; col++)
{
// render each geometric shape
glViewport(gWidth / 2 * col, gHeight * row, gWidth / 2, gHeight);
render(col);
}
}
glFlush();
}
int main(int argc, char** argv)
{
if (!OpenMesh::IO::read_mesh(mesh, "data.off"))
{
std::cerr << "read error\n";
exit(1);
}
// initialize the render window
glutInitWindowSize(800, 400);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("GLUT NURBS");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
// set color
glClearColor(0.5, 0.5, 0.5, 1.0);
glColor3f(0.0, 0.0, 1.0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, gLightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, gLightPosition);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
// set OpenGL view model
glMatrixMode(GL_PROJECTION);
gluPerspective(
22.0, // field of view in degree
1.0, // aspect ratio
1.0, // Z near
10.0); // Z far
glMatrixMode(GL_MODELVIEW);
gluLookAt(
0.0, 0.0, 2.5, // eye is at (0,0,2.5)
0.0, 0.0, 0.0, // center is at (0,0,0)
0.0, 1.0, 0.0); // up is in positive Y direction
glutMainLoop();
return 0;
}
编译没有错误,debug时出现"This application has requested the Runtime to terminate it in an unusual way... ...."错误警告,致使网格和图形无法显示!急寻问题原因和解决办法,先谢谢啦