-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsanity_main.cpp
executable file
·120 lines (97 loc) · 2.61 KB
/
insanity_main.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
// Resource: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/linux/cli/index.php
//Using SDL and standard IO
#include <GL/glew.h>
#include <GL/glu.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <stdio.h>
#include <iostream>
#include "glib.h"
using namespace std;
int main( int argc, char* args[] )
{
// Initialization flag
bool success = true;
// Create viewer Object
Gviewer viewer;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Use OpenGL 2.1
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
// OpenGL prefs - enable double buffering
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetSwapInterval(1);
//Create window
viewer.gWindow = SDL_CreateWindow( "Insanity", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, viewer.width, viewer.height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE );
if( viewer.gWindow == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
// Create Context
viewer.gContext = SDL_GL_CreateContext( viewer.gWindow );
if ( viewer.gContext == NULL ){
printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else{
// Use vsync
if ( SDL_GL_SetSwapInterval(1) < 0 ){
printf("Warning: Unable to set Vsync. SDL Error: %s\n", SDL_GetError());
}
// Use OpenGL 3.0 and later
glewExperimental = GL_TRUE;
// Initialize GLEW
GLenum GlewInitResult = glewInit();
// Error check
if (GLEW_OK != GlewInitResult)
{
printf("ERROR: %s\n",glewGetErrorString(GlewInitResult));
exit(EXIT_FAILURE);
}
// Initialize OpenGL
if ( !viewer.initGL() )
{
printf("Unable to initialize OpenGL!\n");
success = false;
}
else
{
bool running = true;
while (running){
SDL_Event event;
while (SDL_PollEvent(&event)){
// If user quits
if (event.type == SDL_QUIT){
running = false;
}
if (event.type = SDL_KEYDOWN){
}
// Pass event to event handler
viewer.handleEvent(&event);
}
viewer.render();
SDL_GL_SwapWindow(viewer.gWindow);
}
}
}
}
}
//Destroy viewer object
viewer.close();
//Destroy window
SDL_DestroyWindow( viewer.gWindow );
//Quit SDL subsystems
SDL_Quit();
return success;
}