i am new to openGL. Iam using apple documentation as my major referens http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html#//apple_ref/doc/uid/TP40008793-CH107-SW6
My problem is that i am using openGL ES 1.1 and not 2 thus functions which are used in Listing 9-3 such as glVertexAttribPointer, glEnableVertexAttribArray are not recognized ... :)
I trying to make the optimizations which are described in this documentation: to hold indices and vertex as a struct with all of its data: position, color (Listing 9-1)
typedef struct _vertexStruct
{
GLfloat position[3];
GLubyte color[4];
} VertexStruct;
const VertexStruct vertices[] = {...};
const GLushort indices[] = {...};
and to use VBOs such as in Listing 9-2, 9-3
As i mentioned, some of the functions that are used there don't exists in openGL ES 1.1. I am wondering if there is a way to do the same in ES 1.1 maybe with some other code ?
thank, Alex
Edit according to Christians answer, tried to use glVertexPointer, glColorPointer. Here is the code, it prints the cube but no colors ... :(. Anyone, is it possible to use VBOs in such menner using ES 1.1
typedef struct {
GLubyte red;
GLubyte green;
GLubyte blue;
GLubyte alpha;
} Color3D;
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D;
typedef struct{
Vector3D position;
Color3D color;
} MeshVertex;
Cube Data:
static const MeshVertex meshVertices [] =
{
{ { 0.0, 1.0, 0.0 } , { 1.0, 0.0, 0.0 ,1.0 } },
{ { 0.0, 1.0, 1.0 } , { 0.0, 1.0, 0.0 ,1.0 } },
{ { 0.0, 0.0, 0.0 } , { 0.0, 0.0, 1.0 ,1.0 } },
{ { 0.0, 0.0, 1.0 } , { 1.0, 0.0, 0.0, 1.0 } },
{ { 1.0, 0.0, 0.0 } , { 0.0, 1.0, 0.0, 1.0 } },
{ { 1.0, 0.0, 1.0 } , { 0.0, 0.0, 1.0, 1.0 } },
{ { 1.0, 1.0, 0.0 } , { 1.0, 0.0, 0.0, 1.0 } },
{ { 1.0, 1.0, 1.0 } , { 0.0, 1.0, 0.0, 1.0 } }
};
static const GLushort meshIndices [] =
{ 0, 1, 2 ,
2, 1, 3 ,
2, 3, 4 ,
3, 5, 4 ,
0, 2, 6 ,
6, 2, 4 ,
1, 7, 3 ,
7, 5, 3 ,
0, 6, 1 ,
1, 6, 7 ,
6, 4, 7 ,
4, 5, 7
};
Function
GLuint vertexBuffer;
GLuint indexBuffer;
- (void) CreateVertexBuffers
{
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(meshVertices), meshVertices, GL_STATIC_DRAW);
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(meshIndices), meshIndices, GL_STATIC_DRAW);
}
- (void) DrawModelUsingVertexBuffers
{
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(MeshVertex), (void*)offsetof(MeshVertex,position));
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MeshVertex), (void*)offsetof(MeshVertex,color));
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glDrawElements(GL_TRIANGLE_STRIP, sizeof(meshIndices)/sizeof(GLushort), GL_UNSIGNED_SHORT, (void*)0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}