From 8797569d33c4917eb8f8a1dc2341aac7b5815315 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 22 Jul 2012 22:05:12 +0200 Subject: Texture & mouse functions; refactoring & fixes - cleaned up and added documentation to engine.h - refactored CEngine interface and associated structs - added mouse handling functions in CApplication & CEngine - fixed bugs in projection matrix setting - changed texture loading & handling - added const-values in CDevice & CGLDevice - changed event management in CApplication - other minor changes & bugfixes --- src/graphics/opengl/gldevice.cpp | 156 +++++++++++++--------------- src/graphics/opengl/gldevice.h | 31 +++--- src/graphics/opengl/glengine.cpp | 21 ---- src/graphics/opengl/glengine.h | 32 ------ src/graphics/opengl/test/model_test.cpp | 16 +-- src/graphics/opengl/test/texture_test.cpp | 12 +-- src/graphics/opengl/test/transform_test.cpp | 6 +- 7 files changed, 106 insertions(+), 168 deletions(-) delete mode 100644 src/graphics/opengl/glengine.cpp delete mode 100644 src/graphics/opengl/glengine.h (limited to 'src/graphics/opengl') diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 19a9cff..3d63bf2 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -30,21 +30,6 @@ #include -namespace Gfx { - -struct GLDevicePrivate -{ - void (APIENTRY* glMultiTexCoord2fARB)(GLenum target, GLfloat s, GLfloat t); - void (APIENTRY* glActiveTextureARB)(GLenum texture); - - GLDevicePrivate() - { - glMultiTexCoord2fARB = NULL; - glActiveTextureARB = NULL; - } -}; - -}; // namespace Gfx void Gfx::GLDeviceConfig::LoadDefault() @@ -65,7 +50,6 @@ void Gfx::GLDeviceConfig::LoadDefault() Gfx::CGLDevice::CGLDevice() { - m_private = new Gfx::GLDevicePrivate(); m_wasInit = false; m_texturing = false; } @@ -73,8 +57,6 @@ Gfx::CGLDevice::CGLDevice() Gfx::CGLDevice::~CGLDevice() { - delete m_private; - m_private = NULL; } bool Gfx::CGLDevice::GetWasInit() @@ -108,15 +90,6 @@ bool Gfx::CGLDevice::Create() return false; } - /*m_private->glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) SDL_GL_GetProcAddress("glMultiTexCoord2fARB"); - m_private->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); - - if ((m_private->glMultiTexCoord2fARB == NULL) || (m_private->glActiveTextureARB == NULL)) - { - m_error = "Could not load extension functions, even though they seem supported"; - return false; - }*/ - m_wasInit = true; // This is mostly done in all modern hardware by default @@ -141,7 +114,7 @@ bool Gfx::CGLDevice::Create() int maxTextures = 0; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextures); - m_textures = std::vector (maxTextures, (Gfx::Texture*)(NULL)); + m_textures = std::vector (maxTextures, Gfx::Texture()); m_texturesEnabled = std::vector (maxTextures, false); m_texturesParams = std::vector(maxTextures, Gfx::TextureParams()); @@ -150,9 +123,6 @@ bool Gfx::CGLDevice::Create() void Gfx::CGLDevice::Destroy() { - /*m_private->glMultiTexCoord2fARB = NULL; - m_private->glActiveTextureARB = NULL;*/ - // Delete the remaining textures // Should not be strictly necessary, but just in case DestroyAllTextures(); @@ -174,8 +144,7 @@ void Gfx::CGLDevice::BeginScene() glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_projectionMat.Array()); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m_modelviewMat.Array()); + UpdateModelviewMatrix(); } void Gfx::CGLDevice::EndScene() @@ -193,16 +162,12 @@ void Gfx::CGLDevice::SetTransform(Gfx::TransformType type, const Math::Matrix &m if (type == Gfx::TRANSFORM_WORLD) { m_worldMat = matrix; - m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m_modelviewMat.Array()); + UpdateModelviewMatrix(); } else if (type == Gfx::TRANSFORM_VIEW) { m_viewMat = matrix; - m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m_modelviewMat.Array()); + UpdateModelviewMatrix(); } else if (type == Gfx::TRANSFORM_PROJECTION) { @@ -235,16 +200,12 @@ void Gfx::CGLDevice::MultiplyTransform(Gfx::TransformType type, const Math::Matr if (type == Gfx::TRANSFORM_WORLD) { m_worldMat = Math::MultiplyMatrices(m_worldMat, matrix); - m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m_modelviewMat.Array()); + UpdateModelviewMatrix(); } else if (type == Gfx::TRANSFORM_VIEW) { m_viewMat = Math::MultiplyMatrices(m_viewMat, matrix); - m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(m_modelviewMat.Array()); + UpdateModelviewMatrix(); } else if (type == Gfx::TRANSFORM_PROJECTION) { @@ -258,7 +219,17 @@ void Gfx::CGLDevice::MultiplyTransform(Gfx::TransformType type, const Math::Matr } } -void Gfx::CGLDevice::SetMaterial(Gfx::Material &material) +void Gfx::CGLDevice::UpdateModelviewMatrix() +{ + m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glScalef(1.0f, 1.0f, -1.0f); + glMultMatrixf(m_modelviewMat.Array()); +} + +void Gfx::CGLDevice::SetMaterial(const Gfx::Material &material) { m_material = material; @@ -277,7 +248,7 @@ int Gfx::CGLDevice::GetMaxLightCount() return m_lights.size(); } -void Gfx::CGLDevice::SetLight(int index, Gfx::Light &light) +void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light) { assert(index >= 0); assert(index < (int)m_lights.size()); @@ -285,9 +256,9 @@ void Gfx::CGLDevice::SetLight(int index, Gfx::Light &light) m_lights[index] = light; // Indexing from GL_LIGHT0 should always work - glLightfv(GL_LIGHT0 + index, GL_AMBIENT, light.ambient.Array()); - glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, light.diffuse.Array()); - glLightfv(GL_LIGHT0 + index, GL_SPECULAR, light.specular.Array()); + glLightfv(GL_LIGHT0 + index, GL_AMBIENT, const_cast(light.ambient.Array())); + glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, const_cast(light.diffuse.Array())); + glLightfv(GL_LIGHT0 + index, GL_SPECULAR, const_cast(light.specular.Array())); GLfloat position[4] = { light.position.x, light.position.y, light.position.z, 0.0f }; if (light.type == LIGHT_DIRECTIONAL) @@ -334,17 +305,23 @@ bool Gfx::CGLDevice::GetLightEnabled(int index) return m_lightsEnabled[index]; } -/** If image is invalid, returns NULL. +/** If image is invalid, returns invalid texture. Otherwise, returns pointer to new Gfx::Texture struct. 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 Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms) { + Gfx::Texture result; + ImageData *data = image->GetData(); if (data == NULL) - return NULL; + { + m_error = "Invalid texture data"; + return result; // invalid texture + } - Gfx::Texture *result = new Gfx::Texture(); - result->valid = true; + result.valid = true; + result.width = data->surface->w; + result.height = data->surface->h; // Use & enable 1st texture stage glActiveTextureARB(GL_TEXTURE0_ARB); @@ -352,8 +329,8 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glGenTextures(1, &result->id); - glBindTexture(GL_TEXTURE_2D, result->id); + glGenTextures(1, &result.id); + glBindTexture(GL_TEXTURE_2D, result.id); // Set params @@ -395,13 +372,25 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre GLenum sourceFormat = 0; if (params.format == Gfx::TEX_IMG_RGB) + { sourceFormat = GL_RGB; + result.alpha = false; + } else if (params.format == Gfx::TEX_IMG_BGR) + { sourceFormat = GL_BGR; + result.alpha = false; + } else if (params.format == Gfx::TEX_IMG_RGBA) + { sourceFormat = GL_RGBA; + result.alpha = true; + } else if (params.format == Gfx::TEX_IMG_BGRA) + { sourceFormat = GL_BGRA; + result.alpha = true; + } else assert(false); @@ -410,10 +399,10 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre // Restore the previous state of 1st stage - if (m_textures[0] == NULL) - glBindTexture(GL_TEXTURE_2D, 0); + if (m_textures[0].valid) + glBindTexture(GL_TEXTURE_2D, m_textures[0].id); else - glBindTexture(GL_TEXTURE_2D, m_textures[0]->id); + glBindTexture(GL_TEXTURE_2D, 0); if ( (! m_texturing) || (! m_texturesEnabled[0]) ) glDisable(GL_TEXTURE_2D); @@ -421,9 +410,9 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre return result; } -void Gfx::CGLDevice::DestroyTexture(Gfx::Texture *texture) +void Gfx::CGLDevice::DestroyTexture(const Gfx::Texture &texture) { - std::set::iterator it = m_allTextures.find(texture); + std::set::iterator it = m_allTextures.find(texture); if (it != m_allTextures.end()) m_allTextures.erase(it); @@ -431,21 +420,18 @@ void Gfx::CGLDevice::DestroyTexture(Gfx::Texture *texture) for (int index = 0; index < (int)m_textures.size(); ++index) { if (m_textures[index] == texture) - SetTexture(index, NULL); + SetTexture(index, Gfx::Texture()); // set to invalid texture } - glDeleteTextures(1, &texture->id); + glDeleteTextures(1, &texture.id); } void Gfx::CGLDevice::DestroyAllTextures() { - std::set allCopy = m_allTextures; - std::set::iterator it; + std::set allCopy = m_allTextures; + std::set::iterator it; for (it = allCopy.begin(); it != allCopy.end(); ++it) - { DestroyTexture(*it); - delete *it; - } } int Gfx::CGLDevice::GetMaxTextureCount() @@ -454,10 +440,10 @@ int Gfx::CGLDevice::GetMaxTextureCount() } /** - If \a texture is \c NULL or invalid, unbinds the given texture. + If \a texture is invalid, unbinds the given texture. If valid, binds the texture and enables the given texture stage. The setting is remembered, even if texturing is disabled at the moment. */ -void Gfx::CGLDevice::SetTexture(int index, Gfx::Texture *texture) +void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) { assert(index >= 0); assert(index < (int)m_textures.size()); @@ -466,15 +452,15 @@ void Gfx::CGLDevice::SetTexture(int index, Gfx::Texture *texture) glActiveTextureARB(GL_TEXTURE0_ARB + index); glEnable(GL_TEXTURE_2D); - if ((texture == NULL) || (! texture->valid)) + m_textures[index] = texture; // remember the change + + if (! texture.valid) { glBindTexture(GL_TEXTURE_2D, 0); // unbind texture - m_textures[index] = NULL; // remember the changes } else { - glBindTexture(GL_TEXTURE_2D, texture->id); // bind the texture - m_textures[index] = texture; // remember the changes + glBindTexture(GL_TEXTURE_2D, texture.id); // bind the texture SetTextureParams(index, m_texturesParams[index]); // texture params need to be re-set for the new texture } @@ -484,8 +470,8 @@ void Gfx::CGLDevice::SetTexture(int index, Gfx::Texture *texture) } /** - Returns the previously assigned texture or \c NULL if the given stage is not enabled. */ -Gfx::Texture* Gfx::CGLDevice::GetTexture(int index) + Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ +Gfx::Texture Gfx::CGLDevice::GetTexture(int index) { assert(index >= 0); assert(index < (int)m_textures.size()); @@ -528,14 +514,14 @@ void Gfx::CGLDevice::SetTextureParams(int index, const Gfx::TextureParams ¶m m_texturesParams[index] = params; // Don't actually do anything if texture not set - if (m_textures[index] == NULL) + if (! m_textures[index].valid) return; // Enable the given stage glActiveTextureARB(GL_TEXTURE0_ARB + index); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, m_textures[index]->id); + glBindTexture(GL_TEXTURE_2D, m_textures[index].id); // Selection of operation and arguments glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -639,7 +625,7 @@ Gfx::TextureParams Gfx::CGLDevice::GetTextureParams(int index) return m_texturesParams[index]; } -void Gfx::CGLDevice::SetTextureFactor(Gfx::Color &color) +void Gfx::CGLDevice::SetTextureFactor(const Gfx::Color &color) { // Needs to be set for all texture stages for (int index = 0; index < (int)m_textures.size(); ++index) @@ -749,7 +735,7 @@ bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float */ // TODO: testing -int Gfx::CGLDevice::ComputeSphereVisibility(Math::Vector center, float radius) +int Gfx::CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) { Math::Matrix m; m.LoadIdentity(); @@ -847,6 +833,7 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) case Gfx::RENDER_STATE_FOG: flag = GL_FOG; break; case Gfx::RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case Gfx::RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; + case Gfx::RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; case Gfx::RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -872,6 +859,7 @@ bool Gfx::CGLDevice::GetRenderState(Gfx::RenderState state) case Gfx::RENDER_STATE_FOG: flag = GL_FOG; break; case Gfx::RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; case Gfx::RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; + case Gfx::RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; case Gfx::RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -1011,7 +999,7 @@ void Gfx::CGLDevice::GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstB dstBlend = TranslateGLBlendFunc(dstFlag); } -void Gfx::CGLDevice::SetClearColor(Gfx::Color color) +void Gfx::CGLDevice::SetClearColor(const Gfx::Color &color) { glClearColor(color.r, color.g, color.b, color.a); } @@ -1023,7 +1011,7 @@ Gfx::Color Gfx::CGLDevice::GetClearColor() return Gfx::Color(color[0], color[1], color[2], color[3]); } -void Gfx::CGLDevice::SetGlobalAmbient(Gfx::Color color) +void Gfx::CGLDevice::SetGlobalAmbient(const Gfx::Color &color) { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.Array()); } @@ -1035,7 +1023,7 @@ Gfx::Color Gfx::CGLDevice::GetGlobalAmbient() return Gfx::Color(color[0], color[1], color[2], color[3]); } -void Gfx::CGLDevice::SetFogParams(Gfx::FogMode mode, Gfx::Color color, float start, float end, float density) +void Gfx::CGLDevice::SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density) { if (mode == Gfx::FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); else if (mode == Gfx::FOG_EXP) glFogi(GL_FOG_MODE, GL_EXP); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 56ea2c0..792ea4b 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -88,36 +88,36 @@ public: virtual const Math::Matrix& GetTransform(Gfx::TransformType type); virtual void MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix); - virtual void SetMaterial(Gfx::Material &material); + virtual void SetMaterial(const Gfx::Material &material); virtual const Gfx::Material& GetMaterial(); virtual int GetMaxLightCount(); - virtual void SetLight(int index, Gfx::Light &light); + virtual void SetLight(int index, const Gfx::Light &light); virtual const Gfx::Light& GetLight(int index); virtual void SetLightEnabled(int index, bool enabled); virtual bool GetLightEnabled(int index); - virtual Gfx::Texture* CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms); - virtual void DestroyTexture(Gfx::Texture *texture); + virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms); + virtual void DestroyTexture(const Gfx::Texture &texture); virtual void DestroyAllTextures(); virtual int GetMaxTextureCount(); - virtual void SetTexture(int index, Gfx::Texture *texture); - virtual Gfx::Texture* GetTexture(int index); + virtual void SetTexture(int index, const Gfx::Texture &texture); + virtual Gfx::Texture GetTexture(int index); virtual void SetTextureEnabled(int index, bool enabled); virtual bool GetTextureEnabled(int index); virtual void SetTextureParams(int index, const Gfx::TextureParams ¶ms); virtual Gfx::TextureParams GetTextureParams(int index); - virtual void SetTextureFactor(Gfx::Color &color); + virtual void SetTextureFactor(const Gfx::Color &color); virtual Gfx::Color GetTextureFactor(); virtual void DrawPrimitive(Gfx::PrimitiveType type, Vertex *vertices, int vertexCount); virtual void DrawPrimitive(Gfx::PrimitiveType type, Gfx::VertexCol *vertices, int vertexCount); virtual void DrawPrimitive(Gfx::PrimitiveType type, VertexTex2 *vertices, int vertexCount); - virtual int ComputeSphereVisibility(Math::Vector center, float radius); + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); virtual void SetRenderState(Gfx::RenderState state, bool enabled); virtual bool GetRenderState(Gfx::RenderState state); @@ -134,13 +134,13 @@ public: virtual void SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend); virtual void GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend); - virtual void SetClearColor(Gfx::Color color); + virtual void SetClearColor(const Gfx::Color &color); virtual Gfx::Color GetClearColor(); - virtual void SetGlobalAmbient(Gfx::Color color); + virtual void SetGlobalAmbient(const Gfx::Color &color); virtual Gfx::Color GetGlobalAmbient(); - virtual void SetFogParams(Gfx::FogMode mode, Gfx::Color color, float start, float end, float density); + virtual void SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density); virtual void GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density); virtual void SetCullMode(Gfx::CullMode mode); @@ -153,8 +153,9 @@ public: virtual Gfx::FillMode GetFillMode(); private: - //! Private, OpenGL-specific data - GLDevicePrivate* m_private; + void UpdateModelviewMatrix(); + +private: //! Was initialized? bool m_wasInit; //! Last encountered error @@ -180,14 +181,14 @@ private: //! Whether texturing is enabled in general bool m_texturing; //! Current textures; \c NULL value means unassigned - std::vector m_textures; + std::vector m_textures; //! Current texture stages enable status std::vector m_texturesEnabled; //! Current texture params std::vector m_texturesParams; //! Set of all created textures - std::set m_allTextures; + std::set m_allTextures; }; }; // namespace Gfx diff --git a/src/graphics/opengl/glengine.cpp b/src/graphics/opengl/glengine.cpp deleted file mode 100644 index 9aab348..0000000 --- a/src/graphics/opengl/glengine.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * 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 3 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; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// glengine.h - -#include "graphics/opengl/glengine.h" - -// TODO \ No newline at end of file diff --git a/src/graphics/opengl/glengine.h b/src/graphics/opengl/glengine.h deleted file mode 100644 index fa67bfe..0000000 --- a/src/graphics/opengl/glengine.h +++ /dev/null @@ -1,32 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * 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 3 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; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// glengine.h - -#pragma once - - -#include "graphics/common/engine.h" - -namespace Gfx -{ - -class CGLEngine : public Gfx::CEngine -{ - // TODO -}; - -}; diff --git a/src/graphics/opengl/test/model_test.cpp b/src/graphics/opengl/test/model_test.cpp index 88404b7..3aad1b6 100644 --- a/src/graphics/opengl/test/model_test.cpp +++ b/src/graphics/opengl/test/model_test.cpp @@ -34,15 +34,15 @@ Math::Vector ROTATION; const int FRAME_DELAY = 5000; -std::map TEXS; +std::map TEXS; SystemTimeStamp *PREV_TIME = NULL, *CURR_TIME = NULL; -Gfx::Texture* GetTexture(const std::string &name) +Gfx::Texture GetTexture(const std::string &name) { - std::map::iterator it = TEXS.find(name); + std::map::iterator it = TEXS.find(name); if (it == TEXS.end()) - return NULL; + return Gfx::Texture(); return (*it).second; } @@ -52,10 +52,10 @@ void LoadTexture(Gfx::CGLDevice *device, const std::string &name) if (name.empty()) return; - if (GetTexture(name) != NULL) - return; + Gfx::Texture tex = GetTexture(name); - Gfx::Texture *tex = NULL; + if (tex.valid) + return; CImage img; if (! img.Load(std::string("tex/") + name)) @@ -114,7 +114,7 @@ void Render(Gfx::CGLDevice *device, Gfx::CModelFile *modelFile) device->BeginScene(); Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (600.0f) / (800.0f), 0.1f, 100.0f); + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); Math::Matrix id; diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp index 03847fc..66ed770 100644 --- a/src/graphics/opengl/test/texture_test.cpp +++ b/src/graphics/opengl/test/texture_test.cpp @@ -40,8 +40,8 @@ void Init(Gfx::CGLDevice *device) tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; tex2CreateParams.wrapS = Gfx::TEX_WRAP_CLAMP; - Gfx::Texture* tex1 = device->CreateTexture(&img1, tex1CreateParams); - Gfx::Texture* tex2 = device->CreateTexture(&img2, tex2CreateParams); + Gfx::Texture tex1 = device->CreateTexture(&img1, tex1CreateParams); + Gfx::Texture tex2 = device->CreateTexture(&img2, tex2CreateParams); device->SetTexture(0, tex1); device->SetTexture(1, tex2); @@ -75,13 +75,13 @@ void Render(Gfx::CGLDevice *device) static Gfx::VertexTex2 quad[] = { - Gfx::VertexTex2(Math::Vector(-2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 1.0f), Math::Point(0.0f, 1.0f)), - Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), + Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), Gfx::VertexTex2(Math::Vector( 2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 0.0f), Math::Point(1.0f, 0.0f)), + Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), - Gfx::VertexTex2(Math::Vector( 2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 0.0f), Math::Point(1.0f, 0.0f)), - Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), + Gfx::VertexTex2(Math::Vector( 2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(1.0f, 1.0f), Math::Point(1.0f, 1.0f)), Gfx::VertexTex2(Math::Vector(-2.0f, -2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 1.0f), Math::Point(0.0f, 1.0f)), + Gfx::VertexTex2(Math::Vector(-2.0f, 2.0f, 0.0f), Math::Vector(), Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f)), }; Math::Matrix t; diff --git a/src/graphics/opengl/test/transform_test.cpp b/src/graphics/opengl/test/transform_test.cpp index 5982c4e..4decaa0 100644 --- a/src/graphics/opengl/test/transform_test.cpp +++ b/src/graphics/opengl/test/transform_test.cpp @@ -38,13 +38,13 @@ void Init(Gfx::CGLDevice *device) device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); device->SetShadeModel(Gfx::SHADE_SMOOTH); } - +#include void Render(Gfx::CGLDevice *device) { device->BeginScene(); Math::Matrix persp; - Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (600.0f) / (800.0f), 0.1f, 100.0f); + Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f); device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp); @@ -71,6 +71,8 @@ void Render(Gfx::CGLDevice *device) Gfx::VertexCol line[2] = { Gfx::VertexCol() }; + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + for (int x = -40; x <= 40; ++x) { line[0].color = Gfx::Color(0.7f + x / 120.0f, 0.0f, 0.0f); -- cgit v1.2.3-1-g7c22