glActiveTexture and glUseProgramObject


    Sep 16 2007 | 7:57 pm
    hello.
    i'm trying to get my lua, shader and gl chops up to snuff.
    there's some great example shaders in the apple developer examples folder.
    a couple that i've tried to implement require the use of the gl commands glActiveTexture and glUseProgramARB.
    below is a snippet of the code i'm trying to implement (a fur shader example):
    glColor3f(0.9, 0.65, 0.4);
    glEnable(GL_COLOR_MATERIAL);
    glCallList(objectList);
    glUseProgramObjectARB(program_object);
    glColor3f(1.0, 1.0, 1.0);
    glDisable(GL_COLOR_MATERIAL);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, noiseTexture);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, colorTexture);
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_CULL_FACE);
    for (i = 1; i < 10; i++)
    {
    //set shader param
    glCallList(objectList);
    }
    glUseProgramObjectARB(NULL);
    by my best translation, is is drawing the object once with a flat color, then enabling the shader program, and drawing it 10 more times, changing a parameter to the shader each time.
    my first guess was lua, but it doesn't quite cut it:
    a snippet of the last attempt.
    two gl.texture objects are sent into this:
    fur = jit.new("jit.gl.shader", this.drawto)
    fur.file = "fur.jxs"
    fur.automatic = 0
    fur.name = "fur_shader"
    function noiseTex(texture, name)
    noiseTexName = name
    end
    function colorTex(texture, name)
    colorTexName = name
    end
    function draw()
    gl.Color(0.9, 0.65, 0.4);
    gl.Enable('COLOR_MATERIAL');
    drawObject()
    gl.Color(1.0, 1.0, 1.0);
    gl.Disable('COLOR_MATERIAL');
    gl.Enable('BLEND');
    gl.BlendFunc ('SRC_ALPHA', 'ONE_MINUS_SRC_ALPHA');
    local textures = { noiseTexName, colorTexName }
    fur.texture = textures
    gl.Enable('CULL_FACE');
    for i=1, 10 do
    -- set shader param
    fur:draw()
    drawObject()
    end
    end
    -----------------------------
    my only thought at this point is that i can possibly use the shader message to my gl objects to mimic the functionality of glUseProgramObjectARB, is it possible to turn a shader on and off in one render::draw command?
    what about the glActiveTexture? i'm not even sure what this does for this particular example, so it's hard to find a suitable replacement. i'm pretty sure gl.texture handles this stuff, but how would i make one texture object active over the other?
    well, i'm not expecting much, but any ideas would be appreciated.
    shader is attached in case anyone cares to take a peak.
    thanks.
    -rob

    • Sep 16 2007 | 10:18 pm
      To use a shader with geometry in Lua, you do the following:
      shader:bind()
      drawobject()
      shader:unbind()
      This is equivalent to
      glUseProgramARB(myProgram)
      drawobject()
      glUseProgramARB(NULL)
      To use multiple textures (equivalent of active texture/bind texture stuff) do
      jit.gl.bindtexture(tex1.name, 0)
      jit.gl.bindtexture(tex2.name, 1)
      drawobject()
      jit.gl.unbindtexture(tex1.name, 1)
      jit.gl.unbindtexture(tex2.name, 0)
      wes
    • Sep 16 2007 | 10:19 pm
      I messed up the names in the unbindtexture part (they're reversed) but
      you get the point.
      wes
    • Sep 16 2007 | 11:12 pm
      indeed i do.
      many thanks.
      one last quick question.
      3D textues, possible with jit.gl.texture?
      the doc says it can take a matrix with less than 3 dimensions, but it defaults to 3 dimensions correct?
      it appears if i try to send a jit.gl.texture a 3d matrix, it doesn't work. i guess it's not supposed to.
    • Sep 16 2007 | 11:58 pm
      I haven't tried in a while, but I believe I did get it to work once.
      Try setting @rectangle 0.
      wes
      On 9/16/07, Robert Ramirez wrote:
      >
      > indeed i do.
      > many thanks.
      >
      > one last quick question.
      >
      > 3D textues, possible with jit.gl.texture?
      > the doc says it can take a matrix with less than 3 dimensions, but it defaults to 3 dimensions correct?
      >
      > it appears if i try to send a jit.gl.texture a 3d matrix, it doesn't work. i guess it's not supposed to.
      >
    • Sep 17 2007 | 4:25 am
      well, i gave it the community college try, but no worky.
      maybe you (anyone) can sprinkle some pixy dust on it
      just bang one of the bfg's and turn on the metro.
      shader attached.
    • Sep 17 2007 | 12:11 pm
      It seems that it worked after jit.normalizing jit.bfg output(patch
      below), but I'm not totally sure how it should look in the end.
      It looked like this on my computer:
      -nesa
    • Sep 17 2007 | 3:05 pm
      On Sep 17, 2007, at 2:11 PM, nesa wrote:
      > It seems that it worked after jit.normalizing jit.bfg output(patch
      > below), but I'm not totally sure how it should look in the end.
      Hey, that's not the only thing you did!
      You also skipped the slab and applied the shader directly to the
      gridshape. And you didn't check the shader.
      Guilty as charged,
      nesa
    • Sep 17 2007 | 8:16 pm
      however! you still made it work better than it did, so thanks for that.
      i think it's close.
      if you have the apple developer package installed, compile the example/cocoa/glsl showcase xcode proj and check out the erode shader. that's what it's supposed to look like.
    • Sep 17 2007 | 8:35 pm
      I think you're making this more complex than it needs to be. To get
      this to work, you only need jit.gl.shader and jit.gl.texture and some
      geometry to draw using the shader. Here's how I would do it:
      1) Make a 3D texture test with jit.gl.texture @rectangle 0 and sending
      it a simple test 3D matrix like a gradient volume. Then use a super
      simple shader to test the values and compare to the gradient to see if
      you're accessing the texture properly.
      2) Next, incorporate the erode shader based on experience in step 1.
      wes
      On 9/17/07, Robert Ramirez wrote:
      >
      > however! you still made it work better than it did, so thanks for that.
      > i think it's close.
      >
      > if you have the apple developer package installed, compile the example/cocoa/glsl showcase xcode proj and check out the erode shader. that's what it's supposed to look like.
      >