Entityとその子オブジェクトを追加。
Textureクラス、Meshコンポーネントを作成し、画像を表示できるように。
また、画像がGameObjectのtransform.positionに表示されるように。
1 parent ba4f6fa commit 34acd4e6e441e4f0dba06062160c6f87a148b3a1
NoranekoFelician authored on 1 Oct
Showing 20 changed files
View
GameEngine/resources/test.png 0 → 100644
View
2
■■■
GameEngine/src/main/java/Main.java
import gameEngine.*;
import gameEngine.views.Window;
 
public class Main {
public static void main(String[] args) {
Window window = Window.get();
View
156
GameEngine/src/main/java/gameEngine/Window.java 100644 → 0
package gameEngine;
import gameEngine.gameComponent.ColorController;
import gameEngine.gameComponent.GameComponent;
import gameEngine.input.*;
import gameEngine.scene.*;
 
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
 
import java.nio.*;
import java.util.ArrayList;
import java.util.List;
 
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
 
public class Window {
private static Window window;
private static Scene currentScene;
private int width;
private int height;
private String title;
private long glfwWindow;
public float r,g,b,a;
private final List<GameComponent> gameComponents = new ArrayList<>();
 
private Window() {
this.width = 1200;
this.height = 900;
this.title = "HelloWorld";
r = 1;
g = 1;
b = 1;
a = 0;
}
 
public static void changeScene(int newScene){
switch (newScene){
case 0:
currentScene = new EditorScene();
break;
case 1:
currentScene = new GameScene();
break;
default:
assert false : "Unknown Scene [" + newScene + "]";
break;
}
}
 
public static Window get() {
if (window == null) {
window = new Window();
}
 
return window;
}
 
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
glfwFreeCallbacks(glfwWindow);
glfwDestroyWindow(glfwWindow);
glfwTerminate();
glfwSetErrorCallback(null).free();
}
 
private void init() {
GLFWErrorCallback.createPrint(System.err).set();
if ( !glfwInit() ) {
throw new IllegalStateException("Unable to initialize GLFW");
}
 
//Configure GLFW
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE);
 
glfwWindow = glfwCreateWindow(this.width, this.height, this.title, NULL, NULL);
if ( glfwWindow == NULL ) {
throw new RuntimeException("Failed to create the GLFW window");
}
 
glfwSetCursorPosCallback(glfwWindow, MouseInput::mousePosCallback);
glfwSetMouseButtonCallback(glfwWindow, MouseInput::mouseButtonCallback);
glfwSetScrollCallback(glfwWindow, MouseInput::mouseScrollCallBack);
glfwSetKeyCallback(glfwWindow, KeyInput::keyCallback);
 
// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
 
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(glfwWindow, pWidth, pHeight);
 
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
 
// Center the window
glfwSetWindowPos(
glfwWindow,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
}
 
glfwMakeContextCurrent(glfwWindow);
glfwSwapInterval(1);
glfwShowWindow(glfwWindow);
 
gameComponents.add(new ColorController());
for (GameComponent gameComponent : gameComponents) {
gameComponent.init();
}
GL.createCapabilities();
 
Window.changeScene(0);
}
 
private void loop() {
double beginTime = Time.getTime();
double endTime;
double dt = -1.0f;
 
while (!glfwWindowShouldClose(glfwWindow)) {
 
glfwPollEvents(); // ウィンドウイベントをポーリング
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // フレームバッファをクリア
 
for (GameComponent gameComponents : gameComponents) {
gameComponents.update();
}
 
if(dt >= 0){
currentScene.update((float)dt);
}
 
glfwSwapBuffers(glfwWindow); // カラーバッファを交換
 
endTime = Time.getTime();
dt = endTime - beginTime;
beginTime = endTime;
}
 
}
 
}
View
GameEngine/src/main/java/gameEngine/entites/Camera.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/Entity.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/GameObject.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/gameComponents/ColorController.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/gameComponents/GameComponent.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/gameComponents/Mesh.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/entites/gameComponents/Texture.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/gameComponent/ColorController.java 100644 → 0
View
GameEngine/src/main/java/gameEngine/gameComponent/GameComponent.java 100644 → 0
View
GameEngine/src/main/java/gameEngine/geometry/Transform.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/scene/EditorScene.java 100644 → 0
View
GameEngine/src/main/java/gameEngine/scene/GameScene.java 100644 → 0
View
GameEngine/src/main/java/gameEngine/scene/Scene.java 100644 → 0
View
GameEngine/src/main/java/gameEngine/scenes/EditorScene.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/scenes/GameScene.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/scenes/Scene.java 0 → 100644
View
GameEngine/src/main/java/gameEngine/views/Window.java 0 → 100644