Skip to content

Commit bc55ac3

Browse files
committed
merge the system of text with the new unified system
1 parent 8e0f975 commit bc55ac3

7 files changed

Lines changed: 36 additions & 38 deletions

File tree

resources/shaders/3_30/font/coloredTextF.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ uniform sampler2D ourTexture;
1010
void main()
1111
{
1212
FragColor = texture(ourTexture, texCoords) * color;
13+
14+
//FragColor = vec4(0, 0, 0, 1);
1315
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#version 330
22
out vec2 texCoords;
33

4-
layout(location = 0) in vec3 aPos;
4+
layout(location = 0) in vec2 aPos;
55
layout(location = 1) in vec2 inTexCoords;
66

7+
uniform mat4 projection;
8+
uniform mat4 view;
9+
uniform mat4 model;
10+
711
void main()
812
{
9-
gl_Position = vec4(aPos, 1.0f);
13+
gl_Position = projection * view * model * vec4(aPos, 0.0f, 1.0f);
1014
texCoords = inTexCoords;
1115
}

resources/shaders/3_30/shaders.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@
9595
"font/coloredTextV.glsl",
9696
"font/coloredTextF.glsl"
9797
],
98-
"mode" : ["none"],
99-
"links": ["color"]
98+
"mode" : ["cam2DView"],
99+
"links": [
100+
"color",
101+
"projection",
102+
"view",
103+
"model"
104+
]
100105
}
101106
}
102107
}

src/MightyLibrary/mightylib/graphics/GUI/BackgroundlessButton.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public BackgroundlessButton(Context context, Text text){
1717
this.context = context;
1818

1919
if(text == null)
20-
this.Text = new Text(context.getWindow().getInfo());
20+
this.Text = new Text();
2121
else
2222
this.Text = text;
2323

2424
if (text != null) {
2525
this.OverlapsText = text.createCopy();
2626
} else {
27-
this.OverlapsText = new Text(context.getWindow().getInfo());
27+
this.OverlapsText = new Text();
2828
}
2929
}
3030

src/MightyLibrary/mightylib/graphics/text/Text.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@
77
import MightyLibrary.mightylib.util.math.Color4f;
88
import MightyLibrary.mightylib.util.math.EDirection;
99
import org.joml.Vector2f;
10+
import org.joml.Vector3f;
1011
import org.joml.Vector4f;
1112

1213
public class Text extends Renderer {
1314
private static final int NUMBER_INDICES = 4;
1415
private static final int SIZE_INDICES = 6;
1516
private static final int SIZE_COORDINATES = 8;
1617

17-
private final WindowInfo windowInfo;
1818
private float fontSize;
1919
private final int positionIndex;
2020
private final int textureIndex;
2121

2222
private FontFace font;
2323
private String text;
2424

25-
private final Vector2f referencePosition;
2625
private final Vector2f rightLeftPosition;
2726
private final Vector2f rectangleSize;
2827

2928
private EDirection reference;
3029
private ETextAlignment alignment;
3130

32-
public Text(WindowInfo windowInfo) {
31+
public Text() {
3332
super("coloredText", true, true);
34-
this.windowInfo = windowInfo;
3533

3634
fontSize = 10.0f;
3735

@@ -44,7 +42,6 @@ public Text(WindowInfo windowInfo) {
4442
this.reference = EDirection.None;
4543
this.alignment = ETextAlignment.Left;
4644

47-
this.referencePosition = new Vector2f(0, 0);
4845
this.rectangleSize = new Vector2f(0, 0);
4946
this.rightLeftPosition = new Vector2f(0, 0);
5047

@@ -63,9 +60,8 @@ public void display(){
6360
if (shouldNotDrawText())
6461
return;
6562

66-
font.getTexture().bind();
6763
shadManager.getShader(shape.getShaderId()).glUniform("color", color.getR(), color.getG(), color.getB(), color.getA());
68-
super.draw();
64+
super.display();
6965
}
7066

7167

@@ -110,18 +106,11 @@ public Text setPosition(Vector2f position){
110106
if (position == null)
111107
return this;
112108

113-
this.referencePosition.x = position.x;
114-
this.referencePosition.y = position.y;
115-
this.computeRightUpPosition();
109+
super.setPosition(new Vector3f(position.x, position.y, 0.0f));
116110

117111
return this;
118112
}
119113

120-
121-
public Vector2f referencePosition() {
122-
return this.referencePosition;
123-
}
124-
125114
public Vector2f rightLeftPosition() { return this.rightLeftPosition; }
126115

127116
public Vector2f size() { return this.rectangleSize; }
@@ -163,8 +152,8 @@ private void computeRightUpPosition(){
163152
if (shouldNotDrawText())
164153
return;
165154

166-
rightLeftPosition.x = referencePosition.x;
167-
rightLeftPosition.y = referencePosition.y;
155+
rightLeftPosition.x = position.x;
156+
rightLeftPosition.y = position.y;
168157

169158
rectangleSize.x = 0;
170159
rectangleSize.y = 0;
@@ -256,18 +245,17 @@ private void computeRightUpPosition(){
256245

257246
fontChar = font.getFontFile().getCharacter(c);
258247

259-
sizeTemp.x = fontChar.getWidth() * fontSize / windowInfo.getVirtualSizeRef().x * 2.0f - 1.0f;
260-
sizeTemp.y = fontChar.getHeight() * fontSize / windowInfo.getVirtualSizeRef().y * 2.0f - 1.0f;
248+
sizeTemp.x = fontChar.getWidth() * fontSize;
249+
sizeTemp.y = fontChar.getHeight() * fontSize;
261250

262-
posTemp.x = (currentCharOffset.x + fontChar.getxOffset() + referencePosition.x - textReference.x + lineAlignmentOffset)
263-
* 2.0f / windowInfo.getVirtualSizeRef().x;
264-
posTemp.y = (currentCharOffset.y + fontChar.getyOffset() + referencePosition.y - textReference.y)
265-
* 2.0f / windowInfo.getVirtualSizeRef().y;
251+
posTemp.x = (currentCharOffset.x + fontChar.getxOffset() * fontSize - textReference.x + lineAlignmentOffset);
252+
posTemp.y = (currentCharOffset.y + fontChar.getyOffset() * fontSize - textReference.y);
266253

267-
temp.x = -1.0f + posTemp.x;
254+
temp.x = posTemp.x;
268255
temp.y = sizeTemp.x + posTemp.x;
269-
temp.z = 1.0f - posTemp.y;
270-
temp.w = -sizeTemp.y - posTemp.y;
256+
temp.z = posTemp.y;
257+
temp.w = sizeTemp.y + posTemp.y;
258+
271259

272260
position[charCount * SIZE_COORDINATES] = temp.x;
273261
position[charCount * SIZE_COORDINATES + 1] = temp.z;
@@ -314,11 +302,11 @@ private void computeRightUpPosition(){
314302
}
315303

316304
public Text createCopy(){
317-
Text text = new Text(windowInfo);
305+
Text text = new Text();
318306
text.setFont(this.font.getName())
319307
.setColor(color.copy())
320308
.setFontSize(fontSize)
321-
.setPosition(new Vector2f(this.referencePosition.x, this.referencePosition.y))
309+
.setPosition(new Vector2f(this.position.x, this.position.y))
322310
.setReference(this.reference)
323311
.setText(this.text);
324312

@@ -330,7 +318,7 @@ public Text copyTo(Text copy){
330318
.setFont(this.font.getName())
331319
.setColor(color.copy())
332320
.setFontSize(fontSize)
333-
.setPosition(new Vector2f(this.referencePosition.x, this.referencePosition.y))
321+
.setPosition(new Vector2f(this.position.x, this.position.y))
334322
.setReference(this.reference)
335323
.setText(this.text);
336324

src/MightyLibrary/project/scenes/MenuScene.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void init(String[] args) {
3333
.setFontSize(40)
3434
.setText("Test2DScene");
3535

36+
3637
button2DScene.Text.copyTo(button2DScene.OverlapsText);
3738
button2DScene.OverlapsText.setColor(new Color4f(0.3f))
3839
.setText("->Test2DScene<-");
@@ -95,8 +96,6 @@ public void update() {
9596
}
9697
}
9798
}
98-
99-
main3DCamera.updateView();
10099
}
101100

102101

src/MightyLibrary/project/scenes/Test2DScene.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void init(String[] args) {
5353
.setTweeningOption(ETweeningOption.LoopReversed).setAdditionnalArguments(3f, null);
5454

5555

56-
text = new Text(mainContext.getWindow().getInfo());
56+
text = new Text();
5757

5858
Vector2i size = mainContext.getWindow().getInfo().getSizeRef();
5959

0 commit comments

Comments
 (0)