XPLMSetGraphicsState

XPLM_API void       XPLMSetGraphicsState(
                         int                  inEnableFog,
                         int                  inNumberTexUnits,
                         int                  inEnableLighting,
                         int                  inEnableAlphaTesting,
                         int                  inEnableAlphaBlending,
                         int                  inEnableDepthTesting,
                         int                  inEnableDepthWriting);

XPLMSetGraphicsState changes OpenGL’s fixed function pipeline state. You are not responsible for restoring any state that is accessed via XPLMSetGraphicsState, but you are responsible for not accessing this state directly.

  • inEnableFog - enables or disables fog, equivalent to: glEnable(GL_FOG);
  • inNumberTexUnits - enables or disables a number of multitexturing units. If the number is 0, 2d texturing is disabled entirely, as in glDisable(GL_TEXTURE_2D); Otherwise, 2d texturing is enabled, and a number of multitexturing units are enabled sequentially, starting with unit 0, e.g. glActiveTextureARB(GL_TEXTURE0_ARB); glEnable (GL_TEXTURE_2D);
  • inEnableLighting - enables or disables OpenGL lighting, e.g. glEnable(GL_LIGHTING); glEnable(GL_LIGHT0);
  • inEnableAlphaTesting - enables or disables the alpha test per pixel, e.g. glEnable(GL_ALPHA_TEST);
  • inEnableAlphaBlending - enables or disables alpha blending per pixel, e.g. glEnable(GL_BLEND);
  • inEnableDepthTesting - enables per pixel depth testing, as in glEnable(GL_DEPTH_TEST);
  • inEnableDepthWriting - enables writing back of depth information to the depth buffer, as in glDepthMask(GL_TRUE);

The purpose of this function is to change OpenGL state while keeping X-Plane aware of the state changes; this keeps X-Plane from getting surprised by OGL state changes, and prevents X-Plane and plug-ins from having to set all state before all draws; XPLMSetGraphicsState internally skips calls to change state that is already properly enabled.

X-Plane does not have a ‘default’ OGL state for plug-ins with respect to the above state vector; plug-ins should totally set OGL state using this API before drawing. Use XPLMSetGraphicsState instead of any of the above OpenGL calls.

WARNING: Any routine that performs drawing (e.g. XPLMDrawString or widget code) may change X-Plane’s state. Always set state before drawing after unknown code has executed.

Deprecation Warnings: X-Plane’s lighting and fog environment is significantly more complex than the fixed function pipeline can express; do not assume that lighting and fog state is a good approximation for 3-d drawing. Prefer to use XPLMInstancing to draw objects. All calls to XPLMSetGraphicsState should have no fog or lighting.