-1

I'm working on a 3D object viewer, a really basic opengl program i think. But i'm new to opengl and i find a problem that i can't resolve.

The last tutorial that i used is here : LearnOpenGL So the code than i'll show is from there (Model Loading part), i use Assimp to load the object.

There is some code:

Mesh Setup:

struct Vertex {
    glm::vec3  position;
    glm::vec3  normal;
    glm::vec2  texCoords;
  };

    glGenVertexArrays(1, &this->m_VAO);
    glGenBuffers(1, &this->m_VBO);
    glGenBuffers(1, &this->m_EBO);

    glBindVertexArray(this->m_VAO);

    glBindBuffer(GL_ARRAY_BUFFER, this->m_VBO);
    glBufferData(GL_ARRAY_BUFFER, this->m_vertices.size() * sizeof(Vertex),
                 &this->m_vertices[0], GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->m_EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->m_indices.size() * sizeof(GLuint),
                 &this->m_indices[0], GL_STATIC_DRAW);

    // Vertex Positions
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
                         (GLvoid*)0);
    // Vertex Normals
    glEnableVertexAttribArray(1); 
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
                         (GLvoid*)offsetof(Vertex, normal));
    // Vertex Texture Coords
    glEnableVertexAttribArray(2); 
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
                         (GLvoid*)offsetof(Vertex, texCoords));

    glBindVertexArray(0);

You can check the whole code on the site.

Draw :

// Draw mesh
glBindVertexArray(model.get_VAO());
glDrawElements(GL_TRIANGLES, model.get_Indices_Size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);

Shaders :

Vertex ->

#version 130
in vec4 gxl3d_Position;
in vec4 gxl3d_Color;

smooth out vec4 VertexColor;

void main() {
  gl_Position = gxl3d_Position;
  VertexColor = vec4(0.5f, 0.0f, 0.0f, 1.0f);
}

Fragment ->

#version 130

smooth in vec4 VertexColor;

void main() {
  gl_FragColor = VertexColor;
}

When i run this, i can check than the last vertex from Assimp is not the same when i read the .obj directly, maybe it's normal?

So in the end i reach a "nouveau failed idel channel 0xcccc0000 Xorg 677"

If someone have any idea, Thanks!

1 Answers1

0

One thing is wrong in the mesh setup.

This

 // Vertex Positions
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
                     (GLvoid*)0);
// Vertex Normals
glEnableVertexAttribArray(1); 
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
                     (GLvoid*)offsetof(Vertex, normal));
// Vertex Texture Coords
glEnableVertexAttribArray(2); 
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), 
                     (GLvoid*)offsetof(Vertex, texCoords));

Should be after:

glBindBuffer(GL_ARRAY_BUFFER, this->m_VBO);
glBufferData(GL_ARRAY_BUFFER, this->m_vertices.size() * sizeof(Vertex),
             &this->m_vertices[0], GL_STATIC_DRAW);

while the VBO is bound, otherwise you're setting the attrib pointers the EBO instead if the VBO.

And if you have no reason to use that old GLSL version, you should really bump it up to like 330 or so and use layout(location = 0) in vec3 position.

For instance to access to normals:

#version 330

layout(location = 1) in vec3 normals;
etc

About assimp I have no idea.

Good luck :)

JeppeSRC
  • 89
  • 1
  • 9