#### Archived

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

# Targa File and DirectDraw Problem

This topic is 5927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys, This problem is really starting to get to me. I'm cutting and pasting my function that loads a targa(*.tga) file to it's own 16bit surface. It works if I load 16bit color Targa files. However, when I load 24bit color files, only the last file loaded can be seen. The images loaded before it turn pure black. If anyone has any ideas as to what I'm doing wrong, please let me know. Oh, and by the way, I'm already aware that my code is horrible, hard to read, and ugly, so please don't remind me Thanks in advance!

{
DDSURFACEDESC ddsd;
int file = _open(filename,_O_RDONLY | _O_BINARY);
BYTE* byte_buffer = NULL, *byte_surface = NULL;
WORD* word_buffer = NULL, *word_surface = NULL;
int image_length = 0, byte_count = 0;
WORD i = 0, n = 0;
WORD wTemp = 0;
BYTE bTemp = 0, bRTemp = 0, bGTemp = 0, bBTemp = 0;

{
close(file);
return FALSE;
}

byte_buffer = (BYTE*)malloc(image_length);
memset((void*)byte_buffer,0,image_length);
word_buffer = (WORD*)byte_buffer;

{
if(byte_buffer)
free(byte_buffer);
close(file);
return FALSE;
}

{
if(byte_buffer)
free(byte_buffer);
close(file);
return FALSE;
}

memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
if(FAILED(g_pDD->CreateSurface(&ddsd,&surface,NULL)))
{
if(byte_buffer)
free(byte_buffer);
close(file);
return FALSE;
}

surface->GetSurfaceDesc(&ddsd);
if(FAILED(surface->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL)))
{
if(byte_buffer)
free(byte_buffer);
close(file);
return FALSE;
}
memset(ddsd.lpSurface,0,image_length);
byte_surface = (BYTE*)ddsd.lpSurface;
word_surface = (WORD*)ddsd.lpSurface;

switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
{
case 15:
// need to implement

break;
case 16:
{
{
{
case 16:

wTemp = word_buffer[(i * header.wWidth) + n];
wTemp = ( ( (wTemp & _15BIT_REDMASK) << 1) |
( (wTemp & _15BIT_GREENMASK) << 1) |
word_surface[(((ddsd.dwHeight - 1) - i) * (ddsd.lPitch / 2)) + n] = wTemp;
break;
case 24:
wTemp = (((byte_buffer[(((i * header.wWidth) + n) * 3) + 0] >> 3) & 0x1F) ) |
(((byte_buffer[(((i * header.wWidth) + n) * 3) + 1] >> 2) & 0x3F) << 5) |
(((byte_buffer[(((i * header.wWidth) + n) * 3) + 2] >> 3) & 0x1F) << 11);
word_surface[(((ddsd.dwHeight - 1) - i) * (ddsd.lPitch / 2)) + n] = wTemp;
break;
default:
if(byte_buffer)
free(byte_buffer);
close(file);
surface->Unlock(ddsd.lpSurface);
return FALSE;
}
}
}
break;
case 24:
// Need to implement

break;
case 32:
// need to implement

break;
default:
if(byte_buffer)
free(byte_buffer);
close(file);
surface->Unlock(ddsd.lpSurface);
return FALSE;
}

surface->Unlock(ddsd.lpSurface);
if(byte_buffer)
free(byte_buffer);
close(file);

return TRUE;
}

[edited by - silentrob66 on May 30, 2002 10:48:33 PM]

##### Share on other sites
I''m not expecting an answer, but I would like some opinions. Anyone have similar problems in the past? If so, what fixed it? Anyone have any ideas off the top of thier head? Thanks again, guys.

##### Share on other sites
I can''t see anything thats immediately obvious, but are you sure the problem lies in this piece of code?
Are you sure the other surfaces aren''t getting lost somewhere?

1. 1
2. 2
3. 3
4. 4
frob
20
5. 5
JoeJ
20

• 11
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632214
• Total Posts
3004858

×