Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Build-141: Fixes and new Menus!
Browse files Browse the repository at this point in the history
Fixed NanoVG crash #46, New WebRenderer to Main Menu news, New Custom
Mouse Cursor, Water now are 4 quads instead of 1, New Options Menu.
  • Loading branch information
Guerra24 committed Dec 29, 2015
1 parent b8b66af commit 01dfcf3
Show file tree
Hide file tree
Showing 27 changed files with 302 additions and 47 deletions.
4 changes: 2 additions & 2 deletions assets/game/settings.conf
@@ -1,12 +1,12 @@
#Voxel Settings
#Sun Dec 27 16:19:57 CST 2015
#Mon Dec 28 20:22:57 CST 2015
UPS=30
VSYNC=false
useMotionBlur=false
useFXAA=false
DrawDistance=2
SettingsVersion=3
useVolumetricLight=false
useVolumetricLight=true
TESTXMOD=Hello Voxel
FPS=30
useDOF=false
Expand Down
2 changes: 1 addition & 1 deletion assets/shaders/FragmentWater.glsl
Expand Up @@ -70,7 +70,7 @@ void main(void) {

out_Color[0] = vec4(0.0, 0.266, 0.635, 0.0);
out_Color[1] = vec4(pass_position.xyz, 0.0);
out_Color[2] = vec4(sin(pass_position.x + moveFactor) * 0.05, 1.0, cos(pass_position.z + moveFactor) * 0.02, 0.0);
out_Color[2] = vec4(sin(pass_position.x + moveFactor) * 0.05, 1.0, cos(pass_position.z - moveFactor) * 0.02, 0.0);
out_Color[3] = vec4(1.0,1.0,0.0,shadow);
out_Color[4] = vec4(0.0,0.0,0.0,0.0);

Expand Down
2 changes: 1 addition & 1 deletion assets/shaders/VertexWater.glsl
Expand Up @@ -42,7 +42,7 @@ uniform int useShadows;
void main(void) {
vec4 worldPosition = modelMatrix * vec4(position.x, 0.0, position.y, 1.0);
float sina = sin(worldPosition.x + moveFactor) * 0.05;
float sinb = cos(worldPosition.z + moveFactor) * 0.02;
float sinb = cos(worldPosition.z - moveFactor) * 0.02;
worldPosition += vec4(0.0, sina + sinb, 0.0, 0.0);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
pass_position = worldPosition.xyz;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/guerra24/voxel/client/core/Voxel.java
Expand Up @@ -37,6 +37,7 @@
import net.guerra24.voxel.client.bootstrap.Bootstrap;
import net.guerra24.voxel.client.graphics.TextMasterRenderer;
import net.guerra24.voxel.client.graphics.opengl.Display;
import net.guerra24.voxel.client.input.Mouse;
import net.guerra24.voxel.client.network.DedicatedClient;
import net.guerra24.voxel.client.resources.GameResources;
import net.guerra24.voxel.client.util.Logger;
Expand Down Expand Up @@ -143,6 +144,7 @@ private void postInit() {
gameResources.getSoundSystem().play("menu1");
else
gameResources.getSoundSystem().play("menu2");
Mouse.setHidden(true);
}

/**
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class VoxelVariables {
public static final String apiVersion = "0.0.6";
public static final int apiVersionNum = 000006;
public static final String state = "ALPHA";
public static final int build = 140;
public static final int build = 141;
public static int FOV = 90;
public static int WIDTH = 1280;
public static int HEIGHT = 720;
Expand All @@ -59,6 +59,11 @@ public class VoxelVariables {
public static boolean autostart = false;
public static boolean christmas = false;
public static final String settings = "assets/game/settings.conf";

/**
* External Data
*/
public static final String web = "http://guerra24.net/";
/**
* Graphic Settings
*/
Expand Down
Expand Up @@ -37,6 +37,7 @@
import net.guerra24.voxel.client.core.State;
import net.guerra24.voxel.client.core.Voxel;
import net.guerra24.voxel.client.core.VoxelVariables;
import net.guerra24.voxel.client.graphics.MenuRendering;
import net.guerra24.voxel.client.graphics.opengl.Display;
import net.guerra24.voxel.client.input.Mouse;
import net.guerra24.voxel.client.particle.ParticleMaster;
Expand Down Expand Up @@ -70,8 +71,7 @@ public void update(Voxel voxel, GlobalStates states, float delta) {
gm.getCamera().setPitch(0);
gm.getCamera().setYaw(0);
states.setState(GameState.MAINMENU);
}
if(gm.getMenuSystem().pauseMenu.getOptionsButton().pressed()){
} else if (gm.getMenuSystem().pauseMenu.getOptionsButton().pressed()) {
states.setState(GameState.OPTIONS);
}
}
Expand All @@ -81,7 +81,7 @@ public void update(Voxel voxel, GlobalStates states, float delta) {
public void render(Voxel voxel, GlobalStates states, float delta) {
GameResources gm = voxel.getGameResources();
WorldsHandler worlds = voxel.getWorldsHandler();

worlds.getActiveWorld().lighting();
gm.getFrustum().calculateFrustum(gm.getMasterShadowRenderer().getProjectionMatrix(), gm.getSun_Camera());
if (VoxelVariables.useShadows) {
Expand All @@ -94,7 +94,7 @@ public void render(Voxel voxel, GlobalStates states, float delta) {
gm.getFrustum().calculateFrustum(gm.getRenderer().getProjectionMatrix(), gm.getCamera());
gm.getRenderer().prepare();
worlds.getActiveWorld().updateChunksOcclusion(gm);

gm.getDeferredShadingRenderer().getPost_fbo().begin();
gm.getRenderer().prepare();
gm.getSkyboxRenderer().render(VoxelVariables.RED, VoxelVariables.GREEN, VoxelVariables.BLUE, delta, gm);
Expand All @@ -108,9 +108,10 @@ public void render(Voxel voxel, GlobalStates states, float delta) {

gm.getRenderer().prepare();
gm.getDeferredShadingRenderer().render(gm);

Display.beingNVGFrame();
gm.getMenuSystem().pauseMenu.render();
MenuRendering.renderMouse();
Display.endNVGFrame();
}

Expand Down
Expand Up @@ -28,6 +28,7 @@
import net.guerra24.voxel.client.core.GlobalStates.GameState;
import net.guerra24.voxel.client.core.State;
import net.guerra24.voxel.client.core.Voxel;
import net.guerra24.voxel.client.graphics.MenuRendering;
import net.guerra24.voxel.client.graphics.opengl.Display;
import net.guerra24.voxel.client.resources.GameResources;

Expand All @@ -50,6 +51,7 @@ public void render(Voxel voxel, GlobalStates states, float delta) {
gm.getRenderer().prepare();
Display.beingNVGFrame();
gm.getMenuSystem().mainMenu.render();
MenuRendering.renderMouse();
Display.endNVGFrame();
}

Expand All @@ -68,6 +70,7 @@ public void update(Voxel voxel, GlobalStates states, float delta) {
}
states.setState(GameState.OPTIONS);
}
gm.getMenuSystem().mainMenu.update();
}

}
Expand Up @@ -37,6 +37,7 @@
import net.guerra24.voxel.client.core.Voxel;
import net.guerra24.voxel.client.core.VoxelVariables;
import net.guerra24.voxel.client.core.GlobalStates.GameState;
import net.guerra24.voxel.client.graphics.MenuRendering;
import net.guerra24.voxel.client.graphics.opengl.Display;
import net.guerra24.voxel.client.input.Mouse;
import net.guerra24.voxel.client.particle.ParticleMaster;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void render(Voxel voxel, GlobalStates states, float delta) {

Display.beingNVGFrame();
gm.getMenuSystem().optionsMenu.render();
MenuRendering.renderMouse();
Display.endNVGFrame();
}

Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.lwjgl.nanovg.NVGPaint;

import net.guerra24.voxel.client.graphics.opengl.Display;
import net.guerra24.voxel.client.input.Mouse;

import static org.lwjgl.system.MemoryUtil.*;

Expand All @@ -56,6 +57,16 @@ public static NVGColor rgba(int r, int g, int b, int a, NVGColor color) {
return color;
}

public static void renderLabel(String text, String font, float x, float y, float w, float h, float fontSize) {
long vg = Display.getVg();
nvgFontSize(vg, fontSize);
nvgFontFace(vg, font);
nvgFillColor(vg, rgba(255, 255, 255, 128, colorA));

nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgText(vg, x, y + h * 0.5f, text, NULL);
}

public static void renderWindow(String title, String font, float x, float y, float w, float h) {
float cornerRadius = 3.0f;
NVGPaint shadowPaint = paintA;
Expand Down Expand Up @@ -113,18 +124,79 @@ public static void renderWindow(String title, String font, float x, float y, flo
nvgRestore(vg);
}

public static void renderMouse() {
float x = Mouse.getX() - 8;
float y = -Mouse.getY() - 8 + Display.getHeight();
float w = 16;
float h = 16;
NVGPaint bg = paintA;
long vg = Display.getVg();
nvgBoxGradient(vg, x + 1, y + 1 + 1.5f, w - 2, h - 2, 3, 4, rgba(255, 255, 255, 200, colorA),
rgba(32, 32, 32, 32, colorB), bg);
nvgBeginPath(vg);
nvgRoundedRect(vg, x + 1, y + 1, w - 2, h - 2, 4 - 1);
nvgFillPaint(vg, bg);
nvgFill(vg);

nvgBeginPath(vg);
nvgRoundedRect(vg, x + 0.5f, y + 0.5f, w - 1, h - 1, 4 - 0.5f);
nvgStrokeColor(vg, rgba(0, 0, 0, 48, colorA));
nvgStroke(vg);
}

public static void renderSlider(float pos, float x, float y, float w, float h) {
NVGPaint bg = paintA, knob = paintB;
float cy = y + (int) (h * 0.5f);
float kr = (int) (h * 0.25f);
long vg = Display.getVg();

nvgSave(vg);
// nvgClearState(vg);

// Slot
nvgBoxGradient(vg, x, cy - 2 + 1, w, 4, 2, 2, rgba(0, 0, 0, 32, colorA), rgba(0, 0, 0, 128, colorB), bg);
nvgBeginPath(vg);
nvgRoundedRect(vg, x, cy - 2, w, 4, 2);
nvgFillPaint(vg, bg);
nvgFill(vg);

// Knob Shadow
nvgRadialGradient(vg, x + (int) (pos * w), cy + 1, kr - 3, kr + 3, rgba(0, 0, 0, 64, colorA),
rgba(0, 0, 0, 0, colorB), bg);
nvgBeginPath(vg);
nvgRect(vg, x + (int) (pos * w) - kr - 5, cy - kr - 5, kr * 2 + 5 + 5, kr * 2 + 5 + 5 + 3);
nvgCircle(vg, x + (int) (pos * w), cy, kr);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, bg);
nvgFill(vg);

// Knob
nvgLinearGradient(vg, x, cy - kr, x, cy + kr, rgba(255, 255, 255, 255, colorA),
rgba(100, 100, 100, 255, colorB), knob);
nvgBeginPath(vg);
nvgCircle(vg, x + (int) (pos * w), cy, kr - 1);
nvgFillColor(vg, rgba(40, 43, 48, 255, colorA));
nvgFill(vg);
nvgFillPaint(vg, knob);
nvgFill(vg);

nvgBeginPath(vg);
nvgCircle(vg, x + (int) (pos * w), cy, kr - 0.5f);
nvgStrokeColor(vg, rgba(0, 0, 0, 92, colorA));
nvgStroke(vg);

nvgRestore(vg);
}

public static void renderText(String text, String font, float x, float y, float fontSize) {
ByteBuffer textEncoded = memEncodeASCII(text, BufferAllocator.MALLOC);
long vg = Display.getVg();
nvgFontSize(vg, fontSize);
nvgFontFace(vg, font);
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
nvgFillColor(vg, rgba(0, 0, 0, 160, colorA));
nvgText(vg, x, y, textEncoded, NULL);
nvgText(vg, x, y, text, NULL);
nvgFillColor(vg, rgba(255, 255, 255, 160, colorA));
nvgText(vg, x, y, textEncoded, NULL);

memFree(textEncoded);
nvgText(vg, x, y, text, NULL);
}

public static void renderButton(ByteBuffer preicon, String text, String font, float x, float y, float w, float h,
Expand Down
Expand Up @@ -184,7 +184,40 @@ private void unbindOcclusion() {
* Game Loader
*/
private void setUpVAO(Loader loader) {
float[] vertices = { -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1 };
float[] vertices = {
-1,-1,
-1,0,
0,-1,

-1,0,
0,0,
0,-1,

-1,0,
-1,1,
0,0,

-1,1,
0,1,
0,0,

0,0,
0,1,
1,0,

0,1,
1,1,
1,0,

0,-1,
0,0,
1,-1,

0,0,
1,0,
1,-1

};
quad = loader.loadToVAO(vertices, 2);
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/guerra24/voxel/client/input/Mouse.java
Expand Up @@ -114,9 +114,14 @@ public static void poll() {

public static void setGrabbed(boolean grab) {
GLFW.glfwSetInputMode(Display.getWindow(), GLFW.GLFW_CURSOR,
grab ? GLFW.GLFW_CURSOR_DISABLED : GLFW.GLFW_CURSOR_NORMAL);
grab ? GLFW.GLFW_CURSOR_DISABLED : GLFW.GLFW_CURSOR_HIDDEN);
grabbed = grab;
}

public static void setHidden(boolean hidden){
GLFW.glfwSetInputMode(Display.getWindow(), GLFW.GLFW_CURSOR,
hidden ? GLFW.GLFW_CURSOR_HIDDEN : GLFW.GLFW_CURSOR_NORMAL);
}

public static boolean isGrabbed() {
return grabbed;
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/net/guerra24/voxel/client/menu/MainMenu.java
Expand Up @@ -34,6 +34,9 @@ public class MainMenu {
private Button playButton;
private Button exitButton;
private Button optionsButton;
private Button newsRefreshButton;

private WebRenderer webRenderer;

private float xScale, yScale;

Expand All @@ -45,22 +48,37 @@ public MainMenu(GameResources gm) {
playButton = new Button(new Vector2f(177 * xScale, 532 * yScale), new Vector2f(215 * xScale, 80 * yScale));
exitButton = new Button(new Vector2f(177 * xScale, 224 * yScale), new Vector2f(215 * xScale, 80 * yScale));
optionsButton = new Button(new Vector2f(177 * xScale, 376 * yScale), new Vector2f(215 * xScale, 80 * yScale));
newsRefreshButton = new Button(new Vector2f(1096 * xScale, 627 * yScale),
new Vector2f(100 * xScale, 40 * yScale));
webRenderer = new WebRenderer(VoxelVariables.web + "news/menu.webtag", 460 * xScale, 120 * yScale);
webRenderer.update();
}

public void render() {
MenuRendering.renderButton(null, "Play", "Roboto-Bold", 170 * xScale, 112 * yScale, 215 * xScale, 80 * yScale,
MenuRendering.rgba(255, 255, 255, 255, MenuRendering.colorA), playButton.insideButton());

MenuRendering.renderButton(null, "Options", "Roboto-Bold", 170 * xScale, 270 * yScale, 215 * xScale,
80 * yScale, MenuRendering.rgba(255, 255, 255, 255, MenuRendering.colorA),
optionsButton.insideButton());

MenuRendering.renderButton(null, "Exit", "Roboto-Bold", 170 * xScale, 425 * yScale, 215 * xScale, 80 * yScale,
MenuRendering.rgba(255, 255, 255, 255, MenuRendering.colorA), exitButton.insideButton());


MenuRendering.renderText(
"Voxel " + VoxelVariables.version + " " + VoxelVariables.state + " Build " + VoxelVariables.build,
"Roboto-Bold", 0, 710 * yScale, 20);
MenuRendering.renderWindow("Voxel Develop News", "Roboto-Bold", 450 * xScale, 50 * yScale, 750 * xScale, 600 * yScale);
MenuRendering.renderText("- Voxel 0.0.9 ALPHA DevLog", "Roboto-Bold", 460 * xScale, 120 * yScale, 25);
MenuRendering.renderText("NanoVG crashes are delaying the official launch of the update, Im searching for fixes.", "Roboto-Bold", 460 * xScale, 150 * yScale, 15);
MenuRendering.renderWindow("Voxel News", "Roboto-Bold", 450 * xScale, 50 * yScale, 750 * xScale, 600 * yScale);
webRenderer.render();
MenuRendering.renderButton(null, "Reload", "Roboto-Bold", 1096 * xScale, 53 * yScale, 100 * xScale,
40 * yScale, MenuRendering.rgba(80, 80, 80, 80, MenuRendering.colorA),
newsRefreshButton.insideButton());
}

public void update() {
if (newsRefreshButton.pressed())
webRenderer.update();
}

public Button getPlayButton() {
Expand Down

0 comments on commit 01dfcf3

Please sign in to comment.