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  {
  for (loop1=0;loop1   {
   for (loop2=0;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  {
  for( loop=0;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();
}

你可能感兴趣的:(opengl编程)