Opengl ES缩放(缩小)在我的纹理上显示罕见的方形瓷砖.如何避免它



我正在显示一个带有纹理的OPENGL ES 1.X正方形,用户可以放大和缩小正方形缩放它。

当用户缩小正方形时(正方形在屏幕上缩放得

变小),正方形的纹理会得到罕见的半透明正方形,就像谷歌地图中的瓷砖一样。

我认为 OpenGL 的缩放功能现在以更好的方式工作。

我该如何改进它?

这些是我的OpenGL GLSurfaceView主要功能:

    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        
    }

这些是我的方形多边形类的主要函数:

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();
}   

求解:

        //Creamos filtros de texturas
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NICEST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NICEST); 
    //Diferentes parametros de textura posibles GL10.GL_CLAMP_TO_EDGE
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_NICEST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_NICEST); 

最新更新