Skip to content

Mismatch between the comment order and actual data order in main.cpp and potential confusion for learners. #34

@MatinAfzal

Description

@MatinAfzal

In the file YoutubeOpenGL 12 - Mesh Class, specifically in main.cpp, we have a Vertex vertices[] array where we store most of our mesh data:

Vertex vertices[] =
{ //               COORDINATES           /            COLORS          /           NORMALS         /       TEXTURE COORDINATES    //
    Vertex{glm::vec3(-1.0f, 0.0f,  1.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f)},
    Vertex{glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f)},
    Vertex{glm::vec3( 1.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f)},
    Vertex{glm::vec3( 1.0f, 0.0f,  1.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f)}
};

The comment above mentions the order as:
COORDINATES - COLORS - NORMALS - TEXTURE COORDINATES

However, the actual data in the Vertex array does not follow this order. The order of the data is as follows:
COORDINATES - NORMALS (first) - COLORS (second) - TEXTURE COORDINATES

The struct Vertex is defined in VBO.h like this:

struct Vertex
{
    glm::vec3 position;
    glm::vec3 normal;
    glm::vec3 color;
    glm::vec2 texUV;
};

In mesh.cpp, the correct rendering of the object relies on this order, and the LinkAttrib calls follow this pattern:

VAO.LinkAttrib(VBO, 0, 3, GL_FLOAT, sizeof(Vertex), (void*)0);
VAO.LinkAttrib(VBO, 1, 3, GL_FLOAT, sizeof(Vertex), (void*)(3 * sizeof(float)));
VAO.LinkAttrib(VBO, 2, 3, GL_FLOAT, sizeof(Vertex), (void*)(6 * sizeof(float)));
VAO.LinkAttrib(VBO, 3, 2, GL_FLOAT, sizeof(Vertex), (void*)(9 * sizeof(float)));

As you can see, there is a swap between LinkAttrib calls for NORMALS and TEXTURE COORDINATES, which is different from the order in previous chapters. Although this is currently working correctly, this could be misleading and confusing for learners.

Proposed Solutions:
1 - Fix the comment to reflect the correct order (i.e., change the comment above Vertex vertices[] to match the actual order of data).

2 - Fix the data order in the struct Vertex and the corresponding LinkAttrib calls to match the order presented in the comment (COORDINATES, COLORS, NORMALS, TEXTURE COORDINATES). This would require changing the order of attributes in the struct and adjusting the LinkAttrib calls accordingly to preserve the correct rendering behavior.

Thank you for maintaining this amazing repository!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions