本文介绍了在扫描线填充中识别水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试在屏幕上渲染某些字体.其实我已经做到了.
现在我正在尝试填充字符,即填充有界区域.

我唯一拥有的是一个2-d缓冲区,该缓冲区存储每个像素的信息,即如果要照亮像素则设置该像素,否则它包含``0''.

我想不出使用此逻辑来填充边界区域的逻辑.
这是我尝试过的方法,但由于无法识别水平线而失败.

Hey I am trying to render some fonts on the screen. Actually I have done that.
Now what I am trying is to fill the characters i.e. fill the bounded regions.

The only thing I have is a 2-d buffer which stores information for each pixel i.e. it is set if the pixel is to be illuminated otherwise it contains ''0''.

I cant think of a logic to fill the bounded regions using this.
This is what I tried but it failed as it cant recognize the horizontal lines.

for(int p=0 ; p<401 ; ++p){
            for(int q=0 ; q<401 ; ++q){
                if( buffer[p][q] == 1 ){
                    ++q ;
                    while (buffer[p][q] == 0){
                          buffer[p][q]  = 1 ;
                          ++q ;
                    }
                }
            }
        }

推荐答案


struct MyPoint {
	int x, y;
};
// Fill horizontal lines between points in given point list
// - does not draw on outline (border)
void FillBetweens(MyPoint* list, size_t list_size)
{
	// assumes list is sorted from top to bottom and left to right
	int current_y = 0;
	for (size_t i=0; i<list_size-1; ++i)
	{
		if( list[i].y != current_y )
			current_y = list[i].y; // or ++current_y (depends on your choices)
		if( list[i+1].y == current_y )
		{
			// your horizontal line drawing function (y,x1,x2)
			// - assumes drawing between end points
			draw_betweens(list[i].y, list[i].x, list[i+1].x);
			++i;
		}
		// else we skip single point lines
	}
}


这篇关于在扫描线填充中识别水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:31