Skip to main content
GameDev.net gamedev.net
🔒 Locked

image data in memory--how to load it into back buffer??

Started by celu Nov 23, 2006 at 1:37 AM 7 replies 1.7k views
Original Post
celu
celu
i have my image data in an array.i want to load it onto the back buffer.it tried a number of ways..including creating a plain surface and then trying the D3DXLoadSurfaceFromFileInMemory() function. But when i pass the pointer to the array the function fails.Can i pass the array pointer directly to this function? or should i may be create an HBITMAP object from this array before passing it to this function?....or is there any other easier way for loading my backbuffer with this image data....HELP!!!
51mon
51mon
I could give you a suggestion without knowing the details of your system, so it might not be appropriate.

Create first a SYSTEMMEM surface of proper size, lock it and memcpy the array into the surface. Then use IDirect3DDevice9::UpdateSurface to transfer the data to the backbuffer surface.

[EDIT] Actually you might not even need to use memcpy just make the SYSTEMMEM surface point to the array. Also the array needs to match some of the available formats supported by your graphic card to be useful in this context; if it doesn’t you have to manually write a converting routine.

[Edited by - 51mon on November 23, 2006 11:59:25 AM]
celu
celu
ya i created a SYSTEMMEM surface in X8R8G8B8 format and copied my image data on to this suface.I copied this surface on to the back buffer.But when the image gets displayed it appears distorted:(. The reason i can think of is that my image data is 24 bit/pixel( RGB bitmap data)...where as the SYSTEMMEM surface is of the X8R8G8B8 format which is a DWORD 32 bits/pixel.I used a memcpy function to directly copy my image data on to the surface.i think thats the reason for the distorted image.

Now,Does the directx surface support 24 bit RGB format? I went thru the format flags...i dont think it supports the 24 bit format(correct me if im wrong)...in that case how do i convert my 24 bit image data into the 32 bit X8R8G8B8 format?...pls gide me :(

thx a lot for ur help
51mon
51mon
Quote:
Original post by celu
ya i created a SYSTEMMEM surface in X8R8G8B8 format and copied my image data on to this suface.I copied this surface on to the back buffer.But when the image gets displayed it appears distorted:(. The reason i can think of is that my image data is 24 bit/pixel( RGB bitmap data)...where as the SYSTEMMEM surface is of the X8R8G8B8 format which is a DWORD 32 bits/pixel.I used a memcpy function to directly copy my image data on to the surface.i think thats the reason for the distorted image.

Now,Does the directx surface support 24 bit RGB format? I went thru the format flags...i dont think it supports the 24 bit format(correct me if im wrong)...in that case how do i convert my 24 bit image data into the 32 bit X8R8G8B8 format?...pls gide me :(

thx a lot for ur help


Peace of cake :) Lock the SYSTEMMEM surface with IDirect3DSurface9::LockRect then you have a struct D3DLOCKED_RECT with a pointer pBits that point into the surface. Step through the buffer, for every texel you just copy the data and add an extra empty BYTE.

The code is going to look something like this:

BYTE* pTraverse = (BYTE*)pBits;

// For every texel;
*pTraverse = R_DATA;
pTraverse++;
*pTraverse = G_DATA;
pTraverse++;
*pTraverse = B_DATA;
pTraverse++;
*pTraverse = 0;
pTraverse++;


[Edited by - 51mon on November 23, 2006 2:03:31 PM]
celu
celu
gr8 now the image is getting displayed properly..one small problem...the image is actually getting displayed upside down! does that mean i have to sort the whole image array in the reverse order?!! or is there any other more efficient way to do it?(..like may be invert the backbuffer or something)...you guidance has been a gr8 help in completing my project..thx a lot!
51mon
51mon
Quote:
Original post by celu
gr8 now the image is getting displayed properly..one small problem...the image is actually getting displayed upside down! does that mean i have to sort the whole image array in the reverse order?!! or is there any other more efficient way to do it?(..like may be invert the backbuffer or something)...you guidance has been a gr8 help in completing my project..thx a lot!


Good, I think you do it best by traversing the surface from the front-to-back at the same time you traverse the array from back-to-front. You could deal with it a lot of other ways, like inverting the texture coordinates and such but that is just unnecessary complicated. (You do know that the texture height coordinate is inverted by nature so if you are dealing with 1.0f, it is actually in the bottom of the texture, that might be the problem otherwise.)
celu
celu
YUP i changed the traversing order of the image array..now the image appears proper....thx!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.