 Joined: Apr 2008
Posts: 1860
|
Notice: These functions work with any sprite size, but the functionality in _ext differs from GM one. The difference is with scaling. x and y arguments, according to manual, is "(x,y) is the place where one of the sprites is drawn". In GM these arguments are modified with scaling, so, for example, when you have a 100x100 sprite, you tile it with 0.5 scale, and put 25 in x and y position, then you won't have a sprite drawn in 25,25 as manual suggests, but you will have one drawn at 12.5,12.5. In this code this it will be drawn in 25,25. This can be changed with two parenthesis, but I think this is how the function needed to work in the first place.
Function: draw_sprite_tiled(int spr,int subimg,double x,double y);
GSsprite.h:
int draw_sprite_tiled(int spr,int subimg,double x,double y); GSsprite.cpp:
int draw_sprite_tiled(int spr,int subimg,double x,double y) { enigma::sprite *spr2d = enigma::spritestructarray[spr]; if (!spr2d) return -1;
if (enigma::cur_bou_tha_noo_sho_eve_cha_eve != spr2d->texturearray[subimg % spr2d->subcount]) { glBindTexture(GL_TEXTURE_2D,spr2d->texturearray[subimg % spr2d->subcount]); enigma::cur_bou_tha_noo_sho_eve_cha_eve = spr2d->texturearray[subimg % spr2d->subcount]; }
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glPushAttrib(GL_CURRENT_BIT); glColor4f(1,1,1,1);
const float tbx=spr2d->texbordx,tby=spr2d->texbordy, xoff=spr2d->xoffset+x, yoff=spr2d->yoffset+y; const int hortil= int (ceil(room_width/(spr2d->width*tbx))), vertil= int (ceil(room_height/(spr2d->height*tby))); glBegin(GL_QUADS); for (int i=0; i<hortil; i++){ for (int c=0; c<vertil; c++){ glTexCoord2f(0,0); glVertex2f(i*spr2d->width-xoff,c*spr2d->height-yoff); glTexCoord2f(tbx,0); glVertex2f((i+1)*spr2d->width-xoff,c*spr2d->height-yoff); glTexCoord2f(tbx,tby); glVertex2f((i+1)*spr2d->width-xoff,(c+1)*spr2d->height-yoff); glTexCoord2f(0,tby); glVertex2f(i*spr2d->width-xoff,(c+1)*spr2d->height-yoff); } } glEnd();
glPopAttrib(); return 0; } Function:draw_sprite_tiled_ext(int spr,int subimg,double x,double y,double xscale,double yscale,int color,double alpha);
GSsprite.h:
int draw_sprite_tiled_ext(int spr,int subimg,double x,double y,double xscale,double yscale,int color,double alpha); GSsprite.cpp:
int draw_sprite_tiled_ext(int spr,int subimg,double x,double y, double xscale,double yscale,int color,double alpha) { enigma::sprite *spr2d = enigma::spritestructarray[spr]; if (!spr2d) return -1;
if (enigma::cur_bou_tha_noo_sho_eve_cha_eve != spr2d->texturearray[subimg % spr2d->subcount]) { glBindTexture(GL_TEXTURE_2D,spr2d->texturearray[subimg % spr2d->subcount]); enigma::cur_bou_tha_noo_sho_eve_cha_eve = spr2d->texturearray[subimg % spr2d->subcount]; }
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glPushAttrib(GL_CURRENT_BIT); glColor4ub(__GETR(color),__GETG(color),__GETB(color),char(alpha*255));
const float tbx=spr2d->texbordx,tby=spr2d->texbordy, xoff=spr2d->xoffset*xscale+x, yoff=spr2d->yoffset*yscale+y; const int hortil= int (ceil(room_width/(spr2d->width*tbx*xscale))), vertil= int (ceil(room_height/(spr2d->height*tby*yscale))); glBegin(GL_QUADS); for (int i=0; i<hortil; i++){ for (int c=0; c<vertil; c++){ glTexCoord2f(0,0); glVertex2f(i*spr2d->width*xscale-xoff,c*spr2d->height*yscale-yoff); glTexCoord2f(tbx,0); glVertex2f((i+1)*spr2d->width*xscale-xoff,c*spr2d->height*yscale-yoff); glTexCoord2f(tbx,tby); glVertex2f((i+1)*spr2d->width*xscale-xoff,(c+1)*spr2d->height*yscale-yoff); glTexCoord2f(0,tby); glVertex2f(i*spr2d->width*xscale-xoff,(c+1)*spr2d->height*yscale-yoff); } } glEnd();
glPopAttrib(); return 0; } In attachments you can see two images. First one is: draw_sprite_tiled(spr_0,0,50,50); Other one is: draw_sprite_tiled_ext(spr_0,0,25,25,0.5,0.5,c_yellow,0.5);
|