1
\$\begingroup\$

I've been trying to draw a text to the display using Slick. However, when ever I draw the TrueTypeFont to the screen, it draws it reversed upside down and also, it makes the whole display turn black.

This is only a piece of the entire game code, I think this is enough to explain the problem though. I'm new to LWJGL and Slick so this is probably a stupid question.

public Game(String name, int width, int height)
{
    this.name = name;
    this.width = width;
    this.height = height;


    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.setTitle(name + " " + version);
        Display.setResizable(true);

        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();

        Display.destroy();
        return;
    }

    TrueTypeFont font;
    Font awtFont = new Font("Arial", Font.PLAIN, 24);
    font = new TrueTypeFont(awtFont, false);

    Player player = new Player(this, 32, 32);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    while(!Display.isCloseRequested())
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, width, 0, height, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        drawBackground();

        player.update();
        player.draw();
        font.drawString(50, 50, "Platform");

        Display.update();
        Display.sync(60);
    }

    Display.destroy();
}

enter image description here

Edit: After doing what @Katu said, I changed glOrtho(0, width, 0, height, -1, 1); to glOrtho(0, width, height, 0, -1, 1);. The text is not reversed upside down, but the black screen is still there.

enter image description here

The screen should look something like this. (NOTE: It's an edited image)

\$\endgroup\$
1
\$\begingroup\$

Change

glOrtho(0, width, 0, height, -1, 1);

To this:

glOrtho(0, width, height, 0, -1, 1);

A quick little understanding about why your font wasn't working (if you don't already know), glOrtho is called like this:

glOrtho(double left, double right, double bottom, double top, double zNear, double zFar).

This being said, you had the bottom set to 0 where it should have been set to the display's height or a custom bottom if necessary and that is the reason why the text was facing the top of the screen or rather, being drawn up-side down.

I collected this answer from these:

\$\endgroup\$
  • \$\begingroup\$ Thanks, that solved the main problem. Now it's showing a black screen with a text saying "Platform" when it's suppose to draw the player, the background, and the text. Here's a screenshot. \$\endgroup\$ – Vicente Bermúdez May 27 '15 at 16:03
  • \$\begingroup\$ @VicenteBermúdez Test if this helps -> glEnable(GL_TEXTURE_2D); ( Add it to near glEnable(GL_BLEND); ) \$\endgroup\$ – Katu May 27 '15 at 16:15
  • \$\begingroup\$ I tried that and it's still remains the same. It should look something like this \$\endgroup\$ – Vicente Bermúdez May 27 '15 at 16:22
  • \$\begingroup\$ @VicenteBermúdez Then try glBindTexture (GL_TEXTURE_2D,0) If this wont work, I'm out of bullets \$\endgroup\$ – Katu May 27 '15 at 18:20
  • \$\begingroup\$ That makes it draw a white rectangle instead of a text. The background and player is working now but the text isn't. Thanks though :) \$\endgroup\$ – Vicente Bermúdez May 27 '15 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.