0

I have an image of 640x320 and a rectangle (2 triangles) with vertices (0,0) (0,319), (639,0), (639,319). I want to render using (Opengl 4) the rectangle with the texture without normalize the vertices because I need to work with the same units.

1 Answers1

0

You can treat your coordinates of rectangle in window space you convert them to ndc space

xndc = (xw-x)/(width/2)-1

yndc = (yw-y)/(height/2)-1

x y width and height should be 0 0 640 320 Xw and Yw will be your rectangle vertices. One by one calculate vertices in NDC space [-1 1] range. You can now pass them directly to shader to draw no need of any transformation just set proper viewport.

For texture coordinates do same as above which will bring them in [-1 1] range but you will further need to convert them in [0 1] you can use following formula

Uv = Uvndc *0.5 + 0.5

Use this yo bring x and y or uv to range [0 1]. Now you can use this uv to do texture mapping in shader.