Archived
Private
Public Access
1
0

Initial commit

This commit is contained in:
2022-09-04 12:45:01 +02:00
commit f4a01d6a69
11601 changed files with 4206660 additions and 0 deletions

8
Java/LWJGLEngine/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

13
Java/LWJGLEngine/.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="LWJGLEngine" />
</profile>
</annotationProcessing>
</component>
</project>

7
Java/LWJGLEngine/.idea/discord.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

14
Java/LWJGLEngine/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

124
Java/LWJGLEngine/.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

102
Java/LWJGLEngine/pom.xml Normal file
View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.craftix.lwjgl</groupId>
<artifactId>LWJGLEngine</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<lwjgl.version>3.2.3</lwjgl.version>
<joml.version>1.10.1</joml.version>
<lwjgl.natives>natives-windows</lwjgl.natives>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-bom</artifactId>
<version>${lwjgl.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-assimp</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-nfd</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-openal</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-assimp</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-nfd</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-openal</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,39 @@
package de.craftix.lwjgl.engine.jade;
import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.joml.Vector3f;
public class Camera {
private Matrix4f projectionMatrix, viewMatrix;
public Vector2f position;
public Camera(Vector2f position) {
this.position = position;
this.projectionMatrix = new Matrix4f();
this.viewMatrix = new Matrix4f();
adjustProjection();
}
public void adjustProjection() {
projectionMatrix.identity();
projectionMatrix.ortho(0.0f, 32.0f * 40.0f, 0.0f, 32.0f * 21.0f, 0.0f, 100.0f);
}
public Matrix4f getViewMatrix() {
Vector3f cameraFront = new Vector3f(0.0f, 0.0f, -1.0f);
Vector3f cameraUp = new Vector3f(0.0f, 1.0f, 0.0f);
this.viewMatrix.identity();
viewMatrix.lookAt(new Vector3f(position.x, position.y, 20.0f),
cameraFront.add(position.x, position.y, 0.0f),
cameraUp);
return this.viewMatrix;
}
public Matrix4f getProjectionMatrix() {
return this.projectionMatrix;
}
}

View File

@@ -0,0 +1,20 @@
package de.craftix.lwjgl.engine.jade;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
public class KeyListener {
private static final KeyListener instance = new KeyListener();
private boolean[] keyPressed = new boolean[350];
private KeyListener() {}
public static KeyListener get() { return instance; }
public static void keyCallback(long window, int key, int scanCode, int action, int mods) {
if (action == GLFW_PRESS) get().keyPressed[key] = true;
if (action == GLFW_RELEASE) get().keyPressed[key] = false;
}
public static boolean isKeyPressed(int keyCode) { return get().keyPressed[keyCode]; }
}

View File

@@ -0,0 +1,65 @@
package de.craftix.lwjgl.engine.jade;
import java.awt.*;
import java.util.Arrays;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
public class MouseListener {
private static final MouseListener instance = new MouseListener();
private double scrollX, scrollY, xPos, yPos, lastX, lastY;
private final boolean mouseButtonPressed[] = new boolean[MouseInfo.getNumberOfButtons()];
private boolean isDragging;
private MouseListener() {
this.scrollX = 0;
this.scrollY = 0;
this.xPos = 0;
this.yPos = 0;
this.lastX = 0;
this.lastY = 0;
this.isDragging = false;
}
public static MouseListener get() { return instance; }
public static void mousePosCallback(long window, double xPos, double yPos) {
get().lastX = get().xPos;
get().lastY = get().yPos;
get().xPos = xPos;
get().yPos = yPos;
for (boolean button : get().mouseButtonPressed) { if (button) { get().isDragging = true; break; } }
}
public static void mouseButtonCallback(long window, int button, int action, int mods) {
if (action == GLFW_PRESS) {
get().mouseButtonPressed[button] = true;
}
if (action == GLFW_RELEASE) {
get().mouseButtonPressed[button] = false;
get().isDragging = false;
}
}
public static void mouseScrollCallback(long window, double xOffset, double yOffset) {
get().scrollX = xOffset;
get().scrollY = yOffset;
}
public static void endFrame() {
get().scrollX = 0;
get().scrollY = 0;
get().lastX = get().xPos;
get().lastY = get().yPos;
}
public static float getX() { return (float)get().xPos; }
public static float getY() { return (float)get().yPos; }
public static float getDX() { return (float)(get().lastX - get().xPos); }
public static float getDY() { return (float)(get().lastY - get().yPos); }
public static float getScrollX() { return (float)get().scrollX; }
public static float getScrollY() { return (float)get().scrollY; }
public static boolean isDragging() { return get().isDragging; }
public static boolean mouseButtonDown(int button) { return get().mouseButtonPressed[button]; }
}

View File

@@ -0,0 +1,13 @@
package de.craftix.lwjgl.engine.jade;
public abstract class Scene {
protected Camera camera;
public Scene() {}
public abstract void update(float dt);
public void init() {}
}

View File

@@ -0,0 +1,94 @@
package de.craftix.lwjgl.engine.jade;
import org.lwjgl.Version;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;
public class Window {
private int width, height;
private String title;
private long glfwWindow;
private boolean running = false;
public float r = 1, g = 1, b = 1, a = 1;
private static Window window = null;
private static Scene currentScene;
private Window() {}
public static Window get() {
if (window == null)
window = new Window();
return window;
}
public void changeScene(Scene scene) { currentScene = scene; if (running) currentScene.init(); }
public void run(int width, int height, String title) {
this.width = width;
this.height = height;
this.title = title;
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
glfwFreeCallbacks(glfwWindow);
glfwDestroyWindow(glfwWindow);
glfwTerminate();
GLFWErrorCallback.createPrint(null).free();
}
private void init() {
GLFWErrorCallback.createPrint(System.err).set();
if (!glfwInit()) throw new IllegalStateException("Unable to Initialise GLFW!");
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE);
glfwWindow = glfwCreateWindow(width, height, title, NULL, NULL);
if (glfwWindow == NULL) throw new IllegalStateException("Failed to create GLFW Window!");
glfwSetCursorPosCallback(glfwWindow, MouseListener::mousePosCallback);
glfwSetMouseButtonCallback(glfwWindow, MouseListener::mouseButtonCallback);
glfwSetScrollCallback(glfwWindow, MouseListener::mouseScrollCallback);
glfwSetKeyCallback(glfwWindow, KeyListener::keyCallback);
glfwMakeContextCurrent(glfwWindow);
glfwSwapInterval(1);
glfwShowWindow(glfwWindow);
GL.createCapabilities();
if (currentScene != null) currentScene.init();
}
private void loop() {
float beginTime = (float)glfwGetTime();
float endTime;
float dt = -1.0f;
while (!glfwWindowShouldClose(glfwWindow)) {
glfwPollEvents();
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
if (dt >= 0 && currentScene != null) currentScene.update(dt);
glfwSwapBuffers(glfwWindow);
endTime = (float)glfwGetTime();
dt = endTime - beginTime;
beginTime = endTime;
}
}
}

View File

@@ -0,0 +1,152 @@
package de.craftix.lwjgl.engine.render;
import org.joml.*;
import org.lwjgl.BufferUtils;
import java.io.IOException;
import java.nio.FloatBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.lwjgl.opengl.GL11.GL_FALSE;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL20.glGetProgramInfoLog;
public class Shader {
private final String path;
private int shaderProgram;
private int vertexID, fragmentID;
private String vertexSource;
private String fragmentSource;
public Shader(String path) {
this.path = path;
try {
String source = new String(Files.readAllBytes(Path.of(Shader.class.getClassLoader().getResource(path).toURI())));
String[] splitString = source.split("(#type)( )+([a-zA-Z]+)");
int index = source.indexOf("#type") + 6;
int eol = source.indexOf("\r\n", index);
String firstPattern = source.substring(index, eol).trim();
index = source.indexOf("#type", eol) + 6;
eol = source.indexOf("\r\n", index);
String secondPattern = source.substring(index, eol).trim();
if (firstPattern.equalsIgnoreCase("vertex")) {
vertexSource = splitString[1];
}else if (firstPattern.equalsIgnoreCase("fragment")) {
fragmentSource = splitString[1];
} else throw new IOException("Unexpected token '" + firstPattern + "' in '" + path + "'");
if (secondPattern.equalsIgnoreCase("vertex")) {
vertexSource = splitString[2];
}else if (secondPattern.equalsIgnoreCase("fragment")) {
fragmentSource = splitString[2];
} else throw new IOException("Unexpected token '" + secondPattern + "' in '" + path + "'");
}catch (Exception e) {
e.printStackTrace();
assert false;
}
}
public void compile() {
vertexID = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexID, vertexSource);
glCompileShader(vertexID);
int success = glGetShaderi(vertexID, GL_COMPILE_STATUS);
if (success == GL_FALSE) {
int len = glGetShaderi(vertexID, GL_INFO_LOG_LENGTH);
System.err.println("ERROR: '" + path + "' \n\tVertex shader compilation failed.");
System.err.println(glGetShaderInfoLog(vertexID, len));
assert false;
}
fragmentID = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentID, fragmentSource);
glCompileShader(fragmentID);
success = glGetShaderi(fragmentID, GL_COMPILE_STATUS);
if (success == GL_FALSE) {
int len = glGetShaderi(fragmentID, GL_INFO_LOG_LENGTH);
System.err.println("ERROR: '" + path + "' \n\tFragment shader compilation failed.");
System.err.println(glGetShaderInfoLog(fragmentID, len));
assert false;
}
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexID);
glAttachShader(shaderProgram, fragmentID);
glLinkProgram(shaderProgram);
success = glGetProgrami(shaderProgram, GL_LINK_STATUS);
if (success == GL_FALSE) {
int len = glGetProgrami(shaderProgram, GL_INFO_LOG_LENGTH);
System.err.println("ERROR: '" + path + "' \n\tLinking shaders failed.");
System.err.println(glGetProgramInfoLog(shaderProgram, len));
assert false;
}
}
public void use() {
glUseProgram(shaderProgram);
}
public void detach() {
glUseProgram(0);
}
public void uploadMat4f(String varName, Matrix4f mat4) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
FloatBuffer matBuffer = BufferUtils.createFloatBuffer(16);
mat4.get(matBuffer);
glUniformMatrix4fv(varLocation, false, matBuffer);
}
public void uploadMat3f(String varName, Matrix3f mat3) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
FloatBuffer matBuffer = BufferUtils.createFloatBuffer(9);
mat3.get(matBuffer);
glUniformMatrix3fv(varLocation, false, matBuffer);
}
public void uploadVec4f(String varName, Vector4f vec) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform4f(varLocation, vec.x, vec.y, vec.z, vec.w);
}
public void uploadVec3f(String varName, Vector3f vec) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform3f(varLocation, vec.x, vec.y, vec.z);
}
public void uploadVec2f(String varName, Vector2f vec) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform2f(varLocation, vec.x, vec.y);
}
public void uploadFloat(String varName, float val) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform1f(varLocation, val);
}
public void uploadInt(String varName, int val) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform1i(varLocation, val);
}
public void uploadTexture(String varName, int slot) {
int varLocation = glGetUniformLocation(shaderProgram, varName);
use();
glUniform1i(varLocation, slot);
}
}

View File

@@ -0,0 +1,55 @@
package de.craftix.lwjgl.engine.render;
import org.lwjgl.BufferUtils;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Objects;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.stb.STBImage.stbi_image_free;
import static org.lwjgl.stb.STBImage.stbi_load;
public class Texture {
private String path;
private int texID;
public Texture(String path) {
try {
this.path = Objects.requireNonNull(Texture.class.getClassLoader().getResource(path)).toURI().toString().replace("file:/", "");
texID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
IntBuffer width = BufferUtils.createIntBuffer(1);
IntBuffer height = BufferUtils.createIntBuffer(1);
IntBuffer channels = BufferUtils.createIntBuffer(1);
ByteBuffer image = stbi_load(this.path, width, height, channels, 0);
if (image != null && channels.get(0) == 4)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.get(0), height.get(0), 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
else if (image != null && channels.get(0) == 3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width.get(0), height.get(0), 0, GL_RGB, GL_UNSIGNED_BYTE, image);
else throw new IllegalStateException("Could not load texture in OpenGL");
stbi_image_free(image);
} catch (URISyntaxException e) {
e.printStackTrace();
assert false;
}
}
public void bind() {
glBindTexture(GL_TEXTURE_2D, texID);
}
public void unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
}

View File

@@ -0,0 +1,14 @@
package de.craftix.test;
import de.craftix.lwjgl.engine.jade.Window;
import de.craftix.test.scenes.LevelEditorScene;
public class Main {
public static void main(String[] args) {
Window window = Window.get();
window.changeScene(new LevelEditorScene());
window.run(1280, 720, "GLFW Engine");
}
}

View File

@@ -0,0 +1,101 @@
package de.craftix.test.scenes;
import de.craftix.lwjgl.engine.jade.Camera;
import de.craftix.lwjgl.engine.jade.Scene;
import de.craftix.lwjgl.engine.render.Shader;
import de.craftix.lwjgl.engine.render.Texture;
import org.joml.Vector2f;
import org.lwjgl.BufferUtils;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
public class LevelEditorScene extends Scene {
private Shader defaultShader;
private Texture testTexture;
private float[] vertexArray = {
// position // color // UV Coordinates
100.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1, 1, // Bottom right 0
0.0f, 100.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0, 0, // Top left 1
100.0f, 100.0f, 0.0f , 1.0f, 0.0f, 1.0f, 1.0f, 1, 0, // Top right 2
0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0, 1, // Bottom left 3
};
private int[] elementArray = {
2, 1, 0,
0, 1, 3
};
private int vaoID, vboID, eboID;
public LevelEditorScene() {
}
@Override
public void init() {
this.camera = new Camera(new Vector2f(-500, -200));
defaultShader = new Shader("assets/shaders/default.glsl");
defaultShader.compile();
testTexture = new Texture("assets/textures/testImage.jpg");
//----------------------------------------
vaoID = glGenVertexArrays();
glBindVertexArray(vaoID);
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertexArray.length);
vertexBuffer.put(vertexArray).flip();
vboID = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STATIC_DRAW);
IntBuffer elementBuffer = BufferUtils.createIntBuffer(elementArray.length);
elementBuffer.put(elementArray).flip();
eboID = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementBuffer, GL_STATIC_DRAW);
int positionsSize = 3;
int colorSize = 4;
int uvSize = 2;
int vertexSizeInBytes = (positionsSize + colorSize + uvSize) * Float.BYTES;
glVertexAttribPointer(0, positionsSize, GL_FLOAT, false, vertexSizeInBytes, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, colorSize, GL_FLOAT, false, vertexSizeInBytes, positionsSize * Float.BYTES);
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, uvSize, GL_FLOAT, false, vertexSizeInBytes, (positionsSize + colorSize) * Float.BYTES);
glEnableVertexAttribArray(2);
}
@Override
public void update(float dt) {
defaultShader.use();
defaultShader.uploadTexture("TEX_SAMPLER", 0);
glActiveTexture(GL_TEXTURE0);
testTexture.bind();
defaultShader.uploadMat4f("uProjection", camera.getProjectionMatrix());
defaultShader.uploadMat4f("uView", camera.getViewMatrix());
glBindVertexArray(vaoID);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, elementArray.length, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
defaultShader.detach();
}
}

View File

@@ -0,0 +1,14 @@
package de.craftix.test.scenes;
import de.craftix.lwjgl.engine.jade.Scene;
public class LevelScene extends Scene {
public LevelScene() {}
@Override
public void update(float dt) {
}
}

View File

@@ -0,0 +1,33 @@
#type vertex
#version 330 core
layout (location=0) in vec3 aPos;
layout (location=1) in vec4 aColor;
layout (location=2) in vec2 aTexCoords;
uniform mat4 uProjection;
uniform mat4 uView;
out vec4 fColor;
out vec2 fTexCoords;
void main()
{
fColor = aColor;
fTexCoords = aTexCoords;
gl_Position = uProjection * uView * vec4(aPos, 1.0);
}
#type fragment
#version 330 core
uniform sampler2D TEX_SAMPLER;
in vec4 fColor;
in vec2 fTexCoords;
out vec4 color;
void main()
{
color = texture(TEX_SAMPLER, fTexCoords);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

View File

@@ -0,0 +1,33 @@
#type vertex
#version 330 core
layout (location=0) in vec3 aPos;
layout (location=1) in vec4 aColor;
layout (location=2) in vec2 aTexCoords;
uniform mat4 uProjection;
uniform mat4 uView;
out vec4 fColor;
out vec2 fTexCoords;
void main()
{
fColor = aColor;
fTexCoords = aTexCoords;
gl_Position = uProjection * uView * vec4(aPos, 1.0);
}
#type fragment
#version 330 core
uniform sampler2D TEX_SAMPLER;
in vec4 fColor;
in vec2 fTexCoords;
out vec4 color;
void main()
{
color = texture(TEX_SAMPLER, fTexCoords);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B