PDA

View Full Version : Quadrics interfering with textures



Noah
08-27-2000, 03:04 PM
I built a simple 3D modeler to build model files that I can use in my OpenGL apps. To test it out, I made a simple 4 Point Square using

glBegin(GL_QUADS)
Vertexes, texXoords, etc..
glEnd

When I add a texturemap to it, it works just fine. But when I add a sphere or disk to the scene and texturemap it, the square's texture gets distorted. It only happens with spheres and Disks, and only when I texture map them.

I am texturemapping the Spheres/Disks with
glBindTexture( My_Texture )
gluQuadricTexture(MyQuad, True)

Changing the draw order of the two shapes has no effect, can anybody help me?

An image of the correct-looking texture is here:
http://www.angelfire.com/md/torasque/ogl1.JPG

an image of the screwed up texture is here:
http://www.angelfire.com/md/torasque/ogl2.JPG

[This message has been edited by Noah (edited 08-29-2000).]

Nobody
08-27-2000, 06:26 PM
That's the way it works!
Try this... take a sheet of paper and wrap it around ball. Notice how it doesn't wrap smoothly. That's the same problem that OpenGl is having texturing a square texture map onto a none flat object.

The are two possible solutions. One is to modify the texture so that it looks warped when applied to a flat object, but correct when applied to a sphere. The other is to figure out enough points on the texture to cooridinate with the map so that when applied it is stretched and compressed to fit right. But i'd go with the first option, it's actually easier than figuring out the math.

When you appy a square texture to a sphere, the exact center part of the texture will map correctly, as you move up or down, you have less area of sphere compared to texture, so you must adjust your texture to compensate.

Hope this helps.
Nobody

Noah
08-28-2000, 12:46 PM
Originally posted by Nobody:
That's the way it works!
Try this... take a sheet of paper and wrap it around ball. Notice how it doesn't wrap smoothly. That's the same problem that OpenGl is having texturing a square texture map onto a none flat object.
Nobody

No no no, you misunderstand me...The sphere's texture is interfering with the texture of a DIFERENT object. The OTHER object's texture looks fine UNTIL I texture map a sphere, and THEN, the OTHER OBJECTS's (Not the sphere's) texture becomes messed up.

Morgan
08-28-2000, 05:33 PM
I've never had to call glQuadricTexture(), try not using it.

Morgan

Noah
08-29-2000, 12:42 PM
Errr... so how do you texturemap quadric objects? They ignore glBindTexture unless you call gluQuadricTetxure with the number of the quadric objectt and the state of the texture (true/false).

Morgan
08-29-2000, 06:07 PM
Err... A call like the following works fine for me:

glBindTexture( GL_TEXTURE_2D, gTexture );
gluSphere( gQuadratic, 100, 15, 15 );

How are you building your quadratic?

Morgan

Noah
08-30-2000, 12:34 PM
Originally posted by Morgan:

How are you building your quadratic?

Morgan[/B]

Like this: (Written in BASIC but i'm sure you can figure it out)

If Quad = 0 then
Quad = gluNewQuadric()
End if

If Solid then
gluQuadricDrawStyle(Quad, GLU_FILL)
else
gluQuadricDrawStyle(Quad, GLU_LINE)
End if

glBindTexture( GL_TEXTURE_2D, MyTexture )
gluSphere(Quad, Radius, Slices, Stacks)

And I just tried it, the sphere is _not_ texture mapped unless i call
gluQuadricTexture(Quad, True)
end when I do that, the other shape's texture gets messed up.

Morgan
08-31-2000, 04:30 AM
Oops, I looked over some of my code a little more carefully and discovered that I do infact call gluQuadricTexture(), so that's not the problem. Does it make any difference in your program whether you render the cube first or last?

Morgan

Noah
08-31-2000, 12:55 PM
That's the wierd part, draw or creation order does not matter. Also, no matter how many spheres there are, it only screws up the first square, not any subsequent ones. I'm using a 3rd party plugin for my Basic compiler (REALbasic) that allows me to access the OGL libraries. I'll contact the author to see if he's doing something wierd.

[This message has been edited by Noah (edited 08-31-2000).]

Noah
08-31-2000, 01:09 PM
ARRRG! Im such an idiot!

I was accidentally rendering the cube with:

vertex
texcoord
vertex
texcoord
etc...

instead of

texcoord
vertex
texcoord
vertex
etc...

Thanks for your help though http://www.opengl.org/discussion_boards/ubb/smile.gif

Morgan
09-01-2000, 02:45 AM
Atleast you found the solution http://www.opengl.org/discussion_boards/ubb/smile.gif

Morgan