0

I am putting texture to a cube, but I have the plane coord in the same vertex, how can I just texture the cube? every time I apply texture to my cube the plane gets it too. I know I need to get the cube out of there, but I dont know how to do it. any help??

// Vertex data
GLfloat verts[] = {
    // Vertex Positions    // Texture coordinate
    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f,
     0.5f, -0.5f, -0.5f,   1.0f, 0.0f,
     0.5f,  0.5f, -0.5f,   1.0f, 1.0f,
     0.5f,  0.5f, -0.5f,   1.0f, 1.0f,
    -0.5f,  0.5f, -0.5f,   0.0f, 1.0f,
    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f, 

    -0.5f, -0.5f,  0.5f,   0.0f, 0.0f,
     0.5f, -0.5f,  0.5f,   0.0f, 1.0f,
     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,
     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,
    -0.5f,  0.5f,  0.5f,   0.0f, 1.0f,
    -0.5f, -0.5f,  0.5f,   0.0f, 0.0f,

    -0.5f,  0.5f,  0.5f,   0.0f, 1.0f,
    -0.5f,  0.5f, -0.5f,   0.0f, 1.0f,
    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f,
    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f,
    -0.5f, -0.5f,  0.5f,   0.0f, 0.0f,
    -0.5f,  0.5f,  0.5f,   0.0f, 1.0f,

     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,
     0.5f,  0.5f, -0.5f,   1.0f, 1.0f,
     0.5f, -0.5f, -0.5f,   1.0f, 0.0f,
     0.5f, -0.5f, -0.5f,   1.0f, 0.0f,
     0.5f, -0.5f,  0.5f,   1.0f, 0.0f,
     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,

    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f,
     0.5f, -0.5f, -0.5f,   1.0f, 0.0f,
     0.5f, -0.5f,  0.5f,   1.0f, 0.0f,
     0.5f, -0.5f,  0.5f,   1.0f, 0.0f,
    -0.5f, -0.5f,  0.5f,   0.0f, 0.0f,
    -0.5f, -0.5f, -0.5f,   0.0f, 0.0f,

    -0.5f,  0.5f, -0.5f,   0.0f, 1.0f,
     0.5f,  0.5f, -0.5f,   1.0f, 1.0f,
     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,
     0.5f,  0.5f,  0.5f,   1.0f, 1.0f,
    -0.5f,  0.5f,  0.5f,   0.0f, 1.0f,
    -0.5f,  0.5f, -0.5f,   1.0f, 1.0f,

    //plane
    -5.0f,  -0.5f, -5.0f,   0.0f, 0.0f,
     5.0f,  -0.5f, -5.0f,   1.0f, 0.0f,
     5.0f,  -0.5f,  5.0f,   1.0f, 0.0f,

     5.0f,  -0.5f,  5.0f,   1.0f, 0.0f,
    -5.0f,  -0.5f,  5.0f,   0.0f, 0.0f,
    -5.0f,  -0.5f, -5.0f,   0.0f, 0.0f,

};
  • its unclear what the problem is? if you mean you got 2 texture coordinates per the same vertex then just duplicate it ... what do you mean by removing plane? do you have image? I assume you using Triangle primitives ... see [complete GL+GLSL+VAO/VBO C++ example](https://stackoverflow.com/a/31913542/2521214) and [Texturing a cube with different images using OpenGL](https://stackoverflow.com/a/65276638/2521214) for some inspiration / cross check – Spektre Feb 09 '22 at 09:48
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 19 '22 at 12:30

0 Answers0