From 61bfb22f27f5216f989c023a5e39fad7e356d2d6 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 3 Aug 2012 23:23:13 +0200 Subject: Basic font rendering - added basic font rendering - minor refactoring & fixes --- src/graphics/opengl/gldevice.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/graphics/opengl/gldevice.cpp') diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 3a255f4..cef372f 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -64,7 +64,6 @@ void Gfx::GLDeviceConfig::LoadDefault() Gfx::CGLDevice::CGLDevice(const Gfx::GLDeviceConfig &config) { m_config = config; - m_wasInit = false; m_lighting = false; m_texturing = false; } @@ -74,11 +73,6 @@ Gfx::CGLDevice::~CGLDevice() { } -bool Gfx::CGLDevice::GetWasInit() -{ - return m_wasInit; -} - std::string Gfx::CGLDevice::GetError() { return m_error; @@ -110,8 +104,6 @@ bool Gfx::CGLDevice::Create() /* NOTE: when not using GLEW, extension testing is not performed, as it is assumed that glext.h is up-to-date and the OpenGL shared library has the required functions present. */ - m_wasInit = true; - // This is mostly done in all modern hardware by default // DirectX doesn't even allow the option to turn off perspective correction anymore // So turn it on permanently @@ -158,8 +150,6 @@ void Gfx::CGLDevice::Destroy() m_currentTextures.clear(); m_texturesEnabled.clear(); m_textureStageParams.clear(); - - m_wasInit = false; } void Gfx::CGLDevice::ConfigChanged(const Gfx::GLDeviceConfig& newConfig) @@ -385,15 +375,20 @@ bool Gfx::CGLDevice::GetLightEnabled(int index) This struct must not be deleted in other way than through DeleteTexture() */ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms) { - Gfx::Texture result; - ImageData *data = image->GetData(); if (data == NULL) { m_error = "Invalid texture data"; - return result; // invalid texture + return Gfx::Texture(); // invalid texture } + return CreateTexture(data, params); +} + +Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms) +{ + Gfx::Texture result; + result.valid = true; result.size.w = data->surface->w; result.size.h = data->surface->h; @@ -531,6 +526,24 @@ void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) glDisable(GL_TEXTURE_2D); } +void Gfx::CGLDevice::SetTexture(int index, unsigned int textureId) +{ + assert(index >= 0); + assert(index < static_cast( m_currentTextures.size() )); + + // Enable the given texture stage + glActiveTexture(GL_TEXTURE0 + index); + glEnable(GL_TEXTURE_2D); + + m_currentTextures[index].id = textureId; + + glBindTexture(GL_TEXTURE_2D, textureId); + + // Disable the stage if it is set so + if ( (! m_texturing) || (! m_texturesEnabled[index]) ) + glDisable(GL_TEXTURE_2D); +} + /** Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ Gfx::Texture Gfx::CGLDevice::GetTexture(int index) -- cgit v1.2.3-1-g7c22 From 7f80ca297154809523cd533edf1842ab1ae391aa Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 11 Aug 2012 17:17:04 +0200 Subject: Render mode setting, refactoring - finished SetState in CEngine - refactored Size and IntSize back to Point and IntPoint - other minor changes in CEngine --- src/graphics/opengl/gldevice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/graphics/opengl/gldevice.cpp') diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index cef372f..4c36053 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -122,7 +122,7 @@ bool Gfx::CGLDevice::Create() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glViewport(0, 0, m_config.size.w, m_config.size.h); + glViewport(0, 0, m_config.size.x, m_config.size.y); m_lights = std::vector(GL_MAX_LIGHTS, Gfx::Light()); @@ -390,8 +390,8 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr Gfx::Texture result; result.valid = true; - result.size.w = data->surface->w; - result.size.h = data->surface->h; + result.size.x = data->surface->w; + result.size.y = data->surface->h; // Use & enable 1st texture stage glActiveTexture(GL_TEXTURE0); -- cgit v1.2.3-1-g7c22 From b4b74c30e9aa93ae736db73df5cb0c5d508ec6ed Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 12 Aug 2012 10:45:04 +0200 Subject: Fixes & testing in CEngine - fixed bugs in settings modes, etc. - some additions and minor refactoring --- src/graphics/opengl/gldevice.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/graphics/opengl/gldevice.cpp') diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 4c36053..caa79ee 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -73,6 +73,13 @@ Gfx::CGLDevice::~CGLDevice() { } +void Gfx::CGLDevice::DebugHook() +{ + /* This function is only called here, so it can be used + * as a breakpoint when debugging using gDEBugger */ + glColor3i(0, 0, 0); +} + std::string Gfx::CGLDevice::GetError() { return m_error; @@ -1172,17 +1179,19 @@ void Gfx::CGLDevice::GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float & void Gfx::CGLDevice::SetCullMode(Gfx::CullMode mode) { - if (mode == Gfx::CULL_CW) glCullFace(GL_CW); - else if (mode == Gfx::CULL_CCW) glCullFace(GL_CCW); + // Cull clockwise back faces, so front face is the opposite + // (assuming GL_CULL_FACE is GL_BACK) + if (mode == Gfx::CULL_CW ) glFrontFace(GL_CCW); + else if (mode == Gfx::CULL_CCW) glFrontFace(GL_CW); else assert(false); } Gfx::CullMode Gfx::CGLDevice::GetCullMode() { GLint flag = 0; - glGetIntegerv(GL_CULL_FACE, &flag); - if (flag == GL_CW) return Gfx::CULL_CW; - else if (flag == GL_CCW) return Gfx::CULL_CCW; + glGetIntegerv(GL_FRONT_FACE, &flag); + if (flag == GL_CW) return Gfx::CULL_CCW; + else if (flag == GL_CCW) return Gfx::CULL_CW; else assert(false); return Gfx::CULL_CW; } -- cgit v1.2.3-1-g7c22