Sfoglia il codice sorgente

* Nifty will now set the BitmapText base color instead of using the material's color (which could override the color of the shared font)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9995 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Sha..rd 13 anni fa
parent
commit
2e35519182

+ 7 - 8
engine/src/core/com/jme3/font/BitmapText.java

@@ -418,19 +418,18 @@ public class BitmapText extends Node {
     }
 
     public void render(RenderManager rm, ColorRGBA color) {
-
         for (BitmapTextPage page : textPages) {
             Material mat = page.getMaterial();
             mat.setTexture("ColorMap", page.getTexture());
-            ColorRGBA original = getColor(mat, "Color");            
-            mat.setColor("Color", color);
+            //ColorRGBA original = getColor(mat, "Color");            
+            //mat.setColor("Color", color);
             mat.render(page, rm);
             
-            if( original == null ) {
-                mat.clearParam("Color");
-            } else {
-                mat.setColor("Color", original);
-            }
+            //if( original == null ) {
+            //    mat.clearParam("Color");
+            //} else {
+            //    mat.setColor("Color", original);
+            //}
         }
     }
 }

+ 31 - 24
engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java

@@ -68,7 +68,6 @@ public class RenderDeviceJme implements RenderDevice {
     private HashMap<CachedTextKey, BitmapText> textCacheCurrentFrame = new HashMap<CachedTextKey, BitmapText>();
     private final Quad quad = new Quad(1, -1, true);
     private final Geometry quadGeom = new Geometry("nifty-quad", quad);
-    private final Material unshadedMat;
     private boolean clipWasSet = false;
     private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
     private VertexBuffer quadModTC = quadDefaultTC.clone();
@@ -77,6 +76,10 @@ public class RenderDeviceJme implements RenderDevice {
     private ColorRGBA tempColor = new ColorRGBA();
     private RenderState renderState = new RenderState();
     
+    private Material colorMaterial;
+    private Material textureColorMaterial;
+    private Material vertexColorMaterial;
+    
     private static class CachedTextKey {
         
         BitmapFont font;
@@ -118,10 +121,20 @@ public class RenderDeviceJme implements RenderDevice {
         
         quadModTC.setUsage(Usage.Stream);
         
-        // GUI material
-        unshadedMat = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+        // Load the 3 material types separately to avoid
+        // reloading the shader when the defines change.
+        
+        // Material with a single color (no texture or vertex color)
+        colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+        
+        // Material with a texture and a color (no vertex color)
+        textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
         
-        // Shared render state
+        // Material with vertex color, used for gradients (no texture)
+        vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+        vertexColorMaterial.setBoolean("VertexColor", true);
+        
+        // Shared render state for all materials
         renderState.setDepthTest(false);
         renderState.setDepthWrite(false);
     }
@@ -226,9 +239,9 @@ public class RenderDeviceJme implements RenderDevice {
         }
         textCacheCurrentFrame.put(key, text);
         
-        float width = text.getLineWidth();
+//        float width = text.getLineWidth();
 //        float height = text.getLineHeight();
-        float x0 = x + 0.5f * width * (1f - sizeX);
+        float x0 = x; //+ 0.5f * width * (1f - sizeX);
         float y0 = y; // + 0.5f * height * (1f - sizeY);
         
         tempMat.loadIdentity();
@@ -237,6 +250,8 @@ public class RenderDeviceJme implements RenderDevice {
 
         rm.setWorldMatrix(tempMat);
         rm.setForcedRenderState(renderState);
+        text.setColor(colorRgba);
+        text.updateLogicalState(0);
         text.render(rm, colorRgba);
         
 //        System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY);
@@ -250,9 +265,8 @@ public class RenderDeviceJme implements RenderDevice {
         RenderImageJme jmeImage = (RenderImageJme) image;
         Texture2D texture = jmeImage.getTexture();
         
-        unshadedMat.setColor("Color", convertColor(color, tempColor));
-        unshadedMat.setTexture("ColorMap", texture);        
-        unshadedMat.setBoolean("VertexColor", false);
+        textureColorMaterial.setColor("Color", convertColor(color, tempColor));
+        textureColorMaterial.setTexture("ColorMap", texture);        
         
         float imageWidth = jmeImage.getWidth();
         float imageHeight = jmeImage.getHeight();
@@ -286,7 +300,7 @@ public class RenderDeviceJme implements RenderDevice {
         
         rm.setWorldMatrix(tempMat);
         rm.setForcedRenderState(renderState);
-        unshadedMat.render(quadGeom, rm);
+        textureColorMaterial.render(quadGeom, rm);
         
         //System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
         //                                                                                       x, y, w, h, srcX, srcY, srcW, srcH,
@@ -298,9 +312,8 @@ public class RenderDeviceJme implements RenderDevice {
         
         RenderImageJme jmeImage = (RenderImageJme) image;
         
-        unshadedMat.setColor("Color", convertColor(color, tempColor));
-        unshadedMat.setTexture("ColorMap", jmeImage.getTexture());
-        unshadedMat.setBoolean("VertexColor", false);
+        textureColorMaterial.setColor("Color", convertColor(color, tempColor));
+        textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture());
         
         quad.clearBuffer(Type.TexCoord);
         quad.setBuffer(quadDefaultTC);
@@ -314,15 +327,13 @@ public class RenderDeviceJme implements RenderDevice {
         
         rm.setWorldMatrix(tempMat);
         rm.setForcedRenderState(renderState);
-        unshadedMat.render(quadGeom, rm);
+        textureColorMaterial.render(quadGeom, rm);
         
         //System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale);
     }
     
     public void renderQuad(int x, int y, int width, int height, Color color) {
-        unshadedMat.setColor("Color", convertColor(color, tempColor));                        
-        unshadedMat.setTexture("ColorMap", null);
-        unshadedMat.setBoolean("VertexColor", false);
+        colorMaterial.setColor("Color", convertColor(color, tempColor));                        
 
         tempMat.loadIdentity();
         tempMat.setTranslation(x, getHeight() - y, 0);
@@ -330,7 +341,7 @@ public class RenderDeviceJme implements RenderDevice {
 
         rm.setWorldMatrix(tempMat);
         rm.setForcedRenderState(renderState);
-        unshadedMat.render(quadGeom, rm);
+        colorMaterial.render(quadGeom, rm);
         
         //System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString());
     }
@@ -349,18 +360,14 @@ public class RenderDeviceJme implements RenderDevice {
         
         buf.flip();
         quadColor.updateData(buf);
-        
-        unshadedMat.setColor("Color", ColorRGBA.White);                        
-        unshadedMat.setTexture("ColorMap", null);
-        unshadedMat.setBoolean("VertexColor", true);
-        
+                                
         tempMat.loadIdentity();
         tempMat.setTranslation(x, getHeight() - y, 0);
         tempMat.setScale(width, height, 0);
         
         rm.setWorldMatrix(tempMat);
         rm.setForcedRenderState(renderState);
-        unshadedMat.render(quadGeom, rm);
+        vertexColorMaterial.render(quadGeom, rm);
         
         //System.out.format("renderQuad2(%d, %d, %d, %d, %s, %s, %s, %s)\n", x, y, width, height, topLeft.toString(),
         //                                                                                        topRight.toString(),