From ee2c02610d173ffb77e5feb55b66d720cc5cc8f5 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 2 Aug 2012 00:57:28 +0000 Subject: [PATCH] - updated copyright headers is some files that had them missing - added a new language string for battle end screen --- source/glest_game/CMakeLists.txt | 2 +- source/glest_game/main/macosx_main.h | 8 + source/glest_game/main/macosx_main.m | 17 +- source/masterserver/addServerInfo.php | 4 + source/masterserver/cleanUpServerList.php | 4 + source/masterserver/config.php | 4 + source/masterserver/createDB.sql | 3 + source/masterserver/functions.php | 4 + source/masterserver/index.php | 4 + source/masterserver/showMapsForGlest.php | 3 + source/masterserver/showRecentServers.php | 4 + source/masterserver/showScenariosForGlest.php | 3 + source/masterserver/showServers.php | 4 + source/masterserver/showServersForGlest.php | 4 + source/masterserver/showServersJson.php | 4 + source/masterserver/showTechsForGlest.php | 3 + source/masterserver/showTilesetsForGlest.php | 3 + source/shared_lib/CMakeLists.txt | 2 +- .../shared_lib/include/graphics/FileReader.h | 10 +- source/shared_lib/include/graphics/buffer.h | 7 + .../include/graphics/d3d9/context_d3d9.h | 58 ++++++ .../include/graphics/d3d9/d3d9_util.h | 9 +- .../include/graphics/d3d9/font_d3d9.h | 33 ++++ .../graphics/d3d9/model_renderer_d3d9.h | 60 ++++++ .../include/graphics/d3d9/shader_d3d9.h | 116 +++++++++++ .../graphics/d3d9/text_renderer_d3d9.h | 32 ++++ .../include/graphics/d3d9/texture_d3d9.h | 48 +++++ source/shared_lib/include/util/randomgen.h | 5 +- .../sources/graphics/FileReader.cpp | 7 + source/shared_lib/sources/graphics/buffer.cpp | 62 ++++++ .../sources/graphics/d3d9/context_d3d9.cpp | 12 +- .../sources/graphics/d3d9/d3d9_util.cpp | 7 + .../sources/graphics/d3d9/font_d3d9.cpp | 9 +- .../graphics/d3d9/model_renderer_d3d9.cpp | 180 ++++++++++++++++++ .../sources/graphics/d3d9/shader_d3d9.cpp | 7 + .../graphics/d3d9/text_renderer_d3d9.cpp | 47 +++++ .../sources/graphics/d3d9/texture_d3d9.cpp | 9 +- source/shared_lib/sources/util/randomgen.cpp | 12 ++ 38 files changed, 790 insertions(+), 20 deletions(-) create mode 100644 source/shared_lib/include/graphics/d3d9/context_d3d9.h create mode 100644 source/shared_lib/include/graphics/d3d9/font_d3d9.h create mode 100644 source/shared_lib/include/graphics/d3d9/model_renderer_d3d9.h create mode 100644 source/shared_lib/include/graphics/d3d9/shader_d3d9.h create mode 100644 source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h create mode 100644 source/shared_lib/include/graphics/d3d9/texture_d3d9.h create mode 100644 source/shared_lib/sources/graphics/buffer.cpp create mode 100644 source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp create mode 100644 source/shared_lib/sources/graphics/d3d9/text_renderer_d3d9.cpp diff --git a/source/glest_game/CMakeLists.txt b/source/glest_game/CMakeLists.txt index e1207493a..fbb9ea2a4 100644 --- a/source/glest_game/CMakeLists.txt +++ b/source/glest_game/CMakeLists.txt @@ -141,7 +141,7 @@ IF(BUILD_MEGAGLEST) ${GLEST_LIB_INCLUDE_ROOT}util ${GLEST_LIB_INCLUDE_ROOT}graphics ${GLEST_LIB_INCLUDE_ROOT}graphics/gl - ${GLEST_LIB_INCLUDE_ROOT}graphics/md5 + ${GLEST_LIB_INCLUDE_ROOT}graphics/iqm ${GLEST_LIB_INCLUDE_ROOT}sound ${GLEST_LIB_INCLUDE_ROOT}sound/openal ${GLEST_LIB_INCLUDE_ROOT}xml diff --git a/source/glest_game/main/macosx_main.h b/source/glest_game/main/macosx_main.h index a40465e94..1fee22cf7 100644 --- a/source/glest_game/main/macosx_main.h +++ b/source/glest_game/main/macosx_main.h @@ -4,6 +4,14 @@ // // Feel free to customize this file to suit your needs // +// Copyright (C) 2012 Mark Vejvoda +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + #import diff --git a/source/glest_game/main/macosx_main.m b/source/glest_game/main/macosx_main.m index 341543966..b67bbedb6 100644 --- a/source/glest_game/main/macosx_main.m +++ b/source/glest_game/main/macosx_main.m @@ -1,9 +1,16 @@ -/* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn +// SDLMain.m - main entry point for our Cocoa-ized SDL app +// Initial Version: Darrell Walisser +// Non-NIB-Code & other changes: Max Horn +// +// Feel free to customize this file to suit your needs - Feel free to customize this file to suit your needs -*/ +// Copyright (C) 2012 Mark Vejvoda +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== #import #import "macosx_main.h" diff --git a/source/masterserver/addServerInfo.php b/source/masterserver/addServerInfo.php index 0ac925721..ae4a0b87f 100644 --- a/source/masterserver/addServerInfo.php +++ b/source/masterserver/addServerInfo.php @@ -1,4 +1,8 @@ diff --git a/source/masterserver/showMapsForGlest.php b/source/masterserver/showMapsForGlest.php index 3db91d32f..6d2d83024 100644 --- a/source/masterserver/showMapsForGlest.php +++ b/source/masterserver/showMapsForGlest.php @@ -1,4 +1,7 @@ + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class ContextD3d9 +// =============================== + +class ContextD3d9: public Context{ +private: + bool windowed; + bool hardware; + + IDirect3D9 *d3dObject; + IDirect3DDevice9 *d3dDevice; + D3DCAPS9 caps; + D3DPRESENT_PARAMETERS d3dPresentParameters; + +public: + bool getWindowed() const {return windowed;} + bool getHardware() const {return hardware;} + + void setWindowed(bool windowed) {this->windowed= windowed;} + void setHardware(bool hardware) {this->hardware= hardware;} + + ContextD3d9(); + + virtual void init(); + virtual void end(); + virtual void reset(); + + virtual void makeCurrent(); + virtual void swapBuffers(); + + const D3DCAPS9 *getCaps() const {return ∩︀}; + + + IDirect3DDevice9 *getD3dDevice() {return d3dDevice;} +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/graphics/d3d9/d3d9_util.h b/source/shared_lib/include/graphics/d3d9/d3d9_util.h index e5048145f..a529a711b 100644 --- a/source/shared_lib/include/graphics/d3d9/d3d9_util.h +++ b/source/shared_lib/include/graphics/d3d9/d3d9_util.h @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #ifndef _SHARED_D3D9_D3D9UTIL_H_ #define _SHARED_D3D9_D3D9UTIL_H_ @@ -23,4 +30,4 @@ inline void checkResult(HRESULT result, const string &functionCall){ }}}//end namespace -#endif \ No newline at end of file +#endif diff --git a/source/shared_lib/include/graphics/d3d9/font_d3d9.h b/source/shared_lib/include/graphics/d3d9/font_d3d9.h new file mode 100644 index 000000000..89db4340a --- /dev/null +++ b/source/shared_lib/include/graphics/d3d9/font_d3d9.h @@ -0,0 +1,33 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#ifndef _SHARED_D3D9_FONTD3D9_H_ +#define _SHARED_D3D9_FONTD3D9_H_ + +#include "font.h" + +#include + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class FontD3d9 +// =============================== + +class Font2DD3d9: public Font2D{ +private: + LPD3DXFONT d3dFont; + +public: + LPD3DXFONT getD3dFont() const {return d3dFont;} + virtual void init(); + virtual void end(); +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/graphics/d3d9/model_renderer_d3d9.h b/source/shared_lib/include/graphics/d3d9/model_renderer_d3d9.h new file mode 100644 index 000000000..d70bcdbd5 --- /dev/null +++ b/source/shared_lib/include/graphics/d3d9/model_renderer_d3d9.h @@ -0,0 +1,60 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#ifndef _SHARED_D3D9_MODELRENDERERD3D9_H_ +#define _SHARED_D3D9_MODELRENDERERD3D9_H_ + +#include "model_renderer.h" +#include "model.h" + +#include + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class ModelRendererD3d9 +// =============================== + +class ModelRendererD3d9: public ModelRenderer{ +private: + static const int defBufferPointCount= 100; //buffer size in vertices + static const int defBufferIndexCount= 100; //buffer size in vertices + + struct CustomVertexPNTT{ + Vec3f vertex; + Vec3f normal; + Vec2f texCoord; + Vec3f tangent; + }; + +private: + bool rendering; + int bufferPointCount; + int bufferIndexCount; + + IDirect3DDevice9 *d3dDevice; + IDirect3DVertexBuffer9 *d3dVertexBuffer; + IDirect3DIndexBuffer9 *d3dIndexBuffer; + IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNT; + IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNTT; + +public: + ModelRendererD3d9(); + ~ModelRendererD3d9(); + virtual void begin(bool renderNormals= true, bool renderTextures= true, bool renderColors= true); + virtual void end(); + virtual void render(const Model *model); + virtual void renderNormalsOnly(const Model *model); + +private: + void renderMesh(const Mesh *mesh); + void readyBuffers(int newPointCount, int newIndexCount); +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/graphics/d3d9/shader_d3d9.h b/source/shared_lib/include/graphics/d3d9/shader_d3d9.h new file mode 100644 index 000000000..7b5b351da --- /dev/null +++ b/source/shared_lib/include/graphics/d3d9/shader_d3d9.h @@ -0,0 +1,116 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#ifndef _SHARED_D3D9_SHADERD3D9_H_ +#define _SHARED_D3D9_SHADERD3D9_H_ + +#include "shader.h" +#include "vec.h" + +#include +#include + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class ShaderProgramD3d9 +// =============================== + +class VertexShaderD3d9; +class PixelShaderD3d9; + +class ShaderProgramD3d9: public virtual ShaderProgram{ +protected: + IDirect3DDevice9 *d3dDevice; + ID3DXConstantTable *d3dVsConstantTable; + ID3DXConstantTable *d3dPsConstantTable; + + VertexShaderD3d9 *vertexShader; + PixelShaderD3d9 *pixelShader; + +public: + ShaderProgramD3d9(); + + virtual void init(){}; + virtual void end(){}; + + virtual void attach(VertexShader *vs, FragmentShader *fs); + virtual void activate(); + + virtual bool link(string &messages); + + virtual void setUniform(const string &name, int value); + virtual void setUniform(const string &name, float value); + virtual void setUniform(const string &name, const Vec2f &value); + virtual void setUniform(const string &name, const Vec3f &value); + virtual void setUniform(const string &name, const Vec4f &value); + virtual void setUniform(const string &name, const Matrix3f &value); + virtual void setUniform(const string &name, const Matrix4f &value); + //virtual void setUniform(const string &name, const Texture *value); +}; + + +// =============================== +// class ShaderD3d9 +// =============================== + +class ShaderD3d9: virtual public Shader{ +protected: + ShaderSource source; + string target; + + IDirect3DDevice9 *d3dDevice; + ID3DXConstantTable *d3dConstantTable; + +public: + ShaderD3d9(); + virtual void init(){}; + virtual void end(); + virtual void load(const string &path); + + ID3DXConstantTable *getD3dConstantTable() const {return d3dConstantTable;} + + void setTarget(const string &target) {this->target= target;} +}; + +// =============================== +// class VertexShaderD3d9 +// =============================== + +class VertexShaderD3d9: public ShaderD3d9, public VertexShader{ +private: + IDirect3DVertexShader9 *d3dVertexShader; + +public: + VertexShaderD3d9(); + virtual void end(); + + virtual bool compile(string &messages); + + IDirect3DVertexShader9 *getD3dVertexShader() const {return d3dVertexShader;} +}; + +// =============================== +// class PixelShaderD3d9 +// =============================== + +class PixelShaderD3d9: public ShaderD3d9, public FragmentShader{ +private: + IDirect3DPixelShader9 *d3dPixelShader; + +public: + PixelShaderD3d9(); + virtual void end(); + + virtual bool compile(string &messages); + + IDirect3DPixelShader9 *getD3dPixelShader() const {return d3dPixelShader;} +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h b/source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h new file mode 100644 index 000000000..29037a5cd --- /dev/null +++ b/source/shared_lib/include/graphics/d3d9/text_renderer_d3d9.h @@ -0,0 +1,32 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#ifndef _SHARED_D3D9_TEXTRENDERERD3D9_H_ +#define _SHARED_D3D9_TEXTRENDERERD3D9_H_ + +#include "text_renderer.h" + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class TextRenderer2DD3d9 +// =============================== + +class TextRenderer2DD3d9: public TextRenderer2D{ +private: + const Font *font; + Vec4f color; + +public: + virtual void begin(const Font2D *font); + virtual void render(const string &text, int x, int y, bool centered= false); + virtual void end(); +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/graphics/d3d9/texture_d3d9.h b/source/shared_lib/include/graphics/d3d9/texture_d3d9.h new file mode 100644 index 000000000..488237527 --- /dev/null +++ b/source/shared_lib/include/graphics/d3d9/texture_d3d9.h @@ -0,0 +1,48 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#ifndef _SHARED_D3D9_TEXTURED3D9_H_ +#define _SHARED_D3D9_TEXTURED3D9_H_ + +#include "texture.h" +#include + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================== +// class Texture2DD3d9 +// =============================== + +class Texture2DD3d9: public Texture2D{ +private: + IDirect3DTexture9 *d3dTexture; + +public: + IDirect3DTexture9 *getD3dTexture() const {return d3dTexture;} + + virtual void init(Filter textureFilter, int maxAnisotropy= 1); + virtual void end(); +}; + +// =============================== +// class TextureCubeD3d9 +// =============================== + +class TextureCubeD3d9: public TextureCube{ +private: + IDirect3DCubeTexture9 *d3dCubeTexture; + +public: + IDirect3DCubeTexture9 *getD3dCubeTexture() const {return d3dCubeTexture;} + + virtual void init(Filter textureFilter, int maxAnisotropy= 1); + virtual void end(); +}; + +}}}//end namespace + +#endif diff --git a/source/shared_lib/include/util/randomgen.h b/source/shared_lib/include/util/randomgen.h index 634864557..9a319abb9 100644 --- a/source/shared_lib/include/util/randomgen.h +++ b/source/shared_lib/include/util/randomgen.h @@ -1,7 +1,8 @@ // ============================================================== -// This file is part of Glest Shared Library (www.glest.org) +// This file is part of MegaGlest Shared Library (www.megaglest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// 2001-2008 Martiño Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published diff --git a/source/shared_lib/sources/graphics/FileReader.cpp b/source/shared_lib/sources/graphics/FileReader.cpp index f05021e06..a138578ae 100644 --- a/source/shared_lib/sources/graphics/FileReader.cpp +++ b/source/shared_lib/sources/graphics/FileReader.cpp @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #include "FileReader.h" namespace Shared { diff --git a/source/shared_lib/sources/graphics/buffer.cpp b/source/shared_lib/sources/graphics/buffer.cpp new file mode 100644 index 000000000..0f7623d7d --- /dev/null +++ b/source/shared_lib/sources/graphics/buffer.cpp @@ -0,0 +1,62 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#include "buffer.h" + +#include "leak_dumper.h" + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// class VertexBuffer +// ===================================================== + +VertexBuffer::VertexBuffer(){ + positionPointer= NULL; + normalPointer= NULL; + for(int i= 0; i @@ -70,4 +80,4 @@ void ContextD3d9::reset(){ } -}}}//end namespace \ No newline at end of file +}}}//end namespace diff --git a/source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp b/source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp index d7e24ab91..a0312d4c4 100644 --- a/source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp +++ b/source/shared_lib/sources/graphics/d3d9/d3d9_util.cpp @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #include "d3d9_util.h" namespace Shared{ namespace Graphics{ namespace D3d9{ diff --git a/source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp b/source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp index 0a93610c3..5981312fb 100644 --- a/source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp +++ b/source/shared_lib/sources/graphics/d3d9/font_d3d9.cpp @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #include "font_d3d9.h" #include @@ -35,4 +42,4 @@ void Font2DD3d9::end(){ } -}}}//end namespace \ No newline at end of file +}}}//end namespace diff --git a/source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp b/source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp new file mode 100644 index 000000000..55f3546f7 --- /dev/null +++ b/source/shared_lib/sources/graphics/d3d9/model_renderer_d3d9.cpp @@ -0,0 +1,180 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#include "model_renderer_d3d9.h" + +#include + +#include "graphics_interface.h" +#include "context_d3d9.h" +#include "texture_d3d9.h" +#include "interpolation.h" +#include "d3d9_util.h" + +#include "leak_dumper.h" + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================================== +// class ModelRendererD3d9 +// =============================================== + +D3DVERTEXELEMENT9 d3dVertexElementsPNT[]= +{ + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, + {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, + D3DDECL_END() +}; + +D3DVERTEXELEMENT9 d3dVertexElementsPNTT[]= +{ + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, + {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, + {0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0}, + D3DDECL_END() +}; + +ModelRendererD3d9::ModelRendererD3d9(){ + rendering= false; + + GraphicsInterface &gi= GraphicsInterface::getInstance(); + d3dDevice= static_cast(gi.getCurrentContext())->getD3dDevice(); + + bufferPointCount= 0; + bufferIndexCount= 0; + + D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNT, &d3dVertexDeclarationPNT)); + D3DCALL(d3dDevice->CreateVertexDeclaration(d3dVertexElementsPNTT, &d3dVertexDeclarationPNTT)); + + readyBuffers(defBufferPointCount, defBufferIndexCount); +} + +ModelRendererD3d9::~ModelRendererD3d9(){ + d3dVertexBuffer->Release(); +} + +void ModelRendererD3d9::begin(bool renderNormals, bool renderTextures, bool renderColors){ + rendering= true; +} + +void ModelRendererD3d9::end(){ + rendering= false; +} + +void ModelRendererD3d9::render(const Model *model){ + assert(rendering); + + //render every mesh + for(uint32 i=0; igetMeshCount(); ++i){ + renderMesh(model->getMesh(i)); + } +} + +void ModelRendererD3d9::renderNormalsOnly(const Model *model){ +} + +// ====================== Private =============================================== + +void ModelRendererD3d9::renderMesh(const Mesh *mesh){ + + CustomVertexPNTT *vertices; + uint32 *indices; + + readyBuffers(mesh->getVertexCount(), mesh->getIndexCount()); + + //lock vertex buffer + D3DCALL(d3dVertexBuffer->Lock(0, mesh->getVertexCount()*sizeof(CustomVertexPNTT), (void**) &vertices, 0)); + + //copy data vertex buffer + const InterpolationData *interpolationData= mesh->getInterpolationData(); + + for(int i=0; igetVertexCount(); ++i){ + vertices[i].vertex= interpolationData->getVertices()[i]; + vertices[i].normal= interpolationData->getNormals()[i]; + Vec2f texCoord= mesh->getTexCoords()[i]; + vertices[i].texCoord= Vec2f(texCoord.x, texCoord.y); + } + if(mesh->getTangents()!=NULL){ + for(int i=0; igetVertexCount(); ++i){ + vertices[i].tangent= mesh->getTangents()[i]; + } + } + + //unlock vertex buffer + D3DCALL(d3dVertexBuffer->Unlock()); + + //lock index buffer + D3DCALL(d3dIndexBuffer->Lock(0, mesh->getIndexCount()*sizeof(uint32), (void**) &indices, 0)); + + //copy data + for(int i=0; igetIndexCount(); i+=3){ + indices[i]= mesh->getIndices()[i]; + indices[i+1]= mesh->getIndices()[i+2]; + indices[i+2]= mesh->getIndices()[i+1]; + } + + //unlock + D3DCALL(d3dIndexBuffer->Unlock()); + + //set stream data + D3DCALL(d3dDevice->SetStreamSource(0, d3dVertexBuffer, 0, sizeof(CustomVertexPNTT))); + D3DCALL(d3dDevice->SetVertexDeclaration(mesh->getTangents()==NULL? d3dVertexDeclarationPNT: d3dVertexDeclarationPNTT)); + D3DCALL(d3dDevice->SetIndices(d3dIndexBuffer)); + + //set textures + int textureUnit= 0; + for(int i=0; igetTexture(i)!=NULL){ + const Texture2DD3d9* texture2DD3d9= static_cast(mesh->getTexture(i)); + D3DCALL(d3dDevice->SetTexture(textureUnit, texture2DD3d9->getD3dTexture())); + ++textureUnit; + } + } + + //render + D3DCALL(d3dDevice->BeginScene()); + D3DCALL(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getVertexCount(), 0, mesh->getIndexCount()/3)); + D3DCALL(d3dDevice->EndScene()); + + //reset textures + for(int i=0; iSetTexture(i, NULL)); + } +} + +void ModelRendererD3d9::readyBuffers(int newPointCount, int newIndexCount){ + + //vertices, if the buffer is to small allocate a new buffer + if(bufferPointCountCreateVertexBuffer( + bufferPointCount*sizeof(CustomVertexPNTT), + 0, + 0, + D3DPOOL_MANAGED, + &d3dVertexBuffer, + NULL)); + } + + //indices + if(bufferIndexCountCreateIndexBuffer( + bufferIndexCount*sizeof(uint32), + 0, + D3DFMT_INDEX32, + D3DPOOL_MANAGED, + &d3dIndexBuffer, + NULL)); + } +} + +}}}//end namespace diff --git a/source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp b/source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp index 53d6cafd8..26a183dab 100644 --- a/source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp +++ b/source/shared_lib/sources/graphics/d3d9/shader_d3d9.cpp @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #include "shader_d3d9.h" #include diff --git a/source/shared_lib/sources/graphics/d3d9/text_renderer_d3d9.cpp b/source/shared_lib/sources/graphics/d3d9/text_renderer_d3d9.cpp new file mode 100644 index 000000000..148fe4057 --- /dev/null +++ b/source/shared_lib/sources/graphics/d3d9/text_renderer_d3d9.cpp @@ -0,0 +1,47 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + +#include "text_renderer_d3d9.h" + +#include +#include + +#include "font_d3d9.h" +#include "d3d9_util.h" +#include "leak_dumper.h" + +namespace Shared{ namespace Graphics{ namespace D3d9{ + +// =============================================== +// class TextRenderer2DD3d9 +// =============================================== + +void TextRenderer2DD3d9::begin(const Font2D *font){ + this->font= font; + this->color= Vec4f(1.0f); +} + +void TextRenderer2DD3d9::render(const string &text, int x, int y, bool centered){ + RECT rect; + rect.bottom= y; + rect.left= x; + rect.top= y; + rect.right= x; + + D3DCOLOR d3dColor= D3DCOLOR_ARGB( + static_cast(color.w*255), + static_cast(color.x*255), + static_cast(color.y*255), + static_cast(color.z*255)); + + static_cast(font)->getD3dFont()->DrawText(text.c_str(), -1, &rect, DT_NOCLIP, d3dColor); +} + +void TextRenderer2DD3d9::end(){ +} + +}}}//end namespace diff --git a/source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp b/source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp index d1a8327dd..e737c2b0f 100644 --- a/source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp +++ b/source/shared_lib/sources/graphics/d3d9/texture_d3d9.cpp @@ -1,3 +1,10 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// The Megaglest Team, under GNU GPL v3.0 +// ============================================================== + #include "texture_d3d9.h" #include @@ -189,4 +196,4 @@ void TextureCubeD3d9::end(){ } } -}}}//end namespace \ No newline at end of file +}}}//end namespace diff --git a/source/shared_lib/sources/util/randomgen.cpp b/source/shared_lib/sources/util/randomgen.cpp index 51fbc4d3b..31a92f573 100644 --- a/source/shared_lib/sources/util/randomgen.cpp +++ b/source/shared_lib/sources/util/randomgen.cpp @@ -1,3 +1,15 @@ +// ============================================================== +// This file is part of MegaGlest Shared Library (www.megaglest.org) +// +// Copyright (C) 2012 Mark Vejvoda, Titus Tscharntke +// 2001-2008 Martiño Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + #include "randomgen.h" #include #include "util.h"