Hey, i am trying out opengl es for 3d rendering and using edgelib for the remaining framework and 2d rendering.. now i am an opengl noob so maybe this is an opengl mistake by me or something else but i cant get it to run.. my calls to glDrawElements are crashing with an access violation.. but if i try using glBegin/glEnd then it works fine.. here is my code:
Variable declaration:
For loading vertex and index arrays:
For rendering:
As i thought some un needed states were on i have tried disabling them but to vain..
and strangely enough this code works and renders perfectly:
Variable declaration:
- Code:
GLshort* vertices;
GLushort* indices;
unsigned long vertexCount;
unsigned long indexCount;
For loading vertex and index arrays:
- Code:
E3DSURFACEINFO surfInfo;
surf->Lock(&surfInfo);
indexCount = surf->PolygonsInUse()*3;
indices = new GLushort[indexCount];
vertices = new GLshort[surf->VerticesInUse()*3];
vertexCount=0;
EVERTEX3D vertex;
for (unsigned long i=0;i<surf->VerticesInUse();i++)
{
surf->GetVertex(i,&vertex);
vertices[vertexCount] = vertex.position.x;
vertices[vertexCount+1] = vertex.position.y;
vertices[vertexCount+2] = vertex.position.z;
vertexCount += 3;
}
for (unsigned long i=0;i<indexCount;i++)
indices[i] = surfInfo.indexarray[i]*3;
surf->Unlock();
For rendering:
- Code:
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_SHORT, 0, vertices );
glDrawElements( GL_LINES, indexCount, GL_UNSIGNED_SHORT, indices );
glDisableClientState(GL_VERTEX_ARRAY);
As i thought some un needed states were on i have tried disabling them but to vain..
and strangely enough this code works and renders perfectly:
- Code:
glBegin(GL_LINES);
for (int i=0;i<indexCount;i++)
glVertex3d(vertices[indices[i]], vertices[indices[i]+1], vertices[indices[i]+2]);
glEnd();