# OpenGL Problem with textures appearing on the wrong plane (?!)

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

## Recommended Posts

Hi all, New here, seems like a place full of knowledgable people so hoping someone can help :) My problem is: I am attempting to texture map a scene, and the textures are appearing fine for objects in the Y plane (i.e. "vertical"), but not objects in the X plane - the textures appear to be stretched as if it was one pixel high. An example is: here - you can see the horizontal textures look stretched, but the vertical ones appear fine. (It's the exact same grass texture on all the "land") I'm not quite sure where I am going wrong (although it is likely something stupid!) - each quad has texture coords applied (0,0 in the top left, 1,0 in the top right, etc). The problem disappears if I stop textures being bound to an object - i.e. removing the following lines from my LoadTextures() function: // Texturing Contour Anchored To The Object glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); // Texturing Contour Anchored To The Object glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); (example - here) but this then causes the textures to not move when the viewpoint moves, causing a "swimming" effect as you move through the scene. Another solution I found was to draw the object in the Y plane, and then rotate it to be in the correct position, but I'm sure you'll agree this is far from ideal. I must admit that my knowledge of OpenGL is pretty much from code examples (e.g. NeHE, and the examples for the module for which I am creating this work) and reading around the internet and man pages, so it's possible that there is something important that I am overlooking. If anyone has any ideas about what *could* be going wrong here, it would be very much appreciated. Thanks, Tom

##### Share on other sites
What are your texture coordinates? What mode are you using? GL_REPEAT or GL_CLAMP? If you want to tile it set it to GL_REPEAT and make sure you set WRAP_S and WRAP_T in the texture setup functions...

##### Share on other sites
Hi Mars999,

Cheers for your help. I wasn't using GL_REPEAT _or_ GL_CLAMP explicitly, so I've added in GL_REPEAT (as that's what I want). My texture coords are between 0 and 1 in both x and y. None of this has fixed it :(

On the off chance that anyone has spare time (and is a wonderful person ;)) I've uploaded an example, test.cc, to demonstrate this (it just draws three quads, and is about as stripped down as I could make it). It's located on YouSendIt, here, as a ZIP containing the source code, the Makefile, a Linux executable, and a texture - about 700k, apologies for it being so big, the texture didn't compress like I hoped it would.

If anyone has the chance to look through the code and identify where I am going wrong, they would be a lifesaver! You'll have to excuse any messy code,... and not mock me too much for making obvious mistakes :) The loader code is more or less NeHe's, modified slightly to mip map them, load more than one at a time, and to anchor the texture to the object (as per my lecturers advice). The drawing goes on in drawTest().

Cheers,
Tom

##### Share on other sites
For now I don't know why you would want to generate tex coords when you are supplying them yourself so delete this

  // Texturing Contour Anchored To The Object        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);        // Texturing Contour Anchored To The Object        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);           glEnable(GL_TEXTURE_GEN_S);			// Auto Texture Generation        glEnable(GL_TEXTURE_GEN_T);			// Auto Texture Generati

##### Share on other sites
Well, that is a heck of a lot closer to what I was after! Sometimes takes another pair of eyes to spot the obvious, I thought I'd tried removing those lines but obviously not. Thanks so much for taking a look.

Only problem now is getting textures on the cones and cylinders in the actual project, but I'm sure I'll figure that out :)

Thanks a lot,
Tom

##### Share on other sites
Quote:
 Original post by authortitleWell, that is a heck of a lot closer to what I was after! Sometimes takes another pair of eyes to spot the obvious, I thought I'd tried removing those lines but obviously not. Thanks so much for taking a look.Only problem now is getting textures on the cones and cylinders in the actual project, but I'm sure I'll figure that out :)Thanks a lot,Tom

Just use the glu Objects and enable texturing on them. Then you won't have to texture them youself its done automatically for you. :)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 28
• 15
• 39
• ### Forum Statistics

• Total Topics
634837
• Total Posts
3019545
×