Jump to content

[1.8][Solved] drawing a simple line


badner

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

The x,y,z that you have to put in the methods are the block coords.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

}

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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