Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Can anyone with experiance using allegro help??

This topic is 6305 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

Hey, Ive been using allegro for a short time now and one thing thats bugging the hell out of my and cant seem to find a solution to is the strange thing that happens when i draw bitmaps to the screen...The first bitmap comes out fine..but every other bitmap after that''s color is all distorted...I will include a short source (50 lines or so) to see what if you can spot what im doing wrong,it''d be ideal if you could edit this source so that it will work properly and not only display the 1st image correctly and post it up so i can see the error of my ways Note: all bitmaps loaded into WizardSprite are 256 color ****************Begin source******************* #include BITMAP *DoubleBuffer; BITMAP *WizardSprite; RGB pal[256]; int PosX,PosY; void main(void) { allegro_init(); install_timer(); install_keyboard(); set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0); DoubleBuffer=(create_bitmap(640,480)); WizardSprite=load_bmp("wizlookdown.bmp",pal); PosX = (SCREEN_W - WizardSprite->w)/2; PosY = (SCREEN_H - WizardSprite->h)/2; set_palette(pal); set_color_depth(8); /* The Main Loop,The first Bitmap loaded into WizardSprite Comes out fine,however any Bitmap after that comes out different colors than they ought to be.*/ while (!key[KEY_ESC]) { clear_to_color(DoubleBuffer,115); draw_sprite(DoubleBuffer,WizardSprite,PosX,PosY); blit(DoubleBuffer,screen,0,0,0,0, DoubleBuffer->w, DoubleBuffer->h); if( (key[ KEY_LEFT]) && (PosX > 0) ) { WizardSprite=load_bmp("wizlookleft.bmp",pal); PosX--; } if( (key[ KEY_RIGHT]) && (PosX + WizardSprite->w < SCREEN_W) ) { WizardSprite=load_bmp("wizlookright.bmp",pal); PosX++; } if( (key[ KEY_UP]) && (PosY > 0) ) { WizardSprite=load_bmp("wizlookup.bmp",pal); PosY--; } if( (key[ KEY_DOWN]) && (PosY + WizardSprite->h < SCREEN_H) ) { WizardSprite=load_bmp("wizlookdown.bmp",pal); PosY++; } } destroy_bitmap(WizardSprite); destroy_bitmap(DoubleBuffer); allegro_exit(); } **************************** Yesterday we Obeyed kings & bent our necks before emperors,but today we kneel only to the truth. ****************************

Share this post


Link to post
Share on other sites
Advertisement
You''re doing lots of things wrong.


  • set_color_depth should be called before set_gfx_mode.
  • Look at how you''re loading your sprites. At the start, WizardSprite points to wizlookdown.bmp. Then if you press the keys, WizardSprite is set to point to some other bitmap. The current bitmap isn''t destroyed. This brings about a memory leak. A big one.
  • Your bitmap colors aren''t coming out correctly because you didn''t make all the bitmaps use the same palette. Go use a paint program and make sure you use the same palette for all the bitmaps. That will solve your funny color problem. Or you could just change the color depth to 16 bit and stop the problem.


Hope that was helpful.

Share this post


Link to post
Share on other sites

You should load all of your sprites first, eg

WizardSpriteLeft=load_bmp("wizlookleft.bmp",pal);
WizardSpriteRight=load_bmp("wizlookright.bmp",pal);
etc

And them use them when they are needed. Loading takes too long if you do it all the time.

The palette for all the pictures should be the same. I''m not sure if Paint uses the same 256 colour palette every time (I think not). I draw things in 24-bit and use a separate program to convert to 256 colours (email me if you want it) or you could use a different colour depth which removes that problem.

Share this post


Link to post
Share on other sites
Thanks all it really helped,Using the same pallette for each one,I was under the Impression my Palette Was the same just as long as i use the same colors for all my bitmaps lol
im an Idiot,
and the memory leaking from not destroying all bitmaps
( I was wondering why the program would start to jump & get laggy after a while of use ).
Thanks for helping with those problems now i can Get on to being frustrated about something other than why my colors wont work.

Hmmm it seems my post appears multiple times.Must be because i kept getting server timeouts yesterday so i thought it didnt Post my Query the first time...Sorry bout that.

****************************
Yesterday we Obeyed kings & bent our necks before emperors,but today we kneel only to the truth.
****************************

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!