From 30e82851bcc78ef7c93ee260401abac9e7bd5039 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 1 Apr 2016 22:06:21 -0400 Subject: [PATCH] Fixes to 3D mode (mostly fixes it on OS X) --- src/PowderToySDL.cpp | 103 +++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 54658fcfb3..29ad86c9cd 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -205,8 +205,7 @@ void DrawPixel(pixel * vid, pixel color, int x, int y) void DrawCursor(pixel * vid) { - //vid[100+100*WINDOWW] = 255<<24|PIXRGB(100, 0, 100); - for (int j = 1; j <= 9; j++) + for (int j = 0; j <= 9; j++) { for (int i = 0; i <= j; i++) { @@ -277,26 +276,37 @@ void blit(pixel * vid) dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577)) { - //pixel format conversion + //pixel format conversion, used for strange formats (OS X specifically) int i; + unsigned int red, green, blue; pixel px, lastpx, nextpx; SDL_PixelFormat *fmt = sdl_scrn->format; for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - dst[i] = ((PIXR(lastpx)>>fmt->Rloss)<Rshift)| - ((PIXG(nextpx)>>fmt->Gloss)<Gshift)| - ((PIXB(nextpx)>>fmt->Bloss)<Bshift); + int redshift = PIXB(lastpx) + PIXG(lastpx); + if (redshift > 255) + redshift = 255; + int blueshift = PIXR(nextpx) + PIXG(nextpx); + if (blueshift > 255) + blueshift = 255; + red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<Rshift; + green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<Gshift; + blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<Bshift; } else - dst[i] = src[i]; + { + px = src[i]; + red = (PIXR(px)>>fmt->Rloss)<Rshift; + green = (PIXG(px)>>fmt->Gloss)<Gshift; + blue = (PIXB(px)>>fmt->Bloss)<Bshift; + } + dst[i] = red|green|blue; } dst+=sdl_scrn->pitch/PIXELSIZE; src+=pitch; @@ -305,29 +315,26 @@ void blit(pixel * vid) else { int i; - pixel px, lastpx, nextpx; for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; - float redshift = PIXB(lastpx)*.3f + PIXG(lastpx)*.3f; - if (redshift > 255*.3f) - redshift = 255*.3f; - float blueshift = PIXR(nextpx)*.3f + PIXG(nextpx)*.3f; - if (blueshift > 255*.3f) - blueshift = 255*.3f; - dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift)); + int redshift = PIXB(lastpx) + PIXG(lastpx); + if (redshift > 255) + redshift = 255; + int blueshift = PIXR(nextpx) + PIXG(nextpx); + if (blueshift > 255) + blueshift = 255; + dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f)); } - else - dst[i] = src[i]; } - //memcpy(dst, src, w*PIXELSIZE); + else + memcpy(dst, src, w*PIXELSIZE); dst+=sdl_scrn->pitch/PIXELSIZE; src+=pitch; } @@ -356,24 +363,36 @@ void blit2(pixel * vid, int currentScale) { //pixel format conversion SDL_PixelFormat *fmt = sdl_scrn->format; + int red, green, blue; for (j=0; j= depth3d/2 && i < w+depth3d/2 ? src[i-depth3d/2] : 0; - nextpx = i >= -depth3d/2 && i < w-depth3d/2 ? src[i+depth3d/2] : 0; - px = ((PIXR(lastpx)>>fmt->Rloss)<Rshift)| - ((PIXG(nextpx)>>fmt->Gloss)<Gshift)| - ((PIXB(nextpx)>>fmt->Bloss)<Bshift); + lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0; + nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; + int redshift = PIXB(lastpx) + PIXG(lastpx); + if (redshift > 255) + redshift = 255; + int blueshift = PIXR(nextpx) + PIXG(nextpx); + if (blueshift > 255) + blueshift = 255; + red = ((int)(PIXR(lastpx)*.69f+redshift*.3f)>>fmt->Rloss)<Rshift; + green = ((int)(PIXG(nextpx)*.3f)>>fmt->Gloss)<Gshift; + blue = ((int)(PIXB(nextpx)*.69f+blueshift*.3f)>>fmt->Bloss)<Bshift; + } + else + { + px = src[i]; + red = (PIXR(px)>>fmt->Rloss)<Rshift; + green = (PIXG(px)>>fmt->Gloss)<Gshift; + blue = (PIXB(px)>>fmt->Bloss)<Bshift; } - dst[i*2]=px; - dst[i*2+1]=px; + dst[i*2] = red|green|blue; + dst[i*2+1] = red|green|blue; } dst+=sdl_scrn->pitch/PIXELSIZE; } @@ -391,15 +410,15 @@ void blit2(pixel * vid, int currentScale) px = src[i]; if (depth3d) { - lastpx = i >= depth3d/2 && i < w+depth3d/2 ? src[i-depth3d/2] : 0; - nextpx = i >= -depth3d/2 && i < w-depth3d/2 ? src[i+depth3d/2] : 0; - float redshift = PIXB(lastpx)*.3f + PIXG(lastpx)*.3f; - if (redshift > 255*.3f) - redshift = 255*.3f; - float blueshift = PIXR(nextpx)*.3f + PIXG(nextpx)*.3f; - if (blueshift > 255*.3f) - blueshift = 255*.3f; - px = PIXRGB((int)(PIXR(lastpx)*.69f+redshift), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift)); + lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0; + nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; + int redshift = PIXB(lastpx) + PIXG(lastpx); + if (redshift > 255) + redshift = 255; + int blueshift = PIXR(nextpx) + PIXG(nextpx); + if (blueshift > 255) + blueshift = 255; + px = PIXRGB((int)(PIXR(lastpx)*.69f+redshift*.3f), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift*.3f)); } dst[i*2] = px; dst[i*2+1] = px;