Skip to content
Newer
Older
100644 106 lines (78 sloc) 1.94 KB
2700bd0 @wilkie Repository created.
wilkie authored
1 module video;
2
3 import derelict.sdl.sdl;
4 import derelict.sdl.image;
5 import derelict.sdl.ttf;
6 import std.stdio;
7 import std.string;
8
9
10 class Video{
11
12 int SCREEN_WIDTH = 800;
13 int SCREEN_HEIGHT = 600;
14 int SCREEN_BPP = 32;
15 int FRAMES_PER_SECOND = 30;
16
17 SDL_Surface *screen;
18
19 this(){
20 DerelictSDL.load();
21 DerelictSDLImage.load();
22 DerelictSDLttf.load();
23
24 }
25
26 public SDL_Surface *loadImage(char* fileName){
27 //The image that's loaded
28 SDL_Surface* loadedImage = null;
29 //The image that's optimized
30 SDL_Surface* optimizedImage = null;
31
32 //load's image
33 loadedImage = IMG_Load(fileName);
34
35 //optimizes the image
36 optimizedImage = SDL_DisplayFormat(loadedImage);
37 SDL_FreeSurface(loadedImage);
38
39 //return the optimized image
40 return optimizedImage;
41
42 }
43 public void applySurface(int x, int y, SDL_Surface* source){
44 SDL_Rect offset;
45
46 offset.x = x;
47 offset.y = y;
48
49 SDL_BlitSurface( source, null, screen, &offset);
50
51 }
52
53 public void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination){
54 SDL_Rect offset;
55
56 offset.x = x;
57 offset.y = y;
58
59 SDL_BlitSurface(source, null, destination, &offset);
60 }
61
62 public void init(){SDL_Init(SDL_INIT_EVERYTHING);}
63
64 public void init(char* caption){
65
66 //init sdl and setup the screen
67 SDL_Init(SDL_INIT_EVERYTHING);
68 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
69
70 SDL_WM_SetCaption(caption, null);
71 }
72
73 public void flipScreen(){
74 SDL_Flip(screen);
75 }
76
77 public void cleanUp(){
78 writefln("in cleanup");
79 DerelictSDL.unload();
80 DerelictSDLImage.unload();
81 DerelictSDLttf.unload();
82 writefln("above free surface");
83 SDL_FreeSurface(screen);
84 SDL_Quit();
85 }
86
87 public void toggleFullScreen(){
88 SDL_WM_ToggleFullScreen(screen);
89 }
90
91 public SDL_Surface *getScreen(){
92 return screen;
93 }
94
95 public void endScreen(){
96 writefln("in endScreen");
97 SDL_Surface *image = loadImage("graphics/endScreen.png");
98 writefln("below sdl surface");
99 for(int i = 0; i < 1000; i++){
100 applySurface(0,0,image);
101 flipScreen();
102 }
103 cleanUp();
104 }
105
106 }
Something went wrong with that request. Please try again.