我得到上线下面的代码上面运行时错误:
glutMainLoop();
为什么?
#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cassert>
#include <math.h>
#include <gl/glut.h>
#include <stdlib.h>
class Vertex {
public: float X;
float Y;
float Z;
public: Vertex (float first, float second, float third){
X=first;
Y=second;
Z=third;
}
};
using namespace std;
vector <Vertex> vertexCoordinates;
vector <vector<int>> faces;
vector <vector<float>> faceNormals;
vector <vector<float>> faceCenters;
void loadOff(string inputFileName) {
int vertexCount; int faceCount; int edgeCount;
ifstream inputFileStream;
inputFileStream.open(inputFileName.data());
assert(inputFileStream.is_open());
string actualLine;
inputFileStream>>vertexCount;
inputFileStream>>faceCount;
inputFileStream>>edgeCount;
for (int loadVertexIndex=0; loadVertexIndex<vertexCount; loadVertexIndex++){
float X;
float Y;
float Z;
inputFileStream>>(float)X;
inputFileStream>>(float)Y;
inputFileStream>>(float)Z;
vertexCoordinates.push_back(Vertex(X,Y,Z));
if(inputFileStream.eof())break;
}
for (int faceIndex=0; faceIndex<=faceCount; faceIndex++){ //<= faceCount?
string line;
getline(inputFileStream, line);
istringstream actualLineStream(line);
std::vector<int> face((std::istream_iterator<int>(actualLineStream)),
std::istream_iterator<int>());
faces.push_back(face);
}//end for faceCount
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glutSwapBuffers();
glutPostRedisplay();
}
void init(){
//loadOff("spider.off");
//BLACK BACKGROUND
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_BACK, GL_LINE);
glPolygonMode(GL_FRONT, GL_LINE);
}
void reshape(int w, int h) {
glViewport (0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
}
void keyboard (unsigned char key, int x, int y){
}
void specialKeys(int key, int x, int y) {
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
glutInitWindowSize(800,600);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}