Results 1 to 7 of 7

Thread: OpenGL translation of a software pixel pipeline

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    3

    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:
    http://pastebin.com/jTHZ1a51

    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

    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.

  2. #2
    Member Contributor
    Join Date
    Jan 2010
    Posts
    82

    Re: OpenGL translation of a software pixel pipeline

    Here's something simple:
    //sets current fragment to texture1
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture1);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


    //multiples texture1 with texture2
    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture2);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    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.

  3. #3
    Senior Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    346

    Re: OpenGL translation of a software pixel pipeline

    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).

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    3

    Re: OpenGL translation of a software pixel pipeline

    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?
    thanks.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: OpenGL translation of a software pixel pipeline

    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).

  6. #6
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: OpenGL translation of a software pixel pipeline

    Quote Originally Posted by remdul
    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.
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    3

    Re: OpenGL translation of a software pixel pipeline

    thank you all for your suggestions.
    I'm trying to translate that texture combiner to GLSL; up to now, I got this:
    http://pastebin.com/jTHZ1a51
    translated into this:
    http://pastebin.com/RCySvMDL

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

    thanks

Similar Threads

  1. Working with Programmable Pipeline on Previous Fixed Pipeline Code
    By sinaxp19 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-03-2015, 12:15 AM
  2. Programmability in the Pixel Transfer Pipeline?
    By outofsync in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-29-2010, 04:07 AM
  3. The meaning of the 0.375 pixel translation
    By rombust in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-18-2008, 01:08 AM
  4. Texture Splatting: Fixed pipeline VS Pixel Shaders
    By unreal in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-15-2005, 06:08 AM
  5. Software Rendering Engines & Pixel and Vertex shaders
    By Halcyon in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-14-2002, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean