Working on save cards and better culling options

This commit is contained in:
josua 2020-07-23 11:00:39 +10:00
parent 16b04a62ba
commit 96eb85d55a
10 changed files with 147 additions and 27 deletions

View File

@ -116,7 +116,7 @@ public class DisplayRender
GL33.glEnable(GL33.GL_DEPTH_TEST);
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, 1, 1);
ColorRange range = Main.world.getLayer().layergen.getLightLevel();

View File

@ -79,15 +79,16 @@ public class DisplayRenderUI
ModelGui model_temperature = Models.UI_TEMPERATURE;
ModelGui model_water = Models.UI_WATER;
Matrix4 matrix = Matrix4.translate(-(79 * 15.0) / 160, -9.5 + (1.5 * 17) / 16, 0);
double offset = -(79 * 15.0) / 160;
Matrix4 matrix = Matrix4.translate(offset, -9.5 + (1.5 * 17) / 16, 0);
model_health_b.setModel(matrix);
model_health_b.render();
GL33.glUniform2f(Main.window.glsl_tex_cut, 1, (float)MathHelpers.map(
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, (float)MathHelpers.map(
Main.player.getHealth(),
0, Main.player.maxHealth(),
0, model_health_f.getWidth()));
offset, model_health_f.getWidth() + offset), 1);
model_health_f.setModel(matrix);
model_health_f.render();
@ -95,7 +96,7 @@ public class DisplayRenderUI
double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration()) * 0.75;
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, 1, 1);
GL33.glUniform4f(Main.window.glsl_color,
(float)temperature, calculateGreen(temperature), 1 - (float)temperature, 1);

View File

@ -47,7 +47,7 @@ public class DisplayWindow implements IMainloopTask
public int glsl_mist;
public int glsl_color;
public int glsl_contrast;
public int glsl_tex_cut;
public int glsl_discard_coords;
public int glsl_model;
public int glsl_camera;
public int glsl_projection;
@ -136,7 +136,7 @@ public class DisplayWindow implements IMainloopTask
glsl_projection = GL33.glGetUniformLocation(environmentRenderer.program, "projection");
glsl_projection_sun = GL33.glGetUniformLocation(environmentRenderer.program, "projection_sun");
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
glsl_tex_cut = GL33.glGetUniformLocation(environmentRenderer.program, "tex_cut");
glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords");
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast");
glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard");

View File

@ -96,10 +96,10 @@ public class Models
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
public static final ModelGui UI_BUTTON_DELETE = new ModelGui(Resources.ATLAS.get("/gui/button_delete.png"), new Vec2d(1.2, 1.2));
public static final ModelGui UI_BUTTON_DELETE_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_delete_hover.png"), new Vec2d(1.2, 1.2));
public static final ModelGui UI_BUTTON_PLAY = new ModelGui(Resources.ATLAS.get("/gui/button_play.png"), new Vec2d(1.2, 1.2));
public static final ModelGui UI_BUTTON_PLAY_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_play_hover.png"), new Vec2d(1.2, 1.2));
public static final ModelGui UI_BUTTON_DELETE = new ModelGui(Resources.ATLAS.get("/gui/button_delete.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_DELETE_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_delete_hover.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_PLAY = new ModelGui(Resources.ATLAS.get("/gui/button_play.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_PLAY_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_play_hover.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_LABEL = new ModelGui(Resources.ATLAS.get("/gui/label.png"), new Vec2d(24, 3));
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(6, 0.375));

View File

@ -2,6 +2,8 @@ package projectzombie.menu;
import java.util.Random;
import org.lwjgl.opengl.GL33;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.init.Layers;
@ -11,7 +13,8 @@ import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUIAlignment;
import projectzombie.menu.gui.GUIButton;
import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.GuiButtonModel;
import projectzombie.menu.gui.GUISavesCard;
import projectzombie.menu.gui.GUIButtonModel;
import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonCallback;
import projectzombie.menu.gui.components.ButtonSetting;
@ -21,7 +24,7 @@ public class MenuSaves extends Menu
private static final Random rand = new Random();
private Menu parent;
private GUI gui;
private GUI gui, gui_cards;
public MenuSaves(Menu parent)
{
@ -31,7 +34,20 @@ public class MenuSaves extends Menu
doGameRender = parent.doGameRender;
showIngameGUI = parent.showIngameGUI;
gui = new GUI();
gui = new GUI()
{
@Override
public void render()
{
GL33.glUniform4f(Main.window.glsl_discard_coords, -0.5f, -0.5f, 0.5f, 0.5f);
super.render();
GL33.glUniform4f(Main.window.glsl_discard_coords, -1, -1, 1, 1);
}
};
gui_cards = new GUI();
input = new InputGUI(gui);
keepMouse = false;
@ -44,8 +60,8 @@ public class MenuSaves extends Menu
Main.menu = new MenuGame();
});
GuiButtonModel buttonPlay = new GuiButtonModel(Models.UI_BUTTON_DELETE, Models.UI_BUTTON_DELETE_HOVER);
gui.add(buttonPlay);
GUISavesCard savesCard = new GUISavesCard(new Vec2d(0, 0));
gui_cards.add(savesCard);
buttonBack.setAlign(GUIAlignment.RIGHT);
buttonCreate.setAlign(GUIAlignment.LEFT);
@ -57,14 +73,16 @@ public class MenuSaves extends Menu
labelSaves.setText("Saves");
labelSaves.setSize(new Vec2d(1, 1));
labelSaves.setPos(new Vec2d(0, 6.8));
gui.add(labelSaves);
gui_cards.add(labelSaves);
gui.add(buttonBack);
gui.add(buttonCreate);
gui.add(gui_cards);
}
@Override
public void render() {
public void render()
{
gui.render();
}

View File

@ -5,14 +5,20 @@ import gl_engine.vec.Vec2d;
import projectzombie.model.Model;
import projectzombie.model.ModelGui;
public class GuiButtonModel implements GUIComponent
public class GUIButtonModel implements GUIComponent
{
public interface GUIButtonModelCallback {
public void click(GUIButtonModel button);
}
private GUIButtonModelCallback callback;
private ModelGui modelHover;
private ModelGui model;
private Vec2d pos = new Vec2d(0, 0);
public GuiButtonModel(ModelGui model, ModelGui modelHover) {
public GUIButtonModel(ModelGui model, ModelGui modelHover, GUIButtonModelCallback callback) {
this.callback = callback;
this.modelHover = modelHover;
this.model = model;
}
@ -43,14 +49,11 @@ public class GuiButtonModel implements GUIComponent
@Override
public void onRightClick(Vec2d mousePos) {
// TODO Auto-generated method stub
}
@Override
public void onMouseClick(Vec2d mousePos) {
// TODO Auto-generated method stub
this.callback.click(this);
}
@Override

View File

@ -0,0 +1,92 @@
package projectzombie.menu.gui;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import projectzombie.init.Models;
import projectzombie.model.ModelGui;
public class GUISavesCard implements GUIComponent
{
private static final ModelGui LABEL = Models.UI_LABEL;
private Vec2d pos = new Vec2d(0, 0);
private GUIButtonModel buttonDelete;
private GUIButtonModel buttonPlay;
public GUISavesCard(Vec2d pos)
{
pos.x -= LABEL.getWidth() / 2;
this.pos = pos;
buttonDelete = new GUIButtonModel(Models.UI_BUTTON_DELETE, Models.UI_BUTTON_DELETE_HOVER, button -> {
onDeletePressed();
});
buttonPlay = new GUIButtonModel(Models.UI_BUTTON_PLAY, Models.UI_BUTTON_PLAY_HOVER, button -> {
onPlayPressed();
});
buttonPlay.setPos(new Vec2d(-LABEL.getWidth()*122/256.0, LABEL.getHeight()*6/32.0));
buttonDelete.setPos(new Vec2d(LABEL.getWidth()*102/256.0, LABEL.getHeight()*6/32.0));
}
public void onPlayPressed() {
}
public void onDeletePressed() {
}
@Override
public void render(Vec2d mousePos)
{
LABEL.setModel(Matrix4.translate(pos.x, pos.y, 0));
LABEL.render();
buttonDelete.render(mousePos);
buttonPlay.render(mousePos);
}
@Override
public void update(Vec2d mousePos) {
buttonDelete.update(mousePos);
buttonPlay.update(mousePos);
}
@Override
public boolean checkMouseHover(Vec2d pos) {
return (this.pos.x > pos.x && this.pos.x + LABEL.getWidth() < pos.x &&
this.pos.y > pos.y && this.pos.y + LABEL.getHeight() < pos.y);
}
@Override
public void onRightClick(Vec2d pos) {
if(buttonDelete.checkMouseHover(pos))
buttonDelete.onRightClick(pos);
if(buttonPlay.checkMouseHover(pos))
buttonPlay.onRightClick(pos);
}
@Override
public void onMouseClick(Vec2d pos) {
if(buttonDelete.checkMouseHover(pos))
buttonDelete.onMouseClick(pos);
if(buttonPlay.checkMouseHover(pos))
buttonPlay.onMouseClick(pos);
}
@Override
public void onActivate() {
buttonDelete.onActivate();
buttonPlay.onActivate();
}
@Override
public void onBack() {
buttonDelete.onBack();
buttonPlay.onBack();
}
}

View File

@ -4,6 +4,7 @@ in vec3 pPos;
in vec3 pTexture;
in vec3 pLightMapPos;
in vec3 pSunDepth;
in vec2 pVertex;
in float pCameraDepth;
flat in int pFlags;
@ -22,7 +23,7 @@ uniform vec3 lighting_day_high;
uniform vec2 lightmap_offset;
uniform vec2 lightmap_size;
uniform vec2 tex_cut;
uniform vec4 discard_coords;
uniform vec4 color;
uniform float contrast;
@ -99,5 +100,7 @@ void main()
FragColor.b = min(1, FragColor.b);
}
discard(textureRGB.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
discard(textureRGB.a == 0 || (
pVertex.x < discard_coords.x || pVertex.y < discard_coords.y ||
pVertex.x > discard_coords.z || pVertex.y > discard_coords.w));
}

View File

@ -11,6 +11,7 @@ out float pCameraDepth;
out vec3 pSunDepth;
out vec3 pLightMapPos;
out vec3 pTexture;
out vec2 pVertex;
out vec3 pPos;
flat out int pFlags;
@ -65,7 +66,9 @@ void main()
vec4 pos = vec4(aPos, 1) * (mod(type >> 3, 2) == 1 ? billboard : (mod(type, 2) == 1 ? rotated : mat4(1))) *
translate(aOffset) * model;
gl_Position = pos * projection;
vec4 vertex = pos * projection;
gl_Position = vertex;
pVertex = vertex.xy / vertex.w;
if(mode == 0) {
pCameraDepth = mod(type >> 4, 2) == 1 ? 0 : min(1, mist * (-(pos * camera).z * 0.5 + 0.5));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB