From fc6d7c15e18a91e4670c07494d767b76ac5bcc96 Mon Sep 17 00:00:00 2001 From: Petr Sykora Date: Sun, 13 Jul 2008 18:17:29 +0200 Subject: [PATCH] priprava roztahovani spritu --- gr.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- gr.h | 2 ++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/gr.c b/gr.c index 2840777..d5f6571 100644 --- a/gr.c +++ b/gr.c @@ -7,6 +7,7 @@ #define TRECT(x,y,w,h, tw, th) glBegin(GL_TRIANGLE_STRIP);glTexCoord2f(0.0,h/th);glVertex2f(x, y+1*h);glTexCoord2f(0.0,0.0);glVertex2f(x, y);glTexCoord2f(w/tw,h/th);glVertex2f(x+1*w, y+1*h);glTexCoord2f(w/tw,0.0);glVertex2f(x+1*w, y);glEnd(); #define RECT(x,y,w,h) glBegin(GL_TRIANGLE_STRIP);glVertex2f(x, y+1*h);glVertex2f(x, y);glVertex2f(x+1*w, y+1*h);glVertex2f(x+1*w, y);glEnd(); +#define TTRECT(x,y,w,h,sw,sh, tw, th) glBegin(GL_TRIANGLE_STRIP);glTexCoord2f(0.0,sh/th);glVertex2f(x, y+1*h);glTexCoord2f(0.0,0.0);glVertex2f(x, y);glTexCoord2f(sw/tw,sh/th);glVertex2f(x+1*w, y+1*h);glTexCoord2f(sw/tw,0.0);glVertex2f(x+1*w, y);glEnd(); unsigned int occupied=0; @@ -36,6 +37,8 @@ typedef struct{ Sprite *sprite; double x; double y; + double xx; + double yy; int z; //z SDL_Color c; }SpriteQueueItem; @@ -351,23 +354,32 @@ void FlushSpriteQueue(){ void SwapSpriteQueueItems(int aid, int bid){ SpriteQueueItem c; - c.sprite = gsprite_queue_sorted.items[aid].sprite; + memcpy(&c, &gsprite_queue_sorted.items[aid], sizeof(SpriteQueueItem)); + memcpy(&gsprite_queue_sorted.items[aid], &gsprite_queue_sorted.items[bid], sizeof(SpriteQueueItem)); + memcpy(&gsprite_queue_sorted.items[bid], &c, sizeof(SpriteQueueItem)); + /*c.sprite = gsprite_queue_sorted.items[aid].sprite; c.x = gsprite_queue_sorted.items[aid].x; + c.xx = gsprite_queue_sorted.items[aid].xx; c.y = gsprite_queue_sorted.items[aid].y; + c.yy = gsprite_queue_sorted.items[aid].yy; c.z = gsprite_queue_sorted.items[aid].z; c.c = gsprite_queue_sorted.items[aid].c; gsprite_queue_sorted.items[aid].sprite = gsprite_queue_sorted.items[bid].sprite ; gsprite_queue_sorted.items[aid].x = gsprite_queue_sorted.items[bid].x ; + gsprite_queue_sorted.items[aid].xx = gsprite_queue_sorted.items[bid].xx ; gsprite_queue_sorted.items[aid].y = gsprite_queue_sorted.items[bid].y ; + gsprite_queue_sorted.items[aid].yy = gsprite_queue_sorted.items[bid].yy ; gsprite_queue_sorted.items[aid].z = gsprite_queue_sorted.items[bid].z ; gsprite_queue_sorted.items[aid].c = gsprite_queue_sorted.items[bid].c ; gsprite_queue_sorted.items[bid].sprite = c.sprite; gsprite_queue_sorted.items[bid].x = c.x; + gsprite_queue_sorted.items[bid].xx = c.xx; gsprite_queue_sorted.items[bid].y = c.y; + gsprite_queue_sorted.items[bid].yy = c.yy; gsprite_queue_sorted.items[bid].z = c.z; - gsprite_queue_sorted.items[bid].c = c.c; + gsprite_queue_sorted.items[bid].c = c.c;*/ } void YSortSpriteQueue(int from, int to){ @@ -451,8 +463,8 @@ int DrawSprites(){ ds = gsprite_surfaces.surfaces[dspr->SID]; dest.x = G2SX(gsprite_queue_sorted.items[i].x); dest.y = G2SY(gsprite_queue_sorted.items[i].y); - dest.w = G2SX(gsprite_queue_sorted.items[i].sprite->width); - dest.h = G2SX(gsprite_queue_sorted.items[i].sprite->height); + dest.w = G2SX(gsprite_queue_sorted.items[i].xx); + dest.h = G2SX(gsprite_queue_sorted.items[i].yy); src.x = 0; src.y = 0; src.w = G2SX(gsprite_queue_sorted.items[i].sprite->width); @@ -461,7 +473,7 @@ int DrawSprites(){ glBindTexture(GL_TEXTURE_2D, ds); glColor3ub(gsprite_queue_sorted.items[i].c.r, gsprite_queue_sorted.items[i].c.g, gsprite_queue_sorted.items[i].c.b); - TRECT(dest.x, dest.y, dest.w, dest.h, dspr->twidth, dspr->theight); + TTRECT(dest.x, dest.y, dest.w, dest.h, src.w, src.h, dspr->twidth, dspr->theight); } glDisable(GL_TEXTURE_2D); @@ -557,7 +569,37 @@ void QueueDrawSpriteColorize(Sprite *sprite, double x, double y, int z, SDL_Colo item = &gsprite_queue.items[gsprite_queue.next_id]; item->sprite = sprite; item->x = x; + item->xx = sprite->width; item->y = y; + item->yy = sprite->height; + item->z = z; + item->c = color; + + gsprite_queue.next_id ++; +}; + +void QueueDrawSpriteColorizeStretch(Sprite *sprite, double x, double y, double xx, double yy, int z, SDL_Color color){ + SpriteQueueItem *item; + if(!sprite){ + printf("NULL sprite*\n"); + return; + } + if(gsprite_queue.next_id >=gsprite_queue.allocated){ + item = (SpriteQueueItem *) realloc(gsprite_queue.items, sizeof(SpriteQueueItem)*gsprite_queue.allocated*2); + if(item == 0){ + fprintf(stderr, "Can't allocate enough memory for sprite queue\n"); + return; + } + gsprite_queue.allocated *= 2; + gsprite_queue.items = item; + } + + item = &gsprite_queue.items[gsprite_queue.next_id]; + item->sprite = sprite; + item->x = x; + item->xx = xx; + item->y = y; + item->yy = yy; item->z = z; item->c = color; diff --git a/gr.h b/gr.h index 89e13a8..f9c054d 100644 --- a/gr.h +++ b/gr.h @@ -58,3 +58,5 @@ void QueueDrawSprite(Sprite *sprite, double x, double y, int z); void QueueDrawSpriteColorize(Sprite *sprite, double x, double y, int z, SDL_Color c); //queue target sprite to be drawn at [x,y] at level z 0-deepest +void QueueDrawSpriteColorizeStretch(Sprite *sprite, double x, double y, double xx, double yy, int z, SDL_Color c); +//queue target sprite to be drawn at [x,y] at level z 0-deepest -- 2.11.4.GIT