trmnl_sdl/main.cpp

53 lines
1012 B
C++

#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
#include <vector>
#include <stdio.h>
#include "sdl_helpers.h"
#include "Widgets/Widget.h"
using std::vector;
int main(int argd, char **argv)
{
int result = 0;
int screen_width = 800;
int screen_height = 600;
vector<Widget*> widgets;
if (!init_sdl())
{
return -1;
}
// Create surface
SDL_Surface* main_surface = SDL_CreateRGBSurfaceWithFormat(0, screen_width, screen_height, 32, SDL_PIXELFORMAT_RGBA8888);
if (nullptr == main_surface)
{
printf("Could not allocate main surface\n");
result = -1;
goto cleanup;
}
// Clear screen with white
SDL_FillRect(main_surface, nullptr, SDL_MapRGBA(main_surface->format, 255, 0, 255, 255));
// Apply all widgets
for (Widget* widget : widgets)
{
SDL_Rect rect = widget->get_rect();
SDL_BlitSurface(widget->get_internal_surface(), nullptr, main_surface, &rect);
}
// Save image
IMG_SavePNG(main_surface, "asdf.png");
cleanup:
clean_sdl();
return result;
}