10. OpenGL Scaling
Posted on : 25-03-2010 | By : Swiftless | In : OpenGL
Tags: glut, OpenGL, programming, scale, scaling, tutorial
4
If you have worked with vectors before, you will know already that
scaling is simply stretching an object a certain amount.
Say we have an object, but we want it twice the height, we will
have to scale (stretch) it to twice the current height, along the y axis.
I am using:
glScalef(2, 0.5, 1);
in my display function.
If you look at the scale function on its own it takes:
The amount you want to stretch it on the:
x axis
y axis
z axis
In that order.
So I am stretching my cube, 2 times along the x axis, 0.5 times along the
y axis, and 1 time on the z axis.
So it will come out, twice as long, half as high, and the same depth.
And that is all there is to scaling, it is one of the very basic commands
in OpenGL.
If there are any problems with this code, please email me at swiftless@gmail.com
| 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. | #include <GL/gl.h> #include <GL/glut.h> GLfloat angle = 0.0; void cube (void) { void display (void) { void reshape (int w, int h) { int main (int argc, char **argv) {
|
Related posts:







the scale functions seems to be applying on both cubes, I tried adding glScalef( 1.0, 1.0, 1.0) before the rotation lines of second cube but both cubes get scaled
Hi Imrn,
Yes, anything you do will be applied to all the following shapes unless you use glPushMatrix and glPopMatrix, which are mentioned in a later tutorial.
Cheers,
Swiftless
Thanks for the feedback.
I have noticed some issues with the code, this is all fixed in the new versions of the tutorials, once I get around to writing them all that is.
Cheers,
Swiftless
Great tutorial! Like the page’s design too
A minor gripe though: Some of the comments are split up by line breaks. You should use /**/ comments instead.