Here are my shaders...

 GLbyte vShaderStr[] = "attribute vec4 vPosition;   \n"
 "attribute vec2 texPosition; \n"
 "attribute vec4 inColor;   \n"
 "varying vec4 fragColor;   \n"
 "varying vec2 v_texCoord;     \n"
 "void main()                 \n"
 "{                           \n"
 "   gl_Position = vPosition; \n"
 "   fragColor = inColor; \n"
 "   v_texCoord = texPosition; \n"
 "}                           \n";

GLbyte fShaderStr[] =
  "precision mediump float;                            \n"
  "varying vec2 v_texCoord;                            \n"
  "uniform sampler2D s_texture;                        \n"
  "void main()                                         \n"
  "{                                                   \n"
  "  gl_FragColor = texture2D( s_texture, v_texCoord );\n"
  "}                                                   \n";

And here is my code...

GLfloat gObj[18] = {
  0.5f, 0.5f, 0.0f,
  -0.5f, -0.5f, 0.0f,
  0.5f, -0.5f, 0.0f,
  0.5f, 0.5f, 0.0f,
  -0.5f, 0.5f, 0.0f,
  -0.5f, -0.5f, 0.0f
GLuint textureId;

GLubyte bytePix[4 * 3] ={
        255, 0, 0,
        0, 255, 0,
        0,0, 255,
GLfloat texC[] = {
            0.0f, 0.0f,
            0.0f, 1.0f,
            1.0f, 1.0f,
            1.0f, 0.0f
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, bytePix);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, gObj);
glVertexAttribPointer(textCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, texC);

glUniform1i(sampler, 0 );
glDrawArrays(GL_TRIANGLES, 0, 6);

But when I run the app I see the following...


This seems wrong, how can I make it so each quadrant of the square is the color in the texture. Of course I could always be misunderstanding textures in general.


closed as too localized by msell, Nicol Bolas, Josh, Anko, MichaelHouse Jun 6 '13 at 18:02

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.


You have six vertices (correctly) but only four texture coordinate pairs, so the last two are undefined. You must specify matching texture coordinates for each vertex, including the repeated ones.

  • \$\begingroup\$ Thats what I thought and I did finally figure it out but it was based of some sample code so that is what threw me. The sample code used DrawElement instead and reused verts. There also was something to be said about the relation to texture cords order and vertex cords order, as well as, text cords order vs orientation. But that is probably too broad here. \$\endgroup\$ – Jackie Jun 6 '13 at 18:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.