Jump to content
  • Advertisement
Sign in to follow this  
alireza.pir

OpenGL Opengl-Using a shader, is it necessary?

This topic is 1202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?
 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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)

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!