NeHe教程Qt实现——lesson03

NeHe 系列教程之三: 绘制彩色多边形

英文教程地址:lesson03


本课在第二课的基础上,增加了设置颜色的代码, 具体如下:

void MyGLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear The Screen And The Depth Buffer
    glLoadIdentity();       // Reset The Current Modelview Matrix

    glTranslatef(-1.5f,0.0f,-6.0f);     // Move Left 1.5 Units And Into The Screen 6.0
    glBegin(GL_TRIANGLES);                      // Drawing Using Triangles
        glColor3f(1.0f,0.0f,0.0f);	       // Set The Color To Red
        glVertex3f( 0.0f, 1.0f, 0.0f);              // Top
        glColor3f(0.0f,1.0f,0.0f);          // Set The Color To Green
        glVertex3f(-1.0f,-1.0f, 0.0f);              // Bottom Left
        glColor3f(0.0f,0.0f,1.0f);          // Set The Color To Blue
        glVertex3f( 1.0f,-1.0f, 0.0f);              // Bottom Right
    glEnd();                            // Finished Drawing The Triangle

    glTranslatef(3.0f,0.0f,0.0f);                   // Move Right 3 Units
    glColor3f(0.5f,0.5f,1.0f);              // Set The Color To Blue One Time Only
    glBegin(GL_QUADS);                      // Draw A Quad
           glVertex3f(-1.0f, 1.0f, 0.0f);              // Top Left
           glVertex3f( 1.0f, 1.0f, 0.0f);              // Top Right
           glVertex3f( 1.0f,-1.0f, 0.0f);              // Bottom Right
           glVertex3f(-1.0f,-1.0f, 0.0f);              // Bottom Left
    glEnd();                            // Done Drawing The Quad
}

运行效果如图所示:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值