Jump to content
  • Advertisement
Sign in to follow this  
tomba

OpenGL how rendering works?

This topic is 4705 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

i was just wondering. all drawing for opengl prog is down under a function let's say render(); if we wanted to move a single sprite or object we would have to clear the screen, move the object and redraw everything . is this a waste? like just for a single sprite we have to render everything again? this is how i do my coding? is there a better way or this is how all drawing are done? i am not fully understanding the drawing of directx or opengl. as an example, if u create an rpg game and u press left the character animation changes, so I have to redraw the whole map, and the character again. is there a way to draw just the character again only? I find it wasteful to redraw the whole map every time since they don’t' change. or is this how all game rendering works? thx for any comments

Share this post


Link to post
Share on other sites
Advertisement
You have to clear the entire screen because you don't want old renderings to remain on screen. To use your example of an RPG, if you move your character and re-render it, but don't clear the screen and re-render everything else, then the character will still be rendered in its old position.

Share this post


Link to post
Share on other sites
Think of the screen as a painter's canvas. Each pixel can hold a little bit of paint (a combination of red, green, and blue paint to be precise). Now, say the painter want to paint an apple on his canvas. He goes about placing the colors where we feels they should be. In the case of this static painting, everything works out.

Now, let's say that this painter is not happy with the location of the apple he painted. He thinks it should be moved a little more to the left. The painter could simple repaint the apple in another location and it would appear that the apple moved. However, the area of the canvas where the apple used to be still contains the old paint. This is obviously a problem because now it appears that the apple is in two locations. So, the painter now must paint over that old space in order to cover this flaw.

Hopefully you can see from this story that if the painter had instead gotten a new canvas and painted the apple in the new location, he would not have had the problem with the old apple appearing. This is exactly how rendering to the computer screen works. In order to show motion or animation, we do not want to worry about the previous locations of objects still having "paint" on them. Because of this we clear the screen and repaint everything on each frame.

Does that clear things up for you?

Share this post


Link to post
Share on other sites
You could in principle restrict rendering to areas of changes, but it is often complicated to track where and how large these areas are. Moreover, modern games are heavily dynamic, so that it is expected that large portions of the screen will change (think of a camera move as a worst case example in this sense: there _everything_ will change simultaneously). So, in most cases, it is better to clear the screen and make a total new draw.

Share this post


Link to post
Share on other sites
you might think its wastefull however modern hardware is VERY fast when it comes to clearing the screen and they also use this moment to perform a number of per frame setups (certainly the case with the z-buffer, you should ALWAYS clear this)

In short, clearing is a good thing todo.

Share this post


Link to post
Share on other sites
Codewise, this isn't that hard to do either. In your Render function, just clear the screen and draw everything according there current positions. In another function or somewhere else, move everything according to your gameplay physics and input. In most games these days, you won't gain anything trying to only draw what changed. I remember on graphing calculators(TI Series) you could speed it up a little by erasing what was drawn and then drawing the new location, but with the advances in 3d cards, if we do that it will just slow things down due to how rendering is done now. So I can understand where you get the idea from.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!