// Each display list will be named models[x]int models[5];// Vertices for drawing modelsstatic float vertices[12][3] ={ { 1, 0, 0 }, // Vertex 0 { 1, 0, -1 }, // Vertex 1 { 0, 0, -1 }, // Vertex 2 { 5, 0, 0 }, // Vertex 3 { 5, 0, -1 }, // Vertex 4 { 1, 0, -1 }, // Vertex 5 { 0, 0, -5 }, // Vertex 6 { 1, 0, -5 }, // Vertex 7 { 1, 0, -1 }, // Vertex 8 { 5, 0, -1 }, // Vertex 9 { 5, 0, -5 }, // Vertex 10 { 1, 0, -5 } // Vertex 11};// Indices refering to the above list of vertices// Note the first entry indicates the number of useful entry pairs following// Zeros have been added at the end to make them all 17 entries longint indices[5][17] ={ {3,0,7,7,10,10,3,0,0,0,0,0,0,0,0,0,0}, // Display List 1 {2,0,8,9,3,0,0,0,0,0,0,0,0,0,0,0,0}, // Display List 2 {4,0,7,7,11,3,4,4,5,0,0,0,0,0,0,0,0}, // Display List 3 {5,6,11,0,1,1,2,3,4,4,5,0,0,0,0,0,0}, // Display List 4 {8,0,1,1,2,3,4,4,5,6,7,7,8,9,10,10,11} // Display List 5};void makeDisplayList ( int &list, int array[] ){ // Create display list list = glGenLists(1); glNewList(list, GL_COMPILE); // Draw stuff for ( int i = 0; i < array[0]; i++ ) { glBegin(GL_LINES); glVertex3fv( vertices[array[i*2+1]] ); glVertex3fv( vertices[array[i*2+2]] ); glEnd(); } glEndList();}// At initialisation, make display listsfor ( int i = 0; i < 5; i++ ) makeDisplayList ( models[i], indices[i] );// At rendering time, call themfor ( int i = 0; i < 5; i++ ) glCallList ( models[i] );
|