PDA

View Full Version : How to create a 2D coordinate system?

nickyc95
06-06-2014, 04:27 AM
Hello there,

Over the past few weeks I have been learning OpenGL and I feel that I am now at a stage where I can attempt to make something.

The problem that I am having is that I want to make a 2D game...

I don't know how I am supposed to convert the OpenGL coordinate system into something useful.

For example I have a sprite that is 16x16 pixels and I want to place it at 100, 100 within the world, however I cannot because the world coordinates are -1 to 1.

I am using a Orthographic Projection.

void setothographicmat(float l, float r, float t, float b, float n, float f, glm::mat4 &mat)
{
mat[0][0] = 2 / (r - l);
mat[0][1] = 0;
mat[0][2] = 0;
mat[0][3] = 0;

mat[1][0] = 0;
mat[1][1] = 2 / (t - b);
mat[1][2] = 0;
mat[1][3] = 0;

mat[2][0] = 0;
mat[2][1] = 0;
mat[2][2] = -1 / (f - n);
mat[2][3] = 0;

mat[3][0] = -(r + l) / (r - l);
mat[3][1] = -(t + b) / (t - b);
mat[3][2] = -n / (f - n);
mat[3][3] = 1;
}

Any information would be greatly appreciated.

Thanks