Jump to content

[1.6.4] Flickering transparency using GL11.GL_BLEND


lexwebb

Recommended Posts

I have an odd issue when anything i render using GL11.GL_BLEND will become transparent and nontransparent depending on which way you look at it. An example can be seen in the video below. where the item in my hand will randomly switch states.

 

 

The whole structure next to is meant to be transparent to. And look like this. but at the time of recording it was refusing to render transparent at all.

 

6LhJp.jpg

 

Some sample render code:

 

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
		RenderBlocks renderer) {

	GL11.glPushMatrix();

	GL11.glTranslatef(0.0f, 1.4f, 0.0f);

	ResourceLocation textures = (new ResourceLocation(ModInfo.ID.toLowerCase() + ":textures/blocks/ColliderPipeCornerTile.png")); 
	Minecraft.getMinecraft().renderEngine.bindTexture(textures);
                   
     	GL11.glPushMatrix();

        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        this.model.renderFrame((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        
        GL11.glEnable(GL11.GL_BLEND);       
        this.model.renderPipe((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glDisable(GL11.GL_BLEND);

        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

Link to comment
Share on other sites

Private video is private.

 

Anyway, try setting a color, GL11.glColor_f(1, 1, 1, 1)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Opps! ^_^ Try now!

 

I've added the color and and another piece of code i found elsewhere. (See code below below) now it kinda works...

 

6Lk2S.jpg

 

GL11.glEnable(GL11.GL_BLEND); 
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glColor4f(1, 1, 1, 1);
        this.model.renderPipe((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glDisable(GL11.GL_BLEND);

Link to comment
Share on other sites

Unfortunately I am not sure at this point.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Maybe I can enlighten a you a bit when it comes to blend functions.

How it works:

 

Before a face with an alpha value is rendered let there be already existing background on your screen. We'll call the screenplane which openGL paints on "destination pane" (normally you don't speak of a plane but of a framebuffer but you can think of it as a canvas).

 

What happens now is that openGL doesn't directly paint ontop of the already existing stuff. Instead think about taking a new canvas and paint you face on this one. Let's call it "source pane".

 

For the computer of course colors aren't colors. They are Integers and are represented in the "rgb"-colorscheme (red, green, blue). To add transparancy we need a forth number, the alpha-value. For every pixel on value is saved for red, green, blue and alpha (rgba). The effectiva range is [0...1] from "not there" to "all of it".

 

But now you have two different planes! How does this get merged into one? This is where the blending-function blends in. You call GL11.glBlendFunc(sScale, dScale). The function takes two arguments of the exact same "type" (openGL-constants of a specific type, for you they appear as ints but openGL interprets them). When you look at the documentation ( https://www.opengl.org/sdk/docs/man4/xhtml/glBlendFunc.xml ) you see that you can actually pass any of

                    GL_ZERO,

                    GL_ONE,

                    GL_SRC_COLOR,

                    GL_ONE_MINUS_SRC_COLOR,

                    GL_DST_COLOR,

                    GL_ONE_MINUS_DST_COLOR,

                    GL_SRC_ALPHA,

                    GL_ONE_MINUS_SRC_ALPHA,

                    GL_DST_ALPHA,

                    GL_ONE_MINUS_DST_ALPHA.

                    GL_CONSTANT_COLOR,

                    GL_ONE_MINUS_CONSTANT_COLOR,

                    GL_CONSTANT_ALPHA, and

                    GL_ONE_MINUS_CONSTANT_ALPHA

 

What now happens is that the colors on the destination plane are mulitplied by a factor related to the GL-constant you passed, the dScale. For GL_ONE this factor is 1. For GL_ONE_MINUS_SRC_ALPHA this factor is (1-alphaOnSourcePlane) etc.

This is done for the source-plane, too, but with the sScale parameter instead of dScale. Then the resulting source-values just get add ontop of the existing destination colors.

 

Here you can see why GL_ONE is a bit worse than GL_ONE_MINUS_SRC_ALPHA but doesn't look bad after all:

If you can reacall if you use GL_ONE the color after painting the plane would be something like dColor*1+sColor*sValue. This value will always be greater than before and the world "behind the glass/transparent whatever" would not get filtered any bit.

With GL_ONE_MINUS_SRC_ALPHA the equation is about dColor*(1-sValue)+sColor*sValue meaning that the dColor (existing color) gets reduced by a little bit as much as the material you draw is NOT transparent.

 

I hope this can help you figuring it out in your mind ;) Keep up the modding, the pipes look awesome.

  • Like 1
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.