CSCI441 OpenGL Library 5.23.1.1
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
OpenGLEngine.hpp
Go to the documentation of this file.
1
12#ifndef CSCI441_OPENGL_ENGINE_HPP
13#define CSCI441_OPENGL_ENGINE_HPP
14
15#include "constants.h"
16#include "OpenGLUtils.hpp"
17
18#ifdef CSCI441_USE_GLEW
19 #include <GL/glew.h>
20#else
21 #include <glad/gl.h>
22#endif
23
24#include <GLFW/glfw3.h>
25
26#ifdef CSCI441_OPENGL_ENGINE_IMPLEMENTATION
27#define STB_IMAGE_WRITE_IMPLEMENTATION
28#endif
29#include <stb_image_write.h>
30
31#include <cstdio>
32#include <cstring>
33#include <ctime>
34#include <set>
35#include <string>
36#include <memory>
37
38namespace CSCI441 {
39
50 public:
54 OpenGLEngine(const OpenGLEngine&) = delete;
59
63 OpenGLEngine(OpenGLEngine&&) noexcept;
68 OpenGLEngine& operator=(OpenGLEngine&&) noexcept;
69
74 virtual ~OpenGLEngine();
75
83 virtual void initialize();
87 virtual void run() = 0;
95 virtual void shutdown();
96
100 [[maybe_unused]] virtual bool saveScreenshot(const char* FILENAME) noexcept final;
101
106 [[maybe_unused]] virtual void turnDebuggingOn() noexcept final { DEBUG = true; }
111 virtual void turnDebuggingOff() noexcept final { DEBUG = false; }
115 [[maybe_unused]] [[nodiscard]] virtual bool isDebuggingEnabled() const noexcept final { return DEBUG; }
116
122 [[maybe_unused]] [[nodiscard]] virtual bool isExtensionEnabled(const std::string EXT) const noexcept final { return _extensions.find(EXT) != _extensions.end(); }
123
132 virtual void setCurrentWindowSize(const int WINDOW_WIDTH, const int WINDOW_HEIGHT) final { mWindowWidth = WINDOW_WIDTH; mWindowHeight = WINDOW_HEIGHT; }
136 [[maybe_unused]] [[nodiscard]] virtual int getWindowHeight() const noexcept final { return mWindowHeight; }
140 [[maybe_unused]] [[nodiscard]] virtual int getWindowWidth() const noexcept final { return mWindowWidth; }
144 [[maybe_unused]] [[nodiscard]] virtual GLFWwindow* getWindow() const noexcept final { return mpWindow; }
145
149 [[maybe_unused]] virtual void setWindowShouldClose() final { glfwSetWindowShouldClose(mpWindow, GLFW_TRUE); }
150
154 [[nodiscard]] virtual unsigned short getError() noexcept final {
155 const unsigned short storedErrorCode = mErrorCode; // store current error code
157 fprintf( stderr, "[ERROR]: %s\n", getErrorStringDescription(mErrorCode) );
158 }
159 mErrorCode = OPENGL_ENGINE_ERROR_NO_ERROR; // reset error code
160 return storedErrorCode; // return previously stored error code
161 }
162
166 static constexpr unsigned short OPENGL_ENGINE_ERROR_NO_ERROR = 0;
170 static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_INIT = 1;
174 static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_WINDOW = 2;
178 static constexpr unsigned short OPENGL_ENGINE_ERROR_GLEW_INIT = 3;
182 static constexpr unsigned short OPENGL_ENGINE_ERROR_GLAD_INIT = 4;
186 static constexpr unsigned short OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT = 5;
190 static constexpr unsigned short OPENGL_ENGINE_ERROR_UNKNOWN = 6;
191 // note to developers: if more error codes are added, need to update LAST accordingly or
192 // update UNKNOWN to the last value and shift
193 // note to developers: if more error codes are added, need to add description to getErrorStringDescription()
198 static constexpr unsigned short OPENGL_ENGINE_ERROR_LAST = OPENGL_ENGINE_ERROR_UNKNOWN;
202 [[maybe_unused]] static constexpr unsigned short OPENGL_ENGINE_ERROR_SIZE = OPENGL_ENGINE_ERROR_LAST + 1;
203
209 static const char* getErrorStringDescription(unsigned short ERROR_CODE) noexcept;
210
211 protected:
223 OpenGLEngine(int OPENGL_MAJOR_VERSION, int OPENGL_MINOR_VERSION, int WINDOW_WIDTH, int WINDOW_HEIGHT, const char* WINDOW_TITLE, bool WINDOW_RESIZABLE = GLFW_FALSE);
224
229 bool DEBUG;
230
234 unsigned int mErrorCode;
235
290 GLFWwindow* mpWindow;
291
298 static void mErrorCallback(const int error, const char* DESCRIPTION) { fprintf(stderr, "[ERROR]: %d\n\t%s\n", error, DESCRIPTION ); }
299
303 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) {
304 fprintf( stdout, "[VERBOSE]: Debug Message (%d): source = %s, type = %s, severity = %s, message = %s\n",
305 id,
306 CSCI441::OpenGLUtils::debugSourceToString(source),
307 CSCI441::OpenGLUtils::debugTypeToString(type),
308 CSCI441::OpenGLUtils::debugSeverityToString(severity),
309 message
310 );
311 }
312
320 static void mWindowResizeCallback(GLFWwindow* pWindow, int width, int height);
321
341 virtual void mSetupGLFW();
348 virtual void mSetupOpenGL() = 0;
355 virtual void mSetupShaders() {};
361 virtual void mSetupBuffers() {};
367 virtual void mSetupTextures() {}
373 virtual void mSetupScene() {};
374
379 virtual void mCleanupScene() {};
384 virtual void mCleanupTextures() {}
389 virtual void mCleanupBuffers() {};
394 virtual void mCleanupShaders() {};
399 virtual void mCleanupOpenGL() {};
406 virtual void mCleanupGLFW();
407
412 virtual void mReloadShaders() final;
413
414 private:
415 void _setupGLFunctions(); // initialize OpenGL functions
416 void _cleanupGLFunctions() {} // nothing to be done at this time
417
418 void _cleanupSelf(); // delete internal memory
419 void _moveFromSource(OpenGLEngine&);// move members from another instance
420
421 bool _isInitialized; // makes initialization a singleton process
422 bool _isCleanedUp; // makes cleanup a singleton process
423
424 std::set< std::string > _extensions;// set of all available OpenGL extensions
425 };
426}
427
428inline
430 const int OPENGL_MAJOR_VERSION,
431 const int OPENGL_MINOR_VERSION,
432 const int WINDOW_WIDTH,
433 const int WINDOW_HEIGHT,
434 const char* WINDOW_TITLE,
435 const bool WINDOW_RESIZABLE
436) : DEBUG(true),
437 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
438 mOpenGLMajorVersion(OPENGL_MAJOR_VERSION),
439 mOpenGLMinorVersion(OPENGL_MINOR_VERSION),
440 mOpenGLMajorVersionRequested(OPENGL_MAJOR_VERSION),
441 mOpenGLMinorVersionRequested(OPENGL_MINOR_VERSION),
442 mOpenGLMajorVersionCreated(0),
443 mOpenGLMinorVersionCreated(0),
444 mWindowWidth(WINDOW_WIDTH),
445 mWindowHeight(WINDOW_HEIGHT),
446 mWindowResizable(WINDOW_RESIZABLE),
447 mWindowTitle(nullptr),
448 mpWindow(nullptr),
449 _isInitialized(false),
450 _isCleanedUp(false)
451{
452 mWindowTitle = new char[ strlen(WINDOW_TITLE) ];
453 strcpy(mWindowTitle, WINDOW_TITLE);
454}
455
456inline
459) noexcept :
460 DEBUG(true),
461 mErrorCode(OPENGL_ENGINE_ERROR_NO_ERROR),
462 mOpenGLMajorVersion(0),
463 mOpenGLMinorVersion(0),
464 mOpenGLMajorVersionRequested(0),
465 mOpenGLMinorVersionRequested(0),
466 mOpenGLMajorVersionCreated(0),
467 mOpenGLMinorVersionCreated(0),
468 mWindowWidth(0),
469 mWindowHeight(0),
470 mWindowResizable(false),
471 mWindowTitle(nullptr),
472 mpWindow(nullptr),
473 _isInitialized(false),
474 _isCleanedUp(false)
475{
476 _moveFromSource(src);
477}
478
479inline
481 OpenGLEngine&& src
482) noexcept
483{
484 if (this != &src) {
485 _cleanupSelf();
486 _moveFromSource(src);
487 }
488 return *this;
489}
490
491
492inline
494{
495 _cleanupSelf();
496}
497
498inline
499void CSCI441::OpenGLEngine::_cleanupSelf()
500{
501 delete[] mWindowTitle;
502 mWindowTitle = nullptr;
503}
504
505inline
506void CSCI441::OpenGLEngine::_moveFromSource(
507 OpenGLEngine& src
508) {
509 DEBUG = src.DEBUG;
510 src.DEBUG = false;
511
512 mErrorCode = src.mErrorCode;
513 src.mErrorCode = OPENGL_ENGINE_ERROR_NO_ERROR;
514
515 mOpenGLMajorVersion = src.mOpenGLMajorVersion;
516 src.mOpenGLMajorVersion = 0;
517
518 mOpenGLMinorVersion = src.mOpenGLMinorVersion;
519 src.mOpenGLMinorVersion = 0;
520
521 mOpenGLMajorVersionRequested = src.mOpenGLMajorVersionRequested;
522 src.mOpenGLMajorVersionRequested = 0;
523
524 mOpenGLMinorVersionRequested = src.mOpenGLMinorVersionRequested;
525 src.mOpenGLMinorVersionRequested = 0;
526
527 mOpenGLMajorVersionCreated = src.mOpenGLMajorVersionCreated;
528 src.mOpenGLMajorVersionCreated = 0;
529
530 mOpenGLMinorVersionCreated = src.mOpenGLMinorVersionCreated;
531 src.mOpenGLMinorVersionCreated = 0;
532
533 mWindowWidth = src.mWindowWidth;
534 src.mWindowWidth = 0;
535
536 mWindowHeight = src.mWindowHeight;
537 src.mWindowHeight = 0;
538
539 mWindowResizable = src.mWindowResizable;
540 src.mWindowResizable = false;
541
542 mWindowTitle = src.mWindowTitle;
543 src.mWindowTitle = nullptr;
544
545 mpWindow = src.mpWindow;
546 src.mpWindow = nullptr;
547
548 _isInitialized = src._isInitialized;
549 src._isInitialized = false;
550
551 _isCleanedUp = src._isCleanedUp;
552 src._isCleanedUp = false;
553
554 _extensions = std::move(src._extensions);
555}
556
557inline
559{
560 if( !_isInitialized ) {
561 if (DEBUG) {
562 fprintf(stdout, "[INFO]: Using CSCI441 Library v%d.%d.%d.%d\n", CSCI441::VERSION_MAJOR, CSCI441::VERSION_MINOR, CSCI441::VERSION_REVISION, CSCI441::VERSION_PATCH);
563 }
564
565 mSetupGLFW(); // initialize GLFW and set up a window
566 _setupGLFunctions(); // create OpenGL function pointers
567 mSetupOpenGL(); // create the OpenGL context
568
569 // get OpenGL context information
570 if( DEBUG ) {
571 // if wanting debug information with Version 4.3 or higher
572 if( mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3) ) {
573 // check if debug context was created
574 int flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
575 if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
576 // register callback to synchronously print any debug messages without having to call glGetError()
577 glEnable(GL_DEBUG_OUTPUT);
578 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
579 glDebugMessageCallback(mDebugMessageCallback, nullptr);
580 glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE );
581 }
582 }
583
584 CSCI441::OpenGLUtils::printOpenGLInfo();
585 }
586
587 mSetupShaders(); // transfer, compile, link shaders on GPU
588 mSetupBuffers(); // register Buffers on GPU
589 mSetupTextures(); // register Textures on GPU
590 mSetupScene(); // setup any scene specific information
591
592 _isInitialized = true;
593 _isCleanedUp = false;
594 if (DEBUG) fprintf(stdout, "\n[INFO]: Setup complete\n");
595 }
596}
597
598inline
600 const unsigned short ERROR_CODE
601) noexcept {
602 switch (ERROR_CODE) {
603 case OPENGL_ENGINE_ERROR_NO_ERROR: return "No error";
604 case OPENGL_ENGINE_ERROR_GLFW_INIT: return "Error initializing GLFW";
605 case OPENGL_ENGINE_ERROR_GLFW_WINDOW: return "Error initializing GLFW window";
606 case OPENGL_ENGINE_ERROR_GLEW_INIT: return "Error initializing GLEW";
607 case OPENGL_ENGINE_ERROR_GLAD_INIT: return "Error initializing GLAD";
608 case OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT: return "Error saving screenshot";
609 default: return "Unknown error code";
610 }
611}
612
613inline
615 const char* FILENAME
616) noexcept {
617 // Generate a name based on current timestamp if not provided
618 const std::string filename =
619 (
620 FILENAME == nullptr
621 ? "Screenshot_" + std::to_string(time(nullptr)) + ".png"
622 : FILENAME
623 );
624
625 // Get size
626 GLint viewport[4];
627 glGetIntegerv(GL_VIEWPORT, viewport);
628 const GLsizei x = viewport[0], y = viewport[1], width = viewport[2], height = viewport[3];
629
630 // Read pixel data
631 constexpr int CHANNELS = 4; // RGBA
632 const auto bytes = new GLubyte[width*height*CHANNELS];
633 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
634
635 stbi_flip_vertically_on_write(true);
636
637 if( !stbi_write_png(filename.c_str(), width, height, CHANNELS, bytes, width*CHANNELS) ) {
638 fprintf(stderr, "[ERROR]: Could not save screenshot\n");
639 mErrorCode = OPENGL_ENGINE_ERROR_TAKE_SCREENSHOT;
640 } else if(DEBUG) {
641 fprintf(stdout, "[INFO]: Screenshot saved to %s\n", filename.c_str());
642 }
643
644 delete[] bytes;
645
646 return (mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR);
647}
648
649inline
651{
652 // set what function to use when registering errors
653 // this is the ONLY GLFW function that can be called BEFORE GLFW is initialized
654 // all other GLFW calls must be performed after GLFW has been initialized
655 glfwSetErrorCallback(mErrorCallback);
656
657 // initialize GLFW
658 if( !glfwInit() ) {
659 fprintf( stderr, "[ERROR]: Could not initialize GLFW\n" );
660 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_INIT;
661 } else {
662 if(DEBUG) fprintf( stdout, "[INFO]: GLFW v%d.%d.%d initialized\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION );
663
664 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, mOpenGLMajorVersion ); // request OpenGL vX.
665 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, mOpenGLMinorVersion ); // request OpenGL v .X
666 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE ); // request forward compatible OpenGL context
667 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); // request OpenGL Core Profile context
668 glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE ); // request double buffering
669 glfwWindowHint(GLFW_RESIZABLE, mWindowResizable ); // set if our window should be able to be resized
670
671 // if wanting debug information with Version 4.3 or higher
672 if( DEBUG
673 && (mOpenGLMajorVersion > 4 || (mOpenGLMajorVersion == 4 && mOpenGLMinorVersion >= 3)) ) {
674 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); // request a debug context
675 }
676
677 // create a window for a given size, with a given title
678 mpWindow = glfwCreateWindow(mWindowWidth, mWindowHeight, mWindowTitle, nullptr, nullptr );
679 if( !mpWindow ) { // if the window could not be created, NULL is returned
680 fprintf( stderr, "[ERROR]: GLFW Window could not be created\n" );
681 glfwTerminate();
682 mErrorCode = OPENGL_ENGINE_ERROR_GLFW_WINDOW;
683 } else {
684 if(DEBUG) fprintf( stdout, "[INFO]: GLFW Window created\n" );
685 glfwMakeContextCurrent(mpWindow); // make the created window the current window
686 glfwSwapInterval(1); // update our screen after at least 1 screen refresh
687 glfwSetInputMode(mpWindow, GLFW_LOCK_KEY_MODS, GLFW_TRUE); // track state of Caps Lock and Num Lock keys
688 glfwSetWindowUserPointer(mpWindow, (void*)this);
689 glfwSetWindowSizeCallback(mpWindow, mWindowResizeCallback);
690 }
691 }
692}
693
694inline
695void CSCI441::OpenGLEngine::_setupGLFunctions()
696{
697
698#ifdef CSCI441_USE_GLEW
699 glewExperimental = GL_TRUE;
700 const GLenum glewResult = glewInit(); // initialize GLEW
701
702 // check for an error
703 if( glewResult != GLEW_OK ) {
704 fprintf( stderr, "[ERROR]: Error initializing GLEW\n");
705 fprintf( stderr, "[ERROR]: %s\n", reinterpret_cast<const char *>(glewGetErrorString(glewResult)) );
706 mErrorCode = OPENGL_ENGINE_ERROR_GLEW_INIT;
707 } else {
708 if(DEBUG) {
709 fprintf(stdout, "[INFO]: GLEW initialized\n");
710 fprintf(stdout, "[INFO]: Using GLEW %s\n", reinterpret_cast<const char *>(glewGetString(GLEW_VERSION)));
711 }
712 }
713#else
714 int version = gladLoadGL(glfwGetProcAddress);
715 if(version == 0) {
716 fprintf(stderr, "[ERROR]: Failed to initialize GLAD\n" );
717 mErrorCode = OPENGL_ENGINE_ERROR_GLAD_INIT;
718 } else {
719 if(DEBUG) {
720 // Successfully loaded OpenGL
721 fprintf(stdout, "[INFO]: GLAD initialized v%d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
722 }
723 }
724#endif
725
726 if(mErrorCode == OPENGL_ENGINE_ERROR_NO_ERROR) {
727 glGetIntegerv(GL_MAJOR_VERSION, &mOpenGLMajorVersionCreated);
728 glGetIntegerv(GL_MINOR_VERSION, &mOpenGLMinorVersionCreated);
729 if(DEBUG) {
730 fprintf(stdout, "[INFO]: OpenGL v%d.%d requested\n", mOpenGLMajorVersionRequested, mOpenGLMinorVersionRequested);
731 fprintf(stdout, "[INFO]: OpenGL v%d.%d created\n", mOpenGLMajorVersionCreated, mOpenGLMinorVersionCreated);
732 }
733
734 GLint numExtensions = 0;
735 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
736 for (int i = 0; i < numExtensions; i++) {
737 _extensions.insert(reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i)) );
738 }
739 }
740}
741
742inline
744{
745 if(DEBUG) fprintf( stdout, "[INFO]: ...closing window...\n" );
746 glfwDestroyWindow(mpWindow ); // close our window
747 mpWindow = nullptr;
748 if(DEBUG) fprintf( stdout, "[INFO]: ...closing GLFW.....\n" );
749 glfwTerminate();
750}
751
752inline
754{
755 if( !_isCleanedUp ) {
756 if (DEBUG) fprintf(stdout, "\n[INFO]: Shutting down.......\n");
757 mCleanupShaders(); // delete shaders from GPU
758 mCleanupBuffers(); // delete VAOs/VBOs from GPU
759 mCleanupTextures(); // delete textures from GPU
760 mCleanupScene(); // delete scene info from CPU
761 mCleanupOpenGL(); // cleanup anything OpenGL related
762 _cleanupGLFunctions(); // cleanup anything function pointer related
763 mCleanupGLFW(); // shut down GLFW to clean up our context
764 if (DEBUG) fprintf(stdout, "[INFO]: ..shut down complete!\n");
765 _isCleanedUp = true;
766 _isInitialized = false;
767 }
768}
769
770inline
772 GLFWwindow* pWindow,
773 const int width,
774 const int height
775) {
776 const auto pEngine = static_cast<OpenGLEngine *>(glfwGetWindowUserPointer(pWindow));
777 pEngine->setCurrentWindowSize(width, height);
778}
779
780inline
782{
783 if (DEBUG) fprintf(stdout, "\n[INFO]: Removing old shaders...\n");
784 mCleanupShaders();
785 if (DEBUG) fprintf(stdout, "\n[INFO]: Reloading shaders...\n");
786 mSetupShaders();
787 if (DEBUG) fprintf(stdout, "\n[INFO]: Shaders reloaded\n");
788}
789
790#endif //CSCI441_OPENGL_ENGINE_HPP
Helper functions to work with OpenGL 3.0+.
Abstract Class to run an OpenGL application. The following methods must be overridden:
Definition: OpenGLEngine.hpp:49
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:122
bool DEBUG
if information should be printed to console while running
Definition: OpenGLEngine.hpp:229
OpenGLEngine & operator=(const OpenGLEngine &)=delete
do not allow engines to be copied
int mOpenGLMinorVersion
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:245
int mOpenGLMajorVersion
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:240
static constexpr unsigned short OPENGL_ENGINE_ERROR_NO_ERROR
no error is present, everything is currently working
Definition: OpenGLEngine.hpp:166
virtual bool saveScreenshot(const char *FILENAME) noexcept final
Save a PNG screenshot of the viewport.
Definition: OpenGLEngine.hpp:614
virtual void setCurrentWindowSize(const int WINDOW_WIDTH, const int WINDOW_HEIGHT) final
Set the new window size.
Definition: OpenGLEngine.hpp:132
virtual void initialize()
Initialize everything needed for OpenGL Rendering. This includes in order: GLFW, function pointers,...
Definition: OpenGLEngine.hpp:558
virtual void shutdown()
Cleanup everything needed for OpenGL Rendering. This includes freeing memory for data used in: any Sc...
Definition: OpenGLEngine.hpp:753
virtual unsigned short getError() noexcept final
Return current value of error code and clear the error code back to no error.
Definition: OpenGLEngine.hpp:154
virtual void mSetupTextures()
override to register any textures with the GPU
Definition: OpenGLEngine.hpp:367
virtual int getWindowHeight() const noexcept final
Return the height of the window.
Definition: OpenGLEngine.hpp:136
virtual bool isDebuggingEnabled() const noexcept final
Returns if logging is enabled.
Definition: OpenGLEngine.hpp:115
static void mWindowResizeCallback(GLFWwindow *pWindow, int width, int height)
Definition: OpenGLEngine.hpp:771
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLAD_INIT
an error occurred while initializing GLAD
Definition: OpenGLEngine.hpp:182
virtual void mCleanupBuffers()
override to cleanup any buffer objects from the GPU
Definition: OpenGLEngine.hpp:389
virtual void mCleanupScene()
override to cleanup any scene specific information
Definition: OpenGLEngine.hpp:379
virtual void mCleanupShaders()
override to cleanup any shaders from the GPU
Definition: OpenGLEngine.hpp:394
virtual void mCleanupTextures()
override to cleanup any textures from the GPU
Definition: OpenGLEngine.hpp:384
bool mWindowResizable
if the GLFW window can be resized while open
Definition: OpenGLEngine.hpp:282
int mOpenGLMinorVersionRequested
the minor version of the requested OpenGL context
Definition: OpenGLEngine.hpp:257
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:186
virtual void turnDebuggingOn() noexcept final
Enable logging to command line.
Definition: OpenGLEngine.hpp:106
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLEW_INIT
an error occurred while initializing GLEW
Definition: OpenGLEngine.hpp:178
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_WINDOW
an error occurred while creating the GLFW window
Definition: OpenGLEngine.hpp:174
int mOpenGLMajorVersionRequested
the major version of the requested OpenGL context
Definition: OpenGLEngine.hpp:251
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:298
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:198
unsigned int mErrorCode
tracks the current status of the OpenGL engine via error codes
Definition: OpenGLEngine.hpp:234
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:303
char * mWindowTitle
the title of the GLFW window
Definition: OpenGLEngine.hpp:286
int mWindowHeight
the window height of the requested GLFW window
Definition: OpenGLEngine.hpp:277
virtual void setWindowShouldClose() final
Tell our engine's window to close.
Definition: OpenGLEngine.hpp:149
int mOpenGLMajorVersionCreated
the major version of the created OpenGL context
Definition: OpenGLEngine.hpp:262
static constexpr unsigned short OPENGL_ENGINE_ERROR_SIZE
stores the number of unique error codes that can be generated
Definition: OpenGLEngine.hpp:202
virtual void mReloadShaders() final
calls mCleanupShaders() followed by mSetupShaders() to reload shader source code from file
Definition: OpenGLEngine.hpp:781
virtual void mSetupShaders()
override to register any shaders with the GPU
Definition: OpenGLEngine.hpp:355
GLFWwindow * mpWindow
pointer to the GLFW window object
Definition: OpenGLEngine.hpp:290
virtual void turnDebuggingOff() noexcept final
Disable logging to command line.
Definition: OpenGLEngine.hpp:111
static const char * getErrorStringDescription(unsigned short ERROR_CODE) noexcept
Returns a string describing what the error code corresponds to.
Definition: OpenGLEngine.hpp:599
virtual int getWindowWidth() const noexcept final
Return the width of the window.
Definition: OpenGLEngine.hpp:140
virtual void mSetupBuffers()
override to register any buffer objects with the GPU
Definition: OpenGLEngine.hpp:361
virtual ~OpenGLEngine()
cleans up our OpenGL Engine by destroying the OpenGL context, GLFW window, and cleaning up all GPU re...
Definition: OpenGLEngine.hpp:493
virtual void mCleanupGLFW()
Destroys the associated GLFW window and terminates the GLFW instance.
Definition: OpenGLEngine.hpp:743
int mOpenGLMinorVersionCreated
the minor version of the created OpenGL context
Definition: OpenGLEngine.hpp:267
int mWindowWidth
the window width of the requested GLFW window
Definition: OpenGLEngine.hpp:272
virtual void mCleanupOpenGL()
override to cleanup any specific OpenGL features
Definition: OpenGLEngine.hpp:399
static constexpr unsigned short OPENGL_ENGINE_ERROR_GLFW_INIT
an error occurred while initializing GLFW
Definition: OpenGLEngine.hpp:170
virtual void mSetupGLFW()
Used to setup everything GLFW related. This includes the OpenGL context and our window....
Definition: OpenGLEngine.hpp:650
virtual void mSetupScene()
override to setup any scene specific information
Definition: OpenGLEngine.hpp:373
static constexpr unsigned short OPENGL_ENGINE_ERROR_UNKNOWN
a new error that does not correspond to a predefined scenario has occurred
Definition: OpenGLEngine.hpp:190
virtual GLFWwindow * getWindow() const noexcept final
Return the window object.
Definition: OpenGLEngine.hpp:144
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17