简体   繁体   中英

Draw only one indicies from IBO

How can I correctly to draw only one point from elemets array? Code below draws part of array from 0 to selected.

class Mesh
{
public:
...
vector <GLuint> indices;
...
}

void renderSelected(GLuint selectedNum)
{
    glBindVertexArray(this->VAO);
    glDrawElements(GL_POINTS, 
    this->indices[selectedNum] * sizeof(GLuint), 
    GL_UNSIGNED_INT, 
    0;
    glBindVertexArray(0);
}

Something like that everytime draw only one the same point.

    glDrawElements(GL_POINTS, 
    this->indices[selectedNum] * sizeof(GLuint), 
    GL_UNSIGNED_INT, 
    &this->indices[selectedNum];

How can I correctly to draw only one point from elemets array?

Considering that you want to render a single point at a given index. Then you just need to switch it around this->indices[selectedNum] * sizeof(GLuint) should be the number of elements you to render. 0 should be the byte offset relative to the buffer of the first element you want rendered.

So in your case count would be 1 and the offset ( GLvoid *indices ) would be the byte offset to the index you want (presuming that's selectedNum ).

glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, (void*)(selectedNum * sizeof(GLuint)));

Note that if it was triangles instead, and you wanted to render a single triangle, then the count would be 3 instead of 1 . As a single triangle consists of 3 indices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM