Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SDL2/SDL.h>
- #define GL3_PROTOTYPES 1
- #include <GL3/gl3.h>
- int main(int argc, char **argv) {
- SDL_Window *window(0);
- SDL_GLContext glcontext;
- SDL_Init(SDL_INIT_VIDEO);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- window = SDL_CreateWindow("OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 360, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
- glcontext = SDL_GL_CreateContext(window);
- float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
- glClear(GL_COLOR_BUFFER_BIT);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- SDL_GL_SwapWindow(window);
- SDL_Event events;
- bool close(false);
- while(!close) {
- SDL_WaitEvent(&events);
- if((events.type == SDL_KEYDOWN && events.key.keysym.sym == SDLK_ESCAPE) || events.type == SDL_QUIT)
- close = true;
- }
- SDL_GL_DeleteContext(glcontext);
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement