OpenGL学习笔记 之二 (色彩相关)

参考: http://www.cnblogs.com/FredCong/archive/2012/10/13/2722893.html

使用RGB

#include <glut.h>
#include <math.h>

void myDisplay1(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0f, 1.0f, 1.0f);//设置颜色
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    glFlush();
}
void myDisplay2(void)
{
    glClearColor(1.0f,0.0f,0.0f,0.0f);//设置清空成什么颜色
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
const GLfloat Pi = 3.1415926;
void  myDisplay3()
{
    //glShadeModel(GL_FLAT);//保持单色
    //glShadeModel(GL_SMOOTH);//平滑过度 glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLE_FAN);//三角拼成的扇形 glColor3f(
1.0f,1.0f,1.0f); glVertex2f(0.0f,0.0f); for (int i=0; i<=16; i++) { glColor3f(i&0x4, i&0x2, i&0x1); glVertex2f(cos(i*2*Pi/16), sin(i*2*Pi/16)); } glEnd(); glFlush(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowPosition(100,100); glutInitWindowSize(400,400); glutCreateWindow("我的第一个opengl程序"); glutDisplayFunc(&myDisplay2); glutMainLoop(); return 0; }

 

输出:

 

posted @ 2015-06-12 21:10  sunnycs  阅读(206)  评论(0编辑  收藏  举报