Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ALlegro Threads.

This thread is locked; no one can reply to it. rss feed Print
ALlegro Threads.
undertzolkin
Member #15,247
August 2013

Hi, im new around here, so first of all HELLO :D

Well, i've been using Threads lately, and right now i wanted to create a thread that diplays the FPS in-game. but im having some issues with the flip display. yes the thread runs, but the al_flip_display(); aint working properly, or so, not showing anything on screen.
if you dont trust the image:

static void *thdFPS (ALLEGRO_THREAD *thr, void *param)
{
strJuego objJuego = ((strJuego) param);
ALLEGRO_TIMER *timer = al_create_timer( 1.0 / objJuego.FPS );
ALLEGRO_EVENT_QUEUE *eventQueue = al_create_event_queue();
al_register_event_source(eventQueue, al_get_timer_event_source(timer));
ALLEGRO_FONT *font24 = al_load_ttf_font("blr.ttf", 24, 0);

float fFPSCounter = 0.0;

al_start_timer(timer);

while(!al_get_thread_should_stop(thr))
{


//al_draw_textf(font24, al_map_rgb(255, 255, 255),1, 1, 0, "Frames: %i");
al_flip_display();
}

in the image you can clearly see, that in debug, the flip_display have already been called, but itsnot applying, no error messega shown whatsoever...

Any ideas?! thank you greatly . surri for vad ingrish!

uuu btw, if i call the flip function in the main() function, it applies the flip without any problem. but... just once, and i dont want to use a while(). :(

Elias
Member #358
May 2000

You have to use all graphics related functions in the same thread that calls all_create_display, basically. The only exception is if you use al_set_target_bitmap, but that won't work in your case because only one thread at a time can have the display target. So basically - do all drawing including the FPS counter from your main thread.

--
"Either help out or stop whining" - Evert

undertzolkin
Member #15,247
August 2013

Hey! thanks for the Quick reply!

So basically a few more questions had popped out.

1) whhats the difference between a windows thread, and a allegro thread? is the allegro thread mainly for graphical purposes?

2) if I make my allegro thread, I would need to run all graphical process from here?
for example , I could make 2 threads, a windows(to support all programing) and a allegr thread(to support all graphics). is this really that necesarry?

3)if, what i said about allegro's thread only caring about graphical calls is correct. would making a windows thread, to call several graphical outputs be wrong? and vice versa.

THANK YOU SO MUCH FOR YOUR TIME and ANSWER!

Evert
Member #794
November 2000
avatar

1) whhats the difference between a windows thread, and a allegro thread? is the allegro thread mainly for graphical purposes?

Allegro's thread API is the same on all platforms. Windows threads only work on Windows.

In fact, Allegro's thread API (probably) just calls the Windows thread API anyway.

Quote:

2) if I make my allegro thread, I would need to run all graphical process from here?

No.
You cannot draw to the same display from multiple threads. This is independent of how you create the thread.

You should do all your graphics operations from one thread (say, the main thread). The other threads can then do whatever they like.

Quote:

3)if, what i said about allegro's thread only caring about graphical calls is correct.

It's not.

Quote:

would making a windows thread, to call several graphical outputs be wrong?

Yes.

undertzolkin
Member #15,247
August 2013

Alright! thank you for your answers. and also thank you for taking your time, ill try different approaches n.n!

and btw, im sorry posting this in the wrong section. I just noticed it right now u.u

Thanks again :)

Go to: