90 lines
3.4 KiB
C++
90 lines
3.4 KiB
C++
/* +------------------------------------------------------+
|
|
____/ \____ /| - Open source game framework licensed to freely use, |
|
|
\ / / | copy, modify and sell without restriction |
|
|
+--\ ^__^ /--+ | |
|
|
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
|
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
|
| SPACE ~~~~~ | /
|
|
| ~~~~~~~ BOX |/
|
|
+-------------*/
|
|
|
|
#pragma once
|
|
|
|
#include <sstream>
|
|
|
|
#include "glm/vec2.hpp"
|
|
|
|
#include "SDL.h"
|
|
#include "SDL_image.h"
|
|
|
|
#include "sdl2-gfx/SDL2_gfxPrimitives.h"
|
|
#include "sdl2-gfx/SDL2_rotozoom.h"
|
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
#include "emscripten/html5.h"
|
|
#endif
|
|
|
|
#include "Node.hpp"
|
|
#include "Box.hpp"
|
|
#include "Log.hpp"
|
|
|
|
namespace sb
|
|
{
|
|
class Display : public Node
|
|
{
|
|
|
|
public:
|
|
|
|
const static int bpp = 32;
|
|
inline const static Box ndc {-1.0f, -1.0f, 2.0f, 2.0f, true};
|
|
|
|
Display(Node*);
|
|
glm::ivec2 window_size() const;
|
|
Uint32 pixel_format(int = 0) const;
|
|
Box window_box(bool = false) const;
|
|
Box ndc_subsection(const Box&) const;
|
|
Box ndc_to_pixel(const Box&) const;
|
|
|
|
/*!
|
|
* Fill the supplied, pre-allocated buffer with 32-bit pixels (8 bits per component) from the GL read buffer. This buffer of
|
|
* unsigned 8-bit values must be large enough to hold w x h x 32-bits of data
|
|
*
|
|
* @param pixels Pre-allocated, unsigned 8-bit buffer that will be filled with pixel color data
|
|
* @param w Size in width of the region to read from the GL read buffer
|
|
* @param h Size in height of the region to read from the GL read buffer
|
|
* @param x X position of the corner to start reading from in the GL read buffer
|
|
* @param y Y position of the corner to start reading from in the GL read buffer
|
|
*/
|
|
void screen_pixels(unsigned char* pixels, int w, int h, int x = 0, int y = 0) const;
|
|
|
|
SDL_Surface* screen_surface() const;
|
|
SDL_Surface* screen_surface_from_pixels(unsigned char* pixels, bool flip = true) const;
|
|
|
|
/*!
|
|
* Respond to full screen requests and window resize events. If fluid resize is enabled in the configuration, respond to
|
|
* resize events as the screen is being resized, otherwise respond once when the resize is finished.
|
|
*
|
|
* The dispay object subscribes to SDL events in its constructor, so this function will be called automatically by
|
|
* sb::Delegate::dispatch when an event happens.
|
|
*
|
|
* @param event an SDL event
|
|
*/
|
|
void respond(SDL_Event& event);
|
|
|
|
/*!
|
|
* Set window to fullscreen if it is not currently displayed fullscreen, otherwise exit fullscreen.
|
|
*
|
|
* In builds other than Emscripten, this uses the SDL_WINDOW_FULLSCREEN_DESKTOP flag to create a fullscreen window. SDL creates
|
|
* the fullscreen window without changing video modes by resizing the window to the size of desktop and removing borders.
|
|
*
|
|
* Emscripten builds use `emscripten_request_fullscreen()` instead, which handles fullscreen from web browsers more smoothly.
|
|
*
|
|
* If "display" > "fullscreen enabled" is false in the configuration, this function does nothing.
|
|
*/
|
|
void toggle_fullscreen() const;
|
|
|
|
};
|
|
}
|
|
|
|
#include "Game.hpp"
|