mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-17 06:06:00 -06:00
101 lines
2.1 KiB
Text
101 lines
2.1 KiB
Text
template "SDL with Core package" main;
|
|
|
|
option "Create header" header;
|
|
option "Initialize video" video;
|
|
option "Double buffering" doublebuff;
|
|
option "Full screen" fullscreen;
|
|
option "Use SSE2" sse2 = 1;
|
|
|
|
@@<:PACKAGE:>.h
|
|
??header
|
|
#ifndef _<:PACKAGE:>_<:PACKAGE:>_h
|
|
#define _<:PACKAGE:>_<:PACKAGE:>_h
|
|
|
|
#include <Core/Core.h>
|
|
#include <SDL.h>
|
|
|
|
using namespace Upp;
|
|
|
|
#endif
|
|
@@<:PACKAGE:>.cpp
|
|
<:?header:>#include "<:PACKAGE:>.h"
|
|
<:/:>#include <Core/Core.h>
|
|
#include <plugin/SDL/SDL.h>
|
|
|
|
using namespace Upp;
|
|
<:.:><:?video:>
|
|
SDL_Surface * OpenScreen(const int width, const int height, const int bpp, const int flags)
|
|
{
|
|
SDL_Surface * screen = SDL_SetVideoMode(width, height, bpp, flags);
|
|
if(!screen)
|
|
{
|
|
Cout() << Format("Couldn't set display mode: %s\n", SDL_GetError());
|
|
return NULL;
|
|
}
|
|
return screen;
|
|
}
|
|
|
|
void Paint(SDL_Surface * surface)
|
|
{
|
|
/* Put your painting code here */
|
|
}
|
|
<:.:>
|
|
CONSOLE_APP_MAIN
|
|
{
|
|
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
return;
|
|
<:?video:>
|
|
int videoflags = SDL_HWSURFACE | SDL_HWACCEL<:(fullscreen || doublebuff ? fullscreen ? doublebuff ? " | SDL_FULLSCREEN | SDL_DOUBLEBUF" : " | SDL_FULLSCREEN" : doublebuff ? " | SDL_DOUBLEBUF" : "" : ""):>;
|
|
SDL_Surface * screen = OpenScreen(1024, 768, 32, videoflags);
|
|
if(!screen)
|
|
return;
|
|
<:.:>
|
|
SDL_Event event;
|
|
bool done = false;
|
|
|
|
while(!done)
|
|
{
|
|
if(SDL_PollEvent(&event))
|
|
{
|
|
switch (event.type)
|
|
{
|
|
case SDL_KEYDOWN:
|
|
if(event.key.keysym.sym == SDLK_LALT || event.key.keysym.sym == SDLK_TAB)
|
|
break;
|
|
<:?video:>if(event.key.keysym.sym == SDLK_RETURN)
|
|
{
|
|
videoflags ^= SDL_FULLSCREEN;
|
|
screen = OpenScreen(screen->w, screen->h, screen->format->BitsPerPixel, videoflags);
|
|
if(!screen)
|
|
done = true;
|
|
break;
|
|
}<:.:>
|
|
case SDL_QUIT:
|
|
done = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
<:?video:>else
|
|
{
|
|
Paint(screen);
|
|
SDL_Flip(screen);
|
|
}<:.:>
|
|
}<:?video:>
|
|
SDL_FreeSurface(screen);<:.:>
|
|
SDL_Quit();
|
|
}
|
|
@@<:PACKAGE:>.upp
|
|
uses
|
|
Core;
|
|
|
|
library(MSC) "SDL SDLmain";
|
|
library(GCC WIN32) "SDL.dll SDLmain";
|
|
|
|
file<:?header:>
|
|
<:PACKAGE:>.h,<:.:>
|
|
<:PACKAGE:>.cpp;
|
|
|
|
mainconfig
|
|
"" = "<:?sse2:>SSE2<:.:>";
|