当我每帧更新其位置时,OpenGL灯会闪烁 [英] OpenGL light flickering when I update its position each frame

查看:83
本文介绍了当我每帧更新其位置时,OpenGL灯会闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习OpenGL,并且刚刚开始涉足照明领域.我启用照明和照明0,在我的init方法中将其环境/漫反射/镜面反射设置为默认值,然后在每个帧中执行以下操作:

I am learning OpenGL and just started getting into lighting. I enable lighting and light 0, set its ambient/diffuse/specular to default values in my init method, and then each frame I do something like this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// do my 3rd-person camera transforms and rotations
glLightfv(GL_LIGHT0, GL_POSITION, {0.1f, 0.0f, 0.0f});

(请注意,如果这是稍有错误,我正在使用JOGL在Java中编写我的应用程序,因此我对每一行的gl.和GL.进行了修整,以便为所有C ++人士提供更好的可读性:))

(note if it's slightly wrong, I'm writing my app in Java using JOGL so I trimmed the gl. and GL. from each line for better readability for all you C++ folks :) )

然后我继续绘制三角形等,最后我执行glFlush().

I then proceed to draw my triangles and such, and at the end I do a glFlush().

一个奇怪的问题是,当我运行我的应用程序时,指示灯会闪烁.在我的整个程序中,没有其他调用glLightfv的方法(如上所述,除了init方法中的调用,我已对其进行调试以确保其仅运行一次).它以非常快的速度闪烁,并且屏幕显示撕裂.我在场景绘图中的任何时候都不会glDisable(GL_LIGHTING);不是我认为那会导致被照亮的物体闪烁.

The odd problem is that when I run my application, the light flickers. I have no other calls to glLightfv in my whole program (other than, as mentioned above, the calls in my init method, which I have debugged to make sure it does only run once). It flickers very fast and the screen shows tearing. I also do not glDisable(GL_LIGHTING) at any point in my scene drawing; not that I think that should cause the lit objects to flicker.

出于调试目的,我还注释掉了我的绘图代码的大部分内容,并且似乎没有什么破坏照明的;当然,我在编写所有代码并在对场景进行照明之前对其进行了测试,因此我看不出任何理由这应该是错误的.

I have also, for debugging purposes, commented out chunks of my drawing code, and nothing seems to be breaking the lighting - and of course, I wrote all that and tested it before lighting the scene anyway, so I see no reason it should be wrong.

基本上我知道这没什么大不了的,但是其他任何人以前都遇到过这个问题吗?有一些我找不到的简单解决方案吗?请索取任何其他可以帮助您的信息.最后,如果我根本无法获得答案,我可能必须分解并编写一个测试案例,在这里我可以将整个渲染代码发布到这里并演示问题.

Basically I know this isn't much to go by, but has anyone else had this problem before? Is there some simple solution I just can't find? Please request any additional information that could help you help me. And in the end if I simply can't get an answer, I'll probably have to break down and write a test case where I can just post the entire rendering code here and demonstrate the problem.

这是我尝试制作的非常糟糕的动画gif. .但这只是说明了我在说什么,就零星的光线而言.照亮的框架就是它的外观.另外,当我将速度降低到5fps时,它并没有那么多的闪烁,而只是随机地打开或关闭.我不明白...

Here is a really bad animated gif I tried to make... But it kinda shows what I'm talking about, as far as the light being sporadic. The lit frames are what it's supposed to look like. Also it's not so much flickering when I slow it down to 5fps, more just kinda randomly on or off. I don't get it...

谢谢!

推荐答案

啊!我已经找到答案了... 我只为该位置指定了3个浮点数,当它需要4个记录点时,

Aha! I found the answer already... I only specified 3 floats for the position, when it wants 4 as documented here. So the fourth number, which must have some affect on the light's brightness, was being read from some other random area in memory, and of course odd things happened.

很抱歉浪费您的时间!

这篇关于当我每帧更新其位置时,OpenGL灯会闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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