Oddly blended textures.

http://img357.imageshack.us/img357/1649/sbb.png
http://img150.imageshack.us/img150/7073/sbc.png

I have a bunch of these (view on black background), which I draw using the feedback buffer to define at what window coordinates a bunch of points (corresponding to the images’ centres) end up. However, instead of being correctly blended, they are drawn like this:

Any other texture put in their place renders in the same way, and those textures put elsewhere (i.e. “images mode”, the mode which renders 3d billboards of the galaxies with colour images) render correctly. All of my textures are loaded with libSOIL (http://lonesock.net/soil). glColor3f makes a miniscule difference:


(zoom 4x)

It seems as if every galaxy symbol is drawn on top of itself several times. However, the loop seems to be correct (I use a while loop to run through the feedback buffer), and the only other thing that could be making a difference are my Begin2D()/End2D() functions:

void Begin2D()
{
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
      glLoadIdentity();
      glOrtho(0.0, window_width, 0.0, window_height, -1.0, 1.0);
      glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
  return;
}

void End2D()
{
        glPopMatrix();
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
  return;
}

which get me into a 2D view. I draw my text between these, and it blends correctly… I think. I’m not sure just how antialiased does the font get.

Anyone with whatever insights on the subject, please help…

I think the way you are loading your texture is wrong.

Are you using windows? Can you try reading your pngs with GDI+, or any other library for that matter?

It looks like the alpha channel is not being read properly.

Or just post your texture loading code so we can have a look. :slight_smile:

Yes, I am using Windows, but my PNGs are loaded with a library called SOIL, and, if put them in any other section of my program, they are drawn correctly.

Based on the uploaded rendered images you sent, it seems as if the alpha channel is not being read properly. If you look at your image files the alpha of the the galaxies smoothly decreases to zero at the edges. But your rendered images are very pixelated.

Could you paste some additional code snippets so we can have a better look. Are you using glut? Did u create your glut environment glutInitDisplayMode with GLUT_RGBA?

Did you load up your texture as RGBA or ARGB?

Did you enable GL_BLEND?

I’m kinda shooting in the dark here. :slight_smile:

I’m not using glut, I’m coding in plain opengl on win32. I have GL_BLEND on, and my textures are all loaded as RGBA. Here’s the source code.

for (int i=0; i<num_galaxies; i++)
  {
    GLfloat alpha=1.0f;   
    if (first_person&&i==selected_galaxy&&travelled>0.7f) alpha=1.0f-travelled*travelled*travelled;
    
    if (drawmode==DRAW_IMAGES)
    {
      // this works
      glBindTexture(GL_TEXTURE_2D, texture[i]);
        
      if (draw_redshift)
      {
        if (galaxies[i].redshift>0) glColor4f(1.0f,0.8f,0.8f,alpha);
        else if (galaxies[i].redshift<0) glColor4f(0.8f,0.8f,1.0f,alpha);
      } else glColor4f(1.0f,1.0f,1.0f,alpha*3);
      
      glPushMatrix();
        glTranslatef(GX(i),GY(i),GZ(i));
  
        TURN_PLUS;
  
        glRotatef(-spin,0.0f,0.0f,0.1f);
        glRotatef(-tilt,1.0f,0.0f,0.0f);
        
        if (galaxies[i].is_dwarf) glScalef(DWARF_RADIUS, DWARF_RADIUS, DWARF_RADIUS);
        
        if (first_person)
        {
          glScalef(0.26f,0.26f,0.26f);  
        }
          
        glBegin(GL_QUADS);
          glTexCoord2f(0.0f,0.0f); glVertex3f(-1.5f, 1.5f, 0.0f);
          glTexCoord2f(0.0f,1.0f); glVertex3f( 1.5f, 1.5f, 0.0f);
          glTexCoord2f(1.0f,1.0f); glVertex3f( 1.5f,-1.5f, 0.0f);
          glTexCoord2f(1.0f,0.0f); glVertex3f(-1.5f,-1.5f, 0.0f);
        glEnd();
      glPopMatrix();
      
    } else if (drawmode==DRAW_DOTS) {
      // and this does not.

      glBegin2D();

      int j=0;
      while (j<1024)
      {
        if (feedback_buffer_2d[j]==GL_PASS_THROUGH_TOKEN)
        {
          int galaxy_number=(int)feedback_buffer_2d[j+=1];
          if (feedback_buffer_2d[j+1]==GL_POINT_TOKEN)
          {
            j+=1;
            int dot_x=(int)feedback_buffer_2d[j+=1];
            int dot_y=(int)feedback_buffer_2d[j+=1];
            
            glTranslated(dot_x,dot_y,0);
            
            if (draw_redshift)
            {
              if (galaxies[i].redshift>0) glColor4f(1.0f,0.8f,0.8f,0.1f);
              else if (galaxies[i].redshift<0) glColor4f(0.8f,0.8f,1.0f,0.1f);
            } else glColor4f(1.0f,1.0f,1.0f,0.5f);
          
            glBindTexture(GL_TEXTURE_2D, texture_type[TYPE_SBb]);
            
            glBegin(GL_QUADS);
              glTexCoord2f(0.0f,0.0f); glVertex3i(-16,-16, 0);
              glTexCoord2f(0.0f,1.0f); glVertex3i(-16, 16, 0);
              glTexCoord2f(1.0f,1.0f); glVertex3i( 16, 16, 0);
              glTexCoord2f(1.0f,0.0f); glVertex3i( 16,-16, 0);
            glEnd();
            
            glTranslated(-dot_x,-dot_y,0);
          }
        }
        j+=1;
      }
      glEnd2D();
      //glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    }
  }