From 3720964c8f585939d127a76a154bca45b2f09d04 Mon Sep 17 00:00:00 2001 From: Billy Gallagher Date: Thu, 14 Apr 2016 19:51:55 -0400 Subject: [PATCH] Basic rendering and WASD controls complete! Need to finish tile rendering. --- res/playerBlue.png | Bin 0 -> 573 bytes res/{SmoothFloor.png => smoothFloor.png} | Bin shaders/player.frag | 17 +++++ shaders/player.vert | 19 +++++ .../{SmoothFloor.frag => smoothFloor.frag} | 0 .../{SmoothFloor.vert => smoothFloor.vert} | 2 +- src/game/Main.java | 7 ++ src/game/entity/Player.java | 70 ++++++++++++++++++ src/game/entity/PlayerBall.java | 5 -- src/game/graphics/Shader.java | 6 +- src/game/graphics/VertexArray.java | 32 ++++---- src/game/level/Level.java | 33 ++++----- src/game/level/tiles/Tile.java | 4 +- 13 files changed, 149 insertions(+), 46 deletions(-) create mode 100644 res/playerBlue.png rename res/{SmoothFloor.png => smoothFloor.png} (100%) create mode 100644 shaders/player.frag create mode 100644 shaders/player.vert rename shaders/{SmoothFloor.frag => smoothFloor.frag} (100%) rename shaders/{SmoothFloor.vert => smoothFloor.vert} (96%) create mode 100644 src/game/entity/Player.java delete mode 100644 src/game/entity/PlayerBall.java diff --git a/res/playerBlue.png b/res/playerBlue.png new file mode 100644 index 0000000000000000000000000000000000000000..c6462cc4828d532c355a20b42b21de10f959513f GIT binary patch literal 573 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPN3!k{5^sIT(RX`!h64!_l=ltB<)VvY~=c3falGGH1 z^30M91$R&1fbd2>aRvs)rJgR1Ar-gYMjz~JQQ)b~HH%!l{o{Z8!uQtVyT$p}1+pyD zm|`~bv`WVP?09Yt6{Qz9CFVwdXQ{dSQAlYI!=EL6!i=Kd*Shd3Ffm4K*&NCew3Vg9 zK**7+fxV%X!>MKCE*^zL<_-5}Keg_7@YjMd`-uEz|JN+qOMWl@wo+%4(E_#yQ8y2S z9eDoh7>GDA?ZERNr>-4X{_Bh&ztqJQM}O4aWR2>n^GZ)R{UF)k!_hC-T3R>E@jBr2 zC3(q#Yh3YJjy7i)vM=(dGS1IQo3TYX$6Y8Q;kww?ryE3znaZRpBiZ*H|FNDsV(q_$ zc@KmNnC393AK*ly7!KTFeD<@%@XFz)jQzULfGU0|wd()ZC=^+%^w&FQi+b}9e#4*3 zHy)UAP~cy%&cV-&VVe|6+!~76qZs6Ge~QxUn7+?lc1lhtm!agDDE=(LnoDces|p3x zJPqQ{W30KhXMdVdo~6#-%0S<{iKlpb;%5XDJ?PB*yg<=Ctn1Kkw@4o)h2GyzT0#~R zUFTnawoRHpdrHRH9?S5!+3^#joa-ug6~CU>U~iwhG0W+W*aTp#GI+ZBxvX 0) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObj); + glBindVertexArray(vao); + if (ibo > 0) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); } } public void unbind() { - if (indexBufferObj > 0) { + if (ibo > 0) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } glBindVertexArray(0); } public void draw() { - if (indexBufferObj > 0) { + if (ibo > 0) { glDrawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_BYTE, 0); } else { glDrawArrays(GL_TRIANGLES, 0, numVertices); diff --git a/src/game/level/Level.java b/src/game/level/Level.java index 134a7c7..232d7a3 100644 --- a/src/game/level/Level.java +++ b/src/game/level/Level.java @@ -1,17 +1,15 @@ package game.level; +import game.entity.Player; import game.graphics.Shader; import game.graphics.Texture; import game.graphics.VertexArray; public class Level { + // number of tiles +// private int width, height; - private int width, height; -// private VertexArray[][] tiles; -// private Texture[][] tileTextures; - - private VertexArray tile; - private Texture tileTexture; + private Player player; public Level() { float[] vertices = new float[] { @@ -33,26 +31,23 @@ public class Level { 1, 1 }; -// width = 20; -// height = 20; -// tiles = new VertexArray[width][height]; -// tileTextures = new Texture[width][height]; + player = new Player(); - tile = new VertexArray(vertices, indices, tcs); - tileTexture = new Texture("res/SmoothFloor.png"); } public void update() { - // player update // tile update + // player update + // enemy update + + player.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(); + // render tiles + // render player + // render other entities + + player.render(); } } diff --git a/src/game/level/tiles/Tile.java b/src/game/level/tiles/Tile.java index 142f9bc..6c54f7d 100644 --- a/src/game/level/tiles/Tile.java +++ b/src/game/level/tiles/Tile.java @@ -10,7 +10,7 @@ public abstract class Tile { protected VertexArray vertexArray; protected float[] vertices; protected byte[] indices; - protected float[] textureCoords; + protected float[] tcs; protected Tile() { @@ -26,7 +26,7 @@ public abstract class Tile { 2, 3, 0 }; - textureCoords = new float[] { + tcs = new float[] { 0, 1, 0, 0, 1, 0,