画曲线

#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();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值