Jump to content
  • Advertisement
Sign in to follow this  
Arith

Strange Allegro bitmap loading

This topic is 3164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have a half decent terrain working in AllegroGL, which is randomly generated. Now I'm trying to superimpose a tga file as a heightmap using alpha values as a mask so that only certain portions of the tga affect the terrain. Problem is, the way it is now, it's soooo dodgy. Well, let me show you the function.. perhaps shed some light.
char TERRAIN::Superimpose(const char *bitmapfn, bool mask)
{
 BITMAP *overlay;

 int overlayr=0, overlayb=0, overlayg=0, overlaya=0;
 int pxcolour =0, lcount=0;

 overlay = load_bitmap(bitmapfn, NULL);

 if (!overlay) return 111;

 int overlayx=0, overlayy=0;
 for (int terrainy=0; terrainy<height; terrainy++)
  for (int terrainx=0; terrainx<width; terrainx++)
  {
   lcount ++;  
   pxcolour = getpixel(overlay, overlayx, overlayy);
   overlayr=0;
   overlayg=0;
   overlayb=0;
   overlaya=0;
   overlayr = getr(pxcolour);
   overlayg = getg(pxcolour);
   overlayb = getb(pxcolour);
   overlaya = geta(pxcolour);

   overlayx++;
   if (overlayx > overlay->w) 
   {
    overlayx=0;
    overlayy++;
    if (overlayy > overlay->h) continue;
   }

   if ((mask)&&(overlaya==0)) continue; // zero alpha skips current pixel

   Vertex[terrainx][terrainy].z = (float)(overlayr+overlayb+overlayg);
  }

 save_bitmap("./echooverlay.tga", overlay, NULL);
 destroy_bitmap(overlay);

 return 0;
}



If I comment out "if ((mask)&&(overlaya==0)) continue;" the hightmapping works.. sort of. The bitmap appears to be skewed on the terrain (ie the start of the bitmap appears in the middle of the terrain then wraps around) What's worse, the saved bitmap echooverlay.tga is completely blank except for a rogue white pixel usually in the first row. I've tried playing with direct pixel formats with limited success (other variations of geta, getpixel etc) and decided it's best to get some advice. I remember back when I did pure allegro projects that comparing pixels were a pain in the ass. If anyone has some insight it would be greatly appreciated. Arith Edit: Ok, minor tweaks yield that the alpha IS working and is superimposing the image somewhat as desired. However now my main problem is the skewed image. For some reason it puts a seam down the middle of my terrain and half the heightmap is on one end, and the other half on the other end. I've never seen allegro do that before.... [Edited by - Arith on February 23, 2010 2:03:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
Alright, as mentioned in my edit above, the heightmap IS working, but not the way I would have wanted. The function is very much the same as the one above.

Heightmap:
http://i138.photobucket.com/albums/q257/Serojin/heightmap.jpg
(the area outside of the black circle is transparent, not that it matters)


and here is the resulting terrain
http://i138.photobucket.com/albums/q257/Serojin/messedup.jpg

I have no idea what to do about this. I've tried initializing my heightmap container, put in allegro_gl_set_allegro_mode(); I just don't know. I've never had allegro do this to me before.

Also, the echooverlay.tga now copies the original heightmap properly..

Once again, if anyone has any thoughts, it would be much appreciated as this is really getting to me.

Thanks

Arith

Share this post


Link to post
Share on other sites
Well, I got it to work. I have no idea why it did all that skewing. Only thing I can come up with is I had some sort of logic issue with the counters on the heightmap versus the terrain vertices. I merged them into one and it works. (originally I had hoped I could flip them by reversing the y order on the heightmap, but I guess I'll have to live with this for now)


char TERRAIN::Superimpose(const char *bitmapfn, bool mask)
{
allegro_gl_set_allegro_mode();

BITMAP *overlay;

int overlayr=0, overlayb=0, overlayg=0, overlaya=0;
int pxcolour =0, lcount=0;

overlay = create_bitmap(200,200);
clear_bitmap(overlay);
overlay = load_bitmap(bitmapfn, NULL);

if (!overlay) return 111;

for (int terrainy=0; terrainy<height; terrainy++)
for (int terrainx=0; terrainx<width; terrainx++)
{
lcount ++;
pxcolour = getpixel(overlay, terrainx, terrainy);

overlayr = getr(pxcolour);
overlayg = getg(pxcolour);
overlayb = getb(pxcolour);
overlaya = geta(pxcolour);

if ((mask)&&(overlaya==0)) continue; // zero alpha skips current pixel

Vertex[terrainx][terrainy].z = (float)-(overlayr+overlayb+overlayg)/3;
}

save_bitmap("./echooverlay.tga", overlay, NULL);
destroy_bitmap(overlay);
allegro_gl_unset_allegro_mode();
return 0;
}




er. Thanks everyone for your input.. or something.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!