Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Transparency in GUI


garfield1002
 Share

Recommended Posts

I am attempting to create a semi transparent model that will appear in a GUI. However, you can see behind the GUI with it and not behind in the GUI

spacer.png

    @SubscribeEvent
    public static void onTextureStitch(TextureStitchEvent.Pre event){
        if(event.getMap().getTextureLocation().equals(AtlasTexture.LOCATION_BLOCKS_TEXTURE)){
            event.addSprite(new ResourceLocation(MOD_ID, "planets/default"));
        }
    }
@Mod.EventBusSubscriber(modid=Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class GUIBlockScreen extends ContainerScreen<GUIBlockContainer> {
    
  public GUIBlockScreen(GUIBlockContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        drawEntityOnScreen(this.width / 2, this.height / 2, (int) pow(30 - this.zoom / 3, 2 ));
    }

    public void drawOnScreen(int posX, int posY, int scale) {
        RenderSystem.pushMatrix();
      	// I have tried all of these but it dosn't seem to do anything
        // RenderSystem.enableBlend();
        // RenderSystem.enableTexture();
        // RenderSystem.enableDepthTest();
        // RenderSystem.disableCull();
        // RenderSystem.enableRescaleNormal();
        // RenderSystem.enableAlphaTest();
        // RenderSystem.defaultAlphaFunc();
        // RenderSystem.enableBlend();
        // RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        // RenderSystem.defaultBlendFunc();

        RenderSystem.translatef((float)posX, (float)posY, -1050.0F);
        RenderSystem.scalef(0.12F, 0.12F, 0.12F);

        MatrixStack matrixstack = new MatrixStack();

        IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
      
      	IVertexBuilder vertexBuilder = irendertypebuffer$impl.getBuffer(RenderType.getTranslucent());

      	Material material = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(Main.MOD_ID, 		"planets/defaulttransparency"));

		drawCube(new Vec3d(0.5, 0, 0), new Vec3d(0, 0.5, 0), new Vec3d(0, 0, 0.5), matrixstack, vertexBuilder, this.material, 0.3F);

        irendertypebuffer$impl.finish();

        RenderSystem.popMatrix();
    }
}
	private static void add(IVertexBuilder renderer, Matrix4f matrixPos, Vec3d A, Vec3d N, float u, float v, float opacity) {
        renderer.pos(matrixPos, (float) A.x, (float) A.y, (float) A.z)
                .color(1.0F, 1.0F, 1.0F, opacity)
                .tex(u, v)
                .lightmap(0, 240)
                .normal((float) N.x, (float) N.y, (float) N.z)
                .endVertex();
    }

    private static void square(IVertexBuilder renderer, Matrix4f matrixPos, Vec3d A, Vec3d B, Vec3d C, Material material, float opacity) {
        Vec3d N = A.crossProduct(B).normalize();
        float u = material.getSprite().getMinU();
        float U = material.getSprite().getMaxU();
        float v = material.getSprite().getMinV();
        float V = material.getSprite().getMaxV();
        add(renderer, matrixPos, C, N, u, v, opacity);
        add(renderer, matrixPos, A.add(C), N, U, v, opacity);
        add(renderer, matrixPos, A.add(B).add(C), N, U, V, opacity);
        add(renderer, matrixPos, B.add(C), N, u, V, opacity);
    }

    public static void drawCube(Vec3d A, Vec3d B, Vec3d C,
                                MatrixStack matrixstack, IVertexBuilder renderBuffer, Material material, float opacity) {
        // retrieves a position matrix
        Matrix4f matrixPos = matrixstack.getLast().getMatrix();

        // draws the 6 sides
        square(renderBuffer, matrixPos, A, B, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, B, A, C, material, opacity);

        square(renderBuffer, matrixPos, C, A, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, A, C, B, material, opacity);

        square(renderBuffer, matrixPos, B, C, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, C, B, A, material, opacity);
    }

 
Edited by garfield1002
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.