GLfloat currentCoeff[] = {1, 0, 0, 0}; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, currentCoeff); GLfloat currentCoeff2[] = {0, 0, 1, 0}; glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T, GL_OBJECT_PLANE, currentCoeff2); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T);

**0**

# Generating texture coords [Ogre related]

Started by Omid Ghavami, Aug 22 2006 11:07 AM

2 replies to this topic

###
#1
Members - Reputation: **1002**

Posted 22 August 2006 - 11:07 AM

Hi!
I have horizontal polygons consisting of three or more vertices without texture coordinates so I'm looking for a way to generate these.
When I first started playing around with it, I found a solution in OpenGL using the fixed function pipeline.
It was something like this:
Now I've moved my project to the Ogre engine. So I'm stuck with this problem once again, and this time I'm hoping for a more robust solution.
I've tried in vain to find an Ogre feature to generate these uv coordinates for me, but since it's such a huge engine I'm guessing there's still a lot I'm missing.
So the purpose of this thread is to ask if anyone knows of a way to do this, either Ogre specific, or any general method to generate texture coordinates for a vertical polygon consisting of three or more vertices.
(btw: I'm rendering my polygons using triangle fans in Ogre. In OGL I used GL_POLYGON.)
EDIT: typo
To give you an idea of the result I'm looking for, here is a screenshot from the OGL version:

Best regards, Omid

Sponsor:

###
#2
Members - Reputation: **2000**

Posted 22 August 2006 - 01:22 PM

The first thing I'd say here is that the Red Book (I think) describes the computations used in GL_OBJECT_LINEAR texgen mode, and they would most likely be fairly easy to replicate. IIRC it's a simple point-plane distance computation, where the input plane may be non-normalized (effectively scaling the texture coordinates). There may be more to it than that, but I'd have to check.

I'm assuming that this is for generating texcoords for the floor polygons in your example image. Assuming they lie in a cardinal plane, you could special-case this with a simple linear mapping. However, it would most likely end up being equivalent to a GL_OBJECT_LINEAR-type computation, where the reference planes were the two other cardinal planes (possibly with scaled normals), so it might be just as well to add that functionality.

And of couse, as you suggested, the functionality could already be available in the Ogre engine somewhere.

I had to write some code like this for one of my projects, so let me know if you need any further info.

[Edit: Looking at your example code, I'm thinking it should be very easy to implement from scratch. Again I would check the red book, but I think the respective components of the texture coordinates are just the 4D dot product between the (homogeneous) vertex and the respective plane expressed as a 4-vector.]

I'm assuming that this is for generating texcoords for the floor polygons in your example image. Assuming they lie in a cardinal plane, you could special-case this with a simple linear mapping. However, it would most likely end up being equivalent to a GL_OBJECT_LINEAR-type computation, where the reference planes were the two other cardinal planes (possibly with scaled normals), so it might be just as well to add that functionality.

And of couse, as you suggested, the functionality could already be available in the Ogre engine somewhere.

I had to write some code like this for one of my projects, so let me know if you need any further info.

[Edit: Looking at your example code, I'm thinking it should be very easy to implement from scratch. Again I would check the red book, but I think the respective components of the texture coordinates are just the 4D dot product between the (homogeneous) vertex and the respective plane expressed as a 4-vector.]

###
#3
Members - Reputation: **1002**

Posted 22 August 2006 - 08:37 PM

Hi jyk!

Thanks for your reply [smile]

I actually came to think of using each vertex' own 2D position vector in the horizontal plane as it's texture coordinates shortly after I posted, so I felt a bit silly, but since there's so much more to this I'm still glad I posted.

I got a pretty similar result to what I had before.

This what the redbook says on GL_OBJECT_LINEAR:

So if I get this right, you specify two planes (in my case one x = 0 and one z = 0 ), and each texture coordinate is the distance of the vertex to each of these two planes. I am wary of drawing any conclusions, specially since I just woke up, but this seems to agree nicely with your advice of taking the dot product! And in the case of the xz-plane (if y is up) it will be equivalent to what I mentioned trying above.

The result in Ogre:

Then I'll know who to ask if I need guidance [smile]

Thanks for your help and time!

Thanks for your reply [smile]

I actually came to think of using each vertex' own 2D position vector in the horizontal plane as it's texture coordinates shortly after I posted, so I felt a bit silly, but since there's so much more to this I'm still glad I posted.

I got a pretty similar result to what I had before.

This what the redbook says on GL_OBJECT_LINEAR:

Quote:

From the redbook

When GL_TEXTURE_GEN_MODE and GL_OBJECT_LINEAR are specified, the generation function is a linear

combination of the object coordinates of the vertex (xo,yo,zo,wo):

generated coordinate = p1x0 + p2y0 + p3z0 + p4w0

The p1, ..., p4 values are supplied as the param argument to glTexGen*v(), with pname set to GL_OBJECT_PLANE.

With p1, ..., p4 correctly normalized, this function gives the distance from the vertex to a plane. For example, if p2 = p3

= p4 = 0 and p1 = 1, the function gives the distance between the vertex and the plane x = 0. The distance is positive on

one side of the plane, negative on the other, and zero if the vertex lies on the plane.

So if I get this right, you specify two planes (in my case one x = 0 and one z = 0 ), and each texture coordinate is the distance of the vertex to each of these two planes. I am wary of drawing any conclusions, specially since I just woke up, but this seems to agree nicely with your advice of taking the dot product! And in the case of the xz-plane (if y is up) it will be equivalent to what I mentioned trying above.

The result in Ogre:

Quote:

I had to write some code like this for one of my projects, so let me know if you need any further info.

Then I'll know who to ask if I need guidance [smile]

Thanks for your help and time!

Best regards, Omid