Blending versus glTexEnv(GL_BLEND)

Member
Posts: 321
Joined: 2004.10
Post: #1
I've been using RGBA textures with glBlendFunc(GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA) so thought I had a pretty good
handle on things.

But I've lately gotten up to Texture Functions (red book p 402-405)
and I'm having trouble incorporating this with just blending in
general.

It doesn't help that there are no code examples, except for a
mention of Nate Robbins' tutorials.

I'm particularly concerned about a mental image of how the
textures are processed. For instance, in general blending I
visualize the screen (framebuffer) being the destination.
and the incoming textures (source) are blended with the
destination according to glBlendFunc() to make a new image.

But with Texture functions the book is too vague for my taste.
In the note: on p403 it says "a subscript of t indicates a texture
value, f indicates the incoming fragment value,..." Huh? what's
this incoming fragment? What's the final entity that updated?

Hope this isn't too vague, but I've struggled with this for about a
week now. Thanks.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
A fragment is a potential pixel. If it passes window ownership/scissor/depth/stencil/alpha tests, then it will end up as a pixel in the framebuffer.

During texturing, the incoming fragment color is the base color of the primitive. Try drawing a lit, colored, smooth shaded triangle. The fragment color is found by lighting the three vertex colors and interpolating the results across the triangle for each fragment. After that, you can then apply some number of textures, which may or may not combine with the fragment color (PRIMARY_COLOR in texture_env_combine.)
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
Thanks.

I think I'm getting it now. how's this for a rough working definition:

Blending (as discussed in chapter 6) is blending of a texture onto
the framebuffer.

Texture Functions (via glTexEnv(GL_BLEND) ) is modulation, blending
etc. of the texture with the surface of the "texturing" polygon.
For instance if I had a simple rectangular texture with 4 glTexCoords()
and 4 glVertex() and say I had colored (glColor()) the GL_QUAD
say green, the the incoming fragment would be the green rectangle?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Well... blending is a fragment operation. It doesn't have anything to do with texturing. You can blend primitives that aren't textured.

Texturing is an optional rasterization operation. Rasterization happens prior to fragment processing. glTexEnv(GL_BLEND) is one possible mode during texture application-- it blends between the incoming fragment color and the environment color, based on the texture color. See table 3.23 in the spec. The resulting textured fragment is then subject to additional blending into the framebuffer, during fragment processing.

Check out the GL block diagram in the spec (figure 2.1) for the overview. There's a more detailed diagram here.
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #5
Re-reading chapter 10 really helped reinforce what you've said.

How's this?

The Texture Functions (that is glTexEnv() ) is only used during the Rasterization
phase to produce fragments. There is a blending texture function, but this
should not be confused with the blending operation itself.

The blending operation is then done afterwards during the "Testing and
Operating on Fragments" as specified by the glBlendFunc();


However, I'm still confused by some of the terminology regarding Texture
Functions

The Red Book at Note: for Table 9-4 mentions a "texture value" and an "incoming
fragment value". Whereas you mention an "incoming fragment color",
"environment color", and a "texture color".

For simplicity, lets say I've got a paisley (sp?) texture that I want to surface
over a polygon (GL_QUAD). I presume the "texture value" and the "texture
color" refers to the rgba value of the paisley.

Then what is the "incoming fragment value/color"? Would this be the color of
the polygon (GL_QUAD) say if we had put a glColor*() before each glVertex()?

Also, what is the environment color? That's a new one for me.

Thanks, and this really will do it for me.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
Your summary is correct now, although I would say "to modify fragments" instead of "to produce fragments."

My usage of "color" was a bit misleading, but you've got the idea. The Red Book usage of "value" is more correct, because a texture doesn't have to be RGB. It could be grayscale (GL_LUMINANCE) or coverage (GL_ALPHA). The most common format is probably RGB, though.

The "texture value" is the sampled value (i.e. color) of the texture. The exact way this is found depends on the texture parameters (nearest/linear sampling? mipmaps? anisotropic filtering? wrapping/clamping coordinates?) and texture type (1D, 2D, 3D, cubemap?) but ultimately it is some value based on your texture data. Like one pixel of paisley.

The "incoming value" is the result of rasterization preceding the texturing stage. This is just the base color of the polygon (glColor*), although that may be modified by lighting and smooth shading.

The "environment color" is a special constant color per texture unit. You can set it with glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &an_array_of_four_floats) and access it inside of the texture combine stage with GL_CONSTANT. The environment color can be different for each texture unit. One use of this constant is as a interpolator; you could blend between two textures with it over time by using GL_INTERPOLATE combine mode and updating the single constant to a new value each frame.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  general blending versus texture blending questions WhatMeWorry 2 5,146 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  SDL key presses versus key states WhatMeWorry 1 4,600 Oct 2, 2006 08:09 AM
Last Post: Nickolei
  Vector versus raster graphics in openGL WhatMeWorry 2 4,070 Dec 29, 2005 01:23 AM
Last Post: WhatMeWorry
  glTexEnv GL_BLEND inversing texture NitroPye 4 4,167 Jun 12, 2005 09:04 PM
Last Post: NitroPye
  Images versus textures overview.... WhatMeWorry 0 2,336 Jan 18, 2005 12:22 AM
Last Post: WhatMeWorry