Jump to content

Recommended Posts

Posted

I'm trying to draw some world-information as an overlay (so 3D quads, not 2D HUD things) and I'm having two problems:

 

1) I can't get the quads to be full-bright.  They flicker between various lighting values as the camera moves. Pic

2) The block outline's outline color changes. Pic

 

@SubscribeEvent
public void renderEvent(DrawBlockHighlightEvent event) {
	...
		GL11.glPushMatrix();
		GL11.glTranslated(-event.player.posX, -event.player.posY, -event.player.posZ);
		GL11.glDisable(GL11.GL_LIGHTING);
		drawLine(thisBlock, points[i]);
	...
}

private void drawLine(Vec3 blockA, Vec3 blockB) {
	Tessellator tess = Tessellator.instance;
	tess.setBrightness(15728880);
	tess.startDrawing(7);
	int d = Math.round((float)blockA.distanceTo(blockB)+0.2f);

	tess.setColorOpaque_F(1F, 0F, 0F);

	float ox = (blockA.xCoord - blockB.xCoord == 0?-1f/16f:0);
	float oz = (blockA.zCoord - blockB.zCoord == 0?1f/16f:0);

	if(blockA.xCoord - blockB.xCoord > 0 || blockA.zCoord - blockB.zCoord > 0) {
		tess.addVertex(blockA.xCoord + 0.5 + ox, blockA.yCoord - 0.01, blockA.zCoord + 0.5 + oz);
		tess.addVertex(blockB.xCoord + 0.5 + ox, blockB.yCoord + 0.99, blockB.zCoord + 0.5 + oz);
		tess.addVertex(blockB.xCoord + 0.5 - ox, blockB.yCoord + 0.99, blockB.zCoord + 0.5 - oz);
		tess.addVertex(blockA.xCoord + 0.5 - ox, blockA.yCoord - 0.01, blockA.zCoord + 0.5 - oz);
	}
	else {
		tess.addVertex(blockA.xCoord + 0.5 - ox, blockA.yCoord - 0.01, blockA.zCoord + 0.5 - oz);
		tess.addVertex(blockB.xCoord + 0.5 - ox, blockB.yCoord + 0.99, blockB.zCoord + 0.5 - oz);
		tess.addVertex(blockB.xCoord + 0.5 + ox, blockB.yCoord + 0.99, blockB.zCoord + 0.5 + oz);
		tess.addVertex(blockA.xCoord + 0.5 + ox, blockA.yCoord - 0.01, blockA.zCoord + 0.5 + oz);
	}

	tess.draw();
}

 

What've I missed?

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.

Posted

1) Where do  you pop your matrix?

2) Maybe using

glPushAttrib

and

glPopAttrib

will help.

 

1) I trimmed it (there's about 12 lines I removed, checking for various things).  I know about push/pop.  In retrospect I should have left that in.

2)

GL11.glPushAttrib(GL11.GL_ENABLE_BIT)

fixed the block outline color though, thanks!

 

But I still have an issue with the lighting on the quads being incorrect.

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.

Posted

1) Where do  you pop your matrix?

2) Maybe using

glPushAttrib

and

glPopAttrib

will help.

 

1) I trimmed it (there's about 12 lines I removed, checking for various things).  I know about push/pop.  In retrospect I should have left that in.

2)

GL11.glPushAttrib(GL11.GL_ENABLE_BIT)

fixed the block outline color though, thanks!

 

But I still have an issue with the lighting on the quads being incorrect.

 

For the light I'd suggest using

OpenGlHelper.setLightmapTextureCoords()

:

// save the previous lighting brightness
            float prevBrightX = OpenGlHelper.lastBrightnessX;
            float prevBrightY = OpenGlHelper.lastBrightnessY;
// declare new brightness (0xF0 is the max. possible)
            int bright = 0xF0;
            int brightX = bright % 65536;
            int brightY = bright / 65536;
// set new brightness
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX / 1.0F, brightY / 1.0F);

// do rendering here


// reset original brightness, so it doesn't mess up anything post-rendered
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, prevBrightX, prevBrightY);

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Nope, didn't help. :\

 

I'm using the Tessellator for drawing, btw.  And I've already got

tess.setBrightness(15728880)

, but it hasn't made a difference either.

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.

Posted

Hi Draco

 

You could try calling             

GL11.glColor4f(colour.R, colour.G, colour.B, colour.A);

instead of

tess.setColorOpaque_F(1F, 0F, 0F);

 

That fixed a similar problem I had once before.

 

-TGG

 

Posted

You could try calling             

GL11.glColor4f(colour.R, colour.G, colour.B, colour.A);

instead of

tess.setColorOpaque_F(1F, 0F, 0F);

 

Calling tess.setColor...no good

Calling tess.setColor and GL11.glColor...no good

Calling GL11.glColor...no good

 

:\

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.

Posted

Ah... your code triggers a ghost of a memory... let me check...

 

Try this:

		Tessellator tess = Tessellator.instance;
	tess.startDrawing(7);                                        //swap order
                tess.setBrightness(15728880);

    public void startDrawing(int p_78371_1_)
    {
        if (this.isDrawing)
        {
            throw new IllegalStateException("Already tesselating!");
        }
        else
        {
            this.isDrawing = true;
            this.reset();
            this.drawMode = p_78371_1_;
            this.hasNormals = false;
            this.hasColor = false;
            this.hasTexture = false;
            this.hasBrightness = false;
            this.isColorDisabled = false;
        }
    }

-TGG

Posted

Nope.  And I managed to dredge up an older post of my own that gave me what I needed, albeit in decimal format.

 

glDisable(GL_TEXTURE_2D);

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.

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.