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