Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Zoom with OpenGL

  1. #11
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    7
    It's better to post the code now, It is write in java but the functions are totally identical:

    private void render(GLAutoDrawable drawable){
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFF ER_BIT);
    gl.glEnable(GL.GL_DEPTH_TEST|GL2.GL_NORMALIZE);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glDepthFunc(GL.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

    gl.glPushMatrix(); //I push the matrix before draw
    gl.glTranslatef(0, 0, nord) //I Translate the object

    //Green Side - FIRST RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 0.0f, 1.0f, 0.0f );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    //Yellow Side - SECOND RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 1.0f, 1.0f, 0.0f );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    //Red Side - THIRD RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 1.0f, 0.0f, 0.0f );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    //Blue Side - FORTH RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 0.0f, 0.0f, 1.0f );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( 0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    //White Side - FIFTH RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 1.0f, 1.0f, 1.0f );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( 0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    //Grey Side - SIXTH RECTANGLE
    gl.glBegin(GL2.GL_POLYGON);
    gl.glColor3f( 0.5f, 0.5f, 0.5f );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, 0.35f+nord );
    gl.glVertex3f( -0.25f+est, 0.125f+altitudine, -0.35f+nord );
    gl.glVertex3f( -0.25f+est, -0.125f+altitudine, -0.35f+nord );
    gl.glEnd();

    gl.glFlush();

    gl.glRotatef(gyrox, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(gyroy, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(gyroz, 0.0f, 0.0f, 1.0f);

    gl.glFlush();

    gl.glPopMatrix(); //I pop the matrix after draw
    gl.glFlush();
    }

    If I do that and nord = 1.5 I can't see anything. If instead nord = 1.1 I see the object but it seems not bigger.

  2. #12
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    7
    The reason that happens is because you do not have a projection matrix set up. By default it is using orthographic projection and does not have perspective, all non-normalized coordinates are clipped (this is why 1.1 - 0.35 works but 1.5 - 0.35 does not). There are also a several other things that should be fixed.

    I would recommend you to read a tutorial about OpenGL matrices. Understanding them is essential. Once you understand how matrices work you should be able to fix this program easily.

  3. #13
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    7
    YEAH! thank you for the tutorial I'm fixing the program using both gluPerspective() and glTranslated(). Now I do some tests. Thank you very much!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •