Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Triangle::DrawFillMode(Surface* a_Target)
- {
- // Backface culling
- unsigned int t_Width = a_Target->GetWidth();
- unsigned int t_Height = a_Target->GetHeight();
- int t_FirstLine = SCRHEIGHT;
- for(int i = 0; i<SCRHEIGHT; i++)
- {
- t_Lowest[i] = SCRWIDTH;
- t_Highest[i] = 0.0f;
- }
- Pixel * t_Buffer = a_Target->GetBuffer();
- for ( int k = 0; k < 3; k++ )
- {
- float x1 = m_Vertex[k]->GetScreenX(),
- y1 = m_Vertex[k]->GetScreenY(),
- x2 = m_Vertex[(k + 1) % 3]->GetScreenX(),
- y2 = m_Vertex[(k + 1) % 3]->GetScreenY();
- float b = x2 - x1;
- float h = y2 - y1;
- float l = fabsf( b );
- if (fabsf ( h ) > l) l = fabsf( h );
- int il = (int)l;
- float dx = b / (float)l;
- float dy = h / (float)l;
- for ( int i = 0; i <= il; i++ )
- {
- int t_Y = (int)y1;
- if(t_Y<t_Height && t_Y>=0)
- {
- if(x1>t_Highest[t_Y]) t_Highest[t_Y] = x1;
- if(x1<t_Lowest[t_Y]) t_Lowest[t_Y] = x1;
- if((t_Lowest[t_Y]!=SCRWIDTH || t_Highest[t_Y]!=0) && t_Y<t_FirstLine)
- t_FirstLine = t_Y;
- }
- if(x1>=0 && x1<t_Width && y1>=0 && y1<t_Height)
- {
- *(t_Buffer + (int)x1 + (int)y1 * t_Width) = 0xAAAAAA;
- }
- x1 += dx, y1 += dy;
- }
- }
- for(int y = t_FirstLine; y<SCRHEIGHT; y++)
- {
- for(int i = t_Lowest[y]; i<t_Highest[y] && i<SCRWIDTH; i++)
- {
- if(i>=0 && i<=t_Width && y>=0 && y<t_Height)
- {
- if(*(t_Buffer + (int)i + (int)y * t_Width)==0)
- {
- *(t_Buffer + (int)i + (int)y * t_Width) = 0xffffff;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment