Jump to content
  • Advertisement
Sign in to follow this  
LetsDoThis

Split Vertex Data reflection problem

This topic is 902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to use the SubBufferData on assigning Vertex array

 

GLuint cubeVAO, cubeVBO;
    glGenVertexArrays(1, &cubeVAO);
    glGenBuffers(1, &cubeVBO);
    glBindVertexArray(cubeVAO);
    glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeNormal), &cubeNormal, GL_STATIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(cubeVertices), &cubeVertices);

    glBufferSubData(GL_ARRAY_BUFFER, sizeof(cubeVertices), sizeof(cubeNormal), &cubeNormal);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
    glEnableVertexAttribArray(1);

    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)(sizeof(cubeVertices)));
    glBindVertexArray(0);

 

 

thing is, if I use this. I got some issues on refelection

reflection_problem.jpg

 

but I just use the whole vertex data and dont split them

reflection_okay.jpg

 

I dont think that the Fragment shader is at fault because it is working fine on the 2nd image. Anyone know why is opengl doing it like this on split vertex data? Thanks

Share this post


Link to post
Share on other sites
Advertisement

    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeNormal), &cubeNormal, GL_STATIC_DRAW);


I suspect this is your problem. What this does is allocates the buffer to be big enough to store the vertices and copies them over then reallocates the buffer to fit the normals and only the normals then copies those over. You buffer is not big enough to store both the vertices and normals. I would change it to look like this

    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices) + sizeof(cubeNormal), NULL, GL_STATIC_DRAW);
I would also look into interlacing your vertices and normals rather than having them separate, but I would do that only after you get what you currently have working.

Share this post


Link to post
Share on other sites

In terms of debugging things like this in the future, it's a lot easier to debug the geometry before you apply the fancy shader - if you had used a flat coloured material in the beginning, it should have been readily apparent that various faces were missing/reversed from your cube.

Edited by swiftcoder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!