2

I am building a game in Java using some openGL libraries. I have almost finished the application but i have some really ridiculous problem. All I need to to is to change the default color of the text to some other color, in my case its black.

Exactly more than an hour i was trying to make this and every time i start a game the whole window turns into that color... I put the code down there and if any of you have some ideas I would like to consider that.

import java.awt.Font;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import player.Player;


public class GameMenu {

    private TrueTypeFont gameFont;
    private Font font;

    public GameMenu() {

    font = new Font("Times New Roman", Font.BOLD, 24);
    gameFont = new TrueTypeFont(font, false);

 }

    public void drawChangableText(int x, int y, String changableText) {
    gameFont.drawString(x, y, changableText, Color.black);
 }

    public void update() {
    drawChangableText(1330, 700, "Lives " + Player.lives);
    drawChangableText(1330, 750, "Gold " + Player.gold);
 }
}

And then I am calling this update method further somewhere. Let me not forget to mention that if omit 4. parameter of drawString() method, everything works perfectly fine but with white text on the screen.

Once again, if someone could help i would appreciate that. Maybe some of you will mark my question as duplicated but technically its not, someone had the similar problem but in his case he just imported wrong package. Here is the link of the similar problem

LWJGL Drawing colored text to the screen issue

Milos
  • 394
  • 2
  • 19
  • Does it also happen with some other colors, different from black? – Ripi2 Jun 07 '18 at 16:22
  • I didn't try but I guess so. Now I am at work, within 2 hours I will tell you the results. – Milos Jun 07 '18 at 16:34
  • Oh i check the other colors, everything is covered with the green color, but i see the movements and other actions in the game but everything is covered with that color so can you help me somehow? @Ripi2 – Milos Jun 07 '18 at 18:53
  • Seems to me a bug. Better ask in [Slick Forum](http://slick.ninjacave.com/forum/) – Ripi2 Jun 07 '18 at 19:04
  • What can i say else, i will try. But i had the similar problem earlier, the thing was kinda the same instead of the screen wasn't colored with the color, it was colored with the texture, but i had few textures not just one. So i fixed that using the texture.bind(); ! – Milos Jun 07 '18 at 19:19

1 Answers1

2

You are drawing frames with current color, in this case you're using Color.black for everything in your frame not just the text.

So to avoid something like that you can do this:

public void drawChangableText(int x, int y, String text) {
    //pick your color
    Color.black.bind();
    //do the job
    gameFont.drawString(x, y, text, Color.black);
    //reset the color
    Color.white.bind();
}