1

解決すべき OpenGL の問題があります。オブジェクト/メッシュ A、オブジェクト/メッシュ B、背景テクスチャ C があります。

最初に、フレーム バッファは背景テクスチャ C で満たされます。フレーム バッファに A と B の両方を描画します。オブジェクト A を常に表示しておき、オブジェクト B を常に非表示にします。

最初は、A が B の前にあります。回転中、ある角度で、深度テストの結果に基づいて、B は A の前にありますが、B は常に見えないため、B の部分は背景 C で埋められるはずです。

この問題を解決する簡単な方法を知っている人はいますか?

ステンシルテストは良いアプローチですか? 基本的にオブジェクト B に色を設定し、B の色を背景 C と比較し、テストが失敗したときに背景 C を表示します。

私が読めるサンプルコードはありますか?

4

1 に答える 1

2

The easiest solution is to:

  1. draw C;
  2. draw B with the colour mask preventing writes to the frame buffer (but don't touch the depth mask, so that writes are still made to the depth buffer);
  3. draw A, subject to the depth test.

The specific thing to use is glColorMask — if you supply GL_FALSE for each channel via that then subsequent geometry won't write any colour output. But assuming you haven't touched glDepthMask it'll still write depth output.

So, you've probably currently got the code:

drawBackground(C);
render(A);
render(B);

You'd just adapt that to:

drawBackground(C);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
render(B);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
render(A);
于 2015-05-29T17:47:34.787 に答える