我正在研究一个粒子系统,尽管阅读过所有关于alphas的帖子,但我无法让我的png纹理显示在我的粒子上。
我正在使用SOIL库来读取图像:
void makeTexture () {
tex_2D = SOIL_load_OGL_single_cubemap(
"particle2.png",
SOIL_DDS_CUBEMAP_FACE_ORDER,
SOIL_LOAD_RGBA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
//| SOIL_FLAG_COMPRESS_TO_DXT
//| SOIL_FLAG_TEXTURE_REPEATS
//| SOIL_FLAG_INVERT_Y
| SOIL_FLAG_DDS_LOAD_DIRECT
);
if( tex_2D > 0 )
{
printf("%s", "2");
glEnable( GL_TEXTURE_CUBE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glBindTexture( GL_TEXTURE_CUBE_MAP, tex_2D );
}
else
{
printf("%s", "3");
tex_2D = SOIL_load_OGL_HDR_texture(
"particle2.png",
SOIL_HDR_RGBE,
//SOIL_HDR_RGBdivA,
//SOIL_HDR_RGBdivA2,
0,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
//| SOIL_FLAG_COMPRESS_TO_DXT
);
if( tex_2D < 1 )
{
printf("%s", "4");
tex_2D = SOIL_load_OGL_texture(
"particle2.png",
SOIL_LOAD_RGBA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_POWER_OF_TWO
| SOIL_FLAG_MIPMAPS
| SOIL_FLAG_MULTIPLY_ALPHA
//| SOIL_FLAG_COMPRESS_TO_DXT
| SOIL_FLAG_DDS_LOAD_DIRECT
//| SOIL_FLAG_NTSC_SAFE_RGB
//| SOIL_FLAG_CoCg_Y
//| SOIL_FLAG_TEXTURE_RECTANGLE
);
}
if( tex_2D > 0 )
{
printf("%s", "5");
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, tex_2D );
} else
{
glDisable( GL_TEXTURE_2D );
}
}
}
这是我的初始化代码:
void init(void){
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glClearDepth(1.0f);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
//glAlphaFunc(GL_GREATER, 0.4);
glEnable(GL_ALPHA_TEST);
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glLoadIdentity();
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
// Enable blending
}
这是我的渲染代码:
void RenderParticles() {
glBegin(GL_POINTS);
for (int p = 0; p < MAX_PARTICLES; p++) {
if (Particles[p].Active) {
glPushMatrix();
glDepthMask(false);
float dist = sqrt(pow(Particles[p].X, 2) + pow(Particles[p].Y, 2) + pow(Particles[p].Z, 2));
glColor4f(Particles[p].R, Particles[p].G, Particles[p].B, 1.0);
//1.8*(0.5 - dist) + RandomNumber(0, 0.2)
glBegin(GL_TRIANGLE_STRIP);
float d = 0.05;
glTexCoord2d(1,1); glVertex3f(Particles[p].X+d,Particles[p].Y+d,Particles[p].Z); // Top Right
glTexCoord2d(0,1); glVertex3f(Particles[p].X-d,Particles[p].Y+d,Particles[p].Z); // Top Left
glTexCoord2d(1,0); glVertex3f(Particles[p].X+d,Particles[p].Y-d,Particles[p].Z); // Bottom Right
glTexCoord2d(0,0); glVertex3f(Particles[p].X-d,Particles[p].Y-d,Particles[p].Z); // Bottom Left
glEnd();
glDepthMask(true);
//glutSolidSphere(RandomNumber(0.001, 0.002), 20, 20);
glPopMatrix();
}
}
glEnd();
}
这是我尝试使用的纹理:
以下是粒子的截图: