Advertisement
Kitomas

KIT_TTM_ClearCanvas3D

May 5th, 2023
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. int KIT_TTM_ClearCanvas3D(KIT_TTM_Canvas3D* canvas, uint8_t r,uint8_t g,uint8_t b){
  2.   int errorCode, color=0x00000000 | (b<<16) | (g<<8) | r; //0xAABBGGRR
  3.   if(!canvas) return SDL_SetError("\"canvas\" is a NULL pointer");
  4.   if(!canvas->locked) if((errorCode=KIT_TTM_LockCanvas3D(canvas))) return errorCode;
  5.   int canvasArea=canvas->pitch*canvas->h; //=sizeof(SDL_Color/int/float) * width*height
  6.   int* pixels=canvas->pixels;
  7.   if(canvas->autoZReset && canvas->zBuffer) KIT_TTM_ResetCanvas3DZBuffer(canvas);
  8.   else return SDL_SetError("\"canvas->zBuffer\" is a NULL pointer");
  9.   //if r==g && g==b, r==b also, so therefore all 3 are equal
  10.   if(r==g && g==b) memset(pixels,r,canvasArea);
  11.   else { canvasArea/=sizeof(SDL_Color); //now it's just width*height
  12.     for(int i=0; i<canvasArea; ++i) pixels[i]=color;
  13.   }
  14.   if(canvas->autoUnlock) KIT_TTM_UnlockCanvas3D(canvas);
  15.   return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement