これらの2つのコードが同じ結果をもたらさない理由はわかりません。私は、デプステストやステンシルテストを有効にしているし、私のメインループは次のようになります。単純なケースでのステンシルバッファの振る舞い(GL_ALWAYS、GL_LEQUAL)
myShader.Use() // Use shader program
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// define model, projection, view, ....
glBindVertexArray(VAO[0]);
glStencilMask(0xFF); // Enable stencil buffer writing
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
drawCube(&myShader, model, projection, view);
glBindVertexArray(0);
明らかに、私のキューブが、この場合にレンダリングします。私はこのコードを使用する場合、何もすべてでレンダリングしていない
しかし、:
myShader.Use() // Use shader program
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// define model, projection, view, ....
glBindVertexArray(VAO[0]);
glStencilMask(0xFF); // Enable stencil buffer writing
glStencilFunc(GL_LEQUAL, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
drawCube(&myShader, model, projection, view);
glBindVertexArray(0);
私のシーンで唯一のオブジェクトを使用すると、両方のコードでは、同じように動作する必要があります。しかし、それはしません。
私はステンシルバッファのデフォルト値と関係があると考えました。私はこれを行う前に、ステンシルバッファをクリアしていますので、デフォルト値は、このコードで、ちなみに0
する必要があり、キューブは、同様にレンダリング:
myShader.Use() // Use shader program
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// define model, projection, view, ....
glBindVertexArray(VAO[0]);
glStencilMask(0xFF); // Enable stencil buffer writing
glStencilFunc(GL_LEQUAL, 0, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
drawCube(&myShader, model, projection, view);
glBindVertexArray(0);
私はしないでください起こっていることを理解する。