Results 1 to 5 of 5

Thread: Oddly blended textures.

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    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:

    Code :
    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...

  2. #2
    Member Contributor
    Join Date
    Mar 2008
    Location
    Singapore
    Posts
    67

    Re: Oddly blended textures.

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    Re: Oddly blended textures.

    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.

  4. #4
    Member Contributor
    Join Date
    Mar 2008
    Location
    Singapore
    Posts
    67

    Re: Oddly blended textures.

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    Re: Oddly blended textures.

    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.

    Code :
    for (int i=0; i<num_galaxies; i++)
      {
        GLfloat alpha=1.0f;   
        if (first_person&amp;&amp;i==selected_galaxy&amp;&amp;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);
        }
      }

Similar Threads

  1. Using SOIL to load textures onto blended polygons?
    By pandoragami in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-10-2018, 08:05 PM
  2. Create a new texture from two blended textures
    By grasshop in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-08-2012, 03:49 PM
  3. blended textures fade-in?
    By gustawo in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-18-2005, 07:25 PM
  4. edges of blended textures visible
    By dodgyposse in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-23-2001, 02:17 AM
  5. alpha blended textures ???
    By imported_tom in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-14-2000, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean