I am trying to port a demo I found on PositionBasedDynamics . It has a generic function which does the rendering and on their example works but they don't generate/bind any Vertex Array Object or Vertex Buffer Object even though they use Core OpenGL and shaders.

The function is this:

template<class PositionData>
void Visualization::drawTexturedMesh(const PositionData &pd, const IndexedFaceMesh &mesh, const unsigned int offset, const float * const color, GLuint text)
    // draw mesh 
    const unsigned int *faces = mesh.getFaces().data();
    const unsigned int nFaces = mesh.numFaces();
    const Vector3r *vertexNormals = mesh.getVertexNormals().data();
    const Vector2r *uvs = mesh.getUVs().data();

    std::cout << nFaces << std::endl;

    glBindTexture(GL_TEXTURE_2D, text);

    glVertexAttribPointer(0, 3, GL_REAL, GL_FALSE, 0, &pd.getPosition(offset)[0]);
    glVertexAttribPointer(1, 2, GL_REAL, GL_FALSE, 0, &uvs[0][0]);
    glVertexAttribPointer(2, 3, GL_REAL, GL_FALSE, 0, &vertexNormals[0][0]);

    glDrawElements(GL_TRIANGLES, (GLsizei)3 * mesh.numFaces(), GL_UNSIGNED_INT, mesh.getFaces().data());    


    glBindTexture(GL_TEXTURE_2D, 0);

I did the same thing and it render's a white screen . I used RenderDoc to check what's going on and it show's these: https://puu.sh/rM1wB/80620ade8d.png .

How can they get it to work while i can't?

  • \$\begingroup\$ This is evidently not using a core context; in fact all of the GL calls it uses exist in GL 2.0 - which pre-dates core contexts. Shaders also exist in GL 2.0, by the way, so you don't need a core context for shaders either. \$\endgroup\$ – Maximus Minimus Oct 17 '16 at 14:01
  • \$\begingroup\$ Yes but before calling this function they were checking if OpenGL was 3.3 version . I never worked with anything less than 3.1 so i assumed it was core only ! \$\endgroup\$ – mkanakis Oct 17 '16 at 15:07
  • \$\begingroup\$ Yes, you can create a GL 3.3 compatibility context which satisfies checks for GL version 3.3 but yet allows this kind of code (or even glBegin/glEnd code). \$\endgroup\$ – Maximus Minimus Oct 17 '16 at 17:33
  • \$\begingroup\$ Ok i get it . But still, it sucks ! \$\endgroup\$ – mkanakis Oct 17 '16 at 18:08

The debugger's messages are pretty clear : "clean" core OpenGL should use VAO's and VBO's, not access client-side (i.e. RAM) data. That it works on their end is likely a consequence of their graphics drivers being too lenient.

| improve this answer | |
  • \$\begingroup\$ Do you have any idea how this could be ported since it's supposed to be generic? Would appreciate it. \$\endgroup\$ – mkanakis Oct 17 '16 at 13:48
  • \$\begingroup\$ @Davelis4 You'd have to rewrite this the "normal" way, by uploading the various data to VBO's, and adding an explicit VAO. All the information is already present, so this should be reasonably easy. You can just write a first version that creates, fills and throws away the VBOs and optimize it later. \$\endgroup\$ – Quentin Oct 17 '16 at 14:01
  • \$\begingroup\$ @Davelis4 - when you see unbinding in a GL tutorial it's normally a pretty good sign that the tutorial is probably poor-quality. \$\endgroup\$ – Maximus Minimus Oct 17 '16 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.