use of org.lwjgl.opengl.GL in project FMT by Fexcraft.
the class FMT method run.
public void run() throws Exception {
Translator.init();
timer.init();
glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW.");
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(WIDTH, HEIGHT, getTitle(null), MemoryUtil.NULL, MemoryUtil.NULL);
if (window == MemoryUtil.NULL)
throw new RuntimeException("Failed to create window");
glfwMakeContextCurrent(window);
GL.createCapabilities();
log("GL Renderer: " + glGetString(GL_RENDERER));
log("GL Vendor: " + glGetString(GL_VENDOR));
log("GL Version: " + glGetString(GL_VERSION));
icon(window);
glfwShowWindow(window);
glfwFocusWindow(window);
//
CAM = new GGR(5, -5, -5, -Static.rad45, Static.rad30);
AxisRotator.setDefImpl(Axis3DL.class);
Settings.applyTheme();
FRAME = new Frame(WIDTH, HEIGHT);
FRAME.getContainer().add(TOOLBAR = new Toolbar());
EditorComponent.registerComponents();
Settings.loadEditors();
for (Editor editor : Editor.EDITORLIST) FRAME.getContainer().add(editor);
FRAME.getContainer().add(pos = new Label("test", 0, 32, 200, 20));
FRAME.getContainer().add(rot = new Label("test", 0, 54, 200, 20));
FRAME.getContainer().add(fps = new Label("test", 0, 76, 200, 20));
FRAME.getContainer().add(poly = new Label("test", 0, 98, 200, 20));
FRAME.getContainer().add(info = new Label("test", 0, 120, 200, 20));
FRAME.getContainer().add(bar = new Label("test", 0, 0, 500, 20));
FRAME.getComponentLayer().setFocusable(false);
CONTEXT = new Context(window);
//
IMG_FRAME = new Frame(WIDTH, HEIGHT);
IMG_FRAME.getContainer().add(img_line0 = new Label("", 20, 20, 500, 20));
img_line0.getStyle().getBackground().setColor(ColorConstants.transparent());
img_line0.getStyle().setFont(FontRegistry.ROBOTO_BOLD);
IMG_FRAME.getContainer().add(img_line1 = new Label("", 20, 40, 500, 20));
img_line1.getStyle().getBackground().setColor(ColorConstants.transparent());
img_line1.getStyle().setFont(FontRegistry.ROBOTO_BOLD);
//
CallbackKeeper keeper = new DefaultCallbackKeeper();
CallbackKeeper.registerCallbacks(window, keeper);
keeper.getChainKeyCallback().add(new GLFWKeyCallback() {
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
KeyCompound.process(window, key, scancode, action, mods);
}
});
keeper.getChainCursorPosCallback().add(new GLFWCursorPosCallback() {
@Override
public void invoke(long window, double xpos, double ypos) {
CAM.cursorPosCallback(window, xpos, ypos);
}
});
keeper.getChainMouseButtonCallback().add(new GLFWMouseButtonCallback() {
@Override
public void invoke(long window, int button, int action, int mods) {
CAM.mouseCallback(window, button, action, mods);
}
});
keeper.getChainWindowCloseCallback().add(new GLFWWindowCloseCallback() {
@Override
public void invoke(long window) {
//
}
});
keeper.getChainFramebufferSizeCallback().add(new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
HEIGHT = height;
TOOLBAR.setSize(WIDTH = width, TOOLBAR.getSize().y);
Editor.EDITORLIST.forEach(editor -> editor.align());
ToolbarMenu.MENUS.forEach((key, menu) -> menu.layer.hide());
Picker.resetBuffer(true);
}
});
keeper.getChainScrollCallback().add(new GLFWScrollCallback() {
@Override
public void invoke(long window, double xoffset, double yoffset) {
if (SELFIELD == null)
CAM.scrollCallback(window, xoffset, yoffset);
else
SELFIELD.scroll(yoffset);
}
});
SystemEventProcessor sys_event_processor = new SystemEventProcessorImpl();
SystemEventProcessor.addDefaultCallbacks(keeper, sys_event_processor);
RENDERER = new NvgRenderer();
RENDERER.initialize();
TextureManager.load();
// FMT.MODEL = new Model(new File("./saves/dodici.fmtb"), null).load();
FMT.MODEL = new Model(null, "Unnamed Model");
FMT.updateTitle();
// TODO load previous model
Settings.checkForUpdatesAndLogin();
KeyCompound.init();
//
LocalDateTime midnight = LocalDateTime.of(LocalDate.now(ZoneOffset.systemDefault()), LocalTime.MIDNIGHT);
long mid = midnight.toInstant(ZoneOffset.UTC).toEpochMilli();
long date = Time.getDate();
while ((mid += Time.MIN_MS * 5) < date) ;
if (BACKUP_TIMER == null && Settings.BACKUP_INTERVAL.value > 0) {
(BACKUP_TIMER = new Timer("BKUP")).schedule(new BackupHandler(), new Date(mid), Time.MIN_MS * Settings.BACKUP_INTERVAL.value);
}
//
if (Settings.DISCORD_RPC.value) {
DiscordEventHandlers.Builder handler = new DiscordEventHandlers.Builder();
handler.setReadyEventHandler(new DiscordUtil.ReadyEventHandler());
handler.setErroredEventHandler(new DiscordUtil.ErroredEventHandler());
handler.setDisconnectedEventHandler(new DiscordUtil.DisconectedEventHandler());
handler.setJoinGameEventHandler(new DiscordUtil.JoinGameEventHandler());
handler.setJoinRequestEventHandler(new DiscordUtil.JoinRequestEventHandler());
handler.setSpectateGameEventHandler(new DiscordUtil.SpectateGameEventHandler());
DiscordRPC.discordInitialize(CLID, handler.build(), true);
DiscordRPC.discordRunCallbacks();
DiscordUtil.update(true);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
DiscordRPC.discordShutdown();
}
});
DiscordUtil.DISCORD_THREAD = new Thread(() -> {
while (!CLOSE) {
DiscordRPC.discordRunCallbacks();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
DiscordUtil.DISCORD_THREAD.setName("DRPC");
DiscordUtil.DISCORD_THREAD.start();
}
//
vsync();
ShaderManager.loadPrograms();
ModelRendererTurbo.RENDERER = new MRTRenderer();
int vao = glGenVertexArrays();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
Picker.resetBuffer(true);
//
while (!glfwWindowShouldClose(window)) {
CAM.pollInput(accumulator += (delta = timer.getDelta()));
accumulator += (delta = timer.getDelta());
while (accumulator >= interval) {
// TODO "logic"
ToolbarMenu.checkHide();
timer.updateUPS();
accumulator -= interval;
// Trees.updateCounters();
fps.getTextState().setText(timer.getFPS() + "");
info.getTextState().setText(SELFIELD == null ? "none" : SELFIELD.polyval() == null ? SELFIELD.setting() == null ? "other" : "setting:" + SELFIELD.setting().id : SELFIELD.polyval().toString());
poly.getTextState().setText(MODEL.selected().isEmpty() ? "none" : MODEL.first_selected().name());
}
render(vao, alpha = accumulator / interval);
//
adjustLabels();
ImageHandler.updateText();
RENDERER.render(ImageHandler.shouldHide() ? IMG_FRAME : FRAME, CONTEXT);
timer.updateFPS();
glfwPollEvents();
glfwSwapBuffers(window);
sys_event_processor.processEvents(FRAME, CONTEXT);
EventProcessorProvider.getInstance().processEvents();
LayoutManager.getInstance().layout(FRAME);
AnimatorProvider.getAnimator().runAnimations();
ImageHandler.processTask();
timer.update();
}
DiscordRPC.discordShutdown();
RENDERER.destroy();
glfwDestroyWindow(window);
glfwTerminate();
Settings.save();
SessionHandler.save();
// TODO other saves
System.exit(EXIT_CODE);
}
Aggregations