I am new to openGL. I use the documentation on apples as the main referee http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html/dl8fle / doc / doc / doc / SW6
My problem is that I'm using openGL ES 1.1 , not 2 , so the functions used in Listing 9-3, such as glVertexAttribPointer , glEnableVertexAttribArray, are not recognized ... :)
I am trying to do the optimization described in this documentation: hold indexes and a vertex as a structure with all its data: position, color (Listing 9-1)
typedef struct _vertexStruct { GLfloat position[3]; GLubyte color[4]; } VertexStruct; const VertexStruct vertices[] = {...}; const GLushort indices[] = {...};
and use VBOs such as in Listing 9-2, 9-3
As I mentioned, some features that are used there do not exist in openGL ES 1.1. I am wondering if there is a way to do the same in ES 1.1, perhaps with some other code?
thanks Alex
Edit according to Christians the answer, tried to use glVertexPointer, glColorPointer. Here is the code, it prints a cube, but without colors ... :(. Anyone, is it possible to use VBOs in such a scale 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); }