Thread: OpenGL Problems(again)

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

    OpenGL Problems(again)

    yup. third thread with the exact same title. stupid opengl.

    anyway, when i draw a normal square polygon in the center of the screen, and apply a texture(24-bit bmp) to it with alpha blending for purple(255,0,255), it looks perfectly proportional and all, but many of the edges are still purple. so i thought that the bitmap itself contained those purple pixels and went into photoshop and zoomed in like 300% to where the game appeared to have showed purple. I couldn't find anything on the bitmap but solid purple. once in the game, i take a screenshot of the textured square once in the game and go into photoshop and look at the colors. Its varied purple, so naturally i wouldn't be able to alpha it out.

    How does a perfectly good texture with no purple but 255,0,255 all of a sudden have a slightly different shade? its like openGL was anti-aliasing it for me or it was stretched out of proportion and opengl was trying to correct it.

    I can't find anything at all that would change the appearance.

    here's my code for importing the texture from a resource(loadgltextures):
    Code:
    int LoadGLTextures()                                    // Load Bitmaps And Convert To Textures
    {
            int Status=FALSE;                               // Status Indicator
    
        HBITMAP bitmap  = LoadBitmap(GetModuleHandle(NULL), 
    	MAKEINTRESOURCE(102));
    	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;
    	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);
    	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;
    		}
    	}
    	BYTE * data2= new BYTE[4*256*256];
    	int temp=0,temp2=0;
    	
    	for (int n=0; n<256*256; n++)
    	{
    		BYTE alpha = 255;
    		if ((data[temp2] ==255) && data[temp2+1]==0 && (data[temp2+2] == 255) )
    			//|| ((data[temp2] <= data[temp2+2]+20 && data[temp2] >= data[temp2+2]-20) && (data[temp2+1] >= 0 && data[temp2+1]<= 20)))
    		{
    			alpha =0;
    		}
    			else
    			alpha = 255;
    		data2[temp++] = data[temp2++];
    		data2[temp++] = data[temp2++];
    		data2[temp++] = data[temp2++];
    		data2[temp++] = alpha;
    	}
    	glGenTextures(1, &m_texture[0]);
    	glBindTexture(GL_TEXTURE_2D, m_texture[0]);
    	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, data2);
    	delete[] data2;
    
    
    //...
    
    return Status;
    }
    notice my attempts on alphaing out the different shades of purple. obviously wouldn't work since the alphaing would go before opengl screwing with the displaying of the texture.

    and here's my drawing of the polygon(dont think this matters but just incase):

    Code:
    	glLoadIdentity();
    	
    	glBindTexture(GL_TEXTURE_2D, m_texture[0]);
    	glTranslatef(1.4+(wb), -1.2f-(wb), -6.0f+(wb));
    	//		glEnable(GL_ALPHA_TEST);
    	//	glAlphaFunc(GL_LESS,0);
    glEnable(GL_BLEND);		
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    	glBegin(GL_QUADS);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	
    	glEnd();
    helpez-moi por favor

    thanks!

  2. #2
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Use alpha blending instead.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  3. #3
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    i can't. i havn't found a way to use gl's alpha blending with resources.

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    www.gamedev.net

    search the forums, I've seen a couple of threads about it.
    plus you need to switch to tga.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    It has to do with the way OpenGL is filtering your images. Try turning off texture filtering and see what happens.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    Look up glPNG and use real alpha . If you are going to do any serious game programming, do not use resources. Use external files. In fact, while you're at it, find a format for packing everything up as well. For doing little projects for testing stuff, it's a hassle, but for large projects it makes things much cleaner and easier.

  7. #7
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    Quote Originally Posted by MrWizard
    It has to do with the way OpenGL is filtering your images. Try turning off texture filtering and see what happens.
    actually thats what it was! lol i commented out all the glTexParameteri's but it still didn't work so i thought it had nothing to do with my problem. turns out i needed
    Code:
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    and it worked.

    thanks again mr.wizard...for the third time you've helped me.

    thanks for all the ideas everyone else too. maybe i should pack up all my resources...how would i do that bloodstayne? like a resource.001 and resource.002?

    thanks

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    add with your other glTexParam calls

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

  9. #9
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    ok i did. what's that do? i'm a n00b to opengl. used to dx

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: 5
    Last Post: 06-03-2004, 03:41 AM
  3. OpenGL Problems(again)
    By Xterria in forum Game Programming
    Replies: 2
    Last Post: 03-28-2004, 06:46 PM
  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