Sign in to follow this  
Phrawth

Drawing a managed texture

Recommended Posts

I'd like to put all of my sprites onto a single managed texture, but can't figure out how to draw them on there. At initialization, I have an empty managed texture and all of the images are in individual files. From what I can gather, I have to lock the texture, then update it, then unlock it. My question is: How do I update it? I know you get a pointer to the data from lock, but how do I use it to update the texture with the various images? What functions am I supposed to be using here?

Share this post


Link to post
Share on other sites
OK, first of all you haven't even waited 30 minutes.

Secondly, I found all my information using Google and MSDN, so you know where to look for more information or if you have questions in the future.

Third, you should take a look at LockRect, which it appears you may have already done. This function lets you lock a texture surface, and returns a pointer to the data.

First, create a texture object that is big enough to hold all of your smaller textures.

Next, loop through each smaller texture, lock it, receive a pointer to the data, and then read that data and copy it into the larger texture.

The data is a BYTE pointer, and the way it is laid out depends upon the surface format of the texture. If your texture is 32 bits, with 4 bits for each color, you can do something like this to read the colors:


for (DWORD y = 0; y < surfaceDesc.Height; y++)
{
for (DWORD x = 0; x < surfaceDesc.Width; x++)
{
DWORD index=(x * 4 + (y * (locked.Pitch)));

// Blue
BYTE b=bytePointer[index];

// Green
BYTE g=bytePointer[index+1];

// Red
BYTE r=bytePointer[index+2];

// Alpha
BYTE a=bytePointer[index+3];
}
}




Writing the data out to the larger texture would just be a matter of going backwards.

Now, an easier way would be to just copy all of the images into one larger image using a paint program, but that may not always be applicable.

If you need more help, feel free to ask.

Share this post


Link to post
Share on other sites
Actually my first post was at 12:10am in the morning and my second was at 12:37pm. I can see how that would catch you though.
Anyway, thanks a lot for the help. I haven't tried it yet, but it looks good to me.

Share this post


Link to post
Share on other sites

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