Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED... KIND OF]Stencil buffer cuts everything
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Lucius Q. User

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

By Lucius Q. User, July 1, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Lucius Q. User    1

Lucius Q. User

Lucius Q. User    1

  • Tree Puncher
  • Lucius Q. User
  • Members
  • 1
  • 25 posts
Posted July 1, 2017 (edited)

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.glEnable(GL11.GL_STENCIL_TEST);
	GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF);
	GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
	GL11.glStencilMask(0xFF);
	GL11.glDepthMask(false);
	GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
	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();
	tessellator.draw();
	GL11.glStencilFunc(GL11.GL_EQUAL, 1, 0xFF); 
	GL11.glStencilMask(0x00);
	GL11.glDepthMask(true);
}

Here is the actual drawing code:

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

 

Edited July 1, 2017 by Lucius Q. User
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 13991 posts
Posted July 1, 2017

You would have to reset the stencil buffer.

  • Quote

Share this post


Link to post
Share on other sites

Lucius Q. User    1

Lucius Q. User

Lucius Q. User    1

  • Tree Puncher
  • Lucius Q. User
  • Members
  • 1
  • 25 posts
Posted July 1, 2017

Sorry, what? I have just set it up and it cuts everything drawn while it is active.

  • Quote

Share this post


Link to post
Share on other sites

Elix_x    75

Elix_x

Elix_x    75

  • Dragon Slayer
  • Elix_x
  • Members
  • 75
  • 878 posts
Posted July 1, 2017 (edited)

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

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

Edited July 1, 2017 by Elix_x
Added link to stencil buffer creation with Forge
  • Quote

Share this post


Link to post
Share on other sites

Lucius Q. User    1

Lucius Q. User

Lucius Q. User    1

  • Tree Puncher
  • Lucius Q. User
  • Members
  • 1
  • 25 posts
Posted July 1, 2017 (edited)

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

 

EDIT:

The problem is as follows:

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

setUpStencil(...)

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

disableStencil()

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

Edited July 1, 2017 by Lucius Q. User
  • Quote

Share this post


Link to post
Share on other sites

Elix_x    75

Elix_x

Elix_x    75

  • Dragon Slayer
  • Elix_x
  • Members
  • 75
  • 878 posts
Posted July 2, 2017

When stencils don't work for me right away, i usually enable the color write and draw the stencil'ed region with colors, then i go into debug mode and play with it until i get it to work.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • yegor
      [1.12.2] Transparent armor not rendering properly.

      By yegor · Posted 45 minutes ago

      In my mod I have transparent armor which I created with an "ArmorSlime" class, which extends ItemArmor. The item texture for my armor is slightly transparent and it renders correctly, even in item frames.   The armor model uses a slightly transparent texture, which works on the player model, but when I place the armor on an armor stand, it is rendered fully opaque.   Is this a mod issue, or an issue with minecraft itself? Is there a solution?  
    • yegor
      moving topic to just modding support

      By yegor · Posted 50 minutes ago

      Moved
    • J0WAY
      [1.12.2] How do i make it so my sword renders in my mobs hand?.

      By J0WAY · Posted 56 minutes ago

      Okay, But my main problem is why won't my sword spawn on my mob because i did just change it to the vanilla code and it still doesn't work.  
    • thedarkcolour
      [1.14] Patching method with coremod in TreeFeature causes IncompatibleClassChangeError

      By thedarkcolour · Posted 3 hours ago

      https://github.com/thedarkcolour/Future-MC/tree/1.14
    • Draco18s
      [1.14] layout of a modpack

      By Draco18s · Posted 3 hours ago

      I'm pretty sure I've left some comments on his videos about the mistakes he's perpetuating, but its not like anyone reads those.
  • Topics

    • yegor
      0
      [1.12.2] Transparent armor not rendering properly.

      By yegor
      Started 44 minutes ago

    • yegor
      0
      moving topic to just modding support

      By yegor
      Started 50 minutes ago

    • J0WAY
      2
      [1.12.2] How do i make it so my sword renders in my mobs hand?.

      By J0WAY
      Started 5 hours ago

    • thedarkcolour
      15
      [1.14] Patching method with coremod in TreeFeature causes IncompatibleClassChangeError

      By thedarkcolour
      Started 21 hours ago

    • JetCobblestone
      4
      [1.14] layout of a modpack

      By JetCobblestone
      Started 9 hours ago

  • Who's Online (See full list)

    • plugsmustard
    • J0WAY
    • imacatlolol
    • Itz_Yuseix
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED... KIND OF]Stencil buffer cuts everything
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community