yodaaaaaa
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
package chess.view.DDDrender;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import chess.model.Coordinate;
|
||||
import chess.view.DDDrender.shader.BoardShader;
|
||||
import chess.view.DDDrender.shader.PieceShader;
|
||||
import chess.view.DDDrender.shader.ShaderProgram;
|
||||
|
||||
public class Renderer {
|
||||
private BoardShader shader;
|
||||
private BoardShader boardShader;
|
||||
private PieceShader pieceShader;
|
||||
private VertexArray vao;
|
||||
private DDDModel yoda;
|
||||
|
||||
private static int BOARD_WIDTH = 8;
|
||||
private static int BOARD_HEIGHT = 8;
|
||||
@@ -17,12 +27,19 @@ public class Renderer {
|
||||
private static int SQUARE_VERTEX_COUNT = 4;
|
||||
|
||||
public Renderer() {
|
||||
this.shader = new BoardShader();
|
||||
this.boardShader = new BoardShader();
|
||||
this.pieceShader = new PieceShader();
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
shader.LoadShader();
|
||||
boardShader.LoadShader();
|
||||
pieceShader.LoadShader();
|
||||
InitBoard();
|
||||
try {
|
||||
this.yoda = ModelLoader.loadModel("3d/king_yoda.glb");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private float[] GetBoardPositions() {
|
||||
@@ -110,13 +127,34 @@ public class Renderer {
|
||||
}
|
||||
|
||||
public void Render(Camera cam) {
|
||||
this.shader.Start();
|
||||
this.shader.SetCamMatrix(cam.getMatrix());
|
||||
RenderVao(vao);
|
||||
this.boardShader.Start();
|
||||
this.boardShader.SetCamMatrix(cam.getMatrix());
|
||||
this.pieceShader.Start();
|
||||
this.pieceShader.SetCamMatrix(cam.getMatrix());
|
||||
RenderVao(this.boardShader, vao);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
Render(yoda, DDDPlacement.coordinates_to_vector(new Coordinate(i, j)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderVao(VertexArray vertexArray) {
|
||||
this.shader.Start();
|
||||
public void Render(DDDModel model, Vector2f position) {
|
||||
Vector3f realPos = new Vector3f(position.x(), 0, position.y());
|
||||
this.pieceShader.Start();
|
||||
this.pieceShader.setModelTransform(new Matrix4f().translate(realPos));
|
||||
Render(model);
|
||||
}
|
||||
|
||||
public void Render(DDDModel model) {
|
||||
for (int i = 0; i < model.getVaos().size(); i++) {
|
||||
VertexArray vao = model.getVaos().get(i);
|
||||
RenderVao(this.pieceShader, vao);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderVao(ShaderProgram shader, VertexArray vertexArray) {
|
||||
shader.Start();
|
||||
vertexArray.Bind();
|
||||
GL30.glDrawElements(GL30.GL_TRIANGLES, vertexArray.GetVertexCount(), GL_UNSIGNED_INT, 0);
|
||||
vertexArray.Unbind();
|
||||
|
||||
Reference in New Issue
Block a user