Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More rendering progress. Added a (temporary?) basic smooth floor texture
  • Loading branch information
wjg12004 committed Apr 7, 2016
1 parent fa38421 commit 5d348e1
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 12 deletions.
Binary file added res/SmoothFloor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions res/levels/test.txt

This file was deleted.

17 changes: 17 additions & 0 deletions shaders/SmoothFloor.frag
@@ -0,0 +1,17 @@
#version 330 core

layout (location = 0) out vec4 color;

in DATA
{
vec2 tc;
vec3 position;
} fs_in;

uniform vec2 player;
uniform sampler2D tex;

void main()
{
color = texture(tex, fs_in.tc);
}
20 changes: 20 additions & 0 deletions shaders/SmoothFloor.vert
@@ -0,0 +1,20 @@
#version 330 core

layout (location = 0) in vec4 position;
layout (location = 1) in vec2 tc;

uniform mat4 pr_matrix;
uniform mat4 vw_matrix;

out DATA
{
vec2 tc;
vec3 position;
}

void main()
{
gl_Position = pr_matrix * vw_matrix * position;
vs_out.tc = tc;
vs_out.position = vec3(vw_matrix * position);
}
12 changes: 12 additions & 0 deletions src/game/Main.java
Expand Up @@ -32,11 +32,21 @@ public class Main implements Runnable {
}

private void init() {
if (glfwInit() == GL_FALSE) {
System.out.println("glfwInit = False");
return;
}

glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

// Windowed mode, don't share resources
gameWindow = glfwCreateWindow(width, height, "Game Noodle", NULL, NULL);

if (gameWindow == NULL) {
System.out.println("Game Window Null");
return;
}

GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(gameWindow, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
glfwSetKeyCallback(gameWindow, input);
Expand All @@ -51,6 +61,8 @@ public class Main implements Runnable {

// Set all shader uniform variables here
Matrix4f projectionMatrix = Matrix4f.orthographic(-10.0f, 10.0f, -10.0f * 9.0f / 16.0f, 10.0f * 9.0f / 16.0f, -1.0f, 1.0f);
Shader.SMOOTH_FLOOR.setUniformMat4f("pr_matrix", projectionMatrix);
Shader.SMOOTH_FLOOR.setUniform1i("tex", 1);

level = new Level();
}
Expand Down
10 changes: 8 additions & 2 deletions src/game/graphics/Shader.java
Expand Up @@ -15,7 +15,7 @@ public class Shader {
public static final int VERTEX_ATTRIB = 0;
public static final int TCOORD_ATTRIB = 1;

// public static Shader SHADERHERE;
public static Shader SMOOTH_FLOOR;

private boolean enabled = false;

Expand All @@ -27,7 +27,8 @@ public class Shader {
}

public static void loadAll() {
// SHADERHERE = new Shader(vertPathStr, fragPathStr);
SMOOTH_FLOOR = new Shader("shaders/SmoothFloor.vert",
"shaders/SmoothFloor.frag");
}

public int getUniform(String name) {
Expand Down Expand Up @@ -82,4 +83,9 @@ public class Shader {
glUseProgram(ID);
enabled = true;
}

public void disable() {
glUseProgram(0);
enabled = false;
}
}
48 changes: 45 additions & 3 deletions src/game/level/Level.java
@@ -1,16 +1,58 @@
package game.level;

public class Level {
import game.graphics.Shader;
import game.graphics.Texture;
import game.graphics.VertexArray;

public class Level {

private int width, height;
// private VertexArray[][] tiles;
// private Texture[][] tileTextures;

private VertexArray tile;
private Texture tileTexture;

public Level() {
float[] vertices = new float[] {
-10.0f, -10.0f * 9.0f / 16.0f, 0.0f,
-10.0f, 10.0f * 9.0f / 16.0f, 0.0f,
0.0f, 10.0f * 9.0f / 16.0f, 0.0f,
0.0f, -10.0f * 9.0f / 16.0f, 0.0f,
};

byte[] indices = new byte[] {
0, 1, 2,
2, 3, 0
};

float[] tcs = new float[] {
0, 1,
0, 0,
1, 0,
1, 1
};

// width = 20;
// height = 20;
// tiles = new VertexArray[width][height];
// tileTextures = new Texture[width][height];

tile = new VertexArray(vertices, indices, tcs);
tileTexture = new Texture("res/SmoothFloor.png");
}

public void update() {

// player update
// tile update
}

public void render() {

tileTexture.bind();
Shader.SMOOTH_FLOOR.enable();
Shader.SMOOTH_FLOOR.setUniform2f("player", 0, 0);
tile.bind();
Shader.SMOOTH_FLOOR.disable();
tileTexture.unbind();
}
}
26 changes: 26 additions & 0 deletions src/game/level/tiles/SmoothFloor.java
@@ -0,0 +1,26 @@
package game.level.tiles;

import game.graphics.Texture;
import game.graphics.VertexArray;

public class SmoothFloor extends Tile{

public SmoothFloor() {
super();
texture = new Texture("/res/SmoothFloor.png");
}

@Override
public void render() {
// TODO Auto-generated method stub
texture.bind();

}

@Override
public void update() {
// TODO Auto-generated method stub

}

}
42 changes: 42 additions & 0 deletions src/game/level/tiles/Tile.java
@@ -0,0 +1,42 @@
package game.level.tiles;

import game.graphics.Texture;
import game.graphics.VertexArray;

public abstract class Tile {

protected final float SIZE = 1.0f;
protected Texture texture;
protected VertexArray vertexArray;
protected float[] vertices;
protected byte[] indices;
protected float[] textureCoords;


protected Tile() {
vertices = new float[] {
-SIZE / 2.0f, -SIZE / 2.0f, 0.0f,
-SIZE / 2.0f, SIZE / 2.0f, 0.0f,
SIZE / 2.0f, SIZE / 2.0f, 0.0f,
SIZE / 2.0f, -SIZE / 2.0f, 0.0f,
};

indices = new byte[] {
0, 1, 2,
2, 3, 0
};

textureCoords = new float[] {
0, 1,
0, 0,
1, 0,
1, 1
};

}

public abstract void update();

public abstract void render();

}

0 comments on commit 5d348e1

Please sign in to comment.