Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: C and .bmp files....  (Read 3446 times)

nerdpride

  • Bay Watcher
    • View Profile
Re: C and .bmp files....
« Reply #15 on: June 21, 2008, 10:11:06 am »

Sounds like a math error to me.  I looked up order of operations in c/c++ (I remember it being more complex than I guess it is, some nasty bugs I guess).  * or / go before + or -, but within similar operations, it's left-to-right.  There aren't any similar operations, so it's not so bad, but it still looks funny to have a * b + c.

The "foo" part is interesting:
Code: [Select]
(y*16+x)*12+rIt could mean a few things.
They way it is, I think it should evaluate to:
Code: [Select]
12 (16y + x) + r
192y + 12x + r
Which doesn't look so bad, except that the array is only 256 * 12 = 3072 elements big.  The y goes up to 16, so 192 * 16 = 3072.  So there's an extra bunch of x and r values added in there, 12 * 16 + 12 = 84 more than the array can hold.  I have little idea how to fix it.

How do you execute this without getting errors?

The other part should be:
Code: [Select]
myfont[(y*16+x)*12+r]=myfont[(y*16+x)*12+r]*2+(fgetc(bmp)!=0);
= 2 ( myfont[foo] ) + fgetc(bmp)!=0
The multiplication by two is weird, but it shouldn't stop you from reading the first values.  What's it there for?

Also, what's in the myfont array?  Why not just put fgetc directly in there if you're reading from the file?
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: C and .bmp files....
« Reply #16 on: June 21, 2008, 10:22:54 am »

myfont is an array of bytes that are used to draw the font.
So it has to load a 16x16 grid of characters, but the way .bmps store it...


Actually, the problem was solved by changing the screen character storage type to int.
« Last Edit: June 21, 2008, 10:43:50 am by qwertyuiopas »
Logged
Eh?
Eh!

nerdpride

  • Bay Watcher
    • View Profile
Re: C and .bmp files....
« Reply #17 on: June 21, 2008, 10:57:04 am »

Actually, the problem was solved by changing the screen character storage type to int.

Interesting.  GLubyte was one byte I'm guessing.  fgetc gets characters, so that's one byte, but you needed more for the other operations?

What's the output now?
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: C and .bmp files....
« Reply #18 on: June 21, 2008, 11:20:18 am »

It's working fine, but now I have to do the hard part: make a game out of it.
Logged
Eh?
Eh!
Pages: 1 [2]