我一直在尝试使用漂亮的 gui 向 openGl(通过 LWJGL)应用程序添加一些基本的 gui 元素,虽然我已经成功地在应用程序图形之上渲染面板和静态文本,但使用内置的漂亮控件(例如可编辑的文本字段)导致应用程序的其余部分不呈现。奇怪的是,我什至不必渲染 gui 控件,只需声明它似乎会导致此问题。
显示问题基本布局的编译器就绪代码:
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();
}
}