I'm trying to render a texture to the bottom left corner of the screen, so something like:
glViewPort(0, 0, width/4, height/4);
I'm having trouble performing that rendering. I draw a quad and do some basic stuff. I've tried all variants of rendering to a quad as discussed in these links and others on SO:
How to draw a texture as a 2D background in OpenGL ES 2.0?
OpenGL ES 2.0 Rendering with a Texture
My vertex and fragment shaders are as follows:
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\
";
And my rendering code is this:
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);
The vertex and fragment shaders compile and the glProgram links successfully. All I'm getting is a white rectangle in the bottom left of my screen (on top of the already rendered scene, of course). Am I missing something here?
vec2
fora_texCoord
. Also make sure all tests (depth, scissor, etc.) are off. IfglGetError()
is 0, it's probably a test or clipping. – Todd Christensen