2

I am new to this OpenGL ES stuff, I am trying to draw a rectangle using multi-texturing but it does not show anything I dont know what is wrong with this. Any Suggestions or ideas will be very helpful to me.

Here is my code:

What I have done is bring together some codes found on the net but not yet succeeded to get any result. I am able to draw this in two passes such as drawing two rectangles with different textures and produced the desired result.

I used some GL11 and GL10 combined may be this is a blunder. :P I dont know if it is right or not. I have done this because some of the constants are not supported using GL10.

public void draw(GL10 gl) {
    if(status_flag == DISPLAYING_EYES) {                        
        vertexPointer(gl);          

        firstGanColorVert.position(0);
        gl.glColorPointer(4, GL11.GL_FLOAT, VERTEX_SIZE, firstGanColorVert);        
        //gl.glBindTexture(GL10.GL_TEXTURE_2D, firstGaneshaTexture);            

        gl.glActiveTexture(GL11.GL_TEXTURE0);
        gl.glEnable(GL11.GL_TEXTURE_2D);
        gl.glBindTexture(GL11.GL_TEXTURE_2D, firstGaneshaTexture);
        //Simply sample the texture
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
        //------------------------
        gl.glActiveTexture(GL11.GL_TEXTURE1);
        gl.glEnable(GL11.GL_TEXTURE_2D);

        fadeAnimation();         
        secondGanColorVert.position(0);
        gl.glColorPointer(4, GL11.GL_FLOAT, VERTEX_SIZE, secondGanColorVert);        
        gl.glBindTexture(GL11.GL_TEXTURE_2D, secondGaneshaTexture);

        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_COMBINE);
        //Sample RGB, multiply by previous texunit result
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_RGB, GL11.GL_MODULATE);   //Modulate RGB with RGB
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC0_RGB, GL11.GL_PREVIOUS);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC1_RGB, GL10.GL_TEXTURE);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND0_RGB, GL11.GL_SRC_COLOR);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND1_RGB, GL11.GL_SRC_COLOR);
        //Sample ALPHA, multiply by previous texunit result
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_ALPHA, GL11.GL_MODULATE);  //Modulate ALPHA with ALPHA
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC0_ALPHA, GL11.GL_PREVIOUS);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_SRC1_ALPHA, GL11.GL_TEXTURE);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND0_ALPHA, GL11.GL_SRC_ALPHA);
        gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_OPERAND1_ALPHA, GL11.GL_SRC_ALPHA);

        gl.glMatrixMode(GL11.GL_MODELVIEW);
        gl.glLoadIdentity();            
        gl.glTranslatef(this.x,this.y ,0);          
        textCordPointer(gl);        
        gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_SHORT, indices); 
    }
}

Here is the code that works for me but I want to use multi-texturing instead of this:

firstGanColorVert.position(0);
gl.glColorPointer(4, GL10.GL_FLOAT, VERTEX_SIZE, firstGanColorVert);        
gl.glBindTexture(GL10.GL_TEXTURE_2D, firstGaneshaTexture);          

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();            
gl.glTranslatef(this.x,this.y ,0);  

textCordPointer(gl);        
gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indices);   

fadeAnimation();

secondGanColorVert.position(0);
gl.glColorPointer(4, GL10.GL_FLOAT, VERTEX_SIZE, secondGanColorVert);
gl.glBindTexture(GL10.GL_TEXTURE_2D, secondGaneshaTexture);         

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();            
gl.glTranslatef(this.x,this.y ,0);          
textCordPointer(gl);        
gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indices);
Renjith K N
  • 2,613
  • 2
  • 31
  • 53

1 Answers1

1

1) If some constants are not supported by GL10, their functionality is not supported either. Just use GL11 for the whole thing. GL11 extends GL10 anyway. GL10 will see the GL11 constants and probably end up doing nothing, or at least nothing you wanted it to do.

2) I'm not sure what fadeAnimation() does but something tells me you'd want to put that before you start doing anything with your second texture. That is, put it immediately after the //------------------------. This is how you've done it in the second code block anyway.

3) You don't need your second call to gl.glEnable(GL_TEXTURE_2D) after gl.glActiveTexture(GL11.GL_TEXTURE1).

GraphicsMuncher
  • 4,583
  • 4
  • 35
  • 50