[API] Fixed window rendering on resize and white background on start up. (#62)
* Fixed window rendering on resize and white background on start up. * Code formatting and clean up. * Fixed attribute modifier.
This commit is contained in:
1 parent
cbdf36f09e
commit
34e282e091
1 file changed
+44
-9
@@ -8,6 +8,7 @@ import org.lwjgl.glfw.Callbacks;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.glfw.GLFWWindowSizeCallback;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
@@ -22,6 +23,7 @@ import java.util.Objects;
|
||||
* When extended, life-cycle methods should be called manually.
|
||||
*/
|
||||
public abstract class Window {
|
||||
|
||||
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
|
||||
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
|
||||
|
||||
@@ -90,14 +92,26 @@ public abstract class Window {
|
||||
}
|
||||
|
||||
GLFW.glfwMakeContextCurrent(handle);
|
||||
|
||||
GL.createCapabilities();
|
||||
|
||||
GLFW.glfwSwapInterval(GLFW.GLFW_TRUE);
|
||||
GLFW.glfwShowWindow(handle);
|
||||
|
||||
if (config.isFullScreen()) {
|
||||
GLFW.glfwMaximizeWindow(handle);
|
||||
} else {
|
||||
GLFW.glfwShowWindow(handle);
|
||||
}
|
||||
|
||||
GL.createCapabilities();
|
||||
clearBuffer();
|
||||
renderBuffer();
|
||||
|
||||
GLFW.glfwSetWindowSizeCallback(handle, new GLFWWindowSizeCallback() {
|
||||
@Override
|
||||
public void invoke(final long window, final int width, final int height) {
|
||||
runFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void decideGlGlslVersions() {
|
||||
@@ -141,26 +155,40 @@ public abstract class Window {
|
||||
*/
|
||||
protected void run() {
|
||||
while (!GLFW.glfwWindowShouldClose(handle)) {
|
||||
startFrame();
|
||||
preProcess();
|
||||
process();
|
||||
postProcess();
|
||||
endFrame();
|
||||
runFrame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to run the next frame.
|
||||
*/
|
||||
protected void runFrame() {
|
||||
startFrame();
|
||||
preProcess();
|
||||
process();
|
||||
postProcess();
|
||||
endFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be overridden by user to provide main application logic.
|
||||
*/
|
||||
public abstract void process();
|
||||
|
||||
/**
|
||||
* Method used to clear the OpenGL buffer.
|
||||
*/
|
||||
private void clearBuffer() {
|
||||
GL32.glClearColor(colorBg.getRed(), colorBg.getGreen(), colorBg.getBlue(), colorBg.getAlpha());
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called at the beginning of the main cycle.
|
||||
* It clears OpenGL buffer and starts an ImGui frame.
|
||||
*/
|
||||
protected void startFrame() {
|
||||
GL32.glClearColor(colorBg.getRed(), colorBg.getGreen(), colorBg.getBlue(), colorBg.getAlpha());
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
clearBuffer();
|
||||
imGuiGlfw.newFrame();
|
||||
ImGui.newFrame();
|
||||
}
|
||||
@@ -180,6 +208,13 @@ public abstract class Window {
|
||||
GLFW.glfwMakeContextCurrent(backupWindowPtr);
|
||||
}
|
||||
|
||||
renderBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to render the OpenGL buffer and poll window events.
|
||||
*/
|
||||
private void renderBuffer() {
|
||||
GLFW.glfwSwapBuffers(handle);
|
||||
GLFW.glfwPollEvents();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user