Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <glm/glm.hpp>
- using namespace glm;
- const unsigned int WIN_WIDTH = 1024;
- const unsigned int WIN_HEIGHT = 768;
- const char TITLE[] = "Tutorial 02";
- GLFWwindow *init() {
- if (!glfwInit()) {
- fprintf(stderr, "Failed to iniatialize GLFW\n");
- return NULL;
- }
- glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // openGL version 3.3
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- // dla kompatybilności z MacOS. Normalnie niepotrzebne
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- // nie chcemy starego openGL.
- GLFWwindow *window;
- window = glfwCreateWindow(WIN_WIDTH, WIN_HEIGHT, TITLE, NULL, NULL);
- if (window == NULL) {
- fprintf(stderr, "Failed to open GLFW window\n");
- glfwTerminate();
- return NULL;
- }
- // upewniamy się , czy klawisz "escape" jest łapany odpowiednio
- glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
- glfwMakeContextCurrent(window);
- glewExperimental = GL_TRUE;
- GLenum err = glewInit();
- if (GLEW_OK != err) {
- fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
- glfwTerminate();
- exit(1);
- }
- return window;
- }
- GLuint initVAO() {
- glewExperimental = GL_TRUE;
- GLuint VertexArrayID;
- glGenVertexArrays(1, &VertexArrayID);
- glBindVertexArray(VertexArrayID);
- return VertexArrayID;
- }
- static const GLfloat g_vertex_buffer_data[] = {
- -1.0f, -1.0f, 0.0f,
- 1.0f, -1.0f, 0.0f,
- 0.f, 1.0f, 0.0f,
- };
- int main() {
- GLFWwindow *window = init();
- if (!window) {
- return -1;
- }
- initVAO();
- GLuint vertex_buffer;
- glGenBuffers(1, &vertex_buffer);
- glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
- glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data),
- g_vertex_buffer_data, GL_STATIC_DRAW);
- do {
- initVAO();
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
- glVertexAttribPointer(
- 0, // attribute 0. Brak uzasadnienia
- 3, // rozmiar
- GL_FLOAT, // type
- GL_FALSE, // znormalizowane
- 0, // stride
- (void*)0 // array buffer offset
- );
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- glfwSwapBuffers(window);
- glfwPollEvents();
- } while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
- glfwWindowShouldClose(window) == 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement