Page 1 of 1

[Solved] [C SDL] BMP font problems

PostPosted: 20 Aug 2013, 20:35
by Pix3l
It is a bit 'of time that I am aware of this bug, but I could not even figure it out ...
I wrote two functions for writing texts in the game, using a font bmp, drawChar() and drawString() (font.c).

One write the single character and changing the color if necessary, the other write an entire string, passing every single character to the previous one.

Writing a text in different color, or try to apply a transparency around the characters of a string in general, sometimes the effect is applied only to the first char in most cases, or on a random char, as in the image.

Image

I still do not understand where the problem is, all starts passing the values ​​of "alpha" and "color", other than between the various function calls drawstring you generate errors.

Does anyone have an idea about what might be due?

You can find the current sources to the SVN respository: svn checkout svn://svn.code.sf.net/p/retrogear/code/rpg_game rpg_game
Actually I fix it by forcing alpha flag to 0 in drawString() function, try to comment and see.

{l Code}: {l Select All Code}
      // alpha=0;   //Stupid bugfix for now...

      drawChar(screen, bmpfont, area.x, area.y, area.w, area.h, asciicode, color, alpha);   
      area.x+=FONT_W;
   }

Re: [C SDL] BMP font problems

PostPosted: 20 Aug 2013, 22:31
by qubodup
I was not able to reproduce, as I couldn't get into the gameplay screen, where I assume the coloring is. This is because:
I can't do anything in the write player name menu, except scrolling around.
- going up leads me to the last character when the top row is selected but going down while the bottom row is selected does the same, not sure that's intended.
- pressing ESC in that menu probably should put me back in the main menu, unless it's a debug key.

Also I get these messages when starting:
{l Code}: {l Select All Code}
$ ./main
Unable to load file: Mix_LoadWAV_RW with NULL src
Unable to load file: Mix_LoadWAV_RW with NULL src
Unable to load file: Couldn't open 'snd/goal.wav'

Re: [C SDL] BMP font problems

PostPosted: 20 Aug 2013, 22:50
by Pix3l
qubodup {l Wrote}:I was not able to reproduce, as I couldn't get into the gameplay screen, where I assume the coloring is. This is because:
I can't do anything in the write player name menu, except scrolling around.
- going up leads me to the last character when the top row is selected but going down while the bottom row is selected does the same, not sure that's intended.
- pressing ESC in that menu probably should put me back in the main menu, unless it's a debug key.

Also I get these messages when starting:
{l Code}: {l Select All Code}
$ ./main
Unable to load file: Mix_LoadWAV_RW with NULL src
Unable to load file: Mix_LoadWAV_RW with NULL src
Unable to load file: Couldn't open 'snd/goal.wav'


Do not worry about the sounds, they are not a problem.
In any case, put some characters on the pre-game screen by pressing X, and press ENTER to enter the game, that's all.

Re: [Solved] [C SDL] BMP font problems

PostPosted: 21 Aug 2013, 21:42
by Pix3l
I found the mistake!
One was into the bmp image font, since I have copied and pasted some characters from another sheet, I didn't notice that some rgb values weren't like the others.
The other one was that SDL_SetColorKey, I simply set the transparency to off when not needed.

{l Code}: {l Select All Code}
     //Set background transaparency
     if(alpha>0)
      SDL_SetColorKey(tmpfont, SDL_SRCCOLORKEY, BLACK);
     else //Disable any background transaparency
      SDL_SetColorKey(tmpfont, 0, 0);
I'm not sure if there's better method to achieve this...

However, I will begin to be even more meticulous with the RGB values ​​of the graphics henceforth...

Thanks qubodup for you reply :]

Re: [Solved] [C SDL] BMP font problems

PostPosted: 22 Aug 2013, 00:43
by qubodup

Re: [Solved] [C SDL] BMP font problems

PostPosted: 22 Aug 2013, 09:28
by Pix3l
qubodup {l Wrote}:quak!


I didn't know this :D lol
Anyway, thanks :]

Re: [Solved] [C SDL] BMP font problems

PostPosted: 23 Aug 2013, 19:28
by jcantero
I don't think this can be related to your bug, but...
{l Code}: {l Select All Code}
SDL_SetColorKey(tmpfont, SDL_SRCCOLORKEY, BLACK);

Black is not a good choice for the alpha. Try to use a color that you know your are not going to use in any graphics/palette, like magenta (255, 0, 255)

Re: [Solved] [C SDL] BMP font problems

PostPosted: 23 Aug 2013, 19:42
by Pix3l
Don't worry, I appreciate the tip :]
But, can I ask you why you think black is not a good choice? Just for know :]

Re: [Solved] [C SDL] BMP font problems

PostPosted: 23 Aug 2013, 20:08
by jcantero
Pix3l {l Wrote}:But, can I ask you why you think black is not a good choice? Just for know :]

Because later, if you (or an artist) want to introduce some black pixels (that should be black, not transparent) in that graphic, you will have to change the graphic, and the code to use a new ColorKey. If you select a ColorKey that you are sure you are not going to use, that's not going to happen (=less job in the future).

Really it's only a convention (and a common advice in gamedev tutorials).

Re: [Solved] [C SDL] BMP font problems

PostPosted: 23 Aug 2013, 20:36
by Pix3l
I see...
But it can be said the same on magenta for example. If I want to introduce it?
But if it's convention, I shall adopt.
Thanks for the tip again :]

Re: [Solved] [C SDL] BMP font problems

PostPosted: 24 Aug 2013, 12:02
by jcantero
Pix3l {l Wrote}:But it can be said the same on magenta for example. If I want to introduce it?

Yes. But magenta is a color rarely used. Of course, if you think you could use it, just choose another one.