4 #include "SDL_opengl.h"
11 SDL_Init(SDL_INIT_VIDEO);
12 m_window = SDL_CreateWindow("IPDF", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
13 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
17 Fatal("Couldn't create window!");
20 m_gl_context = SDL_GL_CreateContext(m_window);
22 ResizeViewport(800, 600);
28 SDL_GL_DeleteContext(m_gl_context);
29 SDL_DestroyWindow(m_window);
33 void Screen::ResizeViewport(int width, int height)
35 glViewport(0, 0, width, height);
36 m_viewport_width = width;
37 m_viewport_height = height;
40 bool Screen::PumpEvents()
43 bool no_quit_requested = true;
44 while (SDL_PollEvent(&evt))
49 no_quit_requested = false;
52 switch (evt.window.event)
54 case SDL_WINDOWEVENT_RESIZED:
55 case SDL_WINDOWEVENT_SIZE_CHANGED:
56 ResizeViewport(evt.window.data1, evt.window.data2);
61 m_last_mouse_x = evt.motion.x;
62 m_last_mouse_y = evt.motion.y;
65 m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0);
68 case SDL_MOUSEBUTTONDOWN:
69 case SDL_MOUSEBUTTONUP:
70 m_last_mouse_x = evt.button.x;
71 m_last_mouse_y = evt.button.y;
74 m_mouse_handler(evt.button.x, evt.button.y, evt.button.state, 0);
80 m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y);
87 return no_quit_requested;
90 void Screen::SetMouseCursor(Screen::MouseCursors cursor)
92 SDL_SystemCursor system_cursor_id = SDL_SYSTEM_CURSOR_ARROW;
95 case CursorArrow: system_cursor_id = SDL_SYSTEM_CURSOR_ARROW; break;
96 case CursorWait: system_cursor_id = SDL_SYSTEM_CURSOR_WAIT; break;
97 case CursorWaitArrow: system_cursor_id = SDL_SYSTEM_CURSOR_WAITARROW; break;
98 case CursorMove: system_cursor_id = SDL_SYSTEM_CURSOR_SIZEALL; break;
99 case CursorHand: system_cursor_id = SDL_SYSTEM_CURSOR_HAND; break;
102 SDL_Cursor *system_cursor = SDL_CreateSystemCursor(system_cursor_id);
103 SDL_SetCursor(system_cursor);
104 //TODO: Check if we need to free the system cursors.
107 void Screen::Present()
109 SDL_GL_SwapWindow(m_window);