OpenGL:简单的过剩立方体没有光
OpenGL:简单的 glut 立方体没有灯光
嗨,我正在尝试研究 opengl 和 glut 中的灯光,但我很早就遇到了问题。我有这样的代码,用于使用自定义相机设置在自定义位置制作发光立方体:
void testApp::draw(){
static float amb[] = {0.4, 0.4, 0.4, 0.0};
static float dif[] = {1.0, 1.0, 1.0, 0.0};
float light_diffuse[] = {1.0, 0.0, 1.0, 1.0};
float light_position[] = {-1.0, 1.0, 1.0, 0.0}; // i tried a lot of positions here!
// set camera
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 200, 1200, 0,0,0, 0,1,0);
// set lights
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);
// draw scene
ofScale(50, 50, 50);
glPushMatrix();
glutSolidCube(2);
// close everything
glPopMatrix();
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LIGHTING); }
我只看到一个黑色立方体,没有光,我认为问题在于光位置,我尝试了很多位置,但它不起作用: 黑色立方体。
OpenGL: no light for a simple glut cube
Hi, i'm trying to study lights in opengl and glut but I have problems quite early. I have this code for making a lighted cube in a custom position with custom camera setting:
void testApp::draw(){
static float amb[] = {0.4, 0.4, 0.4, 0.0};
static float dif[] = {1.0, 1.0, 1.0, 0.0};
float light_diffuse[] = {1.0, 0.0, 1.0, 1.0};
float light_position[] = {-1.0, 1.0, 1.0, 0.0}; // i tried a lot of positions here!
// set camera
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 200, 1200, 0,0,0, 0,1,0);
// set lights
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, dif);
// draw scene
ofScale(50, 50, 50);
glPushMatrix();
glutSolidCube(2);
// close everything
glPopMatrix();
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LIGHTING); }
I see only a black cube, no light, I think the problem is the light position, I've tried a lot of positions but it does not work: black cube.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你离你的立方体真的很远。让它变小并靠近。或者,像这样改变你的照明:
你几乎不会在立方体上看到任何灯光效果。考虑使用茶壶。
You are really far away from your cube. Make it smaller and move it closer. Alternatively, change your lighting like this:
You will hardly see any light effects on a cube. Consider using a teapot.