• Advertisement
Sign in to follow this  

Creating a texture from an BGRA BYTE array

This topic is 4170 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

Hello, I have a BGRA BYTE array and would like to turn it into a texture. The array looks similar to this: 2a 33 00 ff 12 92 01 FF ...... Its fairly big as it was originally created from a movie frame. The movie frame was a texture and I had to go render to an offscreen surface to make this buffer. Now that Ive analyzed the BYTEs in the buffer I need to see it on screen. I have the total number of bytes, width (in pixels), height (in pixels) and would like to keep it in the exact same pixel space. Once created I will simply map it to a square (or billboard) that renders in a full window. Several thoughts I had about how to do this was: 1. Use D3DXCreateTextureFromFileInMemoryEx and feed it the buffer with all the correct settings. Im unsure about this since it requires certain file formats like .bmp or .tga, which this buffer is not. 2. Use D3DCreateTexture to make an empty texture and fill it with D3DFillTexture but I am not sure how to use this, since Ive never done this before. Any suggestions how I might easiest accomplish this?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by freekquency23
I have the total number of bytes, width (in pixels), height (in pixels)
and would like to keep it in the exact same pixel space.

You are going to have to convert pixel spaces - D3D9 doesn't have a BGRA format.

Quote:

1. Use D3DXCreateTextureFromFileInMemoryEx and feed it the buffer with all the correct settings. Im unsure about this since it requires certain file formats like .bmp or .tga, which this buffer is not.

Yea, you are correct - this won't work, since you just have raw data.

Quote:
2. Use D3DCreateTexture to make an empty texture and fill it with D3DFillTexture but I am not sure how to use this, since Ive never done this before.

D3DXFillTexture is quite self-explanatory to use - it's as simple as the little code sample at the bottom of it's documentation.

You can also create a texture, then lock it and fill it manually - check out this KBase article for some guidelines.

Share this post


Link to post
Share on other sites
Thanks for the suggestion.

I still have a couple of questions, however.

Quote:
"You are going to have to convert pixel spaces - D3D9 doesn't have a BGRA format."

1. Due to byte order, isnt ARGB read out as BGRA on windows machines?
Thats what I meant by BGRA. I guess what I want to tell D3D is that I want to
create an ARGB texture, but my data is stored with the alpha channel as the lsb as was given to me when I locked a texture previously and memcpy the data row by row.

2. Thanks for the link, but Im not sure what attributes I should use when creatingand locking the texture for writing. Also, D3D textures have a pitch with extra data at the end of each row. Do I need to worry about this when writing bytes into the texture?

3. know where there is any sample code for creating and writing textures?
the link only has code that reads from a texture.

thanks

Share this post


Link to post
Share on other sites
Ha! I answered my own question (#1 that is)

excerpt from Direct X SDK documentation (D3DFormat):
"All formats are listed from left to right, most significant bit (MSB) to least significant bit (LSB). For example, D3DFORMAT_ARGB is ordered from the MSB channel A (alpha), to the LSB channel B (blue). When traversing surface data, the data is stored in memory from LSB to MSB, which means that the channel order in memory is from LSB (blue) to MSB (alpha)."

I am locking the surface and reading bytes, which means I am actually seeing BGRA, as the last sentance claims. I guess Ill have to read the data into the texture backwards so it fills it as ARGB.

Still not sure how to fill textures once Ive created them though.
I know I have to lock them, but it looks like I need to use a callback function,
which doesnt make sense. I have all my data stored in a buffer and just want to
write it. (See D3DXFillTexture API)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement