15 C
New York
Sunday, March 16, 2025

c++ – OpenGL does not render though all Objects and Knowledge appears to be accurately arrange


No form appears to point out up on display screen though I’ve meticulously verified every part.

The info set I exploit which is parsed by my code CORRECTLY(I checked that) to be loaded right into a generic array assemble I made(Additionally test for correctness) after which later despatched to vbo and ebo:

v 400 400 0 1 0 // Vertex attributes, x y r g b
v 450 450 1 1 0
v 350 350 0 0 1
v 300 300 0 1 1
f 0 1 2 // Indices for EBO.
f 1 2 3

Vertex Sahder:

#model 460 core

structure (location = 0) in uint vert_data;

out vec3 frag_rgb;

void primary() {
    uint x = (vert_data >> 5) & 4095u; // Extract x (12 bits)
    uint y = (vert_data >> 17) & 4095u; // Extract y (12 bits)
    uint r = (vert_data >> 29); // Boolean coloration flag (1 or 0)
    uint g = (vert_data >> 30); // Boolean coloration flag (1 or 0)
    uint b = (vert_data >> 31); // Boolean coloration flag (1 or 0)

    frag_rgb = vec3(r, g, b);

    gl_Position = vec4((((x / 4095.0) * 2.0) - 1.0), (((y / 4095.0) * 2.0 )- 1.0), 0.0f, 1.0f);
}

Fragment Shader:

#model 460 core

in vec3 frag_rgb;
out vec4 frag_color;

void primary() {
    frag_color = vec4(frag_rgb, 1.0);
}

My object setup to setup objects in accordance with the parsed knowledge from a file.:

static void GenVtxBufferDataObjects(Struct_VtxBufferData *pVtx_buffer_data) {
    glGenVertexArrays(1, &(pVtx_buffer_data->vao));
    glBindVertexArray(pVtx_buffer_data->vao);

    // At this level within the code we're certain that the vertices exist and indices optionally exist.
    glGenBuffers(1, &pVtx_buffer_data->vbo);
    glBindBuffer(GL_ARRAY_BUFFER, pVtx_buffer_data->vbo);
    glBufferData(GL_ARRAY_BUFFER,
                 pVtx_buffer_data->vert.elem_size *
                 pVtx_buffer_data->vert.first_empty_index,
                 pVtx_buffer_data->vert.arr, GL_STATIC_DRAW);

    if (pVtx_buffer_data->face.first_empty_index) { // We discovered indices for ebo.
        glGenBuffers(1, &pVtx_buffer_data->ebo);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pVtx_buffer_data->ebo);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                     pVtx_buffer_data->face.elem_size *
                     pVtx_buffer_data->face.first_empty_index,
                     pVtx_buffer_data->face.arr, GL_STATIC_DRAW);
    } else {
        pVtx_buffer_data->ebo = 0;
    }

    // Because the vertex knowledge is encoded right into a int, utilizing its measurement accurately defines the stride.
    // We're nonetheless utilizing a vert.elem_size as if the encoded knowledge measurement adjustments it might nonetheless perform correctly
    glVertexAttribIPointer(0, 1, GL_UNSIGNED_INT, pVtx_buffer_data->vert.elem_size,
                           (void*)0);
    glEnableVertexAttribArray(0);

    glBindVertexArray(0);
}

Within the above code, The dimensions calculations and the proper knowledge parsed all are checked to be right. In order that should not be the issue.

My Render program:

void gfx_Render(GLuint program, Struct_VtxBufferData *pVtx_buffer_data) {
    glClearColor(0.5f, 1.0f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(program);
    glBindVertexArray(pVtx_buffer_data->vao);

    if (pVtx_buffer_data->face.first_empty_index) { // This signifies that indices for EBO have been recieved.
        glDrawElements(GL_TRIANGLES, pVtx_buffer_data->face.first_empty_index,
                       GL_UNSIGNED_INT, 0);
    } else {
        glDrawArrays(GL_TRIANGLES, 0, pVtx_buffer_data->vert.first_empty_index);
    }
    glBindVertexArray(0);
}

I’ve test for nearly each facet of the code, nonetheless i could not determine something. PLZ assist me.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles