The first line creates a perspective projection equivalent to calling gluPerspective (45.0f, 1.0f, 0.1f, 100.0f). If you do not know what gluPerspective does, check this link
glm::mat4 Projection = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f);
The next line is only modulo an angle of rotation of 360 to ensure that the projection angle is less than 360 degrees.
angle = (GLfloat) (i % 360);
The next few lines define our View matrix. This is basically your camera viewing port, that is, what you see on the monitor. The call to the translation and rotation functions are conversion functions that cause our camera to move to
glm::mat4 View = glm::mat4(1.); View = glm::translate(View, glm::vec3(0.f, 0.f, -5.0f)); View = glm::rotate(View, angle * -1.0f, glm::vec3(1.f, 0.f, 0.f)); View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 1.f, 0.f)); View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 0.f, 1.f));
The next line defines the position of our model. In this case it will be (1.0f, 1.0f, 1.0f, 1.0f). If you are wondering why there are 4 options instead of 3, read the OpenGL orange book or check Wikipedia for uniform coordinates
glm::mat4 Model = glm::mat4(1.0);
The last two lines complete the setup of our scene by calculating the projection matrix of the model and passing it to OpenGL.
glm::mat4 MVP = Projection * View * Model; glUniformMatrix4fv(glGetUniformLocation(shaderprogram, "mvpmatrix"), 1, GL_FALSE, glm::value_ptr(MVP));
In general, what your code block does is simulates an OpenGL drawing pipeline from translating model coordinates into presentation coordinates.
About the second question you ask. I do not understand the first part, what do you understand when translating a number into a pixel? Are you trying to map a point in a 1D matrix to a 2D matrix? if so, just do a standard mapping, something like a pixel [index / rows] [index% rows], where the pixel is your display pixel object, the index is your array index, the row is the width of your screen. For the second part (how to set (0,0) to the middle of the screen), I think that you just need to add an offset to the beginning of the screen, since OpenGL uses the left coordinate system, the starting point of the screen i.e. (0,0) the dot will be in the lower left corner of the screen. Therefore, if you want your system to be in the middle of the screen, just add an offset (-width / 2, -height / 2) to translate your point into OpenGL space or (width / 2, height / 2) for the opposite projection. But using a self-prepared standard is not recommended.