craylib

Transparent textures do not render properly


I was using raylib and instead of partially showing the texture behind it's just black.

Output: output

Expected output (made with an editor): expected

Here's my code:

       BeginDrawing();

            ClearBackground(BLACK);

            BeginMode3D(cam);

                DrawTexturedPlane(test, testPos);
                DrawTexturedPlane(mc, cam.target);
            EndMode3D();

        EndDrawing();

I tried switching lines DrawTexturedPlane(test, testPos); and DrawTexturedPlane(mc, cam.target); but it just made reverse. I feel like I know but I just can't search it or remember it.


Solution

  • I remembered where I've seen solution to my question: https://learnopengl.com/Advanced-OpenGL/Blending

    I just didn't sort texture by their distance to camera. Here's the code if you want tp see it:

    ...
    const float distMc = Vector3Distance(cam.position, cam.target); // position to the guys is constant
    ...
    float distTest = Vector3Distance(cam.position, testPos); // calculate position to the test object
    //draw
    BeginDrawing();
    
                ClearBackground(BLACK);
    
                BeginMode3D(cam);
                    if (distMc <= distTest) {
                        DrawTexturedPlane(test, testPos);
                        DrawTexturedPlane(mc, cam.target);
                    } else {
                        DrawTexturedPlane(mc, cam.target);
                        DrawTexturedPlane(test, testPos);
                    }
                EndMode3D();
    
            EndDrawing();