implemented overlays and text, need depth configuration

This commit is contained in:
devZoGok
2021-10-18 19:05:04 +03:00
parent d1f2f9b152
commit 7a8a178a74
26 changed files with 544 additions and 73 deletions
+24 -11
View File
@@ -31,9 +31,9 @@ namespace vb01{
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER,VBO);
glBufferData(GL_ARRAY_BUFFER, 3*numTris*sizeof(Vertex), vertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, 3*numTris*sizeof(Vertex),staticVerts?vertices:NULL, staticVerts?GL_STATIC_DRAW:GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,3*numTris*sizeof(unsigned int),indices,GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,3*numTris*sizeof(unsigned int),staticVerts?indices:NULL,staticVerts?GL_STATIC_DRAW:GL_DYNAMIC_DRAW);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(Vertex),(void*)0);
glEnableVertexAttribArray(0);
@@ -41,10 +41,13 @@ namespace vb01{
glEnableVertexAttribArray(1);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,sizeof(Vertex),(void*)(offsetof(Vertex,texCoords)));
glEnableVertexAttribArray(2);
}
void Mesh::update(){
mat4 model=mat4(1.f);
mat4 view=mat4(1.f);
mat4 proj=mat4(1.f);
Root *root=Root::getSingleton();
Camera *cam=root->getCamera();
float fov=cam->getFov(),width=root->getWidth(),height=root->getHeight();
@@ -52,19 +55,29 @@ namespace vb01{
Vector3 pos=(node?node->getPosition():Vector3::VEC_ZERO);
Vector3 dir=cam->getDirection(),up=cam->getUp(),camPos=cam->getPosition();
mat4 model=translate(mat4(1.),vec3(pos.x,pos.y,pos.z));
model=translate(mat4(1.),vec3(pos.x,pos.y,pos.z));
model=rotate(model,radians(0.f),vec3(1,1,1));
mat4 view=lookAt(vec3(camPos.x,camPos.y,camPos.z),vec3(camPos.x+dir.x,camPos.y+dir.y,camPos.z+dir.z),vec3(up.x,up.y,up.z));
mat4 proj=perspective(radians(fov),width/height,nearPlane,farPlane);
//proj=ortho(0.f,800.f,0.f,-600.f,nearPlane,farPlane);
view=lookAt(vec3(camPos.x,camPos.y,camPos.z),vec3(camPos.x+dir.x,camPos.y+dir.y,camPos.z+dir.z),vec3(up.x,up.y,up.z));
proj=perspective(radians(fov),width/height,nearPlane,farPlane);
material->update();
material->getShader()->setVec3(camPos,"camPos");
material->getShader()->setMat4(model,"model");
material->getShader()->setMat4(view,"view");
material->getShader()->setMat4(proj,"proj");
Shader *shader=material->getShader();
shader->setVec3(camPos,"camPos");
shader->setMat4(model,"model");
shader->setMat4(view,"view");
shader->setMat4(proj,"proj");
if(material->getType()==Material::MATERIAL_GUI)
shader->setVec2(Vector2((float)width,(float)height),"screen");
//proj=ortho(0.f,800.f,0.f,-600.f,nearPlane,farPlane);
glBindVertexArray(VAO);
if(!staticVerts){
glBindBuffer(GL_ARRAY_BUFFER,VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, 3*numTris*sizeof(Vertex),vertices);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,0,3*numTris*sizeof(unsigned int),indices);
}
glDrawElements(GL_TRIANGLES,3*numTris,GL_UNSIGNED_INT,0);
}
}