Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Windows Tip - OpenGL ► «««« 15 / 18 »»»»

Function glPushMatrix() and glPopMatrix() well explained!?


The OpenGL functions `glPushMatrix();` and `glPopMatrix();` are used to save and restore the current transformation matrix . They help isolate transformations (such as scaling, translation, or rotation) so that changes within a specific range do not affect other objects.







1. How it works:
2. Example: Use for hierarchical transformation
3. Why are `glPushMatrix();` and `glPopMatrix();` important?







1.) How it works:



1. `glPushMatrix();` (Put matrix on the stack)

- Stores the current model-view matrix on an internal stack.

- Changes to the matrix after `glPushMatrix();` only affect the new transformations.

- This ensures that previous transformations are not permanently changed.

2. `glPopMatrix();` (Pop matrix from stack) - Restores

the last saved model-view matrix

. - All transformations performed after `glPushMatrix();` are undone.

- This ensures that other objects are not affected by previous transformations.







2.) Example: Use for hierarchical transformation



void renderScene () {
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glLoadIdentity () ;

// First object ( e.g., a static cube) glPushMatrix
( ) ;   // Saves current matrix
glTranslatef ( -1.0f , 0.0f , -6.0f ) ;   // Moves cube
drawCube () ;   // Draws the cube
glPopMatrix () ;   // Restores the previous matrix

// Second object (e.g. a spinning wheel)
glPushMatrix () ;
glTranslatef ( 1. 0f, 0. 0f, - 6. 0f ) ;   // Position of the wheel
glRotatef ( angle, 0. 0f, 0. 0f, 1. 0f ) ;   // Rotates the wheel
drawWheel () ;   // Draws the wheel
glPopMatrix () ;   // Restores the previous matrix

glutSwapBuffers () ;
}







3.) Why are `glPushMatrix();` and `glPopMatrix();` important?




- They prevent transformations from affecting all subsequent objects.

- They make it easier to work with hierarchical structures (e.g., a robot with arms and legs).

- Without them, you would have to manually undo each transformation, which would be complicated and error-prone.

Note:

These functions are part of OpenGL's fixed function pipeline (deprecated as of OpenGL 3.0). In modern versions of OpenGL, transformations are controlled via shaders and matrices .





Updated on: 12 April 2025 20:42 Windows
Keywords: opengl, function, glpushmatrix, glpopmatrix, well, explained, functions, used, save, restore, current, transformation, matrix, they, help, isolate, transformations


Similar information on the page

Windows

... glMatrix with Javascript, mat2, mat3, mat4, vec2, vec3, vec4, ...


It is easy to work with vectors and matrices using glMatrix based on Javascript, e.g. mat2, mat3, mat4, vec2, vec3, vec4, glMatrix is ​​designed to
Windows

... OpenGL occlusion culling system?


Like all culling algorithms, these are all a kind of bounding box of the scene to test it all at once Typically, a buffer is encoded that contains all the
Windows

... Tell me about IEEE 754, floating point precision and decimal point?


The IEEE 754 standard is the globally recognized standard for representing floating-point numbers in computers. It governs both the formatting and precision
Windows

... Using OpenGL Frame Buffers and advantages?


In OpenGL you can use frame buffers and benefit from post-processing, comparing, to improve quality or save time  A frame buffer in OpenGL is a structure
Windows

... gl_FragDepth Manipulation, deception and effects


The perspective version of optical illusion is great, but the problem remains until an object touches the ground or another object 1. The first example
Windows

... OpenGL or DirectX - remove projection distortion


Whether in OpenGL, DirectX, or other 3D solutions, projection distortion is an annoying and unsightly behavior when calculating and projecting onto the screen
Windows

... Xbox is the only platform that doesnt support OpenGL, why?


Yes, the main reason the Xbox doesnt support OpenGL is Microsofts strategic decision to promote DirectX as the preferred and exclusive graphics API for



▲ Back to the top ▲



... OpenGL Tip



3D.Benchmark.OK # AlwaysMouseWheel # AutoHideDesktopIcons # AutoPowerOptionsOK # ClassicDesktopClock # DesktopDigitalClock # DesktopNoteOK # DesktopOK # DontSleep # Edge-Chromium # ExperienceIndexOK # Find.Same.Images.OK # FontViewOK # GetPixelColor # GetWindowText # Internet # IsMyHdOK # KeepMouseSpeedOK # NewFileTime # OpenCloseDriveEject # OpenGL # PhotoResizerOK # Q-Dir # QuickMemoryTestOK # QuickTextPaste # Registry # ShortDoorNote # StressMyPC # System # TheAeroClock # Tools # Version # WinScan2PDF #




  

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks
  + Security

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + Q-Dir
  + DirPrintOK
  + FontViewOK
  + MeinPlatz
  + DesktopOK
  + IsMyMemoryOK
  + StressTheGPU
  + Brightness.Manager.OK
  + PaintOkay
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Settings | Windows 10 | gc24b | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2025 by Nenad Hrg ERR2: softwareok.de • softwareok.com • softwareok.com • softwareok.eu
56.473 msec.


>> ☕ Buy SoftwareOK a Coffee ☕ <<



► Where can I find the settings for Facebook ads? ◄
► Direct Download free antivirus software for Windows from Microsoft (7,8,Vista,xp)! ◄
► How can I get rid of the Desktop Pixel Query Software on Windows 11, 10, ...? ◄
► Hard disk is formatted with XFS format! ◄


This website does not store personal data. However, third-party providers are used to display ads,
which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF).
The CMP ID is 300 and can be individually customized at the bottom of the page.
more Infos & Privacy Policy

....