Multitexturing in openGL without shaders
I'm using multitexturing in openGL without shaders. Basically I'm using calls
to glActiveTexture. I got the two textures to blend via interpolation. The problem is the that the second texture doesn't rotate with the first one. For example if I were to have two textures, one of the earth and the other of the moon and I placed them on a sphere, the earth texture would rotate when I rotate the sphere (by rotate I mean glRotate), but the moon texture stays stationary. I can't put my finger on it, perhaps I'm setting up the second texture unit wrong? Do I need to rotate the second texture using glRotate on the Texture Matrix?
Thanks,
Bolt
[Edited by - Boltimus on June 5, 2009 1:42:34 PM]
Check the texcoords for both textures.
What exatly are you rotating ??
the sphere ? the view ? the texture coordinates of either texture ?
The approach to maintain is to attach (multiple) texcoords to every vertex.
Translating/rotating the vertices should not affect the texture coordinates.
(as the texture maintains its composition on the model)
so no, you should not be rotating texture coordinates (basically)
post some code on how you set up multitexture and your render calls
What exatly are you rotating ??
the sphere ? the view ? the texture coordinates of either texture ?
The approach to maintain is to attach (multiple) texcoords to every vertex.
Translating/rotating the vertices should not affect the texture coordinates.
(as the texture maintains its composition on the model)
so no, you should not be rotating texture coordinates (basically)
post some code on how you set up multitexture and your render calls
I'm having a hard time visualizing it. Can you post code and/or screenshots?
Textures generally should not "rotate". You supply texture coordinates when sending the vertex data (for instance in immediate mode call glMultiTexCoord for each texture unit that you activated, per vertex), the vertex will be modified by ModelView but that has no bearing on the texture coordinates.
Textures generally should not "rotate". You supply texture coordinates when sending the vertex data (for instance in immediate mode call glMultiTexCoord for each texture unit that you activated, per vertex), the vertex will be modified by ModelView but that has no bearing on the texture coordinates.
Thanks for your responses, your questions help me fill in the blanks here ...
I'm rotating the view around the sphere. So as you move the ouse left or right the "globe" rotates about its own axis. Like spinning a globe.
Here is some sketch code ...
Just an FYI, I'm using JOGL, which is the reason why you're seeing the gl.xxxx and GL.xxxx other than that, its the same as openGL.
Quote:
What exatly are you rotating ??
the sphere ? the view ? the texture coordinates of either texture ?
I'm rotating the view around the sphere. So as you move the ouse left or right the "globe" rotates about its own axis. Like spinning a globe.
Here is some sketch code ...
gl.glActiveTexture(GL.GL_TEXTURE0);gl.glEnable(GL.GL_TEXTURE_2D);gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_SPHERE_MAP);gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_SPHERE_MAP);gl.glBindTexture(GL.GL_TEXTURE_2D, (int) result.texture.getID());gl.glActiveTexture(GL.GL_TEXTURE1);gl.glEnable(GL.GL_TEXTURE_2D);gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_SPHERE_MAP);gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_SPHERE_MAP);gl.glEnable(GL.GL_TEXTURE_GEN_S);gl.glEnable(GL.GL_TEXTURE_GEN_T);gl.glBindTexture(GL.GL_TEXTURE_2D,(Integer) result.texture.getID());gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_COMBINE);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_COMBINE_RGB, GL.GL_INTERPOLATE);gl.glTexEnvfv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_COLOR, new float[]{0.0f, 0.0f, 0.0f, 0.5f}, 0);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_SOURCE0_RGB, GL.GL_PREVIOUS);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_SOURCE1_RGB, GL.GL_TEXTURE);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_OPERAND0_RGB, GL.GL_SRC_COLOR);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_OPERAND1_RGB, GL.GL_SRC_COLOR);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_SOURCE2_RGB, GL.GL_CONSTANT);gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_OPERAND2_RGB, GL.GL_SRC_ALPHA);
Just an FYI, I'm using JOGL, which is the reason why you're seeing the gl.xxxx and GL.xxxx other than that, its the same as openGL.
Okay, I admit I haven't played with spherical texture mapping or multitexturing before, but I think I figured this out.
Generated spherical coordinates are apparently fixed in eye space, so they won't move when you rotate the camera. The reason they still move on texture unit 0 is because you did not call gl.glEnable(); with the texture generation commands for it, so instead of generating texture coordinates on the fly it's using coordinates that you supplied yourself as part of the draw call (you did send some, didn't you?). They are probably on a per-texture-unit basis.
Bottom line is, if you want to use GL_SPHERE_MAP to generate texture coordinates for spheres, you need to enable texture coordinate generation for each separate texture unit as well as transform the texture matrix from eye space back into world space. If I'm horribly wrong, surely someone will be along to correct me. :)
Generated spherical coordinates are apparently fixed in eye space, so they won't move when you rotate the camera. The reason they still move on texture unit 0 is because you did not call gl.glEnable(); with the texture generation commands for it, so instead of generating texture coordinates on the fly it's using coordinates that you supplied yourself as part of the draw call (you did send some, didn't you?). They are probably on a per-texture-unit basis.
Bottom line is, if you want to use GL_SPHERE_MAP to generate texture coordinates for spheres, you need to enable texture coordinate generation for each separate texture unit as well as transform the texture matrix from eye space back into world space. If I'm horribly wrong, surely someone will be along to correct me. :)
GL_SPHERE_MAP is not for texturing spheres. It is used to give a shiny appearance to objects, any objects, including spheres.
http://www.opengl.org/wiki/Texturing_a_Sphere
http://www.opengl.org/wiki/Texturing_a_Sphere
Thx for the replies. V-man, I used GLU to create the texture coordinates originally for texture0, but to no avail. How would I use this with multitexturing?
gluSphere just generate 1 pair of texcoords. If you want another, you write your own sphere code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement