Line rendering in OpenGL not drawing interior vertices

I’m trying to make a function for displaying the vertices of a custom b2Body shape (I am using Box2D and am trying to display the Box2D colliders) and this is the function I’m using. It renders lines and points to denote where the vertices in the b2Body shape are. But it doesn’t render vertices in the “interior” of the shape, meaning that if a vertex is closer to the center than two other vertices then it only renders a line between those two vertices and not the vertex which is “inside”. So, how do I render the interior of the shape? If you’re wondering, my line vertex shader is just three mat4s, and fragment shader is just one color, very simple.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <box2d/box2d.h>
#include <glm/glm.hpp>
#include <vector>
#include <glad/glad.h>
std::vector<glm::vec2> vertices;
// Iterate over all fixtures in the object's Box2D body and put the collider vertices in the vertices vector
for (b2Fixture* f = object.body->GetFixtureList(); f; f = f->GetNext()) {
if (f->GetType() == b2Shape::e_polygon) {
b2PolygonShape* shape = (b2PolygonShape*)f->GetShape();
for (int i = 0; i < shape->m_count; ++i) {
b2Vec2 vertex = object.body->GetWorldPoint(shape->m_vertices[i]);
vertices.push_back(glm::vec2(vertex.x, vertex.y));
}
}
}
// Create and bind VAO and VBO
GLuint VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec2), vertices.data(), GL_STATIC_DRAW);
// Define vertex attribute
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), (void*)0);
glEnableVertexAttribArray(0);
// Use the shader program
shader.use();
// Set shader uniforms
shader.setMat4("view", view);
shader.setMat4("projection", projection);
shader.setVec4("lineColor", glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
glm::mat4 model = glm::mat4(1.0f);
shader.setMat4("model", model);
// Draw the polygon outline
glLineWidth(2.0f);
glDrawArrays(GL_LINE_LOOP, 0, vertices.size());
// Draw points to highlight the vertices
glPointSize(10.0f);
glDrawArrays(GL_POINTS, 0, vertices.size());
// Unbind and delete VAO and VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
glDeleteVertexArrays(1, &VAO);
</code>
<code>#include <box2d/box2d.h> #include <glm/glm.hpp> #include <vector> #include <glad/glad.h> std::vector<glm::vec2> vertices; // Iterate over all fixtures in the object's Box2D body and put the collider vertices in the vertices vector for (b2Fixture* f = object.body->GetFixtureList(); f; f = f->GetNext()) { if (f->GetType() == b2Shape::e_polygon) { b2PolygonShape* shape = (b2PolygonShape*)f->GetShape(); for (int i = 0; i < shape->m_count; ++i) { b2Vec2 vertex = object.body->GetWorldPoint(shape->m_vertices[i]); vertices.push_back(glm::vec2(vertex.x, vertex.y)); } } } // Create and bind VAO and VBO GLuint VAO, VBO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec2), vertices.data(), GL_STATIC_DRAW); // Define vertex attribute glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), (void*)0); glEnableVertexAttribArray(0); // Use the shader program shader.use(); // Set shader uniforms shader.setMat4("view", view); shader.setMat4("projection", projection); shader.setVec4("lineColor", glm::vec4(0.0f, 1.0f, 0.0f, 1.0f)); glm::mat4 model = glm::mat4(1.0f); shader.setMat4("model", model); // Draw the polygon outline glLineWidth(2.0f); glDrawArrays(GL_LINE_LOOP, 0, vertices.size()); // Draw points to highlight the vertices glPointSize(10.0f); glDrawArrays(GL_POINTS, 0, vertices.size()); // Unbind and delete VAO and VBO glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); glDeleteBuffers(1, &VBO); glDeleteVertexArrays(1, &VAO); </code>
#include <box2d/box2d.h>
#include <glm/glm.hpp>
#include <vector>
#include <glad/glad.h>

std::vector<glm::vec2> vertices;

// Iterate over all fixtures in the object's Box2D body and put the collider vertices in the vertices vector
for (b2Fixture* f = object.body->GetFixtureList(); f; f = f->GetNext()) {
    if (f->GetType() == b2Shape::e_polygon) {
        b2PolygonShape* shape = (b2PolygonShape*)f->GetShape();
        for (int i = 0; i < shape->m_count; ++i) {
            b2Vec2 vertex = object.body->GetWorldPoint(shape->m_vertices[i]);
            vertices.push_back(glm::vec2(vertex.x, vertex.y));
        }
    }
}

// Create and bind VAO and VBO
GLuint VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);

glBindVertexArray(VAO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec2), vertices.data(), GL_STATIC_DRAW);

// Define vertex attribute
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), (void*)0);
glEnableVertexAttribArray(0);

// Use the shader program
shader.use();

// Set shader uniforms
shader.setMat4("view", view);
shader.setMat4("projection", projection);
shader.setVec4("lineColor", glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));

glm::mat4 model = glm::mat4(1.0f);
shader.setMat4("model", model);

// Draw the polygon outline
glLineWidth(2.0f);
glDrawArrays(GL_LINE_LOOP, 0, vertices.size());

// Draw points to highlight the vertices
glPointSize(10.0f);  
glDrawArrays(GL_POINTS, 0, vertices.size());

// Unbind and delete VAO and VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
glDeleteVertexArrays(1, &VAO);

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật