12#ifndef CSCI441_OPENGL_ENGINE_HPP
13#define CSCI441_OPENGL_ENGINE_HPP
16#include "FontUtils.hpp"
19#ifdef CSCI441_USE_GLEW
25#include <GLFW/glfw3.h>
27#ifdef CSCI441_OPENGL_ENGINE_IMPLEMENTATION
28#define STB_IMAGE_WRITE_IMPLEMENTATION
30#include <stb_image_write.h>
90 virtual
void run() = 0;
103 [[maybe_unused]] virtual
bool saveScreenshot(const
char* FILENAME) noexcept final;
125 [[maybe_unused]] [[nodiscard]]
virtual bool isExtensionEnabled(
const std::string EXT)
const noexcept final {
return _extensions.find(EXT) != _extensions.end(); }
156 [[maybe_unused]] [[nodiscard]]
virtual GLFWwindow*
getWindow() const noexcept final {
return mpWindow; }
166 [[nodiscard]]
virtual unsigned short getError() noexcept final {
167 const unsigned short storedErrorCode =
mErrorCode;
172 return storedErrorCode;
235 OpenGLEngine(
int OPENGL_MAJOR_VERSION,
int OPENGL_MINOR_VERSION,
int WINDOW_WIDTH,
int WINDOW_HEIGHT,
const char* WINDOW_TITLE,
bool WINDOW_RESIZABLE = GLFW_FALSE);
318 static void mErrorCallback(
const int error,
const char* DESCRIPTION) { fprintf(stderr,
"[ERROR]: %d\n\t%s\n", error, DESCRIPTION ); }
323 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) {
324 fprintf( stdout,
"[VERBOSE]: Debug Message (%d): source = %s, type = %s, severity = %s, message = %s\n",
326 CSCI441::OpenGLUtils::debugSourceToString(source),
327 CSCI441::OpenGLUtils::debugTypeToString(type),
328 CSCI441::OpenGLUtils::debugSeverityToString(severity),
463 void _setupGLFunctions();
464 void _cleanupGLFunctions() {}
467 void _moveFromSource(OpenGLEngine&);
472 std::set< std::string > _extensions;
474 GLdouble _lastFrameTime;
475 std::deque<GLdouble> _frameTimes;
482 const int OPENGL_MAJOR_VERSION,
483 const int OPENGL_MINOR_VERSION,
484 const int WINDOW_WIDTH,
485 const int WINDOW_HEIGHT,
486 const char* WINDOW_TITLE,
487 const bool WINDOW_RESIZABLE
489 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
490 mOpenGLMajorVersion(OPENGL_MAJOR_VERSION),
491 mOpenGLMinorVersion(OPENGL_MINOR_VERSION),
492 mOpenGLMajorVersionRequested(OPENGL_MAJOR_VERSION),
493 mOpenGLMinorVersionRequested(OPENGL_MINOR_VERSION),
494 mOpenGLMajorVersionCreated(0),
495 mOpenGLMinorVersionCreated(0),
496 mWindowWidth(WINDOW_WIDTH),
497 mWindowHeight(WINDOW_HEIGHT),
498 mFramebufferWidth(WINDOW_WIDTH),
499 mFramebufferHeight(WINDOW_HEIGHT),
500 mWindowResizable(WINDOW_RESIZABLE),
501 mWindowTitle(nullptr),
503 _isInitialized(false),
509 strncpy(
mWindowTitle, WINDOW_TITLE, strlen(WINDOW_TITLE) + 1);
521 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
522 mOpenGLMajorVersion(0),
523 mOpenGLMinorVersion(0),
524 mOpenGLMajorVersionRequested(0),
525 mOpenGLMinorVersionRequested(0),
526 mOpenGLMajorVersionCreated(0),
527 mOpenGLMinorVersionCreated(0),
530 mFramebufferWidth(0),
531 mFramebufferHeight(0),
532 mWindowResizable(
false),
533 mWindowTitle(
nullptr),
535 _isInitialized(
false),
540 _moveFromSource(src);
550 _moveFromSource(src);
563void CSCI441::OpenGLEngine::_cleanupSelf()
565 delete[] mWindowTitle;
566 mWindowTitle =
nullptr;
570void CSCI441::OpenGLEngine::_moveFromSource(
576 mErrorCode = src.mErrorCode;
577 src.mErrorCode = OPENGL_ENGINE_ERROR_NO_ERROR;
579 mOpenGLMajorVersion = src.mOpenGLMajorVersion;
580 src.mOpenGLMajorVersion = 0;
582 mOpenGLMinorVersion = src.mOpenGLMinorVersion;
583 src.mOpenGLMinorVersion = 0;
585 mOpenGLMajorVersionRequested = src.mOpenGLMajorVersionRequested;
586 src.mOpenGLMajorVersionRequested = 0;
588 mOpenGLMinorVersionRequested = src.mOpenGLMinorVersionRequested;
589 src.mOpenGLMinorVersionRequested = 0;
591 mOpenGLMajorVersionCreated = src.mOpenGLMajorVersionCreated;
592 src.mOpenGLMajorVersionCreated = 0;
594 mOpenGLMinorVersionCreated = src.mOpenGLMinorVersionCreated;
595 src.mOpenGLMinorVersionCreated = 0;
597 mWindowWidth = src.mWindowWidth;
598 src.mWindowWidth = 0;
600 mWindowHeight = src.mWindowHeight;
601 src.mWindowHeight = 0;
603 mWindowResizable = src.mWindowResizable;
604 src.mWindowResizable =
false;
606 mWindowTitle = src.mWindowTitle;
607 src.mWindowTitle =
nullptr;
609 mpWindow = src.mpWindow;
610 src.mpWindow =
nullptr;
612 _isInitialized = src._isInitialized;
613 src._isInitialized =
false;
615 _isCleanedUp = src._isCleanedUp;
616 src._isCleanedUp =
false;
618 _extensions = std::move(src._extensions);
624 if( !_isInitialized ) {
625 const std::chrono::steady_clock::time_point initBegin = std::chrono::steady_clock::now();
628 fprintf(stdout,
"[INFO]: Using CSCI441 Library v%d.%d.%d.%d\n", CSCI441::VERSION_MAJOR, CSCI441::VERSION_MINOR, CSCI441::VERSION_REVISION, CSCI441::VERSION_PATCH);
631 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
633 glfwGetFramebufferSize( mpWindow, &mFramebufferWidth, &mFramebufferHeight );
634 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
636 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
643 if( mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3) ) {
645 int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
646 if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
648 glEnable(GL_DEBUG_OUTPUT);
649 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
650 glDebugMessageCallback(mDebugMessageCallback,
nullptr);
651 glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE );
655 CSCI441::OpenGLUtils::printOpenGLInfo();
657 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
658 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupOpenGL()");
660 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
662 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
663 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupShaders()");
665 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
667 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
668 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupBuffers()");
670 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
672 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
673 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupTextures()");
675 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
677 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
678 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupFonts()");
680 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
682 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
683 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mSetupScene()");
685 _isInitialized =
true;
686 _isCleanedUp =
false;
688 const std::chrono::steady_clock::time_point initEnd = std::chrono::steady_clock::now();
690 fprintf(stdout,
"\n[INFO]: Setup complete\n");
691 fprintf(stdout,
"[INFO]: Init Time: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(initEnd - initBegin ).count() ) / 1000000.0);
692 fprintf(stdout,
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
693 fprintf(stdout,
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
694 fprintf(stdout,
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
695 fprintf(stdout,
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
696 fprintf(stdout,
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
697 fprintf(stdout,
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
698 fprintf(stdout,
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
706 const unsigned short ERROR_CODE
708 switch (ERROR_CODE) {
709 case OPENGL_ENGINE_ERROR_NO_ERROR:
return "No error";
710 case OPENGL_ENGINE_ERROR_GLFW_INIT:
return "Error initializing GLFW";
711 case OPENGL_ENGINE_ERROR_GLFW_WINDOW:
return "Error initializing GLFW window";
712 case OPENGL_ENGINE_ERROR_GLEW_INIT:
return "Error initializing GLEW";
713 case OPENGL_ENGINE_ERROR_GLAD_INIT:
return "Error initializing GLAD";
714 case OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT:
return "Error saving screenshot";
715 default:
return "Unknown error code";
724 const std::string filename =
727 ?
"Screenshot_" + std::to_string(time(
nullptr)) +
".png"
733 glGetIntegerv(GL_VIEWPORT, viewport);
734 const GLsizei x = viewport[0], y = viewport[1], width = viewport[2], height = viewport[3];
737 constexpr int CHANNELS = 4;
738 const auto bytes =
new GLubyte[width*height*CHANNELS];
739 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
741 stbi_flip_vertically_on_write(
true);
743 if( !stbi_write_png(filename.c_str(), width, height, CHANNELS, bytes, width*CHANNELS) ) {
744 fprintf(stderr,
"[ERROR]: Could not save screenshot\n");
745 mErrorCode = OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT;
747 fprintf(stdout,
"[INFO]: Screenshot saved to %s\n", filename.c_str());
752 return (mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR);
761 glfwSetErrorCallback(mErrorCallback);
765 fprintf( stderr,
"[ERROR]: Could not initialize GLFW\n" );
766 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_INIT;
768 if(DEBUG) fprintf( stdout,
"[INFO]: GLFW v%d.%d.%d initialized\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION );
770 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, mOpenGLMajorVersion );
771 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, mOpenGLMinorVersion );
772 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
773 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
774 glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE );
775 glfwWindowHint(GLFW_RESIZABLE, mWindowResizable );
779 && (mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3)) ) {
780 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT,
true);
784 mpWindow = glfwCreateWindow(mWindowWidth, mWindowHeight, mWindowTitle,
nullptr,
nullptr );
786 fprintf( stderr,
"[ERROR]: GLFW Window could not be created\n" );
788 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_WINDOW;
790 if(DEBUG) fprintf( stdout,
"[INFO]: GLFW Window created\n" );
791 glfwMakeContextCurrent(mpWindow);
793 glfwSetInputMode(mpWindow, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
794 glfwSetWindowUserPointer(mpWindow, (
void*)
this);
795 glfwSetWindowSizeCallback(mpWindow, mWindowResizeCallback);
801void CSCI441::OpenGLEngine::_setupGLFunctions()
804#ifdef CSCI441_USE_GLEW
805 glewExperimental = GL_TRUE;
806 const GLenum glewResult = glewInit();
809 if( glewResult != GLEW_OK ) {
810 fprintf( stderr,
"[ERROR]: Error initializing GLEW\n");
811 fprintf( stderr,
"[ERROR]: %s\n",
reinterpret_cast<const char *
>(glewGetErrorString(glewResult)) );
812 mErrorCode = OPENGL_ENGINE_ERROR_GLEW_INIT;
815 fprintf(stdout,
"[INFO]: GLEW initialized\n");
816 fprintf(stdout,
"[INFO]: Using GLEW %s\n",
reinterpret_cast<const char *
>(glewGetString(GLEW_VERSION)));
820 int version = gladLoadGL(glfwGetProcAddress);
822 fprintf(stderr,
"[ERROR]: Failed to initialize GLAD\n" );
823 mErrorCode = OPENGL_ENGINE_ERROR_GLAD_INIT;
827 fprintf(stdout,
"[INFO]: GLAD initialized v%d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
832 if(mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR) {
833 glGetIntegerv(GL_MAJOR_VERSION, &mOpenGLMajorVersionCreated);
834 glGetIntegerv(GL_MINOR_VERSION, &mOpenGLMinorVersionCreated);
836 fprintf(stdout,
"[INFO]: OpenGL v%d.%d requested\n", mOpenGLMajorVersionRequested, mOpenGLMinorVersionRequested);
837 fprintf(stdout,
"[INFO]: OpenGL v%d.%d created\n", mOpenGLMajorVersionCreated, mOpenGLMinorVersionCreated);
840 GLint numExtensions = 0;
841 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
842 for (
int i = 0; i < numExtensions; i++) {
843 _extensions.insert(
reinterpret_cast<const char *
>(glGetStringi(GL_EXTENSIONS, i)) );
851 if(DEBUG) fprintf( stdout,
"[INFO]: ...closing window...\n" );
852 glfwDestroyWindow(mpWindow );
854 if(DEBUG) fprintf( stdout,
"[INFO]: ...closing GLFW.....\n" );
861 if( !_isCleanedUp ) {
862 const std::chrono::steady_clock::time_point shutdownBegin = std::chrono::steady_clock::now();
863 if (DEBUG) fprintf(stdout,
"\n[INFO]: Shutting down.......\n");
865 const std::chrono::steady_clock::time_point sceneBegin = std::chrono::steady_clock::now();
867 const std::chrono::steady_clock::time_point sceneEnd = std::chrono::steady_clock::now();
868 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupScene()");
870 const std::chrono::steady_clock::time_point fontsBegin = std::chrono::steady_clock::now();
872 const std::chrono::steady_clock::time_point fontsEnd = std::chrono::steady_clock::now();
873 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupFonts()");
875 const std::chrono::steady_clock::time_point texturesBegin = std::chrono::steady_clock::now();
877 const std::chrono::steady_clock::time_point texturesEnd = std::chrono::steady_clock::now();
878 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupTextures()");
880 const std::chrono::steady_clock::time_point buffersBegin = std::chrono::steady_clock::now();
882 const std::chrono::steady_clock::time_point buffersEnd = std::chrono::steady_clock::now();
883 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupBuffers()");
885 const std::chrono::steady_clock::time_point shadersBegin = std::chrono::steady_clock::now();
887 const std::chrono::steady_clock::time_point shadersEnd = std::chrono::steady_clock::now();
888 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupShaders()");
890 const std::chrono::steady_clock::time_point openGLBegin = std::chrono::steady_clock::now();
892 _cleanupGLFunctions();
893 const std::chrono::steady_clock::time_point openGLEnd = std::chrono::steady_clock::now();
894 CSCI441::OpenGLUtils::checkOpenGLErrors(
"post mCleanupOpenGL()");
896 const std::chrono::steady_clock::time_point glfwBegin = std::chrono::steady_clock::now();
898 const std::chrono::steady_clock::time_point glfwEnd = std::chrono::steady_clock::now();
900 const std::chrono::steady_clock::time_point shutdownEnd = std::chrono::steady_clock::now();
902 fprintf(stdout,
"[INFO]: ..shut down complete!\n");
903 fprintf(stdout,
"[INFO]: Shutdown: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shutdownEnd - shutdownBegin).count() ) / 1000000.0);
904 fprintf(stdout,
"[INFO]: \tScene: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(sceneEnd - sceneBegin ).count() ) / 1000000.0);
905 fprintf(stdout,
"[INFO]: \tFonts: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(fontsEnd - fontsBegin ).count() ) / 1000000.0);
906 fprintf(stdout,
"[INFO]: \tTextures: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(texturesEnd - texturesBegin).count() ) / 1000000.0);
907 fprintf(stdout,
"[INFO]: \tBuffers: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(buffersEnd - buffersBegin ).count() ) / 1000000.0);
908 fprintf(stdout,
"[INFO]: \tShaders: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(shadersEnd - shadersBegin ).count() ) / 1000000.0);
909 fprintf(stdout,
"[INFO]: \tOpenGL: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(openGLEnd - openGLBegin ).count() ) / 1000000.0);
910 fprintf(stdout,
"[INFO]: \tGLFW: %2.3fs\n",
static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(glfwEnd - glfwBegin ).count() ) / 1000000.0);
913 _isInitialized =
false;
923 const auto pEngine =
static_cast<OpenGLEngine *
>(glfwGetWindowUserPointer(pWindow));
928 GLint framebufferWidth, framebufferHeight;
929 glfwGetFramebufferSize( pEngine->getWindow(), &framebufferWidth, &framebufferHeight );
930 pEngine->setCurrentFramebufferSize(framebufferWidth, framebufferHeight);
936 if (DEBUG) fprintf(stdout,
"\n[INFO]: Removing old shaders...\n");
938 if (DEBUG) fprintf(stdout,
"\n[INFO]: Reloading shaders...\n");
940 if (DEBUG) fprintf(stdout,
"\n[INFO]: Shaders reloaded\n");
945 const GLdouble currentTime = glfwGetTime();
947 GLdouble fps = ( !_frameTimes.empty() ? _frameTimes.back() : 0.0 );
948 if (currentTime - _lastFrameTime > 0.1667) {
949 fps =
static_cast<GLdouble
>(_numFrames)/(currentTime - _lastFrameTime);
951 _lastFrameTime = currentTime;
953 if (_frameTimes.size() >= 10) _frameTimes.pop_front();
954 _frameTimes.push_back( fps );
961 GLdouble totalFPS = 0;
962 for(
const auto& fpsUnit : _frameTimes ) {
965 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:52
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:125
bool DEBUG
if information should be printed to console while running
Definition: OpenGLEngine.hpp:241
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:293
int mOpenGLMinorVersion
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:257
int mOpenGLMajorVersion
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:252
static constexpr unsigned short OPENGL_ENGINE_ERROR_NO_ERROR
no error is present, everything is currently working
Definition: OpenGLEngine.hpp:178
virtual bool saveScreenshot(const char *FILENAME) noexcept final
Save a PNG screenshot of the viewport.
Definition: OpenGLEngine.hpp:720
virtual void setCurrentWindowSize(const int WINDOW_WIDTH, const int WINDOW_HEIGHT) final
Stores the new window size.
Definition: OpenGLEngine.hpp:135
virtual void initialize()
Initialize everything needed for OpenGL Rendering. This includes in order: GLFW, function pointers,...
Definition: OpenGLEngine.hpp:622
virtual void shutdown()
Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Sc...
Definition: OpenGLEngine.hpp:859
virtual unsigned short getError() noexcept final
Return current value of error code and clear the error code back to no error.
Definition: OpenGLEngine.hpp:166
virtual void mSetupTextures()
override to register any textures with the GPU
Definition: OpenGLEngine.hpp:387
virtual int getWindowHeight() const noexcept final
Return the height of the window.
Definition: OpenGLEngine.hpp:148
virtual bool isDebuggingEnabled() const noexcept final
Returns if logging is enabled.
Definition: OpenGLEngine.hpp:118
static void mWindowResizeCallback(GLFWwindow *pWindow, int width, int height)
Definition: OpenGLEngine.hpp:918
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLAD_INIT
an error occurred while initializing GLAD
Definition: OpenGLEngine.hpp:194
virtual void mCleanupBuffers()
override to cleanup any buffer objects from the GPU
Definition: OpenGLEngine.hpp:420
virtual void mCleanupScene()
override to cleanup any scene specific information
Definition: OpenGLEngine.hpp:405
virtual void mSetupFonts()
override to register any fonts with the GPU
Definition: OpenGLEngine.hpp:393
virtual void setCurrentFramebufferSize(const int FRAMEBUFFER_WIDTH, const int FRAMEBUFFER_HEIGHT) final
Stores the framebuffer size.
Definition: OpenGLEngine.hpp:144
virtual void mCleanupShaders()
override to cleanup any shaders from the GPU
Definition: OpenGLEngine.hpp:425
virtual void mCleanupTextures()
override to cleanup any textures from the GPU
Definition: OpenGLEngine.hpp:415
virtual GLdouble clockFrame() final
measures the amount of time elapsed since the last time this method was called
Definition: OpenGLEngine.hpp:944
bool mWindowResizable
if the GLFW window can be resized while open
Definition: OpenGLEngine.hpp:302
int mOpenGLMinorVersionRequested
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:269
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:198
int mFramebufferHeight
the framebuffer width of the requested GLFW window
Definition: OpenGLEngine.hpp:297
virtual void turnDebuggingOn() noexcept final
Enable logging to command line.
Definition: OpenGLEngine.hpp:109
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLEW_INIT
an error occurred while initializing GLEW
Definition: OpenGLEngine.hpp:190
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_WINDOW
an error occurred while creating the GLFW window
Definition: OpenGLEngine.hpp:186
virtual void mCleanupFonts()
override to cleanup any fonts from the GPU
Definition: OpenGLEngine.hpp:410
int mOpenGLMajorVersionRequested
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:263
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:318
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:210
unsigned int mErrorCode
tracks the current status of the OpenGL engine via error codes
Definition: OpenGLEngine.hpp:246
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:323
char * mWindowTitle
the title of the GLFW window
Definition: OpenGLEngine.hpp:306
int mWindowHeight
the window height of the requested GLFW window
Definition: OpenGLEngine.hpp:289
virtual GLdouble fpsAverage() final
Definition: OpenGLEngine.hpp:960
virtual void setWindowShouldClose() final
Tell our engine's window to close.
Definition: OpenGLEngine.hpp:161
int mOpenGLMajorVersionCreated
the major version of the created OpenGL context
Definition: OpenGLEngine.hpp:274
static constexpr unsigned short OPENGL_ENGINE_ERROR_SIZE
stores the number of unique error codes that can be generated
Definition: OpenGLEngine.hpp:214
virtual void mReloadShaders() final
calls mCleanupShaders() followed by mSetupShaders() to reload shader source code from file
Definition: OpenGLEngine.hpp:934
virtual void mSetupShaders()
override to register any shaders with the GPU
Definition: OpenGLEngine.hpp:375
GLFWwindow * mpWindow
pointer to the GLFW window object
Definition: OpenGLEngine.hpp:310
virtual void turnDebuggingOff() noexcept final
Disable logging to command line.
Definition: OpenGLEngine.hpp:114
static const char * getErrorStringDescription(unsigned short ERROR_CODE) noexcept
Returns a string describing what the error code corresponds to.
Definition: OpenGLEngine.hpp:705
virtual int getWindowWidth() const noexcept final
Return the width of the window.
Definition: OpenGLEngine.hpp:152
virtual void mSetupBuffers()
override to register any buffer objects with the GPU
Definition: OpenGLEngine.hpp:381
virtual ~OpenGLEngine()
cleans up our OpenGL Engine by destroying the OpenGL context, GLFW window, and cleaning up all GPU re...
Definition: OpenGLEngine.hpp:557
virtual void mCleanupGLFW()
Destroys the associated GLFW window and terminates the GLFW instance.
Definition: OpenGLEngine.hpp:849
int mOpenGLMinorVersionCreated
the minor version of the created OpenGL context
Definition: OpenGLEngine.hpp:279
int mWindowWidth
the window width of the requested GLFW window
Definition: OpenGLEngine.hpp:284
virtual void mCleanupOpenGL()
override to cleanup any specific OpenGL features
Definition: OpenGLEngine.hpp:430
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_INIT
an error occurred while initializing GLFW
Definition: OpenGLEngine.hpp:182
virtual void mSetupGLFW()
Used to setup everything GLFW related. This includes the OpenGL context and our window....
Definition: OpenGLEngine.hpp:756
virtual void mSetupScene()
override to setup any scene specific information
Definition: OpenGLEngine.hpp:399
static constexpr unsigned short OPENGL_ENGINE_ERROR_UNKNOWN
a new error that does not correspond to a predefined scenario has occurred
Definition: OpenGLEngine.hpp:202
virtual GLFWwindow * getWindow() const noexcept final
Return the window object.
Definition: OpenGLEngine.hpp:156
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
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17