Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:54:50+00:00 2026-06-14T11:54:50+00:00

I’ve been trying to add some basic gui elements to a openGl (via LWJGL)

  • 0

I’ve been trying to add some basic gui elements to a openGl (via LWJGL) application using nifty gui, and while I’ve been successful in rendering panels and static text on top of the the applications graphics, using the built-in nifty controls (e.g. an editable text field) causes the rest of the application to not render. The strange part is that I don’t even have to render the gui control, merely declaring it appears to cause this problem.

Compiler ready code showing the basic layout of the problem:

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.controls.textfield.builder.TextFieldBuilder;
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.screen.Screen;
import de.lessvoid.nifty.tools.TimeProvider;

public class NiftyBreaksRendering {
    private Nifty nifty;
    private Screen screen;
    public NiftyBreaksRendering() throws Exception{
            //init display
            Display.setDisplayMode(new DisplayMode(640,480));
            Display.create();

            //init nifty gui
              LwjglInputSystem inputSystem = new LwjglInputSystem();
              inputSystem.startup();
              nifty = new Nifty(
                new LwjglRenderDevice(),
              new NullSoundDevice(),
                inputSystem,
              new TimeProvider());
            // load default styles
            nifty.loadStyleFile("nifty-default-styles.xml");
            // load standard controls
            nifty.loadControlFile("nifty-default-controls.xml");
            screen = new ScreenBuilder("start") {{
                  layer(new LayerBuilder("baseLayer") {{
                    childLayoutHorizontal();
                    text(new TextBuilder("test"){{
                        font("aurulent-sans-16.fnt");
                        color("#f00f");
                        backgroundColor("#33af");
                        text("l33t");
                    }});

                    //begin: lines that break the rendering
                    control(new TextFieldBuilder("input","asdf") {{
                        width("200px");
                    }});
                    //end: lines that break the rendering
                  }});
                }}.build(nifty);
                nifty.gotoScreen("start");

        //init opengl
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,640,480,0,1,-1);
        glMatrixMode(GL_MODELVIEW);

        while(!Display.isCloseRequested())
        {
            //render

            glClear(GL_COLOR_BUFFER_BIT);

            glBegin(GL_QUADS);
                glVertex2i(400,400); //Upper left
                glVertex2i(450,400);//upper right
                glVertex2i(450,450);//bottom right
                glVertex2i(400,450);//bottom left
            glEnd();

            glBegin(GL_LINES);
                glVertex2i(100,100);
                glVertex2i(200,200);
            glEnd();

            nifty.render(false);
            Display.update();
            Display.sync(60);
        }
        Display.destroy();
    }

    public static void main(String[] args) throws Exception {
        new NiftyBreaksRendering();

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:54:51+00:00Added an answer on June 14, 2026 at 11:54 am

    What would really help to diagnose this kind of problems is a link to a http://sscce.org/

    I guess this is related to OpenGL states changed by Nifty OR to textures being loaded by the Nifty controls which might mess up the rest of your application.

    If you could provide more or the complete code I’m pretty sure we can find the problem.

    Modified answer after complete example code was provided:

    Thanks for providing a complete example!

    As expected the problem is, that Nifty changes OpenGL state and leaves you with OpenGL basically in undefined state. The solution is to save your OpenGL states before you call Nifty and restore it afterwards. Here is some code that does exactly that. I’ve added the call to nifty.update() as well so that Nifty actually updates the GUI (and makes keyboard and mouse events work):

            // update nifty
            nifty.update();
    
            // save your OpenGL state
            // (assuming you are in glMatrixMode(GL_MODELVIEW) all the time)
            glPushMatrix();
            glPushAttrib(GL_ALL_ATTRIB_BITS);
    
            // render Nifty (this will change OpenGL state)
            nifty.render(false);
    
            // restore your OpenGL state
            glPopAttrib();
            glPopMatrix();
    

    With this change to your original code your example works for me now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.