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 void ResizeViewport(int width, int height);
80 void DebugFontFlush();
82 MouseHandler m_mouse_handler;
86 double m_last_frame_time;
87 double m_frame_begin_time;
88 GLuint m_frame_gpu_timer;
89 GLuint m_last_frame_gpu_timer;
92 int m_viewport_height;
94 SDL_GLContext m_gl_context;
95 ShaderProgram m_texture_prog;
96 ShaderProgram m_font_prog;
97 GLint m_colour_uniform_location;
98 GraphicsBuffer m_viewport_ubo;
99 stbtt_bakedchar m_debug_font_rects[96];
100 unsigned int m_debug_font_atlas;
101 float m_debug_font_x;
102 float m_debug_font_y;
103 float m_debug_font_size;
104 GraphicsBuffer m_debug_font_vertices;
105 GraphicsBuffer m_debug_font_indices;
106 int m_debug_font_vertex_head;
107 int m_debug_font_index_head;
109 bool m_no_quit_requested;
110 bool m_show_debug_font;