Advertisement

Texture problem

Started by December 16, 2000 04:49 PM
8 comments, last by klajntib 23 years, 11 months ago
Okay folks, I have a problem. I have a textured squade made from 2 triangles. the texture is loaded from a tga file. The first and the last line of the texture seem to be switched (first is last and last is first). The problem isn''t in the TGA loading code, ''cause I''ve tried a bunch of different codes. Does anybody have a clue?? Pleeeeeeeeeeeaaase help me, because I couldn''t get rid of the problem in my last 3 opengl programming attempts. Oh yeah if it matters, I have a voodoo 3 3000. Thanks for your feedback!
You mean that top and bottom is mixed?
Hardware has y increasing down and OpenGL the reversed so this is not surprising.

Use a paint program to flip the textures.
Advertisement
you could be specifying the texture co-ords in the wrong order..

Just as an example: A Quad

The First top left hand vertex has co-ords (0,1,0) and a tex co-ord of (0,1)

The Bottom left hand vertex has co-ords (0,0,0) and a tex co-ord of (0,0)

The Bottom right hand vertex has co-ords (1,0,0) and a tex co-ord of (1,0);

The Top right hand vertex has co-ords (1,1,0) and a tex co-ord of (1,1)

Just make sure you specify the texture co-ords in the right order, otherwise the texture appears to be upside down..
No,no

The texture is not upside-down, just the first and the last lines of pixels are switched.

Any ideas?
It sounds suspiciously like the image is simply shifted down by one pixel which would result in that last line having to be wrapped to the top. I know that''s not quite the description you gave, but it''s the closest thing I can think of that makes any sense.

If this is indeed what''s happening, it can be caused by a few things. One, of course, is the image loading code itself. The first incarnation of my TGA loader had this exact problem due to some simple mis-typing, so that was easily fixed. But you said you switched out the image loading code, right? Was it all for TGA also? Perhaps trying to load a BMP as a texture would be something to try simply to narrow things down--if _that_ works, the problem is in the loading algorithm(s).

The only other thing I can think of is that the texture simply is being offset by 1 pixel. Off the top of my head, I can''t think of how that would be the case. I somehow remember there being some functions in OpenGL and Direct3D for setting an offset for textures, but I may be mis-remembering. Otherwise, a similar effect could come from not setting texture coordinates properly. This is possible. I know that with my first 3D app I had tons of weird problems and simply changing the order of things slightly made all the difference in the world. You may want to try that.

Anyway, that''s all that comes to mind at the moment. Please keep us posted, and good luck.
Thanks merlin9x9. I''ve tried many loading codes for BMP and TGA, even the LoadPicture(or something) windows standard function and the problem is still here. Oh yeah, how do I know the last two lines are intechanged? I drew a triangle (widening from top of the tex to the bottom of it) on the texture and I found out that if I render the texture on a square (2 tris) it starts with the widest last line, the lines in bettwen are a normal triangle and the last line is the first topmost pixel. It''s something like this:
. <- first line
/ \
/ \
/ \ <- this is how the TGA texture looks
/ \
/ \
----------- <- last line
=============================================
----------- <- this shold be at the bottom
/ \
/ \
/ \
/ \
/ \
. <- this should be at the top

I hope the above art(hehe) makes it easier to understand!

Maybe it''s a problem with my display driver, I have no clue.

Thanks everybody
Advertisement
Sorry about the pics spaces didn''t work:

''''''''''. <- first line
''''''''/''\
''''''/''''''\
''''/''''''''''\ <- this is how the TGA texture looks
''/''''''''''''''\
/''''''''''''''''''\
----------- <- last line
=============================================
----------- <- this shold be at the bottom
''''''''/''\
''''''/''''''\
''''/''''''''''\
''/''''''''''''''\
/''''''''''''''''''\
''''''''''. <- this should be at the top


don''t mind the '' chars they are just there to fill the space!
DAMN '' DIDN''T WORK WELL I HOPE YOU GET THE PICUTRE!

Bye
Do you have some code to show?
Sounds to me like it''s just texture wrapping at work. Try disabling it (changing the texture addressing mode to clamp) and see if the problem is still there.

- Peter (not the above AP)

This topic is closed to new replies.

Advertisement