Math相关头文件移到hgl/math目录
This commit is contained in:
parent
d5450325ba
commit
4fb13ced34
@ -2,9 +2,77 @@
|
|||||||
#include<hgl/render/RenderWindow.h>
|
#include<hgl/render/RenderWindow.h>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<GLEWCore/glew.h>
|
#include<GLEWCore/glew.h>
|
||||||
|
#include<hgl/render/Shader.h>
|
||||||
|
#include<hgl/math/Math.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
|
|
||||||
|
constexpr uint screen_width=1280;
|
||||||
|
constexpr uint screen_height=720;
|
||||||
|
|
||||||
|
Matrix4f ortho_2d_matrix;
|
||||||
|
|
||||||
|
void InitMatrix()
|
||||||
|
{
|
||||||
|
ortho_2d_matrix=ortho2d(screen_width,screen_height, //2D画面宽高
|
||||||
|
false); //Y轴使用底为0顶为1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
constexpr char vertex_shader[]=R"(
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
uniform mat4 ModelViewProjectionMatrix;
|
||||||
|
|
||||||
|
in vec2 Vertex;
|
||||||
|
in vec3 Color;
|
||||||
|
|
||||||
|
out vec4 FragmentColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 Position;
|
||||||
|
|
||||||
|
FragmentColor=vec4(Color,1.0);
|
||||||
|
|
||||||
|
Position=vec4(Vertex,0.0,1.0);
|
||||||
|
|
||||||
|
gl_Position=Position*ModelViewProjectionMatrix;
|
||||||
|
})";
|
||||||
|
|
||||||
|
constexpr char fragment_shader[]=R"(
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in vec4 FragmentColor;
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor=vec4(FragmentColor.rgb,1);
|
||||||
|
})";
|
||||||
|
|
||||||
|
Shader shader;
|
||||||
|
|
||||||
|
bool InitShader()
|
||||||
|
{
|
||||||
|
if(!shader.AddVertexShader(vertex_shader))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!shader.AddFragmentShader(fragment_shader))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!shader.Build())
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!shader.Use())
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!shader.SetUniformMatrix4fv("ModelViewProjectionMatrix",ortho_2d_matrix))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr GLfloat clear_color[4]=
|
constexpr GLfloat clear_color[4]=
|
||||||
{
|
{
|
||||||
77.f/255.f,
|
77.f/255.f,
|
||||||
@ -43,9 +111,17 @@ int main(void)
|
|||||||
|
|
||||||
RenderSetup rs;
|
RenderSetup rs;
|
||||||
|
|
||||||
RenderWindow *win=device->CreateWindow(1280,720,&ws,&rs);
|
RenderWindow *win=device->CreateWindow(screen_width,screen_height,&ws,&rs);
|
||||||
|
|
||||||
win->MakeToCurrent(); //切换当前窗口到前台
|
win->MakeToCurrent(); //切换当前窗口到前台
|
||||||
|
|
||||||
|
InitMatrix();
|
||||||
|
if(!InitShader())
|
||||||
|
{
|
||||||
|
std::cerr<<"init shader failed."<<std::endl;
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
win->Show();
|
win->Show();
|
||||||
|
|
||||||
while(win->IsOpen())
|
while(win->IsOpen())
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
#ifndef HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
||||||
#define HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
#define HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
@ -6,11 +6,11 @@
|
|||||||
//注:GLM/CML(OpenGLMode)是列矩阵,计算坐标matrix*pos
|
//注:GLM/CML(OpenGLMode)是列矩阵,计算坐标matrix*pos
|
||||||
// 而MGL是行矩阵,需要反过来pos*matrix
|
// 而MGL是行矩阵,需要反过来pos*matrix
|
||||||
|
|
||||||
#include<hgl/algorithm/MathMGL.h> // Game Math and Geometry Library
|
#include<hgl/math/MathMGL.h> // Game Math and Geometry Library
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace algorithm
|
namespace math
|
||||||
{
|
{
|
||||||
double Lsin(int angle); ///<低精度sin计算,注意传入的参数为角度而非弧度
|
double Lsin(int angle); ///<低精度sin计算,注意传入的参数为角度而非弧度
|
||||||
double Lcos(int angle); ///<低精度cos计算,注意传入的参数为角度而非弧度
|
double Lcos(int angle); ///<低精度cos计算,注意传入的参数为角度而非弧度
|
||||||
@ -150,6 +150,6 @@ namespace hgl
|
|||||||
result.x = center.x + ((source.x - center.x)*ac - (source.y - center.y)*as);
|
result.x = center.x + ((source.x - center.x)*ac - (source.y - center.y)*as);
|
||||||
result.y = center.y + ((source.x - center.x)*as + (source.y - center.y)*ac);
|
result.y = center.y + ((source.x - center.x)*as + (source.y - center.y)*ac);
|
||||||
}
|
}
|
||||||
}//namespace algorithm
|
}//namespace math
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
#endif//HGL_ALGORITHM_VECTOR_MATH_INCLUDE
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef HGL_ALGORITHM_VECTOR_MATH_MGL_INCLUDE
|
#ifndef HGL_ALGORITHM_VECTOR_MATH_MGL_INCLUDE
|
||||||
#define HGL_ALGORITHM_VECTOR_MATH_MGL_INCLUDE
|
#define HGL_ALGORITHM_VECTOR_MATH_MGL_INCLUDE
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -119,11 +119,21 @@ namespace hgl
|
|||||||
return m.Inverted();
|
return m.Inverted();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Matrix4f ortho2d(float width,float height,float znear=0,float zfar=1)
|
/**
|
||||||
|
* 生成一个2D正角视图矩阵
|
||||||
|
* @param width 宽
|
||||||
|
* @param height 高
|
||||||
|
* @param top_to_bottom 从上到下(是否最顶部y轴为0,默认否)
|
||||||
|
* @param znear 近平面z值
|
||||||
|
* @param zfar 远平台z值
|
||||||
|
*/
|
||||||
|
inline Matrix4f ortho2d(float width,float height,bool top_to_bottom=false,float znear=0,float zfar=1)
|
||||||
{
|
{
|
||||||
//MathGeoLib生成的2D正交矩阵中心是0,0,所以需要偏移
|
//MathGeoLib生成的2D正交矩阵中心是0,0,所以需要偏移
|
||||||
|
|
||||||
return Matrix4f::OpenGLOrthoProjRH(znear,zfar,width,height)*Matrix4f::Scale(1,-1,1)*Matrix4f::Translate(-(width/2.0f),-(height/2.0f),0);
|
return Matrix4f::OpenGLOrthoProjRH(znear,zfar,width,height)
|
||||||
|
*Matrix4f::Scale(1,top_to_bottom?-1:1,1)
|
||||||
|
*Matrix4f::Translate(-(width/2.0f),-(height/2.0f),0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Matrix4f translate(const Vector3f &v)
|
inline Matrix4f translate(const Vector3f &v)
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include<hgl/type/BaseString.h>
|
#include<hgl/type/BaseString.h>
|
||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
#include<hgl/algorithm/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
// #include<hgl/graph/UBO.h>
|
// #include<hgl/graph/UBO.h>
|
||||||
// #include<hgl/graph/SSBO.h>
|
// #include<hgl/graph/SSBO.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
add_library(ULRE.RenderDriver STATIC GLCore/RenderDriverGLCore.cpp)
|
add_library(ULRE.RenderDriver STATIC GLCore/RenderDriverGLCore.cpp
|
||||||
|
GLSL.cpp
|
||||||
|
Shader.cpp)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//#include<hgl/LogInfo.h>
|
//#include<hgl/LogInfo.h>
|
||||||
#include<hgl/type/Smart.h>
|
#include<hgl/type/Smart.h>
|
||||||
#include<malloc.h>
|
#include<malloc.h>
|
||||||
#include<GL/glext.h>
|
#include<GLEWCore/glew.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -67,7 +67,7 @@ namespace hgl
|
|||||||
|
|
||||||
delete[] log;
|
delete[] log;
|
||||||
|
|
||||||
LOG_ERROR(shader_source);
|
//LOG_ERROR(shader_source);
|
||||||
|
|
||||||
glDeleteShader(shader);
|
glDeleteShader(shader);
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace hgl
|
|||||||
if(!shader_codes
|
if(!shader_codes
|
||||||
||!(*shader_codes))return(false);
|
||!(*shader_codes))return(false);
|
||||||
|
|
||||||
shader_index[shader_type]=CompileShader(OpenGLShaderType[shader_type],ShaderName[shader_type],shader_codes);
|
shader_index[shader_type]=CompileShader(OpenGLShaderType[shader_type],ShaderTypeName[shader_type],shader_codes);
|
||||||
|
|
||||||
if(!shader_index[shader_type])
|
if(!shader_index[shader_type])
|
||||||
return(false);
|
return(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user