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 310533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:50:32+00:00 2026-05-12T07:50:32+00:00

Since OpenGL is a state machine, I am constantly glEnable() and glDisable()-ing things in

  • 0

Since OpenGL is a state machine, I am constantly glEnable() and glDisable()-ing things in my program. There are a select few calls that I make only at the beginning (such as glClearColor) but most others I flip on and off (like lighting, depending on if I’m rendering a model or 3d text or the gui).

How do you keep track of what state things in? Do you constantly set/reset these things at the top of each function? Isn’t that a lot of unnecessary overhead?

For example, when I write a new function, sometimes I know what state things will be in when the function is called, and I leave out glEnable or glDisable or other related state-switching calls at the top of the function. Other times, I’m just writing the function in advance and I add in these sorts of things. So my functions end up being very messy, some of them modifying OpenGL state and others just making assumptions (that are later broken, and then I have to go back and figure out why something turned yellow or why another thing is upside down, etc.).

How do you keep track of OpenGL across functions in an object oriented environment?


Also related to this question, is how to know when to use push and pop, and when to just set the value.

For example, let’s say you have a program that draws some 3D stuff, then draws some 2D stuff. Obviously the projection matrix is different in each case. So do you:

  1. set up a 3d projection matrix, draw 3D, set up a 2d projection matrix, draw 2d, loop
  2. set up a 3d projection matrix at the program; then draw 3d, push matrix, draw 2d, pop matrix, loop

And why?

  • 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-05-12T07:50:32+00:00Added an answer on May 12, 2026 at 7:50 am

    Great question. Think about how textures work. There are an insane amount of textures for OpenGL to switch between, and you need to enable/disable texturing after every object is drawn. You generally try to optimize this by drawing all objects with the same texture at once, but there’s still a remarkable amount of state-switching that goes on. Because of this fact, I do my best to draw everything with the same state at once, but I’m not sure if it’s terribly important to optimize it the way you’re thinking.

    As for pushing and popping between 3D and 2D projection modes, pushing and popping is intended to be used for hierarchical modeling. If you need your 2D projection to be at a location relative to a 3D object, by all means, push the matrix and switch to 2D projection mode, then pop when you’re done. However, if you’re writing a 2D GUI overlay that has a constant location on the screen, I see no reason why pushing and popping is important.

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

Sidebar

Related Questions

I'm writing a game for school in OpenGL. Since there will be several more
I'm trying to add better UI for an OpenGL-based program with Qt. Since I
Since CS3 doesn't have a web service component, as previous versions had, is there
Since OpenGL ES 2.0 is not backward-compatible to OpenGL ES 1.x because of it's
I'm using OpenTK OpenGL wrapper. Since it loads OpenGL dll (or .so on Linux)
I have an OpenGL ES game that I am hacking together. One part of
In my OpenGL program, I am doing the following in sequence: // Drawing filled
Now that my OpenGL application is getting larger and more complex, I am noticing
So I'm making an Android 2.2 app that uses GLSurfaceView. My question is, since
Since the webgl/opengl doesn't support text drawing, so it possible to draw 3D object

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.