ImFusion C++ SDK 4.4.0

Using OpenGL within the ImFusion SDK. More...

Collaboration diagram for OpenGL:

Detailed Description

Using OpenGL within the ImFusion SDK.

Note
This page mainly describes high-level OpenGL aspects. See OpenGL Wrapper Library for low-level wrapper and helper classes for working with OpenGL.
See also
OpenGL Wrapper Library, Rendering Custom Graphics

OpenGL Function Bindings

The ImFusionLib comes with OpenGL core bindings and will resolve the OpenGL function pointers during SDK initialization. Thus, you do not need to use an extra library for this such as GLEW, gl3w or glad. If you want to use low-level OpenGL functionality, please use the following include

#include <ImFusion/Core/GL/glad.h>

Availability of OpenGL Contexts

Generally, the following restriction apply to OpenGL:

  • All OpenGL calls need a current (active) OpenGL context when executed.
  • Each thread may have a maximum of one current OpenGL context.
  • Each OpenGL context may be current in one thread at a time.

Since the ImFusion SDK makes extensive usage of OpenGL it maintains its own set of OpenGL contexts.

  • The main context: Initialized by Framework::init() and bound to the main thread (the thread that called Framework::init() / instantiated a ApplicationController). All rendering and processing that is performed on the main thread (e.g. DisplayWidget, single-threaded Algorithms launched from the main thread, ...) will use this context. SDK code running on the SDK main thread can always assume presence of this OpenGL context and must never leave a state with no or a different current context.
  • The background context: Initialized and managed by GL::ContextManager; bound to GL::ContextManager's background processing thread. It is provided as convenience interface and will be used by GL::ContextManager::runWithOpenGL() when called from any non-OpenGL thread.

You can maintain your own OpenGL contexts if you require OpenGL in a separate thread as long as you ensure that the main and background threads of the ImFusion SDK keep their corresponding contexts current.

See also
GL::ContextManager, ImFusion SDK Threading Model

Default OpenGL State

Since OpenGL 3.3 the OpenGL attribute stack (glPushAttrib()/glPopAttrib()) is deprecated. You can use the GL::StateGuard interface as alternative to manage changes to the OpenGL state. Furthermore, make sure to set the following settings back to its default values in case you change them:

  • GL_DEPTH_DEST: disabled
  • glDepthFunc: GL_LESS
  • glClearDepth: 1.0
  • GL_BLEND: disabled
  • glBlendFunc: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
  • GL_SCISSOR_TEST: disabled

All other OpenGL state settings can not be expected to be in any specific state, hence you have to make sure to set them explicitly. It is good practice to clean up after yourself, i.e. restore the original OpenGL state after you're done.

Loading Custom OpenGL Shaders

See GLSL Shaders and GL::Program.

Font Rendering

See GL::TextRenderer.

Namespaces

namespace  ImFusion::GlUtils
 Utility functions for working with OpenGL and/or GlImages.
Search Tab / S to search, Esc to close