Hi

I'm displaying a OPENGL ES 1.X square with a texture, and the user can zoom 
in and out the square scaling it.

When the user zoom's out the square (the square get's scaled going smaller 
in the screen) the texture of the square get's rare translucent squares, 
like tiles from googlemaps.

I think that the scaling function from OpenGL is now working in the better 
way.

How can i improve it?

These are my OpenGL GLSurfaceView main functions:

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        gl.glDisable(GL10.GL_DITHER);               //dithering OFF
        gl.glEnable(GL10.GL_TEXTURE_2D);            //Texture Mapping ON
        gl.glShadeModel(GL10.GL_SMOOTH);            //Smooth Shading 
        gl.glClearDepthf(1.0f);                     //Depth Buffer Setup
        gl.glEnable(GL10.GL_DEPTH_TEST);            //Depth Testing ON
        gl.glDepthFunc(GL10.GL_LEQUAL);
        gl.glClearColor(0,0,0,0);                   //fondo transparente
        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);         

        //Cargamos la textura del cubo.     
        for (int i=0;i<squares.size();i++){         
            if (squares.get(i)!=null)
                squares.get(i).loadGLTexture(gl, context);
        }
    }

public void onDrawFrame(GL10 gl) {  
        //Limpiamos pantalla y Depth Buffer
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();

        mg.getCurrentProjection(gl); //volvemos a generar las matrices por que 
es un bucle
        mg.getCurrentModelView(gl); 
.
.
.
.
        gl.glTranslatef(X, Y, Z); //Move z units into the screen        
        gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f); //Z               
        gl.glScalef(scale, scale, 1.0f);

        for (int i=0;i<squares.size();i++){
            if (squares.get(i)!=null)
                squares.get(i).draw(gl); //Draw the Cube        
        }
    }

public void onSurfaceChanged(GL10 gl, int width, int height) {
        if(height == 0) {                       //Prevent A Divide By Zero By
            height = 1;                         //Making Height Equal One
        }

        gl.glViewport(0, 0, width, height);     //Reset The Current Viewport
        gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection Matrix
        gl.glLoadIdentity();                    //Reset The Projection Matrix

        //Calculate The Aspect Ratio Of The Window
        GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 
100.0f);

        gl.glMatrixMode(GL10.GL_MODELVIEW);     //Select The Modelview Matrix
        gl.glLoadIdentity();                    //Reset The Modelview Matrix    
    
    }

and these are my square polygon class main functions:

public void draw(GL10 gl) {         
    gl.glFrontFace(GL10.GL_CCW);
    //Bind our only previously generated texture in this case       
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);      
    //Point to our vertex buffer
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    //Enable vertex buffer
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    //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);
}

//Carga de texturas
public void loadGLTexture(GL10 gl, Context context) {       
    //Generamos un puntero de texturas
    gl.glDeleteTextures(1, textures, 0); //libero memoria
    gl.glGenTextures(1, textures, 0);       
    //y se lo asignamos a nuestro array
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    //Creamos filtros de texturas
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, 
GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, 
GL10.GL_LINEAR);
    //Diferentes parametros de textura posibles GL10.GL_CLAMP_TO_EDGE
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, 
GL10.GL_REPEAT);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, 
GL10.GL_REPEAT);     

    //Usamos Android GLUtils para espcificar una textura de 2 dimensiones para 
nuestro bitmap
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 

    //Checkeamos si el GL context es versión 1.1 y generamos los Mipmaps por 
Flag. Si no, llamamos a nuestra propia implementación
    if(gl instanceof GL11) {
        gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, 
GL11.GL_TRUE);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    } else {
        buildMipmap(gl, bitmap);
    }   
    //Limpiamos los bitmaps
    bitmap.recycle();       
    bitmap=null;
    System.gc();
}   

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to