Jump to content
  • Advertisement
Sign in to follow this  
Ahl

Still having trouble wrapping a single texture around a sphere.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!