我有一个程序,可以创建一个黑色边框和一个白色角落(四边形)。
现在我想以不同的颜色制作四边形的角落。
我不知道究竟在哪里写代码,我不知道多少但是color4f,我在谷歌搜索,但没有得到它。 (某处有好的描述吗?)
#include <iostream>
#include <GL/freeglut.h>
void Init()
{
glColor4f(100,0,0,0);
}
void RenderScene() //Zeichenfunktion
{
glLoadIdentity ();
glBegin( GL_POLYGON );
glVertex3f( -0.5, -0.5, -0.5 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glEnd();
glFlush();
}
void Reshape(int width,int height)
{
}
void Animate (int value)
{
std::cout << "value=" << value << std::endl;
glutPostRedisplay();
glutTimerFunc(100, Animate, ++value);
}
int main(int argc, char **argv)
{
glutInit( &argc, argv ); // GLUT initialisieren
glutInitDisplayMode( GLUT_RGB ); // Fenster-Konfiguration
glutInitWindowSize( 600, 600 );
glutCreateWindow( "inkrement screen; visual screen" ); // Fenster-Erzeugung
glutDisplayFunc( RenderScene ); // Zeichenfunktion bekannt machen
glutReshapeFunc( Reshape );
glutTimerFunc( 10, Animate, 0);
Init();
glutMainLoop();
return 0;
}
答案 0 :(得分:3)
首先,你可能想要glColor3f。 glColor4f也采用alpha(透明度)值,您可能还不关心它。参数范围为0表示无强度,1表示最大强度红色,绿色和蓝色。所以你可以这样做:
glColor3f( 1.0f, 0.0f, 0.0f ); // red
glVertex3f( -0.5, -0.5, -0.5 ); // this vertex is red
glColor3f( 0.0f, 1.0f, 0.0f ); // green
glVertex3f( 0.5, -0.5, -0.5 ); // this vertex is green
glColor3f( 0.0f, 0.0f, 1.0f ); // blue
glVertex3f( 0.5, 0.5, -0.5 ); // this vertex is blue
glVertex3f( -0.5, 0.5, -0.5 ); // since it wasn't changed, this one will be blue, too
答案 1 :(得分:0)
在GL_POLYGON块中指定顶点本身之前指定顶点颜色。
但是,我建议使用OpenGL 2.x,而不是再学习旧的OpenGL 1.x。在那里你使用VBO(顶点缓冲对象)而不是glBegin / glEnd等。