Sign in to follow this  
Vindicator

OpenGL Making textures on a sphere look nice?

Recommended Posts

One thing which I noticed about textures in OpenGL when I got a 128x128 sized image of earth's surface and tried to put it on a sphere/ball, is that it looks very weird. =/ Instead of just a single planet with a stretched texture on (and north pole at the top + south pole at the bottom), like I want, I get two planet surfaces (one for the top half of the sphere, and one for the bottom half of it). So I just thought I´d ask if anyone has any advice on how you can do to just put one texture around the entire sphere? :) I suppose it´s not very hard, but I have just started learning OpenGL, so that´s why I don´t know how to do.

Share this post


Link to post
Share on other sites
just set your texture coordinates correctly. 0-1 for north to southpole, and 0-1 around the circumference of the sphere. also make sure to set your texture flags correctly.

Share this post


Link to post
Share on other sites
I´m not sure that I understood your replies correctly.. but my sphere is a glutSolidSphere, not a polygon like the one in the link you posted above, WanMaster.

Does this mean that I can´t use "glutSolidSphere(1.0, 10, 10);" to create it? Because just writing

glTexCoord2f(1,0);
glTexCoord2f(-1,0);
glTexCoord2f(0,1);
glTexCoord2f(0,-1);
after the line
glBindTexture(GL_TEXTURE_2D, texture_id[tex]

doesn´t make any difference at all. Or did I misunderstand how to use the texture coordinates completely?

(sorry if those are stupid questions, btw, but I´m just not used to OpenGL yet =/ )

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The problem is your texture size. For spheres you must have the width be two times the height.

Think about it: What's the distance from north to south pole? Now, what's the distance around the equator?

The distance around the equator is twice the distance between the poles.

What OpenGL is doing is tiling the texture rather than stretching it out horizontaly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your texture file (and therefore the surface) should be 256x128 in your case rather than 128x128

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Your texture file (and therefore the surface) should be 256x128 in your case rather than 128x128


OpenGL texture coordinates always run from 0-1 along all axes regardless of the actual texture size, so it's irrelevant how big the texture really is (okay, except for the NV_texture_rectangle extension, but I doubt that's what's going on).

I'm not sure how you're getting texture coordinates at all using glutSolidSphere unless you use automatic generation of some kind with glTexGen. My best guess is that you're using the GL_OBJECT_LINEAR mode of glTexGen, which would explain why you get the texture repeated. Unfortunately there's nothing you can do about this. GL_SPHERE_MAP is meant for something quite different (that's a sphere reflection map) and GL_EYE_LINEAR is no good, so if you want to do this you're going to have to generate the sphere yourself, with texture coordinates.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this