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

Abstract Class to run an OpenGL application with a 3D environment.

Creates and contains a default ArcballCam implementation, tracks the status of the left mouse button, shift key, and mouse position.

The following methods must be overridden:
More...

#include <OpenGL3DEngine.hpp>

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

Public Member Functions

 OpenGL3DEngine (const OpenGL3DEngine &)=delete
 do not allow engines to be copied
 
OpenGL3DEngineoperator= (const OpenGL3DEngine &)=delete
 do not allow engines to be copied
 
virtual GLboolean isLeftMouseDown () const noexcept final
 the status of the left mouse button being down
 
virtual void setLeftMouseDown (GLboolean isDown) final
 set the status of the left mouse button being down
 
virtual GLboolean isShiftDown () const noexcept final
 the status of either shift key being down
 
virtual void setShiftDown (GLboolean isDown) final
 set the status of the shift keys being down
 
virtual glm::vec2 getMousePosition () const noexcept final
 the location of the mouse within the window
 
virtual void setMousePosition (glm::vec2 mousePos) final
 set the location of the mouse within the window
 
virtual void setArcballCameraAngles (glm::vec3 angles) final
 sets the object space position of the arcball camera in spherical world coordinates
 
virtual glm::vec3 getArcballCameraEyePoint () const noexcept final
 the world space position the arcball camera is located at
 
virtual glm::vec3 getArcballCameraLookAtPoint () const noexcept final
 the world space position the arcball camera is looking at and thus centered around
 
virtual void setArcballCameraLookAtPoint (glm::vec3 lookAtPoint) final
 set the world space position the arcball camera is looking at and thus centered around
 
virtual glm::vec3 getArcballCameraUpVector () const noexcept final
 the world space vector the arcball camera is oriented upwards along
 
virtual void setArcballCameraUpVector (glm::vec3 upVector) final
 sets the world space vector the arcball camera is oriented upwards along
 
virtual glm::mat4 getArcballProjectionMatrix () const final
 returns the current projection matrix for the arcball camera
 
virtual glm::mat4 getArcballViewMatrix () const final
 returns the current view matrix for the arcball camera
 
virtual void addToArcballCameraAngles (glm::vec3 angleAdditions) final
 moves the arcball spherical object space coordinate by the associated amounts
 
virtual void updateArcballCameraDirection () final
 recomputes the arcball camera's world space position
 
virtual void handleCameraCursorPosEvent (double x, double y) final
 moves camera for active cursor movement
 
virtual void handleCameraKeyEvent (int key, int scancode, int action, int mods) final
 tracks if either shift key is currently being pressed
 
virtual void handleCameraMouseButtonEvent (int button, int action, int mods) final
 tracks left mouse button state
 
virtual void handleCameraScrollEvent (double xOffset, double yOffset)
 zooms camera inward/outward based on scroll direction
 
void handleCameraAspectRatioEvent (int width, int height)
 resizes camera aspect ratio
 
- Public Member Functions inherited from CSCI441::OpenGLEngine
 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.
 

Protected Member Functions

 OpenGL3DEngine (int OPENGL_MAJOR_VERSION, int OPENGL_MINOR_VERSION, int WINDOW_WIDTH, int WINDOW_HEIGHT, const char *WINDOW_TITLE, bool WINDOW_RESIZABLE=GLFW_FALSE)
 creates OpenGLEngine for given context and window state as well as creating a default arcball camera and setting the shift + left mouse button to be up
 
 ~OpenGL3DEngine () override
 cleans up OpenGL 3D Engine by deleting arcball camera object
 
- Protected Member Functions inherited from 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)
 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.
 

Protected Attributes

CSCI441::ArcballCammpArcballCamera
 pointer to the ArcballCam object
 
GLboolean mIsShiftDown
 if either shift key (left or right) is currently pressed
 
GLboolean mIsLeftMouseDown
 if the mouse left button is currently pressed
 
glm::vec2 mMousePosition
 current mouse position in screen space
 
- Protected Attributes inherited from CSCI441::OpenGLEngine
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
 

Additional Inherited Members

- Static Public Attributes inherited from CSCI441::OpenGLEngine
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
 
- Static Protected Member Functions inherited from CSCI441::OpenGLEngine
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)
 

Detailed Description

Abstract Class to run an OpenGL application with a 3D environment.

Creates and contains a default ArcballCam implementation, tracks the status of the left mouse button, shift key, and mouse position.

The following methods must be overridden:

Constructor & Destructor Documentation

◆ OpenGL3DEngine()

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

creates OpenGLEngine for given context and window state as well as creating a default arcball camera and setting the shift + left mouse button to be up

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

◆ addToArcballCameraAngles()

virtual void CSCI441::OpenGL3DEngine::addToArcballCameraAngles ( glm::vec3  angleAdditions)
inlinefinalvirtual

moves the arcball spherical object space coordinate by the associated amounts

Parameters
angleAdditions(theta, phi, radius) to add to existing spherical object space coordinate

◆ getArcballCameraEyePoint()

virtual glm::vec3 CSCI441::OpenGL3DEngine::getArcballCameraEyePoint ( ) const
inlinefinalvirtualnoexcept

the world space position the arcball camera is located at

Returns
(x, y, z) world space position of the arcball camera

◆ getArcballCameraLookAtPoint()

virtual glm::vec3 CSCI441::OpenGL3DEngine::getArcballCameraLookAtPoint ( ) const
inlinefinalvirtualnoexcept

the world space position the arcball camera is looking at and thus centered around

Returns
(x, y, z) world space position the arcball is looking at and centered around

◆ getArcballCameraUpVector()

virtual glm::vec3 CSCI441::OpenGL3DEngine::getArcballCameraUpVector ( ) const
inlinefinalvirtualnoexcept

the world space vector the arcball camera is oriented upwards along

Returns
<x, y, z> world space vector the arcball is oriented upwards along

◆ getArcballProjectionMatrix()

virtual glm::mat4 CSCI441::OpenGL3DEngine::getArcballProjectionMatrix ( ) const
inlinefinalvirtual

returns the current projection matrix for the arcball camera

Returns
homogeneous projection matrix

◆ getArcballViewMatrix()

virtual glm::mat4 CSCI441::OpenGL3DEngine::getArcballViewMatrix ( ) const
inlinefinalvirtual

returns the current view matrix for the arcball camera

Returns
homogeneous view matrix

◆ getMousePosition()

virtual glm::vec2 CSCI441::OpenGL3DEngine::getMousePosition ( ) const
inlinefinalvirtualnoexcept

the location of the mouse within the window

Returns
(x, y) coordinate in screen space of the mouse

◆ handleCameraAspectRatioEvent()

void CSCI441::OpenGL3DEngine::handleCameraAspectRatioEvent ( int  width,
int  height 
)
inline

resizes camera aspect ratio

Parameters
widthnew camera frame width
heightnew camera frame height

◆ handleCameraCursorPosEvent()

virtual void CSCI441::OpenGL3DEngine::handleCameraCursorPosEvent ( double  x,
double  y 
)
inlinefinalvirtual

moves camera for active cursor movement

Parameters
xcurrent cursor x coordinate in screen space
ycurrent cursor y coordinate in screen space

◆ handleCameraKeyEvent()

virtual void CSCI441::OpenGL3DEngine::handleCameraKeyEvent ( int  key,
int  scancode,
int  action,
int  mods 
)
inlinefinalvirtual

tracks if either shift key is currently being pressed

Parameters
keykey that triggered event
scancodeunused
actionaction for corresponding key (pressed, released, repeat)
modsunused

◆ handleCameraMouseButtonEvent()

virtual void CSCI441::OpenGL3DEngine::handleCameraMouseButtonEvent ( int  button,
int  action,
int  mods 
)
inlinefinalvirtual

tracks left mouse button state

Parameters
buttonmouse button that triggered event
actionaction for corresponding mouse button (pressed or released)
modsunused

◆ handleCameraScrollEvent()

virtual void CSCI441::OpenGL3DEngine::handleCameraScrollEvent ( double  xOffset,
double  yOffset 
)
inlinevirtual

zooms camera inward/outward based on scroll direction

Parameters
xOffsetunused
yOffsetvertical amount scrolled

◆ isLeftMouseDown()

virtual GLboolean CSCI441::OpenGL3DEngine::isLeftMouseDown ( ) const
inlinefinalvirtualnoexcept

the status of the left mouse button being down

Returns
true if left mouse button is currently being pressed, false otherwise

◆ isShiftDown()

virtual GLboolean CSCI441::OpenGL3DEngine::isShiftDown ( ) const
inlinefinalvirtualnoexcept

the status of either shift key being down

Returns
true if either shift key is currently being pressed, false otherwise

◆ setArcballCameraAngles()

virtual void CSCI441::OpenGL3DEngine::setArcballCameraAngles ( glm::vec3  angles)
inlinefinalvirtual

sets the object space position of the arcball camera in spherical world coordinates

Parameters
angles(theta, phi, radius) spherical object space coordinate

◆ setArcballCameraLookAtPoint()

virtual void CSCI441::OpenGL3DEngine::setArcballCameraLookAtPoint ( glm::vec3  lookAtPoint)
inlinefinalvirtual

set the world space position the arcball camera is looking at and thus centered around

Parameters
lookAtPoint(x, y, z) world space position the arcball is looking at and centered around

◆ setArcballCameraUpVector()

virtual void CSCI441::OpenGL3DEngine::setArcballCameraUpVector ( glm::vec3  upVector)
inlinefinalvirtual

sets the world space vector the arcball camera is oriented upwards along

Parameters
upVector<x, y, z> world space vector the arcball is oriented upwards along

◆ setLeftMouseDown()

virtual void CSCI441::OpenGL3DEngine::setLeftMouseDown ( GLboolean  isDown)
inlinefinalvirtual

set the status of the left mouse button being down

Parameters
isDownset to true if the left mouse button is currently being pressed, false otherwise

◆ setMousePosition()

virtual void CSCI441::OpenGL3DEngine::setMousePosition ( glm::vec2  mousePos)
inlinefinalvirtual

set the location of the mouse within the window

Parameters
mousePos(x, y) coordinate in screen space of the mouse

◆ setShiftDown()

virtual void CSCI441::OpenGL3DEngine::setShiftDown ( GLboolean  isDown)
inlinefinalvirtual

set the status of the shift keys being down

Parameters
isDownset to true if either shift key is currently being pressed, false otherwise

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