I've begun doing a bit of OpenGL, and I've just discovered alternatives to the fixed function pipeline, so I went searching tutorials. Sadly, most good tutorials use C++, and I would like to stick to C if possible. So I wasn't able to just copy-paste stuff and try it.
Copy-pasting and merging code gave errors though, and I'm not sure how I should deal with them. The error in question was "Segmentation fault", and here is the code:
#include <GL/glfw.h>
#include <GL/glu.h>
#include <stdlib.h>
#define SCREEN_WIDTH 1600
#define SCREEN_HEIGHT 1000
void main(int argc, char **argv)
{
float mouse_x, mouse_y;
GLuint positionBufferObject;
const float vertexPositions[] = {
0.75f, 0.75f, 0.0f, 1.0f,
0.75f, -0.75f, 0.0f, 1.0f,
-0.75f, -0.75f, 0.0f, 1.0f,
};
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int running = GL_TRUE;
// Initialize GLFW
if( !glfwInit() )
{
exit( EXIT_FAILURE );
}
// Open an OpenGL window
if( !glfwOpenWindow(SCREEN_WIDTH,SCREEN_HEIGHT, 8,8,8,8,8,8, GLFW_WINDOW ) )
{
glfwTerminate();
exit( EXIT_FAILURE );
}
while (running)
{
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
}
Of course, a lot of code is missing here, because it (apparently) didn't influence the error. Commenting out "glDrawArrays" fixes the error, and OpenGL runs normally (without drawing anything, logically).
Any help?