//////////////////////////////////////////////////////////////////////// // here is some code from the mid 90s which focuses on immediate mode // // code from battalion by Andy Johnson // //////////////////////////////////////////////////////////////////////// void makercube(float x, float y, float z, float u, float v, float w, float c[4]) { float c2[4], c3[4], c4[4]; float tail1[8][3]; // v7----- v4 // /| /| // v0------v3| // | | | | // | |v6---|-|v5 // |/ |/ // v1------v2 // +z Out of screen // 0 1 2 3 // 3 2 5 4 // 0 3 4 7 // 1 6 5 2 // 0 7 6 1 // 7 4 5 6 tail1[0][2] = tail1[1][2] = tail1[2][2] = tail1[3][2] = w + z; tail1[2][0] = tail1[3][0] = tail1[4][0] = tail1[5][0] = u + x; tail1[0][1] = tail1[3][1] = tail1[4][1] = tail1[7][1] = v + y; tail1[0][0] = tail1[1][0] = tail1[6][0] = tail1[7][0] = x - u; tail1[1][1] = tail1[2][1] = tail1[5][1] = tail1[6][1] = y - v; tail1[4][2] = tail1[5][2] = tail1[6][2] = tail1[7][2] = z - w; c2[3] = c3[3] = c4[3] = c[3]; c2[0] = c[0]*0.8; c2[1] = c[1]*0.8; c2[2] = c[2]*0.8; c3[0] = c[0]*0.66; c3[1] = c[1]*0.66; c3[2] = c[2]*0.66; c4[0] = c[0]*0.5; c4[1] = c[1]*0.5; c4[2] = c[2]*0.5; glBegin(GL_QUAD_STRIP); glColor4fv(c2); glVertex3fv(tail1[0]);glVertex3fv(tail1[1]);glVertex3fv(tail1[3]);glVertex3fv(tail1[2]); glColor4fv(c3); glVertex3fv(tail1[4]);glVertex3fv(tail1[5]); glColor4fv(c4); glVertex3fv(tail1[7]);glVertex3fv(tail1[6]); glColor4fv(c3); glVertex3fv(tail1[0]);glVertex3fv(tail1[1]); glEnd(); glColor4fv(c4); glBegin(GL_QUADS); glVertex3fv(tail1[6]); glVertex3fv(tail1[5]); glVertex3fv(tail1[2]); glVertex3fv(tail1[1]); glColor4fv(c); glVertex3fv(tail1[0]); glVertex3fv(tail1[3]); glVertex3fv(tail1[4]); glVertex3fv(tail1[7]); glEnd(); } ///////////////////////////////////////////////// // today you would do something more like this // ///////////////////////////////////////////////// void makercube(float x, float y, float z, float u, float v, float w, float c[4]) { float c2[4], c3[4], c4[4]; float tail1[8][3]; float all36[36][3]; // new float all36c[36][4]; // new tail1[0][2] = tail1[1][2] = tail1[2][2] = tail1[3][2] = z + w; tail1[2][0] = tail1[3][0] = tail1[4][0] = tail1[5][0] = x + u; tail1[0][1] = tail1[3][1] = tail1[4][1] = tail1[7][1] = y + v; tail1[0][0] = tail1[1][0] = tail1[6][0] = tail1[7][0] = x - u; tail1[1][1] = tail1[2][1] = tail1[5][1] = tail1[6][1] = y - v; tail1[4][2] = tail1[5][2] = tail1[6][2] = tail1[7][2] = z - w; c2[3] = c3[3] = c4[3] = c[3]; c2[0] = c[0]*0.8f; c2[1] = c[1]*0.8f; c2[2] = c[2]*0.8f; c3[0] = c[0]*0.66f; c3[1] = c[1]*0.66f; c3[2] = c[2]*0.66f; c4[0] = c[0]*0.5f; c4[1] = c[1]*0.5f; c4[2] = c[2]*0.5f; copyVertices(all36, tail1, threeVertices); copyColors(all36c, c, c2, c3, c4); drawArrays(all36, all36c); } ///// void copyVertices(float all36[][3], float tail1[][3], size_t f) { memcpy(all36[0], tail1[0], f ); memcpy(all36[1], tail1[1], f ); memcpy(all36[2], tail1[3], f ); memcpy(all36[3], all36[1], 2*f ); memcpy(all36[5], tail1[2], f ); memcpy(all36[6], tail1[3], f ); memcpy(all36[7], tail1[2], f ); memcpy(all36[8], tail1[4], f ); memcpy(all36[9], all36[7], 2*f ); memcpy(all36[11], tail1[5], f ); memcpy(all36[12], tail1[0], f ); memcpy(all36[13], tail1[3], f ); memcpy(all36[14], tail1[7], f ); memcpy(all36[15], all36[13], 2*f ); memcpy(all36[17], tail1[4], f ); memcpy(all36[18], tail1[1], f ); memcpy(all36[19], tail1[6], f ); memcpy(all36[20], tail1[2], f ); memcpy(all36[21], all36[19], 2*f ); memcpy(all36[23], tail1[5], f ); memcpy(all36[24], tail1[0], f ); memcpy(all36[25], tail1[7], f ); memcpy(all36[26], tail1[1], f ); memcpy(all36[27], all36[25], 2*f ); memcpy(all36[29], tail1[6], f ); memcpy(all36[30], tail1[7], f ); memcpy(all36[31], tail1[4], f ); memcpy(all36[32], tail1[6], f ); memcpy(all36[33], all36[31], 2*f ); memcpy(all36[35], tail1[5], f ); } ///// void copyColors(float all36c[36][4], float c[4], float c2[4], float c3[4], float c4[4]) { size_t f; f = fourColors; memcpy(all36c[0], c2, f ); memcpy(all36c[1], c2, f ); memcpy(all36c[2], c2, f ); memcpy(all36c[3], all36c[0], 3*f); memcpy(all36c[6], c3, f ); memcpy(all36c[7], c3, f ); memcpy(all36c[8], c3, f ); memcpy(all36c[9], all36c[6], 3*f); memcpy(all36c[12], c, f ); memcpy(all36c[13], c, f ); memcpy(all36c[14], c, f ); memcpy(all36c[15], all36c[12], 3*f); memcpy(all36c[18], c4, f ); memcpy(all36c[19], c4, f ); memcpy(all36c[20], c4, f ); memcpy(all36c[21], all36c[18], 3*f); memcpy(all36c[24], c3, f ); memcpy(all36c[25], c3, f ); memcpy(all36c[26], c3, f ); memcpy(all36c[27], all36c[24], 3*f); memcpy(all36c[30], c4, f ); memcpy(all36c[31], c4, f ); memcpy(all36c[32], c4, f ); memcpy(all36c[33], all36c[30], 3*f); } ///// void drawArrays(float all36[36][3], float all36c[36][4]) { glColorPointer(4, GL_FLOAT, 0, all36c); glVertexPointer(3, GL_FLOAT, 0, all36); glDrawArrays(GL_TRIANGLES, 0, 36); }