Jump to content

Recommended Posts

Posted

Hi,

 

i am looking for a function which allows me to draw a simple line. I found an article: http://www.minecraftforge.net/wiki/Tessellator but i think its outdated? (in 1.8 you have to use the WorldRenderer?). And i dont get the functionality of:

 

GL11.glTranslated(x, y, z);

What kind of coordinates do i have to assign?

 

t.addVertex(0, 0, 0); (t should be an Object of WorldRenderer)

t.addVertex(0, 1, 0);

Same question: For a line i need a starting point and an endpoint. What kind of coordinates do i have to assign?

 

The function should draw a line like this: http://www.pic-upload.de/view-28239930/line.png.html

 

Thanks for your help,

 

Daniel

 

Posted

Dude, please tell us if you want a 3D line or 2D, if you want 2D, there is a very good method in the vanilla Gui class

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Hi,

 

I want to draw lines at the edges of Blocks (-> Screenshot).

 

The Methods in the Gui class are useless?

 

drawHorizontalLine and drawVerticalLine dont have a parameter for Z coordinate?

Posted

Using rectangles wouldn't be good for that, they would be filled. Easier to use are GL11.GL_LINES or GL11.GL_LINE_STIPPLE

You'll have to use the WorldRenderer for that. Do it like this:

GLStateManager.pushMatrix()
GLStateManager.pushAttrib();

WorldRenderer renderer =Tessellator.getInstance().getWorldRenderer();

renderer.startDrawing(GL11.GL_LINES);
//Your code here e.e renderer.addVertex(x,y,z);

Tessellator.getInstance().draw();

GLStateManager.popMatrix()
GLStateManager.popAttrib();

 

EDIT: if you wanna change the color of the line do renderer.setColorOpaque(red, green, blue) or renderer.setColorRGBA(red, green, blue,alpha)

the color/alpha values are all ints from 0-255

The difference between GL:LINES and GL_LINESTIPPLE is, that with GL_LINES every two vertices will be drawn as one line, means if you draw three vertices, the one will be invisible. If you wan't these lines to connect up use GL_LINESTIPPLE.

Posted

This isn't going to give you everything, but it will give you enough to get started.  You're still going to need to get the coorridinates you want to draw to/from yourself as well as modify this code to draw bounding boxes, rather than center to center.

 

(The tessellator, by the way, is just a wrapper and helper class that uses GL commands under the hood).

 

GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
Vec3 pos = event.player.getPosition(event.partialTicks);
//because of the way 3D rendering is done, all coordinates are relative to the camera.  This "resets" the "0,0,0" position to the location that is (0,0,0) in the world.
GL11.glTranslated(-pos.xCoord, -pos.yCoord, -pos.zCoord);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_TEXTURE_2D);
//you will need to supply your own position vectors
drawLineWithGL(pos1, pos2);
GL11.glPopAttrib();
GL11.glPopMatrix();

//...

private void drawLineWithGL(Vec3 blockA, Vec3 blockB) {
	int d = Math.round((float)blockA.distanceTo(blockB)+0.2f);
	GL11.glColor3f(0F, 1F, 0F);
	float oz = (blockA.xCoord - blockB.xCoord == 0?0:-1f/16f);
	float ox = (blockA.zCoord - blockB.zCoord == 0?0:1f/16f);
	GL11.glBegin(GL11.GL_LINE_STRIP);

	//you will want to modify these offsets.
	GL11.glVertex3d(blockA.xCoord + 0.5,blockA.yCoord - 0.01,blockA.zCoord + 0.5);
	GL11.glVertex3d(blockB.xCoord + 0.5,blockB.yCoord - 0.01,blockB.zCoord + 0.5);

	GL11.glEnd();
}

 

This will draw a line from the underside-center to the underside-center in green.

 

Your "the yellow bits don't need to be visible" in this code sample would be true, the lines drawn will be hidden by geometry.  IIRC, in order to draw on top of geometry (the yellow bits visible) you need to call

GL11.glDisable(GL11.GL_DEPTH_TEST);

 

I have most of the GL commands outside the function because I was drawing multiple lines, so I did not need to set my settings, and then unset them, between each line.  Line_strip was inside, because my actual use uses QUADS, so my LINE_STRIP drawing function had to specify.

 

The difference between GL:LINES and GL_LINESTIPPLE is, that with GL_LINES every two vertices will be drawn as one line, means if you draw three vertices, the one will be invisible. If you wan't these lines to connect up use GL_LINESTIPPLE.

 

LINE_STRIP.  Not STIPPLE.  GL_LINE_STIPPLE is an enable/disable parameter that makes lines drawn with GL_LINES or GL_LINE_STRIP to be dashed.

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

This isn't going to give you everything, but it will give you enough to get started.  You're still going to need to get the coorridinates you want to draw to/from yourself as well as modify this code to draw bounding boxes, rather than center to center.

 

 

Vec3 pos = event.player.getPosition(event.partialTicks);

 

Which event (from net.minecraftforge.client.event package e.g.) should I use?

 

According to the previous posts, I can use this:

Vec3 pos1= new Vec3 (0,5,0);  // [b]Vector from 0,0,0 to 0,5,0 -> Blockcoords[/b]
Vec3 pos2= new Vec3 (5,5,0);  // [b]Vector from 0,0,0 to 5,5,0 -> Blockcoords[/b]

//you will need to supply your own position vectors
drawLineWithGL(pos1, pos2);

 

This is never used:

 

int d = Math.round((float)blockA.distanceTo(blockB)+0.2f);

 

 

Posted

This isn't going to give you everything, but it will give you enough to get started.  You're still going to need to get the coorridinates you want to draw to/from yourself as well as modify this code to draw bounding boxes, rather than center to center.

 

Vec3 pos = event.player.getPosition(event.partialTicks);

 

Which event (from net.minecraftforge.client.event package e.g.) should I use?

 

Oh yeah, sorry.

 

I was using the

DrawBlockHighlightEvent

, but there's a handful of render events that would all be appropriate.  And of course, this should be in a client side only event handler, for obvious reasons.  I picked DrawBlockHighlightEvent because I was interested in the block that the player was looking at, and that event gave it to me, I didn't have to ray-trace it.

 

According to the previous posts, I can use this:

Vec3 pos1= new Vec3 (0,5,0);  // [b]Vector from 0,0,0 to 0,5,0 -> Blockcoords[/b]
Vec3 pos2= new Vec3 (5,5,0);  // [b]Vector from 0,0,0 to 5,5,0 -> Blockcoords[/b]

//you will need to supply your own position vectors
drawLineWithGL(pos1, pos2);

 

That will draw a very specific line in the world, from the block at (0,5,0) to (5,5,0).  Every world you create, no matter where you go, that line will be drawn in the same place in the world.  But for testing? Sure, it'll work.

 

This is never used:

int d = Math.round((float)blockA.distanceTo(blockB)+0.2f);

 

That's left over from code I removed that determined what color to draw my line.  For me, the distance was important, for you it isn't.  You can remove that.

Here's a pic of what I was doing:

width=800 height=449http://vignette1.wikia.nocookie.net/reasonable-realism/images/b/b2/2015-08-13_01.44.38.png/revision/latest?cb=20150814171720[/img]

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

Finally I got it  ::)

	@SubscribeEvent
public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event){

	GL11.glPushMatrix();
	GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

        double d0 = event.player.prevPosX + (event.player.posX - event.player.prevPosX) * (double)event.partialTicks;
        double d1 = event.player.prevPosY + (event.player.posY - event.player.prevPosY) * (double)event.partialTicks;
        double d2 = event.player.prevPosZ + (event.player.posZ - event.player.prevPosZ) * (double)event.partialTicks;
        
        Vec3 pos = new Vec3(d0, d1, d2);

	//Vec3 pos = event.player.getPositionEyes(event.partialTicks); Doesnt work because y-part +(double)this.getEyeHeight()

	GL11.glTranslated(-pos.xCoord, -pos.yCoord, -pos.zCoord);
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_DEPTH_TEST);		// draw the line on top of the geometry

	Vec3 posA = new Vec3 (0,10,0);
	Vec3 posB = new Vec3 (10,10,0);

	drawLineWithGL(posA, posB); 

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

private void drawLineWithGL(Vec3 blockA, Vec3 blockB) {


	GL11.glColor4f(1F, 0F, 1F, 0F);  // change color an set alpha

	GL11.glBegin(GL11.GL_LINE_STRIP);

	GL11.glVertex3d(blockA.xCoord, blockA.yCoord, blockA.zCoord);
	GL11.glVertex3d(blockB.xCoord, blockB.yCoord, blockB.zCoord);

	GL11.glEnd();
}

 

Vec3 pos = event.player.getPosition(event.partialTicks);

First i used getPositionEyes Instead of getPosition  but this Method didnt return the correct y-value. You can see this if you look into the declaration.

 

I also switched from GL11.glColor3f to GL11.glColor4f, but alpha 1F or alpha 0F change nothing. The "color" of the line is still depending on the block behind. How can I fix this?

 

Daniel

Posted
I also switched from GL11.glColor3f to GL11.glColor4f, but alpha 1F or alpha 0F change nothing. The "color" of the line is still depending on the block behind. How can I fix this?

 

Huh?

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

Thats a optical illusion (is that the correct word?^^).

 

Is there a better Way to draw a Cube without surfaces? like this -> http://www.pic-upload.de/view-28254561/cube.png.html

 

	ArrayList<Vec3> lineList = new ArrayList<Vec3>(); // Storage of vertices for all lines

Vec3[] cube = new Vec3[8];	// Example

public void setCubeList(){

	// vertices of a cube; 
	cube[0] = new Vec3(0,10,0); 
	cube[1] = new Vec3(10,10,0);
	cube[2] = new Vec3(0,10,10);
	cube[3] = new Vec3(10,10,10);
	cube[4] = new Vec3(0,20,0);
	cube[5] = new Vec3(10,20,0);
	cube[6] = new Vec3(10,20,10);
	cube[7] = new Vec3(0,20,10);

	lineList.add(cube[0]); // edge 1-2
	lineList.add(cube[1]);

	lineList.add(cube[1]); // edge 2-4
	lineList.add(cube[3]);

	lineList.add(cube[0]); // edge 1-3
	lineList.add(cube[2]);

	lineList.add(cube[2]); // edge 3-4
	lineList.add(cube[3]);

	lineList.add(cube[4]); // edge 5-8
	lineList.add(cube[7]);

	lineList.add(cube[4]); // edge 5-6
	lineList.add(cube[5]);

	lineList.add(cube[6]); // edge 7-8
	lineList.add(cube[7]);

	lineList.add(cube[5]); // edge 6-7
	lineList.add(cube[6]);

	lineList.add(cube[0]); // edge 1-5
	lineList.add(cube[4]);

	lineList.add(cube[1]); // edge 2-6
	lineList.add(cube[5]);

	lineList.add(cube[3]); // edge 4-7
	lineList.add(cube[6]);

	lineList.add(cube[2]); // edge 3-8
	lineList.add(cube[7]);
}


@SubscribeEvent
public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event){

	GL11.glPushMatrix();
	GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

        double d0 = event.player.prevPosX + (event.player.posX - event.player.prevPosX) * (double)event.partialTicks;
        double d1 = event.player.prevPosY + (event.player.posY - event.player.prevPosY) * (double)event.partialTicks;
        double d2 = event.player.prevPosZ + (event.player.posZ - event.player.prevPosZ) * (double)event.partialTicks;
        
        Vec3 pos = new Vec3(d0, d1, d2);

	GL11.glTranslated(-pos.xCoord, -pos.yCoord, -pos.zCoord);
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_DEPTH_TEST);		

	for(int a = 0; a<lineList.size(); a+=2){
		drawLineWithGL(lineList.get(a), lineList.get(a+1));
	}

	GL11.glPopAttrib();
	GL11.glPopMatrix();

}

Posted

Nope.  You need to draw all 12 edges.

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.