Jump to content
  • Advertisement
Sign in to follow this  
AcidJazz

Where to draw in your code?

This topic is 4482 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 wasn't sure if I should put this in OpenGL or here. Say I'm making a breakout game. Do I have Draw() functions in each object (ie The Paddle, The Bricks, etc) and they draw themselves or do I have one or two large draw functions that draw everything? I'm having a hard time understanding exactly what Game / Graphics engines really do for some reason. There's really not any animation in this so maybe that's why I'm having a hard time understanding. Lets say I was doing some sort of person walking. The character class would control what frame it was on (or however you decided to handle it) right? What does a Graphics Engine do then? I had / have this picture of a Graphics engine being a giant class that handled certain drawing into the world but in reality it seems smarter to have each individual object handle its own drawing? Can anyone shed some light? Also perhaps a good read? I appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
I guess in every program there is a main rendering / processing function after the window is created, right? This will handle all of the logic in the game itself? Each object will have its own abilities which is what their member functions would be.


So when having a Graphics Engine, would you make a seperate class for something like this, or is the engine itself that function?

If I'm going about this the wrong way, shed light =)

Share this post


Link to post
Share on other sites
My graphics renderer provides a basic Renderable object and several Renderable-inherited objects. Only these have the power to render themselves.

My game objects create such renderables, given them a position (so they know where they are rendered) and give them to the Renderer. Until they're removed from the renderer, all renderable objects will be drawn every frame at the correct position without further intervention from the non-rendering parts of the game.

Therefore, my game loop looks somewhat like this:


for(;;) {
timer.Update();

// Processing
game.Update(Timer.Now);

// Rendering
if(!active) timer.Sleep();
else renderer.Render(Timer.Now);
}

Share this post


Link to post
Share on other sites
Typically there are two possibilities. You can put the rendering code of your Objects into the Objectclass itself (normaly via inheritence) so every object can draw themself or you can write a class or function which gets the neccassary data of the objects like Vertex porsition, color, texture coordinates... and this class, function will render the scene (This would be the renderer). From my point of view the last possibility is better but harder to implement and i think used in graphics engines. So if you use a renderer you do not to have a draw functionfor each object. The object will only store the data (like Vertex and texture coordinates) and give this data to the renderer and thats all. Maybe this will help you.

Share this post


Link to post
Share on other sites
Ahh basically the different scenarios I proposed were "proper" solutions...

Thanks for the help.

I dont see the point of creating a class for a graphics engine (at least of such small needs). Passing a pointer around too is also a pain and makes things sloppy.

I'll just settle with a function near the main logic to handle all of that.

Thanks again!

Share this post


Link to post
Share on other sites
In a very simple scene, you might as well have a separate function that renders everything directly. Render() --> screen

In a scene that is not so simple, that function would not actually do the rendering, but would tell each object to render itself. Render() --> Object --> screen

In a complicated scene, the object would no longer render itself, but would instead tell a renderer to render it. Render() --> Object --> Renderer --> screen

Share this post


Link to post
Share on other sites
I have a renderable class that each object inherits. The renderable class automatically registers itself with the scene graph, so all I have to do is call SceneGraph->Draw () and it will go through every renderable object in the game and draw it.

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!