Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Allotropy\Allotropy.h"
- using namespace al;
- // specify OpenGL version here
- static const unsigned contextVersionMajor = 3;
- static const unsigned contextVersionMinor = 2;
- bool Context::isGlewInit = false;
- static void SetupContextParameters() {
- glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, contextVersionMajor );
- glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, contextVersionMinor );
- glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
- glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
- glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );
- }
- Context::Context() : videoMode( VideoMode::GetDesktopVideoMode() ), windowTitle( "Allotropy Application" ) { }
- Context::Context( const VideoMode mVideoMode, const char* mWindowTitle ) : videoMode( mVideoMode ) {
- windowTitle = new char[strlen( mWindowTitle + 1 )];
- strcpy( windowTitle, mWindowTitle );
- }
- Context::~Context() {
- delete[] windowTitle;
- }
- bool Context::Restart() {
- glfwMakeContextCurrent( 0 ); // disable any current contexts
- SetupContextParameters();
- if ( videoMode.fullscreen ) {
- _window = glfwCreateWindow( videoMode.width, videoMode.height, windowTitle, glfwGetPrimaryMonitor(), nullptr );
- }
- else {
- _window = glfwCreateWindow( videoMode.width, videoMode.height, windowTitle, nullptr, nullptr );
- }
- glfwMakeContextCurrent( _window );
- if ( _window == nullptr ) {
- fprintf( stderr, "Failed to create a window!" ); // TODO: log error messages
- return false;
- }
- if ( !Context::isGlewInit ) {
- if ( glewInit() != GLEW_OK ) {
- fprintf( stderr, "Failed to initialize GLEW!" ); // TODO: log error messages
- return false;
- }
- else {
- Context::isGlewInit = true;
- }
- }
- return true;
- }
- void Context::StartFrame() {
- }
- void Context::EndFrame() {
- glfwSwapBuffers( _window );
- glfwPollEvents();
- }
- bool Context::ShouldClose() {
- return glfwWindowShouldClose( _window );
- }
- Context* Context::Create( const VideoMode mVideoMode, const char* mWindowTitle ) {
- Context* context = new Context( mVideoMode, mWindowTitle );
- if ( context->Restart() ) {
- return context;
- }
- else {
- delete context;
- return nullptr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement