Segfault尝试使用VBO

时间:2013-07-26 13:01:08

标签: c++ opengl sfml vbo

好吧,我正试图摆脱glBegin / glEnd的事情,所以我试图让VBO正常工作。 我实际上在glDrawArrays调用时遇到了段错误,我不知道该怎么做。

如果您需要任何细节,请询问。

这是我的代码:

#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML and VBO", sf::Style::Default);
window.setVerticalSyncEnabled(true);
window.setActive(true);
window.resetGLStates();

GLfloat m_vData[12];
GLuint m_uiVBO;

m_vData[0] = -0.2f; m_vData[1] = -0.1f; m_vData[2] = 0.0f;
m_vData[3] = -0.2f; m_vData[4] = -0.6f; m_vData[5] = 0.0f;
m_vData[6] = 0.2f; m_vData[7] = -0.1f; m_vData[8] = 0.0f;
m_vData[9] = 0.2f; m_vData[10] = -0.6f; m_vData[11] = 0.0f;

glGenBuffers(1, &m_uiVBO);

glBindBuffer(GL_ARRAY_BUFFER, m_uiVBO);
glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float), m_vData, GL_STATIC_DRAW);

float rotation = 0;

bool running = true;
while(running)
{
    sf::Event event;
    while(window.pollEvent(event))
    {
        switch(event.type)
        {
        case sf::Event::KeyPressed:
            if(event.key.code != sf::Keyboard::Key::Return) { break; }
        case sf::Event::Closed:
            running = false;
            break;
        default:
            break;
        }
    }

    glClearColor(0.3f, 0.3f, 0.3f, 1.f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, m_uiVBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Segfault

    window.display();
}
return 0;
}

0 个答案:

没有答案