The ultimate goal is NDC space (normalized device coordinate space).
Y axis: -1 is bottom of screen, +1 is top
X axis: -1 is left side of screen, +1 is right
If you want an ortho view (no "depth" -- which is fine for 2D) then you don't have to care about Z or W. Just have Z=0 and W=1 for all your vertexes.
NDC space is then scaled to your screen res by OpenGL. So if your screen is 800x600... then X=-1 becomes X=0... and X=+1 becomes X=800. Etc.
If you don't care about full matrix calculations... this means you have to do 2 things.
#1 You have to offset your vetexes based on where the "camera" is.
#2 You have to "translate" your pixel coordinates to NDC coordinates.
#1 is up to you how you want to do it. Assuming you have a camera X,Y position... it might be as simple as this:
|
finalposition = vertex - camera;
|
#2 is just a matter of scaling [0,windowsize.X] to [-1,+1]
|
scale = (1.0 / (windowsize * 0.5)) - 1.0;
|
So it ends up being:
|
finalposition = scale * (input_vertex - camera);
|
EDIT:
note that this will make (0,0) the
bottom left corner of your screen and not the top-left like you might be used to.
Also note that using the camera value directly like this is not the best approach because if you have large worlds, you start seeing floating point rounding errors.