Hi,
after having spent quite some time to understand how OpenGL 3.2 basics work, I now wanted to display a first polygon on the screen.
Therefore I tried to build this tutorial, but I’m having some trouble.
The following code is almost completely taken from the above tutorial. The only differences are, that I’m not using SDL but SFML to create the rendering context, I reordered the commands a bit and I’m using my own shader and program classes to encapsulate the raw GL commands. Additionally I removed the loop at the end, since it has nothing to do with my problem.
// Define vertices and colors
const GLfloat diamond[4][2] = {
{ 0.0, 1.0 }, /* Top point */
{ 1.0, 0.0 }, /* Right point */
{ 0.0, -1.0 }, /* Bottom point */
{ -1.0, 0.0 } }; /* Left point */
const GLfloat colors[4][3] = {
{ 1.0, 0.0, 0.0 }, /* Red */
{ 0.0, 1.0, 0.0 }, /* Green */
{ 0.0, 0.0, 1.0 }, /* Blue */
{ 1.0, 1.0, 1.0 } }; /* White */
// Bind attributes
glBindAttribLocation(TestProgram.GetProgramObject(), 0, "in_Position");
glBindAttribLocation(TestProgram.GetProgramObject(), 1, "in_Color");
// Link Program
TestProgram.Link();
TestProgram.Use();
GLuint vao, vbo[2];
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(2, vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), diamond, GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), colors, GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);
while (App.IsOpened()) {
sf::Event Event;
// Handle events
while (App.GetEvent(Event)) {
/* ... */
}
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_LINE_LOOP, 0, 4); // <-- Here, the problem arises
App.Display();
}
The used shaders are taken almost completely from the tutorial.
As the threads title suggests, the problem is an Access Violation during runtime during the glDrawArrays call.
Reducing the count parameter of glDrawArrays(GLenum mode, GLint first, GLsizei count) to 1, solves the problem, so that no Access Violation arises. However nothing is drawn, of course.
Shaders and programs are compiled and linked successfully.
I hope someone here can help me, so that I eventually see a first polygon rendered. =)
Thanks and greetings,
OGLBeginner