Skip to content

Commit dfb2d8b

Browse files
Created Hud class to implement hud using nanovg.
1 parent 504d5a0 commit dfb2d8b

File tree

9 files changed

+415
-187
lines changed

9 files changed

+415
-187
lines changed

.classpath

+5
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@
2727
<attribute name="maven.pomderived" value="true"/>
2828
</attributes>
2929
</classpathentry>
30+
<classpathentry kind="con" path="org.jetbrains.kotlin.core.KOTLIN_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
3035
<classpathentry kind="output" path="target/classes"/>
3136
</classpath>

.idea/workspace.xml

+174-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.project

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.jetbrains.kotlin.ui.kotlinBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
@@ -19,5 +24,13 @@
1924
<natures>
2025
<nature>org.eclipse.jdt.core.javanature</nature>
2126
<nature>org.eclipse.m2e.core.maven2Nature</nature>
27+
<nature>org.jetbrains.kotlin.core.kotlinNature</nature>
2228
</natures>
29+
<linkedResources>
30+
<link>
31+
<name>kotlin_bin</name>
32+
<type>2</type>
33+
<locationURI>org.jetbrains.kotlin.core.filesystem:/Mass/kotlin_bin</locationURI>
34+
</link>
35+
</linkedResources>
2336
</projectDescription>

pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
<artifactId>lwjgl-stb</artifactId>
5858
<version>${lwjgl.version}</version>
5959
</dependency>
60+
<dependency>
61+
<groupId>org.lwjgl</groupId>
62+
<artifactId>lwjgl-nanovg</artifactId>
63+
<version>${lwjgl.version}</version>
64+
</dependency>
6065
<dependency>
6166
<groupId>org.lwjgl</groupId>
6267
<artifactId>lwjgl</artifactId>
@@ -113,6 +118,13 @@
113118
<classifier>${lwjgl.natives}</classifier>
114119
<scope>runtime</scope>
115120
</dependency>
121+
<dependency>
122+
<groupId>org.lwjgl</groupId>
123+
<artifactId>lwjgl-nanovg</artifactId>
124+
<version>${lwjgl.version}</version>
125+
<classifier>${lwjgl.natives}</classifier>
126+
<scope>runtime</scope>
127+
</dependency>
116128
<dependency>
117129
<groupId>org.joml</groupId>
118130
<artifactId>joml</artifactId>

src/main/java/me/oskarmendel/mass/core/Game.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import me.oskarmendel.mass.gfx.*;
3333
import me.oskarmendel.mass.gfx.light.DirectionalLight;
3434
import me.oskarmendel.mass.gfx.weather.Fog;
35+
import me.oskarmendel.mass.hud.Font;
36+
import me.oskarmendel.mass.hud.Hud;
3537
import me.oskarmendel.mass.input.MouseHandler;
3638
import me.oskarmendel.mass.phys.Collidable;
3739
import me.oskarmendel.mass.phys.PhysicsSpace;
@@ -109,6 +111,8 @@ public class Game implements Runnable {
109111
Player player;
110112

111113
Scene scene;
114+
Font font;
115+
Hud hud;
112116

113117
/**
114118
* Default constructor for the game.
@@ -156,7 +160,7 @@ public void init() {
156160
screen.init();
157161

158162
timer.init();
159-
163+
160164
mouseHandler.init(screen);
161165

162166
// Initialize renderer.
@@ -193,6 +197,13 @@ public void init() {
193197
scene.setSkyBox(skyBox);
194198

195199
entities = new Entity[]{massterBall, room, player};
200+
201+
// Initialize the font for the Hud.
202+
font = new Font("src/main/resources/font/OpenSans-Bold.ttf");
203+
204+
// Initialize the Hud.
205+
hud = new Hud(screenOptions, font, SCREEN_WIDTH, SCREEN_HEIGHT);
206+
196207
} catch (Exception e) {
197208
e.printStackTrace();
198209
}
@@ -367,5 +378,7 @@ public void update() {
367378
*/
368379
public void render() {
369380
renderer.render(this.screen, this.camera, this.scene, sceneChanged);
381+
382+
hud.render(this.screen);
370383
}
371384
}

src/main/java/me/oskarmendel/mass/core/Screen.java

+13
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ public static Matrix4f updateProjectionMatrix(Matrix4f matrix, int width, int he
298298
return matrix.setPerspective(FOV, aspectRatio, Z_NEAR, Z_FAR);
299299
}
300300

301+
/**
302+
* Restores the state of the Screen.
303+
*/
304+
public void restore() {
305+
glEnable(GL_DEPTH_TEST);
306+
glEnable(GL_STENCIL_TEST);
307+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
308+
if (this.screenOptions.getCullFace()) {
309+
glEnable(GL_CULL_FACE);
310+
glCullFace(GL_BACK);
311+
}
312+
}
313+
301314
/**
302315
* Destroys the window and releases the callbacks.
303316
*/

src/main/java/me/oskarmendel/mass/gfx/Glyph.java

-57
This file was deleted.

src/main/java/me/oskarmendel/mass/gfx/Font.java src/main/java/me/oskarmendel/mass/hud/Font.java

+22-14
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
* SOFTWARE.
2323
*/
2424

25-
package me.oskarmendel.mass.gfx;
25+
package me.oskarmendel.mass.hud;
2626

27-
import java.util.Map;
28-
import java.util.HashMap;
27+
import me.oskarmendel.mass.util.IOUtil;
28+
29+
import java.nio.ByteBuffer;
2930

3031
/**
3132
* This class represents a Font that the renderer can handle.
@@ -36,18 +37,25 @@
3637
*/
3738
public class Font {
3839

39-
private final Map<Character, Glyph> glyphs;
40-
41-
private final Texture texture;
40+
/**
41+
*
42+
*/
43+
private ByteBuffer fontBuffer;
4244

43-
private int fontHeight;
44-
45-
public Font (Font font, boolean antiAlias) {
46-
glyphs = new HashMap<>();
47-
texture = new Texture();
45+
/**
46+
*
47+
* @param path
48+
* @throws Exception
49+
*/
50+
public Font (String path) throws Exception{
51+
this.fontBuffer = IOUtil.ioResourceToByteBuffer(path, 150*1024);
4852
}
49-
50-
public void draw(String text, float x, float y) {
51-
53+
54+
/**
55+
*
56+
* @return
57+
*/
58+
public ByteBuffer getFontBuffer() {
59+
return this.fontBuffer;
5260
}
5361
}

0 commit comments

Comments
 (0)