Jump to content
  • Advertisement
Sign in to follow this  
Sc4Freak

Rendering to a texture?

This topic is 4417 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
Advertisement
Maybe I'm not getting your problem but...
Can't you just use texture repeat over a bunch of quads?

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
I don't know - I had always thought there was a considerable overhead associated with calls to ID3DXSprite's drawing functions. Has this changed recently?

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
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!