Sign in to follow this  
Bobbi

Bitmap image loading

Recommended Posts

Bobbi    122
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

Share this post


Link to post
Share on other sites
nife    235
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?

Share this post


Link to post
Share on other sites
Bobbi    122

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[i] = 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[i] == 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

Share this post


Link to post
Share on other sites
Enigma    1410
Quote:
Original post by Bobbi
   pBitmap->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

Share this post


Link to post
Share on other sites
Bobbi    122
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

Share this post


Link to post
Share on other sites
Enigma    1410
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):
rgbrg
brgbr
gbrgb

Tiled Image (8 × 4):
rgbrgggg
brgbrrrr
rbrgbbbb
rbrgbbbb

So you "smear" the texture at the edges. This prevents problems with the GL_LINEAR filter interpolating pixels at the borders.

Enigma

Share this post


Link to post
Share on other sites
Bobbi    122
thanks for the help, i made my image 64 by 16, which is actually 60x14 but i filled the rest up with black which is transparant. Now the texture looks a lot sharper but a bit "pixely" if you know what I mean, not really smooth.

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this