2012-02-08 65 views
1

照明我創建了一個小應用程序來顯示單個顆粒:GL_POINT_SPRITE_ARB(產生廣告牌)的問題與在旋轉時

img

當我周圍的場景中的照明變化和粒子幾乎成爲不可見的旋轉:

img

是否可以強制設置整個旋轉的照明?

相關代碼:

// init 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

glAccum(GL_RETURN, 0.95f); 

glClear(GL_ACCUM_BUFFER_BIT); 
glClearAccum(0.0f, 0.0f, 0.0f, 0.0f); 


glDisable(GL_CULL_FACE); 
glShadeModel(GL_SMOOTH); 
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
glClearDepth(1.0f); 
glDisable(GL_DEPTH_TEST); 
glEnable(GL_BLEND); 
glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); 



float quadratic[3] = { 0.0, 0.0, 0.01337f }; 
float linear[3] = { 0.0, 1, 0.0 }; 
float constant[3] = { 0.01, 0.0, 0.0 }; 

glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic); 
float maxSize = 0.0f; 
glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize); 
glPointSize(maxSize); 
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize); 
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f); 

QImage b("particle.bmp"); 

QImage t; 
t = QGLWidget::convertToGLFormat(b); 
glGenTextures(1, texture); 
glBindTexture(GL_TEXTURE_2D, texture[0]); 
glTexImage2D(GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits()); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); 

而且繪製函數:

// draw function: 

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glAccum(GL_RETURN, 0.95f); 
glClear(GL_ACCUM_BUFFER_BIT); 

glDepthMask(GL_FALSE); 
glEnable(GL_BLEND); 
glEnable(GL_TEXTURE_2D); 
glEnable(GL_LIGHTING); 
glEnable(GL_POINT_SPRITE_ARB); 
glColor4f(1.0f, 1.0f, 0.1f, 0.7f); 

glBegin(GL_POINTS); 
// Loop over all particles and draw the gl points separately: 
     glVertex3f(x, y, z); 
glEnd(); 
glDisable(GL_POINT_SPRITE_ARB); 
glDisable(GL_TEXTURE_2D); 
glDisable(GL_LIGHTING); 
glDisable(GL_BLEND); 
glAccum(GL_ACCUM, 0.5f); 

如果你想自己here's完整的代碼進行測試。我使用libqglviewer進行相機旋轉。

+0

Alt + PrintScreen通常只捕獲活動窗口。 – genpfault 2012-02-08 22:58:50

+0

我知道。屏幕截圖似乎是次要的我。我更新了它們。謝謝! – Pascal 2012-02-09 08:17:23

回答

1

關閉GL_LIGHTING。我不確定你爲什麼要放在首位。

+0

哈,是的。這確實是!我在另一臺計算機上創建了這篇文章,並忘記提交這些更改。所以我在我面前的代碼看起來像這樣: ' glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glEnable(GL_POINT_SPRITE_ARB); glColor4f(1.0f,1.0f,0.1f,0.7f); glBegin(GL_POINTS); draw(); glEnd(); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); ' 這讓我記住,libqglviewer *可能*啓用GL_LIGHTING的繪圖功能。我只需要首先禁用GL_LIGHTING。 – Pascal 2012-02-09 09:17:56