Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

Rendering Class

This topic is 2515 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'm wanting to make a class like the following

class Render
{
public:
Render();
void DrawLine();
void DrawSquare();
void DrawText();
void Present();
private:
ID3D11Device Device;
ID3D11Context Context;
ID3D11SwapChain SwapChain;
...
....
....
}

How should i implement my drawline() and drawsquare() functions? Do i just simply have the resources be created inside the call and then call drawn to the back buffer and then all Present() to display the drawing? or should i store ALL the needed resources in my private member section?

I'm pretty much wanting to make a simple class i can use to do basic drawing. Anyone have any advice on how they would implement this?

Share this post


Link to post
Share on other sites
Advertisement
I havent used D3D11 (or D3D10 for that matter). How I would do it in D3D9 is to have a class like:
public:
-MyClass() - initialises D3D9
-~MyClass() - cleans up the device and all the contents
-render() - renders everything (all the arrays)
-clean() - cleans up all the contents
-onLostDevice()
-restoreDevice()
-addLine(point1, point2) - initialises a line and pushes it backwards on an array
-addSquare()
-addText()
-etc..
private:
-The device and all that stuff
-Array of lines
-Array of squares
-Array of text

Share this post


Link to post
Share on other sites

How should i implement my drawline() and drawsquare() functions? Do i just simply have the resources be created inside the call and then call drawn to the back buffer and then all Present() to display the drawing? or should i store ALL the needed resources in my private member section?
I'm pretty much wanting to make a simple class i can use to do basic drawing. Anyone have any advice on how they would implement this?


For drawing a lines and squares, I'd keep a single list of elements containing starting and ending points and a color (if this is enough for your line presentation). When you have finished adding elements to your line container you may draw all of them with a single draw call. Do not allocate resources in any of the draw functions also, try to avoid drawing single elements at time.

- For the Implementation you could have something like a LineDrawer class which would allocate the resources at the startup and release them when deleted. You could have AddLine(Vector Start,Vector End,dword Color) member function which would add elements to the line container. You can use a dynamic vertex buffer for drawing.

- There are simple text rendering functions with DXUT, you may start looking at them.

- Actually you may create your class around the DXUT. It may save you a lot of work.

Just to clear things out with OCN.FIX : D3D11 device may not get lost and there is no need to restore resources.


Cheers!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!