Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <opengl/glew.h>
- #include <opengl/glfw3.h>
- #include <glm\glm.hpp>
- using namespace glm;
- int main()
- {
- if(!glfwInit())
- {
- printf("\nFailed to initialize GLFW.");
- return -1;
- }
- GLFWwindow *window;
- glfwWindowHint(GLFW_SAMPLES, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- window = glfwCreateWindow(1024, 768, "Simple example", NULL, NULL);
- if(!window)
- {
- printf("\nFailed to create window.");
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- glewExperimental = true;
- if(glewInit() != GLEW_OK)
- {
- printf("\nFailed to initialize GLEW.");
- glfwTerminate();
- return -1;
- }
- GLuint VertexArrayID;
- glGenVertexArrays(1, &VertexArrayID);
- glBindVertexArray(VertexArrayID);
- static const GLfloat g_vertex_buffer_data[] = {
- -1.0f, -1.0f, 0.0f,
- 1.0f, -1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f
- };
- GLuint vertexBuffer;
- glGenBuffers(1, &vertexBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
- while(!glfwWindowShouldClose(window))
- {
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- glVertexAttribPointer(0,3,GL_FLOAT, GL_FALSE, 0 , (void*)0);
- glDrawArrays(GL_TRIANGLES, 0,3);
- glDisableVertexAttribArray(0);
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwDestroyWindow(window);
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement