-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_sdl002.cpp
52 lines (42 loc) · 1.05 KB
/
main_sdl002.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
#include <iostream>
#include <SDL/SDL.h>
#include <GL/glew.h>
using namespace std;
enum GameState {PLAY, EXIT};
int main(int argc, char** argv) {
SDL_Window* _window = nullptr;
GameState _gameState = PLAY;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL Initialization Error!" << endl;
}
else {
_window = SDL_CreateWindow("Dipesh Game",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_OPENGL);
if (_window == nullptr) {
cout << "Creating window Error!" << endl;
}
}
SDL_GLContext glContext = SDL_GL_CreateContext(_window);
if (glContext == nullptr) {
cout << "Cannot Create The Context!" << endl;
}
GLenum error = glewInit();
if (error != GLEW_OK) {
cout << "OpenGL is not Supported!" << endl;
}
glClearColor(1.0f, 1.0f, 0.0f, 1);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(_window);
while (_gameState != EXIT) {
SDL_Event evt;
if ( SDL_PollEvent( &evt ) ) {
switch (evt.type) {
case SDL_QUIT:
_gameState = EXIT;
break;
}
}
}
SDL_DestroyWindow(_window);
SDL_Quit();
return 0;
}