Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: opengl es texture combine interpolate - iphone

  1. #1
    Junior Member Newbie
    Join Date
    May 2010
    Posts
    9

    opengl es texture combine interpolate - iphone

    Hi everyone:

    I am new to OpenGL, and hope you guys can help me.

    In my app, I have two textures. I would like to use the opengl texture combine mode to do a a linear interpolation of the two texture and display the resulted texture. So in the displayed texture, the pixel value will be the linear combination of the values of the same pixel from my original two textures,. I used the following code, but looks like the first texture is OK, but the second is totally white. So the results is a "whited" texture1. Why?

    Please help me..



    void generateTexture(int id)
    {
    int width = 128;
    int height = 128;
    unsigned char* data = ...

    glBindTexture(GL_TEXTURE_2D, id);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }


    int main_function()
    {
    ...
    GLuint tex[2];
    glGenTextures(2, tex);

    generateTexture(1);
    generateTexture(2);
    GLint iUnits;

    glBindTexture(GL_TEXTURE_2D, 1);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE1);

    glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
    //------------------------
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); //Interpolate ALPHA with ALPHA
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
    //------------------------
    t = 0.5;
    float mycolor[4];
    mycolor[0]=mycolor[1]=mycolor[2]=t; //RGB doesn't matter since we are not using it
    mycolor[3]=t; //Set the blend factor with this
    glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mycolor);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,891

    Re: opengl es texture combine interpolate - iphone

    I don't work on GL-ES, has been a coons age since I used reg/tex combiners, and I'm no guru on them, but a few thoughts...

    Does your hardware support texture combine crossbar (ARB_texture_env_crossbar, or OES_texture_env_crossbar)? You're assuming it does.

    I don't see you binding two textures when setting up combine, yet you're trying to read 2. I don't see any glActiveTexture(GL_TEXTUREn)/enable texunit n calls before the binds.

    And shouldn't your OPERAND2 be SRC_ALPHA, not SRC_COLOR?

    P.S. Is that you, J.R.?

    Also check this for some examples:

    * http://www.opengl.org/wiki/Texture_Combiners

  3. #3
    Junior Member Newbie
    Join Date
    May 2010
    Posts
    9

    Re: opengl es texture combine interpolate - iphone

    Hi Dark Photon:

    Thank you very much for you reply. I have a few questions:

    1. How do you know if the hardware support texture combine crossbar?
    2. What is the difference of "SRC_ALPHA" and 'SRC_COLOR" in the context?

    Thank you again.

  4. #4
    Member Regular Contributor CrazyButcher's Avatar
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    402

    Re: opengl es texture combine interpolate - iphone

    have a look at the extension
    http://www.opengl.org/registry/specs...nv_combine.txt

    SRC_ALPHA is the alpha value of the operand and SRC_COLOR is the RGB value. In the "alpha combiner" you can only use ALPHA sources whilst in the color combiner stage you can use both, and alpha will be treated as grey-scale value.

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,891

    Re: opengl es texture combine interpolate - iphone

    Quote Originally Posted by fineman
    1. How do you know if the hardware support texture combine crossbar?
    Check the extension list. glGetStringi( GL_EXTENSIONS, i ) or glGetString( GL_EXTENSIONS ), depending on what GL-ES supports.

    CrazyButcher got your other question, better than I could.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •