Jump to content
  • Advertisement
Sign in to follow this  
LevyDee

Creating texture from source file bytes

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

Theoretically:

if you were to open an image file via an I/O object and write its bytes out in plain text and then create an IDirect3DTexture9 object(using a compatible format), then lock the surface to receive a D3DLOCKED_RECT object, could you then simply write the original source image bytes directly to the pBits pointer and result in a functioning IDirect3DTexture9 object(representing the original image)?

 

The question:

AKA is the pBits member of D3DLOCKED_RECT a direct and exact representation of raw image pixel data(from .jpg, .png, ect...), or is their a liaison process that occurs, altering the data, when the d3d device creates the texture from a file?

 

Thank you

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure what exactly you are asking because you seem to express yourself in a weird way.

My understanding is you want to upload the exact file content as it is on disk to the texture? If that is the case, then no. JPG and PNG are compressed formats. You need to decompress them, then upload them to texture. Even a simple, uncompressed bitmap cannot be uploaded as it is because there is a header in front of it which you need to deal with.
There are compressed formats you can upload to a texture (the DXTn family of compression algorithms are famous for that) but even in those cases you will usually have a small header of metadata (which you need to load and understand, followed by the actual texture data you can upload).

One way to deal PNG and JPEG compression would be to use the format's reference implementations (libpng and libjpeg). Another would be to use something simple like stbimage. Many more ways exist. Unless you have a particular interest in that area I would not advise to write your own decoder.

Share this post


Link to post
Share on other sites

pBits is in the same format as you specified upon creation, A8R8G8B8=4 bytes per pixel in pBits and so on...

But you need to interpret the image file before putting it's data into a texture, to get the raw (A)RGB image buffer which should be straightforward to put into pBits :)

Why not use D3DXCreateTextureFromFile() or whatever it's called? It will do all the work for you cool.png

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!