Hello my friends!!
This is my first post here, and I’m a complete newbie to OpenGL…so please be gentle
I’ve followed up some tutorials and I’m using: OpenGL 3.0, GSLM, GLEW, GLM and SOIL.
I’ve created a few triangles, rendered on screen, pretending it is a matrix of squares.
Something like the image bellow
I’ve created my class that generates the array for vertices (to populate my VBO), and for indices (to populate my EBO).
So I have my VAO with all the data that I want.
Now I want to add a texture just to one square (one pair of triangles), so I’ve created successfully my texture, and loaded with SOIL and bind it while rendering like this:
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture);
Now if I draw it like this:
glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(GLuint), GL_UNSIGNED_INT, 0); glBindVertexArray(0);
I see all my squares with the same texture…which makes sense :o
But now I want to add my texture to just one square… to be like this bellow:
So, I’ve tried using the
instead of the
#define BUFFER_OFFSET(i) ((char *)NULL + (i)) glDrawRangeElements (GL_TRIANGLES, 0, 6, 3, GL_UNSIGNED_INT, BUFFER_OFFSET(2));
But it doesn’t work
How can I tell openGL to just add the texture to just one of my triangles that are on the same VAO?
I have my vertices like:
[0, 1, 0, 1, 1, 0, …]
And my indices like:
[0, 1, 3, 1, 2, 3, …]
And I just want to add a texture to a set of 2 triangles (1 square).
Thank you in advance