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

OpenGL OpenGL- Render texture with transapare

This topic is 1126 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

i have a png image which draw it into my rectangular mesh in opengl, the problem is the image background is transparent but, when i bind it to my mesh, its background gets white; i want the image background to still be transparent. 
i tried
glEnableClientState(GLES10.GL_COLOR_ARRAY);
and
glColorPointer
 
but didn't work as i want.
 
 
DgByj.png
 
UPDATE:
the render openGL code:
 
void render(GL10 gl){


// First allocate texture if there is not one yet.
if (DRAW_TEXTURE && mTextureIds == null) {
// Generate texture.
mTextureIds = new int[2];
gl.glGenTextures(2, mTextureIds, 0);
for (int textureId : mTextureIds) {
// Set texture attributes.
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
gl.glTexParameterf(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_CLAMP_TO_EDGE);
}
}


if (DRAW_TEXTURE && mPage.getTexturesChanged()) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]);
Bitmap texture = mPage.getTexture(mTextureRectFront,
CurlPage.SIDE_FRONT);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0);
texture.recycle();


mTextureBack = mPage.hasBackTexture();
if (mTextureBack) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]);
texture = mPage.getTexture(mTextureRectBack,
CurlPage.SIDE_BACK);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0);
texture.recycle();
} else {
mTextureRectBack.set(mTextureRectFront);
}


mPage.recycle();
reset();
}








// Some 'global' settings.
gl.glEnableClientState(GLES10.GL_VERTEX_ARRAY);


if (DRAW_TEXTURE) {
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mBufTexCoords);
}
gl.glVertexPointer(3, GLES10.GL_FLOAT, 0, mBufVertices);
//inja khasiate transparent ro faAl mikonim ke betoonim too CurlPage be kaaghaz alpha bedim
gl.glEnable(GLES10.GL_BLEND);
gl.glBlendFunc(GLES10.GL_SRC_ALPHA, GLES10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GLES10.GL_LIGHTING);
gl.glDisable(GL10.GL_TEXTURE_2D);


// Draw front texture.
if (DRAW_TEXTURE) {
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);


if (!mFlipTexture || !mTextureBack) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]);
} else {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[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);
}


int backStartIdx = Math.max(0, mVerticesCountFront - 2);
//Log.d("mVerticesCountFront", ""+mVerticesCountFront+"");
int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx;


// Draw back facing blank vertices.
//gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
gl.glDrawArrays(GLES10.GL_TRIANGLE_STRIP, backStartIdx, backCount);




// Disable textures and color array.
gl.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);


gl.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
}
OnSurfaceCreated Method:
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// mCurlMesh.setup(gl);
gl.glClearColor(0f, 0f, 0f, 0f);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);
//gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
gl.glEnable(GL10.GL_LINE_SMOOTH);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glDisable(GL10.GL_CULL_FACE);
gl.glDisable(GL10.GL_DITHER);

}

 

Share this post


Link to post
Share on other sites
Advertisement

Do you clear the screen before drawing (glClear), does the texture support alpha channel (both the original, and the gl texture you create), if you use custom shader (probably should) does it support the alpha channel (vec4)? Ensure the image loaded in RAM is actually transparent, too (eg print out a pixel in the middle)

Edited by Waterlimon

Share this post


Link to post
Share on other sites

glColorPointer is used to se vertice colors not texture colors, you do that in shader, (if you set such i thin k you are only able to pass there 4 components per color) i am not sure if es 1.0 supports ffp but if then vertex alpha color is texture alpha? or sth liek that - not worth trying.

 

 

either the way you dont load 32 bit texture properly or your shader (if you have one doesnt output the alpha)

Edited by WiredCat

Share this post


Link to post
Share on other sites

Do you clear the screen before drawing (glClear), does the texture support alpha channel (both the original, and the gl texture you create), if you use custom shader (probably should) does it support the alpha channel (vec4)? Ensure the image loaded in RAM is actually transparent, too (eg print out a pixel in the middle)

 

 

glColorPointer is used to se vertice colors not texture colors, you do that in shader, (if you set such i thin k you are only able to pass there 4 components per color) i am not sure if es 1.0 supports ffp but if then vertex alpha color is texture alpha? or sth liek that - not worth trying.

 

 

either the way you dont load 32 bit texture properly or your shader (if you have one doesnt output the alpha)

 

thanks for your reply, im Sure that the textures has the alpha channel, cause when i set the vertex Color to yellow for example, i get this as result:

 

Untitled_6c586.png

 

the problem is if i set the vertex color "Color.Transparent" Both Texture and vertices become Transparent, I want the vertices to be transparent and Just show the texture itself. 

(The Color Stores in mBufColors and as is shown in the code called by  gl.glColorPointer(4, GLES10.GL_FLOAT, 0, mBufColors); )

Share this post


Link to post
Share on other sites

Transparency/Blending is a render state and is in no way shape or form related to glColorPointer nor any of the other client states.

Share this post


Link to post
Share on other sites

Transparency/Blending is a render state and is in no way shape or form related to glColorPointer nor any of the other client states.

 

thanks. but Now what should i do?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!