Projection Matrix mirrors my object

Hello,

I want my code to draw a triangle of size 200px by 200px at coordinates in pixels 800, 800, to do this I use this code:

For simplicity, I only printed out the start and end values of the vertex coordinates.

``````#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

using namespace std;
using namespace glm;

void printMat4(const glm::mat4& matrice) {
const float* matriceArray = glm::value_ptr(matrice);

for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
if (j == 0)
cout << "\t";

cout << matriceArray[i * 4 + j] << "\t";
}

cout << std::endl;
}

cout << "\n\n";
}

void printVec4(const glm::vec4& vector){
const float* vectorArray = glm::value_ptr(vector);

for (int i = 0; i < 4; i++){
cout << vectorArray[i];
if (i != 3)
cout << ", ";
}
}

int main(){
vec4 vertices[] = {
vec4(0,1,0,1),
vec4(-1,-1,0,1),
vec4(1,-1,0,1),
};

mat4 scale, translate, projection;
scale = translate = projection = mat4(1);

scale = glm::scale(scale, vec3(200/2, 200/2, 0));
translate = glm::translate(translate, vec3(800, 800, 0));
projection = glm::ortho(0.0f, 800.0f, 0.0f, 800.0f, -1.0f, +1.0f);

for (int i = 0; i < 3; i++){
cout << "\n\n - VERTEX " << i << " |\n\n";

cout << "\t";
printVec4(vertices[i]);
cout << "\n";

cout << "\t";
printVec4(projection*translate*scale*vertices[i]);

cout << "\n\n";
}

return 0;
}
``````

The triangle has indeed been scaled and translated correctly, in fact the size is 200x200 and the centre of the triangle is positioned at coordinates 800x800, but is mirrored vertically.

To solve the problem I multiply, within the Vertex Shader, by -1 the y-coordinate of each vertex before applying any transformation, in this way I get what I want.

My questions are:

1. Why do you mirror the triangle?
2. Is this the right way to solve the problem?