Hello there community!
I'm trying to extend my 2D UI to the third dimension, to allow 3D components. When I first played Crysis 3 I really liked the 3D hud and I'd like to be able to create similar UI components (for those who're not familiar with Crysis 3, here is a screenshot - I'm talking about the map and weapon components).
This is how I'm rendering my UI right now:
GLfloat width=(GLfloat) CEngine::getInstance().getWindow()->getWidth();
GLfloat height=(GLfloat) CEngine::getInstance().getWindow()->getHeight();
glm::mat4 viewProj=glm::ortho(0.0f,width,0.0f,height,2.0f*width,0.0f);
////////////////////////////////////////////////////
// Render all the visible UI elements
for (auto it=s_uiElements.begin();it!=s_uiElements.end();it++)
{
CUIElement* element=*it;
if (element->m_visible)
{
element->m_ubo->bindBase(CShader::UNIFORM_BINDPOINT_UI);
element->m_transform=viewProj*element->m_model;
element->uploadData();
element->renderThis();
}
}
A simple perspective projection, nothing fancy.
This is how I'm trying to set up the perspective projection:
glm::mat4 projection=glm::perspective(glm::radians(90.0f),width/height,0.0f,width);
glm::mat4 view=glm::lookAt(glm::vec3(width*0.5f,height*0.5f,0.0f),glm::vec3(width*0.5f,height*0.5f,-1.0f),glm::vec3(0.0f,1.0f,0.0f));
glm::mat4 viewProj=projection*view;
But it just doesn't work.
Could someone tell me what I'm doing wrong, and how I could approach this? I just can't figure it out on my own.
P.s: as for the model matrices and vertex data: they're rendered as quads ((0,0),(0,1),(1,0),(1,1)) and the model matrix takes them into the appropriate window position ((0,0)-(width,height)) and size.
[EDIT]:
For clarification: I have all the vertex data, model matrix, and all the like set up properly. I've been able to render 2D elements just fine for months, but I want to move to 3D now. All I need is a proper projection/view+projection matrix, that I could use to take the UI element's Y rotation and give it some depth.
My vertex data is set up such that each vertex falls into the vec2(0,0)-vec2(window_width,window_height) range, and the Z component is 0 by default, but it can be changed with rotations.
I have recently added support for various fill (normal / radial) and color (constant / gradient / radial gradient) methods, and I happen to have a screenshot of what I've got right now: [link]