Hey,
I’m tryin’ to rotate a texture by changing the UV coords. It’s a cube model, that contains 6 faces (intern: materials). I want to rotate the texture of the ground face. All polygons can only be seen from the inside (face culling), so that i can use it as a skybox.
// Function Call
pApp->mdl3d_rotate_texture_inner_cube(MDL_SKYBOX, CUBE_MAT_GROUND, ROTATE_LEFT);
/////////////////////////////////////
// Definition A
/////////////////////////////////////
int CApp::mdl3d_rotate_texture_inner_cube(int ID, int cube_side, int rot_flag)
{
int exit_code = ERR_EN_NO_ERROR;
Elem_3D_Mdl * pElem = this->mdl3d_get_elem(ID);
if(pElem != NULL)
{exit_code = pElem->pModel->rotate_texture_inner_cube(cube_side, rot_flag);}
else
{exit_code = ERR_EN_MDL_NOEXIST;}
return exit_code;
}
/////////////////////////////////////
// Definition B
/////////////////////////////////////
int CModel_3D::rotate_texture_inner_cube(int cube_side, int rot_flag)
{
int exit_code = ERR_EN_NO_ERROR;
Material * pMaterial = NULL;
switch(cube_side)
{
case CUBE_MAT_FRONT:
{
pMaterial = this->get_material("Cube Front");
} break;
case CUBE_MAT_LEFT:
{
pMaterial = this->get_material("Cube Left");
} break;
case CUBE_MAT_RIGHT:
{
pMaterial = this->get_material("Cube Right");
} break;
case CUBE_MAT_BACK:
{
pMaterial = this->get_material("Cube Back");
} break;
case CUBE_MAT_TOP:
{
pMaterial = this->get_material("Cube Top");
} break;
case CUBE_MAT_GROUND:
{
pMaterial = this->get_material("Cube Ground");
} break;
};
// UV leeren
if(pMaterial != NULL)
{this->clear_UV(pMaterial);}
else
{exit_code = ERR_EN_MAT_NOEXIST;}
// neue UV ground
if(exit_code == ERR_EN_NO_ERROR && cube_side == CUBE_MAT_GROUND)
{
switch(rot_flag)
{
case ROTATE_LEFT:
{
this->add_face_UV(pMaterial, 3); // (1 | 1) , that Vertex is (-x, -y, -z)
this->add_face_UV(pMaterial, 1); // (0 | 0) , that Vertex is (x, -y, z)
this->add_face_UV(pMaterial, 4); // (1 | 0) , that Vertex is (x, -y, -z)
this->add_face_UV(pMaterial, 1); // (0 | 0) , that Vertex is (x, -y, z)
this->add_face_UV(pMaterial, 3); // (1 | 1) , that Vertex is (-x, -y, -z)
this->add_face_UV(pMaterial, 2); // (0 | 1) , that Vertex is (-x, -y, z)
exit_code = this->update_UV(pMaterial);
} break;
};
}
return exit_code;
}
/////////////////////////////////////
// Definition C
/////////////////////////////////////
int CModel_3D::update_UV(Material * pElem)
{
int exit_code = ERR_EN_NO_ERROR;
glm::vec2 * pUV = new glm::vec2[pElem->number_vertexes];
glBindBuffer(GL_ARRAY_BUFFER, pElem->pVBO[INDEX_UV]);
if(glGetError() == GL_NO_ERROR)
{
glBufferSubData(GL_ARRAY_BUFFER, 0, (sizeof(glm::vec2) * pElem->number_vertexes), pUV); // pElem->number_vertexes = 6!
if(glGetError() != GL_NO_ERROR)
{exit_code = ERR_EN_MDL_VBO_SUB_DATA;}
}
else
{exit_code = ERR_EN_MDL_BIND_VBO;}
// Speicher freigeben
if(pUV != NULL)
{delete [] pUV;}
return exit_code;
}
So when I try that, the ground cube face just has a single color. I failed to rotate the texture to the left. Why is that?
No error is returned by any of my functions. When I skip the rotation function mentioned at the very top, the texture is shown correctly.
U can see the image, so you can see what I mean: