diff options
Diffstat (limited to 'src/graphics')
37 files changed, 1525 insertions, 1023 deletions
diff --git a/src/graphics/core/color.cpp b/src/graphics/core/color.cpp index f0b74f8..d51eb1a 100644 --- a/src/graphics/core/color.cpp +++ b/src/graphics/core/color.cpp @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/core/color.h" diff --git a/src/graphics/core/color.h b/src/graphics/core/color.h index 87a50f4..d73b47e 100644 --- a/src/graphics/core/color.h +++ b/src/graphics/core/color.h @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/color.h diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index a896104..f52e07f 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/device.h @@ -258,26 +260,16 @@ public: //! Sets the transform matrix of given type virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0; - //! Returns the current transform matrix of given type - virtual const Math::Matrix& GetTransform(TransformType type) = 0; - //! Multiplies the current transform matrix of given type by given matrix - virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0; //! Sets the current material virtual void SetMaterial(const Material &material) = 0; - //! Returns the current material - virtual const Material& GetMaterial() = 0; //! Returns the maximum number of lights available virtual int GetMaxLightCount() = 0; //! Sets the light at given index virtual void SetLight(int index, const Light &light) = 0; - //! Returns the current light at given index - virtual const Light& GetLight(int index) = 0; //! Enables/disables the light at given index virtual void SetLightEnabled(int index, bool enabled) = 0; - //! Returns the current enable state of light at given index - virtual bool GetLightEnabled(int index) = 0; //! Creates a texture from image; the image can be safely removed after that virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) = 0; @@ -294,17 +286,11 @@ public: virtual void SetTexture(int index, const Texture &texture) = 0; //! Sets the texture image by ID at given texture stage virtual void SetTexture(int index, unsigned int textureId) = 0; - //! Returns the (multi)texture at given index - virtual Texture GetTexture(int index) = 0; //! Enables/disables the given texture stage virtual void SetTextureEnabled(int index, bool enabled) = 0; - //! Returns the current enable state of given texture stage - virtual bool GetTextureEnabled(int index) = 0; //! Sets the params for texture stage with given index virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms) = 0; - //! Returns the current params of texture stage with given index - virtual TextureStageParams GetTextureStageParams(int index) = 0; //! Sets only the texture wrap modes (for faster than thru stage params) virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0; @@ -348,61 +334,39 @@ public: //! Enables/disables the given render state virtual void SetRenderState(RenderState state, bool enabled) = 0; - //! Returns the current setting of given render state - virtual bool GetRenderState(RenderState state) = 0; //! Sets the function of depth test virtual void SetDepthTestFunc(CompFunc func) = 0; - //! Returns the current function of depth test - virtual CompFunc GetDepthTestFunc() = 0; //! Sets the depth bias (constant value added to Z-coords) virtual void SetDepthBias(float factor) = 0; - //! Returns the current depth bias - virtual float GetDepthBias() = 0; //! Sets the alpha test function and reference value virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0; - //! Returns the current alpha test function and reference value - virtual void GetAlphaTestFunc(CompFunc &func, float &refValue) = 0; //! Sets the blending functions for source and destination operations virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0; - //! Returns the current blending functions for source and destination operations - virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) = 0; //! Sets the clear color virtual void SetClearColor(const Color &color) = 0; - //! Returns the current clear color - virtual Color GetClearColor() = 0; //! Sets the global ambient color virtual void SetGlobalAmbient(const Color &color) = 0; - //! Returns the global ambient color - virtual Color GetGlobalAmbient() = 0; //! Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) = 0; - //! Returns the current fog parameters: mode, color, start distance, end distance and density (for exp models) - virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) = 0; //! Sets the current cull mode virtual void SetCullMode(CullMode mode) = 0; - //! Returns the current cull mode - virtual CullMode GetCullMode() = 0; //! Sets the shade model virtual void SetShadeModel(ShadeModel model) = 0; - //! Returns the current shade model - virtual ShadeModel GetShadeModel() = 0; //! Sets the current fill mode virtual void SetFillMode(FillMode mode) = 0; - //! Returns the current fill mode - virtual FillMode GetFillMode() = 0; //! Returns the pixels of the entire screen - virtual void* GetFrameBufferPixels()const = 0; + virtual void* GetFrameBufferPixels() const = 0; }; diff --git a/src/graphics/core/light.h b/src/graphics/core/light.h index 923d0e9..e8eda7b 100644 --- a/src/graphics/core/light.h +++ b/src/graphics/core/light.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/light.h diff --git a/src/graphics/core/material.h b/src/graphics/core/material.h index e0bfaff..1fde860 100644 --- a/src/graphics/core/material.h +++ b/src/graphics/core/material.h @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/material.h diff --git a/src/graphics/core/nulldevice.cpp b/src/graphics/core/nulldevice.cpp new file mode 100644 index 0000000..f5e426d --- /dev/null +++ b/src/graphics/core/nulldevice.cpp @@ -0,0 +1,343 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + + +#include "graphics/core/nulldevice.h" + +#include "common/config.h" +#include "common/logger.h" + +#include "math/geometry.h" + + +// Graphics module namespace +namespace Gfx { + +CNullDevice::CNullDevice() +{ + m_matrix = Math::Matrix(); + m_material = Material(); + m_light = Light(); +} + +CNullDevice::~CNullDevice() +{ +} + +void CNullDevice::DebugHook() +{ +} + +void CNullDevice::DebugLights() +{ +} + +bool CNullDevice::Create() +{ + return true; +} + +void CNullDevice::Destroy() +{ +} + +void CNullDevice::BeginScene() +{ +} + +void CNullDevice::EndScene() +{ +} + +void CNullDevice::Clear() +{ +} + +void CNullDevice::SetTransform(TransformType type, const Math::Matrix &matrix) +{ +} + +const Math::Matrix& CNullDevice::GetTransform(TransformType type) +{ + return m_matrix; +} + +void CNullDevice::MultiplyTransform(TransformType type, const Math::Matrix &matrix) +{ +} + +void CNullDevice::SetMaterial(const Material &material) +{ +} + +const Material& CNullDevice::GetMaterial() +{ + return m_material; +} + +int CNullDevice::GetMaxLightCount() +{ + return 99; +} + +void CNullDevice::SetLight(int index, const Light &light) +{ +} + +const Light& CNullDevice::GetLight(int index) +{ + return m_light; +} + +void CNullDevice::SetLightEnabled(int index, bool enabled) +{ +} + +bool CNullDevice::GetLightEnabled(int index) +{ + return false; +} + +Texture CNullDevice::CreateTexture(CImage *image, const TextureCreateParams ¶ms) +{ + Texture tex; + tex.id = 1; // tex.id = 0 => invalid texture + return tex; +} + +Texture CNullDevice::CreateTexture(ImageData *data, const TextureCreateParams ¶ms) +{ + Texture tex; + tex.id = 1; // tex.id = 0 => invalid texture + return tex; +} + +void CNullDevice::DestroyTexture(const Texture &texture) +{ +} + +void CNullDevice::DestroyAllTextures() +{ +} + +int CNullDevice::GetMaxTextureStageCount() +{ + return 0; +} + +void CNullDevice::SetTexture(int index, const Texture &texture) +{ +} + +void CNullDevice::SetTexture(int index, unsigned int textureId) +{ +} + +Texture CNullDevice::GetTexture(int index) +{ + return Texture(); +} + +void CNullDevice::SetTextureEnabled(int index, bool enabled) +{ +} + +bool CNullDevice::GetTextureEnabled(int index) +{ + return false; +} + +void CNullDevice::SetTextureStageParams(int index, const TextureStageParams ¶ms) +{ +} + +void CNullDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) +{ +} + +TextureStageParams CNullDevice::GetTextureStageParams(int index) +{ + return TextureStageParams(); +} + +void CNullDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, + Color color) +{ +} + +void CNullDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, + Color color) +{ +} + +void CNullDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) +{ +} + +unsigned int CNullDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +{ + return 0; +} + +unsigned int CNullDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +{ + return 0; +} + +unsigned int CNullDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +{ + return 0; +} + +void CNullDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) +{ +} + +void CNullDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) +{ +} + +void CNullDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) +{ +} + +void CNullDevice::DrawStaticBuffer(unsigned int bufferId) +{ +} + +void CNullDevice::DestroyStaticBuffer(unsigned int bufferId) +{ +} + +int CNullDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) +{ + return 0; +} + +void CNullDevice::SetRenderState(RenderState state, bool enabled) +{ +} + +bool CNullDevice::GetRenderState(RenderState state) +{ + return false; +} + +void CNullDevice::SetDepthTestFunc(CompFunc func) +{ +} + +CompFunc CNullDevice::GetDepthTestFunc() +{ + return COMP_FUNC_NEVER; +} + +void CNullDevice::SetDepthBias(float factor) +{ +} + +float CNullDevice::GetDepthBias() +{ + return 0.0f; +} + +void CNullDevice::SetAlphaTestFunc(CompFunc func, float refValue) +{ +} + +void CNullDevice::GetAlphaTestFunc(CompFunc &func, float &refValue) +{ + + func = COMP_FUNC_NEVER; + refValue = 0.0f; +} + +void CNullDevice::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) +{ +} + +void CNullDevice::GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) +{ + srcBlend = BLEND_ZERO; + dstBlend = BLEND_ZERO; +} + +void CNullDevice::SetClearColor(const Color &color) +{ +} + +Color CNullDevice::GetClearColor() +{ + return Color(0.0f, 0.0f, 0.0f, 0.0f); +} + +void CNullDevice::SetGlobalAmbient(const Color &color) +{ +} + +Color CNullDevice::GetGlobalAmbient() +{ + return Color(0.0f, 0.0f, 0.0f, 0.0f); +} + +void CNullDevice::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) +{ +} + +void CNullDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) +{ + // +} + +void CNullDevice::SetCullMode(CullMode mode) +{ +} + +CullMode CNullDevice::GetCullMode() +{ + return CULL_CW; +} + +void CNullDevice::SetShadeModel(ShadeModel model) +{ +} + +ShadeModel CNullDevice::GetShadeModel() +{ + return SHADE_FLAT; +} + +void CNullDevice::SetFillMode(FillMode mode) +{ +} + +FillMode CNullDevice::GetFillMode() +{ + return FILL_POINT; +} + +void* CNullDevice::GetFrameBufferPixels() const +{ + return nullptr; +} + + +} // namespace Gfx + + diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h new file mode 100644 index 0000000..c6065a6 --- /dev/null +++ b/src/graphics/core/nulldevice.h @@ -0,0 +1,145 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ + +/** + * \file graphics/core/device.h + * \brief Abstract graphics device - CDevice class and related structs/enums + */ + +#pragma once + + +#include "graphics/core/device.h" + +// Graphics module namespace +namespace Gfx { + +/** + * \class CNullDevice + * \brief Device implementation that doesn't render anything + * + */ +class CNullDevice : public CDevice +{ +public: + CNullDevice(); + virtual ~CNullDevice(); + + virtual void DebugHook(); + virtual void DebugLights(); + + virtual bool Create(); + virtual void Destroy(); + + virtual void BeginScene(); + virtual void EndScene(); + + virtual void Clear(); + + virtual void SetTransform(TransformType type, const Math::Matrix &matrix); + virtual const Math::Matrix& GetTransform(TransformType type); + virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix); + + virtual void SetMaterial(const Material &material); + virtual const Material& GetMaterial(); + + virtual int GetMaxLightCount(); + virtual void SetLight(int index, const Light &light); + virtual const Light& GetLight(int index); + virtual void SetLightEnabled(int index, bool enabled); + virtual bool GetLightEnabled(int index); + + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms); + virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms); + virtual void DestroyTexture(const Texture &texture); + virtual void DestroyAllTextures(); + + virtual int GetMaxTextureStageCount(); + virtual void SetTexture(int index, const Texture &texture); + virtual void SetTexture(int index, unsigned int textureId); + virtual Texture GetTexture(int index); + virtual void SetTextureEnabled(int index, bool enabled); + virtual bool GetTextureEnabled(int index); + + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms); + virtual TextureStageParams GetTextureStageParams(int index); + + virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); + + virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); + virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); + virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); + + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); + virtual void DrawStaticBuffer(unsigned int bufferId); + virtual void DestroyStaticBuffer(unsigned int bufferId); + + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); + + virtual void SetRenderState(RenderState state, bool enabled); + virtual bool GetRenderState(RenderState state); + + virtual void SetDepthTestFunc(CompFunc func); + virtual CompFunc GetDepthTestFunc(); + + virtual void SetDepthBias(float factor); + virtual float GetDepthBias(); + + virtual void SetAlphaTestFunc(CompFunc func, float refValue); + virtual void GetAlphaTestFunc(CompFunc &func, float &refValue); + + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend); + virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend); + + virtual void SetClearColor(const Color &color); + virtual Color GetClearColor(); + + virtual void SetGlobalAmbient(const Color &color); + virtual Color GetGlobalAmbient(); + + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density); + virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density); + + virtual void SetCullMode(CullMode mode); + virtual CullMode GetCullMode(); + + virtual void SetShadeModel(ShadeModel model); + virtual ShadeModel GetShadeModel(); + + virtual void SetFillMode(FillMode mode) ; + virtual FillMode GetFillMode(); + + virtual void* GetFrameBufferPixels() const; + +private: + Math::Matrix m_matrix; + Material m_material; + Light m_light; +}; + + +} // namespace Gfx + diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h index 0702428..3ce06ee 100644 --- a/src/graphics/core/texture.h +++ b/src/graphics/core/texture.h @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/texture.h diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index ca68352..7af7212 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/core/vertex.h diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index fedc70a..6464b22 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/camera.h" @@ -137,6 +139,7 @@ CCamera::CCamera() m_scriptLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_effect = true; + m_blood = true; m_cameraScroll = true; m_cameraInvertX = false; m_cameraInvertY = false; @@ -151,6 +154,15 @@ void CCamera::SetEffect(bool enable) m_effect = enable; } +void CCamera::SetBlood(bool enable) +{ + m_blood = enable; +} + +bool CCamera::GetBlood() { + return m_blood; +} + void CCamera::SetCameraScroll(bool scroll) { m_cameraScroll = scroll; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 6d94dad..4fe821f 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/camera.h @@ -198,6 +200,8 @@ public: void SetScriptLookat(Math::Vector lookat); void SetEffect(bool enable); + void SetBlood(bool enable); + bool GetBlood(); void SetCameraScroll(bool scroll); void SetCameraInvertX(bool invert); void SetCameraInvertY(bool invert); @@ -379,6 +383,8 @@ protected: //! Shocks if explosion? bool m_effect; + //! Blood? + bool m_blood; //! Scroll in the edges? bool m_cameraScroll; //! X inversion in the edges? diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 74083af..7ec0d9e 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/cloud.h" @@ -125,8 +127,8 @@ void CCloud::Draw() material.ambient = m_ambient; m_engine->SetMaterial(material); - m_engine->SetTexture(m_fileName, 0); - m_engine->SetTexture(m_fileName, 1); + m_engine->SetTexture("textures/"+m_fileName, 0); + m_engine->SetTexture("textures/"+m_fileName, 1); m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_FOG | ENG_RSTATE_WRAP); @@ -218,7 +220,7 @@ void CCloud::Create(const std::string& fileName, m_fileName = fileName; if (! m_fileName.empty()) - m_engine->LoadTexture(m_fileName); + m_engine->LoadTexture("textures/"+m_fileName); if (m_terrain == nullptr) m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 8e820c7..decf1d6 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/cloud.h diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e0861d2..3c642ae 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -1,25 +1,26 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/engine.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -283,7 +284,7 @@ bool CEngine::Create() params.minFilter = TEX_MIN_FILTER_NEAREST; params.magFilter = TEX_MAG_FILTER_NEAREST; params.mipmap = false; - m_miceTexture = LoadTexture("mouse.png", params); + m_miceTexture = LoadTexture("textures/interface/mouse.png", params); GetSystemUtils()->GetCurrentTimeStamp(m_currentFrameTime); GetSystemUtils()->GetCurrentTimeStamp(m_lastFrameTime); @@ -294,6 +295,9 @@ bool CEngine::Create() void CEngine::Destroy() { m_text->Destroy(); + + delete m_pause; + m_pause = nullptr; delete m_lightMan; m_lightMan = nullptr; @@ -319,11 +323,13 @@ void CEngine::Destroy() void CEngine::ResetAfterDeviceChanged() { - m_size = m_app->GetVideoConfig().size;; + m_size = m_app->GetVideoConfig().size; m_text->FlushCache(); FlushTextureCache(); + + LoadAllTextures(); } bool CEngine::ProcessEvent(const Event &event) @@ -509,6 +515,16 @@ int CEngine::GetStatisticTriangle() return m_statisticTriangle; } +void CEngine::SetStatisticPos(Math::Vector pos) +{ + m_statisticPos = pos; +} + +void CEngine::SetTimerDisplay(const std::string& text) +{ + m_timerText = text; +} + /******************************************************* @@ -1124,10 +1140,10 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) p1.next[l2].next.clear(); if (!newP2.tex1.Valid()) - newP2.tex1 = LoadTexture(newP2.tex1Name); + newP2.tex1 = LoadTexture("textures/"+newP2.tex1Name); if (!newP2.tex2.Valid()) - newP2.tex2 = LoadTexture(newP2.tex2Name); + newP2.tex2 = LoadTexture("textures/"+newP2.tex2Name); } } @@ -1965,10 +1981,10 @@ bool CEngine::IsWithinLODLimit(float distance, LODLevel lodLevel) } min *= m_size.x / 640.0f; - min *= m_objectDetail*2.0f; + min *= 1.0f+m_objectDetail*2.0f; max *= m_size.x / 640.0f; - max *= m_objectDetail*2.0f; + max *= 1.0f+m_objectDetail*2.0f; } return distance >= min && distance < max; @@ -2258,7 +2274,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) + if (!img.Load(texName)) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); @@ -2309,27 +2325,27 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& bool CEngine::LoadAllTextures() { - LoadTexture("text.png"); - m_miceTexture = LoadTexture("mouse.png"); - LoadTexture("button1.png"); - LoadTexture("button2.png"); - LoadTexture("button3.png"); - LoadTexture("effect00.png"); - LoadTexture("effect01.png"); - LoadTexture("effect02.png"); - LoadTexture("map.png"); + LoadTexture("textures/interface/text.png"); + m_miceTexture = LoadTexture("textures/interface/mouse.png"); + LoadTexture("textures/interface/button1.png"); + LoadTexture("textures/interface/button2.png"); + LoadTexture("textures/interface/button3.png"); + LoadTexture("textures/effect00.png"); + LoadTexture("textures/effect01.png"); + LoadTexture("textures/effect02.png"); + LoadTexture("textures/interface/map.png"); if (! m_backgroundName.empty()) { TextureCreateParams params = m_defaultTexParams; params.padToNearestPowerOfTwo = true; - m_backgroundTex = LoadTexture(m_backgroundName, params); + m_backgroundTex = LoadTexture("textures/"+m_backgroundName, params); } else m_backgroundTex.SetInvalid(); if (! m_foregroundName.empty()) - m_foregroundTex = LoadTexture(m_foregroundName); + m_foregroundTex = LoadTexture("textures/"+m_foregroundName); else m_foregroundTex.SetInvalid(); @@ -2363,9 +2379,9 @@ bool CEngine::LoadAllTextures() if (! p2.tex1Name.empty()) { if (terrain) - p2.tex1 = LoadTexture(p2.tex1Name, m_terrainTexParams); + p2.tex1 = LoadTexture("textures/"+p2.tex1Name, m_terrainTexParams); else - p2.tex1 = LoadTexture(p2.tex1Name); + p2.tex1 = LoadTexture("textures/"+p2.tex1Name); if (! p2.tex1.Valid()) ok = false; @@ -2374,9 +2390,9 @@ bool CEngine::LoadAllTextures() if (! p2.tex2Name.empty()) { if (terrain) - p2.tex2 = LoadTexture(p2.tex2Name, m_terrainTexParams); + p2.tex2 = LoadTexture("textures/"+p2.tex2Name, m_terrainTexParams); else - p2.tex2 = LoadTexture(p2.tex2Name); + p2.tex2 = LoadTexture("textures/"+p2.tex2Name); if (! p2.tex2.Valid()) ok = false; @@ -2426,7 +2442,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) + if (!img.Load(texName)) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); @@ -2771,7 +2787,7 @@ void CEngine::SetBackground(const std::string& name, Color up, Color down, { TextureCreateParams params = m_defaultTexParams; params.padToNearestPowerOfTwo = true; - m_backgroundTex = LoadTexture(m_backgroundName, params); + m_backgroundTex = LoadTexture("textures/"+m_backgroundName, params); } } @@ -2797,7 +2813,7 @@ void CEngine::SetForegroundName(const std::string& name) m_foregroundName = name; if (! m_foregroundName.empty()) - m_foregroundTex = LoadTexture(m_foregroundName); + m_foregroundTex = LoadTexture("textures/"+m_foregroundName); } void CEngine::SetOverFront(bool front) @@ -3124,67 +3140,67 @@ void CEngine::Draw3DScene() m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN); - // Draw terrain with shadows, if shadows enabled - if (m_shadowVisible) + // Draw terrain + + m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); + + for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++) { - m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); + if (! m_objects[objRank].used) + continue; - for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++) - { - if (! m_objects[objRank].used) - continue; + if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) + continue; - if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) - continue; + if (! m_objects[objRank].drawWorld) + continue; - if (! m_objects[objRank].drawWorld) - continue; + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); - m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); + if (! IsVisible(objRank)) + continue; - if (! IsVisible(objRank)) - continue; + int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + continue; - int baseObjRank = m_objects[objRank].baseObjRank; - if (baseObjRank == -1) - continue; + assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() )); - assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() )); + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (! p1.used) + continue; - EngineBaseObject& p1 = m_baseObjects[baseObjRank]; - if (! p1.used) - continue; + for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; - for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) + SetTexture(p2.tex1, 0); + SetTexture(p2.tex2, 1); + + for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - EngineBaseObjTexTier& p2 = p1.next[l2]; + EngineBaseObjLODTier& p3 = p2.next[l3]; - SetTexture(p2.tex1, 0); - SetTexture(p2.tex2, 1); + if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) + continue; - for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) + for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - EngineBaseObjLODTier& p3 = p2.next[l3]; - - if (! IsWithinLODLimit(m_objects[objRank].distance, p3.lodLevel)) - continue; - - for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) - { - EngineBaseObjDataTier& p4 = p3.next[l4]; + EngineBaseObjDataTier& p4 = p3.next[l4]; - SetMaterial(p4.material); - SetState(p4.state); + SetMaterial(p4.material); + SetState(p4.state); - DrawObject(p4); - } + DrawObject(p4); } } } + } - // Draws the shadows + // Draws the shadows , if shadows enabled + if (m_shadowVisible) DrawShadow(); - } + m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN); @@ -3499,6 +3515,7 @@ void CEngine::DrawInterface() DrawMouse(); DrawHighlight(); DrawStats(); + DrawTimer(); } void CEngine::UpdateGroundSpotTextures() @@ -3736,7 +3753,7 @@ void CEngine::UpdateGroundSpotTextures() } std::stringstream str; - str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png"; + str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; std::string texName = str.str(); DeleteTexture(texName); @@ -3785,7 +3802,7 @@ void CEngine::DrawShadow() SetMaterial(material); // TODO: create a separate texture - SetTexture("text.png"); + SetTexture("textures/interface/text.png"); Math::Point ts, ti; @@ -4329,7 +4346,7 @@ void CEngine::DrawStats() float height = m_text->GetAscent(FONT_COLOBOT, 12.0f); float width = 0.2f; - Math::Point pos(0.04f, 0.04f + 17 * height); + Math::Point pos(0.04f, 0.04f + 20 * height); SetState(ENG_RSTATE_OPAQUE_COLOR); @@ -4337,9 +4354,9 @@ void CEngine::DrawStats() VertexCol vertex[4] = { - VertexCol(Math::Vector(pos.x , pos.y - 17 * height, 0.0f), black), + VertexCol(Math::Vector(pos.x , pos.y - 20 * height, 0.0f), black), VertexCol(Math::Vector(pos.x , pos.y + height, 0.0f), black), - VertexCol(Math::Vector(pos.x + width, pos.y - 17 * height, 0.0f), black), + VertexCol(Math::Vector(pos.x + width, pos.y - 20 * height, 0.0f), black), VertexCol(Math::Vector(pos.x + width, pos.y + height, 0.0f), black) }; @@ -4452,6 +4469,28 @@ void CEngine::DrawStats() pos.y -= height; m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + + pos.y -= height; + pos.y -= height; + + str.str(""); + str << "Position x: " << std::fixed << std::setprecision(2) << m_statisticPos.x/g_unit; + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + pos.y -= height; + + str.str(""); + str << "Position y: " << std::fixed << std::setprecision(2) << m_statisticPos.z/g_unit; + m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); +} + +void CEngine::DrawTimer() +{ + SetState(ENG_RSTATE_TEXT); + + Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COLOBOT, 15.0f)); + m_text->DrawText(m_timerText, FONT_COLOBOT, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index d56bf38..6ca7d1b 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX& EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/engine.h @@ -775,6 +777,12 @@ public: void AddStatisticTriangle(int nb); //! Returns the number of triangles in current frame int GetStatisticTriangle(); + + //! Sets the coordinates to display in stats window + void SetStatisticPos(Math::Vector pos); + + //! Sets text to display as mission timer + void SetTimerDisplay(const std::string& text); /* *************** Object management *************** */ @@ -1231,6 +1239,8 @@ protected: void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon); //! Draw statistic texts void DrawStats(); + //! Draw mission timer + void DrawTimer(); //! Creates a new tier 2 object (texture) EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name); @@ -1346,6 +1356,7 @@ protected: float m_fogStart[2]; Color m_waterAddColor; int m_statisticTriangle; + Math::Vector m_statisticPos; bool m_updateGeometry; bool m_updateStaticBuffers; int m_alphaMode; @@ -1436,6 +1447,8 @@ protected: bool m_debugLights; bool m_debugDumpLights; + + std::string m_timerText; }; diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 564cced..bb67ad0 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/lightman.h" diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 5df466d..d8f32bb 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/lightman.h diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 4395eec..be76b2f 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/lightning.h" @@ -235,7 +237,7 @@ void CLightning::Draw() mat.LoadIdentity(); device->SetTransform(TRANSFORM_WORLD, mat); - m_engine->SetTexture("effect00.png"); + m_engine->SetTexture("textures/effect00.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK); Math::Point texInf; diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index 1b1d339..3426515 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/lightning.h diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 99496aa..c422f18 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/modelfile.h" @@ -22,6 +24,10 @@ #include "common/logger.h" #include "common/stringutils.h" +#ifndef MODELFILE_NO_ENGINE +#include "common/resources/inputstream.h" +#endif + #include "graphics/engine/engine.h" #include "math/geometry.h" @@ -432,13 +438,23 @@ bool CModelFile::ReadModel(const std::string& fileName) { m_triangles.clear(); + #ifndef MODELFILE_NO_ENGINE + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) + { + GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); + return false; + } + #else std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); + stream.open(fileName); if (!stream.good()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; } + #endif return ReadModel(stream); } @@ -823,13 +839,23 @@ struct NewModelTriangle1 bool CModelFile::ReadTextModel(const std::string& fileName) { + #ifndef MODELFILE_NO_ENGINE + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) + { + GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); + return false; + } + #else std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in); + stream.open(fileName); if (!stream.good()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; } + #endif return ReadTextModel(stream); } @@ -1020,13 +1046,23 @@ bool CModelFile::WriteTextModel(std::ostream& stream) bool CModelFile::ReadBinaryModel(const std::string& fileName) { + #ifndef MODELFILE_NO_ENGINE + CInputStream stream; + stream.open(fileName); + if (!stream.is_open()) + { + GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); + return false; + } + #else std::ifstream stream; - stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); + stream.open(fileName); if (!stream.good()) { GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); return false; } + #endif return ReadBinaryModel(stream); } diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index 3b4019b..f6ac229 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/modelfile.h diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 0c0fb98..ec104d0 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -1,24 +1,25 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * Copyright (C) 2012-2014, 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/modelmanager.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/logger.h" @@ -48,11 +49,9 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); - - if (!modelFile.ReadModel(filePath)) + if (!modelFile.ReadModel("models/" + fileName)) { - GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str()); + GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str()); return false; } diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index ee5fc27..3805631 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * Copyright (C) 2012-2014, 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #pragma once diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index abee2e2..f5a16e9 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/particle.h" @@ -114,7 +116,7 @@ bool IsAlien(ObjectType type) //! Returns the damping factor for friendly fire float GetDecay(ObjectType type) { - if (IsSoft(type)) return 0.2f; + if (IsSoft(type)) return 0.004f; return 1.0f; } @@ -201,7 +203,7 @@ void NameParticle(std::string &name, int num) if (num == 1) name = "effect00.png"; else if (num == 2) name = "effect01.png"; else if (num == 3) name = "effect02.png"; - else if (num == 4) name = "text.png"; + else if (num == 4) name = "interface/text.png"; else name = ""; } @@ -3532,7 +3534,7 @@ void CParticle::DrawParticle(int sheet) if (m_particle[i].sheet != sheet) continue; if (m_particle[i].type == PARTIPART) continue; - m_engine->SetTexture(m_triangle[i].tex1Name); + m_engine->SetTexture("textures/"+m_triangle[i].tex1Name); m_engine->SetMaterial(m_triangle[i].material); m_engine->SetState(m_triangle[i].state); DrawParticleTriangle(i); @@ -3551,7 +3553,7 @@ void CParticle::DrawParticle(int sheet) // Draw tire marks. if (m_wheelTraceTotal > 0 && sheet == SH_WORLD) { - m_engine->SetTexture("text.png"); + m_engine->SetTexture("textures/interface/text.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); Math::Matrix matrix; matrix.LoadIdentity(); @@ -3582,7 +3584,7 @@ void CParticle::DrawParticle(int sheet) { std::string name; NameParticle(name, t); - m_engine->SetTexture(name); + m_engine->SetTexture("textures/"+name); loadTexture = true; } diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 7fb24a1..c7c7cef 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/particle.h diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp index 0c96f63..df34fbc 100644 --- a/src/graphics/engine/planet.cpp +++ b/src/graphics/engine/planet.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/planet.h" @@ -86,7 +88,7 @@ void CPlanet::LoadTexture() { for (int i = 0; i < static_cast<int>( m_planet[j].size() ); i++) { - m_engine->LoadTexture(m_planet[j][i].name); + m_engine->LoadTexture("textures/"+m_planet[j][i].name); } } } @@ -102,7 +104,7 @@ void CPlanet::Draw() for (int i = 0; i < static_cast<int>( m_planet[m_mode].size() ); i++) { - m_engine->SetTexture(m_planet[m_mode][i].name); + m_engine->SetTexture("textures/"+m_planet[m_mode][i].name); if (m_planet[m_mode][i].transparent) m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_ALPHA); diff --git a/src/graphics/engine/planet.h b/src/graphics/engine/planet.h index 58d3aeb..52ffd24 100644 --- a/src/graphics/engine/planet.h +++ b/src/graphics/engine/planet.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/planet.h diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index d3e0405..8d5d323 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/pyro.h" @@ -312,7 +314,7 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) } if ( m_type == PT_SHOTH ) { - if ( m_object->GetSelect() ) + if ( m_camera->GetBlood() && m_object->GetSelect() ) { m_camera->StartOver(CAM_OVER_EFFECT_BLOOD, m_pos, force); } @@ -672,7 +674,7 @@ bool CPyro::EventProcess(const Event &event) } } - if ( m_type == PT_SHOTH && + if ( m_camera->GetBlood() && m_type == PT_SHOTH && m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; @@ -694,7 +696,7 @@ bool CPyro::EventProcess(const Event &event) } } - if ( m_type == PT_SHOTM && + if ( m_camera->GetBlood() && m_type == PT_SHOTM && m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; @@ -1594,7 +1596,7 @@ void CPyro::ExploStart() if (channel != -1) m_object->SetMasterParticle(i, channel); } - m_engine->LoadTexture("dirty04.png"); + m_engine->LoadTexture("textures/dirty04.png"); DeleteObject(false, true); // destroys the object transported + the battery } @@ -1637,7 +1639,7 @@ void CPyro::BurnStart() m_engine->ChangeSecondTexture(objRank, "dirty04.png"); } } - m_engine->LoadTexture("dirty04.png"); + m_engine->LoadTexture("textures/dirty04.png"); m_burnPartTotal = 0; diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 60724b4..9646988 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/pyro.h diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 5f37cd8..b58685b 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -1,25 +1,26 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/terrain.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -122,7 +123,8 @@ bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int m_useMaterials = false; m_texBaseName = baseName; - size_t pos = baseName.find('.'); + size_t pos = baseName.rfind('.'); + if(pos < baseName.find_last_of('/')) pos = std::string::npos; // If last . is not a part of filename (some directory, possibly . or ..) if (pos == std::string::npos) { @@ -190,10 +192,10 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); - if (! img.Load(path)) + + if (! img.Load(fileName)) { - GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); + GetLogger()->Error("Cannot load resource file: '%s'\n", fileName.c_str()); return false; } @@ -287,10 +289,10 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); - if (! img.Load(path)) + + if (! img.Load(fileName)) { - GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); + GetLogger()->Error("Could not load relief file: '%s'!\n", fileName.c_str()); return false; } @@ -366,17 +368,11 @@ bool CTerrain::RandomizeRelief() double xi, yi, a, b; a = modf(x * (rozmiar_oktawy-1), &xi); b = modf(y * (rozmiar_oktawy-1), &yi); - /*int xi = floor(x * (rozmiar_oktawy-1)); - int yi = floor(y * (rozmiar_oktawy-1)); - float a = (x * (rozmiar_oktawy-1)) - xi; - float b = (y * (rozmiar_oktawy-1)) - yi;*/ - //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", xi, yi, a, b); float lg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi)]; float pg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi + 1)]; float ld = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi)]; float pd = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi + 1)]; - //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", lg, pg, ld, pd); float g = pg * a + lg * (1-a); float d = pd * a + ld * (1-a); diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 75a8975..a2bb36a 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/terrain.h diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 8fd01b7..bebf30c 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -1,29 +1,31 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/text.h" #include "app/app.h" -#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" #include "common/stringutils.h" +#include "common/resources/resourcemanager.h" #include "math/func.h" @@ -78,12 +80,12 @@ bool CText::Create() return false; } - m_fonts[FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf"); - m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf"); - m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf"); + m_fonts[FONT_COLOBOT] = new MultisizeFont("fonts/dvu_sans.ttf"); + m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("fonts/dvu_sans_bold.ttf"); + m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("fonts/dvu_sans_italic.ttf"); - m_fonts[FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf"); - m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf"); + m_fonts[FONT_COURIER] = new MultisizeFont("fonts/dvu_sans_mono.ttf"); + m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("fonts/dvu_sans_mono_bold.ttf"); for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { @@ -866,10 +868,14 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); - m_lastCachedFont = new CachedFont(); - m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); + SDL_RWops* file = CResourceManager::GetSDLFileHandler(mf->fileName); + if(file == nullptr) + { + m_error = std::string("Unable to open file"); + return nullptr; + } + m_lastCachedFont->font = TTF_OpenFontRW(file, 1, pointSize); if (m_lastCachedFont->font == nullptr) m_error = std::string("TTF_OpenFont error ") + std::string(TTF_GetError()); diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 3abb8b7..0551dcd 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/text.h diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index d1f8d29..8a396a8 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/engine/water.h" @@ -348,8 +350,8 @@ void CWater::DrawSurf() material.ambient = m_ambient; m_engine->SetMaterial(material); - m_engine->SetTexture(m_fileName, 0); - m_engine->SetTexture(m_fileName, 1); + m_engine->SetTexture("textures/"+m_fileName, 0); + m_engine->SetTexture("textures/"+m_fileName, 1); if (m_type[rankview] == WATER_TT) m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_DUAL_WHITE | ENG_RSTATE_WRAP, m_color); @@ -492,7 +494,7 @@ void CWater::Create(WaterType type1, WaterType type2, const std::string& fileNam VaporFlush(); if (! m_fileName.empty()) - m_engine->LoadTexture(m_fileName); + m_engine->LoadTexture("textures/"+m_fileName); if (m_terrain == nullptr) m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 5e9f4b2..5e488d5 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -1,19 +1,21 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/engine/water.h diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index b42f29d..a197b18 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ #include "graphics/opengl/gldevice.h" @@ -65,6 +68,7 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config) m_lastVboId = 0; m_multitextureAvailable = false; m_vboAvailable = false; + m_vertexBufferType = VBT_DISPLAY_LIST; } @@ -183,7 +187,7 @@ bool CGLDevice::Create() { GetLogger()->Info("Creating CDevice\n"); - static bool glewInited = false; + /*static*/ bool glewInited = false; if (!glewInited) { @@ -204,22 +208,43 @@ bool CGLDevice::Create() if (m_config.vboMode == VBO_MODE_ENABLE) { GetLogger()->Info("VBO enabled by override - using VBOs\n"); - m_vboAvailable = true; + SetVertexBufferType(VBT_VBO_CORE); } else if (m_config.vboMode == VBO_MODE_DISABLE) { GetLogger()->Info("VBO disabled by override - using display lists\n"); - m_vboAvailable = false; + SetVertexBufferType(VBT_DISPLAY_LIST); } else { GetLogger()->Info("Auto-detecting VBO support\n"); - m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object"); - - if (m_vboAvailable) - GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n"); - else - GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n"); + + // extracting OpenGL version + const char *version = reinterpret_cast<const char*>(glGetString(GL_VERSION)); + int major = 0, minor = 0; + + sscanf(version, "%d.%d", &major, &minor); + + // detecting VBO ARB extension + bool vboARB = glewIsSupported("GL_ARB_vertex_buffer_object"); + + // VBO is core OpenGL feature since 1.5 + // everything below 1.5 means no VBO support + if(major > 1 || minor > 4) + { + GetLogger()->Info("OpenGL %d.%d, VBO supported\n", major, minor); + SetVertexBufferType(VBT_VBO_CORE); + } + else if(vboARB) // VBO ARB extension available + { + GetLogger()->Info("OpenGL %d.%d with GL_ARB_vertex_buffer_object, VBO supported\n", major, minor); + SetVertexBufferType(VBT_VBO_ARB); + } + else // no VBO support + { + GetLogger()->Info("OpenGL %d.%d without GL_ARB_vertex_buffer_object, VBO not supported\n", major, minor); + SetVertexBufferType(VBT_DISPLAY_LIST); + } } } @@ -288,11 +313,13 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) void CGLDevice::SetUseVbo(bool vboAvailable) { m_vboAvailable = vboAvailable; + m_vertexBufferType = vboAvailable ? VBT_VBO_CORE : VBT_DISPLAY_LIST; } -bool CGLDevice::GetUseVbo() +void CGLDevice::SetVertexBufferType(VertexBufferType type) { - return m_vboAvailable; + m_vertexBufferType = type; + m_vboAvailable = (type != VBT_DISPLAY_LIST); } void CGLDevice::BeginScene() @@ -339,44 +366,6 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) } } -const Math::Matrix& CGLDevice::GetTransform(TransformType type) -{ - if (type == TRANSFORM_WORLD) - return m_worldMat; - else if (type == TRANSFORM_VIEW) - return m_viewMat; - else if (type == TRANSFORM_PROJECTION) - return m_projectionMat; - else - assert(false); - - return m_worldMat; // to avoid warning -} - -void CGLDevice::MultiplyTransform(TransformType type, const Math::Matrix &matrix) -{ - if (type == TRANSFORM_WORLD) - { - m_worldMat = Math::MultiplyMatrices(m_worldMat, matrix); - UpdateModelviewMatrix(); - } - else if (type == TRANSFORM_VIEW) - { - m_viewMat = Math::MultiplyMatrices(m_viewMat, matrix); - UpdateModelviewMatrix(); - } - else if (type == TRANSFORM_PROJECTION) - { - m_projectionMat = Math::MultiplyMatrices(m_projectionMat, matrix); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(m_projectionMat.Array()); - } - else - { - assert(false); - } -} - void CGLDevice::UpdateModelviewMatrix() { m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); @@ -402,11 +391,6 @@ void CGLDevice::SetMaterial(const Material &material) glMaterialfv(GL_FRONT, GL_SPECULAR, m_material.specular.Array()); } -const Material& CGLDevice::GetMaterial() -{ - return m_material; -} - int CGLDevice::GetMaxLightCount() { return m_lights.size(); @@ -482,14 +466,6 @@ void CGLDevice::UpdateLightPosition(int index) glPopMatrix(); } -const Light& CGLDevice::GetLight(int index) -{ - assert(index >= 0); - assert(index < static_cast<int>( m_lights.size() )); - - return m_lights[index]; -} - void CGLDevice::SetLightEnabled(int index, bool enabled) { assert(index >= 0); @@ -503,14 +479,6 @@ void CGLDevice::SetLightEnabled(int index, bool enabled) glDisable(GL_LIGHT0 + index); } -bool CGLDevice::GetLightEnabled(int index) -{ - assert(index >= 0); - assert(index < static_cast<int>( m_lights.size() )); - - return m_lightsEnabled[index]; -} - /** If image is invalid, returns invalid texture. Otherwise, returns pointer to new Texture struct. This struct must not be deleted in other way than through DeleteTexture() */ @@ -781,15 +749,6 @@ void CGLDevice::SetTexture(int index, unsigned int textureId) UpdateTextureParams(index); } -/** - Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ -Texture CGLDevice::GetTexture(int index) -{ - assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() )); - - return m_currentTextures[index]; -} - void CGLDevice::SetTextureEnabled(int index, bool enabled) { assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() )); @@ -813,13 +772,6 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled) glDisable(GL_TEXTURE_2D); } -bool CGLDevice::GetTextureEnabled(int index) -{ - assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() )); - - return m_texturesEnabled[index]; -} - /** Sets the texture parameters for the given texture stage. If the given texture was not set (bound) yet, nothing happens. @@ -851,13 +803,13 @@ void CGLDevice::UpdateTextureParams(int index) glActiveTexture(GL_TEXTURE0 + index); if (params.wrapS == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); else if (params.wrapS == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); else assert(false); if (params.wrapT == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); else if (params.wrapT == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else assert(false); @@ -990,25 +942,18 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr glActiveTexture(GL_TEXTURE0 + index); if (wrapS == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); else if (wrapS == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); else assert(false); if (wrapT == TEX_WRAP_CLAMP) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); else if (wrapT == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else assert(false); } -TextureStageParams CGLDevice::GetTextureStageParams(int index) -{ - assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() )); - - return m_textureStageParams[index]; -} - GLenum TranslateGfxPrimitive(PrimitiveType type) { GLenum flag = 0; @@ -1117,10 +1062,20 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve info.vertexCount = vertexCount; info.bufferId = 0; - glGenBuffers(1, &info.bufferId); - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + { + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glGenBuffersARB(1, &info.bufferId); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } m_vboObjects[id] = info; } @@ -1151,10 +1106,20 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve info.vertexCount = vertexCount; info.bufferId = 0; - glGenBuffers(1, &info.bufferId); - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + { + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glGenBuffersARB(1, &info.bufferId); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } m_vboObjects[id] = info; } @@ -1184,11 +1149,21 @@ unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Ve info.vertexType = VERTEX_TYPE_COL; info.vertexCount = vertexCount; info.bufferId = 0; - - glGenBuffers(1, &info.bufferId); - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + + if(m_vertexBufferType == VBT_VBO_CORE) + { + glGenBuffers(1, &info.bufferId); + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glGenBuffersARB(1, &info.bufferId); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } m_vboObjects[id] = info; } @@ -1219,9 +1194,18 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv info.vertexType = VERTEX_TYPE_NORMAL; info.vertexCount = vertexCount; - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + { + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } } else { @@ -1246,9 +1230,18 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv info.vertexType = VERTEX_TYPE_TEX2; info.vertexCount = vertexCount; - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + { + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } } else { @@ -1273,9 +1266,18 @@ void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiv info.vertexType = VERTEX_TYPE_COL; info.vertexCount = vertexCount; - glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); - glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + { + glBindBuffer(GL_ARRAY_BUFFER, info.bufferId); + glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } + else + { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, info.bufferId); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW_ARB); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } } else { @@ -1296,7 +1298,11 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) return; glEnable(GL_VERTEX_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, (*it).second.bufferId); + + if(m_vertexBufferType == VBT_VBO_CORE) + glBindBuffer(GL_ARRAY_BUFFER, (*it).second.bufferId); + else + glBindBufferARB(GL_ARRAY_BUFFER_ARB, (*it).second.bufferId); if ((*it).second.vertexType == VERTEX_TYPE_NORMAL) { @@ -1368,7 +1374,11 @@ void CGLDevice::DrawStaticBuffer(unsigned int bufferId) glDisableClientState(GL_COLOR_ARRAY); } - glBindBuffer(GL_ARRAY_BUFFER, 0); + if(m_vertexBufferType == VBT_VBO_CORE) + glBindBuffer(GL_ARRAY_BUFFER, 0); + else + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + glDisable(GL_VERTEX_ARRAY); } else @@ -1385,7 +1395,10 @@ void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) if (it == m_vboObjects.end()) return; - glDeleteBuffers(1, &(*it).second.bufferId); + if(m_vertexBufferType == VBT_VBO_CORE) + glDeleteBuffers(1, &(*it).second.bufferId); + else + glDeleteBuffersARB(1, &(*it).second.bufferId); m_vboObjects.erase(it); } @@ -1529,30 +1542,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled) glDisable(flag); } -bool CGLDevice::GetRenderState(RenderState state) -{ - if (state == RENDER_STATE_LIGHTING) - return m_lighting; - - GLenum flag = 0; - - switch (state) - { - case RENDER_STATE_DEPTH_WRITE: flag = GL_DEPTH_WRITEMASK; break; - case RENDER_STATE_BLENDING: flag = GL_BLEND; break; - case RENDER_STATE_FOG: flag = GL_FOG; break; - case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; - case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; - case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - default: assert(false); break; - } - - GLboolean result = GL_FALSE; - glGetBooleanv(flag, &result); - - return result == GL_TRUE; -} - CompFunc TranslateGLCompFunc(GLenum flag) { switch (flag) @@ -1592,39 +1581,16 @@ void CGLDevice::SetDepthTestFunc(CompFunc func) glDepthFunc(TranslateGfxCompFunc(func)); } -CompFunc CGLDevice::GetDepthTestFunc() -{ - GLint flag = 0; - glGetIntegerv(GL_DEPTH_FUNC, &flag); - return TranslateGLCompFunc(static_cast<GLenum>(flag)); -} - void CGLDevice::SetDepthBias(float factor) { glPolygonOffset(factor, 0.0f); } -float CGLDevice::GetDepthBias() -{ - GLfloat result = 0.0f; - glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &result); - return result; -} - void CGLDevice::SetAlphaTestFunc(CompFunc func, float refValue) { glAlphaFunc(TranslateGfxCompFunc(func), refValue); } -void CGLDevice::GetAlphaTestFunc(CompFunc &func, float &refValue) -{ - GLint flag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &flag); - func = TranslateGLCompFunc(static_cast<GLenum>(flag)); - - glGetFloatv(GL_ALPHA_TEST_REF, static_cast<GLfloat*>(&refValue)); -} - BlendFunc TranslateGLBlendFunc(GLenum flag) { switch (flag) @@ -1671,41 +1637,16 @@ void CGLDevice::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) glBlendFunc(TranslateGfxBlendFunc(srcBlend), TranslateGfxBlendFunc(dstBlend)); } -void CGLDevice::GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) -{ - GLint srcFlag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &srcFlag); - srcBlend = TranslateGLBlendFunc(static_cast<GLenum>(srcFlag)); - - GLint dstFlag = 0; - glGetIntegerv(GL_ALPHA_TEST_FUNC, &dstFlag); - dstBlend = TranslateGLBlendFunc(static_cast<GLenum>(dstFlag)); -} - void CGLDevice::SetClearColor(const Color &color) { glClearColor(color.r, color.g, color.b, color.a); } -Color CGLDevice::GetClearColor() -{ - GLfloat color[4] = { 0.0f }; - glGetFloatv(GL_COLOR_CLEAR_VALUE, color); - return Color(color[0], color[1], color[2], color[3]); -} - void CGLDevice::SetGlobalAmbient(const Color &color) { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.Array()); } -Color CGLDevice::GetGlobalAmbient() -{ - GLfloat color[4] = { 0.0f }; - glGetFloatv(GL_LIGHT_MODEL_AMBIENT, color); - return Color(color[0], color[1], color[2], color[3]); -} - void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) { if (mode == FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); @@ -1719,23 +1660,6 @@ void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, floa glFogfv(GL_FOG_COLOR, color.Array()); } -void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) -{ - GLint flag = 0; - glGetIntegerv(GL_FOG_MODE, &flag); - if (flag == GL_LINEAR) mode = FOG_LINEAR; - else if (flag == GL_EXP) mode = FOG_EXP; - else if (flag == GL_EXP2) mode = FOG_EXP2; - else assert(false); - - glGetFloatv(GL_FOG_START, static_cast<GLfloat*>(&start)); - glGetFloatv(GL_FOG_END, static_cast<GLfloat*>(&end)); - glGetFloatv(GL_FOG_DENSITY, static_cast<GLfloat*>(&density)); - GLfloat col[4] = { 0.0f }; - glGetFloatv(GL_FOG_COLOR, col); - color = Color(col[0], col[1], col[2], col[3]); -} - void CGLDevice::SetCullMode(CullMode mode) { // Cull clockwise back faces, so front face is the opposite @@ -1745,16 +1669,6 @@ void CGLDevice::SetCullMode(CullMode mode) else assert(false); } -CullMode CGLDevice::GetCullMode() -{ - GLint flag = 0; - glGetIntegerv(GL_FRONT_FACE, &flag); - if (flag == GL_CW) return CULL_CCW; - else if (flag == GL_CCW) return CULL_CW; - else assert(false); - return CULL_CW; -} - void CGLDevice::SetShadeModel(ShadeModel model) { if (model == SHADE_FLAT) glShadeModel(GL_FLAT); @@ -1762,16 +1676,6 @@ void CGLDevice::SetShadeModel(ShadeModel model) else assert(false); } -ShadeModel CGLDevice::GetShadeModel() -{ - GLint flag = 0; - glGetIntegerv(GL_SHADE_MODEL, &flag); - if (flag == GL_FLAT) return SHADE_FLAT; - else if (flag == GL_SMOOTH) return SHADE_SMOOTH; - else assert(false); - return SHADE_FLAT; -} - void CGLDevice::SetFillMode(FillMode mode) { if (mode == FILL_POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); @@ -1780,21 +1684,10 @@ void CGLDevice::SetFillMode(FillMode mode) else assert(false); } -FillMode CGLDevice::GetFillMode() -{ - GLint flag = 0; - glGetIntegerv(GL_POLYGON_MODE, &flag); - if (flag == GL_POINT) return FILL_POINT; - else if (flag == GL_LINE) return FILL_LINES; - else if (flag == GL_FILL) return FILL_POLY; - else assert(false); - return FILL_POINT; -} - void* CGLDevice::GetFrameBufferPixels()const{ - GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y]; - + GLubyte* pixels = new GLubyte[4 * m_config.size.x * m_config.size.y]; + glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); unsigned int* p = static_cast<unsigned int*> ( static_cast<void*>(pixels) ); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 267ee73..1174367 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -1,18 +1,21 @@ -// * 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/. +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsiteс.ch; http://colobot.info; http://github.com/colobot + * + * 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://gnu.org/licenses + */ /** * \file graphics/opengl/gldevice.h @@ -45,6 +48,17 @@ enum VBOMode }; /** + \enum VertexBufferType + \brief Specifies type of vertex buffer to use + */ +enum VertexBufferType +{ + VBT_DISPLAY_LIST, //! use display lists + VBT_VBO_CORE, //! use core OpenGL 1.5 VBOs + VBT_VBO_ARB //! use ARB extension VBOs +}; + +/** \struct GLDeviceConfig \brief Additional config with OpenGL-specific settings */ struct GLDeviceConfig : public DeviceConfig @@ -92,103 +106,84 @@ public: CGLDevice(const GLDeviceConfig &config); virtual ~CGLDevice(); - virtual void DebugHook(); - virtual void DebugLights(); + virtual void DebugHook() override; + virtual void DebugLights() override; - virtual bool Create(); - virtual void Destroy(); + virtual bool Create() override; + virtual void Destroy() override; void ConfigChanged(const GLDeviceConfig &newConfig); void SetUseVbo(bool useVbo); - bool GetUseVbo(); + void SetVertexBufferType(VertexBufferType type); - virtual void BeginScene(); - virtual void EndScene(); + virtual void BeginScene() override; + virtual void EndScene() override; - virtual void Clear(); + virtual void Clear() override; - virtual void SetTransform(TransformType type, const Math::Matrix &matrix); - virtual const Math::Matrix& GetTransform(TransformType type); - virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix); + virtual void SetTransform(TransformType type, const Math::Matrix &matrix) override; - virtual void SetMaterial(const Material &material); - virtual const Material& GetMaterial(); + virtual void SetMaterial(const Material &material) override; - virtual int GetMaxLightCount(); - virtual void SetLight(int index, const Light &light); - virtual const Light& GetLight(int index); - virtual void SetLightEnabled(int index, bool enabled); - virtual bool GetLightEnabled(int index); + virtual int GetMaxLightCount() override; + virtual void SetLight(int index, const Light &light) override; + virtual void SetLightEnabled(int index, bool enabled) override; - virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms); - virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms); - virtual void DestroyTexture(const Texture &texture); - virtual void DestroyAllTextures(); + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) override; + virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms) override; + virtual void DestroyTexture(const Texture &texture) override; + virtual void DestroyAllTextures() override; - virtual int GetMaxTextureStageCount(); - virtual void SetTexture(int index, const Texture &texture); - virtual void SetTexture(int index, unsigned int textureId); - virtual Texture GetTexture(int index); - virtual void SetTextureEnabled(int index, bool enabled); - virtual bool GetTextureEnabled(int index); + virtual int GetMaxTextureStageCount() override; + virtual void SetTexture(int index, const Texture &texture) override; + virtual void SetTexture(int index, unsigned int textureId) override; + virtual void SetTextureEnabled(int index, bool enabled) override; - virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms); - virtual TextureStageParams GetTextureStageParams(int index); + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms) override; - virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); + virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override; virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, - Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount, - Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)); - virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount); + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; + virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) override; - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); - virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount); - virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount); - virtual void DrawStaticBuffer(unsigned int bufferId); - virtual void DestroyStaticBuffer(unsigned int bufferId); + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override; + virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) override; + virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) override; + virtual void DrawStaticBuffer(unsigned int bufferId) override; + virtual void DestroyStaticBuffer(unsigned int bufferId) override; - virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); + virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius) override; - virtual void SetRenderState(RenderState state, bool enabled); - virtual bool GetRenderState(RenderState state); + virtual void SetRenderState(RenderState state, bool enabled) override; - virtual void SetDepthTestFunc(CompFunc func); - virtual CompFunc GetDepthTestFunc(); + virtual void SetDepthTestFunc(CompFunc func) override; - virtual void SetDepthBias(float factor); - virtual float GetDepthBias(); + virtual void SetDepthBias(float factor) override; - virtual void SetAlphaTestFunc(CompFunc func, float refValue); - virtual void GetAlphaTestFunc(CompFunc &func, float &refValue); + virtual void SetAlphaTestFunc(CompFunc func, float refValue) override; - virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend); - virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend); + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) override; - virtual void SetClearColor(const Color &color); - virtual Color GetClearColor(); + virtual void SetClearColor(const Color &color) override; - virtual void SetGlobalAmbient(const Color &color); - virtual Color GetGlobalAmbient(); + virtual void SetGlobalAmbient(const Color &color) override; - virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density); - virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density); + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) override; - virtual void SetCullMode(CullMode mode); - virtual CullMode GetCullMode(); + virtual void SetCullMode(CullMode mode) override; - virtual void SetShadeModel(ShadeModel model); - virtual ShadeModel GetShadeModel(); + virtual void SetShadeModel(ShadeModel model) override; - virtual void SetFillMode(FillMode mode) ; - virtual FillMode GetFillMode(); + virtual void SetFillMode(FillMode mode) override; - virtual void* GetFrameBufferPixels()const; + virtual void* GetFrameBufferPixels() const override; private: //! Updates internal modelview matrix @@ -252,6 +247,8 @@ private: bool m_multitextureAvailable; //! Whether to use VBOs or display lists bool m_vboAvailable; + //! Which vertex buffer type to use + VertexBufferType m_vertexBufferType; //! Map of saved VBO objects std::map<unsigned int, VboObjectInfo> m_vboObjects; //! Last ID of VBO object |