sreesreenu
sreesreenu

Reputation: 1057

How does opengl texturing works?

I have been playing with opengl for some time and i found texturing to be very interesting. I have a cube with a face selected, i can project that face to a 2d image and map the color in that image to the 3d model. How does this work? What algorithm is involved in this? In software like blender we can live edit the vertices in the 2d projection that gets automatically mapped to the 3d model. There are even options to unwrap, cube project, cylinder project etc.

enter image description here

I am not sure if this is the right place to ask such a question. But i am asking it out of curiosity.

Upvotes: 1

Views: 111

Answers (1)

Dorota Kadłubowska
Dorota Kadłubowska

Reputation: 675

Texturing is basically mapping of texels (a texture's pixel) onto fragments (a pixel that composes the image of the rendered geometry on the screen). What texel is to be mapped onto a given fragment depends on the fragment's texture coordinates. In a simplest case the coordinates are associated with the geometry per vertex basis and interpolated to fragments after the geometry is projected onto the screen and rasterized. The coordinates are usually normalized, meaning they have values between 0 and 1. For a 2D texture one have 2 coordinates - u and v. One of them is aligned with the horizontal axis of the texture image, the other with the vertical. When in a fragment shader a texture is sampled via a texture sampler to get a color for given coordinates, the sampler simply returns a value that is interpolated from a number of texels found according to the coordinate, the mipmap level and an interpolation method. The coordinates applied can vary depending on what type of texturing is required. The interpolation method changes the final image quality. Mipmapping is used for changing level of the texture's detail usually depending on view distance (filtering).

Some links for more information: https://www.cs.utexas.edu/~fussell/courses/cs384g/lectures/lecture12-Texture_mapping.pdf http://cg.informatik.uni-freiburg.de/course_notes/graphics_06_texturing.pdf http://www.cs.cmu.edu/~djames/15-462/Fall03/notes/09-texture.pdf

Upvotes: 3

Related Questions