# how to map normalized device coordinates/world space to screen coordinates in 2D?

I am trying to map the NDC to screen coordinates in 2D , what is the formula for this?

i dont know matrix mathematics so if you can give me the Cartesian formula or method

just to be precise i am trying to go from vertices i give opengl to screen coordinates i.e -1.0,0.0 etc to screen coordinates 200,300 etc in 2D space

Vertices which you give to OpenGL are first converted to clip coordinates, either by multiplying them by the model-view and projection matrices (for the fixed-function pipeline), or by whatever transformations the vertex shader implements (gl_Position is in clip coordinates).

After clipping, clip coordinates are converted to NDC by dividing by W. NDC are converted to window coordinates by the viewport transformation:

X[sub]w[/sub] = (x[sub]ndc[/sub]+1)(width/2)+x
y[sub]w[/sub] = (y[sub]ndc[/sub]+1)
(height/2)+y

where x,y,width,height are the parameters to glViewport().

Note that window coordinates are relative to the lower-left corner of the window.

thanks for that information

also if it is possible if you would be able to tell me how i would also go in reverse? if i have screen coordinates how would i go to ndc?

x[sub]ndc[/sub] = (x[sub]w[/sub]-x)/(width/2)-1
y[sub]ndc[/sub] = (y[sub]w[/sub]-y)/(height/2)-1

thanks for that lol i obviously missed something quiet simple, but thanks nevertheless