Jump to content

[SOLVED] Rendering black lightning


condorcraft110

Recommended Posts

My mod adds a custom lightning bolt called dark lightning, with a custom renderer to make it render darkly. However, I am unable to colour the lightning black, no matter how I set the colour values.

 

RenderDarkLightning:

 

package net.condorcraft110.stygian.render;

import java.util.*;
import org.lwjgl.opengl.*;
import net.minecraft.util.*;
import net.minecraft.entity.*;
import net.minecraft.client.renderer.*;
import net.condorcraft110.stygian.entity.*;
import net.minecraft.client.renderer.entity.*;

public class RenderDarkLightning extends Render
{
public void doRender(EntityDarkLightning entity, double x, double y, double z, float f, float g)
{
	Tessellator tessellator = Tessellator.instance;
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        double[] adouble = new double[8];
        double[] adouble1 = new double[8];
        double d3 = 0.0D;
        double d4 = 0.0D;
        Random random = new Random(entity.boltVertex);
        
        for(int i = 7; i >= 0; --i)
        {
            adouble[i] = d3;
            adouble1[i] = d4;
            d3 += (double)(random.nextInt(11) - 5);
            d4 += (double)(random.nextInt(11) - 5);
        }

        for(int k1 = 0; k1 < 4; ++k1)
        {
            Random random1 = new Random(entity.boltVertex);

            for(int j = 0; j < 3; ++j)
            {
                int k = 7;
                int l = 0;

                if(j > 0)
                {
                    k = 7 - j;
                }

                if(j > 0)
                {
                    l = k - 2;
                }

                double d5 = adouble[k] - d3;
                double d6 = adouble1[k] - d4;

                for(int i1 = k; i1 >= l; --i1)
                {
                    double d7 = d5;
                    double d8 = d6;

                    if(j == 0)
                    {
                        d5 += (double)(random1.nextInt(11) - 5);
                        d6 += (double)(random1.nextInt(11) - 5);
                    }
                    else
                    {
                        d5 += (double)(random1.nextInt(31) - 15);
                        d6 += (double)(random1.nextInt(31) - 15);
                    }
                    
                    tessellator.startDrawing(5);
                    tessellator.setColorRGBA_F(0F, 0F, 0F, 1F); // Sets the colour, but still white 
                    double d9 = 0.1D + (double)k1 * 0.2D;
                    
                    if(j == 0)
                    {
                        d9 *= (double)i1 * 0.1D + 1.0D;
                    }
                    
                    double d10 = 0.1D + (double)k1 * 0.2D;
                    
                    if(j == 0)
                    {
                        d10 *= (double)(i1 - 1) * 0.1D + 1.0D;
                    }
                    
                    for(int j1 = 0; j1 < 5; ++j1)
                    {
                        double d11 = x + 0.5D - d9;
                        double d12 = z + 0.5D - d9;
                        
                        if(j1 == 1 || j1 == 2)
                        {
                            d11 += d9 * 2.0D;
                        }
                        
                        if(j1 == 2 || j1 == 3)
                        {
                            d12 += d9 * 2.0D;
                        }
                        
                        double d13 = x + 0.5D - d10;
                        double d14 = z + 0.5D - d10;
                        
                        if(j1 == 1 || j1 == 2)
                        {
                            d13 += d10 * 2.0D;
                        }
                        
                        if(j1 == 2 || j1 == 3)
                        {
                            d14 += d10 * 2.0D;
                        }
                        
                        tessellator.addVertex(d13 + d5, y + (double)(i1 * 16), d14 + d6);
                        tessellator.addVertex(d11 + d7, y + (double)((i1 + 1) * 16), d12 + d8);
                    }
                    
                    tessellator.draw();
                }
            }
        }
        
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
}

public void doRender(Entity entity, double x, double y, double z, float f, float g)
{
	doRender((EntityDarkLightning)entity, x, y, z, f, g);
}

protected ResourceLocation getEntityTexture(Entity entity)
{
	return null;
}
}

 

 

Update: When I don't enable GL_BLEND, the lightning does indeed render in black - but solidly. I want black-coloured lightning, not a large black line in the world :/

Link to comment
Share on other sites

Hi

 

Try using this blend function instead of GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

 

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

 

Use an alpha value of (say) 0.25 to start off with.

 

This online tool might be helpful,

http://www.andersriggelsen.dk/glblendfunc.php

also this background info link

http://www.glprogramming.com/red/chapter06.html

 

-TGG

 

Link to comment
Share on other sites

Hi

 

Try using this blend function instead of GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

 

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

 

Use an alpha value of (say) 0.25 to start off with.

 

This online tool might be helpful,

http://www.andersriggelsen.dk/glblendfunc.php

also this background info link

http://www.glprogramming.com/red/chapter06.html

 

-TGG

 

IT WORKED! Thank you! I really should get down to learning OpenGL properly...

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.



×
×
  • Create New...

Important Information

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