Hi there,
I have a Scene and want to draw its elements to the display. What I am doing is, I call the scene draw methon in the
GLEventlisteners display method and give it the gl object as parameter like this:
public void display(GLAutoDrawable drawable) {
this.gl = drawable.getGL();
GLController.getInstance().getScene().draw(gl);
gl.glFlush();
}
this is my drawing setup in the scene draw method:
public void draw(GL gl){
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -25.0f);
gl.glColor3f(1.0f,0.0f,0.0f);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modMatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projMatrix, 0);
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
...
the the drawing method, I just want to draw some cubes on different positions. SO I change the values for gl.glTranslatef in two loops
and draw the cube object in the next step:
gl.glBegin(GL.GL_TRIANGLES);
for(int col = 0; col < (int)(floorDimension[0]+2); col++){
for(int row = 0; row < (int)(floorDimension[1]+2) ; row++){
gl.glPushMatrix();
// start drawing in the one row and one column under the gl screen (like a safety buffer zone)
// then add one floor tile after another till top corner is reached one row above gl screen
gl.glTranslatef(((0.0f - floorTileSize[0])+(float)(col*floorTileSize[0])), // x
((0.0f - floorTileSize[1])+(float)(row*floorTileSize[1])), // y
0.0f); // z
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modMatrix, 0);
System.out.println("mod x = " + modMatrix[12] + "mod y = " + modMatrix[13] );
floor.draw(gl);
gl.glPopMatrix();
}
}
gl.glEnd();
Since I was wandering, why the cubes are always drawn in the center of the window, I loaded the modMatrix and printed the x,y coordinates, which are always 0.
Why is it not possible to load them outside the event listener?
When I have to draw everything in the event listener, the code is getting messy.
Or have I done a mistake?