Gouraud着色,拉格朗日线性插值

 

做个记录HOHO #define _RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24)) struct RGBA { int r,g,b,a; RGBA(int _r,int _g,int _b,int _a) { r = _r; g = _g; b = _b; a = _a; } RGBA(){} }; void BLine(HDC hdc, int x1, int y1, int x2, int y2,int color) //bresenham算法 { int i, e, exchange, xsign, ysign; int x, y, dx, dy; dx=abs(x2-x1); dy=abs(y2-y1); x=x1; y=y1; exchange=0; if(dy>dx) { i=dx; dx=dy; dy=i; exchange=1; } e=2*dy-dx; xsign=(x2>x1)? 1:-1; ysign=(y2>y1)? 1:-1; for(i=0; i<=dx; i++){ SetPixel(hdc,x+320, 240-y, color); if(e>=0){ e=e-2*dx; if(exchange) x+=xsign; else y+=ysign; } e=e+2*dy; if(exchange) y+=ysign; else x+=xsign; } } void DrawRectangle(HDC hdc, float left, float top, float right, float bottom, RGBA color1, RGBA color2,RGBA color3, RGBA color4) { RGBA colorx,colory_left ,colory_right; for(int y = top; y <= bottom; y++) { colory_left.r = ((y - bottom) / (top - bottom) * color1.r) + ((top - y) / (top - bottom) * color3.r); colory_left.g = ((y - bottom) / (top - bottom) * color1.g) + ((top - y) / (top - bottom) * color3.g); colory_left.b = ((y - bottom) / (top - bottom) * color1.b) + ((top - y) / (top - bottom) * color3.b); colory_right.r = ((y - bottom) / (top - bottom) * color2.r) + ((top - y) / (top - bottom) * color4.r); colory_right.g = ((y - bottom) / (top - bottom) * color2.g) + ((top - y) / (top - bottom) * color4.g); colory_right.b = ((y - bottom) / (top - bottom) * color2.b) + ((top - y) / (top - bottom) * color4.b); for(int x = left; x <= right; x++) { colorx.r = ((x - right) / (left - right) * colory_left.r) + ((left - x) / (left - right) * colory_right.r); colorx.g = ((x - right) / (left - right) * colory_left.g) + ((left - x) / (left - right) * colory_right.g); colorx.b = ((x - right) / (left - right) * colory_left.b) + ((left - x) / (left - right) * colory_right.b); int color = RGB(colorx.r, colorx.g, colorx.b); SetPixel(hdc, x, y, color); } } } 主函数部分 while (true) { DWORD StartTime=GetTickCount(); if (PeekMessage(&messages,NULL,0,0,PM_REMOVE)) { if(messages.message==WM_QUIT) { break; } TranslateMessage(&messages); DispatchMessage(&messages); } HDC hdc; hdc = GetDC(hwnd); RGBA red(255,0,0,0),green(0,255,0,0),yellow(255,255,0,0), blue(0,0,255,0),black(0,0,0,0),white(255,255,255,0); DrawRectangle(hdc,100,100,300,300,yellow,blue,green,yellow); DeleteDC(hdc); while(GetTickCount()-StartTime<16); //fps 60 } 

 

无聊的一天又要过去咯~~  颜色永远是最漂亮的东西

 

垃圾csdn,又不能图片上传了,早知道我投靠百度的

 

 

你可能感兴趣的:(算法,struct,百度,null,float,Exchange)