在android中使用opengl缩放和滚动图像纹理

发布于 2024-11-01 21:41:49 字数 3852 浏览 0 评论 0原文

我想在 doubleTap 中缩放图像,使其平滑滚动,请帮助我,我的绘制方法如下:

public void draw(GL10 gl) {
    // bind the previously generated texture        
//zooming in  image
    if(Globalconfig.flag==1 && Globalconfig.flag2==true){
        currentVertex=0;
        Globalconfig.b_height=texture.length;
        //Log.d("length",""+Globalconfig.b_height);
        gl.glViewport(0, 0, 444, 555);
        gl.glOrthof(0.0f, 444, 0.0f,555, -0.1f, 0.1f);
        for (int y = 0; y < 10+ 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]*1.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]*1.5f;
                texture[currentVertex]/=1.5f;
                texture[currentVertex+1]/=1.5f;
                currentVertex +=2;
            }
        }

        Globalconfig.flag2=false;
        Log.d("instextureBufferide for", "nhjfghfx" );
                    //vertexBuffer.put(vertices);
        //vertexBuffer.position(0);
        textureBuffer.put(texture);
        textureBuffer.position(0);
} 
//zooming out  image
    //gl.glTranslatef(0,0 , 3);
    if(Globalconfig.flag==2 && Globalconfig.flag2==true){
        currentVertex=0;
        for (int y = 0; y <10 + 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]/3.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]/3.5f;
                texture[currentVertex]*=1.5f;
                texture[currentVertex+1]*=1.5f;
                currentVertex +=2;
            }
        }
        transtaleT=false;
        Globalconfig.flag2=false;
        Log.d("inside for2", "nhjfghfx" );
        //vertexBuffer.put(vertices);
        //vertexBuffer.position(0);
        textureBuffer.put(texture);
        textureBuffer.position(0);
    }       
    if(Globalconfig.transFlag==true && Globalconfig.flag==1  ){
        currentVertex=0;
        for (int y = 0; y < 10+ 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]*3.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]*3.5f;
                texture[currentVertex]+=Globalconfig.x/1000 ;
                texture[currentVertex+1]+=Globalconfig.y/1000;
                currentVertex +=2;
                Globalconfig.x1=(int)Globalconfig.x;
                Globalconfig.y1=(int)Globalconfig.y;
            }
        }
        vertexBuffer.put(vertices);
        vertexBuffer.position(0);
        Log.d("trans", "kjgvgv");
        Globalconfig.transFlag=false;

        Log.d("trans1", "kjgvgv");
    }

    //gl.glViewport(50, 50, 200, 200); 
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    // Point to our buffers
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Set the face rotation
    gl.glFrontFace(GL10.GL_CW);
    // Enable face culling.
    gl.glEnable(GL10.GL_CULL_FACE);
    // What faces to remove with the face culling.
        gl.glCullFace(GL10.GL_CONSTANT_ATTENUATION);
    // Point to our vertex buffer
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT );
    // Draw the vertices as triangle strip
    //gl.glTranslatef(0, 0, -4);
    //gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
    gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices,
            GL10.GL_UNSIGNED_SHORT, indicesBuffer);
    //Disable the client state before leaving
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

i want to zoom a image in doubleTap, make it smoothly scrollable, please help me,my draw method is below:

public void draw(GL10 gl) {
    // bind the previously generated texture        
//zooming in  image
    if(Globalconfig.flag==1 && Globalconfig.flag2==true){
        currentVertex=0;
        Globalconfig.b_height=texture.length;
        //Log.d("length",""+Globalconfig.b_height);
        gl.glViewport(0, 0, 444, 555);
        gl.glOrthof(0.0f, 444, 0.0f,555, -0.1f, 0.1f);
        for (int y = 0; y < 10+ 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]*1.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]*1.5f;
                texture[currentVertex]/=1.5f;
                texture[currentVertex+1]/=1.5f;
                currentVertex +=2;
            }
        }

        Globalconfig.flag2=false;
        Log.d("instextureBufferide for", "nhjfghfx" );
                    //vertexBuffer.put(vertices);
        //vertexBuffer.position(0);
        textureBuffer.put(texture);
        textureBuffer.position(0);
} 
//zooming out  image
    //gl.glTranslatef(0,0 , 3);
    if(Globalconfig.flag==2 && Globalconfig.flag2==true){
        currentVertex=0;
        for (int y = 0; y <10 + 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]/3.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]/3.5f;
                texture[currentVertex]*=1.5f;
                texture[currentVertex+1]*=1.5f;
                currentVertex +=2;
            }
        }
        transtaleT=false;
        Globalconfig.flag2=false;
        Log.d("inside for2", "nhjfghfx" );
        //vertexBuffer.put(vertices);
        //vertexBuffer.position(0);
        textureBuffer.put(texture);
        textureBuffer.position(0);
    }       
    if(Globalconfig.transFlag==true && Globalconfig.flag==1  ){
        currentVertex=0;
        for (int y = 0; y < 10+ 1; y++) {
            for (int x = 0; x <10 + 1; x++) {
                //vertices[currentVertex]=vertices[currentVertex]*3.5f;
                //vertices[currentVertex+1]=vertices[currentVertex+1]*3.5f;
                texture[currentVertex]+=Globalconfig.x/1000 ;
                texture[currentVertex+1]+=Globalconfig.y/1000;
                currentVertex +=2;
                Globalconfig.x1=(int)Globalconfig.x;
                Globalconfig.y1=(int)Globalconfig.y;
            }
        }
        vertexBuffer.put(vertices);
        vertexBuffer.position(0);
        Log.d("trans", "kjgvgv");
        Globalconfig.transFlag=false;

        Log.d("trans1", "kjgvgv");
    }

    //gl.glViewport(50, 50, 200, 200); 
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    // Point to our buffers
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Set the face rotation
    gl.glFrontFace(GL10.GL_CW);
    // Enable face culling.
    gl.glEnable(GL10.GL_CULL_FACE);
    // What faces to remove with the face culling.
        gl.glCullFace(GL10.GL_CONSTANT_ATTENUATION);
    // Point to our vertex buffer
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT );
    // Draw the vertices as triangle strip
    //gl.glTranslatef(0, 0, -4);
    //gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
    gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices,
            GL10.GL_UNSIGNED_SHORT, indicesBuffer);
    //Disable the client state before leaving
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文