Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: glScalef and glRotatef

  1. #1
    Newbie Newbie
    Join Date
    Jul 2013

    glScalef and glRotatef

    I want to use glScalef to zoom, but if after I use glRotatef, the image is cut.

    This is the code:

    glMatrixMode (GL_MODELVIEW);
    **** glLoadIdentity ();
    **** glScalef (scale, scale, scale);
    **** glRotatef (rot_x, 1.0,0.0,0.0);
    **** glRotatef (rot_y, 0.0,1.0,0.0);
    **** glRotatef (rot_z, 0.0,0.0,1.0);

    What can I do to make them compatible?

    Thank you.
    Last edited by SilviaLollipop; 07-03-2013 at 05:51 AM.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2006
    Without quite understanding what your issue is, you could try moving the glScalef after the glRotatef commands.


  3. #3
    Newbie Newbie
    Join Date
    Jul 2013
    Thank you, but I have the same problem.
    My problem is that if I do scale and rotate my image is cut, i canīt see all the image

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    You probably need to adjust your near + far clipping planes. For more details on OpenGL transformations, see + read about the projection matrix.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2013
    I would start out by putting the scaling after the rotations. I'm not sure what you mean by "the image is cut", but the way you have things set up, currently you will be scaling the rotations that come after it.

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Montreal, Canada
    I would do zoom on the projection matrix. If you want a perspective matrix, use glFrustum. If you want a orthogonal matrix, use glOrtho.
    In both cases, the idea is the same. To zoom in, lower the values for {left, right, bottom, top} by a certain factor of your choice.

    If you do want to proceed with your method, the scale function should be the last operation.
    You can think of these operations as starting from bottom to top. Scale happens first, then the rotations.
    glLoadIdentity ();
    **** glRotatef (rot_x, 1.0,0.0,0.0);
    **** glRotatef (rot_y, 0.0,1.0,0.0);
    **** glRotatef (rot_z, 0.0,0.0,1.0);
    **** glScalef (scale, scale, scale);
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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