Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some initial code (disabled for now) for setting up an OGL context
In the interests of getting this all done faster, I've decided to postpone work on the OGL implementation for now and focus on the SDL_Renderer version. This contains some basic code (include-guarded) for setting up an OGL context for the main SDL window.
- Loading branch information
Showing
13 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
ogl/context.cpp | ||
ogl/utils.cpp | ||
sdl/exception.cpp | ||
sdl/rect.cpp | ||
sdl/surface.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#ifdef USE_GL_RENDERING | ||
|
||
#include "ogl/context.hpp" | ||
|
||
#include <SDL_video.h> | ||
|
||
namespace gl | ||
{ | ||
context::context(sdl::window* window) | ||
: gl_context_(SDL_GL_CreateContext(*window)) | ||
{ | ||
// Set flags. | ||
set_context_flags(); | ||
|
||
// Initialize GLEW. | ||
// TODO: should this be moved somewhere else? | ||
glewExperimental = GL_TRUE; | ||
glewInit(); | ||
} | ||
|
||
context::~context() | ||
{ | ||
SDL_GL_DeleteContext(gl_context_); | ||
} | ||
|
||
void context::set_context_flags() | ||
{ | ||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | ||
|
||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | ||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); | ||
|
||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); | ||
|
||
// Turn on double buffering. | ||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | ||
|
||
// Enable VSync (sync buffer refresh with monitor refresh rate). | ||
SDL_GL_SetSwapInterval(1); | ||
} | ||
|
||
} | ||
|
||
#endif // USE_GL_RENDERING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef USE_GL_RENDERING | ||
|
||
#include "sdl/window.hpp" | ||
|
||
#include <GL/glew.h> | ||
#include <GL/gl.h> | ||
|
||
namespace gl | ||
{ | ||
/** Encapsulates the management of an OpenGL context for the current window. */ | ||
class context | ||
{ | ||
public: | ||
context(const context&) = delete; | ||
context& operator=(const context&) = delete; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param window The SDL window to attach a context to. | ||
*/ | ||
context(sdl::window* window); | ||
|
||
~context(); | ||
|
||
private: | ||
/** Sets any relevant flags for the GL context. */ | ||
void set_context_flags(); | ||
|
||
/** The window's OpenGL context. */ | ||
SDL_GLContext gl_context_; | ||
}; | ||
|
||
} // namespace gl | ||
|
||
#endif // USE_GL_RENDERING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#ifdef USE_GL_RENDERING | ||
|
||
#include "ogl/utils.hpp" | ||
|
||
#include <GL/gl.h> | ||
|
||
namespace gl | ||
{ | ||
void clear_screen() | ||
{ | ||
// Fully alpha black | ||
glClearColor(0.0, 0.0, 0.0, 1.0); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
} | ||
|
||
} // namespace gl | ||
|
||
#endif // USE_GL_RENDERING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef USE_GL_RENDERING | ||
|
||
namespace gl | ||
{ | ||
/** Fills the screen with fully-transparent black. */ | ||
void clear_screen(); | ||
|
||
} // namespace gl | ||
|
||
#endif // USE_GL_RENDERING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters