0

So I created a quad using glBegin(GL_QUADS) and then drawing vertices and now I want to pass into my shader an array of texture coordinates so that I can apply a texture to my quad.

So I'm having some trouble getting the syntax right.

First I made a 2D array of values

GLfloat coords[4][2];
coords[0][0] = 0;
coords[0][1] = 0;
coords[1][0] = 1;
coords[1][1] = 0;
coords[2][0] = 1;
coords[2][1] = 1;
coords[3][0] = 0;
coords[3][1] = 1;

and then I tried to put it into my shader where I have a attribute vec2 texcoordIn

GLint texcoord = glGetAttribLocation(shader->programID(), "texcoordIn");
glEnableVertexAttribArray(texcoord);
glVertexAttribPointer(texcoord, ???, GL_FLOAT, ???, ???, coords);

So I'm confused as to what I should put in for parameters to glVertexAttribPointer that I marked with '???' and I'm also wondering if I'm even allowed to represent the texture coordinates as a 2d array like I did in the first place.

user1782677
  • 1,963
  • 5
  • 26
  • 48

1 Answers1

0

The proper values would be

glVertexAttribPointer(
 texcoord,
 2, /* two components per element */
 GL_FLOAT,
 GL_FALSE, /* don't normalize, has no effect for floats */
 0, /* distance between elements in sizeof(char), or 0 if tightly packed */
 coords);

and I'm also wondering if I'm even allowed to represent the texture coordinates as a 2d array like I did in the first place.

If you write it in the very way you did above, i.e. using a statically allocated array, then yes, because the C standard asserts that the elements will be tightly packed in memory. However if using a dynamically allocated array of pointers to pointers, then no.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks for the help! I'm still having trouble though. It doesn't seem like my 2d 'coord' array is actually doing anything (the quad turns up blank). I'm pretty confident my internal shader code is correct. – user1782677 Feb 09 '13 at 01:21
  • @user1782677: Only way to tell would be, if you posted your shaders' code. – datenwolf Feb 09 '13 at 01:24