[Solved] [C SDL] BMP font problems

[Solved] [C SDL] BMP font problems

Postby Pix3l » 20 Aug 2013, 20:35

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;
   }
Last edited by Pix3l on 21 Aug 2013, 21:31, edited 1 time in total.
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Re: [C SDL] BMP font problems

Postby qubodup » 20 Aug 2013, 22:31

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'
User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

Re: [C SDL] BMP font problems

Postby Pix3l » 20 Aug 2013, 22:50

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.
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

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

Postby Pix3l » 21 Aug 2013, 21:42

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 :]
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

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

Postby qubodup » 22 Aug 2013, 00:43

User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

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

Postby Pix3l » 22 Aug 2013, 09:28

qubodup {l Wrote}:quak!


I didn't know this :D lol
Anyway, thanks :]
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

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

Postby jcantero » 23 Aug 2013, 19:28

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)
jcantero
 
Posts: 43
Joined: 01 Jul 2013, 18:20

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

Postby Pix3l » 23 Aug 2013, 19:42

Don't worry, I appreciate the tip :]
But, can I ask you why you think black is not a good choice? Just for know :]
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

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

Postby jcantero » 23 Aug 2013, 20:08

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).
jcantero
 
Posts: 43
Joined: 01 Jul 2013, 18:20

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

Postby Pix3l » 23 Aug 2013, 20:36

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 :]
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

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

Postby jcantero » 24 Aug 2013, 12:02

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.
jcantero
 
Posts: 43
Joined: 01 Jul 2013, 18:20

Who is online

Users browsing this forum: No registered users and 1 guest