Drawing using Vertex buffer objects in OpenGL ES 1.1 vs ES 2.0

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); } 
+4
source share
1 answer

Functions such as glVertexAttribPointer and glEnableVertexAttribArray are used for common user vertex attributes (which are the only supported method for sending vertex data in OpenGL ES 2.0).

When using a fixed-function pipeline (as in OpenGL ES 1.1), you simply use the built-in attributes (think of the glVertex and glColor calls that you could use before switching to vertex arrays). There are functions for each attribute that are called similar to their direct copies, for example glVertexPointer or glColorPointer (instead of glVertexAttribPointer ). These arrays are turned on / off by calling gl(En/Dis)ableClientState with constants like GL_VERTEX_ARRAY or GL_COLOR_ARRAY (instead of gl(En/Dis)ableVertexAttribArray ).

But as a rule, you should not learn programming OpenGL ES 1.1 with resources 2.0, since most of the information is not suitable for you (at least if you are new to OpenGL). For example, some methods described on your linked site may not be supported in 1.1, such as VBOs or even VAO. But I also have to admit that I don't have ES experience, so I'm not quite sure about that.

EDIT: As for your updated code: I assume that no color means the cube has one color, possibly white. In your first code example, you used GLubyte color[4] , and now its some type Color3D , maybe this does not correspond to the call to glColorPointer(4, GL_UNSIGNED_BYTE, ...) (where the first argument is the number of components and the second is the type)?

If your Color3D type contains only 3 colors or floating-point colors, I would still suggest you use 4-ubyte colors, because together with 3 floats for a position, you should get a vertex ideally oriented at 16 bytes, which is also an optimization. which they offer in your provided link.

And by the way, repeating the creation of the index buffer in your CreateVertexBuffers function CreateVertexBuffers more of a typo, right?

EDIT. . Your colors contain ubytes (from 0 (black) to 255 (full color)), and you initialize them with floats. Thus, your float 1.0 (which should mean full color) is converted to ubyte, and you get 1, which is still very small compared to the entire range [0.255], so everything is black. When you use ubytes, you must also initialize them with ubytes, so just replace every 0.0 0 and every 1.0 with 255 in the color data.

And by the way, since you are using VBOs in ES 1.1 and at least something is drawn, ES ES seems to support VBOs. I did not know that. But I'm not sure if it also supports VAO.

And by the way, you should call glBindBuffer(GL_ARRAY_BUFFER, 0) and similarly for the buffer of the array of elements after you finish using them at the end of these two functions. Otherwise, you may run into problems in other functions that do not accept any buffers, but the buffers are still connected. Always remember that OpenGL is a state machine, and every state you set remains until it changes or the context is destroyed.

+4
source

All Articles