#include <windows.h> // Windows的头文件
#include <gl\gl.h> // OpenGL32库的头文件
#include <gl\glu.h> // GLu32库的头文件
#include <gl\glaux.h> // GLaux库的头文件
#include <gl\glut.h> // Glut库头文件
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
#pragma comment( lib, "opengl32.lib") // OpenGL32连接库
#pragma comment( lib, "glu32.lib") // GLu32连接库
#pragma comment( lib, "glaux.lib") // GLaux连接库
#pragma comment( lib, "glut.lib") // Glut链接库
int screenWidth=640;
int screenHeight=480;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0); //设置背景颜色为亮白
glColor3f(0.0f,0.0f,0.0f); //设置绘图颜色为黑色
glPointSize(4.0); //设置点的大小为4*4像素
glMatrixMode(GL_PROJECTION); //设置合适的矩阵
glLoadIdentity();
gluOrtho2D(0.0,screenWidth,0.0,screenHeight);
}
void drawLine(GLint x1,GLint y1,GLint x2,GLint y2)
{
glBegin(GL_LINES);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
}
void myDisplay()
{
fstream inStream;
inStream.open("dino.txt",ios::in);
if(inStream.fail())
return;
glClear(GL_COLOR_BUFFER_BIT);
GLint numpolys,numLines,x,y;
inStream>>numpolys;
for(int j=0;j<numpolys;j++)
{
inStream>>numLines;
glBegin(GL_LINE_STRIP);
for(int i=0;i<numLines;i++)
{
inStream>>x>>y;
glVertex2i(x,y);
}
glEnd();
}
glFlush();
inStream.close();
}
void main(int argc, char **argv)
{
glutInit(&argc,argv); //初始化工具包
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//设置显示模式
glutInitWindowSize(640,480); //设置窗口大小
glutInitWindowPosition(100,150); //设置窗口在屏幕上的位置
glutCreateWindow("my first attempt"); //打开屏幕窗口
//注册回调函数
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop(); //进入循环
}
数据在这里:http://web.cs.wpi.edu/~gogo/courses/cs4731/assignments/ass1/dino.dat