简体   繁体   中英

OpenGL VBO Normals/Lighting Issue

I can not get normals to render properly with a VBO. Below is the code I am using, with vertices being an array holding the vertices, and normals being an array holding the normals:

//Create the buffers and such
GLuint VBOID;
glGenBuffersARB(1, &VBOID);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertices) + sizeof(normals), 0, GL_STATIC_DRAW_ARB);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(vertices), vertices);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

///Start loop
cout << "Starting" << endl;
while( window.isOpen() ) {
    sf::Event event;
    while( window.pollEvent( event ) ) {
        if( event.type == sf::Event::Closed )
            window.close();
    }
    fps = FPS.getElapsedTime().asSeconds();
    fps = 1 / fps;
    FPS.restart();
    if(ShowFPS.getElapsedTime().asSeconds() > 1)
    {
        cout << "FPS: " << fps << "\t FrameTime: " << 1000 / fps << endl;
        ShowFPS.restart();
    }

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.0, 1.0, 1.0, 5000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(5, 5, 5, 0, 0, 0, 0, 1, 0);

    //VBO
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    glColor3f(1, 0, 0);
    glRotatef(25 * TurnTimer.getElapsedTime().asSeconds(), 0, 1, 0);
    glRotatef(15 * TurnTimer.getElapsedTime().asSeconds(), 1, 0, 0);
    glNormalPointer(GL_FLOAT, 0, (void*)sizeof(vertices));
    glVertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, NumOfF*3);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

    window.display();
}
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(vertices), vertices);

OK, so where's the part where you do this for your normals ?

Also, please stop using the ARB extension functions. It's been core OpenGL functionality for almost a decade now; drop the ARB suffix already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM