pull/12/head
hYdos 2020-02-27 16:07:53 +10:00
parent e3fef20582
commit b6c411caaf
7 changed files with 58 additions and 34 deletions

View File

@ -2,6 +2,8 @@ package com.github.halotroop.litecraft;
import java.util.Random;
import org.lwjgl.glfw.GLFW;
import com.github.halotroop.litecraft.screens.TitleScreen;
import com.github.halotroop.litecraft.world.World;
import com.github.halotroop.litecraft.world.gen.Dimension;
@ -86,7 +88,10 @@ public class Litecraft extends Game
@Override
public void exit()
{ ginger3D.cleanup(); }
{
ginger3D.cleanup();
System.exit(0);
}
@Override
public void render()
@ -127,6 +132,11 @@ public class Litecraft extends Game
Input.invokeAllListeners();
data.player.updateMovement();
tps++;
if(Window.isKeyDown(GLFW.GLFW_KEY_TAB)) {
ginger3D.gingerRegister.wireframe = !ginger3D.gingerRegister.wireframe;
}
}
public static Litecraft getInstance() {

View File

@ -3,7 +3,7 @@ package com.github.halotroop.litecraft.world;
import java.util.*;
import com.github.halotroop.litecraft.types.block.*;
import com.github.halotroop.litecraft.world.block.BlockAccess;
import com.github.halotroop.litecraft.world.block.*;
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
import com.github.hydos.ginger.engine.math.vectors.Vector3f;
import com.github.hydos.ginger.engine.render.renderers.ObjectRenderer;
@ -57,7 +57,7 @@ public class Chunk implements BlockAccess, WorldGenConstants
return this.blockEntities.get(hash);
}
public void render(ObjectRenderer renderer)
public void render(BlockRenderer blockRenderer)
{
renderList.clear();
if (render)
@ -71,8 +71,7 @@ public class Chunk implements BlockAccess, WorldGenConstants
}
}
renderer.prepare();
renderer.render(renderList);
blockRenderer.render(renderList);
}
}

View File

@ -3,7 +3,7 @@ package com.github.halotroop.litecraft.world;
import java.util.Random;
import com.github.halotroop.litecraft.types.block.Block;
import com.github.halotroop.litecraft.world.block.BlockAccess;
import com.github.halotroop.litecraft.world.block.*;
import com.github.halotroop.litecraft.world.gen.*;
import com.github.hydos.ginger.engine.elements.objects.Player;
import com.github.hydos.ginger.engine.math.vectors.Vector3f;
@ -89,6 +89,6 @@ public class World implements BlockAccess, WorldGenConstants
return chunk;
}
public void render(ObjectRenderer entityRenderer)
{ this.chunks.forEach((pos, chunk) -> chunk.render(entityRenderer)); }
public void render(BlockRenderer blockRenderer)
{ this.chunks.forEach((pos, chunk) -> chunk.render(blockRenderer)); }
}

View File

@ -27,53 +27,47 @@ public class BlockRenderer extends Renderer
shader.stop();
}
private void prepareInstance(RenderObject entity)
private void prepBlockInstance(RenderObject entity)
{
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
shader.loadTransformationMatrix(transformationMatrix);
}
private void prepareTexturedModel(TexturedModel model)
private void prepareModel(TexturedModel model)
{
RawModel rawModel = model.getRawModel();
GL30.glBindVertexArray(rawModel.getVaoID());
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
ModelTexture texture = model.getTexture();
if (texture.isTransparent())
{
MasterRenderer.disableCulling();
}
else
{
MasterRenderer.enableCulling();
}
}
private void prepTexture(ModelTexture texture, int textureID) {
shader.loadFakeLightingVariable(texture.isUseFakeLighting());
shader.loadShine(texture.getShineDamper(), texture.getReflectivity());
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
}
public void render(Map<TexturedModel, List<RenderObject>> entities)
{
for (TexturedModel model : entities.keySet())
{
prepareTexturedModel(model);
prepareModel(model);
List<RenderObject> batch = entities.get(model);
for (RenderObject entity : batch)
{
if(entity.isVisible) {
prepareInstance(entity);
prepBlockInstance(entity);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
}
}
unbindTexturedModel();
unbindModel();
}
}
private void unbindTexturedModel()
private void unbindModel()
{
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
@ -86,16 +80,26 @@ public class BlockRenderer extends Renderer
shader.start();
shader.loadSkyColour(Window.getColour());
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
TexturedModel model = renderList.get(0).getModel();
prepareModel(model);
if(GingerRegister.getInstance().wireframe)
{
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE );
}
for (RenderObject entity : renderList)
{
if (entity != null && entity.getModel() != null) {
TexturedModel model = entity.getModel();
prepareTexturedModel(model);
prepareInstance(entity);
prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID());
prepBlockInstance(entity);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
unbindTexturedModel();
}
}
if(GingerRegister.getInstance().wireframe)
{
GL11.glPolygonMode( GL11.GL_FRONT_AND_BACK,GL11.GL_FILL );
}
unbindModel();
shader.stop();
}

View File

@ -22,6 +22,7 @@ public class GingerRegister
public Game game;
public Screen currentScreen;
public boolean wireframe = false;
public GingerRegister()
{ INSTANCE = this; }

View File

@ -4,6 +4,7 @@ import com.github.hydos.ginger.engine.obj.Mesh;
public class StaticCube
{
//@formatter:off
public static float[] vertices =
{
@ -95,19 +96,25 @@ public class StaticCube
23, 21, 22
};
//@formatter:on
private static Mesh mesh = null;
public static Mesh getCube()
public static Mesh getCube()
{
if (mesh == null)
{ mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); }
if (mesh == null)
{
mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
}
return mesh;
}
public static void scaleCube(float multiplier)
public static void scaleCube(float multiplier)
{
for (int i = 0; i < vertices.length; i++)
{ vertices[i] = vertices[i] * multiplier; }
{
vertices[i] = vertices[i] * multiplier;
}
mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
}
}

View File

@ -6,6 +6,7 @@ import org.joml.Vector4f;
import org.lwjgl.opengl.*;
import com.github.halotroop.litecraft.world.World;
import com.github.halotroop.litecraft.world.block.BlockRenderer;
import com.github.hydos.ginger.engine.cameras.Camera;
import com.github.hydos.ginger.engine.elements.GuiTexture;
import com.github.hydos.ginger.engine.elements.objects.*;
@ -31,6 +32,7 @@ public class MasterRenderer
// GL11.glCullFace(GL11.GL_BACK);
}
public BlockRenderer blockRenderer;
private StaticShader entityShader;
public ObjectRenderer entityRenderer;
private GuiShader guiShader;
@ -48,6 +50,7 @@ public class MasterRenderer
{
createProjectionMatrix();
entityShader = new StaticShader();
blockRenderer = new BlockRenderer(entityShader, projectionMatrix);
entityRenderer = new ObjectRenderer(entityShader, projectionMatrix);
skyboxRenderer = new SkyboxRenderer(projectionMatrix);
guiShader = new GuiShader();
@ -169,7 +172,7 @@ public class MasterRenderer
{
prepare();
renderEntities(entities, camera, lights);
world.render(entityRenderer);
world.render(blockRenderer);
renderNormalEntities(normalEntities, lights, camera, clipPlane);
skyboxRenderer.render(camera);
}