Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // Include GLEW PRIJE GLFW!
- #include <GL/glew.h> // u ovom programu nije potrebno
- // Include GLFW
- #include <GLFW/glfw3.h>
- // GLM
- #include <glm/glm.hpp> // u ovom programu nije potrebno
- using namespace glm;
- //[5]
- #include "shader.h"
- int main()
- {
- // GLFW inicijalizacija
- if( !glfwInit() )
- {
- std::cerr << "GLFW nije inicijaliziran\n";
- getchar();
- return -1;
- }
- glfwWindowHint(GLFW_SAMPLES, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // samo za MacOS
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- // kreiranje prozora i OpenGL context
- GLFWwindow* window = glfwCreateWindow( 1024, 768, "prog_01", nullptr, nullptr);
- if( window == nullptr )
- {
- std::cerr << "Nije prošao init glfw prozora. Npr. neki Intel GPU nisu 3.3 kompatibilni.\n";
- getchar();
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- // GLEW inicijalizacija
- if (glewInit() != GLEW_OK)
- {
- std::cerr << "GLEW nije inicijaliziran\n";
- getchar();
- glfwTerminate();
- return -1;
- }
- // sticky key press capture
- glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
- // pozadina
- glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
- //[1 Vertex Array Object
- GLuint VertexArrayID;
- glGenVertexArrays(1, &VertexArrayID);
- glBindVertexArray(VertexArrayID);
- //]
- // [2 An array of three vectors which represents three vertices
- 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,
- };
- //]
- //[3
- GLuint vertexbuffer; // This will identify our vertex buffer
- glGenBuffers(1, &vertexbuffer); // Generate 1 buffer, put the resulting identifier in vertexbuffer
- glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer
- glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // Give our vertices to OpenGL.
- //]
- // [5] Create and compile our GLSL program from the shaders
- GLuint programID = loadShaders( "vertex.glsl", "fragment.glsl" );
- // napokon, loop
- do {
- // Brisanje ekrana
- // glClear( GL_COLOR_BUFFER_BIT );
- //[6
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glUseProgram(programID); // Use our shader
- //]
- //[4 first attribute buffer : vertices
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
- glVertexAttribPointer(
- 0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
- 3, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
- );
- // Draw the triangle !
- glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
- glDisableVertexAttribArray(0);
- //]
- // Swap buffers
- glfwSwapBuffers(window);
- glfwPollEvents();
- } // loop se vrti sve dok ne stisnemo ESC ili dok se prozor ne zatvori
- while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
- glfwWindowShouldClose(window) == 0 );
- // zatvaranje OpenGL prozora i GLFW
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment