View Full Version: Allegro problem

C++ Learning Community > Misc. C++ library help > Allegro problem


Title: Allegro problem
Description: Dialogues *not solved anymore*


biggoron - November 27, 2006 05:35 PM (GMT)
Me again! I wanted to make a program that had a GUI, but wasn't as hard as Win32, so I looked to the allegro UI functions. I found this learning source on Google (Here) but whenever I run this code:

CODE
#include <allegro.h>

#define S_RED 2
#define S_GREEN 3
#define S_BLUE 4

volatile int speed_counter;
void increment_speed_counter(void) {
speed_counter++;
} END_OF_FUNCTION(increment_speed_counter);

int update_color(void* dp3, int d2);

DIALOG color_builder[] = {
{ d_clear_proc, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_shadow_box_proc, 0, 0, 320, 240, 0, 254, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_slider_proc, 10, 110, 16, 64, 1, 0, 0, 0, 64, 0, NULL, (void*)update_color, NULL },
{ d_slider_proc, 42, 110, 16, 64, 2, 0, 0, 0, 64, 0, NULL, (void*)update_color, NULL },
{ d_slider_proc, 74, 110, 16, 64, 2, 0, 0, 0, 64, 0, NULL, (void*)update_color, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};

int main() {
allegro_init();
install_keyboard();
install_mouse();
install_timer();

LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));

set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
set_palette(desktop_palette);

update_color(NULL, 0);
color_builder[2].d2 = 0;
color_builder[3].d2 = 0;
color_builder[4].d2 = 0;

BITMAP *handle = create_bitmap(16, 8);
rectfill(handle, 0, 0, 16, 8, makecol32(255, 255, 255));
color_builder[2].dp = handle;
color_builder[3].dp = handle;
color_builder[4].dp = handle;

   do_dialog(color_builder, -1);

return EXIT_SUCCESS;
} END_OF_MAIN()

int update_color(void *dp3, int d2) {
   RGB col;
   col.r = color_builder[2].d2;
   col.g = color_builder[3].d2;
   col.b = color_builder[4].d2;
vsync();
set_color(255, &col);
return 0;
}


I keep getting errors concerning the line marked with an empty slash-star comment. Sorry if it's hard to read.

The error I get is "invalid conversion from 'int(*)(void*, int)' to 'void'". I'm pretty sure I copied out the code correctly.

So what is the problem?

Thanks in advance.

[edit]
After looking through it a few times it seems Allegro doesn't like it when I use anything other than NULL as a procedure. What can I do to fix it?

[edit2]
Fixed it by typecasting it. Can't believe I didn't think of that earlier...

[edit3]
Okay, that stopped the errors, but now (obviously) I can't get the correct values from the function. Still need help solving this...




Hosted for free by InvisionFree