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.
Asked
Active
Viewed 193 times
0
-
The rectangle is 640x320 too, their indices are 0 to 639 and 0 to 319 – Pavel Angel Mendoza Villafane Apr 05 '17 at 18:28
1 Answers
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.

Paritosh Kulkarni
- 854
- 7
- 18