Drawing a managed texture

Started by
3 comments, last by Mike.Popoloski 17 years ago
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?
Advertisement
Hate to bump a question, but if someone could just point me in the right direction i'd appreciate it.
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.
Mike Popoloski | Journal | SlimDX
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.
Oops, my bad. Anyways, hope it helps.
Mike Popoloski | Journal | SlimDX

This topic is closed to new replies.

Advertisement