miller
miller

Reputation: 1728

Difference between glTexImage1D and glTexImage2D

What is the difference between glTexImage2D() and glTexImage1D()? Actually, I can't imagine 1D texturing. How can something have a 1D texture?

Upvotes: 3

Views: 1118

Answers (2)

Nicol Bolas
Nicol Bolas

Reputation: 473322

A texture is not a picture you draw onto triangles. A texture is a look-up table of values, which your shaders can access and get data from. You can use textures as "pictures you draw onto triangles", but you should not limit your thinking to just that.

A 1D texture is a texture with only one dimension: width. It's a line. It is a function of one dimension: f(x). You provide one texture coordinate, and you get a value.

A 2D texture is a texture with two dimensions: width and height. It is a rectangle. It is a function of two dimensions: f(x, y). You provide two texture coordinates, and you get a value.

A 1D texture can be used for a discrete approximation of any one-dimensional function. You could precompute some Fresnel specular factors and access a 1D texture to get them, rather than computing them in the shader. A 1D texture could represent the Gaussian specular term, as I do in the first chapter on texturing in my book.

A 1D texture can be any one-dimensional function.

Upvotes: 8

StuGrey
StuGrey

Reputation: 1477

A 2D texture has both height and width whereas a 1D texture has a height of just 1 pixel. This basically means that the texture is a line of pixels. They are frequently used when we want to map some numeric value to a colour or map colour to a different colour (as in cell-shading techniques).

Upvotes: 2

Related Questions