43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "Display.hpp"
|
|
#include "Game.hpp"
|
|
|
|
Display::Display(Node* parent) : Node(parent) {}
|
|
|
|
glm::ivec2 Display::get_window_size()
|
|
{
|
|
glm::ivec2 size;
|
|
SDL_GetWindowSize(get_root()->window, &size.x, &size.y);
|
|
return size;
|
|
}
|
|
|
|
void Display::get_screen_pixels(unsigned char* pixels, int w, int h, int x, int y)
|
|
{
|
|
GLenum format;
|
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
format = GL_RGB;
|
|
#else
|
|
format = GL_BGR;
|
|
#endif
|
|
glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
|
|
}
|
|
|
|
SDL_Surface* Display::get_screen_surface()
|
|
{
|
|
glm::ivec2 size = get_window_size();
|
|
unsigned char* pixels = new unsigned char[bpp / 8 * size.x * size.y];
|
|
get_screen_pixels(pixels, size.x, size.y);
|
|
SDL_Surface* surface = get_screen_surface_from_pixels(pixels);
|
|
delete[] pixels;
|
|
return surface;
|
|
}
|
|
|
|
SDL_Surface* Display::get_screen_surface_from_pixels(unsigned char* pixels)
|
|
{
|
|
glm::ivec2 size = get_window_size();
|
|
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
|
|
pixels, size.x, size.y, bpp, bpp / 8 * size.x, 0, 0, 0, 0);
|
|
SDL_Surface* zoomed_surface = zoomSurface(surface, 1, -1, SMOOTHING_OFF);
|
|
SDL_FreeSurface(surface);
|
|
return zoomed_surface;
|
|
}
|