Hello, i’m trying to move from ndc coordinates in the vbo to use projection and model view matrices so i can just put screen spaced coordinated to the vbo and to be able to translate and rotate but the problem I can’t get it working, I try to found the problem but i couldn’t. I use this forum as a last resort.
draw part
float[] ve = new float[]{
(float) (x + width), (float) (y + height), 0.0f, 0, 0, 1.0f, 1.0f, 1.0f, 1.0f,
(float) x, (float) (y + height), 0.0f, 1, 0, 1.0f, 1.0f, 1.0f, 1.0f,
(float) (x + width), (float) y, 0.0f, 0, 1, 1.0f, 1.0f, 1.0f, 1.0f,
(float) x, (float) y, 0.0f, 1, 1, 1.0f, 1.0f, 1.0f, 1.0f,
(float) (x + width), (float) y, 0.0f, 0, 1, 1.0f, 1.0f, 1.0f, 1.0f,
(float) x, (float) (y + height), 0.0f, 1, 0, 1.0f, 1.0f, 1.0f, 1.0f
};
FloatBuffer quadBuffer = BufferUtils.createFloatBuffer(ve.length);
quadBuffer.put(ve).flip();
int prevVao = GL11.glGetInteger(GL30.GL_VERTEX_ARRAY_BINDING);
int prevVbo = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, ShaderUtil.vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, quadBuffer, GL15.GL_DYNAMIC_DRAW);
GlStateManager.glActiveTexture(GL13.GL_TEXTURE0);
GlStateManager._bindTexture(test);
GL11.glEnable(GL11.GL_BLEND);
glViewport(0,0,mc.getWindow().getWidth(), mc.getWindow().getHeight());
ShaderProgram prog = Shaders.Test.getProgram();
prog.bind();
int proj = GL20.glGetUniformLocation(prog.getProgramId(), "projection");
setProjectionMatrix(proj, RenderSystem.getModelViewMatrix(), RenderSystem.getProjectionMatrix());
GL30.glBindVertexArray(ShaderUtil.vao);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
GL30.glBindVertexArray(prevVao);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, prevVbo);
prog.unbind();
vertex shader
void main()
{
gl_Position = projection * vec4(position.xy, 0.0, 1.0);
fragTexCoord = texCoord;
fragColor = color;
}
setProjectionMatrix in the draw part
public void setProjectionMatrix(int proj,Matrix4f modelViewMatrix, Matrix4f projectionMatrix) {
Matrix4f mvpMatrix = new Matrix4f(projectionMatrix).mul(modelViewMatrix);
float[] matrixArray = new float[] {
mvpMatrix.m00(), mvpMatrix.m01(), mvpMatrix.m02(), mvpMatrix.m03(),
mvpMatrix.m10(), mvpMatrix.m11(), mvpMatrix.m12(), mvpMatrix.m13(),
mvpMatrix.m20(), mvpMatrix.m21(), mvpMatrix.m22(), mvpMatrix.m23(),
mvpMatrix.m30(), mvpMatrix.m31(), mvpMatrix.m32(), mvpMatrix.m33()
};
ChatUtil.sendChatMessage(Text.literal(Arrays.toString(matrixArray)));
GL20.glUniformMatrix4fv(proj, false, matrixArray);
}
a vertex in my vbo contains 9 floats x, y, z, u, v, r, g, b, a
this code worked when i manually put ndc coordinates in the vbo
i doubt its the matrix the problem as other uses it and it works for them
if you need some informations in addition pls leave a reply i will try to reply fast
the current goal of this projection is for 2D
thanks