Bitmap image loading
Hello, i followed the tutorial about bitmaps. I have my bitmap loaded fine, but the quality is somewhat blurry, i use the same settings as in the tutorial, how can i make the quality better?
Thanks
Can you give more info? A code posting, or posting the bitmap would be great :)
Cheers,
- llvllatrix
Cheers,
- llvllatrix
Quote: Original post by Bobbi
Hello, i followed the tutorial about bitmaps. I have my bitmap loaded fine, but the quality is somewhat blurry, i use the same settings as in the tutorial, how can i make the quality better?
Thanks
That depends on what texture parameters you're using?
Killers don't end up in jailThey end up on a high-score!
unsigned char* CreateRGBA(unsigned char * oImage,COLORREF ZeroAlpha, int Width, int Height){ if(oImage == NULL) return NULL; int nSize = (Height*Width) * 4; unsigned char * Image = (unsigned char *) malloc(nSize); if(Image == NULL) return NULL; for(int n=0,i=0; n < (Height*Width)*3; n+=3,i+=4) { Image = oImage[n]; Image[i+1] = oImage[n+1]; Image[i+2] = oImage[n+2]; if(ZeroAlpha == -1) { Image[i+3]= (int)255; continue; } if(Image == GetRValue(ZeroAlpha) && Image[i+1] == GetGValue(ZeroAlpha) && Image[i+2] == GetBValue(ZeroAlpha)) Image[i+3] = 0; else Image[i+3] = 255; } return Image;}bool CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID){ AUX_RGBImageRec *pBitmap = NULL; if(!strFileName) return false; pBitmap = auxDIBImageLoad(strFileName); if(pBitmap == NULL) return false; COLORREF Color; Color = RGB(0, 0, 0); pBitmap->data = CreateRGBA(pBitmap->data, Color, 60, 14); glGenTextures(1, &textureArray[textureID]); glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, pBitmap->sizeX, pBitmap->sizeY, GL_RGBA, GL_UNSIGNED_BYTE, pBitmap->data); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering if (pBitmap) { if (pBitmap->data) { free(pBitmap->data); } free(pBitmap); } return true;}
Is what i use, the bmp image is 60x40 24 bits
Quote: Original post by BobbipBitmap->data = CreateRGBA(pBitmap->data, Color, 60, 14);
the bmp image is 60x40
Typo or bug?
The image is probably blurry because gluBuild2DMipmaps resizes your image to the nearest power of two. Try either padding your image to a power of 2 and adjusting the texture coordinates to show only the part you need, or look into one of the NPOT or texture rectangle extensions.
Enigma
my bad, was a typo, the image is 60x14
I am not english so i dont exactly know what you mean by padding. You mean i make the image 360x196 and then i set the coords to only show the 60x14 part where my image is?
Thanks
I am not english so i dont exactly know what you mean by padding. You mean i make the image 360x196 and then i set the coords to only show the 60x14 part where my image is?
Thanks
Exactly, although neither 360 nor 196 are powers of two, so you'd make it 64 by 16 and use texture coordinates 0 to 0.938 in x and 0 to 0.882 is y. This method does mean that you can't tile your texture though. When you pad your image do as follows:
Original Image (5 × 3):
Tiled Image (8 × 4):
So you "smear" the texture at the edges. This prevents problems with the GL_LINEAR filter interpolating pixels at the borders.
Enigma
Original Image (5 × 3):
rgbrgbrgbrgbrgb
Tiled Image (8 × 4):
rgbrggggbrgbrrrrrbrgbbbbrbrgbbbb
So you "smear" the texture at the edges. This prevents problems with the GL_LINEAR filter interpolating pixels at the borders.
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement