#include<windows.h>
#include<math.h>
#include<gl/gl.h>
#include<gl/glut.h>
#define pi 3.1415926
#define MAXSIZE 1366
const int screenWidth=1366;
const int screenHeight=768;
struct GLdoublePoint
{
GLdouble x,y;
};
struct GLdoublePoint CP;
GLdouble x[MAXSIZE],y[MAXSIZE];
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);//背景颜色为白
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);//画图颜色为黑
glLineWidth(1.0);//画线线粗大小
glMatrixMode(GL_PROJECTION);//设置"相机形状"
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void moveTo(GLdouble x,GLdouble y)
{
CP.x=x;
CP.y=y;
}
void lineTo(GLdouble x,GLdouble y)
{
glBegin(GL_LINES);
glVertex2d(CP.x,CP.y);
glVertex2d(x,y);
glEnd();
glFlush();
CP.x=x;
CP.y=y;
}
void myDisplay()
{
int i;
for(i=0;i<MAXSIZE;i++)
{
x[i]=i;
y[i]=100*cos(-pi*i/200)+300;
}
moveTo(x[0],y[0]);
for(i=0;i<MAXSIZE;i++)
lineTo(x[i]+5.0,y[i]);
}
void main(int argc,char** argv)
{
glutInit(&argc,argv); //初始化工具包
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//设置显示模式
glutInitWindowSize(screenWidth,screenHeight);//设置窗口大小
glutInitWindowPosition(0,0);//设置窗口在屏幕上的位置
glutCreateWindow("OpenGL DEMO");
glutDisplayFunc(myDisplay);//注册重画函数
myInit();
glutMainLoop();
}