Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  BitmapFont in libGDX problem  (Read 6579 times)
0 Members and 1 Guest are viewing this topic.
Offline jhallenberg

Senior Newbie





« Posted 2012-10-13 23:12:08 »

When I try to draw a string in libGDX using a BitmapFont I only get filled boxes instead of characters, with the specified font color.
I haven't found any information googling so I'm asking here.
Offline Cero
« Reply #1 - Posted 2012-10-13 23:50:12 »

Never seen that.
If you open the png in like photoshop, are the characters all fine and visible ?

Maybe you do something really wrong with the code, would help if you post a minimal scenario

Offline jhallenberg

Senior Newbie





« Reply #2 - Posted 2012-10-13 23:58:22 »

I open the font in the image viewer and the background is transparent.
Here's the loading/declaration
1  
BitmapFont font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false);

And the rendering code
1  
2  
3  
4  
5  
6  
batch.begin();
     
font.draw(batch, "blabla", 10, 10);
stage.draw();
     
batch.end();
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2012-10-14 00:40:33 »

Never used Stage before, but I dont think it would be a problems
It does sound like the alpha channel has a problem or the texture is destroyed or the png has like a color format not supported by the libgdx png reader

Try posting it here : http://www.badlogicgames.com/forum/viewforum.php?f=11

Mario, one of the creators checks there really frequently and not as often here.

Offline davedes
« Reply #4 - Posted 2012-10-14 01:47:01 »

Try this instead:

1  
2  
3  
4  
5  
6  
batch.begin();
font.draw(batch, "blabla", 10, 10);
batch.end();

//Stage.draw will call begin and end on the given batch
stage.draw();


If you want to include text in the same batch as the rest of your stage sprites, use the Label UI.

Offline jhallenberg

Senior Newbie





« Reply #5 - Posted 2012-10-14 02:55:56 »

Thanks, davedes.
Another question I have:
Is it possible to change the text/font color without changing the file itself?
Offline Cero
« Reply #6 - Posted 2012-10-14 03:27:00 »

Well font.setColor(Color)
Since the png has white characters, you can filter it to any color, which is done internally, by using that call

Offline jhallenberg

Senior Newbie





« Reply #7 - Posted 2012-10-14 13:25:13 »

That doesn't seem to work. The characters in the font.png are all white, but they always display as black ingame.
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #8 - Posted 2012-10-14 13:41:56 »

don't you need batch.setColor?
Offline jhallenberg

Senior Newbie





« Reply #9 - Posted 2012-10-14 13:48:58 »

Tried changing the batch color to something else, no change.
Tried changing batch color to white and font color to something else and no change.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #10 - Posted 2012-10-14 14:51:01 »

no its font.setColor if you just want to change font color

there is something from with you font I guess.
What tool are you using to create them ?

You might wanna post your whole code and font files...

Offline jhallenberg

Senior Newbie





« Reply #11 - Posted 2012-10-14 19:38:36 »

I've tried fonts created with "Hiero" and "BMFont", both look/behave the same.
Offline Cero
« Reply #12 - Posted 2012-10-14 20:11:11 »

I've tried fonts created with "Hiero" and "BMFont", both look/behave the same.

Both should work.

Offline davedes
« Reply #13 - Posted 2012-10-14 20:16:43 »

This tool is better IMO:
http://twl.l33tlabs.org/themer/fonttool.jnlp

If your white fonts are not being recolored, I'm guessing you have something else in your code interfering (i.e. calls to glTexEnvi or a custom shader).

Try this test case:
http://www.java-gaming.org/?action=pastebin&id=282

Other than that, learn to debug... Wink

Offline Cero
« Reply #14 - Posted 2012-10-14 21:29:01 »


Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features.

Offline Vladiedoo
« Reply #15 - Posted 2012-10-14 21:39:14 »

This is really off-topic but jhallenberg you were using Slick2D a week or two ago, what made you switch over to LibGDX? The reason I'm asking is because I'm working on a Slick2D game but I've learned that LibGDX is a superior engine. I'm not sure if I should finish my game in Slick2D or switch over to LibGDX first, what did you experience with the two engines? Thanks in advance in you have time to reply.
Offline jhallenberg

Senior Newbie





« Reply #16 - Posted 2012-10-14 21:52:41 »

This is really off-topic but jhallenberg you were using Slick2D a week or two ago, what made you switch over to LibGDX? The reason I'm asking is because I'm working on a Slick2D game but I've learned that LibGDX is a superior engine. I'm not sure if I should finish my game in Slick2D or switch over to LibGDX first, what did you experience with the two engines? Thanks in advance in you have time to reply.
I switched due to libGDX having built in box2d mainly, I didn't get very far into using slick2d either so it wasn't a big deal.
Offline Vladiedoo
« Reply #17 - Posted 2012-10-14 21:57:15 »

Ah good to know, thanks.
Offline davedes
« Reply #18 - Posted 2012-10-14 22:07:56 »


Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features.
Why do you hate TWL?

Why would your hatred of TWL have anything to do with this incredibly useful tool that Matthias has made open source?

I am not a Windows user so BMFont is useless to me. Smiley

Offline jhallenberg

Senior Newbie





« Reply #19 - Posted 2012-10-14 22:46:00 »

I got the font coloring to work. It was a really dumb error made by me that I didn't see until now. I placed the new font files in the wrong folder so I kept using the same ones..  Emo
Offline Cero
« Reply #20 - Posted 2012-10-14 23:44:13 »


Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives.


Why would your hatred of TWL have anything to do with this incredibly useful tool that Matthias has made open source?

Well the gui is incredible confusing.
Even the file dialog which looks nothing like a native one, everyone is used to.
It doesnt have many features and for that it seems very complicated.
Also, I have to choose a ttf... Not a big deal, but I do have all the font installed, so being able to just browse my fonts in hiero is much nicer. And doesnt seem to support .otf files and such


@Slick to Libgdx switch
We recently refractored and recoded our whole big ass game from Slick to Libgdx.
Mainly for the particle system but of course there is lot of other goodies aswell: fast deployment on android if necessary, SpriteBatches, Cameras, natives are within jars, box2d and more

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #21 - Posted 2012-10-15 02:12:25 »


Well I hate TWL, so I would disagree. I think BMFont is the best, Hiero is very good but lacks features.

There are some notes about the different tools here:
https://code.google.com/p/libgdx/wiki/Hiero
IMO the BMFont tool is the best (even though I wrote Hiero :p).

Quote
Quote
Why do you hate TWL?

Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives.
That seems odd, TWL has an extremely clean codebase. It is quite complicated but it is a complicated problem, especially when trying to solve it in such a completely configurable/themeable manner. Other toolkits like scene2d have less code but are less powerful. As far as ease of use, I'd agree there that TWL is hard to just pick up and get running.

Offline Cero
« Reply #22 - Posted 2012-10-15 02:45:06 »

Quote
Quote
Why do you hate TWL?

Well I'm open minded to products using TWL - of course it can be good. But I thought the code was a horrible mess and hard to use compared with other alternatives.
That seems odd, TWL has an extremely clean codebase. It is quite complicated but it is a complicated problem, especially when trying to solve it in such a completely configurable/themeable manner. Other toolkits like scene2d have less code but are less powerful. As far as ease of use, I'd agree there that TWL is hard to just pick up and get running.


I know, I know, but like you said its hard to get in Nifty looked easier still not appealing.
I just wrote my own... If you dont need as much functionality, these libs are just overkill - and most games dont have many complex gui elements...
scene2d is quite new IIRC or at least you guys have remade it recently or something, so I haven't looked into it yet.

When I tried TWL I couldnt even get a button - well after hours of work.
I am very fond of "keeping things simple" - lets have all those complex interesting features optional, but a really simple easy to grasp codebase.
A simple button should be like 4 lines of code, similar to how AWT would do it:
- new button (size, label-String, color)
- call render method
- check for click event
- react to click event
Thats it.

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #23 - Posted 2012-10-15 06:11:36 »

scene2d is a few years old. It saw a lot of work a few months ago but was more evolutionary, not a rewrite. I consider scene2d to be very stable. It has a pretty large user base and I've personally developed multiple complex app UIs with it (eg).

It is as simple as you describe when using TWL, with the addition of having to first create a theme that defines how the button looks/acts, and that is where it is easy to get bogged down.

Offline Euregan

Junior Newbie





« Reply #24 - Posted 2012-12-12 15:54:54 »

Hello, I have the same problem as jhallenberg.
Whenever I draw some text, it appears as black, even though its color is white or anything I want with setColor() (I checked after changing with getColor()). I made the font with BMFont. Other than that the font works fine.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #25 - Posted 2012-12-12 16:06:20 »

Well, I had some similar problems in the beginning. Changing the export option preset to "Outlined text with alpha" fixed it for me. These are my settings.
Width/Height: 256
Bitdepth: 8bit
Chnl A: outline
Font Descriptor: Text
Textures: PNG
Compression: Deflate

- Jonas
Offline Euregan

Junior Newbie





« Reply #26 - Posted 2012-12-12 16:46:36 »

Actually, switching to GL10 has solved the problem, should have thought of that earlier really ...
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #27 - Posted 2012-12-12 16:54:21 »

Not a lasting solution, though, is it?

- Jonas
Offline Euregan

Junior Newbie





« Reply #28 - Posted 2012-12-12 17:26:41 »

I wish it wouldnt be, sadly the camera system only works with GL10, so I have no choice but to use it anyway
Offline cavemaneca

Junior Newbie


Medals: 1



« Reply #29 - Posted 2013-02-25 03:02:52 »

I know this is a bit of an old bump (so, sorry for the necro), but this is one of the first google results when trying to figure out this problem, and I have an answer.

Export the fnt file as 32bit if you're using gl2.0.
I'm guessing the newer GL version uses the built in channels when changing the color, or something. With 8bit, only the alpha channel can be changed, but with 32bit it can change the color.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!