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

    • Museumbola merupakan wadah judi online terkhusus untuk sbobet atau judi bola. Dengan daftar dan deposit menggunakan BANK BCA, Anda berkesempatan mendapatkan prediksi jitu pertandingan secara update setiap hari yang bisa anda jadikan acuan untuk bermain judi bola. Hanya dengan 10 ribu rupiah dan anda bermain Mix Parlay menggunakan prediksi yang telah di sediakan oleh kami, anda akan memenangkan jutaan rupiah. Yuk segera klik DAFTAR sekarang juga.
    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
  • Topics

×
×
  • Create New...

Important Information

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