Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Opengl : the vbo doen't build correctly.  (Read 2960 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Opengl : the vbo doen't build correctly.
« on: April 07, 2014, 04:49:24 pm »
Hi, I'm trying to make a class to build vbo, but it doesn't work, the size of the data passed is not good : (it's 4 instead of 12 so it draw nothing)

void VBO::create (const void* data, const unsigned int dataSize) {
    ensureGlContext();
    if (m_vbo == 0) {
        GLuint vbo;
        glCheck(glGenBuffers(1, &vbo));
        m_vbo = static_cast<unsigned int>(vbo);

    }

    if (isAvailable() && m_vbo != 0 ) {
        glCheck(glBindBuffer(GL_ARRAY_BUFFER, m_vbo));
        glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB,dataSize, data, GL_DYNAMIC_DRAW));
        glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
    } else {
        std::cerr<<"Failed to create the vbo, you should check if vbo are avalaible first! (by calling the VBO::isAvailable function)"<<std::endl;
    }
}
 

const_cast<VertexArray*>(this)->vboVertex.create(&m_vertices[0], m_vertices.size() * sizeof(Vertex));
 

Anyone have any idea about how I have to pass data to my create function ?

And I'm searching for a good opengl forum to get some help. :P

therocode

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Development blog
Re: Opengl : the vbo doen't build correctly.
« Reply #1 on: April 07, 2014, 04:52:32 pm »
I am sorry, but I thought you knew OpenGL?

VBOs are a very basic thing in OpenGL and it surprises me that you don't know it well since you're a really good coder. :O

I am sure you can find out the answer if you think a bit harder.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Opengl : the vbo doen't build correctly.
« Reply #2 on: April 07, 2014, 05:12:57 pm »
It's not very vbo with cause me problems, when I pass the &m_vertices[0] directly to the gl function it works, it's memory management and c array management with cause me some problems...

 

therocode

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Development blog
Re: Opengl : the vbo doen't build correctly.
« Reply #3 on: April 07, 2014, 05:25:00 pm »
Well, maybe that is why fifty thousand people in this forum have advised you to not use manual memory management? And even still, managing arrays is a very very basic thing so I am pretty sure you know such stuff as well.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Opengl : the vbo doen't build correctly.
« Reply #4 on: April 07, 2014, 05:26:14 pm »
Why was your last thread closed BTW?

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Opengl : the vbo doen't build correctly.
« Reply #5 on: April 07, 2014, 05:39:27 pm »
I find it strange that it doesn't display anything so..., I'm passing the adress of the array of my vertices to the create function..., and it doens't seems to work.


Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Opengl : the vbo doen't build correctly.
« Reply #6 on: April 07, 2014, 06:33:02 pm »
When I don't pass the datas to a generic class, it works :

  if (vboVertexBuffer == 0) {
                    GLuint vbo;
                    glCheck(glGenBuffers(1, &vbo));
                    const_cast<VertexArray*>(this)->vboVertexBuffer = static_cast<unsigned int>(vbo);
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
                    glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertices.size() * sizeof(Vertex), &(m_vertices[0]), GL_DYNAMIC_DRAW));
                } else {
                    GLvoid *pos_vbo = nullptr;
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
                    pos_vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
                    if (pos_vbo != nullptr) {
                        memcpy(pos_vbo,&m_vertices[0],  m_vertices.size() * sizeof(Vertex));
                        glCheck(glUnmapBuffer(GL_VERTEX_ARRAY));
                        pos_vbo = nullptr;
                    }
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
                }
                 if (vboVertexBuffer == 0) {
                    GLuint vbo;
                    glCheck(glGenBuffers(1, &vbo));
                    const_cast<VertexArray*>(this)->vboNormalBuffer = static_cast<unsigned int>(vbo);
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
                    glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_normals.size() * sizeof(Vector3f), &(m_normals[0]), GL_DYNAMIC_DRAW));
                } else {
                    GLvoid *pos_vbo = nullptr;
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
                    pos_vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
                    if (pos_vbo != nullptr) {
                        memcpy(pos_vbo,&m_normals[0],  m_normals.size() * sizeof(Vector3f));
                        glCheck(glUnmapBuffer(GL_VERTEX_ARRAY));
                        pos_vbo = nullptr;
                    }
                    glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
                }
 
But it's quite anoying to don't have the possibility to encapsulate them in a class.

therocode

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Development blog
Re: Opengl : the vbo doen't build correctly.
« Reply #7 on: April 07, 2014, 07:14:24 pm »
You are very unlikely to get help since you constantly ignore the advice people give you anyway.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Opengl : the vbo doen't build correctly.
« Reply #8 on: April 07, 2014, 07:53:24 pm »
I've found why, I think, it's because the void* hold only the address and not the datas.

Or the vbo need both.

Maybe I need to make a template class which hold a std::vector instead but I'll make it later. (For the moment my vertex array class only is sufficient, and I think I'll also use it for the vbo buffer.)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Opengl : the vbo doen't build correctly.
« Reply #9 on: April 07, 2014, 08:25:41 pm »
Next time you post something not about SFML you're banned. I hope this is clear enough.
Laurent Gomila - SFML developer

 

anything