开发者

How can I tell OpenGL how often to draw stuff?

开发者 https://www.devze.com 2023-03-10 16:15 出处:网络
Okay, I\'m going to sound like an idiot with this one. Here goes. I\'ve been doing iOS development for about a year now, but only tonight have I started doing anything OpenGL related. I\'ve followed

Okay, I'm going to sound like an idiot with this one. Here goes.

I've been doing iOS development for about a year now, but only tonight have I started doing anything OpenGL related. I've followed Jeff LaMarche's wonderful guide and I'm drawing a neat looking triangle, and I got it to flip around and stuff. I'm one entertained programmer.

Okay, here's the stupid question part: How can I set somewhere for OpenGL to perform glRotatef and glDrawArrays + friends continuously, or at a set frames per second? I'v开发者_运维知识库e tried Googling it, but really can't come up with good search terms.

Thanks in advance, and get ready to field a ton more of these questions.


While the others make good suggestions for the general case of OpenGL ES, I know that you're probably working on iOS here, Will, so there's a better platform-specific alternative. In your case, I believe you'll be better served by CADisplayLink, which fires off callbacks that are synchronized with the refresh rate of the screen. Using this, you'll get far smoother updates than with a timer or some kind of polling within a loop.

This is particularly effective when combined with Grand Central Dispatch, as I describe in my answer here. When I switched from using a loop to CADisplayLink for updates, my rendering became much smoother on all iOS devices due to fewer dropped frames. Adding GCD on top of that made things even better.

You can refer to my Molecules code for an example of this in action (see the SLSMoleculeGLViewController for how my autorotation is animated with this). Apple's OpenGL ES application template also uses CADisplayLink for updates, last I checked.


You should read up on the concept of game loops.

http://entropyinteractive.com/2011/02/game-engine-design-the-game-loop/ is a good resource to get you started.


Well I'm not an expert on the subject but can't you just put the rotate/draw commands in a while loop that ends when a certain button is pressed or when a specific event occurs ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号