1
\$\begingroup\$

Let's say I have

    glGenBuffers(1, &vertexbuffer);
    glGenBuffers(1, &indexbuffer);
    glGenBuffers(1, &normalbuffer);

    glBindBuffer(GL_ARRAY_BUFFER,vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER,sizeof(float)*numVertices*3,verticesArr,GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexbuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,numIndices*sizeof(GLuint)*3,indicesArr,GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER,normalbuffer);
    glBufferData(GL_ARRAY_BUFFER,sizeof(float)*numVertices*3, normalsArr, GL_STATIC_DRAW);


    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER,vertexbuffer);
    glVertexAttribPointer( 0, 3GL_FLOAT,GL_FALSE,24, (void*)(0));

    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER,normalbuffer);
    glVertexAttribPointer( 1, 3GL_FLOAT,GL_FALSE,24, (void*)(12));

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexbuffer);

is it possible to tell OpenGl to use the normals in buffer for light "calculation"?

Basically I want to know how to say to OpenGl: "Here are my normals take them and make me nice lighting". Since I didn't find answer in google I posted my question here. Thank you for attention.

\$\endgroup\$
1
  • \$\begingroup\$ Any particular reason for mixing obsolete fixed pipeline with VBOs(modern OpenGL)? \$\endgroup\$ – wondra Apr 12 '16 at 6:04
1
\$\begingroup\$

I found solution:

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normalsArr);

above code tells OpenGL to consider normals

\$\endgroup\$

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.