I just want to draw a simple triangle using GL_LINES primitive with orthographic projection matrix.
This is my vertices...
float_t vertices[]{
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f
};
And this is my matrices(model, view, projection)...
glm::mat4 model = glm::mat4(1.0f);
prog.setMat4fv1("model", model);
glm::mat4 view = glm::mat4(1.0f);
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
prog.setMat4fv1("view", view);
glm::mat4 projection = glm::mat4(1.0f);
projection = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);
prog.setMat4fv1("projection", projection);
And this is the code in the while loop (game loop) that draws a triangle...
prog.useProgram();
glBindVertexArray(vao);
glDrawArrays(GL_LINES, 0, 6);
I see nothing. But when I change the code for projection matrix from glm::ortho()
to glm::perspective()
, it draws a triangle which is obviously smaller than the original one because of the code view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
which moves all the objects a little bit away from the camera.(I am not coding for the camera class at this time.)
So this is the code for projection matrix which works fine...
projection = glm::perspective(glm::radians(45.0f), (float_t)win_width / (float_t)win_height, 0.1f, 100.0f);
Am I doing something wrong with glm::ortho()? I can only create a model matrix and it's just fine. But this the first time I am using glm::ortho() and I don't see any examples on the internet. How can I solve the issuse with glm::ortho()?
projection = glm::ortho(0.0f, 4.0f, 0.0f, 3.0f, 0.1f, 100.0f);
. After that, you might notice that the triangle is not centered, try with thisprojection = glm::ortho(-2.0f, +2.0f, -1.5f, +1.5f, 0.1f, 100.0f);
\$\endgroup\$projection = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);
and scale my triangle with model matix, is it fine? Or should I put smaller values in theglm::ortho()
? Thanks. \$\endgroup\$