Jump to content

  • Log In with Google      Sign In   
  • Create Account

Allegro bitmap problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 PlayswithSquirrels   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 February 2013 - 06:15 AM

New at programming. Trying to create a 16-puzzle on allegro. I'm still at the stage of trying to make an image show up on the screen, but when I compile, the screen goes black and no image is shown. No error messages or warnings pop up.

 

#include <allegro.h>

void init();
void deinit();

int main() {
	init();
	
	BITMAP *my_pic;
	PALETTE palette;
	my_pic = load_bitmap("chihuahua.bmp", palette);
	
	if(my_pic==NULL)
	{
		set_gfx_mode(GFX_TEXT, 0,0,0,0);
		allegro_message("Can't load chihuahua.bmp");
		return 1;
	}

	while (!key[KEY_ESC]) {
		blit(my_pic, screen, 0,0,0,0,50,50);
		blit(my_pic, screen, 50,50,100,100,150,150);
		clear(my_pic);
	}
	
	destroy_bitmap(my_pic);
	deinit();
	return 0;
}
END_OF_MAIN()

void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}

	install_timer();
	install_keyboard();
	install_mouse();
}

void deinit() {
	clear_keybuf();
}

 

I'm really frustrated, I've been at this for 3 days, to no avail. I'm on a time crunch, I still have alot to do with the code, and can't do any of it if the bitmap refuses to open. Any and all help is welcome.



Sponsor:

#2 PlayswithSquirrels   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 February 2013 - 06:17 AM

Please don't tell me to google and to read the manual. I have, and am still doing so. Nonetheless, I'm stuck.



#3 RulerOfNothing   Members   -  Reputation: 1160

Like
0Likes
Like

Posted 27 February 2013 - 06:25 AM

I have a question: what exactly does clear(my_pic); do? If it clears the loaded image you probably want clear(screen); or whatever clears the screen instead.



#4 PlayswithSquirrels   Members   -  Reputation: 102

Like
0Likes
Like

Posted 27 February 2013 - 06:50 AM

Thanks for the tip, the image now shows up. But now it keeps flickering. When I take out clear(screen) the image still shows up and doesn't flicker. Do you think the clear(screen) would make too much of a difference if I just don't use it?



#5 RulerOfNothing   Members   -  Reputation: 1160

Like
0Likes
Like

Posted 27 February 2013 - 07:23 AM

If you redraw the entire screen (or at least all parts of the screen that change) every frame then removing clear(screen) won't make any difference otherwise part of the old frame will still be on the screen.



#6 Aldacron   GDNet+   -  Reputation: 3177

Like
0Likes
Like

Posted 27 February 2013 - 07:27 AM

You'll need to look into double buffering. Also, a little advice. Allegro 5 is a much nicer interface than Allegro 4. Moreover, it uses OpenGL or Direct3D under the hood, along with a nice event system. You should really consider learning with it instead.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS