OpenGL装gult库

https://www.cnblogs.com/liangliangdetianxia/p/4491874.html

链接中的测试代码有误,下面是调试好的。

测试代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>  
#include <windows.h>
#include <glut.h>


using namespace std;

void init(void)
{
    //设置显示窗口的背景为白色。参数顺序为:红、绿、蓝、透明度。
    glClearColor(1.0, 1.0, 1.0, 0.0);
    //设置投影类型:正投影
    glMatrixMode(GL_PROJECTION);
    //观察参数:x坐标值从0到200,y是从0到150
    gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}

//绘制线段的函数
void lineSegment(void)
{
    //将窗口颜色的设置显示到窗口上,参数是颜色缓存的位值
    glClear(GL_COLOR_BUFFER_BIT);
    //设置显示内容颜色
    glColor3f(1.0, 0.0, 0.0);
    //绘制内容
    glBegin(GL_LINES);
    glVertex2i(180, 15);
    glVertex2i(10, 145);
    glEnd();

    glFlush();

}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    //设置窗口的缓存和颜色模型
    //下面指定的是:窗口使用单个缓存并且使用RGB颜色模型来设定颜色值。
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    //设置窗口左上角的位置
    glutInitWindowPosition(50, 100);
    //设置窗口的宽高
    glutInitWindowSize(800, 600);
    glutCreateWindow("Test OpenGL Program");

    init();
    glutDisplayFunc(lineSegment);
    glutMainLoop();
    return 0;
}
原文地址:https://www.cnblogs.com/h694879357/p/13719928.html