Texture transfers

I am using visual basic 6 and direct x 9.  In direct x one loads a texture from a .dds or .bmp file. In visual basic, one can create a picture box and draw graphics on it and then save it as a .bmp file. In order to transfer the contents of a picture box to a texture, one must save the picture as a .bmp file to disk, then reload the texture from disk as a .bmp file.  Is there a way to transfer the picture to the texture without going through the process of saving to and loading back from disk. Is there an alternative process  that I could use, bearing in mind that I want to do realtime texture modifications in the same way that one would use say the picture.line function to draw a line on a picture, I want to be able to draw a line on a mesh ?

Then, does anyone know if it is possible to texture an object in dx9 with an avi file ?


Who is Participating?
davebytesConnect With a Mentor Commented:
I'm not exactly sure of the limitations in VB for doing pointer-based work, but that's the way to do it.

Actually, both answers can work the same.

You want a dynamic texture, USAGE_DYNAMIC.  That is, one whose data is going to change frequently.  Create a raw D3D texture object of the correct dimensions (again, I always suggest keeping to power-of-2 for cleanliness...).  I'd likely suggest making it a raw ARGB8888 format.  CreateTexture off the device, or D3DXCreateTexture will both work.

Then, when the source changes, LockRect the entire texture, giving you a ptr, and an offset per row.  Grab a DIB from the bitmap, and walk the two step by step copying pixels for each row, then jumping to the start of the new row of data.

Similar approach for an AVI.  Decompress into a memory buffer, lock a texture, copy the data.

There are more optimal approaches using functions like D3DXFillTexture to simplify raw byte-processing through the texture (just need the source data), or D3DXLoadSurfaceFromMemory which might work better for auto-converting data formats for you without need to walk either surface directly.

All Courses

From novice to tech pro — start learning today.