KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Can I have Stencil prepared with a texture (Image) in OpenGL 2.0 So that some part of the Image will be transparent and as a result it will be transfered as is to Stencil buffer and then will use this use this stencil buffer for further drawing. EDIT by datenwolf to account for OPs question update in a answer: By @InfiniteLoop: @datenwolf thanks a lot for ur reply but no success :( here is my code - (void)render { [EAGLContext setCurrentContext:context]; glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); glUseProgram(program); glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0); glViewport(0, 0, backingWidth, backingHeight); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Set the stencil clear value glClearStencil ( 0x1 ); // Set the depth clear value glClearDepthf( 0.75f ); //////// //// GLfloat threshold = 0.5f;//half transparency /* the order in which orthogonal OpenGL state is set doesn't matter */ glEnable(GL_STENCIL_TEST); glEnable(GL_ALPHA_TEST); /* don't write to color or depth buffer */ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); /* first set alpha test so that fragments greater than the threshold will pass thus will set nonzero bits masked by 1 in stencil */ glStencilFunc(GL_ALWAYS, 1, 1);//set one glAlphaFunc(GL_GREATER, threshold);//greater than half transparency glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, fullVertices); glVertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, 0, colorVertices); glVertexAttribPointer(textureLoc, 2, GL_FLOAT, GL_FALSE, 0, textureVertices); [self drawTexture:texture2DMaskImage]; /* second pass of the fragments less or equal than the threshold will pass thus will set zero bits masked by 1 in stencil */ glStencilFunc(GL_
Tags (comma-separated)
Save Edits
Cancel