Texture mapping on a Cube

I need to map 3D texture on a cube. I have it mapped on a sphere as follows:

const float da = PI/steps;
const float db = PI/steps;

for(float b = -PI/2; b < PI/2; b+=db)
for(float a = 0; a < 2*PI; a+=da){
DrawSphereVertexFunction( a, b, center, radius, tex);
DrawSphereVertexFunction( a, b+db, center,radius,tex);
DrawSphereVertexFunction( a+da, b+db, center,radius,tex);
DrawSphereVertexFunction( a+da, b, center, radius,tex);



void DrawSphereVertexFunction(float a, float b, const V3f & where, float radius, Textured * t){
V3f pos(where); V3f n(cos(b)*sin(a),
pos += n



//glColor3f(cos(b), cos(b)cos(a), cos(b)cos(a+b));
n.x, 1
n.y, 1*n.z);


Could any one help me converting and mapping the function to a cube?
Thank you in advance.

hi , even i hd struggled initially to map textures to cube… but thn succeded…

so if u could tell me exactly in what way u want to apply textures for cube… isit same texture for all faces or different pictures fr each face… i would be able to help u :wink:

Thank you very much for your reply. I need to map the texture to the whole cube, it may not be the same texture for all faces. I think I need to map the same way as has been mapped considering the sphere.

Thank you again for your cooperation.

hey why you are trying to use 3d textures… i guess for a cube 2d textures are enough , i have not worked on 3d textures but they are rarely used and increase the complexity.

So if u wanna do it with 2d textures then i will help u to do it step by step :wink:

Thank you very much for your kind reply. Actually I am working on some other’s code where 3D texture has been used. I also don’t know much about it. It is ok to work with 2D texture and it would be very kind of you to show the steps.

Thank you in advance.