Texture

Started by
3 comments, last by jaba 20 years, 5 months ago
Hello, I have four maps(satellite photos) for example 256x256, how can I combine these maps on a single texture 512x512, where: -the upper left corner (0-255, 0-255) is map 1 -the upper right Corner (256-511, 0-255) is map 2 -the lower left corner (0-255, 256-511) is map 3 -the lower right corner (256-511, 256-511) is map 4 With this big map I can texture a terrain.
============================== Videoman Library Project
Advertisement
I just did something like this, but with my screen shot system. I did by doing the following:

//--//-- QuadrantID's//--  ---------------//-- |       |       |//-- |  (0)  |  (1)  |//-- |       |       |//--  -------+-------//-- |       |       |//-- |  (2)  |  (3)  |//-- |       |       |//--  ---------------//--int PixelID;              //--Result Pixel IDint HMPixelID;            //--Heightmap Pixel IDint PositionX;            //--Position X Of The Quadrantint PositionY;            //--Position Y Of The Quadrantint QuadrantWidth = 256;  //--Width Of The Quadrantint QuadrantHeight = 256; //--Height Of The Quadrant////--Create an array big enough to store all four//--The (* 3) is for 3 channels, if you want RGBA use 4unsigned char* Result = (unsigned char*)malloc(QuadrantWidth * QuadrantHeight * 3 * sizeof(unsigned char));if(Result == NULL){    return;}//for(int QuadrantID = 0; QuadrantID < 4; QuadrantID++){    switch(QuadrantID)    {        case 0:        {            PositionX = 0;            PositionY = ((QuadrantHeight * 2) - QuadrantHeight);            break;        }//        case 1:        {            PositionX = ((QuadrantWidth * 2) - QuadrantWidth) / 2;            PositionY = ((QuadrantHeight * 2) - QuadrantHeight);            break;        }//        case 2:        {            PositionX = 0;            PositionY = ((QuadrantHeight * 2) - QuadrantHeight) / 2;            break;        }//        case 3:        {            PositionX = ((QuadrantWidth * 2) - QuadrantWidth) / 2;            PositionY = ((QuadrantHeight * 2) - QuadrantHeight) / 2;            break;        }    }//    for(int Y = 0; Y < QuadrantHeight; Y++)    {        for(int X = 0; X < QuadrantWidth; X++)	{            //--Compute the pixel positions            PixelID = (3 * ((PositionY + Y) * (QuadrantWidth * 2) + (PositionX + X)));            HMPixelID = (3 * (Y * QuadrantWidth + X));//            //--Set the pixel            Result[PixelID + 0] = HeightMap[QuadrantID].Data[HMPixelID + 0];	    Result[PixelID + 1] = HeightMap[QuadrantID].Data[HMPixelID + 1];	    Result[PixelID + 2] = HeightMap[QuadrantID].Data[HMPixelID + 2];        }    }}


Something like this should work fine. You might have to tweek it some because I did most of it from memory. If you have any problems let me know and I'll help.

EDIT
Guess I could finish it
Of course the Result[] will contain the final height map with all 4 "merged" together. At this point you could free the memory used from the 4 height maps used to make the final image. Most likely they wont be used and memory is crucial, so just delete them unless you need them for something.

The HeightMap[QuadrantID].Data[HMPixelID] are of course the 4 height maps in an array. I don't know how you have it setup so I had to take a guess.

HeightMap[0].Data[HMPixelID] = upper left corner (Map 1)
HeightMap[1].Data[HMPixelID] = upper right corner (Map 2)
HeightMap[2].Data[HMPixelID] = lower left corner (Map 3)
HeightMap[3].Data[HMPixelID] = lower right corner (Map 4)

Best of luck,
-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on November 10, 2003 10:06:54 AM]
Ok, thank you very much, i will try it
============================== Videoman Library Project
You''re welcome.

If you run into a problem let me know and I''ll help you figure it out.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"
Oops, I found an error:
unsigned char* Result = (unsigned char*)malloc(QuadrantWidth * QuadrantHeight * 3 * sizeof(unsigned char));

That would be only enough to hold 1. Change it to this:
unsigned char* Result = (unsigned char*)malloc((QuadrantWidth * 2) * (QuadrantHeight * 2) * 3 * sizeof(unsigned char));


-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

This topic is closed to new replies.

Advertisement