Jump to content
  • Advertisement
Sign in to follow this  
Daivuk

OpenGL Creating Texture from Buffer

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

Hi, I search a lot in the MSDN and didnt find anything about that. I was creating 3d for long time with OpenGL. Now for school I have to make a demo in Directx. So for loading texture I'm using this :
D3DXCreateTextureFromFileEx(
	D3DDevice, 
	"main/textures/textureTest.tga", 
	D3DX_DEFAULT, 
	D3DX_DEFAULT,
	D3DX_DEFAULT, 
	0, 
	D3DFMT_UNKNOWN, 
	D3DPOOL_MANAGED,
	D3DX_DEFAULT, 
	D3DX_DEFAULT, 
	0, 
	NULL, 
	NULL, 
	&Texture);

Thats work fine for texture from file. Now, I want to use my own texture format, that I use in many of my engines :P This file contain Base texture, detail texture, specular texture, normal map, etc. I have my own loader for this, and for each layer I have the following input :
unsigned char *Buffer
int Width
int Height
int BytePerPixel

So with that I can create easily a texture in opengl. But HOW in directx from this buffer??? The buffer is just an array of all color RGB or RGBA. What I did first is to try this function :
D3DXCreateTextureFromFileInMemoryEx(      
	D3DDevice,
	Buffer,
	BytePerPixel*Width*Height,
	Width,
	Height,
	D3DX_DEFAULT,
	0,
	(BytePerPixel == 3) ? D3DFMT_R8G8B8 : D3DFMT_A8B8G8R8,
	D3DPOOL_MANAGED,
	D3DX_DEFAULT,
	D3DX_DEFAULT,
	0,
	NULL,
	NULL,
	&Texture);

Using this function the result it White, thats mean NULL, didnt work ;) So, I found this on MSDN :
D3DXCreateTexture(      
	D3DDevice,
	Width,
	Height,
	D3DX_DEFAULT,
	0,
	(BytePerPixel == 3) ? D3DFMT_R8G8B8 : D3DFMT_A8B8G8R8,
	D3DPOOL_MANAGED,
	&Texture);

Hum, this create me a texture, but empty (black) Now, how to put my buffer in it then it will automaticly create my Mipmap or there is a function to create a texture from my buffer?? thanks!

Share this post


Link to post
Share on other sites
Advertisement
D3DXCreateTextureFromFileInMemoryEx isn't what you want, it loads a texture from file data in memory, a jpeg file copied into memory for example, not a raw buffer of image data.

To create a texture from a buffer in memory, first create a texture of the appropriate size ( although this method can also automatically resize the image if the size of your texture is different ), then get a pointer to its top level surface using the GetSurfaceLevel method. Then call D3DXLoadSurfaceFromMemory, and call the GenerateMipSubLevels method of the texture. (your texture must be created with the AUTOGENMIPMAPS flag for this to work)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Oxyacetylene
D3DXCreateTextureFromFileInMemoryEx isn't what you want, it loads a texture from file data in memory, a jpeg file copied into memory for example, not a raw buffer of image data.


How can i copy a file into memory, eg. jpg??

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Quote:
Original post by Oxyacetylene
D3DXCreateTextureFromFileInMemoryEx isn't what you want, it loads a texture from file data in memory, a jpeg file copied into memory for example, not a raw buffer of image data.


How can i copy a file into memory, eg. jpg??


You need a white chicken and red paint.
Make a pentagram with the red paint. Slice the chickens throat and pour its blood at each edge of the pentagram. Cast the magic word "Iksalamir!".
If all goes well (and the moon is in the right conjugation to Alpha Centauri), your JPEG file will be copied to memory.

Share this post


Link to post
Share on other sites
Hum, nice answer but not very useful lol

To load a file into memory its simple :
Open the file, and read all the bytes and put them in an array.
Then close the file, and pass this array to the function :P

So its like the same file, but in memory ;)

This is useful if you pack all your files into something like a .pk3 ;)

Share this post


Link to post
Share on other sites
Hum, probably an array of what you want.
It recieve an void*, so D3D convert it into what he want ;)
But it have to be exactly the file

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!