Sign in to follow this  

Rendering to a texture?

This topic is 4108 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 writing a 2D game in Direct3D9. Its an RTS, and the game is played from a top-down view. You play on a grid-based terrain map, so each grid in the map has a terrain tile associated to it (a 64x64 texture). Since drawing a screen full of individual 64x64 tiles was slow, I decided to put them all together into 1 big texture at application startup. When I did it in DirectDraw, all I had to do was blit the individual tiles to the surface. But I'm stumped as to how I could achieve the same thing in Direct3D. The easiest way I could think of would be to lock the surfaces and memcpy it over line by line. But that would lengthen load time by a fair amount. I've heard of Direct3D's ability to render to a texture, and it seems the ideal solution. I'm wondering if its possible to do this in 2D, and how I would go about doing this. I'm using ID3DXSprite, if that helps any. Thanks in advance.

Share this post


Link to post
Share on other sites

Hello,

Using memcpy and Direct3D for drawing graphics is definetely a way to make a slow performing application and also, it will throw away the greatest advantage of D3D, that is 3d acceleration and hardware rasterization.

So umm, why not study a bit of drawing textured polygons with D3D ? That's the way to go, even for 2d game.

Cheers!

Share this post


Link to post
Share on other sites
Sorry if I wasn't clear enough. What I've got are a lot of textures, each 64x64 pixels and each representing a terrain type (such as dirt, grass, etc).

A map is made up of a large grid of such textures, and instead of individually rendering each and every 64x64 pixel texture, I want to combine them all into one large texture at initialisation so that, in-game, I only have to render that single large texture as the terrain instead of rendering all the little ones separately.

Problem is, I don't know how to do it fast (i.e. not doing it on the CPU).

Share this post


Link to post
Share on other sites
Sorry, I can't give you an answer since I've never tried rendering to a texture, but you can check out this. It's not the best, but it seems to have the info.

I do have to ask why you don't want to render each tile during runtime? It's not slow at all (it's the method that I'm using and have been using for quite some time) and has it's advantages. Plus, I don't think one giant quad/texture would be any faster or efficient.

Edit: Also, if you do a giant texture at runtime you can't do stuff like animated tiles.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yes, it really changed. in one of the 9.0c updates, the sprite functions were rewritten and they are really fast now.
but when rendering a grid, you dont even need to use the sprites, just create your own vertex and indexbuffer (for the world), and use sprites for the player object etc. read up about performance issues in the dx-sdk abd about locking buffers with NOOVERWRITE-flag.
this should give you the performance you need.

btw. just try to optimize rendering only if you need it. as long as YOU dont have performance issues ("they all say its so slow", "i thought there was..."), everything is fine. optimize only when you really have to (fps <

Share this post


Link to post
Share on other sites

Rendering a just a grid, even with many different textures is rather fast. Just one thing to remember "Don't never ever draw the tiles individually".

The render to texture isn't out of question. I could imagine that you could use it in a situation where you need to zoom out far from the tiles. Otherwise you can do with out it.

Cheers !

Share this post


Link to post
Share on other sites

This topic is 4108 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this