1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #include <glew.h>
#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
// Notre fenêtre
SDL_Window* fenetre;
SDL_GLContext contexteOpenGL;
SDL_Event evenements;
bool terminer(false);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
// Initialisation de la SDL
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
cout << "Erreur lors de l'initialisation de la SDL : " << SDL_GetError() << endl;
SDL_Quit();
return -1;
}
fenetre = SDL_CreateWindow("Chapitre 3", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
contexteOpenGL = SDL_GL_CreateContext(fenetre);
// Création de la fenêtre
// Vertices et coordonnées
float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
// Boucle principale
while(!terminer)
{
// Gestion des évènements
SDL_WaitEvent(&evenements);
if(evenements.window.event == SDL_WINDOWEVENT_CLOSE)
terminer = true;
// Nettoyage de l'écran
glClear(GL_COLOR_BUFFER_BIT);
// On remplie puis on active le tableau Vertex Attrib 0
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
// On affiche le triangle
glDrawArrays(GL_TRIANGLES, 0, 3);
// On désactive le tableau Vertex Attrib puisque l'on n'en a plus besoin
glDisableVertexAttribArray(0);
// Actualisation de la fenêtre
SDL_GL_SwapWindow(fenetre);
}
// On quitte la SDL
SDL_GL_DeleteContext(contexteOpenGL);
SDL_DestroyWindow(fenetre);
SDL_Quit();
return 0;
} |
Partager