Opengl-Using a shader, is it necessary?

Started by
5 comments, last by alireza.pir 8 years, 7 months ago
in my Android game im drawing a rectangle and binding a texture to it using this code:

   gl.glVertexPointer(3, GLES10.GL_FLOAT, 0, mBufVertices);
   // Enable color array.
   gl.glEnableClientState(GLES10.GL_COLOR_ARRAY);
   gl.glColorPointer(4, GLES10.GL_FLOAT, 0, mBufColors);
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, renderTex[1]);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, mVerticesCountFront);
gl.glDisable(GL10.GL_BLEND);
gl.glDisable(GL10.GL_TEXTURE_2D);
every thing is fine, But the problem is that i want the rectangle to be completely transparent and just draw the texture visible on it, meaning i want the yellow part to be transparent:
6RK8w.png
i tried to change the rectangle vertex color and make them transparent, but this made the Whole page transparent even the texture.
does i have to use a shader to do what i want?
Advertisement

I dont know if you have to, but you absolutely should. That way you have full control of whats happening which might be useful in the future. The shaders should be pretty simple if you are just doing some 2D stuff and not photorealistic rendering with 50 different material types.

o3o

The description is not particularly clear about what you want to do, but if you insist on not using shaders you might want to try using glTexEnvi, maybe with GL_DECAL.

The description is not particularly clear about what you want to do, but if you insist on not using shaders you might want to try using glTexEnvi, maybe with GL_DECAL.

i have a texture, which has alpha, i want the alpha parts of the texture drawing to triangle to be transparent:

Image005.png

(i should mention that i set the triangle vertices color to yellow)

It should work fine without shaders.

(Though shaders would be recommended, after getting used to the idea of them, a lot of things are actually easier in a programmable pipeline instead of a fixed function one. Under the hood, the fixed function pipeline also uses shaders, you just do not have direct control over them)

Have you made sure you didn't make a mistake somewhere loading the texture?

Kind of looks like you do not have alpha in the texture where you expect it.

Maybe you are losing your alpha channel while loading the texture.

Another possibility is drawing in the wrong order, if you draw with depth test enabled.

(that is, you try to draw the foreground before drawing the background)

how did you load the texture?

It should work fine without shaders.

(Though shaders would be recommended, after getting used to the idea of them, a lot of things are actually easier in a programmable pipeline instead of a fixed function one. Under the hood, the fixed function pipeline also uses shaders, you just do not have direct control over them)

Have you made sure you didn't make a mistake somewhere loading the texture?

Kind of looks like you do not have alpha in the texture where you expect it.

Maybe you are losing your alpha channel while loading the texture.

Another possibility is drawing in the wrong order, if you draw with depth test enabled.

(that is, you try to draw the foreground before drawing the background)

Thank you Very Much, the Problem Exactly was what you mentioned. i draw the triangle before drawing the texture, and that was the problem.

thanks again.

This topic is closed to new replies.

Advertisement