OpenGL translation of a software pixel pipeline

Hi all,
I’m new to this forum (and to opengl in general).
I need a hand with translating portions of a software rasterizer to opengl.
Up to now I made some progress, but I’m not skilled enough to front some of the advanced techniques, like correctly combining textures and other things.

My first question is about combining two textures in opengl.
I’m using glActiveTextureARB extension.

few definitions first:
cother - contains rgba values of texture1 texel
clocal - contains rgba values of texture0 texel
tc_ prefix applies to R,G and B channels.
tca_ prefix applies to A channel.
the possible path that the pipeline can take is determined by few selectors, named TEXMODE_*

Here’s the code that combines the texels of the two textures:

this is basically what it should do.
to sum it up, it calculates

  • the color tr,tg,tb,ta, starting from simple operations on texture1 texel (cother), texture0 texel (clocal) or constant color/alpha (zero)
  • the color blendr/g/b/a from simple operations on texture1 texel (cother), texture0 texel (clocal) , constant color/alpha (zero), constant value for rgba (lod/detail stuff)
  • does an average of the above two resulting color
  • optionally adds clocal color or alpha to the result
  • optionally inverts final color

I guess (hope) it’s just a matter of correctly setting glTexEnv, without the need of using shaders or other recent technologies; the purpose it’s not to perfectly translate everything, it’s just to make it work :slight_smile:

I’m looking at some sample code on multitexturing, like this, and I’m reading the online opengl documentation, but I find hard to understand how glTexEnv parameters and operands work.

Thanks in advance for any help.

Here’s something simple:

//sets current fragment to texture1
glBindTexture(GL_TEXTURE_2D, texture1);

//multiples texture1 with texture2
glBindTexture(GL_TEXTURE_2D, texture2);

You can give different or same texcoords per texture unit by using glMultiTexCoord instead of glTexCoord which I think only work on GL_TEXTURE0 (texture unit). So you should set up your texcoords even if they are the same with glMultiTexCoord if you want to do multitexturing. I use shaders which are much more easier to deal with and if you have time might want to study them.

Depending on how much you want invest in learning OpenGL, you may want to use shaders (GLSL) from the start. Texture environment, register combiners etc. are very outdated, inflexible and IMO more complex than just getting GLSL working. Even if you want to do simple rendering, GLSL can be very ‘direct’ and convenient as you don’t have to keep track of many GL states.

If GLSL is not an option and texture environment alone is too limited, another method is multi-pass rendering, where you draw the geometry several times with different textures and blend modes. Tip to get you started: glDepthFunc(GL_EQUAL).

Thank you both for your answers.
It looks like the better option is to use shaders; unfortunately I’ve limited knowledge of how to use them, but I’d like to learn.
Could you point me to a very very simple code, as portable as possible (ARB?), without third party libs, that loads and uses basic shaders?

Could you point me to a very very simple code, as portable as possible (ARB?), without third party libs, that loads and uses basic shaders?

There are the tutorials in my signature. They do use “third party libs,” but those libraries are included with the distribution, and are for dealing with issues outside of OpenGL (creating the GL window, image loading, math, etc).

I’ll second this and add that you might find that a lot of per-pixel tricks that are possible in a pure software renderer are just not possible in hardware without either (a) performance-killing stuff like heavy tesselation, multiple texture updates per frame and/or framebuffer readbacks; or (b) using shaders.

thank you all for your suggestions.
I’m trying to translate that texture combiner to GLSL; up to now, I got this:
translated into this:

lod-based combiners are still not converted.
could you please give me some comments/critiques on this ?

thanks :slight_smile: