openGL線型和線寬以及線的抗鋸齒

2021-06-22 19:26:55 字數 3625 閱讀 2894

opengl的線寬設定:

gllinewidth(width); width為

float

型別值,在

0~10.0

,大於10

以上按10

來處理。

若開啟線的反走樣glenable(gl_line_smooth);

,設定小數值才起作用,否則就四捨五入的處理整數了。

函式為gllinestipple(factor, pattern[patternmode]);

其中pattern

值可以是任意的你想要的,把

01轉換為

16進製制的值就可以了。

factor

為縮放因子。

pattern引數是由1或

0組成的

16位序列,它們根據需要進行重複,對一條特定的直線進行點畫處理。從這個模式的低位開始,乙個畫素乙個畫素的進行處理。如果模式中對應的位是

1,就繪製這個畫素,否則就不繪製。模式可以使用

factor

引數(表示重複因子)進行擴充套件,它與1和

0的連續子串行相乘。因此,如果模式中出現了3個

1,並且

factor是2

,那麼它們就擴充套件為

6個連續的

1。必須以

gl_line_stipple為引數呼叫glenable()

才能啟用直線點畫功能。

三、線寬**

void show_width_lines(int width,float red,float green,float blue)

//啟用反走樣

glenable(gl_blend);

glenable(gl_line_smooth);

glhint(gl_line_smooth_hint, gl_fastest); // antialias the lines

glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);

//初始化直線寬度

width=1.0;

// line_2

glcolor4f(0,green,0,1.0);

for (int i = 0; i < 8;i++ )

glflush();

}

四、線型**

void show_dot_lines(int width,float red,float green,float blue)

; static float angle = 0.0;

glenable(gl_blend);

glenable(gl_line_smooth);

glenable(gl_line_stipple);

//初始化直線寬度

width=2.0;

// line_2

glcolor3f(0,0,blue);

for (int i = 0; i<6; i++)

width = 1.0;

glcolor3f(red,0,0);

for (int i = 0; i<6; i++)

gldisable(gl_line_stipple);

glflush();

}

五、結果

線的線寬

很明顯,綠色線開啟反走樣,而淡紅色的沒有。

線型--點劃線的實現效果

開啟的反走樣,為fastest. 當然你可以根據你效果與效率之間選擇自己需要的。

六、全部實現**和工程

#include #include "glew.h"

#pragma comment(lib,"opengl32.lib")

#pragma comment(lib,"glu32.lib")

#pragma comment(lib,"./glew32.lib")

#include //

#include "glut.h"

#include#include#define drawoneline(x1,y1,x2,y2) glbegin(gl_lines);glvertex3f((x1),(y1),0); glvertex3f((x2),(y2),0);glend();

#define qingxie_ 2.0

// function declear

void init (void)

void show_width_lines(int width,float red,float green,float blue)

//啟用反走樣

glenable(gl_blend);

glenable(gl_line_smooth);

glhint(gl_line_smooth_hint, gl_fastest); // antialias the lines

glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);

//初始化直線寬度

width=1.0;

// line_2

glcolor4f(0,green,0,1.0);

for (int i = 0; i < 8;i++ )

glflush();

}void line3f(glfloat fromx, glfloat fromy, glfloat fromz,

glfloat tox, glfloat toy, glfloat toz)

void show_dot_lines(int width,float red,float green,float blue)

; static float angle = 0.0;

glenable(gl_blend);

glenable(gl_line_smooth);

glhint(gl_line_smooth_hint, gl_fastest); // 反走樣的fastest效果,也可以根據需要選擇gl_nicest.etc.

glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);

glenable(gl_line_stipple);

//初始化直線寬度

width=5.0;

// line_2

glcolor3f(0,0,blue);

for (int i = 0; i<6; i++)

width = 1.0;

glcolor3f(red,0,0);

for (int i = 0; i<6; i++)

gldisable(gl_line_stipple);

gldisable(gl_blend);

glflush();

}void pointfun()

int main (int argc, char** argv)

免分原始碼工程

end多多指教!

openGL 線型和線寬以及線抗鋸齒

opengl 的線寬設定 gllinewidth width width 為 float 型別值,在 0 10.0 大於 10 以上按 10 來處理。若開啟線的反走樣 glenable gl line smooth 設定小數值才起作用,否則就四捨五入的處理整數了。函式為 gllinestipple ...

OpenGL之抗鋸齒 以及 線寬的設定

原文 opengl之抗鋸齒 以及 線寬的設定 抗鋸齒 1.線的抗鋸齒 glenable gl line smooth 啟用 glhint gl line smooth,gl nicest 繪製 gldisable gl line smooth 關閉 2.點的抗鋸齒 glenable gl point...

線刷和卡刷的區別以及步驟

你也可以檢視我的其他同類文章,也會讓你有一定的收貨!卡刷包一般是指代ota格式的更新包,它需要擁有差分更新的能力 在某些場合,卡刷包只包含新舊檔案的差別以節省空間。如果不使用這個特性,ota格式的包也可以接近成為完整的刷機包 因此需要乙個能操作單個檔案的平台上才能執行,這個平台就是recovery。...