PDA

View Full Version : ogl texturing problem



gl_CodER
03-06-2006, 10:14 AM
I draw two textured quads(1d texturing ) with tex coords shown below. My assumption ws that the quads will be colored as mirror images of each .. thats how i have specified the tex coords. But it does not happed so. Have a look at it here

ogl tex (http://www.geocities.com/gl_coder_one/ogl_texturing_problem.html)

0_1
|_|
0 0

1_0
|_|
0 0
sorry for the real bad diagram . hope it suffices
The quads are drwan with counter clockwise winding with the bottom left vertex first.

Shouldnt the coloring produced for the two quads be mirror images of each other ????

jide
03-06-2006, 10:38 AM
I guess you'll need to rotate the texture on your second quad. The problem more looks like belonging to the algorithm GL uses to do the calculations.

gl_CodER
03-06-2006, 10:52 AM
hmm ,, what do you mean by rotate the texture coords .. it would not serve the purpose then :( As in the texture stores a red to blue color transition. And a coord of 1 maps to red and 0 to blue. If it a problem belongin to the algorithm OGL uses ,, isnt there a way out >>>???

i may hav put some wrong info on that link above .. forgot to update some text while updating pics .

jide
03-06-2006, 10:56 AM
I didn't meant to rotate the texture coords, but the texture, using the texture matrix. Something like:


glMatrixMode (GL_TEXTURE);
glRotatef (90, 0,1,0);
...
glMatrixMode (GL_MODELVIEW);

gl_CodER
03-06-2006, 11:03 AM
:( that actually cannot be done .. cause tex coords are generated procedurally and i would not know in advance what tex coord is generated. Also using a texture matrix actually rotates the texture matrix rite. Isnt this a serious problem .. if it has to do with how ogl calculates ?

jide
03-06-2006, 11:08 AM
I don't know, I'm afraid I can't try to help you more than that. Maybe with using a 2D texture instead.

Chuck0
03-06-2006, 11:30 AM
i guess this is happening because the quad is split into two triangles. thus the texture coordinates are interpolated on those two triangles resulting in what you showed with your screenshots.

evanGLizr
03-06-2006, 12:25 PM
The problem here is that OpenGL doesn't specify how a polygon is broken into triangles, for a quad with vertices 0123, in some cases you may get triangles 012, 230 and in others you may get 301, 123 (the OpenGL invariance rules guarantee that under certain conditions you will always get the same triangulation, though).
Interpolating your texture coordinates for one triangulation gives completely different results from the other.

The technical issue is that non-linear attributes are not guaranteed to be properly interpolated across polygons. This is easy to picture if you imagine that your texture coordinates are actually your vertex positions, you will see that the polygon drawn in this texture coordinate system is not "flat", but warped.

This problem also occurs with vertex lighting, depending on how the hardware breaks up the polygon you'll get different lighting (again, because the polygon is not flat in the color coordinate system).

You will have the same problem if your polygon is clipped, as the clipping algorithm will try to linearly interpolate attributes which are not linear.

Dirk
03-06-2006, 02:05 PM
evanGLizr explained the problem, here are some idea towards a solution.

The simple one is to triangulate the quads yourself. That will give you consistency, but not necessarily the result you want.

To really solve it you need barycentric interpolation in the quad, which OpenGL won't give you. But you can probably implement it in a shader yourself. You might want to look at the 'A Quadrilateral Rendering Primitive' paper by Kai Hormann and Marco Tari, and at the paper they get their idea from, 'Mean value coordinates' by Michael S. Floater. It's not going to be as trivial as just using GL_QUADS, but it should be possible. I haven't tried it myself though, so if somebody has (and maybe has code to spare ;) ), please speak up.

Hope it helps

Dirk