• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Generating texture coords [Ogre related]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Omid Ghavami  Members

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:
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);


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

### #2scgames  Members

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.]

### #3Omid Ghavami  Members

Posted 22 August 2006 - 08:37 PM

Hi jyk!

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 redbookWhen GL_TEXTURE_GEN_MODE and GL_OBJECT_LINEAR are specified, the generation function is a linearcombination of the object coordinates of the vertex (xo,yo,zo,wo):generated coordinate = p1x0 + p2y0 + p3z0 + p4w0The 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 onone 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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.