opengl中紋理 顏色怎麼共存的問題
使用opengl繪製煙花 其中紋理映射了一張背景圖片 此時再使用glcolor控制煙花粒子顏色的時候 發現粒子顏色不顯示 只有白色
如果不使用glcolor 則背景紋理可以正常顯示 請問怎麼能讓紋理和顏色都正常顯示呢?
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//繪製背景
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-70,-70,-10);
glTexCoord2f(1,0);
glVertex3f(70,-70,-10);
glTexCoord2f(1,1);
glVertex3f(70,70,10);
glTexCoord2f(0,1);
glVertex3f(-70,70,10);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
//繪製粒子
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,texture[0]);
for(loop=0;loop<MAX_FIRE;++loop)
{
for (loop1=0;loop1<MAX_PARTICLES;++loop1)
{
for (loop2=0;loop2<MAX_TAIL;++loop2)
{
glPushMatrix();
glTranslatef(Fire[loop].particle[loop1][loop2].x,
Fire[loop].particle[loop1][loop2].y,
Fire[loop].particle[loop1][loop2].z+130);
// glColor3f(Fire[loop].particle[loop1][loop2].r,
// Fire[loop].particle[loop1][loop2].g,
// Fire[loop].particle[loop1][loop2].b);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-1,-1,0);
glTexCoord2f(1,0);
glVertex3f(1,-1,0);
glTexCoord2f(1,1);
glVertex3f(1,1,0);
glTexCoord2f(0,1);
glVertex3f(-1,1,0);
glEnd();
glPopMatrix();
}
}
}
glDisable(GL_TEXTURE_2D);
//粒子的更新
for (loop2=0;loop2<MAX_FIRE;++loop2)
{
for( loop=0;loop<MAX_PARTICLES;loop++)
{
// 粒子位置更新
Fire[loop2].particle[loop][0].x += Fire[loop2].particle[loop][0].xSpeed/(speedFator*1000.0f);
Fire[loop2].particle[loop][0].y += Fire[loop2].particle[loop][0].ySpeed/(speedFator*1000.0f);
Fire[loop2].particle[loop][0].z += Fire[loop2].particle[loop][0].zSpeed/(speedFator*1000.0f);
// 粒子速度更新
Fire[loop2].particle[loop][0].ySpeed +=Fire[loop2].particle[loop][0].yg/(speedFator*1000.0f);
//爆炸後更新方式
if(Fire[loop2].particle[loop][0].style==0 && Fire[loop2].particle[loop][0].ySpeed <2.0)
{
int color=rand()%12;
Fire[loop2].particle[loop][0].style = 1;
Fire[loop2].particle[loop][0].r = colors[color][0];
Fire[loop2].particle[loop][0].g = colors[color][1];
Fire[loop2].particle[loop][0].b = colors[color][2];
//速度分解
Fire[loop2].particle[loop][0].xSpeed = Fire[loop2].rad*sin(loop*15.0/(2*3.14159));
Fire[loop2].particle[loop][0].zSpeed = Fire[loop2].rad*cos(loop*15.0/(2*3.14159));
}
}
Fire[loop2].life -= Fire[loop2].fade;
}
// showframe();
glFlush();
glutSwapBuffers();
}