Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GLEW_STATIC
- #include <GL/glew.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <glm.hpp>
- #include <gtx/transform.hpp>
- #include <gtc/type_ptr.hpp>
- #include <SDL.h>
- #include <SDL_image.h>
- #include <iostream>
- #include "Shader.h"
- #include "textures.h"
- int main(int argc, char **argv)
- {
- SDL_Window* fenetre(0);
- SDL_GLContext contexteOpenGL(0);
- SDL_Event evenements;
- bool terminer(false);
- if(SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- std::cout << "Erreur lors de l'initialisation de la SDL : " << SDL_GetError() << std::endl;
- SDL_Quit();
- return -1;
- }
- fenetre = SDL_CreateWindow("Test SDL 2.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
- contexteOpenGL = SDL_GL_CreateContext(fenetre);
- GLenum initialisationGLEW( glewInit() );
- glEnable(GL_DEPTH_TEST);
- //Shader shader("shader.vs", "shader.fs");
- Shader shader("Shaders/couleur3D.vert", "Shaders/couleur3D.frag");
- float vertices[] = {-1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, // Face 1
- -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, // Face 1
- 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, // Face 2
- 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, // Face 2
- -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, // Face 3
- -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, // Face 3
- -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, // Face 4
- -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, // Face 4
- -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, // Face 5
- -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, // Face 5
- -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, // Face 6
- -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0}; // Face 6
- float couleurs[] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Face 1
- 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Face 1
- 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, // Face 2
- 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, // Face 2
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, // Face 3
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, // Face 3
- 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Face 4
- 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Face 4
- 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, // Face 5
- 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, // Face 5
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, // Face 6
- 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0}; // Face 6
- unsigned int VBO, VAO;
- glGenVertexArrays(1, &VAO);
- glGenBuffers(1, &VBO);
- glBindVertexArray(VAO);
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(couleurs), 0, GL_STATIC_DRAW);
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
- glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(couleurs), couleurs);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, ((char*)NULL + (sizeof(couleurs))));
- glEnableVertexAttribArray(1);
- //GLuint texture = loadTexture("wall.jpg", 1);
- //3d matrices
- glm::mat4 projection;
- glm::mat4 modelview;
- projection = glm::perspective(70.0, (double) 800 / 600, 1.0, 10000.0);
- modelview = glm::mat4(1.0);
- float angle(0.0);
- unsigned long fps = 0;
- Uint32 time = SDL_GetTicks();
- while(!terminer)
- {
- SDL_PollEvent(&evenements);
- switch(evenements.type)
- {
- case SDL_WINDOWEVENT:
- if(evenements.window.event == SDL_WINDOWEVENT_CLOSE)
- terminer = true;
- break;
- case SDL_KEYDOWN:
- switch(evenements.key.keysym.scancode)
- {
- case SDL_SCANCODE_ESCAPE:
- terminer = true;
- break;
- }
- break;
- }
- if(SDL_GetTicks() - time >= 1000)
- {
- std::cout << fps << std::endl;
- time = SDL_GetTicks();
- fps = 0;
- }
- else
- fps++;
- //Clear scren
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- modelview = glm::lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
- modelview = glm::rotate(modelview, angle, glm::vec3(0, 1, 0));
- // render container
- shader.use();
- glBindVertexArray(VAO);
- // On envoie les matrices au shader
- shader.setMat4("projection", projection);
- shader.setMat4("modelview", modelview);
- // On affiche le polygone
- glDrawArrays(GL_TRIANGLES, 0, 36);
- //Update screen
- //SDL_GL_SwapWindow(fenetre);
- angle += 4.0;
- if(angle >= 360.0)
- angle -= 360.0;
- //SDL_Delay(50);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement