开发者

zooming and scrolling texture of image using opengl in android

开发者 https://www.devze.com 2023-02-26 10:09 出处:网络
i want to zoom a image in doubleTap, make it smoothly scrollable, please help me,my draw method is below:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号