Hi, have been spending many hours of setting up glfw with xcode and i believe i finally got it to work, since it works to create a window using it. I am very new to OpenGL and I have followed several tutorials on how to make a single triangle on the screen and no matter what i try it seems like I can't get it to draw the triangle to the screen, as in it draws the window but nothing more.
I am not sure if it is of importance but when running these,
the program breaks on glewInit() with EXC_BAD_ACCESS, but without them it works just fine.
So if anyone could take a look on my code and see if it is my code that is wrong or it might be my linking and such,
Thanks for you time!
//Hintze
I am not sure if it is of importance but when running these,
Code:
glfwWindowHint(GLFW_SAMPLES, 1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
So if anyone could take a look on my code and see if it is my code that is wrong or it might be my linking and such,
Code:
#include <iostream>
#include <GL/glew.h>
#include <GL/glfw3.h>
GLuint vboId;
void CreateVertexBuffer()
{
float triangle [] ={-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f};
glGenBuffers(1, &vboId);
glBindBuffer(GL_ARRAY_BUFFER,vboId);
glBufferData(GL_ARRAY_BUFFER,sizeof(triangle),triangle,GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
}
int main(int argc,char **argv)
{
GLFWwindow* window;
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_SAMPLES, 1); // 4x antialiasing
glfwWindowHint(3,1);
window = glfwCreateWindow(1024, 768, "Hello World", NULL, NULL);
glfwMakeContextCurrent(window);
glewExperimental=GL_TRUE;
if (glewInit () != GLEW_NO_ERROR)
{
std::cout << "Failed to initialize GLEW... " << std::endl;
return -1;
}
CreateVertexBuffer();
while (!glfwWindowShouldClose(window))
{
glClearColor(.1, .1, .1, .1);
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
}
//Hintze