summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c65
1 files changed, 60 insertions, 5 deletions
diff --git a/src/graphic.c b/src/graphic.c
index 7f25437..3a64cfa 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -84,7 +84,6 @@ void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint3
#define PIXEL32(s,x,y) (((Uint32 *)s->pixels)[y*s->w + x])
-//FIXME : to be implmented
int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
int res, res2, bpp;
int i, modifier;
@@ -129,10 +128,10 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
for(i=0 ; i < gIni->level.terrainCount ; i++) {
int tid=gIni->level.terrains[i].id;
MPL_CHECK(
- tid > 0 && tid < MAX_TILES_COUNT,
+ tid >= 0 && tid < MAX_TILES_COUNT,
{ return 4; },
SDL_LOG_PRIORITY_CRITICAL,
- "paintTerrain(), gIni->level.terrains[%].id == %i and it's out of range", i, tid
+ "paintTerrain(), gIni->level.terrains[%i].id == %i and it is out of range", i, tid
);
tile=gRess->tiles[tid];
@@ -211,7 +210,62 @@ int paint_terrain(gameIni_t *gIni, gameRess_t *gRess) {
return 0;
}
-void render_all(SDL_Renderer *rend, render_item_t render_list[], int list_size) {
+int render_terrain(SDL_Renderer *rend, SDL_Surface *terrain, int xPos) {
+ int res;
+ SDL_Rect src_rect, dst_rect;
+ SDL_Surface *tmp_surf;
+ SDL_PixelFormat *pf = terrain->format;
+ SDL_Texture * tmp_tex;
+
+ tmp_surf = SDL_CreateRGBSurface(0,MPL_WIN_W, LEVEL_HEIGHT,
+ pf->BitsPerPixel, pf->Rmask, pf->Gmask, pf->Bmask, pf->Amask);
+
+ MPL_CHECK(
+ tmp_surf,
+ { return 1; },
+ SDL_LOG_PRIORITY_CRITICAL,
+ "Can't SDL_CreateRGBSurface() for converting terrain"
+ );
+
+ src_rect.x=xPos;
+ src_rect.y=0;
+ src_rect.w=MPL_WIN_W;
+ src_rect.h=LEVEL_HEIGHT;
+
+ dst_rect=src_rect;
+ dst_rect.x=0;
+
+ res = SDL_BlitSurface(terrain, &src_rect, tmp_surf, &dst_rect);
+ MPL_CHECK(
+ res==0,
+ { SDL_FreeSurface(tmp_surf); return 2; },
+ SDL_LOG_PRIORITY_CRITICAL,
+ "Can't SDL_BlitSurface(terrain,...)"
+ );
+
+ tmp_tex = SDL_CreateTextureFromSurface(rend, tmp_surf);
+ MPL_CHECK(
+ tmp_tex,
+ { SDL_FreeSurface(tmp_surf); return 3; },
+ SDL_LOG_PRIORITY_CRITICAL,
+ "Can't convert terrain to texture"
+ );
+
+ res=SDL_RenderCopy(rend, tmp_tex, &dst_rect, &dst_rect);
+ MPL_CHECK(
+ res==0,
+ { SDL_FreeSurface(tmp_surf); SDL_DestroyTexture(tmp_tex); return 4; },
+ SDL_LOG_PRIORITY_CRITICAL,
+ "Can't SDL_RenderCopy() the terrain"
+ );
+
+ SDL_FreeSurface(tmp_surf);
+ SDL_DestroyTexture(tmp_tex);
+
+ return 0;
+}
+
+int render_sprites(SDL_Renderer *rend, render_item_t render_list[], int list_size) {
int i, res;
SDL_Rect src,dst;
@@ -220,7 +274,8 @@ void render_all(SDL_Renderer *rend, render_item_t render_list[], int list_size)
src.y = src.h * render_list[i].currframe;
dst.x = render_list[i].x;
dst.y = render_list[i].y;
- /*res=*/ (void) SDL_RenderCopy(rend, render_list[i].sprite->t, &src, &dst);
+ res=SDL_RenderCopy(rend, render_list[i].sprite->t, &src, &dst);
}
+ return res;
}