Sign in to follow this  
Ahl

Still having trouble wrapping a single texture around a sphere.

Recommended Posts

Ahl    170
The title says it all. I asked about this problem a few weeks ago. Since then I've made some progress but have not solved it entirely. This is what it was doing originally: http://i298.photobucket.com/albums/mm265/ahlywog/badtextures.png Now this is what it's doing: http://i298.photobucket.com/albums/mm265/ahlywog/bettertextures.png This is the code im using to create the texture:
texturefile = os.path.join('data', my_image)
textureSurface = image.load(texturefile)
t1=textureSurface.image_data.create_texture(image.Texture)
                
glBindTexture(GL_TEXTURE_2D, t1.id)
# glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, t1.width, t1.height, 0, GL_RGB, GL_UNSIGNED_BYTE, rawimage)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)
glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP)
glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP)
glTexGenf(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP)
Keep in mind that this is all Python using the Pyglet API. You will notice that glTexImage2D is commented out. For some reason I cannot get it to work. It wont take the last arguement. I think Pyglet uses some form of internal image handling that I haven't figured out yet. Anyways that creates the texture. I bind the texture to the model when I load it into the display list:
glDisable(GL_TEXTURE_2D)
loaded_object = glGenLists(1)
glNewList(loaded_object, GL_COMPILE)
if image != 0:
     glEnable(GL_TEXTURE_2D)
     glBindTexture(GL_TEXTURE_2D, image.id)
     glBegin(GL_TRIANGLES)
     filepointer = file(filename)
     for line in filepointer.readlines():
          coords = [str(x) for x in line.strip().split(' ')]
          newcoord = []
          for coord in coords:
               newcoord.append(coord.strip('(),'))
               if len(newcoord) == 4:
                    if newcoord[0] == 'NORMAL':
                         glNormal3f(float(newcoord[1]), float(newcoord[2]), float(newcoord[3]))
                         glTexCoord3f(float(newcoord[1]), float(newcoord[2]), float(newcoord[3]))
                     else:
                         glVertex3f(float(newcoord[1]), float(newcoord[2]), float(newcoord[3]))
                     newcoord = []
                

                glEnd()
                glEndList()
Essentially all this section does is binds the texture then calls a file where I have my sphere mapped out. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
sprite_hound    461
With a 2d texture, I'm not sure you want to do anything with the r coordinates.

Also, GL_NORMAL_MAP isn't a valid parameter to glTexGen AFAIK. I'd have thought you'd want GL_SPHERE_MAP instead.

Share this post


Link to post
Share on other sites
Ahl    170
Alright tried switching it too GL_SPHERE_MAP and that wraps the texture around the entire sphere. But now the texture twists and distorts as it moves around the field of view. Also it doesnt rotate as you rotate the object its bound too.

Share this post


Link to post
Share on other sites
V-man    813
GL_SPHERE_MAP is for doing a reflection kind of effect using a 2D texture.
GL_NORMAL_MAP, you would use this along with a CUBEMAP.
For just standard texturing, you should generate the texcoordinates yourself or find some code (class Sphere)
If you want, look at my glhlibrary
which has glhCreateSpheref2() and glhDeleteSpheref2()

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