PDA

View Full Version : OpenGl multi texturing with C#, Part II



Jakeop132
01-15-2011, 10:50 PM
If you are trying to use multitexcoord in c#, you first have to get an address pointer to that function. This forum taught me how to do that in "OpenGl multi texturing with C#", and I'm grateful for that.

But now I'm trying to actually use multitexcoord, and I'm having trouble despite reading several tutorials.

Here's my code to prepare a texture for multitexturing:

GL.ActiveTexture(TexID.Tex0);
GL.BindTexture(TexMode.Tex2D, TexID.Tex0);
GL.Enable(GLFeature.Tex2D);

(I set TexID.Tex0 = 0x84C0; and I set TexMode.Tex2D = 0x0DE1)

I later call multitexcoord using:

GL.MultiTexCoord(TexID.Tex0, x, y);

Which is in a loop just before my call to GL.Vertex.

The result is good: a texture is added to my quads just as expected. But here's where the problem comes in. Suppose instead I try to activate another texture just after my activation of Tex0 using the following:

GL.ActiveTexture(TexID.Tex0);
GL.BindTexture(TexMode.Tex2D, TexID.Tex0);
GL.Enable(GLFeature.Tex2D);

GL.ActiveTexture(TexID.Tex1);
GL.BindTexture(TexMode.Tex2D, TexID.Tex1);
GL.Enable(GLFeature.Tex2D);

But then when I call GL.MultiTexCoord(TexID.Tex0, x, y);, the texture that gets rendered is different than it was when I merely activate Tex0! But the code I added has nothing to do with Tex0. It has to do with Tex1. I'm not trying to combine multiple textures yet. I only call multitexcoord one time and pass it Tex0. Why should activating Tex0 make a difference?

If someone knows a link to a sample program that implements multitexturing in c#, that might be the easiest solution. I didn't see any such examples in OpenTK.

Alfonse Reinheart
01-15-2011, 11:04 PM
I'm not trying to combine multiple textures yet.

Well, you enabled a second texture unit. You bound a texture to it. So you told OpenGL that you are using it; it's only doing what you told it to do.

There is always a texture coordinate for a texture unit, whether you set it with glMultiTexCoord or not. There is always texture environment state set for a texture unit. So the only way OpenGL knows that you are serious about using a texture unit or not is to see if it is enabled.

So don't enable texture units that you do not intend to use.

Dan Bartlett
01-16-2011, 03:46 AM
You're using the wrong value in the second parameter of glBindTexture. It is meant to be the texture id (which was generated using glGenTextures)

V-man
01-16-2011, 07:42 AM
Multitexture with GL 1.5 requires that you setup the GPU with glTexEnv calls.
Here are several examples :
http://www.opengl.org/wiki/Texture_Combiners

No, they are not in c#

I should also state that you should call glGetError() to check for errors.
http://www.opengl.org/wiki/GL_error_codes

Jakeop132
01-16-2011, 07:55 PM
Awwwwwww. You're right, OpenGlPro. I had completely convinced myself that things weren't working, so I didn't even move on to try combining the two textures with two multitex calls. (Well, I did try that but something else wasn't working at the time.) But I just tested it with the second multitex call, and it appears to mix the textures together! I'm embarrassed to have got stuck at this point. But I'm so grateful for your helpful insight. Very grateful.

Good work.

(The other two comments were helpful, too, because of their references.)