I used the tutorial 10 camera code in one of my project, as I started OpenGL 3 days ago I'm not sure about my Opengl INIT.
my problem is the following, if I only do translation or Y rotation everything looks fine.
But as soon as I do X rotation my sector get "seprarated"
this is my init
private void initGL() {
GL11.glEnable(GL11.GL_TEXTURE_2D);//texture mapping
GL11.glShadeModel(GL11.GL_SMOOTH);//smooth shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);//couleur de fond noire
GL11.glClearDepth(1.0);//setup du buffer de profondeur
GL11.glEnable(GL11.GL_DEPTH_TEST);//permet le test de profondeur
GL11.glDepthFunc(GL11.GL_LEQUAL); //le type de test de profondeur a faire
GL11.glMatrixMode(GL11.GL_PROJECTION);//selectrione la matrice de projection
GL11.glLoadIdentity();//reset la matrice de projection
// Calcul l'aspect ratio de la fenetre
GLU.gluPerspective(
45.0f,
(float) displayMode.getWidth() / (float) displayMode.getHeight(),
0.1f,
100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);//selectionne la modelview Matrix
GL11.glColor4f(1.0f,1.0f,1.0f,0.3f); // Full luminosité, 30% Alpha
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE); // Blending mode one
// met les melleur parametre
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}
any problem in it? (projection mode or something)
as for the rendering algorythm, I don't think that there is any problem with it.
it's quite simple.
I made a function that draw cube where I want (from the current position).
I have 16x256x16 sectors containing 65k cubes
a world is 9x9 sectors large.
I draw the world line by line
world top view
-z
^
|Sec Sec Sec <- World line 3
|Sec Sec Sec
|Sec Sec Sec <-World line 1
|------------------------>x
and a sector is drawed layer by lawer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glRotatef(lookupdown,1.0f,0.0f,0.0f);
GL11.glRotatef(sceneroty,0.0f,1.0f,0.0f);
GL11.glTranslatef(xtrans, ytrans, ztrans); //starting position
//drawing each sector
for (int zsect=0 ; zsect < displayArea; zsect++)
{
for (int xsect=0 ; xsect < displayArea; xsect++){
chunk = world.getSector((short)xsect, (short)zsect);
//drawing each layer
for(int yc=0; yc<256; yc++){
for(int zc=0; zc<16;zc++){
for(int xc=0; xc<16; xc++){
chunk.drawCube(xc.yc.zc,0.5f) //0.5f is a x translation
}
GL11.glTranslatef(-16.0f, 0.0f, 1.0f); //goes where line+1 of the layer is starting
}
GL11.glTranslatef(0.0f, 1.0f, -16.0f); //goes where layer+1 is starting
}
GL11.glTranslatef(16.0f, -256.0f, 0.0f); //goes where the next chunk on the line is starting
}
GL11.glTranslatef(-(float)(displayArea*16.0f), 0.0f, 16.0f);//goes at the beginning of the next chunk line
}
video examples, chunk generation :
world generation
any idea?
thanks =D