12#ifndef CSCI441_OPENGL_ENGINE_HPP
13#define CSCI441_OPENGL_ENGINE_HPP
16#include "FontUtils.hpp"
17#include "LogUtils.hpp"
20#ifdef CSCI441_USE_GLEW
26#include <GLFW/glfw3.h>
28#ifdef CSCI441_OPENGL_ENGINE_IMPLEMENTATION
29#define STB_IMAGE_WRITE_IMPLEMENTATION
31#include <stb_image_write.h>
91 virtual
void run() = 0;
104 [[maybe_unused]] virtual
bool saveScreenshot(const
char* FILENAME) noexcept final;
126 [[maybe_unused]] [[nodiscard]]
virtual bool isExtensionEnabled(
const std::string EXT)
const noexcept final {
return _extensions.find(EXT) != _extensions.end(); }
157 [[maybe_unused]] [[nodiscard]]
virtual GLFWwindow*
getWindow() const noexcept final {
return mpWindow; }
167 [[nodiscard]]
virtual unsigned short getError() noexcept final {
168 const unsigned short storedErrorCode =
mErrorCode;
173 return storedErrorCode;
237 OpenGLEngine(
int OPENGL_MAJOR_VERSION,
int OPENGL_MINOR_VERSION,
int WINDOW_WIDTH,
int WINDOW_HEIGHT,
const char* WINDOW_TITLE,
bool WINDOW_RESIZABLE = GLFW_FALSE, GLushort NUM_SAMPLES = 0);
331 static void APIENTRY
mDebugMessageCallback(
const GLenum source,
const GLenum type,
const GLuint
id,
const GLenum severity,
const GLsizei length,
const GLchar* message,
const void* userParam) {
332 CSCI441::LogUtils::log(
"[VERBOSE]: Debug Message (%u): source = %s, type = %s, severity = %s, length = %i, message = %s, userParam = %i\n",
334 CSCI441::OpenGLUtils::debugSourceToString(source),
335 CSCI441::OpenGLUtils::debugTypeToString(type),
336 CSCI441::OpenGLUtils::debugSeverityToString(severity),
339 *(
static_cast<const int*
>(userParam))
482 void _setupGLFunctions();
483 void _cleanupGLFunctions() {}
486 void _moveFromSource(OpenGLEngine&);
491 std::set< std::string > _extensions;
493 GLdouble _lastFrameTime;
494 std::deque<GLdouble> _frameTimes;
501 const int OPENGL_MAJOR_VERSION,
502 const int OPENGL_MINOR_VERSION,
503 const int WINDOW_WIDTH,
504 const int WINDOW_HEIGHT,
505 const char* WINDOW_TITLE,
506 const bool WINDOW_RESIZABLE,
507 const GLushort NUM_SAMPLES
509 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
510 mOpenGLMajorVersion(OPENGL_MAJOR_VERSION),
511 mOpenGLMinorVersion(OPENGL_MINOR_VERSION),
512 mOpenGLMajorVersionRequested(OPENGL_MAJOR_VERSION),
513 mOpenGLMinorVersionRequested(OPENGL_MINOR_VERSION),
514 mOpenGLMajorVersionCreated(0),
515 mOpenGLMinorVersionCreated(0),
516 mWindowWidth(WINDOW_WIDTH),
517 mWindowHeight(WINDOW_HEIGHT),
518 mFramebufferWidth(WINDOW_WIDTH),
519 mFramebufferHeight(WINDOW_HEIGHT),
520 mWindowResizable(WINDOW_RESIZABLE),
521 mNumSamplesPerFragment(NUM_SAMPLES),
522 mWindowTitle(nullptr),
524 _isInitialized(false),
530 strncpy(
mWindowTitle, WINDOW_TITLE, strlen(WINDOW_TITLE) + 1);
542 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
543 mOpenGLMajorVersion(0),
544 mOpenGLMinorVersion(0),
545 mOpenGLMajorVersionRequested(0),
546 mOpenGLMinorVersionRequested(0),
547 mOpenGLMajorVersionCreated(0),
548 mOpenGLMinorVersionCreated(0),
551 mFramebufferWidth(0),
552 mFramebufferHeight(0),
553 mWindowResizable(
false),
554 mNumSamplesPerFragment(0),
555 mWindowTitle(
nullptr),
557 _isInitialized(
false),
562 _moveFromSource(src);
572 _moveFromSource(src);
585void CSCI441::OpenGLEngine::_cleanupSelf()
587 delete[] mWindowTitle;
588 mWindowTitle =
nullptr;
592void CSCI441::OpenGLEngine::_moveFromSource(
598 mErrorCode = src.mErrorCode;
599 src.mErrorCode = OPENGL_ENGINE_ERROR_NO_ERROR;
601 mOpenGLMajorVersion = src.mOpenGLMajorVersion;
602 src.mOpenGLMajorVersion = 0;
604 mOpenGLMinorVersion = src.mOpenGLMinorVersion;
605 src.mOpenGLMinorVersion = 0;
607 mOpenGLMajorVersionRequested = src.mOpenGLMajorVersionRequested;
608 src.mOpenGLMajorVersionRequested = 0;
610 mOpenGLMinorVersionRequested = src.mOpenGLMinorVersionRequested;
611 src.mOpenGLMinorVersionRequested = 0;
613 mOpenGLMajorVersionCreated = src.mOpenGLMajorVersionCreated;
614 src.mOpenGLMajorVersionCreated = 0;
616 mOpenGLMinorVersionCreated = src.mOpenGLMinorVersionCreated;
617 src.mOpenGLMinorVersionCreated = 0;
619 mWindowWidth = src.mWindowWidth;
620 src.mWindowWidth = 0;
622 mWindowHeight = src.mWindowHeight;
623 src.mWindowHeight = 0;
625 mWindowResizable = src.mWindowResizable;
626 src.mWindowResizable =
false;
628 mNumSamplesPerFragment = src.mNumSamplesPerFragment;
629 src.mNumSamplesPerFragment = 0;
631 mWindowTitle = src.mWindowTitle;
632 src.mWindowTitle =
nullptr;
634 mpWindow = src.mpWindow;
635 src.mpWindow =
nullptr;
637 _isInitialized = src._isInitialized;
638 src._isInitialized =
false;
640 _isCleanedUp = src._isCleanedUp;
641 src._isCleanedUp =
false;
643 _extensions = std::move(src._extensions);
649 if( !_isInitialized ) {
650 const std::chrono::steady_clock::time_point initBegin = std::chrono::steady_clock::now();
653 CSCI441::LogUtils::log(
"[INFO]: Using CSCI441 Library v%d.%d.%d.%d\n", CSCI441::VERSION_MAJOR, CSCI441::VERSION_MINOR, CSCI441::VERSION_REVISION, CSCI441::VERSION_PATCH);
656 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
658 glfwGetFramebufferSize( mpWindow, &mFramebufferWidth, &mFramebufferHeight );
659 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
661 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
666 if (mNumSamplesPerFragment > 0) {
667 glEnable(GL_MULTISAMPLE);
669 glDisable(GL_MULTISAMPLE);
675 if( mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3) ) {
677 int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
678 if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
680 glEnable(GL_DEBUG_OUTPUT);
681 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
682 glDebugMessageCallback(mDebugMessageCallback,
nullptr);
683 glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE );
687 CSCI441::OpenGLUtils::printOpenGLInfo();
689 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
690 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupOpenGL()");
692 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
694 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
695 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupShaders()");
697 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
699 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
700 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupBuffers()");
702 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
704 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
705 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupTextures()");
707 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
709 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
710 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupFonts()");
712 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
714 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
715 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupScene()");
717 _isInitialized =
true;
718 _isCleanedUp =
false;
720 const std::chrono::steady_clock::time_point initEnd = std::chrono::steady_clock::now();
723 CSCI441::LogUtils::log(
"[INFO]: Init Time: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(initEnd - initBegin ).count() ) / 1000000.0);
724 CSCI441::LogUtils::log(
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
725 CSCI441::LogUtils::log(
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
726 CSCI441::LogUtils::log(
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
727 CSCI441::LogUtils::log(
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
728 CSCI441::LogUtils::log(
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
729 CSCI441::LogUtils::log(
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
730 CSCI441::LogUtils::log(
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
737 const unsigned short ERROR_CODE
739 switch (ERROR_CODE) {
740 case OPENGL_ENGINE_ERROR_NO_ERROR:
return "No error";
741 case OPENGL_ENGINE_ERROR_GLFW_INIT:
return "Error initializing GLFW";
742 case OPENGL_ENGINE_ERROR_GLFW_WINDOW:
return "Error initializing GLFW window";
743 case OPENGL_ENGINE_ERROR_GLEW_INIT:
return "Error initializing GLEW";
744 case OPENGL_ENGINE_ERROR_GLAD_INIT:
return "Error initializing GLAD";
745 case OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT:
return "Error saving screenshot";
746 default:
return "Unknown error code";
755 const std::string filename =
758 ?
"Screenshot_" + std::to_string(time(
nullptr)) +
".png"
764 glGetIntegerv(GL_VIEWPORT, viewport);
765 const GLsizei x = viewport[0], y = viewport[1], width = viewport[2], height = viewport[3];
768 constexpr int CHANNELS = 4;
769 const auto bytes =
new GLubyte[width*height*CHANNELS];
770 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
772 stbi_flip_vertically_on_write(
true);
774 if( !stbi_write_png(filename.c_str(), width, height, CHANNELS, bytes, width*CHANNELS) ) {
776 mErrorCode = OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT;
783 return (mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR);
792 glfwSetErrorCallback(mErrorCallback);
797 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_INIT;
799 if(DEBUG)
CSCI441::LogUtils::log(
"[INFO]: GLFW v%d.%d.%d initialized\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION );
801 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, mOpenGLMajorVersion );
802 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, mOpenGLMinorVersion );
803 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
804 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
805 glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE );
806 glfwWindowHint(GLFW_RESIZABLE, mWindowResizable );
807 glfwWindowHint(GLFW_SAMPLES, mNumSamplesPerFragment);
811 && (mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3)) ) {
812 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT,
true);
816 mpWindow = glfwCreateWindow(mWindowWidth, mWindowHeight, mWindowTitle,
nullptr,
nullptr );
820 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_WINDOW;
823 glfwMakeContextCurrent(mpWindow);
825 glfwSetInputMode(mpWindow, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
826 glfwSetWindowUserPointer(mpWindow, (
void*)
this);
827 glfwSetWindowSizeCallback(mpWindow, mWindowResizeCallback);
828 glfwSetFramebufferSizeCallback(mpWindow, mWindowResizeCallback);
834void CSCI441::OpenGLEngine::_setupGLFunctions()
837#ifdef CSCI441_USE_GLEW
838 glewExperimental = GL_TRUE;
839 const GLenum glewResult = glewInit();
842 if( glewResult != GLEW_OK ) {
845 mErrorCode = OPENGL_ENGINE_ERROR_GLEW_INIT;
849 CSCI441::LogUtils::log(
"[INFO]: Using GLEW %s\n",
reinterpret_cast<const char *
>(glewGetString(GLEW_VERSION)));
853 int version = gladLoadGL(glfwGetProcAddress);
856 mErrorCode = OPENGL_ENGINE_ERROR_GLAD_INIT;
860 CSCI441::LogUtils::log(
"[INFO]: GLAD initialized v%d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
865 if(mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR) {
866 glGetIntegerv(GL_MAJOR_VERSION, &mOpenGLMajorVersionCreated);
867 glGetIntegerv(GL_MINOR_VERSION, &mOpenGLMinorVersionCreated);
869 CSCI441::LogUtils::log(
"[INFO]: OpenGL v%d.%d requested\n", mOpenGLMajorVersionRequested, mOpenGLMinorVersionRequested);
870 CSCI441::LogUtils::log(
"[INFO]: OpenGL v%d.%d created\n", mOpenGLMajorVersionCreated, mOpenGLMinorVersionCreated);
873 GLint numExtensions = 0;
874 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
875 for (
int i = 0; i < numExtensions; i++) {
876 _extensions.insert(
reinterpret_cast<const char *
>(glGetStringi(GL_EXTENSIONS, i)) );
885 glfwDestroyWindow(mpWindow );
894 if( !_isCleanedUp ) {
895 const std::chrono::steady_clock::time_point shutdownBegin = std::chrono::steady_clock::now();
898 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
900 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
901 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupScene()");
903 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
905 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
906 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupFonts()");
908 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
910 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
911 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupTextures()");
913 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
915 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
916 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupBuffers()");
918 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
920 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
921 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupShaders()");
923 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
925 _cleanupGLFunctions();
926 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
927 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupOpenGL()");
929 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
931 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
933 const std::chrono::steady_clock::time_point shutdownEnd = std::chrono::steady_clock::now();
936 CSCI441::LogUtils::log(
"[INFO]: Shutdown: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shutdownEnd - shutdownBegin).count() ) / 1000000.0);
937 CSCI441::LogUtils::log(
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
938 CSCI441::LogUtils::log(
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
939 CSCI441::LogUtils::log(
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
940 CSCI441::LogUtils::log(
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
941 CSCI441::LogUtils::log(
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
942 CSCI441::LogUtils::log(
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
943 CSCI441::LogUtils::log(
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
946 _isInitialized =
false;
956 const auto pEngine =
static_cast<OpenGLEngine *
>(glfwGetWindowUserPointer(pWindow));
968 const auto pEngine =
static_cast<OpenGLEngine *
>(glfwGetWindowUserPointer(pWindow));
984 const GLdouble currentTime = glfwGetTime();
986 GLdouble fps = ( !_frameTimes.empty() ? _frameTimes.back() : 0.0 );
987 if (currentTime - _lastFrameTime > 0.1667) {
988 fps =
static_cast<GLdouble
>(_numFrames)/(currentTime - _lastFrameTime);
990 _lastFrameTime = currentTime;
992 if (_frameTimes.size() >= 10) _frameTimes.pop_front();
993 _frameTimes.push_back( fps );
1000 GLdouble totalFPS = 0;
1001 for(
const auto& fpsUnit : _frameTimes ) {
1002 totalFPS += fpsUnit;
1004 return totalFPS /
static_cast<GLdouble
>(_frameTimes.size());
Helper functions to work with OpenGL 3.0+.
Abstract Class to run an OpenGL application. The following methods must be overridden:
Definition: OpenGLEngine.hpp:53
virtual void mSetupOpenGL()=0
override to enable specific OpenGL features
virtual bool isExtensionEnabled(const std::string EXT) const noexcept final
Returns if OpenGL extension exists.
Definition: OpenGLEngine.hpp:126
bool DEBUG
if information should be printed to console while running
Definition: OpenGLEngine.hpp:243
OpenGLEngine & operator=(const OpenGLEngine &)=delete
do not allow engines to be copied
int mFramebufferWidth
the framebuffer height of the requested GLFW window
Definition: OpenGLEngine.hpp:295
int mOpenGLMinorVersion
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:259
int mOpenGLMajorVersion
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:254
static constexpr unsigned short OPENGL_ENGINE_ERROR_NO_ERROR
no error is present, everything is currently working
Definition: OpenGLEngine.hpp:179
virtual bool saveScreenshot(const char *FILENAME) noexcept final
Save a PNG screenshot of the viewport.
Definition: OpenGLEngine.hpp:751
virtual void setCurrentWindowSize(const int WINDOW_WIDTH, const int WINDOW_HEIGHT) final
Stores the new window size.
Definition: OpenGLEngine.hpp:136
virtual void initialize()
Initialize everything needed for OpenGL Rendering. This includes in order: GLFW, function pointers,...
Definition: OpenGLEngine.hpp:647
virtual void shutdown()
Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Sc...
Definition: OpenGLEngine.hpp:892
virtual unsigned short getError() noexcept final
Return current value of error code and clear the error code back to no error.
Definition: OpenGLEngine.hpp:167
virtual void mSetupTextures()
override to register any textures with the GPU
Definition: OpenGLEngine.hpp:406
virtual int getWindowHeight() const noexcept final
Return the height of the window.
Definition: OpenGLEngine.hpp:149
virtual bool isDebuggingEnabled() const noexcept final
Returns if logging is enabled.
Definition: OpenGLEngine.hpp:119
static void mWindowResizeCallback(GLFWwindow *pWindow, int width, int height)
Definition: OpenGLEngine.hpp:951
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLAD_INIT
an error occurred while initializing GLAD
Definition: OpenGLEngine.hpp:195
virtual void mCleanupBuffers()
override to cleanup any buffer objects from the GPU
Definition: OpenGLEngine.hpp:439
virtual void mCleanupScene()
override to cleanup any scene specific information
Definition: OpenGLEngine.hpp:424
virtual void mSetupFonts()
override to register any fonts with the GPU
Definition: OpenGLEngine.hpp:412
virtual void setCurrentFramebufferSize(const int FRAMEBUFFER_WIDTH, const int FRAMEBUFFER_HEIGHT) final
Stores the framebuffer size.
Definition: OpenGLEngine.hpp:145
virtual void mCleanupShaders()
override to cleanup any shaders from the GPU
Definition: OpenGLEngine.hpp:444
virtual void mCleanupTextures()
override to cleanup any textures from the GPU
Definition: OpenGLEngine.hpp:434
virtual GLdouble clockFrame() final
measures the amount of time elapsed since the last time this method was called
Definition: OpenGLEngine.hpp:983
bool mWindowResizable
if the GLFW window can be resized while open
Definition: OpenGLEngine.hpp:304
int mOpenGLMinorVersionRequested
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:271
GLushort mNumSamplesPerFragment
how many samples to fire per fragment
Definition: OpenGLEngine.hpp:310
OpenGLEngine(const OpenGLEngine &)=delete
do not allow engines to be copied
static constexpr unsigned short OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT
an error occurred while taking a screenshot
Definition: OpenGLEngine.hpp:199
int mFramebufferHeight
the framebuffer width of the requested GLFW window
Definition: OpenGLEngine.hpp:299
virtual void turnDebuggingOn() noexcept final
Enable logging to command line.
Definition: OpenGLEngine.hpp:110
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLEW_INIT
an error occurred while initializing GLEW
Definition: OpenGLEngine.hpp:191
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_WINDOW
an error occurred while creating the GLFW window
Definition: OpenGLEngine.hpp:187
virtual void mCleanupFonts()
override to cleanup any fonts from the GPU
Definition: OpenGLEngine.hpp:429
int mOpenGLMajorVersionRequested
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:265
static void mErrorCallback(const int error, const char *DESCRIPTION)
We will register this function as GLFW's error callback. When an error within OpenGL occurs,...
Definition: OpenGLEngine.hpp:326
static constexpr unsigned short OPENGL_ENGINE_ERROR_LAST
stores the error code number of the last possible error, this corresponds to the max error code value...
Definition: OpenGLEngine.hpp:211
unsigned int mErrorCode
tracks the current status of the OpenGL engine via error codes
Definition: OpenGLEngine.hpp:248
virtual void run()=0
Initiate the draw loop.
static void APIENTRY mDebugMessageCallback(const GLenum source, const GLenum type, const GLuint id, const GLenum severity, const GLsizei length, const GLchar *message, const void *userParam)
callback called whenever a debug message is signaled
Definition: OpenGLEngine.hpp:331
static void mFramebufferResizeCallback(GLFWwindow *pWindow, int width, int height)
Definition: OpenGLEngine.hpp:963
char * mWindowTitle
the title of the GLFW window
Definition: OpenGLEngine.hpp:314
int mWindowHeight
the window height of the requested GLFW window
Definition: OpenGLEngine.hpp:291
virtual GLdouble fpsAverage() final
Definition: OpenGLEngine.hpp:999
virtual void setWindowShouldClose() final
Tell our engine's window to close.
Definition: OpenGLEngine.hpp:162
int mOpenGLMajorVersionCreated
the major version of the created OpenGL context
Definition: OpenGLEngine.hpp:276
static constexpr unsigned short OPENGL_ENGINE_ERROR_SIZE
stores the number of unique error codes that can be generated
Definition: OpenGLEngine.hpp:215
virtual void mReloadShaders() final
calls mCleanupShaders() followed by mSetupShaders() to reload shader source code from file
Definition: OpenGLEngine.hpp:973
virtual void mSetupShaders()
override to register any shaders with the GPU
Definition: OpenGLEngine.hpp:394
GLFWwindow * mpWindow
pointer to the GLFW window object
Definition: OpenGLEngine.hpp:318
virtual void turnDebuggingOff() noexcept final
Disable logging to command line.
Definition: OpenGLEngine.hpp:115
static const char * getErrorStringDescription(unsigned short ERROR_CODE) noexcept
Returns a string describing what the error code corresponds to.
Definition: OpenGLEngine.hpp:736
virtual int getWindowWidth() const noexcept final
Return the width of the window.
Definition: OpenGLEngine.hpp:153
virtual void mSetupBuffers()
override to register any buffer objects with the GPU
Definition: OpenGLEngine.hpp:400
virtual ~OpenGLEngine()
cleans up our OpenGL Engine by destroying the OpenGL context, GLFW window, and cleaning up all GPU re...
Definition: OpenGLEngine.hpp:579
virtual void mCleanupGLFW()
Destroys the associated GLFW window and terminates the GLFW instance.
Definition: OpenGLEngine.hpp:882
int mOpenGLMinorVersionCreated
the minor version of the created OpenGL context
Definition: OpenGLEngine.hpp:281
int mWindowWidth
the window width of the requested GLFW window
Definition: OpenGLEngine.hpp:286
virtual void mCleanupOpenGL()
override to cleanup any specific OpenGL features
Definition: OpenGLEngine.hpp:449
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_INIT
an error occurred while initializing GLFW
Definition: OpenGLEngine.hpp:183
virtual void mSetupGLFW()
Used to setup everything GLFW related. This includes the OpenGL context and our window....
Definition: OpenGLEngine.hpp:787
virtual void mSetupScene()
override to setup any scene specific information
Definition: OpenGLEngine.hpp:418
static constexpr unsigned short OPENGL_ENGINE_ERROR_UNKNOWN
a new error that does not correspond to a predefined scenario has occurred
Definition: OpenGLEngine.hpp:203
virtual GLFWwindow * getWindow() const noexcept final
Return the window object.
Definition: OpenGLEngine.hpp:157
void setFontSize(GLfloat scaleX, GLfloat scaleY)
set the amount to scale font when drawing
Definition: FontUtils.hpp:180
void setWindowSize(GLint width, GLint height)
store the size of the window
Definition: FontUtils.hpp:172
void log(const char *MSG,...)
log a message to both the standard output stream and file
Definition: LogUtils.hpp:116
void logError(const char *MSG,...)
log a message to both the standard error stream and file
Definition: LogUtils.hpp:128
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17