10
10
11
11
package freeworld .client .render ;
12
12
13
- import freeworld .client .render .gl .GLDrawMode ;
14
- import freeworld .client .render .gl .GLStateMgr ;
15
- import freeworld .client .render .texture .TextureRegion ;
16
- import freeworld .client .render .world .HitResult ;
17
- import freeworld .client .render .world .WorldRenderer ;
18
13
import freeworld .client .Freeworld ;
14
+ import freeworld .client .render .gl .GLDrawMode ;
19
15
import freeworld .client .render .gl .GLProgram ;
20
16
import freeworld .client .render .gl .GLResource ;
17
+ import freeworld .client .render .gl .GLStateMgr ;
21
18
import freeworld .client .render .model .VertexLayout ;
22
19
import freeworld .client .render .model .VertexLayouts ;
23
20
import freeworld .client .render .texture .TextureAtlas ;
24
21
import freeworld .client .render .texture .TextureManager ;
22
+ import freeworld .client .render .texture .TextureRegion ;
25
23
import freeworld .client .render .world .BlockRenderer ;
24
+ import freeworld .client .render .world .HitResult ;
25
+ import freeworld .client .render .world .WorldRenderer ;
26
26
import freeworld .client .world .chunk .ClientChunk ;
27
27
import freeworld .core .Identifier ;
28
28
import freeworld .core .math .AABBox ;
29
29
import freeworld .util .Direction ;
30
30
import freeworld .util .Logging ;
31
+ import freeworld .world .block .BlockType ;
31
32
import freeworld .world .entity .Entity ;
32
33
import org .joml .Matrix4f ;
33
34
import org .slf4j .Logger ;
@@ -46,7 +47,7 @@ public final class GameRenderer implements GLResource {
46
47
private final Freeworld client ;
47
48
private GLProgram positionColorProgram ;
48
49
private GLProgram positionColorTexProgram ;
49
- private final Matrix4f projectionViewMatrix = new Matrix4f ();
50
+ @ Deprecated
50
51
private final Matrix4f modelMatrix = new Matrix4f ();
51
52
public static final Identifier TEX_DIRT = Identifier .ofBuiltin ("texture/block/dirt.png" );
52
53
public static final Identifier TEX_GRASS_BLOCK = Identifier .ofBuiltin ("texture/block/grass_block.png" );
@@ -112,23 +113,24 @@ public void render(GLStateMgr gl, double partialTick) {
112
113
gl .enableDepthTest ();
113
114
gl .setDepthFunc (GL10C .LEQUAL );
114
115
blockAtlas .bind (gl );
115
- projectionViewMatrix .setPerspective (
116
+
117
+ RenderSystem .pushMatrices ();
118
+ RenderSystem .setProjectionMatrix (RenderSystem .projectionMatrix ().setPerspective (
116
119
(float ) Math .toRadians (70.0 ),
117
120
(float ) client .framebufferWidth () / client .framebufferHeight (),
118
121
0.01f ,
119
122
1000.0f
120
- );
123
+ )) ;
121
124
final Camera camera = client .camera ();
122
125
final Entity player = client .player ();
123
126
camera .moveToEntity (player );
124
127
camera .updateLerp (partialTick );
125
128
camera .updateViewMatrix ();
126
- projectionViewMatrix .mul (camera .viewMatrix ());
127
- modelMatrix .identity ();
128
- positionColorTexProgram .use (gl );
129
- positionColorTexProgram .getUniform (GLProgram .UNIFORM_PROJECTION_VIEW_MATRIX ).set (projectionViewMatrix );
130
- positionColorTexProgram .getUniform (GLProgram .UNIFORM_MODEL_MATRIX ).set (modelMatrix );
131
- positionColorTexProgram .uploadUniforms (gl );
129
+ RenderSystem .setViewMatrix (camera .viewMatrix ());
130
+ RenderSystem .setModelMatrix (RenderSystem .modelMatrix ().identity ());
131
+
132
+ RenderSystem .bindProgram (positionColorTexProgram );
133
+ RenderSystem .updateMatrices ();
132
134
133
135
final List <ClientChunk > chunks = worldRenderer .renderingChunks (player );
134
136
worldRenderer .compileChunks (chunks );
@@ -145,10 +147,8 @@ public void render(GLStateMgr gl, double partialTick) {
145
147
final float maxZ = (float ) box .maxZ ();
146
148
final float offset = 0.005f ;
147
149
gl .setTextureBinding2D (0 );
148
- positionColorProgram .use (gl );
149
- positionColorProgram .getUniform (GLProgram .UNIFORM_PROJECTION_VIEW_MATRIX ).set (projectionViewMatrix );
150
- positionColorProgram .getUniform (GLProgram .UNIFORM_MODEL_MATRIX ).set (modelMatrix );
151
- positionColorProgram .uploadUniforms (gl );
150
+ RenderSystem .bindProgram (positionColorProgram );
151
+ RenderSystem .updateMatrices ();
152
152
tessellator .begin (GLDrawMode .LINES );
153
153
tessellator .color (0 , 0 , 0 );
154
154
// -x
@@ -170,6 +170,8 @@ public void render(GLStateMgr gl, double partialTick) {
170
170
tessellator .end (gl );
171
171
}
172
172
173
+ RenderSystem .popMatrices ();
174
+
173
175
renderGui (gl , partialTick );
174
176
}
175
177
@@ -178,8 +180,13 @@ private void renderGui(GLStateMgr gl, double partialTick) {
178
180
final int height = client .framebufferHeight ();
179
181
final float screenWidth = width / guiScale ;
180
182
final float screenHeight = height / guiScale ;
181
- projectionViewMatrix .setOrtho (0.0f , screenWidth , 0.0f , screenHeight , -100.0f , 100.0f );
182
- modelMatrix .translation (screenWidth * 0.5f , screenHeight * 0.5f , 0.0f );
183
+
184
+ RenderSystem .pushMatrices ();
185
+
186
+ RenderSystem .setProjectionMatrix (RenderSystem .projectionMatrix ()
187
+ .setOrtho (0.0f , screenWidth , 0.0f , screenHeight , -300.0f , 300.0f ));
188
+ RenderSystem .setModelMatrix (RenderSystem .modelMatrix ()
189
+ .translation (screenWidth * 0.5f , screenHeight * 0.5f , 0.0f ));
183
190
184
191
gl .clear (GL10C .DEPTH_BUFFER_BIT );
185
192
@@ -188,10 +195,8 @@ private void renderGui(GLStateMgr gl, double partialTick) {
188
195
gl .disableCullFace ();
189
196
gl .disableDepthTest ();
190
197
guiAtlas .bind (gl );
191
- positionColorTexProgram .use (gl );
192
- positionColorTexProgram .getUniform (GLProgram .UNIFORM_PROJECTION_VIEW_MATRIX ).set (projectionViewMatrix );
193
- positionColorTexProgram .getUniform (GLProgram .UNIFORM_MODEL_MATRIX ).set (modelMatrix );
194
- positionColorTexProgram .uploadUniforms (gl );
198
+ RenderSystem .bindProgram (positionColorTexProgram );
199
+ RenderSystem .updateMatrices ();
195
200
tessellator .begin (GLDrawMode .TRIANGLES );
196
201
renderCrossing ();
197
202
tessellator .end (gl );
@@ -201,6 +206,12 @@ private void renderGui(GLStateMgr gl, double partialTick) {
201
206
renderHotBar (screenHeight );
202
207
renderHotBarSelected (screenHeight );
203
208
tessellator .end (gl );
209
+
210
+ gl .enableDepthTest ();
211
+ blockAtlas .bind (gl );
212
+ renderHotBarItems (gl , screenHeight );
213
+
214
+ RenderSystem .popMatrices ();
204
215
}
205
216
206
217
private void renderGuiSprite (Identifier identifier , float x , float y , float anchorX , float anchorY ) {
@@ -228,11 +239,29 @@ private void renderCrossing() {
228
239
}
229
240
230
241
private void renderHotBar (float screenHeight ) {
231
- renderGuiSprite (TEX_HOT_BAR , 0.0f , -screenHeight * 0.5f , 0.5f , 0.0f );
242
+ renderGuiSprite (TEX_HOT_BAR , 0.0f , -screenHeight * 0.5f + 1 , 0.5f , 0.0f );
232
243
}
233
244
234
245
private void renderHotBarSelected (float screenHeight ) {
235
- renderGuiSprite (TEX_HOT_BAR_SELECTED , (client .hotBarSelection () - 5 ) * 22.0f - 2.0f , -screenHeight * 0.5f , 0.0f , 0.0f );
246
+ renderGuiSprite (TEX_HOT_BAR_SELECTED , (client .hotBarSelection () - 5 ) * 20.0f - 2.0f , -screenHeight * 0.5f , 0.0f , 0.0f );
247
+ }
248
+
249
+ private void renderHotBarItems (GLStateMgr gl , float screenHeight ) {
250
+ int i = 0 ;
251
+ for (BlockType blockType : client .hotBar ()) {
252
+ RenderSystem .modelMatrix ().pushMatrix ();
253
+ RenderSystem .setModelMatrix (RenderSystem .modelMatrix ()
254
+ .translate ((i - 5 ) * 20 + 3 , 0 , 0 )
255
+ .translate (0 , -screenHeight * 0.5f + 8 , 100 )
256
+ .rotateX ((float ) Math .toRadians (30.0 ))
257
+ .rotateY ((float ) Math .toRadians (45.0 ))
258
+ .scale (10 ));
259
+ tessellator .begin (GLDrawMode .TRIANGLES );
260
+ blockRenderer .renderBlock (tessellator , blockType , 0 , 0 , 0 );
261
+ tessellator .end (gl );
262
+ i ++;
263
+ RenderSystem .modelMatrix ().popMatrix ();
264
+ }
236
265
}
237
266
238
267
@ Override
@@ -268,14 +297,6 @@ public BlockRenderer blockRenderer() {
268
297
return blockRenderer ;
269
298
}
270
299
271
- public Matrix4f projectionViewMatrix () {
272
- return projectionViewMatrix ;
273
- }
274
-
275
- public Matrix4f modelMatrix () {
276
- return modelMatrix ;
277
- }
278
-
279
300
public HitResult hitResult () {
280
301
return hitResult ;
281
302
}
0 commit comments