summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c69
1 files changed, 51 insertions, 18 deletions
diff --git a/src/graphic.c b/src/graphic.c
index 18e62c2..576cbfa 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -70,6 +70,52 @@ SDL_Surface * loadGif(char *filePath) {
return IMG_Load(filePath);
}
+int init(char *winCaption, gameConfig_t *conf, gameGraphics_t *gGraph) {
+ int result;
+
+ memset(gGraph,0,sizeof(gameGraphics_t));
+
+ // SDL subsystems initialization
+ result = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO );
+ if ( result != 0 ) {
+ logs2(LOG_ERROR, "init(), SDL_Init()", SDL_GetError());
+ return 1;
+ }
+
+ // Screen setup
+ gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, 32, SDL_HWSURFACE | SDL_ASYNCBLIT);
+ if( gGraph->screen == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError());
+ return 2;
+ }
+
+ // SDL main window caption
+ SDL_WM_SetCaption(winCaption, NULL);
+
+ // We dont want to see the standard mouse cursor in our main window
+ //TODO: SDL_ShowCursor(0);
+
+ // Memory allocation and initialization for all display layers
+ gGraph->surfaces.terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if( gGraph->surfaces.terrain == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError());
+ return 3;
+ }
+
+ gGraph->surfaces.stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if( gGraph->surfaces.stencil == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError());
+ return 3;
+ }
+
+ gGraph->surfaces.tmpSurf = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if( gGraph->surfaces.tmpSurf == NULL ) {
+ logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError());
+ return 3;
+ }
+
+ return 0;
+}
int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) {
int res, i, modifier;
int x,y,xmin,xmax,ymin,ymax,y2,xdst,ydst;
@@ -178,43 +224,30 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) {
int repaint(gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect) {
int objToRepaintCount, i, res;
gameGraphObjState_t *objToRepaint;
- SDL_Surface *tmpSurf;
- tmpSurf=createSurface(srcRect->w, srcRect->h);
-
- if (tmpSurf==NULL) {
- logs(LOG_ERROR, "repain(), createSurface() has failed");
- return 1;
- }
objToRepaintCount=findAndZSortObjects(srcSurfs->objectsStat, srcRect, &objToRepaint);
for(i=0;i<objToRepaintCount;++i) {
if(objToRepaint[i].zOrder>0) break;
- res=paintObject(objToRepaint+i, srcRect, tmpSurf);
+ res=paintObject(objToRepaint+i, srcRect, dstSurf, &dstRect);
if ( res!=0 ) {
logs(LOG_DEBUG, "repaint(), paintObject() failed");
}
}
- res=SDL_BlitSurface(srcSurfs->terrain, srcRect, tmpSurf, NULL);
+ res=SDL_BlitSurface(srcSurfs->terrain, srcRect, dstSurf, &dstRect);
if ( res!=0 ) {
logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError());
}
for(;i<objToRepaintCount;++i) {
- res=paintObject(objToRepaint+i, srcRect, tmpSurf);
+ res=paintObject(objToRepaint+i, srcRect, dstSurf, &dstRect);
if ( res!=0 ) {
logs(LOG_DEBUG, "repaint(), paintObject() failed");
}
}
- res=SDL_BlitSurface(tmpSurf, NULL, dstSurf, &dstRect);
- if ( res!=0 ) {
- logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError());
- }
-
free(objToRepaint);
- SDL_FreeSurface(tmpSurf);
return res;
}
@@ -225,8 +258,8 @@ int findAndZSortObjects(gameGraphObjState_t *objectsStat, SDL_Rect *offsetRect,
return 0;
}
-int paintObject(gameGraphObjState_t *obj, SDL_Rect *srcRect, SDL_Surface *dstSurf) {
+int paintObject(gameGraphObjState_t *obj, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect *dstRect) {
//TODO
- fprintf(stderr, "TODO paintObject(%p, %p, %p)\n", (void *)obj,(void *)srcRect,(void *)dstSurf);
+ fprintf(stderr, "TODO paintObject(%p, %p, %p, %p)\n", (void *)obj,(void *)srcRect,(void *)dstSurf, (void *)dstRect);
return 0;
}