Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


DDS texture Loader

This topic is 5450 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, im trying to make my own DDS texture loader in C(not c++) i have been working on it for a little to long with many of the same errors poping up again and again. If you would all be so kind as to direct me as to what portion of my loader is wrong.
static void InitalizeTextures(D3DPointers *data)
	D3DLOCKED_RECT pLockedRect;

	FILE *in;
	VOID *ImgDat;
	VOID *bla;
	VOID *Header;
	DWORD *Size;
	int read = 0;
	Header = malloc(sizeof(DWORD)*10);
	bla = malloc(sizeof(DWORD)*22);
	Size = malloc(2);

	ImgDat = malloc(262144);
	//MessageBox(data->hWnd,read ,in,0);

	read = fread(ImgDat,1, 262144, in);

	data->m_pD3DDevice->lpVtbl->CreateTexture(data->m_pD3DDevice,512,512,0,NULL, D3DFMT_DXT5, D3DPOOL_MANAGED, &data->TextureArray[0], NULL);
	data->TextureArray[0]->lpVtbl->LockRect(data->TextureArray[0],0,&pLockedRect, NULL, NULL);
	pLockedRect.pBits = ImgDat;
	//pLockedRect.Pitch = Size;


Share this post

Link to post
Share on other sites
First of all, I believe the DDS header is 128 bytes. (4 bytes of magic-number + 124 bytes for the DDSURFACEDESC2.) From what I can tell, you are only skipping 36 bytes (12+2+22) before you try to read your image data.

Secondly, you can''t just lock your surface and change the value of the pBits pointer. You have to actually copy your data. Something like memcpy(pBits, ImgDat, 262114) would work. Or you could read the data directly into your surface:

in = fopen(...);
fseek(in, 128, SEEK_CUR);
fread(pLockedRect->pBits, pLockedRect->Size, 1, in);


Share this post

Link to post
Share on other sites
thanks so much your posting allowed me to go back to an earlyer version and find out that the reason i was haveing trouble with it was i thought the magic number was 2 bytes i know i saw that in the Dx docs but i guess not. well thanks alot for you help and may all you debugging be short.

Share this post

Link to post
Share on other sites

  • 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!