我是按照这个教程来的:http://m.blog.csdn.net/article/details?id=50521504
现在的问题是程序能运行,但是并不能显示茶壶。
#include "stdafx.h"
#include <gl/glut.h>
#include <cstdlib>
#include "TeaPot.h"
#include <gl/GL.h>
GLuint model = -1;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glCallList(model);//void glCallList(GLuint list)执行一个显示列表 //glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glTranslatef(0.0, 0.0, -10.0);
glRotatef(0.0, 0.0, 1.0, 0.0);
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(450, 450);
glutInitWindowPosition(150, 150);
model = GL3DS_initialize_TeaPot();
glutCreateWindow("TeaPot");
glutDisplayFunc(display);
glutMainLoop();
return EXIT_SUCCESS;
}
初始化函数
int ReturnVal;
FILE *in;
if (!(in = fopen("TeaPot.gl", "rb")))
return(-1);
if (fread(GL3DS_VERTEX_TeaPot, 31424, 1, in) != 1)
return(-1);
fclose(in);
ReturnVal = glGenLists(1);
glInterleavedArrays(GL_T2F_N3F_V3F, 0, GL3DS_VERTEX_TeaPot);
glNewList(ReturnVal, GL_COMPILE);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat *) &GL3DS_MATERIAL_TeaPot[0]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat *) &GL3DS_MATERIAL_TeaPot[4]);
glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat *) &GL3DS_MATERIAL_TeaPot[8]);
glDrawElements(GL_TRIANGLES, 5952, GL_UNSIGNED_INT, &GL3DS_INDEX_TeaPot[0]);
glEndList();
return (ReturnVal);
可能是没有导入成功,可以用Assimp库导入模型试试