We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › problem with texture mapping in opengl
Page Index Toggle Pages: 1
problem with texture mapping in opengl (Read 615 times)
problem with texture mapping in opengl
Aug 30th, 2008, 6:14pm
 
hi. i was making some experiments with texture mapping, trying to apply a texture to a sphere.

i'm creating my own sphere, but as soon as i bind the texture about half of my sphere disappears.

the texture coordinates are being determined by the variables 'v' and 'u' and these are ranging from 0 to 1 as expected

i've made a simple applet to show what is happening: http://www.rui-m.com/p5/texmapping_test/

pressing 't' will bind/unbind the texture, and pressing 'p' will render the sphere using points or triangle strips (just because its easier to see whats happening to the sphere using points).

does anyone know whats happening?
i've never done any texture mapping or used textures that much, its probably some noob mistake Smiley

thanks
Re: problem with texture mapping in opengl
Reply #1 - Sep 1st, 2008, 12:44am
 
well.. i just found out something strange...
i'm using the variables 'u' and 'v' to define the texture coordinates in the gl.glTexCoord2f function. if i divide these values by 1.6 it kinda works. i'm not sure if it is precise, but the texture now fully wraps the sphere.

printing the 'u' and 'v' variables to the console they range from 0 to 0.625. so i have no idea why this seems to work. aren't the texture coordinates supposed to range between 0 and 1?
if i dont divide the values they do range between 0 and 1 but the texture only wraps around about half of the sphere as you can see in the example. does any one know whats happening??
thanks
Re: problem with texture mapping in opengl
Reply #2 - Sep 1st, 2008, 11:24am
 
textures in openGl are only generally available in sizes that are powers of two, ie 512x512, 1024x1024, 2048x2048 etc.

your image is 1350x675. i would guess that 1350 is .625 of 2048 - the next power of two up.

(.66, close enough)

try resizing the image to 1024x1024 (the stretching doesn't matter) and see if it changes.
Re: problem with texture mapping in opengl
Reply #3 - Sep 1st, 2008, 1:52pm
 
so as expected... it was a noob mistake!!

but now it works. thanks a lot!!! it was driving me nuts Smiley
Re: problem with texture mapping in opengl
Reply #4 - Sep 1st, 2008, 1:52pm
 
right, this is happening because you're using glTexCoord2f instead of the texture() and vertex() commands built into processing, which hide those details.
Re: problem with texture mapping in opengl
Reply #5 - Sep 1st, 2008, 6:47pm
 
pelintra wrote on Sep 1st, 2008, 1:52pm:
but now it works. thanks a lot!!


cool. was a lucky guess 8)
Page Index Toggle Pages: 1