Compare commits

...

8 Commits

Author SHA1 Message Date
Vladislav Khorev
75cadf21cc Set light to uniforms 2024-06-10 22:48:52 +03:00
Vladislav Khorev
f346e55819 Now bump mapping works 2024-06-10 22:18:06 +03:00
Vladislav Khorev
d49d09a1e5 light working 2024-06-09 21:41:54 +03:00
Vladislav Khorev
d218d158f1 Working on models 2024-06-09 01:27:32 +03:00
Vladislav Khorev
737b30e8ec Working with sky boxes 2024-06-09 01:09:40 +03:00
Vladislav Khorev
79cfbeada3 Finally somehow correct cubemap 2024-06-08 23:24:03 +03:00
Vladislav Khorev
84ee2dc70c Finally cubemap is working 2024-06-08 20:56:35 +03:00
Vladislav Khorev
ef92c70ae8 A lot of changes 2024-06-05 21:19:20 +03:00
28 changed files with 12934 additions and 166 deletions

View File

@ -23,17 +23,20 @@
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_nosound|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_nosound|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -94,17 +94,20 @@
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_nosound|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_nosound|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet> <CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@ -135,8 +138,8 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG</PreprocessorDefinitions> <PreprocessorDefinitions>NOSOUND;TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..;C:\Boost\include\boost-1_84;..\..\lpng1510</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>

12146
gl/glext.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -59,7 +59,8 @@ protected:
cardinal TexID; cardinal TexID;
cardinal NormTexID; cardinal NormTexID;
TTriangleList TriangleList; //TTriangleList TriangleList;
VertexDataStruct vertexDataStruct;
mat3 ShaderRotateMatrix; mat3 ShaderRotateMatrix;
vec3 ShaderTranslateVector; vec3 ShaderTranslateVector;

View File

@ -75,6 +75,10 @@ extern PFNGLBUFFERSUBDATAPROC glBufferSubData;
extern PFNGLMAPBUFFERPROC glMapBuffer; extern PFNGLMAPBUFFERPROC glMapBuffer;
extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; extern PFNGLUNMAPBUFFERPROC glUnmapBuffer;
extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArray;
//========================================= //=========================================
//============ Frame buffer =============== //============ Frame buffer ===============
//========================================= //=========================================

View File

@ -20,6 +20,55 @@
namespace SE namespace SE
{ {
class VBOHolder {
GLuint Buffer;
public:
VBOHolder();
VBOHolder(const VBOHolder& v) = delete;
VBOHolder& operator=(const VBOHolder& v) = delete;
~VBOHolder();
GLuint getBuffer();
};
class VAOHolder {
GLuint vao;
public:
VAOHolder();
VAOHolder(const VAOHolder& v) = delete;
VAOHolder& operator=(const VAOHolder& v) = delete;
~VAOHolder();
GLuint getBuffer();
};
struct VertexDataStruct
{
std::vector<vec3> PositionData;
std::vector<vec2> TexCoordData;
std::vector<vec3> NormalData;
std::vector<vec3> TangentData;
std::vector<vec3> BitangentData;
std::shared_ptr<VAOHolder> vao;
std::shared_ptr<VBOHolder> positionVBO;
std::shared_ptr<VBOHolder> texCoordVBO;
std::shared_ptr<VBOHolder> normalVBO;
std::shared_ptr<VBOHolder> tangentVBO;
std::shared_ptr<VBOHolder> bitangentVBO;
void RefreshVBO();
void CalcTangentBitangent();
};
struct T2DQuad struct T2DQuad
{ {
vec3 VertexCoord[4]; vec3 VertexCoord[4];
@ -58,6 +107,7 @@ public:
}; };
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32
class VBOObject //Must stay in shared ptr only! class VBOObject //Must stay in shared ptr only!
@ -75,6 +125,7 @@ public:
}; };
void DrawVertexDataStruct(const VertexDataStruct& vertexDataStruct);
class TTriangleList : public TTriangleListAncestor //Implementation differs for Windows and Android class TTriangleList : public TTriangleListAncestor //Implementation differs for Windows and Android
{ {

View File

@ -30,6 +30,15 @@ protected:
float GlobalShadowAreaHalfSize; float GlobalShadowAreaHalfSize;
cardinal BkgTexID;
std::string BkgShaderName;
float FogBeginDistance;
float FogEndDistance;
vec4 FogColor;
vec3 lightPos;
void CalcCamPosVec(); void CalcCamPosVec();
virtual void DrawQuad(const T2DQuad& quad) = 0; virtual void DrawQuad(const T2DQuad& quad) = 0;
@ -49,14 +58,15 @@ public:
void SetPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar); void SetPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar);
void PushPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar); void PushPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar);
void SetGLCamAngleView();
void SetGLCamView(); void SetGLCamView();
void SetGlIdentityView(); void SetGlIdentityView();
void SetGlPosXView(); void SetGlPosXView(bool translate = true, bool renderToFrame = false);
void SetGlNegXView(); void SetGlNegXView(bool translate = true, bool renderToFrame = false);
void SetGlPosYView(); void SetGlPosYView(bool translate = true, bool renderToFrame = false);
void SetGlNegYView(); void SetGlNegYView(bool translate = true, bool renderToFrame = false);
void SetGlPosZView(); void SetGlPosZView(bool translate = true, bool renderToFrame = false);
void SetGlNegZView(); void SetGlNegZView(bool translate = true, bool renderToFrame = false);
void MoveAlpha(float dAlpha); void MoveAlpha(float dAlpha);
@ -79,6 +89,21 @@ public:
void BeginDrawToDepthBufferLocal(std::string& localBufferName); void BeginDrawToDepthBufferLocal(std::string& localBufferName);
void EndDrawToDepthBuffer(); void EndDrawToDepthBuffer();
void SetBackgroundCubemap(cardinal bkgTex) { BkgTexID = bkgTex; }
void SetBackgroundShader(const std::string& shaderName) { BkgShaderName = shaderName; }
void DrawBackground();
float GetFogBeginDistance();
float GetFogEndDistance();
vec4 GetFogColor();
void SetFogBeginDistance(float distance);
void SetFogEndDistance(float distance);
void SetLightPos(vec3 newLightPos);
}; };
} //namespace SE } //namespace SE

View File

@ -22,11 +22,6 @@ protected:
bool IsCameraTransparentToLand; //To make it work you must setup LandToCalcCollision bool IsCameraTransparentToLand; //To make it work you must setup LandToCalcCollision
TSimpleLandClass* LandToCalcCollision; TSimpleLandClass* LandToCalcCollision;
float FogBeginDistance;
float FogEndDistance;
vec4 FogColor;
//Other data: //Other data:
float ShadowClampValue; float ShadowClampValue;
@ -45,9 +40,6 @@ public:
float GetShadowClampValue(); float GetShadowClampValue();
void SetShadowClampValue(float shadowClampValue); void SetShadowClampValue(float shadowClampValue);
float GetFogBeginDistance();
float GetFogEndDistance();
vec4 GetFogColor();
void DrawTriangleList(const TTriangleList& triangleList); void DrawTriangleList(const TTriangleList& triangleList);

View File

@ -1,7 +1,7 @@
#ifndef SCRIPT_MANAGER_H_INCLUDED #ifndef SCRIPT_MANAGER_H_INCLUDED
#define SCRIPT_MANAGER_H_INCLUDED #define SCRIPT_MANAGER_H_INCLUDED
#include "sqplus.h" //#include "sqplus.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -44,22 +44,23 @@ public:
}; };
class TScriptManager : public TSerializeInterface class TScriptManager : public TSerializeInterface
{ {
protected: protected:
HSQUIRRELVM virtualMachine; //HSQUIRRELVM virtualMachine;
std::map<std::string, TScriptInfo> FuncInfoMap; std::map<std::string, TScriptInfo> FuncInfoMap;
template<typename T1,typename T2> template<typename T1,typename T2>
void RegisterFunc(T1& object, T2 method, const std::string& funcName) void RegisterFunc(T1& object, T2 method, const std::string& funcName)
{ {
SqPlus::RegisterGlobal(virtualMachine, object, method, _SC(funcName.c_str())); //SqPlus::RegisterGlobal(virtualMachine, object, method, _SC(funcName.c_str()));
} }
template<typename T> template<typename T>
void RegisterFunc(T globalFunc, const std::string& funcName) void RegisterFunc(T globalFunc, const std::string& funcName)
{ {
SqPlus::RegisterGlobal(virtualMachine, globalFunc, _SC(funcName.c_str())); //SqPlus::RegisterGlobal(virtualMachine, globalFunc, _SC(funcName.c_str()));
} }
public: public:
@ -103,9 +104,9 @@ public:
void SQ_Print(const SQChar *inString); //void SQ_Print(const SQChar *inString);
void SQ_PrintWidgetList(); //void SQ_PrintWidgetList();
void SQ_MoveWidget(const SQChar *widgetName, float x, float y); //void SQ_MoveWidget(const SQChar *widgetName, float x, float y);
//void SQ_PrintTextureList(); //void SQ_PrintTextureList();
//void SQ_PrintAnimationList(); //void SQ_PrintAnimationList();

View File

@ -56,6 +56,7 @@ private:
cardinal NormTexID; cardinal NormTexID;
//For VBO: //For VBO:
/*
std::vector<word> IndexArr; std::vector<word> IndexArr;
TVBOLandVertex VBOLandVertexArr; TVBOLandVertex VBOLandVertexArr;
@ -64,7 +65,8 @@ private:
cardinal NormBuffer; cardinal NormBuffer;
cardinal TangentBuffer; cardinal TangentBuffer;
cardinal BinormBuffer; cardinal BinormBuffer;
cardinal TexcoordBuffer; cardinal TexcoordBuffer;*/
VertexDataStruct vertexDataStruct;
void CreateVBO(); void CreateVBO();
void FreeVBO(); void FreeVBO();

View File

@ -41,7 +41,7 @@ public:
} }
template<typename TYPENAME> template<typename TYPENAME>
boost::signal<void(const TYPENAME&)>& GetSignal(const std::string& dictName, const std::string& valueName) boost::signals2::signal<void(const TYPENAME&)>& GetSignal(const std::string& dictName, const std::string& valueName)
{ {
return boost::get<std::shared_ptr<TBindableVar<TYPENAME>>>(GetSmartValue(dictName, valueName))->OnVarChanged; return boost::get<std::shared_ptr<TBindableVar<TYPENAME>>>(GetSmartValue(dictName, valueName))->OnVarChanged;
} }

View File

@ -87,7 +87,7 @@ public:
cardinal AddTexture(const std::string& fileName, std::string texName = ""); //Adds path to resources to the filename then call previous one cardinal AddTexture(const std::string& fileName, std::string texName = ""); //Adds path to resources to the filename then call previous one
cardinal AddTextureFromUserdata(const std::string& fileName, std::string texName = ""); //Same as above but checks if file is created in user data cardinal AddTextureFromUserdata(const std::string& fileName, std::string texName = ""); //Same as above but checks if file is created in user data
cardinal AddCubemapTexture(std::string filename[6]); // "posx.bmp","negx.bmp","posy.bmp","negy.bmp","posz.bmp","negz.bmp" cardinal AddCubemapTexture(std::array<std::string, 6> filename); // "posx.bmp","negx.bmp","posy.bmp","negy.bmp","posz.bmp","negz.bmp"
cardinal AddEmptyTexture(const std::string& texName, cardinal width, cardinal height); cardinal AddEmptyTexture(const std::string& texName, cardinal width, cardinal height);

View File

@ -1,7 +1,7 @@
#ifndef BINDABLE_VAR_H_INCLUDED #ifndef BINDABLE_VAR_H_INCLUDED
#define BINDABLE_VAR_H_INCLUDED #define BINDABLE_VAR_H_INCLUDED
#include "boost/signal.hpp" #include "boost/signals2.hpp"
#include "boost/variant.hpp" #include "boost/variant.hpp"
namespace SE namespace SE
@ -17,7 +17,7 @@ protected:
public: public:
boost::signal<void(const TYPENAME&)> OnVarChanged; boost::signals2::signal<void(const TYPENAME&)> OnVarChanged;
TBindableVar() TBindableVar()
{ {

View File

@ -70,7 +70,7 @@ public:
tvec3<TYPENAME1>& operator-=(const tvec3<TYPENAME1>& vc); tvec3<TYPENAME1>& operator-=(const tvec3<TYPENAME1>& vc);
tvec3<TYPENAME1> operator+(const tvec3<TYPENAME1>& a) const; tvec3<TYPENAME1> operator+(const tvec3<TYPENAME1>& a) const;
tvec3<TYPENAME1> operator-(const tvec3<TYPENAME1>& a) const; tvec3<TYPENAME1> operator-(const tvec3<TYPENAME1>& a) const;
tvec3<TYPENAME1>& operator-(); tvec3<TYPENAME1> operator-();
tvec3<TYPENAME1>& operator*=(TYPENAME1 c); tvec3<TYPENAME1>& operator*=(TYPENAME1 c);
tvec3<TYPENAME1> operator*(const tmat3<TYPENAME1>& mt) const; //MultRowMatrix() tvec3<TYPENAME1> operator*(const tmat3<TYPENAME1>& mt) const; //MultRowMatrix()
}; };
@ -440,13 +440,14 @@ inline tvec3<TYPENAME1> tvec3<TYPENAME1>::operator-(const tvec3<TYPENAME1>& a) c
} }
template<typename TYPENAME1> template<typename TYPENAME1>
inline tvec3<TYPENAME1>& tvec3<TYPENAME1>::operator-() tvec3<TYPENAME1> tvec3<TYPENAME1>::operator-()
{ {
v[0] = -v[0]; tvec3<TYPENAME1> result;
v[1] = -v[1]; result.v[0] = -v[0];
v[2] = -v[2]; result.v[1] = -v[1];
result.v[2] = -v[2];
return *this; return result;
} }
template<typename TYPENAME1> template<typename TYPENAME1>

View File

@ -14,7 +14,7 @@ This code combines additional routines (such as console/log, exceptions, math ut
#include "boost/asio.hpp" #include "boost/asio.hpp"
#include "boost/date_time/posix_time/posix_time.hpp" #include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/signal.hpp" #include "boost/signals2.hpp"
#include "include/Utils/Console/Console.h" #include "include/Utils/Console/Console.h"

View File

@ -554,7 +554,7 @@ void TAnimModel::RecalcVertexPos()
} }
//LiteModel.VertexArr[i] = px; //LiteModel.VertexArr[i] = px;
LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] = px; //LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] = px;
/* /*
//Normal //Normal
@ -578,14 +578,14 @@ void TAnimModel::RecalcVertexPos()
void TAnimModel::SaveVertexInfoToBuf() void TAnimModel::SaveVertexInfoToBuf()
{ {
CopyVertexArr = LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB]; //CopyVertexArr = LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB];
AnimList->SaveBoneSystemToBuf(); AnimList->SaveBoneSystemToBuf();
} }
void TAnimModel::LoadVertexInfoFromBuf() void TAnimModel::LoadVertexInfoFromBuf()
{ {
LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB] = CopyVertexArr; //LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB] = CopyVertexArr;
AnimList->LoadBoneSystemFromBuf(); AnimList->LoadBoneSystemFromBuf();
} }
@ -597,8 +597,8 @@ bool TAnimModel::LoadModel(const std::string& modelName)
return false; return false;
CopyVertexArr.resize(LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].size()); //CopyVertexArr.resize(LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].size());
CopyVertexArr = LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB]; //CopyVertexArr = LiteModel.TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB];
AnimList = ResourceManager->ModelAnimManager[modelName]; AnimList = ResourceManager->ModelAnimManager[modelName];

View File

@ -32,8 +32,10 @@ bool TLiteModelResource::LoadModel(boost::shared_array<byte> filePointer, cardin
int normtexnamelen = *reinterpret_cast<word*>(&filePointer[78]+texnamelen); int normtexnamelen = *reinterpret_cast<word*>(&filePointer[78]+texnamelen);
Normtexname = std::string(reinterpret_cast<char*>(&filePointer[80]+texnamelen), reinterpret_cast<char*>(&filePointer[80]+texnamelen) + normtexnamelen); Normtexname = std::string(reinterpret_cast<char*>(&filePointer[80]+texnamelen), reinterpret_cast<char*>(&filePointer[80]+texnamelen) + normtexnamelen);
if (Texname != "")
ResourceManager->TexList.AddTextureDirectly((PathToResource + std::string(Texname))); {
ResourceManager->TexList.AddTextureDirectly((PathToResource + std::string(Texname)));
}
if (Normtexname != "") if (Normtexname != "")
{ {
ResourceManager->TexList.AddTextureDirectly((PathToResource + std::string(Normtexname))); ResourceManager->TexList.AddTextureDirectly((PathToResource + std::string(Normtexname)));
@ -115,13 +117,20 @@ bool TLiteModel::LoadModel(const std::string& s)
else else
NormTexID = 0; NormTexID = 0;
vertexDataStruct.PositionData = res.VertexArr;
vertexDataStruct.TexCoordData = res.TexCoordArr;
vertexDataStruct.NormalData = res.NormalArr;
vertexDataStruct.CalcTangentBitangent();
vertexDataStruct.RefreshVBO();
/*
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB] = res.VertexArr; TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB] = res.VertexArr;
TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB] = res.NormalArr; TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB] = res.NormalArr;
TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB] = res.TangentArr; TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB] = res.TangentArr;
TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB] = res.BinormalArr; TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB] = res.BinormalArr;
TriangleList.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB] = res.TexCoordArr; TriangleList.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB] = res.TexCoordArr;
*/
Loaded = true; Loaded = true;
return true; return true;
@ -131,10 +140,10 @@ void TLiteModel::FreeModel()
{ {
Loaded = false; Loaded = false;
TriangleList.Data.Vec3CoordArr.clear(); //TriangleList.Data.Vec3CoordArr.clear();
TriangleList.Data.Vec2CoordArr.clear(); //TriangleList.Data.Vec2CoordArr.clear();
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32
TriangleList.VertBufferArr.clear(); //TriangleList.VertBufferArr.clear();
#endif #endif
TriangleCount = 0; TriangleCount = 0;
TexID = 0; TexID = 0;
@ -149,7 +158,8 @@ void TLiteModel::UpdateVBO()
CheckGlError(); CheckGlError();
TriangleList.RefreshBuffer(); //TriangleList.RefreshBuffer();
vertexDataStruct.RefreshVBO();
CheckGlError(); CheckGlError();
@ -157,7 +167,7 @@ void TLiteModel::UpdateVBO()
void TLiteModel::DrawImmediate() void TLiteModel::DrawImmediate()
{ {
/*
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32
if (Loaded) if (Loaded)
@ -209,7 +219,7 @@ void TLiteModel::DrawImmediate()
RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 1); RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 1);
} }
#endif #endif*/
} }
void TLiteModel::DrawVBO() void TLiteModel::DrawVBO()
@ -228,7 +238,22 @@ void TLiteModel::DrawVBO()
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,TexID); glBindTexture(GL_TEXTURE_2D,TexID);
Renderer->DrawTriangleList(TriangleList); EnableVertexAttribArray("vPosition");
EnableVertexAttribArray("vTexCoord");
EnableVertexAttribArray("vNormal");
EnableVertexAttribArray("vTangent");
EnableVertexAttribArray("vBitangent");
//Renderer->DrawTriangleList(TriangleList);
DrawVertexDataStruct(vertexDataStruct);
DisableVertexAttribArray("vBitangent");
DisableVertexAttribArray("vTangent");
DisableVertexAttribArray("vNormal");
DisableVertexAttribArray("vTexCoord");
DisableVertexAttribArray("vPosition");
RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 1); RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 1);
@ -236,13 +261,12 @@ void TLiteModel::DrawVBO()
} }
void TLiteModel::MoveModel(const vec3& v) void TLiteModel::MoveModel(const vec3& v)
{ {
for (cardinal i = 0; i < TriangleCount * 3; i++) for (cardinal i = 0; i < TriangleCount * 3; i++)
{ {
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] += v; vertexDataStruct.PositionData[i] += v;
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] += v;
} }
} }
@ -251,10 +275,14 @@ void TLiteModel::RotateModel(const mat3& r)
for (cardinal i = 0; i < TriangleCount * 3; i++) for (cardinal i = 0; i < TriangleCount * 3; i++)
{ {
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i]; vertexDataStruct.PositionData[i] = r * vertexDataStruct.PositionData[i];
TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i]; vertexDataStruct.NormalData[i] = r * vertexDataStruct.NormalData[i];
TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i]; vertexDataStruct.TangentData[i] = r * vertexDataStruct.TangentData[i];
TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB][i]; vertexDataStruct.BitangentData[i] = r * vertexDataStruct.BitangentData[i];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB][i];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_TANGENT_ATTRIB][i];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB][i] = r * TriangleList.Data.Vec3CoordArr[CONST_STRING_BINORMAL_ATTRIB][i];
} }
} }
@ -263,7 +291,8 @@ void TLiteModel::ScaleModel(float s)
for (cardinal i = 0; i < TriangleCount * 3; i++) for (cardinal i = 0; i < TriangleCount * 3; i++)
{ {
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] *= s; vertexDataStruct.PositionData[i] *= s;
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i] *= s;
} }
} }
@ -274,9 +303,12 @@ void TLiteModel::ScaleModel(const vec3& s)
for (cardinal i = 0; i < TriangleCount * 3; i++) for (cardinal i = 0; i < TriangleCount * 3; i++)
{ {
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[0] *= s.v[0]; vertexDataStruct.PositionData[i].v[0] *= s.v[0];
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[1] *= s.v[1]; vertexDataStruct.PositionData[i].v[1] *= s.v[1];
TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[2] *= s.v[2]; vertexDataStruct.PositionData[i].v[2] *= s.v[2];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[0] *= s.v[0];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[1] *= s.v[1];
//TriangleList.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][i].v[2] *= s.v[2];
} }
} }

View File

@ -66,6 +66,10 @@ PFNGLBUFFERSUBDATAPROC glBufferSubData = NULL;
PFNGLMAPBUFFERPROC glMapBuffer = NULL; PFNGLMAPBUFFERPROC glMapBuffer = NULL;
PFNGLUNMAPBUFFERPROC glUnmapBuffer = NULL; PFNGLUNMAPBUFFERPROC glUnmapBuffer = NULL;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = NULL;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray = NULL;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArray = NULL;
//========================================= //=========================================
//============ Frame buffer =============== //============ Frame buffer ===============
//========================================= //=========================================

View File

@ -2,6 +2,186 @@
namespace SE namespace SE
{ {
VBOHolder::VBOHolder()
{
glGenBuffers(1, &Buffer);
}
VBOHolder::~VBOHolder()
{
glDeleteBuffers(1, &Buffer);
}
GLuint VBOHolder::getBuffer()
{
return Buffer;
}
VAOHolder::VAOHolder()
{
#ifndef EMSCRIPTEN
glGenVertexArrays(1, &vao);
#endif
}
VAOHolder::~VAOHolder()
{
#ifndef EMSCRIPTEN
glDeleteVertexArray(1, &vao);
#endif
}
GLuint VAOHolder::getBuffer()
{
return vao;
}
void VertexDataStruct::RefreshVBO()
{
//Check if main thread, check if data is not empty...
#ifndef EMSCRIPTEN
if (!vao)
{
vao = std::make_shared<VAOHolder>();
}
glBindVertexArray(vao->getBuffer());
#endif
if (!positionVBO)
{
positionVBO = std::make_shared<VBOHolder>();
}
glBindBuffer(GL_ARRAY_BUFFER, positionVBO->getBuffer());
glBufferData(GL_ARRAY_BUFFER, PositionData.size() * 12, &PositionData[0], GL_STATIC_DRAW);
if (!texCoordVBO)
{
texCoordVBO = std::make_shared<VBOHolder>();
}
glBindBuffer(GL_ARRAY_BUFFER, texCoordVBO->getBuffer());
glBufferData(GL_ARRAY_BUFFER, TexCoordData.size() * 8, &TexCoordData[0], GL_STATIC_DRAW);
if (NormalData.size() > 0)
{
if (!normalVBO)
{
normalVBO = std::make_shared<VBOHolder>();
}
glBindBuffer(GL_ARRAY_BUFFER, normalVBO->getBuffer());
glBufferData(GL_ARRAY_BUFFER, NormalData.size() * 12, &NormalData[0], GL_STATIC_DRAW);
}
if (TangentData.size() > 0)
{
if (!tangentVBO)
{
tangentVBO = std::make_shared<VBOHolder>();
}
glBindBuffer(GL_ARRAY_BUFFER, tangentVBO->getBuffer());
glBufferData(GL_ARRAY_BUFFER, TangentData.size() * 12, &TangentData[0], GL_STATIC_DRAW);
}
if (BitangentData.size() > 0)
{
if (!bitangentVBO)
{
bitangentVBO = std::make_shared<VBOHolder>();
}
glBindBuffer(GL_ARRAY_BUFFER, bitangentVBO->getBuffer());
glBufferData(GL_ARRAY_BUFFER, BitangentData.size() * 12, &BitangentData[0], GL_STATIC_DRAW);
}
}
void VertexDataStruct::CalcTangentBitangent()
{
TangentData.clear();
BitangentData.clear();
for (int i = 0; i < PositionData.size() / 3; i++)
{
vec3 v0 = PositionData[i * 3];
vec3 v1 = PositionData[i * 3 + 1];
vec3 v2 = PositionData[i * 3 + 2];
vec2 t0 = TexCoordData[i * 3];
vec2 t1 = TexCoordData[i * 3 + 1];
vec2 t2 = TexCoordData[i * 3 + 2];
vec3 deltaPos1 = v1 - v0;
vec3 deltaPos2 = v2 - v0;
vec2 deltaUV1 = t1 - t0;
vec2 deltaUV2 = t2 - t0;
float r = 1.0f / (deltaUV1.v[0] * deltaUV2.v[1] - deltaUV1.v[1] * deltaUV2.v[0]);
vec3 tangent = (deltaPos1 * deltaUV2.v[1] - deltaPos2 * deltaUV1.v[1]) * r;
vec3 bitangent = (deltaPos2 * deltaUV1.v[0] - deltaPos1 * deltaUV2.v[0]) * r;
TangentData.push_back(tangent);
TangentData.push_back(tangent);
TangentData.push_back(tangent);
BitangentData.push_back(bitangent);
BitangentData.push_back(bitangent);
BitangentData.push_back(bitangent);
}
RefreshVBO();
}
void DrawVertexDataStruct(const VertexDataStruct& vertexDataStruct)
{
static const std::string vTexCoord("vTexCoord");
static const std::string vPosition("vPosition");
static const std::string vNormal("vNormal");
static const std::string vTangent("vTangent");
static const std::string vBitangent("vBitangent");
//Check if main thread, check if data is not empty...
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.texCoordVBO->getBuffer());
VertexAttribPointer2fv(vTexCoord, 0, NULL);
if (vertexDataStruct.normalVBO)
{
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.normalVBO->getBuffer());
VertexAttribPointer3fv(vNormal, 0, NULL);
}
if (vertexDataStruct.tangentVBO)
{
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.tangentVBO->getBuffer());
VertexAttribPointer3fv(vTangent, 0, NULL);
}
if (vertexDataStruct.bitangentVBO)
{
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.bitangentVBO->getBuffer());
VertexAttribPointer3fv(vBitangent, 0, NULL);
}
glBindBuffer(GL_ARRAY_BUFFER, vertexDataStruct.positionVBO->getBuffer());
VertexAttribPointer3fv(vPosition, 0, NULL);
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vertexDataStruct.PositionData.size()));
}
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32

View File

@ -5,6 +5,7 @@
namespace SE namespace SE
{ {
const float speed_coef = 0.1;
TSalmonRendererInterface::TSalmonRendererInterface() TSalmonRendererInterface::TSalmonRendererInterface()
@ -13,6 +14,9 @@ TSalmonRendererInterface::TSalmonRendererInterface()
, CamDist(0.0f) , CamDist(0.0f)
, CamShift(ZeroVec3) , CamShift(ZeroVec3)
, GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE) , GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE)
, FogBeginDistance(CONST_DEFAULT_FOG_BEGIN_DISTANCE)
, FogEndDistance(CONST_DEFAULT_FOG_END_DISTANCE)
, FogColor(CONST_DEFAULT_FOG_COLOR)
{ {
ProjectionMatrixStack.push(IdentityMatrix4); ProjectionMatrixStack.push(IdentityMatrix4);
@ -54,12 +58,14 @@ void TSalmonRendererInterface::SetUniforms()
//RenderUniform1f(CONST_STRING_SHADOWCLAMPVALUE_UNIFORM, GetShadowClampValue()); //RenderUniform1f(CONST_STRING_SHADOWCLAMPVALUE_UNIFORM, GetShadowClampValue());
//RenderUniform1i(CONST_STRING_ACTIVELIGHTCOUNT_UNIFORM, ResourceManager->LightManager.GetActiveLightCount()); //RenderUniform1i(CONST_STRING_ACTIVELIGHTCOUNT_UNIFORM, ResourceManager->LightManager.GetActiveLightCount());
//RenderUniform1f(CONST_STRING_FOG_BEGIN_DISTANCE_UNIFORM, GetFogBeginDistance()); RenderUniform1f(CONST_STRING_FOG_BEGIN_DISTANCE_UNIFORM, GetFogBeginDistance());
//RenderUniform1f(CONST_STRING_FOG_END_DISTANCE_UNIFORM, GetFogEndDistance()); RenderUniform1f(CONST_STRING_FOG_END_DISTANCE_UNIFORM, GetFogEndDistance());
//RenderUniform4fv(CONST_STRING_FOG_COLOR_UNIFORM, GetFogColor().v); //RenderUniform4fv(CONST_STRING_FOG_COLOR_UNIFORM, GetFogColor().v);
RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM, GetCamPos().v); RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM, GetCamPos().v);
RenderUniform3fv("lightPos", lightPos.v);
ResourceManager->LightManager.SetLightUniforms(); ResourceManager->LightManager.SetLightUniforms();
} }
@ -171,7 +177,36 @@ void TSalmonRendererInterface::PushPerspectiveProjectionMatrix(float angle, floa
void TSalmonRendererInterface::SetGLCamAngleView()
{
/*
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -CamDist);
glRotatef(CamPhi*180.0f/pi, 1.0f, 0.0f, 0.0f);
glRotatef(CamAlpha*180.0f/pi, 0.0f, 1.0f, 0.0f);
//TODO
glTranslatef(-CamShift.v[0], -CamShift.v[1], -CamShift.v[2]);
glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m);
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,CamPos.v);*/
LoadIdentity();
TranslateMatrix(vec3(0.0f, 0.0f, -CamDist));
RotateMatrix(vec4(1.f * sin(CamPhi / 2.f), 0.f, 0.f, 1.f * cos(CamPhi / 2.f)));
RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha / 2.f), 0.f, 1.f * cos(CamAlpha / 2.f)));
TranslateMatrix(-CamVec);
CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
SetUniforms();
}
void TSalmonRendererInterface::SetGLCamView() void TSalmonRendererInterface::SetGLCamView()
{ {
@ -189,7 +224,6 @@ void TSalmonRendererInterface::SetGLCamView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,CamPos.v);*/ RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,CamPos.v);*/
LoadIdentity(); LoadIdentity();
TranslateMatrix(vec3(0.0f, 0.0f, -CamDist)); TranslateMatrix(vec3(0.0f, 0.0f, -CamDist));
RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f))); RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f)));
@ -221,7 +255,7 @@ void TSalmonRendererInterface::SetGlIdentityView()
SetUniforms(); SetUniforms();
} }
void TSalmonRendererInterface::SetGlPosXView() void TSalmonRendererInterface::SetGlPosXView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -234,11 +268,19 @@ void TSalmonRendererInterface::SetGlPosXView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/
LoadIdentity(); LoadIdentity();
if (renderToFrame)
RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); {
RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); }
else
{
RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
}
if (translate)
{
TranslateMatrix(-CamPos);
}
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -247,7 +289,7 @@ void TSalmonRendererInterface::SetGlPosXView()
} }
void TSalmonRendererInterface::SetGlNegXView() void TSalmonRendererInterface::SetGlNegXView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -260,11 +302,19 @@ void TSalmonRendererInterface::SetGlNegXView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/
LoadIdentity(); LoadIdentity();
if (renderToFrame)
RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); {
RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); }
else
{
RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
}
if (translate)
{
TranslateMatrix(-CamPos);
}
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -272,7 +322,7 @@ void TSalmonRendererInterface::SetGlNegXView()
SetUniforms(); SetUniforms();
} }
void TSalmonRendererInterface::SetGlPosYView() void TSalmonRendererInterface::SetGlPosYView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -283,10 +333,13 @@ void TSalmonRendererInterface::SetGlPosYView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/
LoadIdentity();
RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f)));
TranslateMatrix(-CamShift); LoadIdentity();
RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.0f, 0.f, 1.f * cos(pi / 4.f)));
if (translate)
{
TranslateMatrix(-CamPos);
}
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -295,7 +348,7 @@ void TSalmonRendererInterface::SetGlPosYView()
} }
void TSalmonRendererInterface::SetGlNegYView() void TSalmonRendererInterface::SetGlNegYView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -307,9 +360,11 @@ void TSalmonRendererInterface::SetGlNegYView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/
LoadIdentity(); LoadIdentity();
RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.0f, 0.f, 1.f * cos(pi / 4.f)));
if (translate)
TranslateMatrix(-CamShift); {
TranslateMatrix(-CamPos);
}
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -317,7 +372,7 @@ void TSalmonRendererInterface::SetGlNegYView()
SetUniforms(); SetUniforms();
} }
void TSalmonRendererInterface::SetGlPosZView() void TSalmonRendererInterface::SetGlPosZView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -330,12 +385,24 @@ void TSalmonRendererInterface::SetGlPosZView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
*/ */
LoadIdentity(); LoadIdentity();
RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f)));
if (renderToFrame)
{
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
}
if (translate)
{
TranslateMatrix(-CamPos);
}
/*LoadIdentity();
RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f)));
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-CamShift);*/
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -343,7 +410,7 @@ void TSalmonRendererInterface::SetGlPosZView()
SetUniforms(); SetUniforms();
} }
void TSalmonRendererInterface::SetGlNegZView() void TSalmonRendererInterface::SetGlNegZView(bool translate, bool renderToFrame)
{ {
/* /*
glLoadIdentity(); glLoadIdentity();
@ -355,10 +422,16 @@ void TSalmonRendererInterface::SetGlNegZView()
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/
LoadIdentity(); LoadIdentity();
//RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f)));
if (renderToFrame)
{
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
}
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); if (translate)
{
TranslateMatrix(-CamShift); TranslateMatrix(-CamPos);
}
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -554,9 +627,9 @@ void TSalmonRendererInterface::MoveForward()
float sina = sinf(CamAlpha); float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha); float cosa = cosf(CamAlpha);
mov.v[0] = sina; mov.v[0] = speed_coef * sina;
mov.v[1] = 0; mov.v[1] = 0;
mov.v[2] = - cosa; mov.v[2] = -speed_coef * cosa;
CamShift = CamShift + mov; CamShift = CamShift + mov;
@ -601,9 +674,9 @@ void TSalmonRendererInterface::MoveBackward()
float sina = sinf(CamAlpha); float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha); float cosa = cosf(CamAlpha);
mov.v[0] = - sina; mov.v[0] = -speed_coef*sina;
mov.v[1] = 0; mov.v[1] = 0;
mov.v[2] = cosa; mov.v[2] = speed_coef * cosa;
CamShift = CamShift + mov; CamShift = CamShift + mov;
//Possibly refactor??? //Possibly refactor???
@ -647,9 +720,9 @@ void TSalmonRendererInterface::MoveLeft()
float sina = sinf(CamAlpha); float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha); float cosa = cosf(CamAlpha);
mov.v[0] = - cosa; mov.v[0] = -speed_coef * cosa;
mov.v[1] = 0; mov.v[1] = 0;
mov.v[2] = - sina; mov.v[2] = -speed_coef * sina;
CamShift = CamShift + mov; CamShift = CamShift + mov;
@ -691,8 +764,8 @@ void TSalmonRendererInterface::MoveRight()
{ {
vec3 mov; vec3 mov;
float sina = sinf(CamAlpha); float sina = speed_coef * sinf(CamAlpha);
float cosa = cosf(CamAlpha); float cosa = speed_coef * cosf(CamAlpha);
mov.v[0] = cosa; mov.v[0] = cosa;
mov.v[1] = 0; mov.v[1] = 0;
@ -770,6 +843,9 @@ void TSalmonRendererInterface::SwitchToCubemapBuffer(const std::string& frameNam
glBindFramebuffer(GL_FRAMEBUFFER, Frame.FrameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, Frame.FrameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + cubeSide, Frame.TexID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + cubeSide, Frame.TexID, 0);
//PopProjectionMatrix();
//PushPerspectiveProjectionMatrix(pi / 2, 1.0, 1, 1000);
//glViewport(0, 0, Frame.Width, Frame.Height);
/* /*
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -777,7 +853,7 @@ void TSalmonRendererInterface::SwitchToCubemapBuffer(const std::string& frameNam
glViewport(0, 0, Frame.Width, Frame.Height); glViewport(0, 0, Frame.Width, Frame.Height);
glMatrixMode(GL_MODELVIEW);*/ glMatrixMode(GL_MODELVIEW);*/
SetPerspectiveProjectionMatrix(90, 1, 1, 100); SetPerspectiveProjectionMatrix(pi / 2, 1, 1, 100);
SetFrameViewport(frameName); SetFrameViewport(frameName);
@ -805,6 +881,108 @@ void TSalmonRendererInterface::EndDrawToDepthBuffer()
SetPerspectiveFullScreenViewport(); SetPerspectiveFullScreenViewport();
} }
void TSalmonRendererInterface::DrawBackground()
{
if (BkgTexID != 0)
{
//ResourceManager->ShaderManager.PushShader(BkgShaderName);
this->PushShader(BkgShaderName);
//if (BkgShaderName != "")
// ResourceManager->ShaderManager.SetCurrentShader(BkgShaderName);
glPushMatrix();
glLoadIdentity();
glRotatef(CamPhi * 180.0f / pi, 1.0f, 0.0f, 0.0f);
glRotatef(CamAlpha * 180.0f / pi, 0.0f, 1.0f, 0.0f);
glBindTexture(GL_TEXTURE_CUBE_MAP, BkgTexID);
//x
glBegin(GL_QUADS);
glVertex3f(-10.0f, -10.0f, -10.0f);
glVertex3f(-10.0f, 10.0f, -10.0f);
glVertex3f(-10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, -10.0f, 10.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(10.0f, -10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, 10.0f);
glVertex3f(10.0f, -10.0f, 10.0f);
glEnd();
//y
glBegin(GL_QUADS);
glVertex3f(-10.0f, 10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, 10.0f, 10.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(-10.0f, -10.0f, -10.0f);
glVertex3f(10.0f, -10.0f, -10.0f);
glVertex3f(10.0f, -10.0f, 10.0f);
glVertex3f(-10.0f, -10.0f, 10.0f);
glEnd();
//z
glBegin(GL_QUADS);
glVertex3f(10.0f, -10.0f, 10.0f);
glVertex3f(10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, -10.0f, 10.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(10.0f, -10.0f, -10.0f);
glVertex3f(10.0f, 10.0f, -10.0f);
glVertex3f(-10.0f, 10.0f, -10.0f);
glVertex3f(-10.0f, -10.0f, -10.0f);
glEnd();
glClear(GL_DEPTH_BUFFER_BIT);
glPopMatrix();
PopShader();
}
}
vec4 TSalmonRendererInterface::GetFogColor()
{
return FogColor;
}
float TSalmonRendererInterface::GetFogBeginDistance()
{
return FogBeginDistance;
}
float TSalmonRendererInterface::GetFogEndDistance()
{
return FogEndDistance;
}
void TSalmonRendererInterface::SetFogBeginDistance(float distance)
{
FogBeginDistance = distance;
}
void TSalmonRendererInterface::SetFogEndDistance(float distance)
{
FogEndDistance = distance;
}
void TSalmonRendererInterface::SetLightPos(vec3 newLightPos)
{
lightPos = newLightPos;
}
} //namespace SE } //namespace SE

View File

@ -13,9 +13,6 @@ namespace SE
TSalmonRenderer::TSalmonRenderer() : TSalmonRenderer::TSalmonRenderer() :
ShadowClampValue(0.0f), ShadowClampValue(0.0f),
FogBeginDistance(CONST_DEFAULT_FOG_BEGIN_DISTANCE),
FogEndDistance(CONST_DEFAULT_FOG_END_DISTANCE),
FogColor(CONST_DEFAULT_FOG_COLOR),
LandToCalcCollision(NULL), LandToCalcCollision(NULL),
IsCameraTransparentToLand(true) IsCameraTransparentToLand(true)
{ {
@ -51,6 +48,10 @@ bool TSalmonRenderer::BindOpenGLFunctions()
glMapBuffer = (PFNGLMAPBUFFERPROC) wglGetProcAddress("glMapBuffer"); glMapBuffer = (PFNGLMAPBUFFERPROC) wglGetProcAddress("glMapBuffer");
glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) wglGetProcAddress("glUnmapBuffer"); glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) wglGetProcAddress("glUnmapBuffer");
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray");
glDeleteVertexArray = (PFNGLDELETEVERTEXARRAYSPROC)wglGetProcAddress("glDeleteVertexArray");
glCreateProgram = (PFNGLCREATEPROGRAMPROC) wglGetProcAddress("glCreateProgram"); glCreateProgram = (PFNGLCREATEPROGRAMPROC) wglGetProcAddress("glCreateProgram");
glDeleteProgram = (PFNGLDELETEPROGRAMPROC) wglGetProcAddress("glDeleteProgram"); glDeleteProgram = (PFNGLDELETEPROGRAMPROC) wglGetProcAddress("glDeleteProgram");
glLinkProgram = (PFNGLLINKPROGRAMPROC) wglGetProcAddress("glLinkProgram"); glLinkProgram = (PFNGLLINKPROGRAMPROC) wglGetProcAddress("glLinkProgram");
@ -293,22 +294,6 @@ void TSalmonRenderer::SetShadowClampValue(float shadowClampValue)
} }
float TSalmonRenderer::GetFogBeginDistance()
{
return FogBeginDistance;
}
float TSalmonRenderer::GetFogEndDistance()
{
return FogEndDistance;
}
vec4 TSalmonRenderer::GetFogColor()
{
return FogColor;
}
void TSalmonRenderer::DrawTriangleList(const TTriangleList& triangleList) void TSalmonRenderer::DrawTriangleList(const TTriangleList& triangleList)

View File

@ -34,8 +34,8 @@ void TApplicationAncestor::OuterDeinit()
void TApplicationAncestor::OuterDraw() void TApplicationAncestor::OuterDraw()
{ {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
RenderUniform1i("Texture", 0); RenderUniform1i("Texture", 0);
@ -43,16 +43,16 @@ void TApplicationAncestor::OuterDraw()
InnerDraw(); InnerDraw();
glDisable(GL_DEPTH_TEST); //glDisable(GL_DEPTH_TEST);
Renderer->PushShader("DefaultShader"); /*Renderer->PushShader("DefaultShader");
if (IsConsoleOut) if (IsConsoleOut)
{ {
Console->Draw(); Console->Draw();
} }
Renderer->PopShader(); Renderer->PopShader();*/
glEnable(GL_DEPTH_TEST); //glEnable(GL_DEPTH_TEST);
} }
void TApplicationAncestor::OuterUpdate(cardinal timer) void TApplicationAncestor::OuterUpdate(cardinal timer)

View File

@ -10,9 +10,9 @@ std::vector<TFunctionBinderInterface*> TFunctionBinderInterface::BinderList;
TScriptManager::TScriptManager() TScriptManager::TScriptManager()
{ {
SquirrelVM::Init(); //SquirrelVM::Init();
virtualMachine = SquirrelVM::GetVMPtr(); //virtualMachine = SquirrelVM::GetVMPtr();
//SqPlus::RegisterGlobal(virtualMachine, SQ_Print, _SC("Print")); //SqPlus::RegisterGlobal(virtualMachine, SQ_Print, _SC("Print"));
//SqPlus::RegisterGlobal(virtualMachine, SQ_Print, _SC("p")); //SqPlus::RegisterGlobal(virtualMachine, SQ_Print, _SC("p"));
@ -58,12 +58,12 @@ TScriptManager::TScriptManager()
TScriptManager::~TScriptManager() TScriptManager::~TScriptManager()
{ {
*Console<<"Script manager shutdown"; *Console<<"Script manager shutdown";
SquirrelVM::Shutdown(); //SquirrelVM::Shutdown();
} }
void TScriptManager::RunScript(const std::string& scriptCode) void TScriptManager::RunScript(const std::string& scriptCode)
{ {
try /*try
{ {
SquirrelObject m = SquirrelVM::CompileBuffer(_T(scriptCode.c_str())); SquirrelObject m = SquirrelVM::CompileBuffer(_T(scriptCode.c_str()));
@ -72,7 +72,7 @@ void TScriptManager::RunScript(const std::string& scriptCode)
catch (SquirrelError) catch (SquirrelError)
{ {
*Console<<"Script failed to run"; *Console<<"Script failed to run";
} }*/
} }
@ -80,7 +80,7 @@ void TScriptManager::RunScript(const std::string& scriptCode)
void TScriptManager::BindBasicFunctions() void TScriptManager::BindBasicFunctions()
{ {
//Hack =D //Hack =D
static bool alreadyBind = false; /*static bool alreadyBind = false;
if (!alreadyBind) if (!alreadyBind)
{ {
@ -102,7 +102,7 @@ void TScriptManager::BindBasicFunctions()
alreadyBind = true; alreadyBind = true;
} }
*/
@ -171,10 +171,11 @@ void TScriptManager::Serialize(boost::property_tree::ptree& propertyTree)
//============= Typical commands ============== //============= Typical commands ==============
//============================================= //=============================================
/*
void SQ_Print(const SQChar *inString) void SQ_Print(const SQChar *inString)
{ {
Console->PrintImmediate(std::string(inString)); Console->PrintImmediate(std::string(inString));
} }*/
/* /*
void SQ_PrintWidgetList() void SQ_PrintWidgetList()

View File

@ -1,4 +1,5 @@
#include "include/Engine.h" #include "include/Engine.h"
#define TARGET_WIN32
namespace SE namespace SE
{ {
@ -67,15 +68,113 @@ TSimpleLandClass::~TSimpleLandClass()
void TSimpleLandClass::CreateVBO() void TSimpleLandClass::CreateVBO()
{ {
IndexArr.resize(6*(Width-1)*(Height-1));
int i, j, k, k_up, k_right, k_right_up;
vertexDataStruct.PositionData.clear();
vertexDataStruct.TexCoordData.clear();
vertexDataStruct.NormalData.clear();
for (i = 0; i < Height - 1; i++)
{
for (j = 0; j < Width - 1; j++)
{
k = j + i * Width;
k_right = (j + 1) + i * Width;
k_up = j + (i + 1) * Width;
k_right_up = (j + 1) + (i + 1) * Width;
float tx0 = float(j) / (Width - 1);
float ty0 = float(i) / (Height - 1);
float tx1 = float(j + 1) / (Width - 1);
float ty1 = float(i + 1) / (Height - 1);
vertexDataStruct.PositionData.push_back(VertexMatrix[k].pos);
vertexDataStruct.PositionData.push_back(VertexMatrix[k_right].pos);
vertexDataStruct.PositionData.push_back(VertexMatrix[k_up].pos);
vertexDataStruct.PositionData.push_back(VertexMatrix[k_right_up].pos);
vertexDataStruct.PositionData.push_back(VertexMatrix[k_up].pos);
vertexDataStruct.PositionData.push_back(VertexMatrix[k_right].pos);
vertexDataStruct.NormalData.push_back(VertexMatrix[k].norm);
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right].norm);
vertexDataStruct.NormalData.push_back(VertexMatrix[k_up].norm);
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right_up].norm);
vertexDataStruct.NormalData.push_back(VertexMatrix[k_up].norm);
vertexDataStruct.NormalData.push_back(VertexMatrix[k_right].norm);
vertexDataStruct.TexCoordData.push_back({ tx0, ty0 });
vertexDataStruct.TexCoordData.push_back({ tx1, ty0 });
vertexDataStruct.TexCoordData.push_back({ tx0, ty1 });
vertexDataStruct.TexCoordData.push_back({ tx1, ty1 });
vertexDataStruct.TexCoordData.push_back({ tx0, ty1 });
vertexDataStruct.TexCoordData.push_back({ tx1, ty0 });
/*
glBegin(GL_TRIANGLES);
glNormal3fv(VertexMatrix[k].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty0 }[0]);
glVertex3fv(VertexMatrix[k].pos.v);
glNormal3fv(VertexMatrix[k_right].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty0 }[0]);
glVertex3fv(VertexMatrix[k_right].pos.v);
glNormal3fv(VertexMatrix[k_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty1 }[0]);
glVertex3fv(VertexMatrix[k_up].pos.v);
glEnd();
glBegin(GL_TRIANGLES);
glNormal3fv(VertexMatrix[k_right_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right_up].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty1 }[0]);
glVertex3fv(VertexMatrix[k_right_up].pos.v);
glNormal3fv(VertexMatrix[k_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty1 }[0]);
glVertex3fv(VertexMatrix[k_up].pos.v);
glNormal3fv(VertexMatrix[k_right].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty0 }[0]);
glVertex3fv(VertexMatrix[k_right].pos.v);
glEnd();*/
}
}
vertexDataStruct.RefreshVBO();
/*IndexArr.resize(6 * (Width - 1) * (Height - 1));
//VBOLandVertexArr.resize(Width*Height); //VBOLandVertexArr.resize(Width*Height);
VBOLandVertexArr.pos.resize(Width * Height); VBOLandVertexArr.pos.resize(Width * Height);
VBOLandVertexArr.norm.resize(Width * Height); VBOLandVertexArr.norm.resize(Width * Height);
VBOLandVertexArr.tangent.resize(Width * Height); VBOLandVertexArr.tangent.resize(Width * Height);
VBOLandVertexArr.binorm.resize(Width * Height); VBOLandVertexArr.binorm.resize(Width * Height);
VBOLandVertexArr.texCoord.resize(Width * Height); VBOLandVertexArr.texCoord.resize(Width * Height);*/
/*
for (int i = 0; i < Height-1; i++) for (int i = 0; i < Height-1; i++)
for (int j = 0; j < Width-1; j++) for (int j = 0; j < Width-1; j++)
{ {
@ -126,12 +225,17 @@ void TSimpleLandClass::CreateVBO()
glBindBuffer(GL_ARRAY_BUFFER, TexcoordBuffer); glBindBuffer(GL_ARRAY_BUFFER, TexcoordBuffer);
glBufferData(GL_ARRAY_BUFFER, Width * Height * sizeof(vec2), &(VBOLandVertexArr.texCoord[0]), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, Width * Height * sizeof(vec2), &(VBOLandVertexArr.texCoord[0]), GL_STATIC_DRAW);
#endif #endif
*/
} }
void TSimpleLandClass::FreeVBO() void TSimpleLandClass::FreeVBO()
{ {
/*
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32
glDeleteBuffers(1, &VertexBuffer); glDeleteBuffers(1, &VertexBuffer);
glDeleteBuffers(1, &NormBuffer); glDeleteBuffers(1, &NormBuffer);
glDeleteBuffers(1, &TangentBuffer); glDeleteBuffers(1, &TangentBuffer);
@ -145,13 +249,16 @@ void TSimpleLandClass::FreeVBO()
VBOLandVertexArr.tangent.clear(); VBOLandVertexArr.tangent.clear();
VBOLandVertexArr.binorm.clear(); VBOLandVertexArr.binorm.clear();
VBOLandVertexArr.texCoord.clear(); VBOLandVertexArr.texCoord.clear();
IndexArr.clear(); IndexArr.clear();*/
} }
void TSimpleLandClass::UpdateVBO() void TSimpleLandClass::UpdateVBO()
{ {
//Index array remains the same - only vertex array is to be changed CreateVBO();
vertexDataStruct.RefreshVBO();
//Index array remains the same - only vertex array is to be changed
/*
for (int i = 0; i < Height; i++) for (int i = 0; i < Height; i++)
{ {
for (int j = 0; j < Width; j++) for (int j = 0; j < Width; j++)
@ -182,6 +289,7 @@ void TSimpleLandClass::UpdateVBO()
glBindBuffer(GL_ARRAY_BUFFER, TexcoordBuffer); glBindBuffer(GL_ARRAY_BUFFER, TexcoordBuffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, Width * Height * sizeof(vec2), &(VBOLandVertexArr.texCoord[0])); glBufferSubData(GL_ARRAY_BUFFER, 0, Width * Height * sizeof(vec2), &(VBOLandVertexArr.texCoord[0]));
#endif #endif
*/
} }
vec3 TSimpleLandClass::CalcCrossingForPoint(const vec3& pos, int i, int j) vec3 TSimpleLandClass::CalcCrossingForPoint(const vec3& pos, int i, int j)
@ -263,7 +371,7 @@ bool TSimpleLandClass::LoadFromFile(const std::string& filename)
//Replace old matrices with new //Replace old matrices with new
TriangleMatrix.resize(2*(Width-1)*(Height-1)); TriangleMatrix.resize(2*(Width)*(Height));
VertexMatrix = tempVertexMatrix; VertexMatrix = tempVertexMatrix;
UpdateTriangleMatrix(); UpdateTriangleMatrix();
@ -381,23 +489,27 @@ void TSimpleLandClass::DrawImmediate()
float tx1 = float(j+1)/(Width-1); float tx1 = float(j+1)/(Width-1);
float ty1 = float(i+1)/(Height-1); float ty1 = float(i+1)/(Height-1);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
glNormal3fv(VertexMatrix[k].norm.v); glNormal3fv(VertexMatrix[k].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k].binorm.v);
glTexCoord2f(tx0,ty0); //glTexCoord2f(tx0,ty0);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty0 }[0]);
glVertex3fv(VertexMatrix[k].pos.v); glVertex3fv(VertexMatrix[k].pos.v);
glNormal3fv(VertexMatrix[k_right].norm.v); glNormal3fv(VertexMatrix[k_right].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v);
glTexCoord2f(tx1,ty0); //glTexCoord2f(tx1,ty0);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty0 }[0]);
glVertex3fv(VertexMatrix[k_right].pos.v); glVertex3fv(VertexMatrix[k_right].pos.v);
glNormal3fv(VertexMatrix[k_up].norm.v); glNormal3fv(VertexMatrix[k_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v);
glTexCoord2f(tx0,ty1); //glTexCoord2f(tx0,ty1);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty1 }[0]);
glVertex3fv(VertexMatrix[k_up].pos.v); glVertex3fv(VertexMatrix[k_up].pos.v);
glEnd(); glEnd();
@ -405,19 +517,22 @@ void TSimpleLandClass::DrawImmediate()
glNormal3fv(VertexMatrix[k_right_up].norm.v); glNormal3fv(VertexMatrix[k_right_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right_up].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right_up].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right_up].binorm.v);
glTexCoord2f(tx1,ty1); //glTexCoord2f(tx1,ty1);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty1 }[0]);
glVertex3fv(VertexMatrix[k_right_up].pos.v); glVertex3fv(VertexMatrix[k_right_up].pos.v);
glNormal3fv(VertexMatrix[k_up].norm.v); glNormal3fv(VertexMatrix[k_up].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_up].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_up].binorm.v);
glTexCoord2f(tx0,ty1); //glTexCoord2f(tx0,ty1);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx0, ty1 }[0]);
glVertex3fv(VertexMatrix[k_up].pos.v); glVertex3fv(VertexMatrix[k_up].pos.v);
glNormal3fv(VertexMatrix[k_right].norm.v); glNormal3fv(VertexMatrix[k_right].norm.v);
VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v); VertexAttrib3fv(CONST_STRING_TANGENT_ATTRIB, VertexMatrix[k_right].tangent.v);
VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v); VertexAttrib3fv(CONST_STRING_BINORMAL_ATTRIB, VertexMatrix[k_right].binorm.v);
glTexCoord2f(tx1,ty0); //glTexCoord2f(tx1,ty0);
VertexAttrib3fv(CONST_STRING_TEXCOORD_ATTRIB, &std::array<float, 2>{ tx1, ty0 }[0]);
glVertex3fv(VertexMatrix[k_right].pos.v); glVertex3fv(VertexMatrix[k_right].pos.v);
glEnd(); glEnd();
@ -432,21 +547,37 @@ void TSimpleLandClass::DrawVBO()
{ {
//RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, min<cardinal>(NormTexID, 1));
//RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m); if (NormTexID == 0)
//RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
if (NormTexID != 0)
{ {
glActiveTexture(GL_TEXTURE1); RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM, 0);
glBindTexture(GL_TEXTURE_2D,NormTexID);
} }
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, WhiteColor);
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, NormTexID);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,TexID); glBindTexture(GL_TEXTURE_2D, TexID);
EnableVertexAttribArray("vPosition");
EnableVertexAttribArray("vTexCoord");
EnableVertexAttribArray("vNormal");
//Renderer->DrawTriangleList(TriangleList);
DrawVertexDataStruct(vertexDataStruct);
DisableVertexAttribArray("vPosition");
DisableVertexAttribArray("vTexCoord");
DisableVertexAttribArray("vNormal");
/*
#ifdef TARGET_WIN32 #ifdef TARGET_WIN32
@ -486,7 +617,7 @@ void TSimpleLandClass::DrawVBO()
glDrawElements(GL_TRIANGLES, 6*(Width-1)*(Height-1), GL_UNSIGNED_SHORT, &IndexArr[0]); glDrawElements(GL_TRIANGLES, 6*(Width-1)*(Height-1), GL_UNSIGNED_SHORT, &IndexArr[0]);
#endif #endif*/
RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM,1); RenderUniform1i(CONST_STRING_NORMALMAPEXISTS_UNIFORM,1);
@ -758,6 +889,25 @@ void TSimpleLandClass::RecalcNormalVectors()
{ {
int i,j,ifrom,ito,jfrom,jto; int i,j,ifrom,ito,jfrom,jto;
vec3 v1,v2; vec3 v1,v2;
for (i = 1; i < Height-1; i++)
{
for (j = 1; j < Width-1; j++)
{
ifrom = i - 1;
ito = i + 1;
jfrom = j - 1;
jto = j + 1;
v1 = Normalize(VertexMatrix[j + ito * Width].pos - VertexMatrix[j + ifrom * Width].pos);
v2 = Normalize(VertexMatrix[jto + i * Width].pos - VertexMatrix[jfrom + i * Width].pos);
VertexMatrix[j+i*Width].norm = CrossProduct(v2, v1);
}
}
/*
for (i=0;i<Height;i++) for (i=0;i<Height;i++)
for (j=0;j<Width;j++) for (j=0;j<Width;j++)
@ -776,7 +926,12 @@ void TSimpleLandClass::RecalcNormalVectors()
VertexMatrix[j+i*Width].tangent = v2; VertexMatrix[j+i*Width].tangent = v2;
VertexMatrix[j+i*Width].norm = CrossProduct(v2, v1); VertexMatrix[j+i*Width].norm = CrossProduct(v2, v1);
} if (VertexMatrix[j + i * Width].norm.v[1] < fabs(VertexMatrix[j + i * Width].norm.v[2]))
{
std::cout << "Wait..." << std::endl;
}
}*/
} }

View File

@ -86,7 +86,6 @@ ov_callbacks OggCallbacks = {
}; };
#endif //NOSOUND
} //namespace SE } //namespace SE
#endif //NOSOUND

View File

@ -1016,7 +1016,7 @@ cardinal TOggMusicStream::GetSamplesPerSec()
} }
#endif //NOSOUND
} //namespace SE } //namespace SE
#endif //NOSOUND

View File

@ -3,7 +3,7 @@
#include "include/Utils/Utils.h" #include "include/Utils/Utils.h"
#include "include/Engine.h" #include "include/Engine.h"
#include "boost/gil/gil_all.hpp" #include "boost/bind.hpp"
#include "boost/gil/extension/numeric/sampler.hpp" #include "boost/gil/extension/numeric/sampler.hpp"
#include "boost/gil/extension/numeric/resample.hpp" #include "boost/gil/extension/numeric/resample.hpp"
@ -18,6 +18,7 @@ TTextureListClass::TTextureListClass()
using namespace std; using namespace std;
CreateFunctionMap[".bmp"] = boost::bind(&TTextureListClass::CreateTexDataFromBmp24, this, _1, _2); CreateFunctionMap[".bmp"] = boost::bind(&TTextureListClass::CreateTexDataFromBmp24, this, _1, _2);
CreateFunctionMap[".bmp32"] = boost::bind(&TTextureListClass::CreateTexDataFromBmp32, this, _1, _2); CreateFunctionMap[".bmp32"] = boost::bind(&TTextureListClass::CreateTexDataFromBmp32, this, _1, _2);
CreateFunctionMap[".png"] = boost::bind(&TTextureListClass::CreateTexDataFromPng, this, _1, _2); CreateFunctionMap[".png"] = boost::bind(&TTextureListClass::CreateTexDataFromPng, this, _1, _2);
@ -569,7 +570,7 @@ cardinal TTextureListClass::AddTextureFromUserdata(const std::string& fileName,
} }
cardinal TTextureListClass::AddCubemapTexture(std::string filename[6]) cardinal TTextureListClass::AddCubemapTexture(std::array<std::string, 6> filename)
{ {