Android OpenGL ES simple tile generator performance issue

following this question: Best approach for playing the tree-like bilingual version of oldschool

Thanks to the previous answers and with great inspiration from http://insanitydesign.com/wp/projects/nehe-android-ports/ , I started creating a simple tile generator for my simple 2D zelda-like game project.

Now I can create a map with the same textured tile, using 2 for (..) fixed iterations to draw horizontal and vertical tiles, and get some basic DPAD key input listeners to scroll along the x and y axis.

but now I am facing my first performance issues, with only one texture and one model.

When you try to build a 10x10 map, the scroll will be beautiful and smooth.

When you try with 50x50, everything gets worse, and with 100x100 it’s unacceptable.

Is there a way to tell OpenGL about the “visible” part of my map set and ignore hidden fragments? im brand new to this.

im using

GLU.gluLookAt(gl, cameraPosX, cameraPosY, 10.0f,cameraPosX, cameraPosY, 0.0f, 0.0f, 1.0f, 0.0f);

to set the camera and point of view for a 2D feel.

Any help? :)

for (int j = 0; j < 10; j++) {

        for (int i = 0; i < 10; i++) {

            gl.glPushMatrix(); // Sauvegarde la matrice sur le stack

            //Bind the texture according to the set texture filter
            gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
            //Set the face rotation
            gl.glFrontFace(GL10.GL_CW);
            //Enable texture state
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
            //Enable vertex state
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
            //Point to our vertex buffer
            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
            //point to our texture buff
            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
            //Draw the vertices as triangle strip
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
            //Disable the client state before leaving
            gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

            gl.glTranslatef(1.0f, 0.0f, 0.0f); // on avance d'une tile
        }
        // on va commencer a dessiner la 2e ligne
        gl.glPopMatrix(); // Rappelle la matrice sur le stack
        gl.glTranslatef(0.0f, -1.0f, 0.0f);
    }
+2
source share
2 answers

You can easily make your cycle by drawing only the visible aria. Here is an example of how to do this. I do not know the android API, so write my example as a metacode.

int cols = SCREEN_WIDTH / TILE_SIZE + 1;      // how many columns can fit on the screen
int rows = SCREEN_HEIGHT / TILE_SIZE + 1;     // haw many rows can fit on the screen
int firstVisibleCol = cameraPosX / TILE_SIZE; // first column we need to draw
int firstVisibleRow = cameraPosY / TILE_SIZE; // first row we need to draw

// and now the loop becomes
for (int j = firstVisibleRow; j < rows; j++) {
    for (int i = firstVisibleCol ; i < cols; i++) {
        ...
    }
}
+2
source

, , , OpenGL . , .

, gl , . OpenGL, .

, glBindTexture , . , . . , .

, glDrawArrays. .

, , . , glDrawArrays ( glDrawElements). , Google, .

+3

All Articles