gpt4 book ai didi

c++ - 旋转时照明的 GL_POINT_SPRITE_ARB(广告牌)问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:09:06 24 4
gpt4 key购买 nike

我创建了一个小应用程序来显示单个粒子:

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 进行相机旋转。

最佳答案

关闭GL_LIGHTING。我不确定你为什么要戴上它。

关于c++ - 旋转时照明的 GL_POINT_SPRITE_ARB(广告牌)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9191592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com