How to convert pixel coordinates of a texture image to texture coordinates on a quadrilateral geometry?

env is win10 gtx3050ti opengl4.x.

Texture coordinates are in the range of [0…1]. So lets say your image resolution is ImgX x ImgY and the pixel you want to convert is Px, Py, then all you need to do to calculate the Texture coordinates U, V is

U = Px / ImgX
V = Py / ImgY

Now here is the catch, pixel coordinates usually start at the top left corner of the image and texture coordinates usually start at the bottom left corner of the texture, this means that to get the correct orientation you need to do 1 minus V, so we have this

U = Px / ImgX
V = 1 - (Py / ImgY)

Hope it helps


How do you compute on this quadrilateral geometry?

I’m not sure I understand the question anymore. Can you give an example of where the pixel you want to convert is and where is the texture?

Post more detail about the problems you’re having, if any, and what you’ve tried to resolve them.

This perhaps?: