0 Members and 3 Guests are viewing this topic.
void drawprintnum(int x, int y, int num, int width, int height, void*glyph_nums) { int digits[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; int pos_num = (num<0)?(-num):(num); int num_digits = 0; for(int i = 0; i < 10; i++) { if(!pos_num) { break; } digits[i] = pos_num%10; pos_num = (pos_num - (pos_num%10)) / 10; num_digits++; } if(num<0) { CopySpriteMasked(glyph_nums + (width*height*2*10), x, y, width, height, 0xFFFF); x += width+2; } else if (num == 0) { CopySpriteMasked(glyph_nums, x, y, width, height, 0xFFFF); return; } for(int i = 0; i < num_digits; i++) { CopySpriteMasked((digits[i]*(width*height*2))+glyph_nums, x, y, width, height, 0xFFFF); x += width+2; }}
#define WIDTH 384#define HEIGHT 216short * VRAM = (short*) GetVRAMAddress();void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha){ int y_index; int x_index; short * base = y * WIDTH + x + VRAM; for (y_index = height; y_index > 0; --y_index, base += WIDTH - width) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } }}
I think if (*base != alpha) should be if (*bitmap != alpha) because you want that color in the bitmap to cause transparency, not that color in VRAM.Edit: Also, base += WIDTH should be base += WIDTH - width because base was increased by the inner loop.
I should have clip' too, may you do it, please?
#define WIDTH 384#define HEIGHT 216short * VRAM = (short*) GetVRAMAddress();void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha){ int y_index; int x_index; short * base = y * WIDTH + x + VRAM; if (y < 0) { base += (y & 0x8fffffff) * WIDTH; bitmap += (y & 0x8fffffff) * WIDTH; height += y; y = 0; } if (height > HEIGHT) height = HEIGHT + y; for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } }}
#define WIDTH 384#define HEIGHT 216short * VRAM = (short*) GetVRAMAddress();void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha){ int x_inc = width; if (y < 0) { bitmap -= y * x_inc; height += y; y = 0; } if (height > HEIGHT - y) height = HEIGHT - y; if (x < 0) { bitmap -= x; width += x; x = 0; } if (width > WIDTH - x) width = WIDTH - x; int y_index; int x_index; short * base = y * WIDTH + x + VRAM; for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } }}
#define WIDTH 384#define HEIGHT 216short * VRAM = (short*) GetVRAMAddress();void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha){ int x_inc = 0; if (y < 0) { bitmap -= (short*)(y * width); height += y; y = 0; } if (height > HEIGHT - y) height = HEIGHT - y; if (x < 0) { bitmap -= (short*)x; width += x; x = 0; x_inc += -x; } if (width > WIDTH - x) { width = WIDTH - x; x_inc += WIDTH - (width + x); } int y_index; int x_index; short * base = (short*)(y * WIDTH) + x + VRAM; for (y_index = height; y_index > 0; --y_index, base += (short*)WIDTH - width, bitmap += (short*)x_inc) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } }}
Eww bad bad typecasts. They won't work (ever try adding a short* to a short*?) and they're just not needed. Adding an int to a pointer is the preferred method for offsetting anyway.
Quote from: calc84maniac on October 25, 2011, 10:52:59 pmEww bad bad typecasts. They won't work (ever try adding a short* to a short*?) and they're just not needed. Adding an int to a pointer is the preferred method for offsetting anyway.It's been awhile since I did some heavy messing around with type casts. Looks like I forgot that adding an int to a pointer results in an implicit type cast. All of my programming class stuff (which is in java) makes pointers a lot harder when I come back to C especially because java is very strongly typed.
#define WIDTH 384#define HEIGHT 216short * VRAM = (short*) GetVRAMAddress();void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha){ int x_inc = width; if (y < 0) { bitmap -= y * width; height += y; y = 0; } if (height > HEIGHT - y) height = HEIGHT - y; if (x < 0) { bitmap -= x; width += x; x = 0; } if (width > WIDTH - x) width = WIDTH - x; x_inc -= width; int y_index; int x_index; short * base = y * WIDTH + x + VRAM; for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } }}