Welcome on MasterOf13FPS! MasterOf13FPS

Register today or sign up if you are already a member and never miss any cool content again :)

Help understanding the gl stencil buffer

lavaflowglow

New member
Joined
Dec 13, 2020
Messages
25
Reaction score
6
Points
0
Hello everybody, it's not often I make a post asking for help but decided it would be beneficial for me and potentially anybody in the future if I asked. I am currently a bit confused on how the stencil buffer works, I'm planning to use it for a clickgui but am trying to understand it before I start. As of right now my goal is to draw a small white box and then a large red box covering the screen, but I want the red box to not draw over the white one. I understand I can just draw the red box first and the other second but this is really only so I can understand how to use a stencil. I looked a bit online and on the forum and read a lot of documentation but for some reason my code isn't working, it's like the stencil doesn't exist at all. I'm assuming the problem has to do with minecraft itself and not opengl so I'm asking here, I put my code below, any help is appreciated

(Note for my code: The class containing the code extends off of mc guiscreen and is in the drawScreen method. Due to this, method calls like "drawRect" are just to minecraft's default drawRect method. Also the screenshots are of the middle of the screen, they're large enough to show both boxes but not the size of the full window)

Code: https://pastebin.com/ViLA7YUW
Result if I only draw the small box: https://aetherclient.com/uploads/lavaflowglow/f1610fe9b0.png
Result if I draw both boxes: https://aetherclient.com/uploads/lavaflowglow/b9c8224da9.png
Result if I draw both boxes but set the stencil test to never pass before drawing the red box: https://yiffing.zone/c4ab76ffd0

Again any help is appreciated, thanks in advance
 
I think it's an issue with minecraft. A while ago I used stencils to crop an image to a circle in minecraft. Recently I tried to use the same code and it didn't work.
 
To avoid confusion I made the center box purposely a different tone of red, and the background box color white.

After a while of messing around it was simply minecraft messing with the colors.

My first attempt was to use glColorMask() to make sure the red box's colors are rendered.

Java:
glColorMask(true, true, true, true);
glColor3f(255,255,255);
Gui.drawRect(screen.getScaledWidth()/2-40, screen.getScaledHeight()/2-40, screen.getScaledWidth()/2+40, screen.getScaledHeight()/2+40, new Color(210,100,80).getRGB());
glColorMask(false, false, false, false);

After a while though, the background turned black. 🤔

I decided I would disable the color mask after the white background was rendered:

Java:
glColor3f(255,255,255);
drawRect(0, 0, width, height, -1);
glColorMask(false, false, false, false);

It seemed to have worked without issue!

Screenshot_20220521_151337.png

Honestly not sure why this is but it fixed the issue that the background would go black after a while

Resulting code:

Pastebin

Hope this helps :)
 
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top