Glusphere 发出奇怪的光 [英] Glusphere giving strange lighting

查看:64
本文介绍了Glusphere 发出奇怪的光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 glut 时,我使用 glutsolidsphere 来绘制球体,但是转移到 glfw 后,我不得不使用 glusphere.我基本上将整个函数glutsolidsphere"复制到我自己的代码中,但是在我之前没有遇到过奇怪的照明问题.这是球体的代码:

void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks){GLUquadric *shape = gluNewQuadric();gluQuadricDrawStyle(形状,GLU_FILL);gluQuadricNormals(形状,GLU_SMOOTH);gluSphere(形状,半径,切片,堆栈);}

这里有什么问题?

由于某种原因,我无法上传大学的图片,所以我会尝试描述它:球体轮廓看起来不错,但是您可以看到内部的片段,就像球体的外部是透明的一样,并且它会导致球体出现明显的分界线.

解决方案

深度测试好像有问题.

假设您有来自 glfw 的深度缓冲区,这能解决吗?

glEnable(GL_DEPTH_TEST);

我没有使用过 glfw,但是要请求一个深度缓冲区,您似乎只需要将 24 传递给 glfwOpenWindowdepthbits 参数.

如果您还没有将 GL_DEPTH_BUFFER_BIT 添加到您的 glClear 调用中,您还需要这样做.

我之前在 windows 和 linux 中使用 glut/freeglut 时遇到过与默认 GL 状态不一致的情况,特别是 GL_DEPTH_TEST.

另请参阅gluNewQuadric 内存泄漏

When working with glut, i used glutsolidsphere to draw my spheres, but having moved to glfw, i had to use glusphere. I basically copied the entire function "glutsolidsphere" to my own code, but am getting a strange lighting problem where before i wasn't. Heres the code for the sphere :

void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
    GLUquadric *shape = gluNewQuadric();
    gluQuadricDrawStyle(shape, GLU_FILL);
    gluQuadricNormals(shape, GLU_SMOOTH);
    gluSphere(shape, radius, slices, stacks);
}

Whats the problem here?

Edit : For some reason, i cant upload images from college, so i'll try describe it : The sphere outline looks fine, however you can see the segments on the inside, like the outside of the sphere is transparent, and it causes there to be clear divides in the sphere.

解决方案

Looks like there's a problem with depth testing.

Assuming you have a depth buffer from glfw, does this fix it?

glEnable(GL_DEPTH_TEST);

I haven't used glfw, but to request a depth buffer it looks like you just need to pass 24 for example to the depthbits argument of glfwOpenWindow.

You will also need to add GL_DEPTH_BUFFER_BIT to your glClear call if you haven't already.

I've experienced inconsistencies with the default GL state, specifically GL_DEPTH_TEST, across windows and linux using glut/freeglut before.

Also, see gluNewQuadric leaking memory

这篇关于Glusphere 发出奇怪的光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆