Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Easy StencilTest

$
0
0

@UmiKOMPnMI4QrmG wrote:

I wrote a simple code, but the result was different from what I thought.

    glEnable(GL_STENCIL_TEST|GL_DEPTH_TEST);
	glClearStencil(0);
	glClearDepth(0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);


	float sabun = -10;

	glColor3f(1, 0, 0);
	glStencilFunc(GL_ALWAYS, 1, 0);
	glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
	planecreate(ofVec3f(0,0, sabun));

	sabun =0;

	glColor3f(0, 1,0);
	glStencilFunc(GL_ALWAYS, 0, 0);
	glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
	planecreate(ofVec3f(10, 10, sabun));

	sabun = 10;

	glColor3f(0, 0, 1);
	glStencilFunc(GL_EQUAL,2, 0);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	planecreate(ofVec3f(15, 15, sabun));


	glDisable(GL_STENCIL_TEST);

//

void  testApp::planecreate(ofVec3f v) {
	glBegin(GL_POLYGON);
	float x = 40;
	float y = 40;
	float z = v.z;

	glVertex3d(-x+ v.x,-y+v.y,z);
	glVertex3d(-x+ v.x, y + v.y,z);
	glVertex3d( x+ v.x, y + v.y, z);
	glVertex3d( x+ v.x,-y + v.y, z);
	glEnd();
}

I expected that the blue panel had been scraped off...

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles