• Advertisement
Sign in to follow this  

Rendering per second

This topic is 424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I want openGL to render the objects every one second.

How can I do that ?I've searched on topics but I didn't find anything.

It could work if I use glfwGetTime()?

 

Thank you!

Share this post


Link to post
Share on other sites
Advertisement

I don't really understand what your asking here, can you elaborate a little bit. When you say you want them to render every second, do you mean you want it to only update once a second? - this would be quite slow, ie a game running at 60 FPS would be rendering 60 frames every second.

Or do you just mean you want something to constantly render? - which i assume it is doing whatever way you have set it up

Share this post


Link to post
Share on other sites

It sounds like an odd thing to do - it might help if you could explain what you're trying to achieve.

 

With glfw you might want to set glfwSwapInterval to the refresh rate of the monitor although getting the refresh rate might not be straightforward - there didn't seem to be a simple function for getting it. Setting it to 60 might suffice, depending on how accurate you need to be, but some monitors have 240hz so it'd be 1/4 of a second on there. glfwSwapInterval probably isn't intended for intervals that high so maybe it won't work.

 

Or you could do something crude like sleep for nearly a second Sleep(990) on windows, usleep(990000) on most other systems. If you need it more accurate you could measure how long your frame took and sleep for the remaining time.

Share this post


Link to post
Share on other sites
Render as fast as the hardware wants, but just update the state (e.g. positions, sprite frames, whatever) once per second. Same difference visually but much more sensible approach.

Share this post


Link to post
Share on other sites

Thank you for replies,

 

@C0lumbo, I want to make a 2D snake game and I had some problems with the body updating its positions. Somebody told me to put the snake parts in a vector, but I don't know exactly how to make this. So I've made something else and I thought that might work if the speed was slower.But today I realised that it doesn't have anything to do with the speed.

 

I feel sorry guys, because I made a topic for such a simple question :).

Edited by alx119

Share this post


Link to post
Share on other sites

You can get the current time, and from that you compute the time for the next draw.

http://www.glfw.org/docs/latest/input_guide.html#time

 

glfw has "glfwWaitEventsTimeout(double timeout)" where you can wait until an event happened or enough time has passed.

http://www.glfw.org/docs/latest/group__window.html#ga605a178db92f1a7f1a925563ef3ea2cf

 

compute the 'timeout' value from the current time and the time of the next draw, then call the "waitsEventsTimeout" function. When it returns, process the event if there is one.

Next, check the curent time. If you still have to wait jump back to waiting, else draw the screen, and update the time for the next draw.

 

To handle rounding errors, and other silly things like waiting for 0.000001 seconds, also draw the new screen when the time for the next screen is "near enough", eg less than 0.01 second away, or something.

Edited by Alberth

Share this post


Link to post
Share on other sites

Hi,

 

I edited my last post so many times because I didn't know if the updating per second will help me.I said that it won't, but know I think that it will. :D

I had a few problems with the logic. :D

But now with Alberth's advice I might succeed.

Thank you very much. :)

Share this post


Link to post
Share on other sites

You shouldn't be trying to control how fast the screen draws for something like this, just change how often the snake is updated. Delaying draws to one second between presents is just going to give you all kinds of trouble.

 

I could go into the reasons but the simplest one would be that if you suddenly want to draw something more often than once per second then you not only will have to remove your frame limiting code but then you'll have to add delayed logic to update the snake anyway, making all your work completely redundant.

Share this post


Link to post
Share on other sites

Hi,

 

To be honestly I don't know how to make it.I tried a lot of things all day, but I did nothing.I don't know how to change how often the snake is updated. :(

I tried a few things with the glfwGetTime() and with glfwWaitEventsTimeout like Alberth said but didn't succeed.To be honestly maybe because I don't know how those functions work or maybe I don't know where to put them...

Help please. :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement