gpt4 book ai didi

c++ - OpenGL光照

转载 作者:太空宇宙 更新时间:2023-11-04 16:15:28 25 4
gpt4 key购买 nike

我有一个 opengl 照明问题,我有一个对象可以说这个。

enter image description here

这是一个没有应用光效的原始对象,所以问题是当我尝试向这个对象添加光时它隐藏了对象颜色并将对象变成这种颜色

enter image description here

我使用的漫反射和镜面反射分量:

GLfloat diffu[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat spec[] = {0.5f, 0.5f, 0.5f, 0.5f};
GLfloat shinnes [] = {50};
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffu);
glLightfv(GL_LIGHT1, GL_SPECULAR, spec);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS,shinnes);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);

所以我需要了解问题是什么???

最佳答案

从这个(http://www.glprogramming.com/red/chapter05.html)链接:

Define Material Properties for the Objects in the Scene

An object's material properties determine how it reflects light and therefore what material it seems to be made of. Because the interaction between an object's material surface and incident light is complex, specifying material properties so that an object has a certain desired appearance is an art. You can specify a material's ambient, diffuse, and specular colors and how shiny it is. In this example, only these last two material properties - the specular material color and shininess - are explicitly specified (with the glMaterialfv() calls). (See "Defining Material Properties" for a description and examples of all the material-property parameters.)

一旦您开始使用光照,对象的 Material 属性(它的颜色)就由 glMaterialfv() 传入的镜面反射/漫反射...属性指定。因此,如果您使用 glColor(),您现在需要使用 glMaterialfv() 指定 Material 属性。

在您的代码中,除了设置光的镜面反射和漫反射颜色外,您还需要设置 Material 的镜面反射和漫反射颜色:

// Set light properties
GLfloat diffu[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat spec[] = {0.5f, 0.5f, 0.5f, 0.5f};
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffu);
glLightfv(GL_LIGHT1, GL_SPECULAR, spec);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);

// Set material properties
GLfloat shinnes [] = {50};
GLfloat matdiffu[] = {1.0f, 0.f, 0.f, 1.0f};
GLfloat matspec[] = {1.0f, 0.f, 0.f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,matdiffu);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,matspec);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS,shinnes);

// Draw object

关于c++ - OpenGL光照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23246785/

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