Hi, I’ve installed the last version of mesa driver, but, this one seems to be still experimental, and …, I’m just wandering if I shoudn’t use old opengl versions on linux.
I’m trying to display a single triangle, if I pass an array to the glVertexAttribPointer it works, but, if I pass an std::vector I doesn’t work anymore :
int main(int argc, char* argv[]) {
odfaeg::RenderWindow window(sf::VideoMode(800, 600, 32), "Modern OpenGL",sf::Style::Default,sf::ContextSettings(24, 8, 4, 3, 3));
odfaeg::Matrix4f matrix = window.getView().getProjMatrix().get3DMatrix() * window.getView().getViewMatrix().get3DMatrix();
// Create and compile our GLSL program from the shaders
/*GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
GLuint location = glGetUniformLocation(programID, "mvp");
if (location == -1)
std::cout<<"param not found in shader!"<<std::endl;*/
/*glUseProgram(programID);
glUniformMatrix4fv(location, 1, GL_TRUE,pm.get3DMatrix().toGlMatrix());*/
odfaeg::Shader shader;
shader.loadFromFile("SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader");
shader.setParameter("mvp", matrix);
// An array of 3 vectors which represents 3 vertices
std::vector<odfaeg::Vertex> vertices;
vertices.push_back(odfaeg::Vertex(sf::Vector3f(0.0f, 300.0f, 0)));
vertices.push_back(odfaeg::Vertex(sf::Vector3f(400.0f, -300.0f, 0)));
vertices.push_back(odfaeg::Vertex(sf::Vector3f(-400.0f, -300.0f, 0)));
/*static const GLfloat vertices[] = {
0.0f, 300.0f, 0.0f,
400.0f, -300.0f, 0.0f,
-400.0f, -300.0f, 0.0f
};*/
// This will identify our vertex buffer
GLuint vertexbuffer;
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
while (window.isOpen()) {
window.clear(sf::Color::Blue);
//rt.clear(sf::Color::Blue);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Use our shader
//glUseProgram(programID);
odfaeg::Shader::bind(&shader);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
glDisableVertexAttribArray(0);
window.display();
sf::Event event;
while(window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}