Just going through the tutorials on VC++ while waiting for eMbeddedwhatevertheheckmicrosoftnamedtheirsoftware to complete downloading and installing. Had a couple of Q's:
1. I noticed a comment in the tutorial that there are some difference between windows CE and Win 9x, and they'll be talked about later. But there isn't anything mentioned in the tutorial? I ask because..
2. When I try to compile loadtga, I get errors on the CreateFile function that its first parameter should be a const char *, not const short *. I assume this is somehow Unicode related? I change the parameter to char, and the L"..." string to "..." and it will load files, so I guess that's ok.
3. I have to use 24 bit Targa files (curses ThumbsPlus! I thought better of you...). Wierd thing is that in order to load them properly, I have to reverse the position of red and blue. Wierd, huh? Here is the code I'm using to load 24 bit TIFF's:
Hey, I don't get it either, but WTF, it works!
4. Couple of issues with the "average" example. Like, it doesn't average! The example does a / by 4, which isn't really going to average the colors because Green is given an extra bit. So what I did is tack an extra bit onto red and blue, and divide by 6:
5. Second, the "average" example uses the "total" number, not the "average" number it just calculated! D'oh!
6. Third, the examples multiply y by 320. Shouldn't that be 240, the width of one line?
Anyways, like the tutorial alot. I'm hoping to, like probably alot of people, write games in my "spare" time. Yeah, right.
Last modification: Richard Hendricks - 01/02/02 at 02:19:51
Last modification: Richard Hendricks - 01/02/02 at 02:20:16
1. I noticed a comment in the tutorial that there are some difference between windows CE and Win 9x, and they'll be talked about later. But there isn't anything mentioned in the tutorial? I ask because..
2. When I try to compile loadtga, I get errors on the CreateFile function that its first parameter should be a const char *, not const short *. I assume this is somehow Unicode related? I change the parameter to char, and the L"..." string to "..." and it will load files, so I guess that's ok.
3. I have to use 24 bit Targa files (curses ThumbsPlus! I thought better of you...). Wierd thing is that in order to load them properly, I have to reverse the position of red and blue. Wierd, huh? Here is the code I'm using to load 24 bit TIFF's:
- Code:
// Function to load standard TARGA files. Must be uncompressed, 24 bit format
void loadtga24( const char* file, int w, int h, PIXEL* dest )
{
int red=0, green=0, blue=0;
DWORD size = w * 3 * h + 20, bytesread;
BYTE* tgabuff = new BYTE[size];
HANDLE tga = CreateFile( file, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
ReadFile( tga, tgabuff, size, &bytesread, 0 );
CloseHandle( tga );
unsigned char* src = (unsigned char*)tgabuff + 18 + (h - 1) * w * 3;
unsigned short* dst = (unsigned short*)dest;
for ( int i = 0; i < h; i++ )
{
for ( int x = 0; x < w; x++ )
{
//For some odd reason, Targa 24 bit files are red/blue reversed.
blue = *(src + x*3 ) >> 3;
green = *(src + x*3 + 1) >> 2;
red = *(src + x*3 + 2) >> 3;
*(dst + x) = (red << 11) + (green << 5) + blue;
}
dst += w;
src -= w*3;
}
delete tgabuff;
}
Hey, I don't get it either, but WTF, it works!
4. Couple of issues with the "average" example. Like, it doesn't average! The example does a / by 4, which isn't really going to average the colors because Green is given an extra bit. So what I did is tack an extra bit onto red and blue, and divide by 6:
- Code:
int total = (red >> 10) + (green >> 5) + (blue << 1);
int average = total / 6;
5. Second, the "average" example uses the "total" number, not the "average" number it just calculated! D'oh!
6. Third, the examples multiply y by 320. Shouldn't that be 240, the width of one line?
Anyways, like the tutorial alot. I'm hoping to, like probably alot of people, write games in my "spare" time. Yeah, right.
Last modification: Richard Hendricks - 01/02/02 at 02:19:51
Last modification: Richard Hendricks - 01/02/02 at 02:20:16