mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
implemented depth configuration for 2D elements
fixed text offset configuration
This commit is contained in:
@@ -6,11 +6,12 @@ layout (location=2) in vec2 aTexCoords;
|
||||
out vec2 texCoords;
|
||||
|
||||
uniform vec2 screen;
|
||||
uniform vec3 pos;
|
||||
|
||||
void main(){
|
||||
float x,y;
|
||||
x=(aVert.x-screen.x*.5)/(screen.x*.5);
|
||||
y=(screen.y*.5-aVert.y)/(screen.y*.5);
|
||||
gl_Position=vec4(x,y,0,1);
|
||||
x=(aVert.x+pos.x-screen.x*.5)/(screen.x*.5);
|
||||
y=(screen.y*.5-(aVert.y+pos.y))/(screen.y*.5);
|
||||
gl_Position=vec4(x,y,pos.z+aVert.z,1);
|
||||
texCoords=aTexCoords;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,11 @@ namespace vb01{
|
||||
shader->setMat4(proj,"proj");
|
||||
shader->setVec3(camPos,"camPos");
|
||||
shader->setMat4(model,"model");
|
||||
if(material->getType()==Material::MATERIAL_GUI)
|
||||
if(material->getType()==Material::MATERIAL_GUI){
|
||||
shader->setVec2(Vector2((float)width,(float)height),"screen");
|
||||
if(node)
|
||||
shader->setVec3(pos,"pos");
|
||||
}
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -57,31 +57,34 @@ namespace vb01{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
/*
|
||||
glGenFramebuffers(1,&guiFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,guiFBO);
|
||||
glGenFramebuffers(1,&FBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,FBO);
|
||||
Texture *texture=new Texture();
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,*(texture->getTexture()),0);
|
||||
|
||||
glGenRenderbuffers(1,&guiRBO);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER,guiRBO);
|
||||
/*
|
||||
glGenRenderbuffers(1,&RBO);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER,RBO);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8,width,height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,guiRBO);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,RBO);
|
||||
*/
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
else
|
||||
cout<<"Complete\n";
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
guiPlane=new Quad(Vector3::VEC_IJK);
|
||||
guiPlane=new Quad(Vector3(width,height,-1),false);
|
||||
Material *mat=new Material(Material::MATERIAL_GUI);
|
||||
mat->addDiffuseMap(texture);
|
||||
guiPlane->setMaterial(mat);
|
||||
*/
|
||||
}
|
||||
|
||||
void Root::update(){
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,FBO);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
@@ -94,21 +97,21 @@ namespace vb01{
|
||||
}
|
||||
|
||||
rootNode->update();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
guiNode->update();
|
||||
/*
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,guiFBO);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
*/
|
||||
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
//guiPlane->update();
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
guiPlane->update();
|
||||
/*
|
||||
*/
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
guiNode->update();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void Root::createSkybox(string textures[6]){
|
||||
|
||||
@@ -25,13 +25,14 @@ namespace vb01{
|
||||
inline Node* getGuiNode(){return guiNode;}
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline GLFWwindow* getWindow(){return window;}
|
||||
void createSkybox(std::string[6]);
|
||||
static Root* getSingleton();
|
||||
private:
|
||||
Box *skybox=nullptr;
|
||||
Quad *guiPlane=nullptr;
|
||||
int width,height;
|
||||
unsigned int guiFBO,guiRBO;
|
||||
unsigned int FBO,RBO;
|
||||
GLFWwindow *window;
|
||||
Node *rootNode,*guiNode;
|
||||
Camera *camera;
|
||||
|
||||
@@ -17,6 +17,7 @@ EBO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typere
|
||||
EBO particleEmitter.h /^ unsigned int instanceVBO,VAO,VBO,EBO;$/;" m class:vb01::ParticleEmitter typeref:typename:unsigned int
|
||||
ErrorType shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" g class:vb01::Shader
|
||||
FAST_BITS stb_image.h /^#define FAST_BITS /;" d
|
||||
FBO root.h /^ unsigned int FBO,RBO;$/;" m class:vb01::Root typeref:typename:unsigned int
|
||||
FRAGMENT shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" e enum:vb01::Shader::ErrorType
|
||||
Glyph text.h /^ struct Glyph{$/;" s class:vb01::Text
|
||||
LIGHT_H light.h /^#define LIGHT_H$/;" d
|
||||
@@ -63,6 +64,7 @@ Quaternion quaternion.h /^ Quaternion(){}$/;" f class:vb01::Quaternion
|
||||
Quaternion quaternion.h /^ Quaternion(float angle, Vector3 axis){$/;" f class:vb01::Quaternion
|
||||
Quaternion quaternion.h /^ Quaternion(float w,float x,float y,float z){$/;" f class:vb01::Quaternion
|
||||
Quaternion quaternion.h /^ class Quaternion{$/;" c namespace:vb01
|
||||
RBO root.h /^ unsigned int FBO,RBO;$/;" m class:vb01::Root typeref:typename:unsigned int
|
||||
RECTANGLE_H rectangle.h /^#define RECTANGLE_H$/;" d
|
||||
ROOT_H root.h /^#define ROOT_H$/;" d
|
||||
Rectangle rectangle.cpp /^ Rectangle::Rectangle(Vector3 size){$/;" f class:vb01::Rectangle
|
||||
@@ -134,6 +136,7 @@ TEXTURE_H texture.h /^#define TEXTURE_H$/;" d
|
||||
TEXT_H text.h /^#define TEXT_H$/;" d
|
||||
Text text.cpp /^ Text::Text(string fontPath,string entry){$/;" f class:vb01::Text
|
||||
Text text.h /^ class Text{$/;" c namespace:vb01
|
||||
Texture texture.cpp /^ Texture::Texture(){$/;" f class:vb01::Texture
|
||||
Texture texture.cpp /^ Texture::Texture(FT_Face &face, char ch){$/;" f class:vb01::Texture
|
||||
Texture texture.cpp /^ Texture::Texture(int width, int height){$/;" f class:vb01::Texture
|
||||
Texture texture.cpp /^ Texture::Texture(string path){$/;" f class:vb01::Texture
|
||||
@@ -378,10 +381,9 @@ getTime util.h /^ inline s64 getTime(){return s64(std::chrono::system_clock::now
|
||||
getType material.h /^ inline Type getType(){return type;}$/;" f class:vb01::Material typeref:typename:Type
|
||||
getUp camera.h /^ inline Vector3 getUp(){return up;}$/;" f class:vb01::Camera typeref:typename:Vector3
|
||||
getWidth root.h /^ inline int getWidth(){return width;}$/;" f class:vb01::Root typeref:typename:int
|
||||
guiFBO root.h /^ unsigned int guiFBO,guiRBO;$/;" m class:vb01::Root typeref:typename:unsigned int
|
||||
getWindow root.h /^ inline GLFWwindow* getWindow(){return window;}$/;" f class:vb01::Root typeref:typename:GLFWwindow *
|
||||
guiNode root.h /^ Node *rootNode,*guiNode;$/;" m class:vb01::Root typeref:typename:Node **
|
||||
guiPlane root.h /^ Quad *guiPlane=nullptr;$/;" m class:vb01::Root typeref:typename:Quad *
|
||||
guiRBO root.h /^ unsigned int guiFBO,guiRBO;$/;" m class:vb01::Root typeref:typename:unsigned int
|
||||
h stb_image.h /^ int h,v;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
|
||||
h stb_image.h /^ int w,h;$/;" m struct:__anon84e4e8861308 typeref:typename:int
|
||||
h2 stb_image.h /^ int x,y,w2,h2;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
|
||||
@@ -546,6 +548,7 @@ setBool shader.cpp /^ void Shader::setBool(bool b, string var){$/;" f class:vb01
|
||||
setCastShadow mesh.h /^ inline void setCastShadow(bool castShadow){this->castShadow=castShadow;}$/;" f class:vb01::Mesh typeref:typename:void
|
||||
setCastShadow model.cpp /^ void Model::setCastShadow(bool castShadow){$/;" f class:vb01::Model typeref:typename:void
|
||||
setColor light.h /^ inline void setColor(Vector3 color){this->color=color;}$/;" f class:vb01::Light typeref:typename:void
|
||||
setColor text.h /^ inline void setColor(Vector4 c){this->color=c;}$/;" f class:vb01::Text typeref:typename:void
|
||||
setDiffuseColor material.h /^ inline void setDiffuseColor(Vector4 diffuse){this->diffuseColor=diffuse;}$/;" f class:vb01::Material typeref:typename:void
|
||||
setDirection light.h /^ inline void setDirection(Vector3 dir){this->direction=dir;}$/;" f class:vb01::Light typeref:typename:void
|
||||
setEndColor particleEmitter.h /^ inline void setEndColor(Vector4 color){this->endColor=color;}$/;" f class:vb01::ParticleEmitter typeref:typename:void
|
||||
@@ -568,6 +571,7 @@ setPosition camera.h /^ void setPosition(Vector3 position){this->position=posi
|
||||
setPosition light.h /^ inline void setPosition(Vector3 pos){this->position=pos;}$/;" f class:vb01::Light typeref:typename:void
|
||||
setPosition node.h /^ inline void setPosition(Vector3 pos){this->pos=pos;}$/;" f class:vb01::Node typeref:typename:void
|
||||
setScale node.h /^ inline void setScale(Vector3 scale){this->scale=scale;}$/;" f class:vb01::Node typeref:typename:void
|
||||
setScale text.h /^ inline void setScale(float s){this->scale=s;}$/;" f class:vb01::Text typeref:typename:void
|
||||
setShadowFarPlane light.h /^ inline void setShadowFarPlane(float farPlane){this->farPlane=farPlane;}$/;" f class:vb01::Light typeref:typename:void
|
||||
setShadowNearPlane light.h /^ inline void setShadowNearPlane(float nearPlane){this->nearPlane=nearPlane;}$/;" f class:vb01::Light typeref:typename:void
|
||||
setSize box.cpp /^ void Box::setSize(Vector3 size){$/;" f class:vb01::Box typeref:typename:void
|
||||
|
||||
@@ -13,7 +13,7 @@ using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Text::Text(string fontPath,string entry){
|
||||
string basePath="/home/dominykas/c++/FSim/text.";
|
||||
string basePath="/home/dominykas/c++/vb01/text.";
|
||||
shader=new Shader(basePath+"vert",basePath+"frag");
|
||||
|
||||
FT_Library ft;
|
||||
@@ -27,7 +27,7 @@ namespace vb01{
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
|
||||
for(u32 i=0;i<15000;i++){
|
||||
for(u32 i=0;i<256;i++){
|
||||
if(FT_Load_Char(face,i,FT_LOAD_RENDER)){
|
||||
cout<<"Could not load glyph\n";
|
||||
continue;
|
||||
@@ -56,6 +56,7 @@ namespace vb01{
|
||||
shader->use();
|
||||
shader->setVec4(color,"color");
|
||||
shader->setVec2(Vector2(width,height),"screen");
|
||||
shader->setVec3(node->getPosition(),"pos");
|
||||
|
||||
Vector3 origin=node->getPosition();
|
||||
for(int i=0;i<entry.length();i++){
|
||||
@@ -69,13 +70,13 @@ namespace vb01{
|
||||
if(!foundChar)continue;
|
||||
Vector2 size=ch.size*scale,bearing=ch.bearing;
|
||||
float data[]={
|
||||
origin.x+bearing.x,origin.y-bearing.y,0,1,
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y,1,1,
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y+size.y,1,0,
|
||||
origin.x+bearing.x,origin.y-bearing.y,0,0,
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y,1,0,
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y+size.y,1,1,
|
||||
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y+size.y,1,0,
|
||||
origin.x+bearing.x,origin.y-bearing.y+size.y,0,0,
|
||||
origin.x+bearing.x,origin.y-bearing.y,0,1
|
||||
origin.x+bearing.x+size.x,origin.y-bearing.y+size.y,1,1,
|
||||
origin.x+bearing.x,origin.y-bearing.y+size.y,0,1,
|
||||
origin.x+bearing.x,origin.y-bearing.y,0,0
|
||||
};
|
||||
origin.x+=(ch.advance>>6)*scale;
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace vb01{
|
||||
void update();
|
||||
void setText(std::string);
|
||||
inline void setNode(Node *node){this->node=node;}
|
||||
inline void setScale(float s){this->scale=s;}
|
||||
inline void setColor(Vector4 c){this->color=c;}
|
||||
private:
|
||||
Node *node=nullptr;
|
||||
std::string entry;
|
||||
|
||||
@@ -5,11 +5,12 @@ layout (location=0) in vec4 aVert;
|
||||
out vec2 texCoords;
|
||||
|
||||
uniform vec2 screen;
|
||||
uniform vec3 pos;
|
||||
|
||||
void main(){
|
||||
float x,y;
|
||||
x=(aVert.x-screen.x*.5)/(screen.x*.5);
|
||||
y=(screen.y*.5-aVert.y)/(screen.y*.5);
|
||||
gl_Position=vec4(x,y,0,1);
|
||||
y=(screen.y*.5-(aVert.y))/(screen.y*.5);
|
||||
gl_Position=vec4(x,y,pos.z,1);
|
||||
texCoords=aVert.zw;
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,18 +9,18 @@ using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
/*
|
||||
*/
|
||||
Texture::Texture(){
|
||||
width=800,height=600;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,1,GL_RGB,GL_UNSIGNED_BYTE,NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
*/
|
||||
|
||||
Texture::Texture(int width, int height){
|
||||
this->width=width;
|
||||
|
||||
Reference in New Issue
Block a user