Jump to content

[Solved] Rendering a NURBS Curve


Bedrock_Miner

Recommended Posts

Heyho Guys!

I searched for a method to draw NURBS Curves with GL. The problem is: I googled a bit and it told me that I can use the method GLU.newNurbsRenderer(). The problem is that this method doesnt exist. How can I draw one of these curves? Or is there another way of drawing Curves which are formed with controlpoints like the nurbs curve?

Link to comment
Share on other sites

This looks quite useful, but I still cannot find out where the needed method gluNewNurbsRenderer is implemented. Either I'm totally blind or it doesn't exist in GLU.class or anywhere else.

 

Edit:

Looks like NURBS are not supported by this version of lwjgl. Take a look over here. Damn.. seems like I have to implement my own methods for this.

I have no Idea how this works but I'll try.

Link to comment
Share on other sites

This looks quite useful, but I still cannot find out where the needed method gluNewNurbsRenderer is implemented. Either I'm totally blind or it doesn't exist in GLU.class or anywhere else.

Being a NURBS noob I'm for sure no expert but it looks to me like you can either use the glu methods, or the OpenGL 1.1 glMap2f methods.

i.e. you don't need the glu methods.

(Or - do the matrix maths yourself to generate the patches manually, if you don't go crazy on the number of patches it should be plenty fast enough)

 

-TGG

Link to comment
Share on other sites

@SideOnly(Side.CLIENT)
public void renderToCodex(GuiCodexMagicum gui, Minecraft mc, int x, int y) {
	if (Codex.getStatusFor(mc.thePlayer, this) > 0) {
		mc.getTextureManager().bindTexture(this.icons);
		GLUtil.resetColour();
		GL11.glDisable(GL11.GL_LIGHTING);
		gui.drawTexturedModalRect(x, y, (Codex.getStatusFor(mc.thePlayer, this) - 1) * 26, this.hasSpecialLayout ? 26 : 0, 26, 26);
		if (this.isIconItem) {
			gui.drawItemStack(this.iconItem, x + 5, y + 5, "");
		} else {
			mc.getTextureManager().bindTexture(this.labels);
			gui.drawTexturedModalRect(x + 5, y + 5, this.iconX * 16, this.iconY * 16, 16, 16);
		}

		GL11.glDisable(GL11.GL_LIGHTING);
		if (Codex.getStatusFor(mc.thePlayer, this) == 1) {
			GLUtil.setColour(0, 0, 0);
		} else {
			GLUtil.setColour((this.lineColour >> 16) % 256, (this.lineColour >>  % 256, this.lineColour % 256);
		}
		GL11.glColor3f(0, 1, 0);
		for (Vertex2D[] line : this.lines) {
			if (line.length > 2) {
				this.renderBezier(gui, line, x - this.getX(), y - this.getY());
			} else {
				GL11.glBegin(GL11.GL_LINE);
				GL11.glVertex3d(line[0].x + x - this.getX(), line[0].y + y - this.getY(), gui.getZLevel() - 2);
				GL11.glVertex3d(line[1].x + x - this.getX(), line[1].y + y - this.getY(), gui.getZLevel() - 2);
				GL11.glEnd();
			}
		}
	}
}

private void renderBezier(GuiCodexMagicum gui, Vertex2D[] controlpoints, int x, int y) {
	FloatBuffer buf = BufferUtils.createFloatBuffer(controlpoints.length * 6);
	for (int i = 0; i < controlpoints.length; i ++) {
		buf.put(i*3, (float) controlpoints[i].x + x);
		buf.put(i*3+1, (float) controlpoints[i].y + y);
		buf.put(i*3+2, gui.getZLevel() - 2);
		buf.put(i*3+3, (float) controlpoints[i].x + x);
		buf.put(i*3+4, (float) controlpoints[i].y + y);
		buf.put(i*3+5, gui.getZLevel() - 2);
	}
	GL11.glMap1f(GL11.GL_MAP1_VERTEX_3, 0.0f, 1.0f, 3, 4, buf);
	GL11.glEnable(GL11.GL_MAP1_VERTEX_3);
	GL11.glBegin(GL11.GL_LINE_STRIP);
	for (int i = 0; i < 24; i ++) {
		GL11.glEvalCoord1f(i / 24.0f);
	}
	GL11.glEnd();
}

Link to comment
Share on other sites

I am no expert, but maybe, try using GL11.glColor4f(1, 1, 1, 1); this will enable red, green, blue, and alpha (transparency) I saw you had GL11.glColor3f(0, 1, 0); I have never used this one, but I'm logically assuming that is red, green and blue. so this is only enabling green. But weirdly, you said green is the only one not working. Maybe it is somehow inverted? try setting that 1 to a 0, or all of them to 1.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

If I write this piece of code at the beginning of the method, the line is in a very dark green. Maybe this helps you..

		GL11.glDisable(GL11.GL_LIGHTING);
		if (Codex.getStatusFor(mc.thePlayer, this) == 1) {
			GLUtil.setColour(0, 0, 0);
		} else {
			GLUtil.setColour((this.lineColour >> 16) % 256, (this.lineColour >>  % 256, this.lineColour % 256);
		}
		GL11.glColor3f(0, 1, 0);
		for (Vertex2D[] line : this.lines) {
			if (line.length > 2) {
				this.renderBezier(gui, line, x - this.getX(), y - this.getY());
			} else {
				GL11.glBegin(GL11.GL_LINE);
				GL11.glVertex3d(line[0].x + x - this.getX(), line[0].y + y - this.getY(), gui.getZLevel() - 2);
				GL11.glVertex3d(line[1].x + x - this.getX(), line[1].y + y - this.getY(), gui.getZLevel() - 2);
				GL11.glEnd();
			}
		}
	}
}

 

If I use only this piece of code, without the rest, nothing is rendered. Is it possible that the Lines are rendered with the actual texture? Its the Purple/Black Missing Texture, this would explain the green colour problem.

How can I disable the texture, if this is the problem?

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



×
×
  • Create New...

Important Information

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