• OpenGL3D图形绘制


    GLfloat        xtri;                        
    GLfloat ytri;
    GLfloat ztri;
    int DrawGLScene(GLvoid) // 从这里开始进行所有的绘制
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
    glLoadIdentity(); // 重置模型观察矩阵
    glTranslatef(-0.0f,0.0f,-6.0f); // 左移 1.5 单位,并移入屏幕 6.0

    glRotatef(xtri,1.0f,0.0f,0.0f); // 绕Y轴旋转金字塔
    glRotatef(ytri,0.0f,1.0f,0.0f); // 绕Y轴旋转金字塔
    glRotatef(ztri,0.0f,0.0f,1.0f); // 绕Y轴旋转金字塔

    glBegin(GL_TRIANGLES); // 开始绘制金字塔的各个面

    glColor3f(1.0f,0.0f,0.0f); // 红色
    glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (前侧面)
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f(-1.0f,-0.0f, 1.0f); // 三角形的左下顶点 (前侧面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f( 1.0f,-0.0f, 1.0f); // 三角形的右下顶点 (前侧面)


    glColor3f(1.0f,0.0f,0.0f); // 红色
    glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (右侧面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f( 1.0f,-0.0f, 1.0f); // 三角形的左下顶点 (右侧面)
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f( 1.0f,-0.0f, -1.0f); // 三角形的右下顶点 (右侧面)


    glColor3f(1.0f,0.0f,0.0f); // 红色
    glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (后侧面)
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f( 1.0f,-0.0f, -1.0f); // 三角形的左下顶点 (后侧面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f(-1.0f,-0.0f, -1.0f); // 三角形的右下顶点 (后侧面)


    glColor3f(1.0f,0.0f,0.0f); // 红色
    glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (左侧面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f(-1.0f,-0.0f,-1.0f); // 三角形的左下顶点 (左侧面)
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f(-1.0f,-0.0f, 1.0f); // 三角形的右下顶点 (左侧面)
    glEnd(); // 金字塔绘制结束

    glBegin(GL_QUADS); // 开始绘制金字塔的底部
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f(-1.0f, 0.0f,1.0f); // 四边形的右上顶点 (顶面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f(1.0f, 0.0f,1.0f); // 四边形的左上顶点 (顶面)
    glColor3f(0.0f,1.0f,0.0f); // 绿色
    glVertex3f(1.0f, 0.0f, -1.0f); // 四边形的左下顶点 (顶面)
    glColor3f(0.0f,0.0f,1.0f); // 蓝色
    glVertex3f( -1.0f, 0.0f, -1.0f); // 四边形的右下顶点 (顶面)
    glEnd();

    xtri+=0.8f;
    ytri+=0.5f;
    ztri+=0.9f;

    return TRUE; // 一切 OK
    }
  • 相关阅读:
    查看Linux内核版本命令
    身份证测试用
    aaa
    aaaaaaaaaaaaaaa
    https
    httpclient调用https
    共阴极数码管编码
    时间单位换算
    Java 中System里getProperty(something)
    VM arguments
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2329026.html
Copyright © 2020-2023  润新知