Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

C#
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;
}

MSIL
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.
Posted
Comments
CPallini 27-Oct-10 4:53am    
How did you pass the std::vector to the library (your 'manual' inputs are in a std::vector?)?
Sauro Viti 27-Oct-10 9:13am    
Look at the code: he copied the entire content of the std::vector to a standard C-array and then he used that one...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900