I'm trying to genereate a plane consisting of 9 squares using vertex lists. It works when I fill in all the coordinates manually but when I try to generate them instead it wont work. Nothing shows.
I've checked the generated list and all numbers are correct.
glShadeModel(GL_FLAT);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
vector<int> vertexV;
short vertex[48];
if ( initChess == false)
{
for (int i = 0; i<4;i++){
for (int j = 0; j<4;j++){
int X = -6+i*4;
int Y = -5;
int Z = -6+j*4;
vertexV.push_back(X);
vertexV.push_back(Y);
vertexV.push_back(Z);
}
}
for (int i=0; i<48;i++){
vertex[i]= vertexV[i];
cout<<vertex[i]<<" "<<i<<endl;
}
initChess = true;
}
short indexQuads[]={
4,5,1,0,
5,6,2,1,
6,7,3,2,
8,9,5,4,
9,10,6,5,
10,11,7,6,
12,13,9,8,
13,14,10,9,
14,15,11,10,
}
GLfloat color[] = {
1.0f,1.0f,1.0f,
0.1f,0.1f,0.1f,
1.0f,1.0f,1.0f,
0.1f,0.1f,0.1f,
0.1f,0.1f,0.1f,
1.0f,1.0f,1.0f,
0.1f,0.1f,0.1f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
0.1f,0.1f,0.1f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
1.0f,1.0f,1.0f,
}
glVertexPointer(3,GL_SHORT,0,&vertex)
glColorPointer(3,GL_FLOAT,0,&color)
glDrawElements(GL_QUADS,4,GL_UNSIGNED_SHORT,&indexQuads)
}
What I've done is pushing in the numbers I generate in to a vector and then take each element of the vector nad puts it in my short list.
As can be seen I've also written all numbers of the listto the cmd window to see that they are indeed correct.