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 (%d): source = %s, type = %s, severity = %s, message = %s\n",
334 CSCI441::OpenGLUtils::debugSourceToString(source),
335 CSCI441::OpenGLUtils::debugTypeToString(type),
336 CSCI441::OpenGLUtils::debugSeverityToString(severity),
480 void _setupGLFunctions();
481 void _cleanupGLFunctions() {}
484 void _moveFromSource(OpenGLEngine&);
489 std::set< std::string > _extensions;
491 GLdouble _lastFrameTime;
492 std::deque<GLdouble> _frameTimes;
499 const int OPENGL_MAJOR_VERSION,
500 const int OPENGL_MINOR_VERSION,
501 const int WINDOW_WIDTH,
502 const int WINDOW_HEIGHT,
503 const char* WINDOW_TITLE,
504 const bool WINDOW_RESIZABLE,
505 const GLushort NUM_SAMPLES
507 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
508 mOpenGLMajorVersion(OPENGL_MAJOR_VERSION),
509 mOpenGLMinorVersion(OPENGL_MINOR_VERSION),
510 mOpenGLMajorVersionRequested(OPENGL_MAJOR_VERSION),
511 mOpenGLMinorVersionRequested(OPENGL_MINOR_VERSION),
512 mOpenGLMajorVersionCreated(0),
513 mOpenGLMinorVersionCreated(0),
514 mWindowWidth(WINDOW_WIDTH),
515 mWindowHeight(WINDOW_HEIGHT),
516 mFramebufferWidth(WINDOW_WIDTH),
517 mFramebufferHeight(WINDOW_HEIGHT),
518 mWindowResizable(WINDOW_RESIZABLE),
519 mNumSamplesPerFragment(NUM_SAMPLES),
520 mWindowTitle(nullptr),
522 _isInitialized(false),
528 strncpy(
mWindowTitle, WINDOW_TITLE, strlen(WINDOW_TITLE) + 1);
540 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
541 mOpenGLMajorVersion(0),
542 mOpenGLMinorVersion(0),
543 mOpenGLMajorVersionRequested(0),
544 mOpenGLMinorVersionRequested(0),
545 mOpenGLMajorVersionCreated(0),
546 mOpenGLMinorVersionCreated(0),
549 mFramebufferWidth(0),
550 mFramebufferHeight(0),
551 mWindowResizable(
false),
552 mNumSamplesPerFragment(0),
553 mWindowTitle(
nullptr),
555 _isInitialized(
false),
560 _moveFromSource(src);
570 _moveFromSource(src);
583void CSCI441::OpenGLEngine::_cleanupSelf()
585 delete[] mWindowTitle;
586 mWindowTitle =
nullptr;
590void CSCI441::OpenGLEngine::_moveFromSource(
596 mErrorCode = src.mErrorCode;
597 src.mErrorCode = OPENGL_ENGINE_ERROR_NO_ERROR;
599 mOpenGLMajorVersion = src.mOpenGLMajorVersion;
600 src.mOpenGLMajorVersion = 0;
602 mOpenGLMinorVersion = src.mOpenGLMinorVersion;
603 src.mOpenGLMinorVersion = 0;
605 mOpenGLMajorVersionRequested = src.mOpenGLMajorVersionRequested;
606 src.mOpenGLMajorVersionRequested = 0;
608 mOpenGLMinorVersionRequested = src.mOpenGLMinorVersionRequested;
609 src.mOpenGLMinorVersionRequested = 0;
611 mOpenGLMajorVersionCreated = src.mOpenGLMajorVersionCreated;
612 src.mOpenGLMajorVersionCreated = 0;
614 mOpenGLMinorVersionCreated = src.mOpenGLMinorVersionCreated;
615 src.mOpenGLMinorVersionCreated = 0;
617 mWindowWidth = src.mWindowWidth;
618 src.mWindowWidth = 0;
620 mWindowHeight = src.mWindowHeight;
621 src.mWindowHeight = 0;
623 mWindowResizable = src.mWindowResizable;
624 src.mWindowResizable =
false;
626 mNumSamplesPerFragment = src.mNumSamplesPerFragment;
627 src.mNumSamplesPerFragment = 0;
629 mWindowTitle = src.mWindowTitle;
630 src.mWindowTitle =
nullptr;
632 mpWindow = src.mpWindow;
633 src.mpWindow =
nullptr;
635 _isInitialized = src._isInitialized;
636 src._isInitialized =
false;
638 _isCleanedUp = src._isCleanedUp;
639 src._isCleanedUp =
false;
641 _extensions = std::move(src._extensions);
647 if( !_isInitialized ) {
648 const std::chrono::steady_clock::time_point initBegin = std::chrono::steady_clock::now();
651 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);
654 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
656 glfwGetFramebufferSize( mpWindow, &mFramebufferWidth, &mFramebufferHeight );
657 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
659 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
664 if (mNumSamplesPerFragment > 0) {
665 glEnable(GL_MULTISAMPLE);
667 glDisable(GL_MULTISAMPLE);
673 if( mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3) ) {
675 int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
676 if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
678 glEnable(GL_DEBUG_OUTPUT);
679 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
680 glDebugMessageCallback(mDebugMessageCallback,
nullptr);
681 glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE );
685 CSCI441::OpenGLUtils::printOpenGLInfo();
687 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
688 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupOpenGL()");
690 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
692 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
693 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupShaders()");
695 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
697 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
698 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupBuffers()");
700 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
702 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
703 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupTextures()");
705 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
707 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
708 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupFonts()");
710 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
712 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
713 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupScene()");
715 _isInitialized =
true;
716 _isCleanedUp =
false;
718 const std::chrono::steady_clock::time_point initEnd = std::chrono::steady_clock::now();
721 CSCI441::LogUtils::log(
"[INFO]: Init Time: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(initEnd - initBegin ).count() ) / 1000000.0);
722 CSCI441::LogUtils::log(
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
723 CSCI441::LogUtils::log(
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
724 CSCI441::LogUtils::log(
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
725 CSCI441::LogUtils::log(
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
726 CSCI441::LogUtils::log(
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
727 CSCI441::LogUtils::log(
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
728 CSCI441::LogUtils::log(
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
735 const unsigned short ERROR_CODE
737 switch (ERROR_CODE) {
738 case OPENGL_ENGINE_ERROR_NO_ERROR:
return "No error";
739 case OPENGL_ENGINE_ERROR_GLFW_INIT:
return "Error initializing GLFW";
740 case OPENGL_ENGINE_ERROR_GLFW_WINDOW:
return "Error initializing GLFW window";
741 case OPENGL_ENGINE_ERROR_GLEW_INIT:
return "Error initializing GLEW";
742 case OPENGL_ENGINE_ERROR_GLAD_INIT:
return "Error initializing GLAD";
743 case OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT:
return "Error saving screenshot";
744 default:
return "Unknown error code";
753 const std::string filename =
756 ?
"Screenshot_" + std::to_string(time(
nullptr)) +
".png"
762 glGetIntegerv(GL_VIEWPORT, viewport);
763 const GLsizei x = viewport[0], y = viewport[1], width = viewport[2], height = viewport[3];
766 constexpr int CHANNELS = 4;
767 const auto bytes =
new GLubyte[width*height*CHANNELS];
768 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
770 stbi_flip_vertically_on_write(
true);
772 if( !stbi_write_png(filename.c_str(), width, height, CHANNELS, bytes, width*CHANNELS) ) {
774 mErrorCode = OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT;
781 return (mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR);
790 glfwSetErrorCallback(mErrorCallback);
795 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_INIT;
797 if(DEBUG)
CSCI441::LogUtils::log(
"[INFO]: GLFW v%d.%d.%d initialized\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION );
799 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, mOpenGLMajorVersion );
800 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, mOpenGLMinorVersion );
801 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
802 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
803 glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE );
804 glfwWindowHint(GLFW_RESIZABLE, mWindowResizable );
805 glfwWindowHint(GLFW_SAMPLES, mNumSamplesPerFragment);
809 && (mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3)) ) {
810 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT,
true);
814 mpWindow = glfwCreateWindow(mWindowWidth, mWindowHeight, mWindowTitle,
nullptr,
nullptr );
818 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_WINDOW;
821 glfwMakeContextCurrent(mpWindow);
823 glfwSetInputMode(mpWindow, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
824 glfwSetWindowUserPointer(mpWindow, (
void*)
this);
825 glfwSetWindowSizeCallback(mpWindow, mWindowResizeCallback);
826 glfwSetFramebufferSizeCallback(mpWindow, mWindowResizeCallback);
832void CSCI441::OpenGLEngine::_setupGLFunctions()
835#ifdef CSCI441_USE_GLEW
836 glewExperimental = GL_TRUE;
837 const GLenum glewResult = glewInit();
840 if( glewResult != GLEW_OK ) {
843 mErrorCode = OPENGL_ENGINE_ERROR_GLEW_INIT;
847 CSCI441::LogUtils::log(
"[INFO]: Using GLEW %s\n",
reinterpret_cast<const char *
>(glewGetString(GLEW_VERSION)));
851 int version = gladLoadGL(glfwGetProcAddress);
854 mErrorCode = OPENGL_ENGINE_ERROR_GLAD_INIT;
858 CSCI441::LogUtils::log(
"[INFO]: GLAD initialized v%d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
863 if(mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR) {
864 glGetIntegerv(GL_MAJOR_VERSION, &mOpenGLMajorVersionCreated);
865 glGetIntegerv(GL_MINOR_VERSION, &mOpenGLMinorVersionCreated);
867 CSCI441::LogUtils::log(
"[INFO]: OpenGL v%d.%d requested\n", mOpenGLMajorVersionRequested, mOpenGLMinorVersionRequested);
868 CSCI441::LogUtils::log(
"[INFO]: OpenGL v%d.%d created\n", mOpenGLMajorVersionCreated, mOpenGLMinorVersionCreated);
871 GLint numExtensions = 0;
872 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
873 for (
int i = 0; i < numExtensions; i++) {
874 _extensions.insert(
reinterpret_cast<const char *
>(glGetStringi(GL_EXTENSIONS, i)) );
883 glfwDestroyWindow(mpWindow );
892 if( !_isCleanedUp ) {
893 const std::chrono::steady_clock::time_point shutdownBegin = std::chrono::steady_clock::now();
896 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
898 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
899 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupScene()");
901 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
903 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
904 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupFonts()");
906 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
908 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
909 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupTextures()");
911 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
913 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
914 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupBuffers()");
916 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
918 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
919 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupShaders()");
921 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
923 _cleanupGLFunctions();
924 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
925 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupOpenGL()");
927 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
929 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
931 const std::chrono::steady_clock::time_point shutdownEnd = std::chrono::steady_clock::now();
934 CSCI441::LogUtils::log(
"[INFO]: Shutdown: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shutdownEnd - shutdownBegin).count() ) / 1000000.0);
935 CSCI441::LogUtils::log(
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
936 CSCI441::LogUtils::log(
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
937 CSCI441::LogUtils::log(
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
938 CSCI441::LogUtils::log(
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
939 CSCI441::LogUtils::log(
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
940 CSCI441::LogUtils::log(
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
941 CSCI441::LogUtils::log(
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
944 _isInitialized =
false;
954 const auto pEngine =
static_cast<OpenGLEngine *
>(glfwGetWindowUserPointer(pWindow));
966 const auto pEngine =
static_cast<OpenGLEngine *
>(glfwGetWindowUserPointer(pWindow));
982 const GLdouble currentTime = glfwGetTime();
984 GLdouble fps = ( !_frameTimes.empty() ? _frameTimes.back() : 0.0 );
985 if (currentTime - _lastFrameTime > 0.1667) {
986 fps =
static_cast<GLdouble
>(_numFrames)/(currentTime - _lastFrameTime);
988 _lastFrameTime = currentTime;
990 if (_frameTimes.size() >= 10) _frameTimes.pop_front();
991 _frameTimes.push_back( fps );
998 GLdouble totalFPS = 0;
999 for(
const auto& fpsUnit : _frameTimes ) {
1000 totalFPS += fpsUnit;
1002 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:749
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:645
virtual void shutdown()
Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Sc...
Definition: OpenGLEngine.hpp:890
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:404
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:949
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:437
virtual void mCleanupScene()
override to cleanup any scene specific information
Definition: OpenGLEngine.hpp:422
virtual void mSetupFonts()
override to register any fonts with the GPU
Definition: OpenGLEngine.hpp:410
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:442
virtual void mCleanupTextures()
override to cleanup any textures from the GPU
Definition: OpenGLEngine.hpp:432
virtual GLdouble clockFrame() final
measures the amount of time elapsed since the last time this method was called
Definition: OpenGLEngine.hpp:981
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:427
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:961
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:997
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:971
virtual void mSetupShaders()
override to register any shaders with the GPU
Definition: OpenGLEngine.hpp:392
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:734
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:398
virtual ~OpenGLEngine()
cleans up our OpenGL Engine by destroying the OpenGL context, GLFW window, and cleaning up all GPU re...
Definition: OpenGLEngine.hpp:577
virtual void mCleanupGLFW()
Destroys the associated GLFW window and terminates the GLFW instance.
Definition: OpenGLEngine.hpp:880
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:447
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:785
virtual void mSetupScene()
override to setup any scene specific information
Definition: OpenGLEngine.hpp:416
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