vcapra1
vcapra1

Reputation: 2025

OpenGL ES 2 - color and texture in vertex

I'm making a program with OpenGL ES 2.0. I need to render a texture on top of another, like a clock hand. The textures are both 1024 x 1024 and are transparent. The transparency is always rendering black, and this is preventing me from overlaying the clock hand texture over the clock.

simple_fragment_shader.glsl

precision mediump float;

varying vec4 v_Color;

void main() 
{
    gl_FragColor = v_Color;
}

simple_vertex_shader.glsl

uniform mat4 u_Matrix;

attribute vec4 a_Position;  
attribute vec4 a_Color;

varying vec4 v_Color;

void main()                    
{                            
    v_Color = a_Color;

    gl_Position = u_Matrix * a_Position;
    gl_PointSize = 10.0;          
}          

texture_fragment_shader.glsl

precision mediump float; 

uniform sampler2D u_TextureUnit;                                        
varying vec2 v_TextureCoordinates;                                          

void main()                         
{                               
    gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates);    
}

texture_vertex_shader.glsl

uniform mat4 u_Matrix;

attribute vec4 a_Position;  
attribute vec2 a_TextureCoordinates;

varying vec2 v_TextureCoordinates;

void main()                    
{                            
    v_TextureCoordinates = a_TextureCoordinates;          
    gl_Position = u_Matrix * a_Position;    
}          

I'm kind of new at OpenGL, and I have used textures, but I don't know how to get the transparency.

Also, if this helps, I am sort of following the methods in OpenGL ES 2 for Android by Kevin Brothaler from The Pragmatic Programmers.

Upvotes: 0

Views: 101

Answers (1)

Yorung
Yorung

Reputation: 64

Alpha value might be ignored without following settings.

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I hope this help you:)

Upvotes: 1

Related Questions