0

画面の左下隅にテクスチャをレンダリングしようとしているので、次のようになります。

glViewPort(0, 0, width/4, height/4);

そのレンダリングの実行に問題があります。四角形を描き、いくつかの基本的なことを行います。SOのこれらのリンクや他のリンクで説明されているように、クワッドへのレンダリングのすべてのバリアントを試しました:

OpenGL ES 2.0 でテクスチャを 2D 背景として描画するには?

テクスチャを使用した OpenGL ES 2.0 レンダリング

私の頂点シェーダーとフラグメントシェーダーは次のとおりです。

const char * VERTEX_SHADER =
"                                               \n\
attribute vec4 a_position;                      \n\
attribute vec4 a_texCoord;                      \n\
                                                \n\
                                                \n\
#ifdef GL_ES                                    \n\
varying mediump vec2 v_texCoord;                \n\
#else                                           \n\
varying vec2 v_texCoord;                        \n\
#endif                                          \n\
                                                \n\
void main()                                     \n\
{                                               \n\
    gl_Position = a_position;                   \n\
    v_texCoord = a_texCoord.xy;                 \n\
}                                               \n\
";


const char * FRAGMENT_SHADER =
"                                                       \n\
#ifdef GL_ES                                            \n\
precision lowp float;                                   \n\
#endif                                                  \n\
                                                        \n\
varying vec2 v_texCoord;                                \n\
uniform sampler2D u_texture;                            \n\
                                                        \n\
void main()                                             \n\
{                                                       \n\
    gl_FragColor =  texture2D(u_texture, v_texCoord);   \n\
}                                                       \n\
";

そして私のレンダリングコードはこれです:

static const GLfloat squareVertices[] = {
    -1.0f, -1.0f,
     1.0f, -1.0f,
    -1.0f,  1.0f,
     1.0f,  1.0f,
};

static const GLfloat textureVertices[] = {
    0.0f, 0.0f,
    1.0f, 0.0f,
    0.0f, 1.0f,
    1.0f, 1.0f,
};


// ...

glUseProgram(myProgram_);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewPort(0, 0, width/4, height/4);  // width and height are defined elsewhere

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, myTexture_); // myTexture_ has been successfully loaded and checked

// Update uniform values
glUniform1i(textureUniformLocation_, 0);

// Update attribute values.
glEnableVertexAttribArray(a_position_location_);
glEnableVertexAttribArray(a_texcoord_location_);
glVertexAttribPointer(a_position_location_, 2, GL_FLOAT, 0, 0, squareVertices);
glVertexAttribPointer(a_texcoord_location_, 2, GL_FLOAT, 0, 0, textureVertices;

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

頂点シェーダーとフラグメント シェーダーがコンパイルされ、glProgram が正常にリンクされます。私が得ているのは、画面の左下にある白い長方形だけです (もちろん、既にレンダリングされたシーンの上にあります)。ここで何か不足していますか?

4

2 に答える 2

0

縮小フィルターの設定を忘れていませんか?テクスチャを画像として保存しても、おそらくこのようなサンプリング エラーは警告されません。

http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture

于 2012-06-20T01:21:35.570 に答える