gpt4 book ai didi

c++ - opengl颜色四边形

转载 作者:行者123 更新时间:2023-11-28 01:11:54 26 4
gpt4 key购买 nike

我有一个程序可以创建黑色边框和白色角(四边形)。

现在我想用不同的颜色制作四边形的角。

我不知 Prop 体应该在哪里写代码,除了 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;
}

最佳答案

首先,您可能需要 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

关于c++ - opengl颜色四边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2572994/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com