-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcore.c
67 lines (53 loc) · 1.33 KB
/
gcore.c
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
#include <stdio.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
SDL_Surface* SC_InitVideo(int x, int y, int depth) {
SDL_Surface *surface;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Init video error\n");
return NULL;
}
surface = SDL_SetVideoMode(x,y,depth, SDL_DOUBLEBUF | SDL_ANYFORMAT);
if (surface == NULL) {
printf("Unable to set video mode:%s\n",SDL_GetError());
return NULL;
}
return surface;
}
SDL_Surface* SC_LoadImage(char* filename) {
SDL_Surface *temp;
SDL_Surface *image;
temp = IMG_Load(filename);
if (temp == NULL) {
printf("Unable to load BMP:%s\n",SDL_GetError());
return NULL;
}
image = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
SDL_SetColorKey(image,SDL_SRCCOLORKEY,0xFF00FF);
return image;
}
void SC_DrawSurface(double x, double y, SDL_Surface* image, SDL_Surface* screen) {
SDL_Rect src,dst;
src.x=0;
src.y=0;
src.w=image->w;
src.h=image->h;
dst.x=x;
dst.y=y;
dst.w=image->w;
dst.h=image->h;
SDL_BlitSurface(image,&src,screen,&dst);
}
void SC_DrawPartialSurface(double srcx, double srcy, double x, double y, double w, double h, SDL_Surface* image, SDL_Surface* screen) {
SDL_Rect src,dst;
src.x=srcx;
src.y=srcy;
src.w=w;
src.h=h;
dst.x=x;
dst.y=y;
dst.w=w;
dst.h=h;
SDL_BlitSurface(image,&src,screen,&dst);
}