View Full Version : Automatic Texture-coordinate Generation

09-05-2008, 04:48 AM

I have a series of 4D vertexes (x, y, z, v) that I represent by a position (x, y, z) and a color given as function of v between vmin and vmax.

In the case v is identical to z, I can use automatic texture-coordinate generation with:

glTexGenfv(GL_S, GL_OBJECT_PLANE, parameters)

and parameters[] = {0.0, 0.0, 1.0/(zmax - zmin), -zmin/ (zmax-zmin)}

Is there a way I can achieve the same thing using v?

In other words, I would like to avoid calling:


prior to each call to glVertex3f(x[i], y[i], z[i])

Is there an efficient way?


09-05-2008, 04:51 AM
Yes, use vertex shaders.

09-05-2008, 08:22 AM
Either my hardware or my OpenGL implementation does not seem to support vertex shaders because I cannot run some demos on the subject.

I have found a simpler although probably less efficient solution:

glDrawElements(GL_TRIANGLES, 3*n_faces, GL_UNSIGNED_INT, *faces)

It forces to have a color defined for each vertex but it solves the looping problem.

Thanks for the hint.

09-05-2008, 09:52 AM
I don't see how your "solution" can be a solution. How this should generate texture coordinates?

09-05-2008, 11:11 AM
Well, you're right.

That does not generate texture coordinates.

That just allows me to achieve the final effect I wanted in a fast way. By fast I mean without looping which is quite slow in my implementation.

Since I do not seem to have access to vertex shaders in my system (glGetString(GL_VERSION) returns 1.1.0), I am satisfied with that workaround. If there is a solution compatible with OpenGL 1.1 then I am eager to hear/read about it.

09-05-2008, 01:19 PM
glGetString(GL_VERSION) returns 1.1.0 ? Then you need to install correct drivers, because currently you are using software emulation.

09-07-2008, 11:58 AM
more details on the subject :

09-08-2008, 12:51 AM
Thanks, after updating the drivers I get 1.3.0.

The beauty of glTexGenfv(GL_S, GL_OBJECT_PLANE, parameters) is that for plotting millions of vertexes I do not need to store millions of colors. In my application a 1D texture of 256 colors is enough for the case of visualizing f(x,y,z) = z

I am going to study vertex shaders to see if I can achieve a similar thing for the case f(x,y,z) = v

Thanks again for all your hints.