Jump to content
  • Advertisement
Sign in to follow this  
L. Spiro

OpenGL GL_OBJECT_LINEAR

This topic is 2909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For my terrain I want to generate texture coordinates instead of sending a bunch to the hardware.


I am trying to use GL_OBJECT_LINEAR but it is always generating coordinates based off the X and Y of the terrain instead of the X and Z. Y is up. So my texture only tiles correctly on slopes. See the picture.

http://memoryhacking.com/Pictures/Screen48.png

This is obviously the normal to-be-expected result.
ST--
XYZW

Of course the T is going t coincide with Y.


I thought I could use a texture matrix to swap T and R.
[1 0 0 0]
[0 0 1 0]
[0 1 0 0]
[0 0 0 1]

But this fails, leaving T at 0 always.


How can I get this to work?
My actual calls to OpenGL® API functions were extracted via OpenGL Intercept. 9217.000000 == GL_OBJECT_LINEAR.
glMatrixMode(GL_TEXTURE)
glLoadMatrixf(
[0.020000,0.000000,0.000000,0.000000]
[0.000000,0.000000,0.020000,0.000000]
[0.000000,0.020000,0.000000,0.000000]
[0.000000,0.000000,0.000000,1.000000])
glTexGenf(GL_S,GL_TEXTURE_GEN_MODE,9217.000000)
glTexGenf(GL_T,GL_TEXTURE_GEN_MODE,9217.000000)
glTexGenf(GL_R,GL_TEXTURE_GEN_MODE,9217.000000)
glEnable(GL_TEXTURE_GEN_S)
glEnable(GL_TEXTURE_GEN_T)
glEnable(GL_TEXTURE_GEN_R)
glDisable(GL_TEXTURE_GEN_Q)
glVertexPointer(3,GL_FLOAT,24,0x8db0470)
glNormalPointer(GL_FLOAT,24,0x8db047c)
glDrawElements(GL_TRIANGLE_STRIP,574,GL_UNSIGNED_SHORT,0x8dab790) Textures[ (0,5) ]




Thank you,
Yogurt Emperor

Share this post


Link to post
Share on other sites
Advertisement
I'm nor entirely sure how the texture matrix interacts with the texture coordinate generation, but I don't think it can accomplish your desired effect. What you can do, if I remember correct, is to set the object planes for each texture axis.

You shouldn't need to generate anything for the R coordinate, only the S and T coordinates.

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

Then set the object plane parameters for how you want to generate the texture coordinates. Basically, these are the object axes used to generate the texture coordinates.

GLfloat saxis[4] = {1, 0, 0, 1};
GLfloat taxis[4] = {0, 0, 1, 1};
glTexGenf(GL_S, GL_OBJECT_PLANE, saxis);
glTexGenf(GL_T, GL_OBJECT_PLANE, taxis);

saxis is the axis along which the S coordinate is generated; the X-axis. taxis is the axis along which the T coordinate is generated; the Z-axis. As shown, one unit in object coordinate along the Z-axis will generate one unit along the T axis. You can scale the axes (keep W=1 though) to control how many texture coordinate units are generated for each object coordinate unit. Replacing 1 by, say, 1/10.0, generates one texture unit for every ten object unit.

Keep in mind, it was a long time since I did anything with this, so it may need some tweaking.

Share this post


Link to post
Share on other sites
Thank you; it works.

Unfortunately. Because I was hoping for a solution that could be done with no modifications to my DirectX engine. In order to replicate this I will have to add an object-plane matrix to each texture unit.
But that is not so bad.

Also I researched it a bit. The values you feed into GL_OBJECT_PLANE are actually used in a plane equation, so the W value is actually the distance in the direction of XYZ of the plane. So it is not restricted to being just 1.0f.


Thank you again.
Yogurt Emperor

Share this post


Link to post
Share on other sites
Quote:
Original post by YogurtEmperor
Thank you; it works.

Unfortunately. Because I was hoping for a solution that could be done with no modifications to my DirectX engine. In order to replicate this I will have to add an object-plane matrix to each texture unit.
But that is not so bad.

I'm not sure what you mean, but it appears from the intercept log that you are already supplying this matrix in an attempt do to something with the texture matrix. If I understand it correct, the plane vectors are just the rows of this matrix, so perhaps you don't have to add extra parameters.

Quote:
Original post by YogurtEmperor
Also I researched it a bit. The values you feed into GL_OBJECT_PLANE are actually used in a plane equation, so the W value is actually the distance in the direction of XYZ of the plane. So it is not restricted to being just 1.0f.

Yes, you are correct. It is not a homogeneous vector, but a plane equation. If you have W=0, it means there's no offset being added to the generated texture coordinates. If you use the n:th row of the matrix, you'll see that you have the translation part of the matrix in the W component of the n:th plane equation.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
I'm not sure what you mean, but it appears from the intercept log that you are already supplying this matrix in an attempt do to something with the texture matrix. If I understand it correct, the plane vectors are just the rows of this matrix, so perhaps you don't have to add extra parameters.

What I mean to say is in order to get my engine to support DirectX and OpenGL equally, my DirectX shader will need more additions. I already had to use a shader to gain support for object-linear texgen in DirectX; now I have to add a matrix modifier to that.


Quote:
Original post by Brother Bob
Yes, you are correct. It is not a homogeneous vector, but a plane equation. If you have W=0, it means there's no offset being added to the generated texture coordinates. If you use the n:th row of the matrix, you'll see that you have the translation part of the matrix in the W component of the n:th plane equation.

Yep. I plan to implement this in my DirectX shader as a simple matrix multiply.


Yogurt Emperor

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!