Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:57:52+00:00 2026-06-03T07:57:52+00:00

I draw several 2D shapes using OpenGL and now I want to add the

  • 0

I draw several 2D shapes using OpenGL and now I want to add the pinch/zoom. My view is perspective (top view). I assumed that it’s 3D with z axis = 0.

Now, how should I change glfrustum and add on a touch method in my activity so that I could be able to pinch/zoom?

gl.glFrustumf(-ratio, ratio, -1, 1, 1, 25);

I think it should be something like

gl.glFrustumf(-ratio, ratio, -1, 1, 1*zoom, 25*zoom);

but how should the touch method be written to change this zoom parameter for doing two finger zoom?

the problem is rendrer right now , I add zoom method at the end , but in zoom method it gives me error with gl.glfrustum while on onsurfacechanged it does not give me error with the same thing ! how could I fix that ?

public class GLrenderer implements Renderer {
    public GLqueue tri;
    public GLrenderer() {
        tri = new GLqueue();


    }


    public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
        // TODO Auto-generated method stub
        gl.glDisable(GL10.GL_DITHER);
        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
        gl.glClearColor(.0f, .0f, .0f, 0f);
        gl.glClearDepthf(1f);
    }


    public void onDrawFrame(GL10 gl) {
        // TODO Auto-generated method stub
        gl.glDisable(GL10.GL_DITHER);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_COLOR_BUFFER_BIT);

        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        GLU.gluLookAt(gl, 0, 0, -5, 0, 0, 0, 0, 2, 0);

        //gl.glRotatef(1, 1, 0, 0);
    //  gl.glRotatef(10, 0, 0, 1);
        tri.draw(gl);

    }

    public void onSurfaceChanged(GL10 gl, int width, int height ) {
        // TODO Auto-generated method stub
        gl.glViewport(0, 0, width, height);
        float ratio = (float) width / height;
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();

        gl.glFrustumf(-ratio, ratio, -1, 1, 1, 25);
    }

    public static void zoom(float d2) {
        // TODO Auto-generated method stub
          int zoom = (int) (zoom*d2);

                gl.glFrustumf(-ratio, ratio, -1, 1, 1*zoom, 25*zoom);

    }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:57:53+00:00Added an answer on June 3, 2026 at 7:57 am

    If you have some float value that determines your zoom, you can use this:

    glFrustum(left*zoom, right*zoom, bottom*zoom, top*zoom, near, far);
    

    Here is an example:

    excerpt from the OnTouchListener

    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction()){
        case MotionEvent.ACTION_DOWN:
            pointers = 1;
            return true;
        case MotionEvent.ACTION_POINTER_2_DOWN:
            pointers = 2;
            distance = fingerDist(event);
            return true;
        case MotionEvent.ACTION_MOVE:
            if( pointers == 2 ){
                float newDist = fingerDist(event);
                float d = distance/newDist;
                renderer.zoom(d);
                distance = newDist;
            }
            return true;
        default:
            return false;
        }
    
        }
    
    protected final float fingerDist(MotionEvent event){
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return FloatMath.sqrt(x * x + y * y);
    }
    

    From the renderer:

    public final void zoom(float mult){
        zoom *= mult;
        Matrix.frustumM(
                pMatrix, 0, 
                zoom*left, zoom*right, zoom*bottom, zoom*top, 
                near, far);
    }
    

    Note that this code is written for gles 2.0 rather then 1.0, so instead of calling Matrix.frustumM() you would call gl.glFrustumf(). You might possibly have to post this operation to your gl-thread for it to work properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw shapes on mobile screens via touch that define a closed
I want to draw several shapes (over 40) for separated zones in a city
I want to draw several cubes using glutSolidCube in some points in space. The
I want to draw several pie charts to my site using the Google Charts
I am drawing several shapes (such as circles) that are keyed off of the
I have overridden the drawRect: in my UIView and I want to draw several
Several answers mention to use GradientDrawable.setDither(true) to draw smooth gradients in Android. That has
I have a PDF file that I want to draw in outline form. I
How to draw several separate lines using a single VBO?
I have several geo points witch I want to use to draw a route

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.