opengl vertex shader getting wrong values when rendering a cube

  assimp, c++, glsl, opengl

I have the following code

void Mesh::draw(Shader shader)
{
        //bind appropriate textures
        GLuint diffuse_nr = 1;
        GLuint specular_nr = 1;
        for(GLuint i = 0; i < textures.size(); i++)
        {
                //active proper texture unit before binding
                glActiveTexture(GL_TEXTURE0 + i);
                //retrieve texture number (the N in the diffuse_textureN)
                stringstream ss;
                string number;
                string name = textures[i].type;
                if(name == "texture_diffuse")
                        ss << diffuse_nr++;
                else if(name == "texture_specular")
                        ss << specular_nr++;
                number = ss.str();
                //now set the sampler to the correct texture unit
                glUniform1i(glGetUniformLocation(shader.get_program(), (name + number).c_str()), i);
                //finally bind the texture
                glBindTexture(GL_TEXTURE_2D, textures[i].id);
        }
        //also set each of mesh's shininess property to a default value 
        glUniform1i(glGetUniformLocation(shader.get_program(), "material.shininess"), 16.0f);

        //draw the mesh
        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        for(int c = 0; c<vertices.size(); c++)
        {
                cout <<"x2: " << vertices.at(c).position.x << " Y: " << vertices.at(c).position.y << " z: " << vertices.at(c).position.z << endl;       
        }
        //always good practise to set everything back to default once configured
        for(GLuint i = 0; i < textures.size(); i++)
        {
                glActiveTexture(GL_TEXTURE0 + i);
                glBindTexture(GL_TEXTURE_2D, 0);
        }
}

When i print out the vertices i get the following

x2: 1 Y: 1 z: -1
x2: -1 Y: 1 z: -1
x2: -1 Y: 1 z: 1
x2: 1 Y: 1 z: 1
x2: 1 Y: -1 z: 1
x2: 1 Y: 1 z: 1
x2: -1 Y: 1 z: 1
x2: -1 Y: -1 z: 1
x2: -1 Y: -1 z: 1
x2: -1 Y: 1 z: 1
x2: -1 Y: 1 z: -1
x2: -1 Y: -1 z: -1
x2: -1 Y: -1 z: -1
x2: 1 Y: -1 z: -1
x2: 1 Y: -1 z: 1
x2: -1 Y: -1 z: 1
x2: 1 Y: -1 z: -1
x2: 1 Y: 1 z: -1
x2: 1 Y: 1 z: 1
x2: 1 Y: -1 z: 1
x2: -1 Y: -1 z: -1
x2: -1 Y: 1 z: -1
x2: 1 Y: 1 z: -1
x2: 1 Y: -1 z: -1

The problem is that the cube is not rendering and when i check the vertices using render doc i get empty values as shown vertices

Also when i check the buffer contents they are as shown in the image
buffer

The vertex shader code is

#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 texture_coordinate;

out vec2 texture_coord;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
    gl_Position = projection * view * model *  vec4(position, 1.0f);
    texture_coord = texture_coordinate;
}

Where could the problem be. Why are the position values changing?

Source: Windows Questions C++

LEAVE A COMMENT