I want to texturemap an image of 3450*5678 pixel ,but the max matrix of texturemap in my pc is 1024*1024,how can i solve it? is cutting map is a good way? how to do it?

thanks for any help.

Yeah cut it or shrink it. All texture maps have to be square and a power of 2

I recommend you shrink it

Pseudocode in case…

for i := 0 to 1023 do begin

for j := 0 to 1023 do begin

_i := (i * 3450) div 1023;

_j := (j * 5678) div 1023;

final_texture[i][j] := your_texture[_i][_j];

end;

end;

Hope you don’t mind my Pascal code

Originally posted by mdog1234:

Yeah cut it or shrink it. All texture maps have to be square and a power of 2

You’re right about the power of 2, but not about them needing to be square. As long as both dimensions are a power of 2, you can have rectangular textures. (e.g. 256x128)

oh ok, thats good to know

I copy pasted parts of my imagelibrary that does the trick

[source]

inline unsigned int toPowerOf2(unsigned int w) { // Returns maximum power of 2 value that is smaller than or equals w

unsigned int p=1;

while (p<=w) { p<<=1; }

return p>>1;

}

void Image: ower2() // Scale down to nearest 2^n x 2^m size.

{

int p2_width = toPowerOf2(getWidth());

int p2_height = toPowerOf2(getHeight());

if (p2_width==getWidth() && p2_height==getHeight())

return;

```
//printf("Scaling image to power of 2
```

");

```
Image p2img(p2_width,p2_height,getComponents());
int x,y;
for (x=0; x<p2_width; x++)
for (y=0; y<p2_height; y++)
{
int x2 = getWidth()*x / p2_width;
int y2 = getHeight()*y / p2_height;
p2img.setPixel(x, y, getPixel(x2,y2));
}
*this = p2img;
```

}

void Image::halve() // Halve image

{

Image half(getWidth()>>1,getHeight()>>1,getComponents());

int x,x2,y,y2;

for (x=0,x2=0; x2<getWidth(); x++, x2+=2)

for (y=0,y2=0; y2<getHeight(); y++, y2+=2)

half.setPixel(x, y, getPixel(x2,y2));

*this = half;

}

Image img(“fname.png”);

img.power2();

while (img.getWidth()>1024 | | img.getHeight()>1024) img.halve();

[/source]

Actually our codes could be optimized a bit .

This would probably save you a lot of time:

i_step := (3450 << 16) div 1023;

j_step := (5678 << 16) div 1023;_i := 0;

for i := 0 to 1023 do begin

_j := 0;

for j := 0 to 1023 do begin

_i := i + i_step;

_j := j + j_step;

final_texture[i][j] := your_texture[_i >> 16][_j >> 16];

end;

end;

Just for fun