Author Topic: Black color is rendered as transparent !!!  (Read 3200 times)

Offline ares91x

  • byte
  • *
  • Posts: 6
    • View Profile
Black color is rendered as transparent !!!
« on: September 11, 2016, 10:35:40 am »
Hi, i have integrated JPCT-AE with ARtoolkit and it works fine but can't render black color, when i render an object the black part of the texture is rendered as transparent.

This is the ARtoolkit Render
Code: [Select]
public class ARRenderer implements GLSurfaceView.Renderer {

    /**
     * Allows subclasses to load markers and prepare the scene. This is called after
     * initialisation is complete.
     */
public boolean configureARScene() {
return true;
}

    public void onSurfaceCreated(GL10 unused, EGLConfig config) {       
   
    // Transparent background
    GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.f);
    }

    public void onSurfaceChanged(GL10 unused, int w, int h) {
    GLES10.glViewport(0, 0, w, h);
    }

    public void onDrawFrame(GL10 gl) {
    if (ARToolKit.getInstance().isRunning()) {   
    draw(gl);
    }   
    }
   
    /**
     * Should be overridden in subclasses and used to perform rendering.
     */
    public void draw(GL10 gl) {
    GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
    }
   
}

and this is JPCT-AE render
Code: [Select]
public class RenderARESX extends ARRenderer {

    private World mWorld;
    private Camera mCamera;
    private FrameBuffer mBuffer ;

    Matrix projMatrix = new Matrix();

    @Override
    public boolean configureARScene() {

        Config.useRotationPivotFrom3DS=true;
        // Initialize the game world and the camera
        mWorld = new World();
        mWorld.setClippingPlanes(0.1f, 10000.0f);
        mWorld.setAmbientLight(150, 150, 150);

        mCamera = mWorld.getCamera();

        // Load all objects to the world
        for (AmbientElement ae: MainScene.getInstance ().getAmbientElementsList()) {
            // init AmbientElement
            if (!ae.initRendering(mWorld) ) {
                // If there was a problem, return false
                return false;
            }
            //Log.wtf("esx","getmMarkerId = "+ae.getTracer().getmMarkerId());
        }

        return true;
    }

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int w, int h) {

        Config.useRotationPivotFrom3DS=true;

        super.onSurfaceChanged(gl10, w, h);
        mBuffer = new FrameBuffer(gl10,w,h);
    }

    float[] projection;
    @Override
    public void onDrawFrame(GL10 gl10) {

        mBuffer.clear();

        try {
            projection = ARToolKit.getInstance().getProjectionMatrix();

            projMatrix.setIdentity();
            projMatrix.setDump(projection);
            projMatrix.transformToGL();

            SimpleVector translation = projMatrix.getTranslation();
            SimpleVector dir = projMatrix.getZAxis();
            SimpleVector up = projMatrix.getYAxis();

            mCamera.setPosition(translation);
            mCamera.setOrientation(dir, up);

            for (AmbientElement ae : MainScene.getInstance().getAmbientElementsList()) {
                ae.updateMarkerTransformation();
            }

            mWorld.renderScene(mBuffer);
            mWorld.draw(mBuffer);
            mBuffer.display();
        }catch (Exception e){
            Log.e("esx","ERRORE RenderARESX.onDrawFrame "+e.toString());
            e.printStackTrace();
        }
    }

}

is it possible that this make the black part of the texture transparent GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.f); in ARtoolkit render?
I tried to change this but nothing happens.
Any idea how to solve this?
« Last Edit: September 11, 2016, 10:37:55 am by ares91x »

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: Black color is rendered as transparent !!!
« Reply #1 on: September 11, 2016, 11:01:19 am »
have you tried Object3D.setTransparency(-1)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Black color is rendered as transparent !!!
« Reply #2 on: September 11, 2016, 02:34:11 pm »
By default, the texture loader creates an alpha channel out of the black pixels of a texture. If you don't want that, use the constructor that takes the boolean argument in addition and set it to true.
Anyway, the alpha channel will only be taken into account when transparency is enabled on the object. Some objects are exported in a way that the loader defaults to transparency. Just try Michael's suggestion and see if that helps.

Offline ares91x

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Black color is rendered as transparent !!!
« Reply #3 on: September 13, 2016, 02:57:34 pm »
nothing happens , i tried 3dobject.setTrasparency(-1); with 3ds and md2 models and it still transparent

Can it be that this GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.f); on the ARtoolkit render make the texture transparent?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Black color is rendered as transparent !!!
« Reply #4 on: September 13, 2016, 04:38:53 pm »
No, it can't. Clearing the framebuffer has no influence on how a texture will be rendered. It might be caused by the fact that the framebuffer itself is transparent. Try setTransparency(-1) in combination with using the new Texture(..., true)-constructor for your textures.