@@ -74,7 +74,7 @@ public class GlRenderer {
74
74
public TextureRegion miniMap ;
75
75
public boolean showMap = false ;
76
76
77
- protected BitmapFont font = null ;
77
+ public BitmapFont font = null ;
78
78
79
79
protected TextureAtlas wallTextures ;
80
80
protected TextureAtlas spriteTextures ;
@@ -780,67 +780,104 @@ public void updateShaderAttributes() {
780
780
}
781
781
}
782
782
783
+ TextureRegion tempGlyphTextureRegion = new TextureRegion ();
783
784
public void renderTextBatches () {
784
- ShaderProgram activeProgram ;
785
+ DecalBatch batch = getDecalBatch ("sprite" , Entity .BlendMode .OPAQUE );
786
+ if (renderingForPicking )
787
+ batch = getDecalBatch ("picking" , Entity .BlendMode .OPAQUE );
785
788
786
- if (renderingForPicking ) {
787
- activeProgram = ShaderManager .getShaderManager ().getCompiledShader ("picking" ).shader ;
788
- } else {
789
- activeProgram = smoothLighting ;
790
- }
789
+ // Global text scale modifier. Make a constant?
790
+ float baseTextScale = 0.025f ;
791
791
792
- textBatch .setShader (activeProgram );
792
+ for (int i = 0 ; i < textToRender .size ; i ++) {
793
+ DrawableText dT = textToRender .get (i );
793
794
794
- try {
795
- int pvMatrixLoc = activeProgram . getUniformLocation ( "u_projectionViewMatrix" ) ;
795
+ float curXPos = 0f ;
796
+ float textWidth = 0f ;
796
797
797
- for (int i = 0 ; i < textToRender .size ; i ++) {
798
- DrawableText dT = textToRender .get (i );
798
+ // TODO: Handle newline characters?
799
799
800
- textBatch .begin ();
800
+ // Figure out the width of this text
801
+ for (int ii = 0 ; ii < dT .text .length (); ii ++) {
802
+ BitmapFont .Glyph glyph = font .getData ().getGlyph (dT .text .charAt (ii ));
803
+ textWidth += glyph .width * dT .scale * baseTextScale ;
804
+ }
801
805
802
- Gdx .gl .glDepthMask (true ); // SpriteBatch.begin() forces off depth writing, which we need for 3D space.
806
+ // Draw a decal per-glyph for this text
807
+ for (int ii = 0 ; ii < dT .text .length (); ii ++) {
808
+ BitmapFont .Glyph glyph = font .getData ().getGlyph (dT .text .charAt (ii ));
803
809
804
- Vector3 position = dT .parentPosition .cpy ().add (dT .drawOffset );
810
+ float glyphWidth = glyph .width * dT .scale * baseTextScale ;
811
+ float glyphHeight = glyph .height * dT .scale * baseTextScale ;
805
812
806
- if (renderingForPicking ) {
807
- font .setColor (dT .pickingColor );
808
- } else {
809
- if (dT .editorState == Entity .EditorState .hovered ) {
810
- font .setColor (Color .SKY );
811
- } else {
812
- font .setColor (dT .worldColor .cpy ().mul (dT .color )); // How to 'light' this correctly?
813
- }
814
- }
813
+ float tx = dT .parentPosition .x + curXPos ;
814
+ float ty = dT .parentPosition .y + 0.001f ; // Pull out a bit, to place directly on walls
815
+ float tz = dT .parentPosition .z + (glyphHeight * 0.5f ); // Place font baseline directly on entity origin
815
816
816
- GlyphLayout layout = font .draw (textBatch , dT .text , 0 , 0 );
817
+ // Center text on origin
818
+ tx -= textWidth * 0.5f ;
817
819
818
- float scale = 0.025f * dT .scale ;
819
- Matrix4 pvmMatrix = camera .combined .cpy () // Calculate a new matrix to override the already-set uniform.
820
- .translate (position .x , position .z , position .y )
821
- .rotate (new Quaternion ().setEulerAngles (dT .parentRotation .z , dT .parentRotation .y , dT .parentRotation .x ))
822
- .scale (scale , scale , scale )
823
- .translate ( -layout .width / 2 , 0 , 0 ); // Center text on origin.
820
+ // Offset a tiny bit, because something was doing that in the glyph rendering code
821
+ tx += 0.1f * dT .scale ;
822
+
823
+ // Increase the cursor position for next time
824
+ curXPos += glyphWidth ;
825
+
826
+ // Update the position based on our rotation
827
+ Vector3 rotTemp = new Vector3 (tx - dT .parentPosition .x , ty - dT .parentPosition .y , tz - dT .parentPosition .z );
828
+ rotTemp .rotate (Vector3 .X , -dT .parentRotation .x );
829
+ rotTemp .rotate (Vector3 .Y , -dT .parentRotation .y );
830
+ rotTemp .rotate (Vector3 .Z , -dT .parentRotation .z );
831
+
832
+ tx = rotTemp .x + dT .parentPosition .x ;
833
+ ty = rotTemp .y + dT .parentPosition .y ;
834
+ tz = rotTemp .z + dT .parentPosition .z - 0.5f ;
835
+
836
+ // Have everything, can now set up a sprite decal to draw
837
+ DDecal sd = decalPool .obtain ();
838
+ usedDecals .add (sd );
824
839
825
- activeProgram .setUniformMatrix (pvMatrixLoc , pvmMatrix );
840
+ sd .setBlending (-1 , -1 );
841
+ if (!renderingForPicking ) {
842
+ if (dT .blendMode == Entity .BlendMode .ALPHA ) {
843
+ sd .setBlending (GL20 .GL_SRC_ALPHA , GL20 .GL_ONE_MINUS_SRC_ALPHA );
844
+ } else if (dT .blendMode == Entity .BlendMode .ADD ) {
845
+ sd .setBlending (GL20 .GL_SRC_ALPHA , GL20 .GL_ONE );
846
+ }
847
+ }
826
848
827
- if ( dT . editorState == Entity . EditorState . picked ) {
828
- textBatch . flush () ;
849
+ sd . setPosition ( tx , tz , ty );
850
+ sd . transformationOffset = Vector2 . Zero ;
829
851
830
- font .setColor (Color .CORAL );
831
- font .draw (textBatch , dT .text , 0 , 0 );
852
+ sd .setRotation (0 , 0 , 0 );
853
+ sd .rotateY (dT .parentRotation .z );
854
+ sd .rotateX (dT .parentRotation .x );
855
+ sd .rotateZ (dT .parentRotation .y );
832
856
833
- activeProgram .setUniformMatrix (pvMatrixLoc , pvmMatrix .translate (0 , 0 , -0.2f ));
857
+ if (dT .fullbrite ) {
858
+ sd .setColor (dT .color .r , dT .color .g , dT .color .b , 1.0f );
859
+ } else {
860
+ Color lightmap = GetLightmapAt (tx , tz , ty );
861
+ sd .setColor (lightmap .r , lightmap .g , lightmap .b , 1.0f );
834
862
}
835
863
836
- textBatch .end ();
837
- }
864
+ if (renderingForPicking )
865
+ sd .setColor (dT .pickingColor );
866
+
867
+ sd .setScale (1f );
868
+ sd .setWidth (glyphWidth );
869
+ sd .setHeight (glyphHeight );
838
870
839
- activeProgram .setUniformMatrix (pvMatrixLoc , camera .combined ); // Reset the projection matrix.
871
+ tempGlyphTextureRegion .setTexture (font .getRegion ().getTexture ());
872
+ tempGlyphTextureRegion .setRegion (glyph .u , glyph .v2 , glyph .u2 , glyph .v );
873
+ sd .setTextureRegion (tempGlyphTextureRegion );
840
874
841
- textToRender .clear ();
875
+ batch .add (sd );
876
+ }
877
+ batch .flush ();
842
878
}
843
- catch (Exception ex ) { }
879
+
880
+ textToRender .clear ();
844
881
}
845
882
846
883
public void renderOpaqueSprites () {
@@ -1470,6 +1507,7 @@ public void renderSelectedEntities(Array<Entity> selected, Entity.EditorState ed
1470
1507
}
1471
1508
1472
1509
renderOpaqueSprites ();
1510
+ renderTextBatches ();
1473
1511
renderMeshes ();
1474
1512
renderTransparentEntities ();
1475
1513
@@ -2368,7 +2406,6 @@ else if(drawable.billboard) {
2368
2406
2369
2407
public void renderDrawableText (float x , float y , float z , Entity entity , DrawableText drawable )
2370
2408
{
2371
- drawable .worldColor .set (GetLightmapAt (x + drawable .drawOffset .x , z , y + drawable .drawOffset .y ));
2372
2409
drawable .pickingColor .set (entityPickColor );
2373
2410
textToRender .add (drawable );
2374
2411
}
0 commit comments