i have a code of Maze Game in JOGL, and it’s use this code to create the walls in the init method:
//Create a draw list of a generic wall/ceiling/floor rectangle
//that consists of 100x100 smaller vertexes for smooth lignting
rectList = gl.glGenLists(1);
gl.glNewList(rectList, GL2.GL_COMPILE);
gl.glPushMatrix();
gl.glRotatef(90, 1.0f, 0.0f, 0.0f);
gl.glTranslatef(0.0f, -0.475f, -0.475f);
//gl.glNormal3f(0,0,-1);
//create generic wall vertices on the y-z axis
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
gl.glBegin(GL2.GL_POLYGON);
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, (i / 20.0f) + (0.5f * 0.05f), (j / 20.0f) + (0.5f * 0.05f));
gl.glVertex3f(-0.5f, (i / 20.0f) + (0.5f * 0.05f), (j / 20.0f) + (0.5f * 0.05f));
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, (i / 20.0f) - (0.5f * 0.05f), (j / 20.0f) + (0.5f * 0.05f));
gl.glVertex3f(-0.5f, (i / 20.0f) - (0.5f * 0.05f), (j / 20.0f) + (0.5f * 0.05f));
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, (i / 20.0f) - (0.5f * 0.05f), (j / 20.0f) - (0.5f * 0.05f));
gl.glVertex3f(-0.5f, (i / 20.0f) - (0.5f * 0.05f), (j / 20.0f) - (0.5f * 0.05f));
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, (i / 20.0f) + (0.5f * 0.05f), (j / 20.0f) - (0.5f * 0.05f));
gl.glVertex3f(-0.5f, (i / 20.0f) + (0.5f * 0.05f), (j / 20.0f) - (0.5f * 0.05f));
gl.glEnd();
}
}
and then in the cell:
//Enable and bind the textures to be used for mapping onto the faces
gl.glActiveTexture(GL2.GL_TEXTURE0);
textures[0].enable(gl);
textures[0].bind(gl);
gl.glColor3f(1.0f, 1.0f, 1.0f);
//If a wall of the current maze cell exists, draw it. Repeat for all 4 walls.
//right wall
if (walls[0]) {
gl.glNormal3f(1.0f, 0.0f, 0.0f);
gl.glCallList(rectList);
}
//left wall
if (walls[1]) {
gl.glPushMatrix();
gl.glRotatef(180, 0.0f, 1.0f, 0.0f);
gl.glNormal3f(1.0f, 0.0f, 0.0f);
gl.glCallList(rectList);
gl.glPopMatrix();
}
i just didnt understand… why it use a loop from 0 to 20? every wall have only 4 vertices, so why it’s create so many?
thanks!