绘制文件中的折线

haozhao1984 2009-06-01 04:34:55
#include<windows.h>
#include<stdlib.h>
#include<fstream.h>
#include<math.h>
#include<gl/gl.h>
#include<gl/glu.h>
#include<gl/glut.h>
struct GLPoint{
GLfloat x,y;
};
GLPoint p;
int screenwith=640.0,screenheight=440.0;
const float r=1.618033989;
void myinit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
//glMatrixMode(GL_PROJECTION);
//gluOrtho2D(0.0,screenwith,0.0,screenheight);
}

void drawPolyLineFile(char * fileName)
{
fstream inStream;
inStream.open(fileName, ios ::in); // open the file
if(inStream.fail())
return;
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
GLint numpolys, numLines, x ,y;
inStream >> numpolys; // read the number of polylines
for(int j = 0; j < numpolys; j++) // read each polyline
{
inStream >> numLines;
glBegin(GL_LINE_STRIP); // draw the next polyline
for (int i = 0; i < numLines; i++)
{
inStream >> x >> y; // read the next x, y pair
glVertex2i(x, y);
}
glEnd();
}
glFlush();
inStream.close();
}
void setWindow(GLdouble left,GLdouble right,GLdouble buttom,GLdouble top)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(left,right,buttom,top);
}
void setViewport(GLint left,GLint right,GLint bottom,GLint top)
{
glViewport(left,bottom,right-left,top-bottom);
}

void mydiplay(void)
{
//glClear(GL_COLOR_BUFFER_BIT);
setWindow(0.0,screenwith,0.0,screenheight);
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
glViewport(i*64,j*44,64,44);
drawPolyLineFile("dino.dat");
}
}
}
void mydisplay()
{
//glClear(GL_COLOR_BUFFER_BIT);
//setWindow(0.0,screenwith,0.0,screenheight);
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
if((i+j)%2==0)
setWindow(0.0,screenwith,0.0,screenheight);
else
setWindow(0.0,screenwith,screenheight,0.0);
glViewport(i*64,j*44,64,44);
drawPolyLineFile("dino.dat");
}
}
}
void main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenwith,screenheight);
glutInitWindowPosition(100,150);
glutCreateWindow("OpenGL makes gode scale rectangle!");
glutDisplayFunc(mydisplay);
myinit();
glutMainLoop();
}
为什么只有一只恐龙?应该是25个
...全文
28 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4,448

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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