Here's the code:
struct vertexData{
float position[3];
float normal[3];
float tangent[3];
float color[3];
float uv[2];
};
struct vertexID{
unsigned int id[3];
};
vertexData quad[4];
quad[3].position[0] = -1.0f;
quad[3].position[1] = 1.0f;
quad[3].position[2] = 0.0f;
quad[3].normal[0] = -1.0f;
quad[3].normal[1] = -0.0f;
quad[3].normal[2] = 0.0f;
quad[3].uv[0] = 0.0f;
quad[3].uv[1] = 1.0f;
quad[2].position[0] = 1.0f;
quad[2].position[1] = 1.0f;
quad[2].position[2] = 0.0f;
quad[2].normal[0] = -1.0f;
quad[2].normal[1] = -0.0f;
quad[2].normal[2] = 0.0f;
quad[2].uv[0] = 1.0f;
quad[2].uv[1] = 1.0f;
quad[1].position[0] = 1.0f;
quad[1].position[1] = -1.0f;
quad[1].position[2] = 0.0f;
quad[1].normal[0] = 1.0f;
quad[1].normal[1] = 0.0f;
quad[1].normal[2] = 0.0f;
quad[1].uv[0] = 1.0f;
quad[1].uv[1] = 0.0f;
quad[0].position[0] = -1.0f;
quad[0].position[1] = -1.0f;
quad[0].position[2] = 0.0f;
quad[0].normal[0] = -1.0f;
quad[0].normal[1] = -0.0f;
quad[0].normal[2] = 0.0f;
quad[0].uv[0] = 0.0f;
quad[0].uv[1] = 1.0f;
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,4*sizeof(vertexData), &quad,GL_STATIC_DRAW);
vertexID id[2];
id[0].id[0] = 0;
id[0].id[1] = 1;
id[0].id[2] = 2;
id[1].id[0] = 0;
id[1].id[1] = 2;
id[1].id[2] = 3;
glGenBuffers(1,&vbo2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,vbo2);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(unsigned int),&id,GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
What exacly is that variable i created called id what holds those index numbers? I don't quite get it.
I do understand one thing that its for saving memory, for ... hmm building mesh?
Basically sorting out the vertices what are in same position?
I really dont like these things since im holding normal, color etc... data there and perhaps something would go wrong.
Perhaps normals&smoothing would be wrong but i guess thats up to mesh compiler to care for.
but one question and the reply for it could change my view point of them.
for example if im having complex transparent mesh what triangles i need to sort by nearest to far
basically i can change the triangle draw order in that id variable?
if thats not possible then i have get the idea of that GL_ELEMENT_ARRAY_BUFFER pretty wrong way.