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