PDA

View Full Version : Resize Textures



10-16-2005, 04:09 AM
Hello again :)

I wrote a code that loads a free-sized bitmap into memory, and fills it up to a loadable texture size like 128x128 for example. But in some cases, the texture doesnt look right anymore after that. I guess my code is wrong, but I dont know how to solve. Is there any example code I can learn from?
If anybody wants to take a look at, I can post here my code I have and maybe find the mistake :)

Thank your for your help

Hlz
10-17-2005, 12:48 AM
There's lots of code out there to learn from. Google, but try to get some sleep sometime.

Posting your code is a good idea if you want people to quickly identify your problem, especially if it's a simple/short one, and it's related to opengl ;-)

10-17-2005, 03:48 AM
unsigned char *d_rgba=NULL;
int d_rgb_size=rx_pot*ry_pot*3;
int d_rgba_size=nx_pot*ny_pot*4;
d_rgba=new unsigned char[d_rgba_size];
memset(d_rgba,0,sizeof(d_rgba));

int i=0,j=0;
for(i=0,j=0;i<d_rgb_size;i+=3,j+=4)
{
if((temptex->data[i]==key_red)&amp;&amp;
(temptex->data[i+1]==key_green)&amp;&amp;
(temptex->data[i+2]==key_blue))
{
d_rgba[j+3]=0;
}
else
d_rgba[j+3]=255;

d_rgba[j]=temptex->data[i];
d_rgba[j+1]=temptex->data[i+1];
d_rgba[j+2]=temptex->data[i+2];
}rx_pot, ry_pot hold the real size of the image, eg 120x90
nx_pot, ny_pot hold the size of the texture to fill up, eg 128x128. This got already calculated in the code before but I didn't post it, as it works.

I guess the problem is in the loop, where the pixels get filled up. As you can see, there's also color-keying implemented. This works fine. I just guess, filling the data from the smaller array into the bigger one works wrong. But I don't know how to fix it at the moment.

Who can help?

memfr0b
10-17-2005, 12:05 PM
I see two problems in that code snippet.

Your memset will only clear the first (maybe) four bytes of your new image buffer. sizeof(d_rgba) is the size of an "unsigned char *" (a pointer), not the whole size of your allocated array. Your index into the new image array is wrong, after the first row. You are correctly accounting for the different pixel sizes (rgb vs rgba) in the two buffer, but not for the different row sizes.