TransWikia.com

NiftyGUI - Text isn't rendering

Game Development Asked by Ben Steffan on November 2, 2021

I am trying to create a gui with nifty on top of lwjgl. I’ve already had some problems during the Nifty setup, however now Nifty is set up and running correctly but for text rendering.
Here is my xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.4.xsd" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://niftygui.
sourceforge.net/nifty-1.4.xsd http://nifty-gui.sourceforge.net/nifty-1.4.xsd">
    <screen id="start">
        <layer childLayout="center">
            <panel id="panel" height="25%" width="35%" align="center" valign="center" backgroundColor="#f60f" childLayout="center" visibleToMouse="true">
                <text id="text" font="aurulent-sans-16.fnt" color="#ffff" text="Hello World!"/>
            </panel>
        </layer>
    </screen>
</nifty>

and here the respective java class:

package niftylwjgl;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.nulldevice.NullSoundDevice;
import de.lessvoid.nifty.renderer.lwjgl.input.LwjglInputSystem;
import de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderDevice;
import de.lessvoid.nifty.tools.TimeProvider;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

public class NiftyLwjgl {

    private static Nifty nifty;
    private static boolean close;
    private static LwjglInputSystem inSys;

    public static void main(String[] args) throws LWJGLException, Exception {
        init();
        initNifty();
        while (!close) {
            update();
            preRender();
            render();
            postRender();
        }
        destroy();
    }

    private static void init() throws LWJGLException {
        Display.setDisplayMode(Display.getDesktopDisplayMode());
        Display.setFullscreen(true);
        Display.create();

        GL11.glOrtho(0, 1920, 0, 1080, 1, -1);
    }

    private static void initNifty() throws Exception {
        inSys = new LwjglInputSystem();
        inSys.startup();

        nifty = new Nifty(new LwjglRenderDevice(),
                new NullSoundDevice(),
                inSys,
                new TimeProvider());
        nifty.fromXml("xml/main.xml", "start");
        nifty.loadStyleFile("nifty-default-styles.xml");
        nifty.loadControlFile("nifty-default-controls.xml");
    }

    private static void preRender() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();

        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    private static void postRender() {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
    }

    private static void update() {
        if (Display.isCloseRequested()
                || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)
                || nifty.update()) {
            close = true;
        }
    }

    private static void render() {
        nifty.render(false);
        Display.update();
    }

    private static void destroy() {
        inSys.shutdown();
        Display.destroy();
    }
}

Here is a screenshot of the application running:
enter image description here
I somehow feel like I’m missing something incredible simple but important, like an glXXXXX call.
Any help/suggestions are appreciated.

One Answer

You're not setting the projection matrix correctly. At the time you call glOrtho() you probably want to have the GL_PROJECTION matrix mode enabled.

Something like that


// set projection matrix
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 1920, 1080, 0, 1, -1);

// set modelview matrix to identity
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();

Also note that Nifty assumes the coordinates (0,0) at the top left corner. That's why the third and fourth parameter should be switched.

Answered by void256 on November 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP