ultimatepp/uppsrc/upt/SDLPure.upt
cxl 2b551591c8 Fixed SDL.upt #889
git-svn-id: svn://ultimatepp.org/upp/trunk@7891 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2014-11-13 14:09:22 +00:00

92 lines
2 KiB
Text

template "SDL project (no U++)" 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 <SDL.h>
#endif
@@<:PACKAGE:>.cpp
<:?header:>#include "<:PACKAGE:>.h"<:/:>#include <plugin/SDL/SDL.h><:.:>
<:?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)
{
printf("Couldn't set display mode: %s\n", SDL_GetError());
return NULL;
}
return screen;
}
void Paint(SDL_Surface * surface)
{
/* Put your painting code here */
}
<:.:>
int main(int argc, char **argv)
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;
<:?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 1;
<:.:>
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();
return 0;
}
@@<:PACKAGE:>.upp
library(MSC) "SDL SDLmain";
library(GCC WIN32) "SDL.dll SDLmain";
file<:?header:>
<:PACKAGE:>.h,<:.:>
<:PACKAGE:>.cpp;
mainconfig
"" = "<:?sse2:>SSE2<:.:>";