Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Rendering 2D


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 BambooCatfish   Members   -  Reputation: 130

Like
0Likes
Like

Posted 11 December 2012 - 02:57 PM

Hi,

I have question about rendering in general. I have windows or a HUD if you want... how do I handle telling the renderer to draw the informaiton for each window? should they just draw themselves? I'm not sure how to handle turning window specific information into a form that can be handled in a general sense by the renderer.

Another way of putting it:

I want the window to "tell" the renderer to draw it at a position and then to draw its contents, whatever they may be.

Dont know where to start and I'm just scratching my head thinking about it.

Thanks,
Nick

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 20948

Like
2Likes
Like

Posted 11 December 2012 - 03:19 PM

A window should know it's own location. It's children should know their own location (relative to the window's topleft corner).
When told to draw, a window draws itself, then tells each child to draw themselves, and so on.

A window is a widget, and buttons, text labels, line edits, etc... are all also widgets. Thus, you have a tree hierarchy of abstract widgets that are overrided as windows, buttons, menus, and other GUI elements. Each widget draws itself at the parent's absolute pos, then tells each other widget to draw themselves.
The same thing happens with events, but in reverse. A mouse click gets passed (untouched) from parent to child, until the bottom-most child gets it. If the bottom-most child decides to process the click, then afterward the event is discarded. Otherwise, the second-to-the-bottom child gets an opportunity to process the click and discard, and so on.

This is a very common way GUIs are handled. Almost everything is a widget. Sometimes a 'widget' is also called a 'window', like in Win32 - which in Win32, a button IS-A window. But I think it's better to use the term 'widget', because it separates out the 'abstract' concept from the specific idea of a application window and pop-up windows that contains buttons and other elements.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 BeerNutts   Crossbones+   -  Reputation: 2998

Like
1Likes
Like

Posted 11 December 2012 - 03:22 PM

How do you store these Windows? When you perform your rendering phase, you will have to loop through all the windows and draw them; I would suggest having a Draw() function each window has, and it handles drawing itself since it knows where it is, and what all it needs to draw. Something like this

// Let's assume you put all the windows into a vector of TWindows, and they have a Draw() funciton
std::vector<TWindows> Windows;


// in main rendering loop
void Render()
{
  // Draw all object in game 1st since HUD sits on top of the game

  for (int i = 0; i < Windows.size(); ++i) {
    Windows[i].Draw(SurfaceToDraw);
  }
}

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 BambooCatfish   Members   -  Reputation: 130

Like
0Likes
Like

Posted 11 December 2012 - 09:00 PM

Servant of the Lord-

Thanks for the info I wasn;t sure how they were handled. The hierarchy definitely makes sense, hopefully I can put it to good use!

BeerNutts-

Yeah, basically I have a container that holds them in my renderer object. However, I am handling sprites and such by reading an xml file to load the appropriate data. so the "playerCharacter" doesn't actually hold is sprite it holds the ID of where it is located in the list of loaded images. the image is drawn @ the playerCharacters location. Thats how my tile map works as well loads the tilemap xml and adds the resources and reads what texture to use based on a textureID. Right now I am just rendering rectangles to get a feel for displaying the data and getting everyhting working right before I start using images and such for the widget/window Appropriate?

Thanks,
Nick

#5 BeerNutts   Crossbones+   -  Reputation: 2998

Like
1Likes
Like

Posted 12 December 2012 - 09:59 AM

Nick,

There are many different ways to solve this kind of problem, but I'm of the opinion the individual entities should handle drawing themselves, since they have all the information, and you don't have to share it. And, if you take the path of having the windows draw themselves (which would be best since these "windows" could have different data that it has to display; images, text, etc.), but keep the characters drawn externally, it's a clash of styles.

It's fine how you load the images, and the character only stores an ID for the image it is using, but that doesn't preclude you from still having the character (and all other on-screen entities) draw themselves.

You are limiting how you can draw the player; will your player ONLY ever be the image it's assigned to? Will he not have special FX as well (blinking, glowing, transparent, wearing different items)? If so, then you're going to be writing a lot of code outside the player or other objects to get every possible status. However, if you handle the objects drawing themselves, it will all be contained within the draw:
void Player::Draw()
{
  uint8_t Alpha = 255;

  // if our player is invisible, set the alpha small so he looks transparent
  if (IsInvisible) {
    Alpha = 50;
  }
  // Draw the image we currently are using
  RenderingEngine->Draw(CurrentImage, Alpha, LocationX, LocationY);

  // If we have a powerup, create a glow around the player
  if (HasQuadDamage) {
    RenderingEngine->CircleGlow(LocationX, LocationY, COLOR_BLUE);
  }
...
}

As an example, you can check out my Old Blog (see the link in my Sig) for a simple game I made. You can also download the source from here

Good luck and have fun!
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS