PDA

View Full Version : Does glTexEnvf not work accross several glDrawElements passes?



WhatEver
06-07-2002, 03:39 PM
I guess the best way to explain it would be like this. Say my video card only supports up to 2 texture units for multitexturing(exageration for simplicity), now say that my model had 4 texture layers. All 4 textures need to be combined together to make some sort of cool looking texture, but since it seems that glTexEnvf only works with the current texture units 1 and 2, I need to call glDrawElements again for the second two texture units. Only problem is, is that it doesn't work. What happens is that the second call to glDrawElements overwrites the previous two textures draw.

Am I suppose to use a glBlendFunc in this situation?

I want to deal with texture layers like this so that my algorithm won't even stutter if it detects differant max multitexture unit amounts.

Nutty
06-07-2002, 03:46 PM
Dude, thats multipass. Using two render calls on the same geometry, with differing render states is multipass, and the only way to combine the results of multiple passes is using blending.

Dont mean to offend, but I was under the impresion that you were quite advanced in OpenGL, and am surprised you're asking this. http://www.opengl.org/discussion_boards/ubb/smile.gif

Nutty

WhatEver
06-07-2002, 03:59 PM
No offense taken. I am still quite weak in a few places in OpenGL. To name them: Vertex Programs, Stencil Tests, glBlendFunc and MultiTexturing.

Other than that, I'm good to go http://www.opengl.org/discussion_boards/ubb/smile.gif.

So a multipass is when you have to actually call glDrawElements again to blend over the same geomentry, correct? This is where glBlendFunc scares me http://www.opengl.org/discussion_boards/ubb/smile.gif. Is it possible to carry accross the same blending mode from glTexEnv over to glBlendFunc?

I sound like a newb http://www.opengl.org/discussion_boards/ubb/redface.gif

If I had more time to experiment with this stuff, I'd know it by now. Once Spider3D has a solid foundation(it does now because I can export model directly from LightWave), then I can impliment all the stuff I don't know using Spider3D.

Also, I usually go looking for info before coming to places like this, so it may seem like I know more than I do simply because I only answer question I'm pretty sure I know the answers too...and that's far and few between http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by WhatEver (edited 06-07-2002).]

WhatEver
06-07-2002, 04:04 PM
Oh, you can add glTexEnv to that list of things I don't know well http://www.opengl.org/discussion_boards/ubb/smile.gif.

Nutty
06-07-2002, 04:11 PM
So a multipass is when you have to actually call glDrawElements again to blend over the same geomentry, correct?

Yep.


This is where glBlendFunc scares me

It's not that bad once you know the equation. The equation is.

(Src * SF) + (Dest * DF)

Where Src is the computed fragments of the current pass. i.e. the result of the multi-texturing, the value computed at the end of Register combiners, the value that is written into the framebuffer under non blend.

Dest is the color in the framebuffer.

SF and DF are source and destination blend factors. These are the GL_ONE, GL_ZERO, GL_SRC_ALPHA, etc etc.. things.

Theres also a blend equation extension, that allows you to use subtractive blending, and reverse the order of subtraction also.

You dont have the as much flexability with blending, as you do with RC's or even TexEnv, which can make converting heavily textured geometry difficult to split into multipass, if they all use quite complex Texture combinations. Usually they dont tho.

Nutty

WhatEver
06-07-2002, 07:41 PM
Ok, now that makes more sense.

Thx Nutty!

WhatEver
06-07-2002, 08:24 PM
I've been trying to figure this out for 4 hours now. I have my DOT3 bumpmapping working in another program of mine, but I can't get it going in a new program.

Here's what it looks like:

s3dClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Bumpmap);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, 0x8740);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

glTexCoordPointer(2, GL_FLOAT, 0, UVMaps[SurfaceCur->Layers[0].UVMapIndex].UVs);

s3dClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture);

glTexCoordPointer(2, GL_FLOAT, 0, UVMaps[SurfaceCur->Layers[0].UVMapIndex].UVs);

This code is suppose to blend GL_TEXTURE1_ARB on top of GL_TEXTURE0_ARB. If I only use GL_TEXTURE0_ARB, then I get a bumpmapped surface that is black and white only.

Any suggestion why GL_TEXTURE1_ARB isn't blending properly?

Nutty
06-08-2002, 01:58 AM
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, 0x8740);

What the hell is 0x8740?? I can't find that in gl.h or texture env combine tokens?

Change that to the correct token definition you are wanting, and see if it helps.

Nutty

Bob
06-08-2002, 03:15 AM
What the hell is 0x8740?? I can't find that in gl.h or texture env combine tokens?

Taken from latest glext.h



#ifndef GL_EXT_texture_env_dot3
#define GL_DOT3_RGB_EXT 0x8740
#define GL_DOT3_RGBA_EXT 0x8741
#endif

WhatEver
06-08-2002, 04:42 AM
I couldn't find the latest glext.h also, so I just used the hex value I got from NitroGLs code because I was avoiding defining the constant myself. Lazynes on my part.

Anyway, anyone know why the second texture unit won't blend properly?

I post some screenies in a sec.

WhatEver
06-08-2002, 04:48 AM
What you see here is suppose to show my Spider3D logo with a bump mapped surface, but instead it's black and white (http://www.spider3d.com/img/bm1.jpg)

This shows that the bump mapping is indeed working. I could only get this to work if I did not use the second texture unit. (http://www.spider3d.com/img/bm2.jpg)

[This message has been edited by WhatEver (edited 06-08-2002).]

PH
06-08-2002, 05:49 AM
To select the texture unit to bind a texture to, use glActiveTextureARB not glClientActiveTextureARB ( that's for texcoord arrays ).

This code won't bind the texture to unit 1,

s3dClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture);

try this,

s3dClientActiveTextureARB(GL_TEXTURE1_ARB);
s3dActiveTextureARB(GL_TEXTURE1_ARB); // <---
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture);

WhatEver
06-08-2002, 07:24 AM
AAAAAAAAAARRRRRRRRRRRRRRGGGGGGGGGGGGGG!!!!!!!!!!!! !!!!!

I KNEW IT WAS SOMETHING STUPID LIKE THAT!

http://www.opengl.org/discussion_boards/ubb/frown.gif

Now you know why I usually don't ask questions, because they're something stupid that I overlooked http://www.opengl.org/discussion_boards/ubb/smile.gif.

Well, then, THANK YOU http://www.opengl.org/discussion_boards/ubb/biggrin.gif I will most likely throw up the result for you guys to look at.

LOL

<-------cuts and pastes a lot http://www.opengl.org/discussion_boards/ubb/smile.gif

WhatEver
06-08-2002, 07:30 AM
WOOOOOHOOOOO!!!

It works now! Here's a pic http://www.opengl.org/discussion_boards/ubb/smile.gif...I changed the bump texture to some tiles.

The right result (http://www.spider3d.com/img/bm3.jpg)

Hey, what is s3dClientActiveTextureARB for if it doesn't make a texture unit level active?

zeckensack
06-08-2002, 10:56 AM
What's this s3d prefix anyway?

If it's anything like glClientActiveTexture, it selects the texture unit for the next call to glTexCoordPointer (for Vertex Arrays). If you want multiple sets of tex coords with vertex arrays (ie you want multitexturing), you need to select multiple pointers.

So you first call
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(duhdahdah); //texture coordinates for unit 0
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(dumdadiddy); //texture coordinates for unit 1
...

WhatEver
06-08-2002, 11:19 AM
Hmmmm, maybe they should have used a different name to avoid confusion, glClientAvtivateTextureArrayARB...LOL that's a long function name http://www.opengl.org/discussion_boards/ubb/biggrin.gif.

Someone had a problem compiling Spider3D in their program because of duplicate extension function names, so to solve that problem I decided to use the s3d prefix on my extensions.

Thanks for all the help guys. The functions used for multitexturing are making a lot more sense now.

WhatEver
06-08-2002, 02:03 PM
Here's the demo http://www.opengl.org/discussion_boards/ubb/biggrin.gif

The test.s3d model file contains everything needed for Spider3D to set up and draw a bumpmapped model without you having to set it up manually.

Bucket of Bumpmapping - 400KB (http://www.spider3d.com/dl/bucket.zip)

Screenshot (http://www.spider3d.com/img/bucket.jpg)

Thanks again for helping me. The glClient... function confused me a bit.