@@ -147,6 +147,8 @@ int main(int argc, char** argv) {
147147 float time = 0 .0f ;
148148 bool close = false ;
149149 SDL_SetRelativeMouseMode (SDL_TRUE);
150+ GLCALL (glEnable (GL_CULL_FACE));
151+ GLCALL (glEnable (GL_DEPTH_TEST));
150152 while (!close) {
151153 SDL_Event event;
152154 while (SDL_PollEvent (&event)) {
@@ -172,6 +174,9 @@ int main(int argc, char** argv) {
172174 case SDLK_LSHIFT:
173175 buttonShift = true ;
174176 break ;
177+ case SDLK_ESCAPE:
178+ SDL_SetRelativeMouseMode (SDL_FALSE);
179+ break ;
175180 }
176181 } else if (event.type == SDL_KEYUP) {
177182 switch (event.key .keysym .sym ) {
@@ -195,12 +200,18 @@ int main(int argc, char** argv) {
195200 break ;
196201 }
197202 } else if (event.type == SDL_MOUSEMOTION) {
198- camera.onMouseMoved (event.motion .xrel , event.motion .yrel );
203+ if (SDL_GetRelativeMouseMode ()) {
204+ camera.onMouseMoved (event.motion .xrel , event.motion .yrel );
205+ }
206+ } else if (event.type == SDL_MOUSEBUTTONDOWN) {
207+ if (event.button .button == SDL_BUTTON_LEFT) {
208+ SDL_SetRelativeMouseMode (SDL_TRUE);
209+ }
199210 }
200211 }
201212
202213 glClearColor (0 .0f , 0 .0f , 0 .0f , 1 .0f );
203- glClear (GL_COLOR_BUFFER_BIT);
214+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
204215 time += delta;
205216
206217 if (buttonW) {
0 commit comments