Can't get stencil testing to work

Started by fictiveLaark, June 17, 2010, 12:10:51

Previous topic - Next topic

fictiveLaark

I'm not sure how I can get any more direct than this method, I enable stencil testing, set the stencil function to always fail, and it still draws the rectangle.

public static void drawFilledRectangle(Rectangle.Float toDraw) {
		GL11.glEnable(GL11.GL_STENCIL_TEST);
		GL11.glStencilFunc(GL11.GL_NEVER, 1, 1);
		GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glVertex2f(toDraw.x, toDraw.y);
			GL11.glVertex2f(toDraw.x + toDraw.width, toDraw.y);
			GL11.glVertex2f(toDraw.x + toDraw.width, toDraw.y + toDraw.height);
			GL11.glVertex2f(toDraw.x, toDraw.y + toDraw.height);
		GL11.glEnd();
		
		GL11.glDisable(GL11.GL_STENCIL_TEST);
	}

Ciardhubh

You have to create the display with a pixel format that has a stencil buffer, e.g.
Display.create(new PixelFormat(0, 8, 1)); // 1 bit stencil buffer

If you're looking for a working example: http://ciardhubh.de/node/13 . It's example 10-1 in the source code (http://ciardhubh.de/download/node/13/lwjgl_redbook_examples_src_2010-05-29.zip); basically the stencil test example from the Redbook in LWJGL.

fictiveLaark