I have some code to render GUI's, and if I dont use a vertex shader then it renders exactly where its meant to :
However, as soon as I use a vertex shader, even simply one that calls
gl_position = vec4(position,1.0);
It hides, or moves, or otherwise makes my GUI disappear
Whats the correct way to have a shader for GUIs in OpenGL?
GUI render :
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -10, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
RendererUtils.setWireframeMode(false);
for (Interface i : interfaces)
{
i.updateShaderForThisB();
if (i instanceof InterfaceContainer)
{
((InterfaceContainer) i).draw();
}
else
{
((InterfaceControl) i).draw();
}
}
InterfaceShader.getInstance().unbind();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
InterfaceContainer and InterfaceControl's draw call is largely the same, so I'll only add one of them.
InterfaceControl.draw()
public void draw()
{
this.updateShaderForThisB();
this.getMesh().draw();
if (this.hasText)
{
//this.updateShaderForThisF();
//drawText();
}
}
InterfaceControl.updateShaderForThisB()
public void updateShaderForThisB()
{
InterfaceShader shader = InterfaceShader.getInstance();
shader.bind();
shader.setColour(this.getActingColour());
shader.setLocation(this.getLocation());
shader.setSize(this.getBounds());
shader.setGradient(this.getShouldGradient());
shader.updateUniforms();
}
Mesh.draw()
public void draw()
{
glEnableVertexAttribArray(0); //Vertices
glEnableVertexAttribArray(1); //Tex coords
glEnableVertexAttribArray(2); //Normals
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE * 4, 0);
glVertexAttribPointer(1, 2, GL_FLOAT, false, Vertex.SIZE * 4, 12);
glVertexAttribPointer(2, 3, GL_FLOAT, false, Vertex.SIZE * 4, 20);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
}
InterfaceShader.vs
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texCoord;
uniform mat4 viewMatrix;
out vec2 texCoord0;
void main()
{
gl_Position = viewMatrix * vec4(position,1.0);
texCoord0 = texCoord;
}
Can anyone see an obvious problem that i've overlooked? My first thought was that the shader was translating my interface-oriented coordinates (ie 50,50,1) into real world coordinates, but I dont know
Edit : As requested, updated shader code and added matrix projection code
pastebin for Transform class, for getting the view matrix and such, and how it's related back to the shader