* Fix incorrect nifty display

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9993 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 12 years ago
parent 99bf4248df
commit e8f747e8ce
  1. 43
      engine/src/niftygui/com/jme3/niftygui/RenderDeviceJme.java

@ -70,19 +70,12 @@ public class RenderDeviceJme implements RenderDevice {
private final Geometry quadGeom = new Geometry("nifty-quad", quad);
private final Material unshadedMat;
private boolean clipWasSet = false;
private BlendMode blendMode = null;
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
private VertexBuffer quadModTC = quadDefaultTC.clone();
private VertexBuffer quadColor;
private Matrix4f tempMat = new Matrix4f();
private ColorRGBA tempColor = new ColorRGBA();
private static final RenderState noZWriteState = new RenderState();
static {
noZWriteState.setDepthTest(false);
noZWriteState.setDepthWrite(false);
}
private RenderState renderState = new RenderState();
private static class CachedTextKey {
@ -127,8 +120,10 @@ public class RenderDeviceJme implements RenderDevice {
// GUI material
unshadedMat = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
unshadedMat.getAdditionalRenderState().setDepthTest(false);
unshadedMat.getAdditionalRenderState().setDepthWrite(false);
// Shared render state
renderState.setDepthTest(false);
renderState.setDepthWrite(false);
}
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
@ -163,7 +158,6 @@ public class RenderDeviceJme implements RenderDevice {
}
public void beginFrame() {
rm.setForcedRenderState(noZWriteState);
}
public void endFrame() {
@ -186,12 +180,10 @@ public class RenderDeviceJme implements RenderDevice {
}
public void setBlendMode(BlendMode blendMode) {
if (this.blendMode != blendMode) {
this.blendMode = blendMode;
}
renderState.setBlendMode(convertBlend(blendMode));
}
private RenderState.BlendMode convertBlend() {
private RenderState.BlendMode convertBlend(BlendMode blendMode) {
if (blendMode == null) {
return RenderState.BlendMode.Off;
} else if (blendMode == BlendMode.BLEND) {
@ -218,11 +210,7 @@ public class RenderDeviceJme implements RenderDevice {
@Override
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) {
if (str.length() == 0) {
return;
}
if (font instanceof RenderFontNull) {
if (str.length() == 0 || font instanceof RenderFontNull) {
return;
}
@ -238,11 +226,6 @@ public class RenderDeviceJme implements RenderDevice {
}
textCacheCurrentFrame.put(key, text);
// unshadedMat.getAdditionalRenderState().setBlendMode(convertBlend());
// unshadedMat.setBoolean("VertexColor", true);
// unshadedMat.setColor("Color", convertColor(color, tempColor));
// text.setMaterial(unshadedMat);
float width = text.getLineWidth();
// float height = text.getLineHeight();
float x0 = x + 0.5f * width * (1f - sizeX);
@ -253,6 +236,7 @@ public class RenderDeviceJme implements RenderDevice {
tempMat.setScale(sizeX, sizeY, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
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);
@ -262,10 +246,10 @@ public class RenderDeviceJme implements RenderDevice {
int srcX, int srcY, int srcW, int srcH,
Color color, float scale,
int centerX, int centerY) {
RenderImageJme jmeImage = (RenderImageJme) image;
Texture2D texture = jmeImage.getTexture();
unshadedMat.getAdditionalRenderState().setBlendMode(convertBlend());
unshadedMat.setColor("Color", convertColor(color, tempColor));
unshadedMat.setTexture("ColorMap", texture);
unshadedMat.setBoolean("VertexColor", false);
@ -301,6 +285,7 @@ public class RenderDeviceJme implements RenderDevice {
tempMat.setScale(w * scale, h * scale, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
unshadedMat.render(quadGeom, rm);
//System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
@ -313,7 +298,6 @@ public class RenderDeviceJme implements RenderDevice {
RenderImageJme jmeImage = (RenderImageJme) image;
unshadedMat.getAdditionalRenderState().setBlendMode(convertBlend());
unshadedMat.setColor("Color", convertColor(color, tempColor));
unshadedMat.setTexture("ColorMap", jmeImage.getTexture());
unshadedMat.setBoolean("VertexColor", false);
@ -329,13 +313,13 @@ public class RenderDeviceJme implements RenderDevice {
tempMat.setScale(width * imageScale, height * imageScale, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
unshadedMat.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.getAdditionalRenderState().setBlendMode(convertBlend());
unshadedMat.setColor("Color", convertColor(color, tempColor));
unshadedMat.setTexture("ColorMap", null);
unshadedMat.setBoolean("VertexColor", false);
@ -345,6 +329,7 @@ public class RenderDeviceJme implements RenderDevice {
tempMat.setScale(width, height, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
unshadedMat.render(quadGeom, rm);
//System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString());
@ -365,7 +350,6 @@ public class RenderDeviceJme implements RenderDevice {
buf.flip();
quadColor.updateData(buf);
unshadedMat.getAdditionalRenderState().setBlendMode(convertBlend());
unshadedMat.setColor("Color", ColorRGBA.White);
unshadedMat.setTexture("ColorMap", null);
unshadedMat.setBoolean("VertexColor", true);
@ -375,6 +359,7 @@ public class RenderDeviceJme implements RenderDevice {
tempMat.setScale(width, height, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
unshadedMat.render(quadGeom, rm);
//System.out.format("renderQuad2(%d, %d, %d, %d, %s, %s, %s, %s)\n", x, y, width, height, topLeft.toString(),

Loading…
Cancel
Save