iPhone プラットフォームで OpenGL es 2.0 を使用して、テクスチャ付きのクワッドを適切に表示する作業を行っています。ここのチュートリアルに従って始めました
http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/
これは基本的に単純な三角形を作成し、非常に単純なシェーダーを使用して画面に表示するだけです。Z軸で三角形を回転させると問題が発生します。
これは、回転を適用せず、Z 軸で 90 回転したときのトレイングルの外観です。
NEHE チュートリアル サイトのソース コード プロジェクトを使用しましたが、変更点は頂点シェーダーにワールド マトリックスを追加することだけです。
//the incoming vertex' position
attribute vec4 position;
//and its color
attribute vec3 color;
//the varying statement tells the shader pipeline that this variable
//has to be passed on to the next stage (so the fragment shader)
varying lowp vec3 colorVarying;
//added this matrix
uniform mat4 world;
//the shader entry point is the main method
void main()
{
colorVarying = color; //save the color for the fragment shader
gl_Position = world * position; //multiplied the matrix with the position
}
ピクセル シェーダーはすぐに色を付けます。
プログラムでは、次のようにワールド マトリックスを設定して渡します。
GLKMatrix4 _world = GLKMatrix4MakeRotation(1.5708, 0, 0, 1);
glUniformMatrix4fv(m_worldMat, 1, GL_FALSE, _world.m);
これは、この質問で問題を再現できる最も簡単な方法です。また、0 から画面の幅、0 から画面の高さまでの正投影カメラを作成してみました。
-------------------q______bからの提案後の反復2--------------- ----
そのため、コードを編集して、正投影を作成しました。まず、三角形を長方形に変更しました。これが頂点の設定です
right = 0.75 * m_renderbufferWidth;
left = 0.25 * m_renderbufferWidth;
top = 0.55 * m_renderbufferHeight;
bottom = 0.45 * m_renderbufferHeight;
widthOver2 = (right - left) * 0.5;
heightOver2 = (bottom - top) * 0.5;
//push the vertex data into the buffer
//4 floats define one vertex (x, y, z and w), first one is lower left
geometryData.push_back(-widthOver2); geometryData.push_back(heightOver2 ); geometryData.push_back(1.0); geometryData.push_back(1.0);
//we go counter clockwise, so lower right vertex next
geometryData.push_back(widthOver2); geometryData.push_back(heightOver2); geometryData.push_back(1.0); geometryData.push_back(1.0);
//top left vertex is last
geometryData.push_back(-widthOver2); geometryData.push_back(-heightOver2); geometryData.push_back(1.0); geometryData.push_back(1.0);
//top right vertex is last
geometryData.push_back(widthOver2); geometryData.push_back(-heightOver2); geometryData.push_back(1.0); geometryData.push_back(1.0);
変更された描画コードは次のとおりです。正投影カメラが 0, 0 から画面の寸法になり、原点の周りに長方形を作成し、画面の中央に移動しました。
GLKMatrix4 temp = GLKMatrix4Identity;
GLKMatrix4 _world = GLKMatrix4Identity;
temp = GLKMatrix4Multiply(GLKMatrix4MakeTranslation(left + widthOver2, top + heightOver2, 0), GLKMatrix4MakeRotation(1.5708, 0, 0, 1));
_world = GLKMatrix4Multiply(GLKMatrix4MakeScale(1, 1, 1), temp);
glUniformMatrix4fv(m_worldMat, 1, GL_FALSE, _world.m);
GLKMatrix4 _projection = GLKMatrix4MakeOrtho(0, m_renderbufferWidth, 0, m_renderbufferHeight , -100, 100);
glUniformMatrix4fv(m_projectionMat, 1, GL_FALSE, _projection.m);
//initiate the drawing process, we want a triangle, start at index 0 and draw 3 vertices
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
こちらが頂点シェーダー部分。
void main()
{
colorVarying = color; //save the color for the fragment shader
gl_Position = projection * world * position; //multiplied the matrix with the position
}
私はまだ同じ問題に直面しています。2つ以上のリンクを投稿するのに十分な担当者がいないため、元の投稿のリンクを最新のスクリーンショットで更新しました
助けてください。これまでの提案と助けに感謝します。