Implement RenderManager & Fix escape key callback.
This commit is contained in:
parent
9b1864191d
commit
71284a9dae
6 changed files with 120 additions and 5 deletions
|
@ -15,11 +15,15 @@ public class EngineManager {
|
|||
|
||||
private WindowManager window;
|
||||
private GLFWErrorCallback errorCallback;
|
||||
private ILogic gameLogic;
|
||||
|
||||
private void init() throws Exception {
|
||||
GLFW.glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
|
||||
window = Launcher.getWindow();
|
||||
gameLogic = Launcher.getGame();
|
||||
|
||||
window.init();
|
||||
gameLogic.init();
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
|
@ -84,19 +88,22 @@ public class EngineManager {
|
|||
}
|
||||
|
||||
private void input() {
|
||||
|
||||
gameLogic.input();
|
||||
}
|
||||
|
||||
private void render() {
|
||||
gameLogic.render();
|
||||
window.update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
|
||||
gameLogic.update();
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
window.cleanup();
|
||||
gameLogic.cleanup();
|
||||
|
||||
errorCallback.free();
|
||||
|
||||
GLFW.glfwTerminate();
|
||||
|
|
13
src/main/java/com/okseby/core/ILogic.java
Normal file
13
src/main/java/com/okseby/core/ILogic.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package com.okseby.core;
|
||||
|
||||
public interface ILogic {
|
||||
void init() throws Exception;
|
||||
|
||||
void input();
|
||||
|
||||
void update();
|
||||
|
||||
void render();
|
||||
|
||||
void cleanup();
|
||||
}
|
|
@ -1,18 +1,21 @@
|
|||
package com.okseby.core;
|
||||
|
||||
import com.okseby.core.test.TestGame;
|
||||
import com.okseby.core.utils.Constants;
|
||||
import org.lwjgl.Version;
|
||||
|
||||
public class Launcher {
|
||||
|
||||
private static WindowManager window;
|
||||
private static EngineManager engine;
|
||||
private static TestGame game;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("LWJGL Version: " + Version.getVersion());
|
||||
|
||||
window = new WindowManager(Constants.title, 1600, 900, false);
|
||||
engine = new EngineManager();
|
||||
game = new TestGame();
|
||||
|
||||
EngineManager engine = new EngineManager();
|
||||
|
||||
try {
|
||||
engine.start();
|
||||
|
@ -24,4 +27,8 @@ public class Launcher {
|
|||
public static WindowManager getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public static TestGame getGame() {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
|
27
src/main/java/com/okseby/core/RenderManager.java
Normal file
27
src/main/java/com/okseby/core/RenderManager.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package com.okseby.core;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class RenderManager {
|
||||
private final WindowManager window;
|
||||
|
||||
public RenderManager() {
|
||||
window = Launcher.getWindow();
|
||||
}
|
||||
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
||||
}
|
||||
}
|
|
@ -65,7 +65,7 @@ public class WindowManager {
|
|||
});
|
||||
|
||||
GLFW.glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE || action == GLFW.GLFW_RELEASE)
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE && action == GLFW.GLFW_RELEASE)
|
||||
GLFW.glfwSetWindowShouldClose(window, true);
|
||||
});
|
||||
|
||||
|
|
61
src/main/java/com/okseby/core/test/TestGame.java
Normal file
61
src/main/java/com/okseby/core/test/TestGame.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package com.okseby.core.test;
|
||||
|
||||
import com.okseby.core.ILogic;
|
||||
import com.okseby.core.Launcher;
|
||||
import com.okseby.core.RenderManager;
|
||||
import com.okseby.core.WindowManager;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class TestGame implements ILogic {
|
||||
private int direction = 0;
|
||||
private float color = 0.0f;
|
||||
|
||||
private final RenderManager renderer;
|
||||
private final WindowManager window;
|
||||
|
||||
public TestGame() {
|
||||
renderer = new RenderManager();
|
||||
window = Launcher.getWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
renderer.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void input() {
|
||||
if (window.isKeyPressed(GLFW.GLFW_KEY_UP))
|
||||
direction = 1;
|
||||
else if (window.isKeyPressed(GLFW.GLFW_KEY_DOWN))
|
||||
direction = -1;
|
||||
else
|
||||
direction = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
color += direction * 0.01f;
|
||||
if (color > 1)
|
||||
color = 1.0f;
|
||||
else if (color <= 0)
|
||||
color = 0.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (window.isResizeable()) {
|
||||
GL11.glViewport(0, 0, window.getWidth(), window.getHeight());
|
||||
window.setResizeable(true);
|
||||
}
|
||||
|
||||
window.setClearColor(color, color, color, 0.0f);
|
||||
renderer.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
renderer.cleanup();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue