You should be able to figure out the basic theory behind it yourself!
I hope I interpreted your task right because otherwise, the stuff below was for nothing.
Code untested (I only made sure it doesn’t crash), but you should be able to understand what was done and adapt it accordingly if it doesn’t work.
void drawFace(float x, float y, float z, float normalX, float normalY, float normalZ,
float dir1X, float dir1Y, float dir1Z, int dir1num,
float dir2X, float dir2Y, float dir2Z, int dir2num)
{
// set normal for all to-come vertices first
glNormal3f(normalX, normalY, normalZ);
// increment because of more coordinates
dir1num++;
dir2num++;
// allocate space for raster
float *vertices = (float*)malloc(dir1num*dir2num*3*sizeof(float));
// fill raster according to directions specified in header
for(int i = 0; i < dir1num; i++)
{
for(int j = 0; j < dir2num; j++)
{
vertices[3*(dir2num*i+j)+0] = x + i * dir1X + j * dir2X;
vertices[3*(dir2num*i+j)+1] = y + i * dir1Y + j * dir2Y;
vertices[3*(dir2num*i+j)+2] = z + i * dir1Z + j * dir2Z;
}
}
// draw triangles according to raster
for(int i = 0; i < dir1num - 1; i++)
{
for(int j = 0; j < dir2num - 1; j++)
{
glVertex3fv(vertices+3*(dir2num*i+j));
glVertex3fv(vertices+3*(dir2num*i+j+1));
glVertex3fv(vertices+3*((dir2num*i+1)+j+1));
glVertex3fv(vertices+3*(dir2num*i+j));
glVertex3fv(vertices+3*((dir2num*i+1)+j+1));
glVertex3fv(vertices+3*((dir2num*i+1)+j));
}
}
// don't forget to free allocated space
free(vertices);
}
void drawCubeSubdivided(float x, float y, float z,
float width, float height, float length,
int widthSegments, int heightSegments, int lengthSegments)
{
glBegin(GL_TRIANGLES);
// bottom
drawFace(x, y, z,
0, -1, 0,
0, 0, length / lengthSegments, lengthSegments,
width / widthSegments, 0, 0, widthSegments
);
// top
drawFace(x, y + height, z,
0, 1, 0,
width / widthSegments, 0, 0, widthSegments,
0, 0, length / lengthSegments, lengthSegments
);
// front
drawFace(x, y, z,
-1, 0, 0,
0, height / heightSegments, 0, heightSegments,
0, 0, length / lengthSegments, lengthSegments
);
// back
drawFace(x + width, y, z,
1, 0, 0,
0, 0, length / lengthSegments, lengthSegments,
0, height / heightSegments, 0, heightSegments
);
// left
drawFace(x, y, z,
0, 0, -1,
width / widthSegments, 0, 0, widthSegments,
0, height / heightSegments, 0, heightSegments
);
// right
drawFace(x, y, z + length,
0, 0, 1,
0, height / heightSegments, 0, heightSegments,
width / widthSegments, 0, 0, widthSegments
);
glEnd();
}
void runCube()
{
drawCubeSubdivided(1, 1, 1, 1, 1, 1, 100, 100, 100);
}