Jump to content

[SOLVED... KIND OF]Stencil buffer cuts everything

Lucius Q. User

Recommended Posts

EDIT: I switched to using scissor test.

I am trying to set up stencil buffer to cut everything that gets drawn outside of a specific rectangle in the gui. Instead, everything that is drawn after the stencil buffer is set up gets cut;

Here is the stencil set up code:

public static void setUpStencil(int left, int top, int right, int bottom) {
	if (left < right) {
		int i = left;
		left = right;
		right = i;

	if (top < bottom) {
		int j = top;
		top = bottom;
		bottom = j;
	Tessellator tessellator = Tessellator.getInstance();
	VertexBuffer vertexbuffer = tessellator.getBuffer();
	GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF);
	GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
	vertexbuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
	vertexbuffer.pos(left, bottom, 0.0D).endVertex();
	vertexbuffer.pos(right, bottom, 0.0D).endVertex();
	vertexbuffer.pos(right, top, 0.0D).endVertex();
	vertexbuffer.pos(left, top, 0.0D).endVertex();
	GL11.glStencilFunc(GL11.GL_EQUAL, 1, 0xFF); 

Here is the actual drawing code:

setUpStencil(20, 20, width - 20, height - 20);
drawRect(0, 0, 50, 65); //Some drawRect calls here


Edited by Lucius Q. User
Link to comment
Share on other sites

You would have to reset the stencil buffer.

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

Make sure that you enabled (created) stencil buffer. By default, MC does not create one.

Alternatively, because you're in 2D, use scissors.

Edited by Elix_x
Added link to stencil buffer creation with Forge
Link to comment
Share on other sites

I did enable it. The problem is not that it is not cutting anything, but rather that it cuts too much.



The problem is as follows:

drawRect(...)// <- gets drawn


drawRect(...) // <- gets cut entirely (should get cut only partially)


drawRect(...) // <- gets drawn

Edited by Lucius Q. User
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.

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.


  • Create New...

Important Information

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