Openmesh 读入off文件并用opengl显示,VS2008平台下遇到问题,急求帮助

pixels_zcc 2012-04-08 08:29:52
我的代码如下:

#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... ...."错误警告,致使网格和图形无法显示!急寻问题原因和解决办法,先谢谢啦
...全文
628 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
梦里茶 2014-11-04
  • 打赏
  • 举报
回复
虽然说坟贴勿回,但是看到没说怎么解决的总是要犯强迫症。。。 应该是data.off文件里没有法向量的信息, 所以画三角形带应用法向量的时候出错
qyxsxz 2013-05-02
  • 打赏
  • 举报
回复
引用 2 楼 pixels_zcc 的回复:
问题已解决,感谢
问题在哪啊
wu_123_456_789 2012-10-11
  • 打赏
  • 举报
回复
怎么解决的呢。。
pixels_zcc 2012-04-10
  • 打赏
  • 举报
回复
问题已解决,感谢
evencoming 2012-04-09
  • 打赏
  • 举报
回复
这个代码用到了命令行参数.
在 执行.exe文件的时候传入
看看文档吧

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧