[Change] Stars use alpha instead of colors.
This commit is contained in:
parent
fd22930673
commit
c124c9fcca
59
src/space.c
59
src/space.c
@ -12,34 +12,37 @@ static Vec2 starPos[STAR_LAYERS];
|
|||||||
|
|
||||||
static gl_texture* starBG_create(const int density);
|
static gl_texture* starBG_create(const int density);
|
||||||
static void put_pixel(SDL_Surface* surface, const int x, const int y,
|
static void put_pixel(SDL_Surface* surface, const int x, const int y,
|
||||||
const Uint8 R, const Uint8 G, const Uint8 B);
|
const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A);
|
||||||
|
|
||||||
// Modify the pixel at (x,y) of the surface to be of color RGB.
|
// Modify the pixel at (x,y) of the surface to be of color RGB.
|
||||||
static void put_pixel(SDL_Surface* surface, const int x, const int y, const Uint8 R, const Uint8 G, const Uint8 B) {
|
static void put_pixel(SDL_Surface* surface, const int x, const int y,
|
||||||
Uint32 color = SDL_MapRGB(surface->format, R, G, B);
|
const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A) {
|
||||||
|
|
||||||
Uint8* bufp8;
|
Uint32 pixel = SDL_MapRGBA(surface->format, R, G, B, A);
|
||||||
Uint16* bufp16;
|
int bpp = surface->format->BytesPerPixel;
|
||||||
Uint32* bufp32;
|
// p is the address to the pixel we want to set.
|
||||||
|
Uint8* p = (Uint8*)surface->pixels + y * surface->pitch + x * bpp;
|
||||||
|
|
||||||
switch(surface->format->BytesPerPixel) {
|
switch(bpp) {
|
||||||
case 1: // 8bpp.
|
case 1:
|
||||||
bufp8 = (Uint8)surface->pixels + y*surface->pitch + x;
|
*p = pixel;
|
||||||
*bufp8 = color;
|
|
||||||
break;
|
break;
|
||||||
case 2: // 15 or 16bpp.
|
case 2:
|
||||||
bufp16 = (Uint16*)surface->pixels + y*surface->pitch/2 + x;
|
*(Uint16*)p = pixel;
|
||||||
*bufp16 = color;
|
|
||||||
break;
|
break;
|
||||||
case 3: // 24bpp, Slow as hell.
|
case 3:
|
||||||
bufp8 = (Uint8*)surface->pixels + y*surface->pitch + x;
|
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
|
||||||
*(bufp8 + surface->format->Rshift/8) = R;
|
p[0] = (pixel >> 16) & 0xff;
|
||||||
*(bufp8 + surface->format->Gshift/8) = G;
|
p[1] = (pixel >> 8) & 0xff;
|
||||||
*(bufp8 + surface->format->Bshift/8) = B;
|
p[2] = pixel & 0xff;
|
||||||
|
} else {
|
||||||
|
p[0] = pixel & 0xff;
|
||||||
|
p[1] = (pixel >> 8) & 0xff;
|
||||||
|
p[2] = (pixel >> 16) & 0xff;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4: // 32bpp.
|
case 4:
|
||||||
bufp32 = (Uint32*)surface->pixels + y*surface->pitch/4 + x;
|
*(Uint32*)p = pixel;
|
||||||
*bufp32 = color;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +52,7 @@ static void put_pixel(SDL_Surface* surface, const int x, const int y, const Uint
|
|||||||
static gl_texture* starBG_create(const int density) {
|
static gl_texture* starBG_create(const int density) {
|
||||||
SDL_Surface* surface;
|
SDL_Surface* surface;
|
||||||
int w, h;
|
int w, h;
|
||||||
int i, b, d, x, y;
|
int i, d;
|
||||||
|
|
||||||
w = (int)((float)gl_screen.w * 1.5);
|
w = (int)((float)gl_screen.w * 1.5);
|
||||||
if((w & (w-1)) != 0) {
|
if((w & (w-1)) != 0) {
|
||||||
@ -72,13 +75,13 @@ static gl_texture* starBG_create(const int density) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_LockSurface(surface);
|
||||||
|
|
||||||
d = (int)((FP)(density)*(FP)(gl_screen.w)*(FP)(gl_screen.h)/1000./1000.);
|
d = (int)((FP)(density)*(FP)(gl_screen.w)*(FP)(gl_screen.h)/1000./1000.);
|
||||||
for(i = 0; i < d; i++) {
|
for(i = 0; i < d; i++)
|
||||||
b = RNG(50, 255);
|
put_pixel(surface, RNG(0,w-1), RNG(0,h-1), 255, 255, 255, RNG(50, 255));
|
||||||
x = RNG(0, w-1);
|
|
||||||
y = RNG(0, h-1);
|
SDL_UnlockSurface(surface);
|
||||||
put_pixel(surface, x, y, b, b, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gl_loadImage(surface);
|
return gl_loadImage(surface);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user