Creating texture from source file bytes

Started by
1 comment, last by vinterberg 8 years, 5 months ago

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

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.

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

.:vinterberg:.

This topic is closed to new replies.

Advertisement