Convert Pixel Length to OPENGL coordinates -


how 1 convert pixel length (i.e image 512 pixel width , height) accurate opengl coordinates?

all can try guess size manually between -1 , 1.

the question quite vague, see problem window coordinates ranging, say, between -1 1; , since screen rectangle, quads drawn rectangle rather square.

it not recommended draw in "pixel coordinates" since monitors don't have same resolution nor same aspect ratio. however, if want do, how you'd it:

if using shaders opengl 3+:

  • just divide x coordinate half of width of window , subtract 1.

  • do same the y coordinate divide half height instead of half width.

if using old immediate mode opengl (which way not recommended , outdated since long ago) should glortho

note above orthographic projection (2d).

if want draw in 3d should not draw in "pixel coordinates" means. instead, multiply either width or height relevant aspect ratio (i.e width/height or height/width) or integrate aspect ratio perspective projection if creating own shader.

generally, opengl not draw pixels. draw opengl's own coordinate system , opengl convert pixels. makes powerful 3d rendering. approach more convenient because of differing monitor resolutions , aspect ratios.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -