-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenGL rendering sample #26
Comments
Even though the issue was opened about a year ago, here's my implementation. First, we need to load the mesh itself. And for that we need a loader. So it's Now, when we have the for(int vertex = 0; vertex < mesh.Vertices.size(); vertex++){
vertexData.push_back(mesh.Vertices[vertex].Position.X);
vertexData.push_back(mesh.Vertices[vertex].Position.Y);
vertexData.push_back(mesh.Vertices[vertex].Position.Z);
} And now we do the usual, make a Vertex Array Object: GLuint VAO;
glGenVertexArrays(1, &VAO); make a Vertex Buffer Object: GLuint VBO;
glGenBuffers(1, &VBO); bind them and load the data: glBindVertexArray(VAO);
glBindBuffer(GL_VERTEX_BUFFER, VBO);
glBufferData(GL_VERTEX_BUFFER, vertexData.size() * sizeof(float), vertexData.data(), GL_STATIC_DRAW); *We used glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)0);
glEnableVertexAttribArray(0); You can learn more about Please note, that explanation/example above works only for triangulated meshes and doesn't incorporate UVs. To incorporate UVs, in first loop also ...
vertexData.push_back(mesh.Vertices[vertex].TextureCoordinate.X);
vertexData.push_back(mesh.Vertices[vertex].TextureCoordinate.Y); Don't forget to update vertex attributes: glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)(3 * sizeof(float)));
glEnableVertexAttribArray(1); Now you can access your UVs from vertex shaders using If your mesh is not triangulated (has quads in it, or other non-triangle faces), GLuint EBO;
glGenBuffers(1, &EBO); and fill it glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh.Indices.size() * sizeof(unsigned int), mesh.Indices.data(), GL_STATIC_DRAW);
Please note that you can't always use indices. If the mesh is triangulated, Hopefully this will help someone some day. And it's readable. |
Is there any OpenGL GLFW rendering sample that I could learn from ?
Thank you.
The text was updated successfully, but these errors were encountered: