Posted February 28, 201411 yr Hi Does anyone know if there are any GL11 methods to create coloured lines that look somewhat like lasers? If not how would i make one that looks like the build craft lasers? Im hoping its just say a gl11 draw line method or something.
February 28, 201411 yr Author So GL11 does have a method for a ray and then i use a renderer class to render it out correct? if found this: GL11.glBegin(GL11.GL_LINES); but not sure how to use it
February 28, 201411 yr Hi This code draws black semi-transparent lines, if you fiddle with it you might be able to get what you want... GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(Colour.BLACK_40.R, Colour.BLACK_40.G, Colour.BLACK_40.B, Colour.BLACK_40.A); // change this for your colour GL11.glLineWidth(2.0F); GL11.glDepthMask(false); Tessellator tessellator = Tessellator.instance; tessellator.startDrawing(GL11.GL_LINES); tessellator.addVertex(x1, y1, z1); tessellator.addVertex(x2, y2, z2); tessellator.draw(); GL11.glDepthMask(true); GL11.glPopAttrib(); If you want to draw a series of connected lines (bendy laser?) then tessellator.startDrawing(GL11.GL_LINE_STRIP); can be useful to. A great guide on OpenGL here http://www.glprogramming.com/red/index.html -TGG
February 28, 201411 yr Author Thanks for that - are the x1 y1 z1 and x2 y2 z2 the stat and end coords of the line? Also i can't seem to get the colour to work. Also thanks for that tutorial - I'm going to give it a read through for future needs EDIT: Ok i think I've got everything working great now. Thanks heaps
February 28, 201411 yr Thanks for that - are the x1 y1 z1 and x2 y2 z2 the stat and end coords of the line? yes that's right Also i can't seem to get the colour to work. Yeah Colour is my own custom class which I didn't include. Just change it to numbers, eg GL11.glColor4f(0, 0, 0, 0.4); // semi-transparent black or GL11.glColor4f(1, 0, 0, 0.4); // semi-transparent red etc (You know about Red, Green, Blue, Alpha yes?) Also thanks for that tutorial - I'm going to give it a read through for future needs No worries, it's a bit complicated in parts but it sure taught me a lot. -TGG
March 1, 201411 yr Author One more thing Is there anyway i can make these lines shine bright in dark areas or emit light. Doesn't matter if there isn't
March 1, 201411 yr Hi You mean - nearby blocks light up if the laser is shining? Yes I think it's possible, but it will be tricky because the block lighting would need to be updated. It would probably look something like putting transparent (invisible) blocks along the path of the beam and causing them to emit light for the blocklight calculations. Some info on lighting here, to give you an idea of how vanilla works it. http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html -TGG
March 4, 201411 yr Author Sorry to bring this back but I've been trying to spawn a line form player position to the crosshair of the player or the block the player is looking at; Ive got this so far: Vec3 lookPos = Entityplayer.getLookVec(); MovingObjectPosition Coord = Entityplayer.rayTrace(300, 1); if(Coord != null){ GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(1, 0, 0, 0.5F); // change this for your colour GL11.glLineWidth(10.0F); GL11.glDepthMask(false); Tessellator tessellator = Tessellator.instance; tessellator.startDrawing(GL11.GL_LINES); tessellator.addVertex(posX, posY, posZ); tessellator.addVertex(Coord.blockX, Coord.blockY, Coord.blockZ); tessellator.draw(); GL11.glDepthMask(true); GL11.glPopAttrib(); } } I thought this would work but it doesn't go to the block. I see it on the right side buts it looks like it is just a small length I think it may be the second vertex and the coords are not right?
March 4, 201411 yr Hi Which method are you drawing this in? the coordinates of the origin are often different. In many of them, the origin is set to the player's eyes (0,0,0). So if you are using block coordinates, you need to subtract the player position EntityPlayer.getPosition(partialTick); can be useful for that. so to draw from a block coordinate to the player's eyes, you would draw from [blockx-playerx, blocky-playery, blockz-playerz] to [0, 0, 0] A bit of trial and error often helps you guess the right offsets... -TGG
March 4, 201411 yr Author So I'm drawing this in a custom Item Render where it renders the model and the posX, posY, posZ are from EntityPlayer.pos.... So i would replace the pos... to 0, 0, 0, and subtract the pos.. from the block coords?
March 4, 201411 yr Ah, no the item renderers are different, they set the origin relative to the item (see http://greyminecraftcoder.blogspot.com.au/2013/09/custom-item-rendering-using.html) and it could be very tricky to figure out where the block goes relative to this origin I'd suggest moving your line rendering into the RenderWorldLast event. Then you get the player origin which you need; check to see if the player is holding the item. eg something like this @ForgeSubscribe public void drawSelectionBox(RenderWorldLastEvent event) { RenderGlobal context = event.context; assert(context.mc.renderViewEntity instanceof EntityPlayer); EntityPlayer player = (EntityPlayer)context.mc.renderViewEntity; ItemStack currentItem = player.inventory.getCurrentItem(); float partialTick = event.partialTicks; if (currentItem != null && currentItem.getItem() == myItemWhichDrawsLines) { MovingObjectPosition target = currentItem.getItem().getMovingObjectPositionFromPlayer(player.worldObj, player, true); // check target to see if it's a block, if so take the coordinates and subtract the EntityPlayer.getPosition and draw to 0,0,0 } -TGG
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.