I'm new to OpenGL-ES and have started working my way through Buck's Learning OpenGL ES for iOS book.
Chapter 2 covers drawing triangles with a solid color, and chapter 3 moves on to use textures.
As a personal learning exercise, I'm trying to alter the sample code to draw two triangles; one with the texture, the other solid.
Seems like a very basic exercise, but one that - as an OpenGL-ES beginner - is proving tricky.
So far I've tried a combination of things.
First, I prepare to draw with GLKVertexAttribPosition
, then GLKVertexAttribTexCoord0
. I then draw my vertex buffer with triangle 1.
Next, I've tried a couple of things, including:
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
and
GLuint name = self.textureInfo0.name;
glDeleteTextures(1, &name);
prior to then drawing the colour attributes:
[self.vertexBuffer prepareToDrawWithAttrib:GLKVertexAttribColor
numberOfCoordinates:3
attribOffset:offsetof(SceneVertex, colours)
shouldEnable:YES];
You can see in the screenshot that the bottom left triangle has the texture blended with the vertex color attributes. The right triangle - that makes the square - is completely black.
Note that the prepareToDrawWithAttrib
method calls are Buck's utility classes that principally call the glVertexAttribPointer
method.
It's important to note that I'm using GLKit here, so no shaders or any of that stuff.
Here's the screenshot:
Any thoughts much appreciated.