Hi there,
I’m new to jMe (so noob inside).
While I was training to jMe, I want to make a sphere from 6 TriMesh. The sphere is good but it seems there is a problem with the (Z ?) rendering.
I use part of the tutorial but with a StandardGame. Jars are the one that you can download from this website (I don’t want to mess up with the cvs too :P)
My main is :
public static void main(String argv[])
{
StandardGame game = new StandardGame("Bonbon's Civ");
try
{
GameSettingsPanel.prompt(game.getSettings());
}
catch(Exception ex) { ex.printStackTrace(); System.exit(0); }
game.start();
DebugGameState gameState = new DebugGameState(); // Create our game state
create(gameState,"Name1",VAL_I,VAL_J,VAL_PLUS);
create(gameState,"Name2",VAL_I,VAL_J,VAL_MINUS);
create(gameState,"Name3",VAL_I,VAL_PLUS,VAL_J);
create(gameState,"Name4",VAL_I,VAL_MINUS,VAL_J);
create(gameState,"Name5",VAL_MINUS,VAL_I,VAL_J);
create(gameState,"Name6",VAL_PLUS,VAL_I,VAL_J);
/* ZBufferState buf = game.getDisplay().getRenderer().createZBufferState();
buf.setFunction(ZBufferState.CF_LEQUAL);
buf.setWritable(true);
gameState.getRootNode().setRenderState(buf);
gameState.getRootNode().updateRenderState();*/
// gameState.getRootNode().setLightCombineMode(LightState.OFF);
GameStateManager.getInstance().attachChild(gameState); // Attach it to the GameStateManager
gameState.setActive(true); // Activate it
}
Mesh are created there :
protected static void create(DebugGameState gameState,String name,int X,int Y,int Z)
{
java.nio.FloatBuffer vertices = BufferUtils.createFloatBuffer((NB+1)*(NB+1)*3);
java.nio.FloatBuffer normal = BufferUtils.createFloatBuffer((NB+1)*(NB+1)*3);
java.nio.FloatBuffer color = BufferUtils.createFloatBuffer((NB+1)*(NB+1)*4);
java.nio.FloatBuffer texture = BufferUtils.createFloatBuffer((NB+1)*(NB+1)*2);
java.nio.IntBuffer indices = BufferUtils.createIntBuffer(NB*NB*2*3);
for(int x=0;x<=NB;x++)
{
for(int y=0;y<=NB;y++)
{
float xx = 0;
if (X == VAL_I) { xx = (x*diam)/NB-rayon; }
else if (X == VAL_J) { xx = (y*diam)/NB-rayon; }
else if (X == VAL_PLUS) { xx = rayon; }
else if (X == VAL_MINUS) { xx = -rayon; }
float yy = 0;
if (Y == VAL_I) { yy = (x*diam)/NB-rayon; }
else if (Y == VAL_J) { yy = (y*diam)/NB-rayon; }
else if (Y == VAL_PLUS) { yy = rayon; }
else if (Y == VAL_MINUS) { yy = -rayon; }
float zz = 0;
if (Z == VAL_I) { zz = (x*diam)/NB-rayon; }
else if (Z == VAL_J) { zz = (y*diam)/NB-rayon; }
else if (Z == VAL_PLUS) { zz = rayon; }
else if (Z == VAL_MINUS) { zz = -rayon; }
float ln = (float)Math.sqrt(xx*xx+yy*yy+zz*zz);
xx /= ln;
yy /= ln;
zz /= ln;
normal.put(xx);
normal.put(yy);
normal.put(zz);
xx *= 5.0;
yy *= 5.0;
zz *= 5.0;
vertices.put(xx);
vertices.put(yy);
vertices.put(zz);
color.put( red(xx,yy,zz) );
color.put( green(xx,yy,zz) );
color.put( blue(xx,yy,zz) );
color.put( 1.0f );
texture.put(0.0f);
texture.put(0.0f);
}
}
for(int x=0;x<NB;x++)
{
for(int y=0;y<NB;y++)
{
int nb1 = x+y*(NB+1);
int nb2 = (x+1)+y*(NB+1);
int nb3 = x+(y+1)*(NB+1);
indices.put(nb1);
indices.put(nb2);
indices.put(nb3);
nb1 = (x+1)+(y+1)*(NB+1);
indices.put(nb2);
indices.put(nb1);
indices.put(nb3);
}
}
// TriMesh sphere = new TriMesh(name,vertices,normal,color,texture,indices);
TriMesh sphere = new TriMesh(name,vertices,normal,color,null,indices);
BoundingBox bb = new BoundingBox();
sphere.setModelBound(bb);
sphere.updateModelBound();
sphere.updateRenderState();
gameState.getRootNode().attachChild(sphere); // Attach the box to rootNode in DebugGameState
}
Since it seems to be a ZBuffer problem, I try to use a ZBufferState. But when I do a "gameState.getRootNode().updateRenderState();" my sphere is all grey (and it doesn't solve my problem).
By the way, when I use "GameSettingsPanel.prompt(game.getSettings());", I get a ugly dialogue. How do I get the same as in BasicGame ?