Thread: OpenGL Problems(again)

  1. #1
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,037

    OpenGL Problems(again)

    Nobody on Nehe's forums couldn't help me. I've been programming this little cube with a bitmap texture as a win32 resource in msvc++ 6. My problem is, I can't get the transparency to work. Heres my LoadGLTextures:
    Code:
    int LoadGLTextures()									// Load Bitmaps And Convert To Textures
    {
    	
    HWND hwnd;
    	int Status=TRUE;									// Status Indicator
    
       // load bitmap from resource file
       HBITMAP bitmap  = LoadBitmap(GetModuleHandle(NULL), 
          MAKEINTRESOURCE(IDB_BITMAP2));
    
    
       // setup 24 bits bitmap structure
       // works on 8 bits bitmaps also!
    
    
       BITMAPINFO info;
       BITMAPINFOHEADER header;
       header.biSize = sizeof(BITMAPINFOHEADER);     
       header.biWidth = 256;     
       header.biHeight = 256; 
       header.biPlanes = 1;     
       header.biBitCount = 24;     
       header.biCompression = BI_RGB;
       header.biSizeImage = 0;     
       header.biClrUsed = 0;     
       header.biClrImportant = 0; 
    
       info.bmiHeader = header;
       info.bmiColors->rgbRed      = NULL;
       info.bmiColors->rgbGreen    = NULL;
       info.bmiColors->rgbBlue     = NULL;
       info.bmiColors->rgbReserved = NULL;
    
    
       // store bitmap data in a vector
       const int size = 256*256*3;
       unsigned char data[size];  
    
       HDC hdc = GetDC(hWnd);
          GetDIBits(hdc, bitmap,  0, 256,  &data,  &info, DIB_RGB_COLORS);
      
    	  ReleaseDC(hWnd, hdc);
      
    
    
       // convert from BGR to RGB
       unsigned char buff;
       for(int i=0; i<256*256; i++)
       {
          buff = data[i*3];
          if(i>=3)
          {
             data[i*3]   = data[i*3+2];
             data[i*3+2] = buff;
          }
       }
     unsigned char  *src_bitmap = data;
       unsigned char *alpha_bitmap = (unsigned char *)malloc(((256)*(256)) *4) ;
       for (unsigned int src = 0, dst = 0; src < (256)*3; src +=3, dst +=4)
    {
    // if the pixel is black, set the alpha to 0. Otherwise, set it to 255.
    	
    	if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
    {
    alpha_bitmap[dst+3] = 0;
    PostQuitMessage(0); //I tell it to quit, and it WONT!
    }
    else
    alpha_bitmap[dst+3] = 0xFF;
    
    // copy pixel data over
    alpha_bitmap[dst] = src_bitmap[src];
    alpha_bitmap[dst+1] = src_bitmap[src+1];
    alpha_bitmap[dst+2] = src_bitmap[src+2];
    }
    
       // create one texture
       glGenTextures(1, &m_texture[0]);
    				
       // select texture
       glBindTexture(GL_TEXTURE_2D, m_texture[0]);
    
    	
       // SetTextureParameters
    		glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    
       gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 256, 256,
    GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);
    		// generate texture
       glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
    //free all the stuff, etc.
    and within my DrawScene(), i have:
    Code:
      
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER,0);
    right before i draw my cube. My cube's texture has a large pink(255,0,255) square on it that should go transparent, but it doesn't. Help me, please.
    Thank you all!

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Have you enabled blending (GL_BLEND) ?
    Do not make direct eye contact with me.

  3. #3
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,037
    yes, under my drawscene().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  2. OpenGL Problems(again)
    By Xterria in forum Game Programming
    Replies: 8
    Last Post: 06-23-2004, 01:21 PM
  3. OpenGL Problems(again)
    By Xterria in forum Game Programming
    Replies: 5
    Last Post: 06-03-2004, 03:41 AM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM