# Texture mapping on a Cube

Hello,
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);
};

``````glEnd();
``````

/**************************************************************************************************************************************/

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

if(t){

``````t-&gt;SetTexture(pos);
``````

}else{
//glColor3f(cos(b), cos(b)cos(a), cos(b)cos(a+b));
glColor3f(0.5,0.5,0.5);
};
glNormal3f(1
n.x, 1
n.y, 1*n.z);
glVertex3f(pos);
};

/***************************************************************************************************************************************/

Could any one help me converting and mapping the function to a cube?

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

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

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.