1

Here are the paste bins for the code main.cpp and the shaders. It uses devIL, glload and glfw. Runs on windows and linux. any png named pic.png will load.

I buffer my data in a fairly normal way. Just a simple triangle.

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
//vX     vY    vZ   vW       nX   nY   nZ     U    V        
float bufferDataThree[9*3] = {  
-1.0f, -1.0f, 0.0f,1.0f,    0.0f,1.0f,0.0f,  0.0f,0.0f,
1.0f, -1.0f, 0.0f,1.0f,    0.0f,1.0f,0.0f,  0.0f,1.0f,
1.0f,  1.0f, 0.0f,1.0f,    0.0f,1.0f,0.0f,  1.0f,1.0f};
//TOTAL 4 + 3 + 2 = 9;  
glBufferData(GL_ARRAY_BUFFER, (9*3)*4, bufferDataThree, GL_STATIC_DRAW); //Doesnt Work
//glBufferData(GL_ARRAY_BUFFER, (10*3)*4, bufferDataThree, GL_STATIC_DRAW); //Works

There is 9*3 = 27 floats. Therefore 108 bytes. if I buffer 108 bytes it will screw up the texture coords. If I buffer 116 bytes, (2 floats more) It renders fine.

My display method.

void display()
{
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(program);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D,tbo);

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float), 0);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float),(void*) (4*sizeof(float)));
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, (4 + 3 + 2)*sizeof(float),(void*) ((4+3)*sizeof(float)));

    glDrawArrays(GL_TRIANGLES,0,3);
    glDisableVertexAttribArray(0);
    glUseProgram(0);

    glfwSwapBuffers();
}

How can this be happening?

1
  • Why was this down-voted? Was my question lacking detail required for solving ? I didn't think so... Commented May 22, 2013 at 1:43

1 Answer 1

3

second argument to glVertexAttribPointer is number of components, for texture coord it is 2 and 3 for normal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.