Skip to content

Commit a5408cd

Browse files
committed
first commit
0 parents  commit a5408cd

29 files changed

+1436
-0
lines changed

.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>LWJGL Test 2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.release=disabled
12+
org.eclipse.jdt.core.compiler.source=1.8
Binary file not shown.
1.52 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#version 400 core
2+
3+
in vec3 color;
4+
5+
out vec4 out_Color;
6+
7+
void main(void){
8+
out_Color = vec4(color.xyz, 1.0f);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#version 400 core
2+
3+
in vec3 position;
4+
5+
out vec3 color;
6+
7+
void main(void){
8+
gl_Position = vec4(position.xyz, 1.0f);
9+
color = vec3(1.0f, 0.0f, 1.0f);
10+
}
Binary file not shown.
Binary file not shown.
751 Bytes
Binary file not shown.

hs_err_pid18504.log

+303
Large diffs are not rendered by default.

hs_err_pid3160.log

+303
Large diffs are not rendered by default.

hs_err_pid6072.log

+303
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.finnthehumanlol.lwjgl.engine;
2+
3+
import org.lwjgl.glfw.GLFW;
4+
5+
import me.finnthehumanlol.lwjgl.engine.core.MainGameLoop;
6+
import me.finnthehumanlol.lwjgl.engine.io.Window;
7+
8+
public final class Engine {
9+
10+
public static MainGameLoop mainGameLoop;
11+
private static Window window;
12+
13+
public static Thread mainThread = new Thread(new Runnable() {
14+
15+
@Override
16+
public void run() {
17+
mainGameLoop.start();
18+
while(!GLFW.glfwWindowShouldClose(window.getWindow())) {
19+
mainGameLoop.update();
20+
window.onRender();
21+
mainGameLoop.render();
22+
GLFW.glfwSwapBuffers(window.getWindow());
23+
}
24+
mainGameLoop.stop();
25+
}
26+
}, "main");
27+
28+
public static void start(MainGameLoop mainGameLoop) {
29+
Engine.mainGameLoop = mainGameLoop;
30+
mainThread.run();
31+
}
32+
33+
public static void createWindow(int width, int height, String title) {
34+
window = new Window(width, height, title);
35+
}
36+
37+
public static MainGameLoop getMainGameLoop() {
38+
return mainGameLoop;
39+
}
40+
41+
public static Window getWindow() {
42+
return window;
43+
}
44+
45+
public static Thread getMainThread() {
46+
return mainThread;
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.finnthehumanlol.lwjgl.engine.core;
2+
3+
public interface MainGameLoop {
4+
5+
public void start();
6+
public void update();
7+
public void render();
8+
public void stop();
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.finnthehumanlol.lwjgl.engine.core;
2+
3+
public interface Updateable {
4+
5+
public void onUpdate();
6+
public void onRender();
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package me.finnthehumanlol.lwjgl.engine.io;
2+
3+
import org.lwjgl.glfw.GLFW;
4+
import org.lwjgl.glfw.GLFWVidMode;
5+
import org.lwjgl.opengl.GL;
6+
import org.lwjgl.opengl.GL11;
7+
8+
import me.finnthehumanlol.lwjgl.engine.core.Updateable;
9+
10+
public class Window implements Updateable{
11+
12+
private int width, height;
13+
private String title;
14+
private long window;
15+
private GLFWVidMode vidMode;
16+
17+
public Window(int width, int height, String title) {
18+
this.width = width;
19+
this.height = height;
20+
this.title = title;
21+
22+
if(!GLFW.glfwInit()) {
23+
System.err.println("GLFW couldnt be initialised");
24+
System.exit(-1);
25+
}
26+
27+
window = GLFW.glfwCreateWindow(width, height, title, 0, 0);
28+
29+
if(window == 0) {
30+
System.err.println("Window coult be created");
31+
System.exit(-1);
32+
}
33+
34+
vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
35+
GLFW.glfwSetWindowPos(window, (vidMode.width() - width)/ 2, (vidMode.height() - height) / 2 );
36+
37+
GLFW.glfwMakeContextCurrent(window);
38+
GL.createCapabilities();
39+
40+
GLFW.glfwShowWindow(window);
41+
42+
}
43+
44+
@Override
45+
public void onUpdate() {
46+
47+
}
48+
49+
@Override
50+
public void onRender() {
51+
GLFW.glfwPollEvents();
52+
53+
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
54+
GL11.glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
55+
}
56+
57+
public int getWidth() {
58+
return width;
59+
}
60+
61+
public int getHeight() {
62+
return height;
63+
}
64+
65+
public String getTitle() {
66+
return title;
67+
}
68+
69+
public long getWindow() {
70+
return window;
71+
}
72+
73+
public GLFWVidMode getVidMode() {
74+
return vidMode;
75+
}
76+
77+
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.finnthehumanlol.lwjgl.engine.render;
2+
3+
import org.lwjgl.opengl.GL11;
4+
5+
import me.finnthehumanlol.lwjgl.engine.types.Mesh;
6+
7+
public class Renderer {
8+
9+
public static void render(Mesh mesh) {
10+
mesh.prepareRender();
11+
if(mesh.getIbo() == 0)
12+
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, mesh.getVertexCount());
13+
else {
14+
GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
15+
}
16+
mesh.finishRender();
17+
}
18+
19+
private Renderer() {}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package me.finnthehumanlol.lwjgl.engine.render;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
8+
import org.lwjgl.opengl.GL20;
9+
10+
public class Shader {
11+
12+
private String vertexPath, fragmentPath;
13+
14+
private int program, vertexShader, fragmentShader;
15+
16+
public Shader(String vertexPath, String fragmentPath) {
17+
program = GL20.glCreateProgram();
18+
this.vertexPath = vertexPath;
19+
this.fragmentPath = fragmentPath;
20+
21+
vertexShader = addShader(GL20.GL_VERTEX_SHADER, vertexPath);
22+
fragmentShader = addShader(GL20.GL_FRAGMENT_SHADER, fragmentPath);
23+
24+
GL20.glAttachShader(program, vertexShader);
25+
GL20.glAttachShader(program, fragmentShader);
26+
GL20.glLinkProgram(program);
27+
GL20.glValidateProgram(program);
28+
29+
}
30+
31+
public void bindAttribute(int index, String varName) {
32+
GL20.glBindAttribLocation(program, index, varName);
33+
}
34+
35+
private int addShader(int type, String filePath) {
36+
37+
int shader = GL20.glCreateShader(type);
38+
StringBuilder shaderSource = new StringBuilder();
39+
40+
try {
41+
BufferedReader reader = new BufferedReader(new FileReader(filePath));
42+
43+
String line;
44+
45+
while ((line = reader.readLine()) != null) {
46+
shaderSource.append(line).append("\n");
47+
}
48+
49+
reader.close();
50+
51+
} catch (IOException e) {
52+
e.printStackTrace();
53+
}
54+
55+
GL20.glShaderSource(shader, shaderSource);
56+
GL20.glCompileShader(shader);
57+
if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) != GL20.GL_TRUE) {
58+
System.err.println("Error! Couldnt compile shader " + filePath);
59+
System.err.println(GL20.glGetShaderInfoLog(shader));
60+
}
61+
62+
return shader;
63+
64+
}
65+
66+
public void activate() {
67+
GL20.glUseProgram(program);
68+
}
69+
70+
public void deactivate() {
71+
GL20.glUseProgram(0);
72+
}
73+
74+
public String getVertexPath() {
75+
return vertexPath;
76+
}
77+
78+
public String getFragmentPath() {
79+
return fragmentPath;
80+
}
81+
82+
public int getProgram() {
83+
return program;
84+
}
85+
86+
public int getVertexShader() {
87+
return vertexShader;
88+
}
89+
90+
public int getFragmentShader() {
91+
return fragmentShader;
92+
}
93+
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#version 400 core
2+
3+
in vec3 color;
4+
5+
out vec4 out_Color;
6+
7+
void main(void){
8+
out_Color = vec4(color.xyz, 1.0f);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#version 400 core
2+
3+
in vec3 position;
4+
5+
out vec3 color;
6+
7+
void main(void){
8+
gl_Position = vec4(position.xyz, 1.0f);
9+
color = vec3(1.0f, 0.0f, 1.0f);
10+
}

0 commit comments

Comments
 (0)