writing a bunch of boiler plate so i can like draw stuff to the screen
This commit is contained in:
1 parent
b295c1f57e
commit
b154776905
4 files changed
+94
-19
No files matched your search
@@ -0,0 +1,64 @@
|
|||||||
|
package org.example;
|
||||||
|
|
||||||
|
import com.mokiat.data.front.parser.IOBJParser;
|
||||||
|
import com.mokiat.data.front.parser.OBJModel;
|
||||||
|
import com.mokiat.data.front.parser.OBJParser;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Entity
|
||||||
|
{
|
||||||
|
OBJModel model;
|
||||||
|
|
||||||
|
ShaderProgram shader;
|
||||||
|
|
||||||
|
public Entity(String object_file_path, String fragment_shader_path, String vertex_shader_path)
|
||||||
|
{
|
||||||
|
// Load Object
|
||||||
|
try (InputStream in = this.getClass().getResourceAsStream(object_file_path)) {
|
||||||
|
// Create an OBJParser and parse the resource
|
||||||
|
final IOBJParser parser = new OBJParser();
|
||||||
|
this.model = parser.parse(in);
|
||||||
|
|
||||||
|
// Use the model representation to get some basic info
|
||||||
|
System.out.println(MessageFormat.format(
|
||||||
|
"OBJ model has {0} vertices, {1} normals, {2} texture coordinates, and {3} objects.",
|
||||||
|
model.getVertices().size(),
|
||||||
|
model.getNormals().size(),
|
||||||
|
model.getTexCoords().size(),
|
||||||
|
model.getObjects().size()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Shaders
|
||||||
|
try {
|
||||||
|
this.shader = new ShaderProgram();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String vertex_shader_code = new Scanner(new File(vertex_shader_path)).useDelimiter("\\Z").next();
|
||||||
|
this.shader.createVertexShader(vertex_shader_code);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("ERROR Initializing the vertex shader");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String fragment_shader_code = new Scanner(new File(fragment_shader_path)).useDelimiter("\\Z").next();
|
||||||
|
this.shader.createFragmentShader(fragment_shader_code);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("ERROR Initializing the fragment shader");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -88,32 +88,21 @@ public class Game
|
|||||||
|
|
||||||
// Make the window visible
|
// Make the window visible
|
||||||
glfwShowWindow(window);
|
glfwShowWindow(window);
|
||||||
|
|
||||||
// Load Objects
|
|
||||||
try (InputStream in = this.getClass().getResourceAsStream("/objs/cube.obj")) {
|
|
||||||
// Create an OBJParser and parse the resource
|
|
||||||
final IOBJParser parser = new OBJParser();
|
|
||||||
final OBJModel model = parser.parse(in);
|
|
||||||
|
|
||||||
// Use the model representation to get some basic info
|
|
||||||
System.out.println(MessageFormat.format(
|
|
||||||
"OBJ model has {0} vertices, {1} normals, {2} texture coordinates, and {3} objects.",
|
|
||||||
model.getVertices().size(),
|
|
||||||
model.getNormals().size(),
|
|
||||||
model.getTexCoords().size(),
|
|
||||||
model.getObjects().size()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loop()
|
private void loop()
|
||||||
{
|
{
|
||||||
GL.createCapabilities();
|
// Setup world
|
||||||
|
World world = new World();
|
||||||
|
|
||||||
|
// Add stuff to world
|
||||||
|
world.addEntity(new Entity("/obs/cube.obj", "/shaders/shader.fraq", "/shaders/shader.vert"));
|
||||||
|
|
||||||
|
// Do open gl stuff
|
||||||
|
GL.createCapabilities();
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
// Main loop or something
|
||||||
while ( !glfwWindowShouldClose(window) )
|
while ( !glfwWindowShouldClose(window) )
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|||||||
@@ -77,4 +77,7 @@ public class ShaderProgram {
|
|||||||
glDeleteProgram(programId);
|
glDeleteProgram(programId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set stuff
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.example;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class World
|
||||||
|
{
|
||||||
|
ArrayList<Entity> entities;
|
||||||
|
|
||||||
|
public World()
|
||||||
|
{
|
||||||
|
this.entities = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntity(Entity e)
|
||||||
|
{
|
||||||
|
this.entities.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user