-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdl.cpp
63 lines (51 loc) · 1.3 KB
/
sdl.cpp
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
/**
* @file sfml.cpp
* @author your name ([email protected])
* @brief
* @version 0.1
* @date 2022-09-20
*
* @copyright Copyright (c) 2022
*
* Compile -flags:
* -lSDL2
*
*/
#define GLEW_STATIC
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <stdio.h>
int main(int argc, char *argv[]){
// OpenGL window and Context settings
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
// Creae Window
SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
// Create OpenGL context
SDL_GLContext context = SDL_GL_CreateContext(window);
//Initialize glew
glewExperimental = GL_TRUE;
glewInit();
// Make sure your project is well set up
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
printf("%u\n", vertexBuffer);
SDL_Event windowEvent;
while(true){
if(SDL_PollEvent(&windowEvent)){
if(windowEvent.type == SDL_QUIT)
break;
if(windowEvent.type == SDL_KEYUP &&
windowEvent.key.keysym.sym == SDLK_ESCAPE)
break;
}
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(context);
SDL_Quit();
return 0;
}