Skip to content

Commit 2aa6543

Browse files
committed
font sdf and shit (in progress)
1 parent 2abd06a commit 2aa6543

File tree

23 files changed

+487
-260
lines changed

23 files changed

+487
-260
lines changed

common/src/main/java/com/lambda/mixin/render/ChatInputSuggestorMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import com.google.common.base.Strings;
2121
import com.lambda.command.CommandManager;
22-
import com.lambda.graphics.renderer.gui.font.LambdaAtlas;
22+
import com.lambda.graphics.renderer.gui.font.core.LambdaAtlas;
2323
import com.lambda.module.modules.client.LambdaMoji;
2424
import com.lambda.module.modules.client.RenderSettings;
2525
import com.mojang.brigadier.CommandDispatcher;

common/src/main/java/com/lambda/mixin/render/TextRendererMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.Lambda;
21-
import com.lambda.graphics.renderer.gui.font.LambdaAtlas;
22-
import com.lambda.graphics.renderer.gui.font.LambdaEmoji;
21+
import com.lambda.graphics.renderer.gui.font.core.LambdaAtlas;
22+
import com.lambda.graphics.renderer.gui.font.core.LambdaEmoji;
2323
import com.lambda.module.modules.client.LambdaMoji;
2424
import com.lambda.module.modules.client.RenderSettings;
2525
import com.lambda.util.math.Vec2d;

common/src/main/kotlin/com/lambda/graphics/RenderMain.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@ package com.lambda.graphics
2020
import com.lambda.Lambda.mc
2121
import com.lambda.event.EventFlow.post
2222
import com.lambda.event.events.RenderEvent
23-
import com.lambda.graphics.buffer.FrameBuffer
2423
import com.lambda.graphics.gl.GlStateUtils.setupGL
2524
import com.lambda.graphics.gl.Matrices
2625
import com.lambda.graphics.gl.Matrices.resetMatrices
2726
import com.lambda.graphics.pipeline.UIPipeline
28-
import com.lambda.graphics.shader.Shader
2927
import com.lambda.module.modules.client.GuiSettings
3028
import com.lambda.util.math.Vec2d
3129
import com.mojang.blaze3d.systems.RenderSystem.getProjectionMatrix
3230
import org.joml.Matrix4f
3331

3432
object RenderMain {
35-
private val projectionMatrix = Matrix4f()
36-
private val modelViewMatrix get() = Matrices.peek()
33+
val projectionMatrix = Matrix4f()
34+
val modelViewMatrix get() = Matrices.peek()
3735
val projModel get() = Matrix4f(projectionMatrix).mul(modelViewMatrix)
3836

3937
var screenSize = Vec2d.ZERO

common/src/main/kotlin/com/lambda/graphics/buffer/FrameBuffer.kt

Lines changed: 0 additions & 154 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/graphics/buffer/IRenderContext.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ interface IRenderContext {
3838
fun upload()
3939
fun clear()
4040

41+
fun immediateDraw() {
42+
upload()
43+
render()
44+
clear()
45+
}
46+
4147
fun grow(amount: Int)
4248

4349
fun use(block: IRenderContext.() -> Unit) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.graphics.buffer.frame
19+
20+
import com.lambda.Lambda.mc
21+
import com.lambda.graphics.RenderMain
22+
import com.lambda.graphics.gl.Matrices
23+
import org.joml.Matrix4f
24+
import org.lwjgl.opengl.GL11C.glViewport
25+
26+
/**
27+
* A class that handles a cached frame, encapsulating a framebuffer with a specified width and height.
28+
* It provides methods for binding the framebuffer texture and writing to the framebuffer with custom rendering operations.
29+
*
30+
* @param width The width of the framebuffer.
31+
* @param height The height of the framebuffer.
32+
*/
33+
class CachedFrame(val width: Int, val height: Int) {
34+
35+
// The framebuffer associated with this cached frame
36+
private val frameBuffer = FrameBuffer(width, height)
37+
38+
/**
39+
* Binds the color texture of the framebuffer to a specified texture slot.
40+
*
41+
* @param slot The texture slot to bind the color texture to. Defaults to slot 0.
42+
*/
43+
fun bind(slot: Int = 0) = frameBuffer.bindColorTexture(slot)
44+
45+
/**
46+
* Executes custom drawing operations on the framebuffer.
47+
*
48+
* The method temporarily modifies the view and projection matrices, the viewport,
49+
* and then restores them after the block is executed.
50+
*
51+
* @param block A block of code that performs custom drawing operations on the framebuffer.
52+
*/
53+
fun write(block: () -> Unit): CachedFrame {
54+
frameBuffer.write {
55+
// Save the current viewmodel matrix
56+
Matrices.push()
57+
// Set the viewmodel matrix to translate the scene away
58+
Matrices.peek().set(Matrix4f().translate(0f, 0f, -3000f))
59+
60+
// Save the previous projection matrix and set a custom orthographic projection
61+
val prevProj = Matrix4f(RenderMain.projectionMatrix)
62+
RenderMain.projectionMatrix.setOrtho(0f, width.toFloat(), height.toFloat(), 0f, 1000f, 21000f)
63+
64+
// Resize the viewport to match the framebuffer's dimensions
65+
glViewport(0, 0, width, height)
66+
67+
// Execute the drawing operations defined in the block
68+
block()
69+
70+
// Restore the previous viewport dimensions
71+
glViewport(0, 0, mc.framebuffer.viewportWidth, mc.framebuffer.viewportHeight)
72+
73+
// Restore the previous projection matrix
74+
RenderMain.projectionMatrix.set(prevProj)
75+
76+
// Restore the previous viewmodel matrix
77+
Matrices.pop()
78+
}
79+
80+
return this
81+
}
82+
}

0 commit comments

Comments
 (0)