8 #include "stb_truetype.h"
9 #include "graphicsbuffer.h"
10 #include "shaderprogram.h"
16 * The "Screen" class handles managing the OS window (using SDL2).
21 Screen(bool visible = true);
24 // 'Pumps' the system event queue.
25 // Returns 'false' if the program should quit.
28 // Clears the screen to a given colour.
29 void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0);
31 // Finishes rendering a frame, and presents it on the screen.
34 // Get the current width/height of the window's viewport.
35 int ViewportWidth() const { return m_viewport_width; }
36 int ViewportHeight() const { return m_viewport_height; }
38 // Debug Font handling
39 void DebugFontInit(const char *font_name, float font_size = 12);
40 void DebugFontClear();
41 void DebugFontPrint(const char *str);
42 void DebugFontPrintF(const char *fmt, ...);
44 // Handle mouse input.
45 typedef void(*MouseHandler)(int x, int y, int button, int wheel, Screen * scr, View * view);
46 void SetMouseHandler(MouseHandler handler)
48 m_mouse_handler = handler;
59 void SetMouseCursor(MouseCursors cursor);
61 void ScreenShot(const char * filename) const;
62 void RenderBMP(const char * filename) const;
63 void RenderPixels(int x, int y, int w, int h, uint8_t * pixels) const;
66 void SetView(View * new_view) {m_view = new_view;}
68 // Returns the CPU time (in seconds) it took to render the last completed frame.
69 double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); }
70 // Returns the GPU time (in seconds) it took to render the last completed frame.
71 double GetLastFrameTimeGPU() const;
73 void RequestQuit() {m_no_quit_requested = false;}
74 bool QuitRequested() const {return !m_no_quit_requested;}
76 void ShowDebugFont(bool show = true) {m_show_debug_font = show;}
77 bool DebugFontShown() const {return m_show_debug_font;}
79 bool Valid() const {return m_window != NULL;}
81 void ResizeViewport(int width, int height);
82 void DebugFontFlush();
84 MouseHandler m_mouse_handler;
88 double m_last_frame_time;
89 double m_frame_begin_time;
90 GLuint m_frame_gpu_timer;
91 GLuint m_last_frame_gpu_timer;
94 int m_viewport_height;
96 SDL_GLContext m_gl_context;
97 ShaderProgram m_texture_prog;
98 ShaderProgram m_font_prog;
99 GLint m_colour_uniform_location;
100 GraphicsBuffer m_viewport_ubo;
101 stbtt_bakedchar m_debug_font_rects[96];
102 unsigned int m_debug_font_atlas;
103 float m_debug_font_x;
104 float m_debug_font_y;
105 float m_debug_font_size;
106 GraphicsBuffer m_debug_font_vertices;
107 GraphicsBuffer m_debug_font_indices;
108 int m_debug_font_vertex_head;
109 int m_debug_font_index_head;
111 bool m_no_quit_requested;
112 bool m_show_debug_font;