CSCI441 OpenGL Library 5.9.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
CSCI441::OpenGLEngine Class Referenceabstract

Abstract Class to run an OpenGL application. The following methods must be overridden:
More...

#include <OpenGLEngine.hpp>

Inheritance diagram for CSCI441::OpenGLEngine:
CSCI441::OpenGL3DEngine

Public Member Functions

 OpenGLEngine (const OpenGLEngine &)=delete
 do not allow engines to be copied
 
OpenGLEngineoperator= (const OpenGLEngine &)=delete
 do not allow engines to be copied
 
virtual void initialize ()
 Initialize everything needed for OpenGL Rendering. This includes in order: GLFW, function pointers, OpenGL, Shader Programs, Buffer Objects, Textures, and any Scene information.
 
virtual void run ()=0
 Initiate the draw loop.
 
virtual void shutdown ()
 Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Scene information, Textures, Buffer Objects, Shader Programs, OpenGL, function pointers, GLFW.
 
virtual void turnDebuggingOn () noexcept final
 Enable logging to command line.
 
virtual void turnDebuggingOff () noexcept final
 Disable logging to command line.
 
virtual bool isDebuggingEnabled () const noexcept final
 Returns if logging is enabled.
 
virtual bool isExtensionEnabled (const std::string EXT) const noexcept final
 Returns if OpenGL extension exists.
 
virtual void setCurrentWindowSize (const int WINDOW_WIDTH, const int WINDOW_HEIGHT) final
 Set the new window size.
 
virtual int getWindowHeight () const noexcept final
 Return the height of the window.
 
virtual int getWindowWidth () const noexcept final
 Return the width of the window.
 
virtual GLFWwindow * getWindow () const noexcept final
 Return the window object.
 
virtual void setWindowShouldClose () final
 Tell our engine's window to close.
 
virtual unsigned short getError () noexcept final
 Return current value of error code and clear the error code back to no error.
 

Static Public Attributes

static const unsigned short OPENGL_ENGINE_ERROR_NO_ERROR = 0
 no error is present, everything is currently working
 
static const unsigned short OPENGL_ENGINE_ERROR_GLFW_INIT = 1
 an error occurred while initializing GLFW
 
static const unsigned short OPENGL_ENGINE_ERROR_GLFW_WINDOW = 2
 an error occurred while creating the GLFW window
 
static const unsigned short OPENGL_ENGINE_ERROR_GLEW_INIT = 3
 an error occurred while initializing GLEW
 
static const unsigned short OPENGL_ENGINE_ERROR_GLAD_INIT = 4
 an error occurred while initializing GLAD
 
static const unsigned short OPENGL_ENGINE_ERROR_UNKNOWN = 5
 a new error that does not correspond to a predefined scenario has occurred
 
static const unsigned short OPENGL_ENGINE_ERROR_LAST = OPENGL_ENGINE_ERROR_UNKNOWN
 stores the error code number of the last possible error, this corresponds to the max error code value.
 
static const unsigned short OPENGL_ENGINE_ERROR_SIZE = OPENGL_ENGINE_ERROR_LAST + 1
 stores the number of unique error codes that can be generated
 

Protected Member Functions

 OpenGLEngine (int OPENGL_MAJOR_VERSION, int OPENGL_MINOR_VERSION, int WINDOW_WIDTH, int WINDOW_HEIGHT, const char *WINDOW_TITLE, bool WINDOW_RESIZABLE=GLFW_FALSE)
 initializes our OpenGL Engine by setting the OpenGL context and GLFW window parameters
 
virtual ~OpenGLEngine ()
 cleans up our OpenGL Engine by destroying the OpenGL context, GLFW window, and cleaning up all GPU resources
 
virtual void mSetupGLFW ()
 Used to setup everything GLFW related. This includes the OpenGL context and our window.

By default, completes the following steps in order:

 
virtual void mSetupOpenGL ()=0
 override to enable specific OpenGL features
 
virtual void mSetupShaders ()
 override to register any shaders with the GPU
 
virtual void mSetupBuffers ()
 override to register any buffer objects with the GPU
 
virtual void mSetupTextures ()
 override to register any textures with the GPU
 
virtual void mSetupScene ()
 override to setup any scene specific information
 
virtual void mCleanupScene ()
 override to cleanup any scene specific information
 
virtual void mCleanupTextures ()
 override to cleanup any textures from the GPU
 
virtual void mCleanupBuffers ()
 override to cleanup any buffer objects from the GPU
 
virtual void mCleanupShaders ()
 override to cleanup any shaders from the GPU
 
virtual void mCleanupOpenGL ()
 override to cleanup any specific OpenGL features
 
virtual void mCleanupGLFW ()
 Destroys the associated GLFW window and terminates the GLFW instance.
 

Static Protected Member Functions

static void mErrorCallback (int error, const char *DESCRIPTION)
 We will register this function as GLFW's error callback. When an error within OpenGL occurs, GLFW will tell us by calling this function. We can then print this info to the terminal to alert the user.
 
static void mDebugMessageCallback (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
 callback called whenever a debug message is signaled
 
static void mWindowResizeCallback (GLFWwindow *pWindow, int width, int height)
 

Protected Attributes

bool DEBUG
 if information should be printed to console while running
 
unsigned int mErrorCode
 tracks the current status of the OpenGL engine via error codes
 
int mOpenGLMajorVersion
 the major version of the requested OpenGL context
 
int mOpenGLMinorVersion
 the minor version of the requested OpenGL context
 
int mWindowWidth
 the window width of the requested GLFW window
 
int mWindowHeight
 the window height of the requested GLFW window
 
bool mWindowResizable
 if the GLFW window can be resized while open
 
char * mWindowTitle
 the title of the GLFW window
 
GLFWwindow * mpWindow
 pointer to the GLFW window object
 

Detailed Description

Abstract Class to run an OpenGL application. The following methods must be overridden:

Constructor & Destructor Documentation

◆ OpenGLEngine()

CSCI441::OpenGLEngine::OpenGLEngine ( int  OPENGL_MAJOR_VERSION,
int  OPENGL_MINOR_VERSION,
int  WINDOW_WIDTH,
int  WINDOW_HEIGHT,
const char *  WINDOW_TITLE,
bool  WINDOW_RESIZABLE = GLFW_FALSE 
)
inlineprotected

initializes our OpenGL Engine by setting the OpenGL context and GLFW window parameters

Parameters
OPENGL_MAJOR_VERSIONOpenGL Major version to request context of (for example 4.X)
OPENGL_MINOR_VERSIONOpenGL Minor version to request context of (for example X.1)
WINDOW_WIDTHwidth of window to request creation of
WINDOW_HEIGHTheight of window to request creation of
WINDOW_TITLEtitle to place on window bar
WINDOW_RESIZABLEif window should be resizable or not (defaults to false)
Note
does not actually create the context nor the window at this time. To do so, call the initialize() method after the object has been created

Member Function Documentation

◆ initialize()

void CSCI441::OpenGLEngine::initialize ( )
inlinevirtual

Initialize everything needed for OpenGL Rendering. This includes in order: GLFW, function pointers, OpenGL, Shader Programs, Buffer Objects, Textures, and any Scene information.

Warning
If this method is overridden, then the parent implementation must be called first as part of the derived implementation

◆ isExtensionEnabled()

virtual bool CSCI441::OpenGLEngine::isExtensionEnabled ( const std::string  EXT) const
inlinefinalvirtualnoexcept

Returns if OpenGL extension exists.

Parameters
EXTname of extension
Returns
true if extension exists, false otherwise

◆ mCleanupBuffers()

virtual void CSCI441::OpenGLEngine::mCleanupBuffers ( )
inlineprotectedvirtual

override to cleanup any buffer objects from the GPU

Note
called after textures have been cleaned up and prior to shaders, OpenGL, or GLFW being cleaned

◆ mCleanupGLFW()

void CSCI441::OpenGLEngine::mCleanupGLFW ( )
inlineprotectedvirtual

Destroys the associated GLFW window and terminates the GLFW instance.

Warning
If this method is overridden, then the parent implementation must be called last as part of the derived implementation
Note
final cleanup method to be called

◆ mCleanupOpenGL()

virtual void CSCI441::OpenGLEngine::mCleanupOpenGL ( )
inlineprotectedvirtual

override to cleanup any specific OpenGL features

Note
called after shaders have been cleaned and prior to GLFW being cleaned

◆ mCleanupScene()

virtual void CSCI441::OpenGLEngine::mCleanupScene ( )
inlineprotectedvirtual

override to cleanup any scene specific information

Note
first cleanup method to be called

◆ mCleanupShaders()

virtual void CSCI441::OpenGLEngine::mCleanupShaders ( )
inlineprotectedvirtual

override to cleanup any shaders from the GPU

Note
called after buffer objects have been cleaned up and prior to OpenGL or GLFW being cleaned

◆ mCleanupTextures()

virtual void CSCI441::OpenGLEngine::mCleanupTextures ( )
inlineprotectedvirtual

override to cleanup any textures from the GPU

Note
called after scene cleanup and prior to any other cleanup processes

◆ mSetupBuffers()

virtual void CSCI441::OpenGLEngine::mSetupBuffers ( )
inlineprotectedvirtual

override to register any buffer objects with the GPU

Note
called after shaders are setup and prior to textures or scene setup has been performed
If overridden, then it is likely that mCleanupBuffers should be overridden as well

◆ mSetupGLFW()

void CSCI441::OpenGLEngine::mSetupGLFW ( )
inlineprotectedvirtual

Used to setup everything GLFW related. This includes the OpenGL context and our window.

By default, completes the following steps in order:

  • sets error callback
  • initializes GLFW
  • sets window hints for OpenGL MAJOR.minor
  • requests Core Profile
  • requests double buffering
  • marks window as resizable or not based on constructor creation
  • creates a window
  • makes the window the current context
  • sets the swap interval to 1
    Note
    This method should be overridden if any additional callbacks need to be registered. When registering additional callbacks, the parent implementation must be called first and then the additional callbacks may be registered as desired.
    If overridden, then it is likely that mCleanupGLFW should be overridden as well
    Sets mErrorCode if process does not complete successfully

◆ mSetupOpenGL()

virtual void CSCI441::OpenGLEngine::mSetupOpenGL ( )
protectedpure virtual

override to enable specific OpenGL features

Note
called after GLFW window is created and OpenGL context is created and prior to any other shader, buffer, texture, or scene setup has been performed
If overridden, then it is likely that mCleanupOpenGL should be overridden as well

◆ mSetupScene()

virtual void CSCI441::OpenGLEngine::mSetupScene ( )
inlineprotectedvirtual

override to setup any scene specific information

Note
final setup method to be called
If overridden, then it is likely that mCleanupScene should be overridden as well

◆ mSetupShaders()

virtual void CSCI441::OpenGLEngine::mSetupShaders ( )
inlineprotectedvirtual

override to register any shaders with the GPU

Note
called after OpenGL features are setup and prior to buffers, textures, or scene setup has been performed
If overridden, then it is likely that mCleanupShaders should be overridden as well

◆ mSetupTextures()

virtual void CSCI441::OpenGLEngine::mSetupTextures ( )
inlineprotectedvirtual

override to register any textures with the GPU

Note
called after buffer objects are setup and prior to scene setup has been performed
If overridden, then it is likely that mCleanupTextures should be overridden as well

◆ mWindowResizeCallback()

void CSCI441::OpenGLEngine::mWindowResizeCallback ( GLFWwindow *  pWindow,
int  width,
int  height 
)
inlinestaticprotected

callback called when GLFW pWindow is resized. internally updated mWindowWidth and mWindowHeight to new values

Parameters
pWindowpointer to the window that was resized
widthnew width of the window
heightnew height of the window

◆ setCurrentWindowSize()

virtual void CSCI441::OpenGLEngine::setCurrentWindowSize ( const int  WINDOW_WIDTH,
const int  WINDOW_HEIGHT 
)
inlinefinalvirtual

Set the new window size.

Parameters
WINDOW_WIDTHwidth of the new window
WINDOW_HEIGHTheight of the new window
Warning
This function does not cause the window to be resized, rather after the window has been resized this function is used to update the data members storing the current window size.

◆ shutdown()

void CSCI441::OpenGLEngine::shutdown ( )
inlinevirtual

Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Scene information, Textures, Buffer Objects, Shader Programs, OpenGL, function pointers, GLFW.

Warning
If this method is overridden, then the parent implementation must be called last as part of the derived implementation

◆ turnDebuggingOff()

virtual void CSCI441::OpenGLEngine::turnDebuggingOff ( )
inlinefinalvirtualnoexcept

Disable logging to command line.

Note
Enabled by default

◆ turnDebuggingOn()

virtual void CSCI441::OpenGLEngine::turnDebuggingOn ( )
inlinefinalvirtualnoexcept

Enable logging to command line.

Note
Enabled by default

Member Data Documentation

◆ DEBUG

bool CSCI441::OpenGLEngine::DEBUG
protected

if information should be printed to console while running

Note
defaults to true

◆ mOpenGLMajorVersion

int CSCI441::OpenGLEngine::mOpenGLMajorVersion
protected

the major version of the requested OpenGL context

Note
may not correspond to the actual OpenGL context created

◆ mOpenGLMinorVersion

int CSCI441::OpenGLEngine::mOpenGLMinorVersion
protected

the minor version of the requested OpenGL context

Note
may not correspond to the actual OpenGL context created

◆ mWindowHeight

int CSCI441::OpenGLEngine::mWindowHeight
protected

the window height of the requested GLFW window

Note
may not correspond to the actual GLFW window created

◆ mWindowResizable

bool CSCI441::OpenGLEngine::mWindowResizable
protected

if the GLFW window can be resized while open

Note
by default false

◆ mWindowWidth

int CSCI441::OpenGLEngine::mWindowWidth
protected

the window width of the requested GLFW window

Note
may not correspond to the actual GLFW window created

The documentation for this class was generated from the following file: