zoukankan      html  css  js  c++  java
  • OpenGL绘制函数

    #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>

    #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;
    GLdouble A,B,C,D; //比例变换平移值

    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);
    A=screenWidth/4.0;
    B=0.0;
    C=D=screenHeight/2.0;
    }


    GLdouble func(GLdouble x)
    {
    return exp(-x)*cos(2*3.1415926*x);
    }

    void myDisplay()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POINTS);

    for(GLdouble x=0;x<2*3.14159;x+=0.00025)
    glVertex2d(A*x+B,C*func(x)+D);

    glEnd();
    glFlush();

    }

    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(); //进入循环
    }
  • 相关阅读:
    记录一次线上优化流程
    php ignite 使用问题记录
    invalid contrller specified 错误分析及解决
    koa 2 的 async 和 await 语法
    koa 2 的安装
    vue 自定义组件 v-model双向绑定、 父子组件同步通信的多种写法
    VS2019专业版和企业版激活密钥
    RE:ゼロから始める PKU 生活 episode 2
    CSP-S 2020 游记
    ioi2021集训队作业
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2328636.html
Copyright © 2011-2022 走看看