Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » migrating from windows to linux

This thread is locked; no one can reply to it. rss feed Print
migrating from windows to linux
matt.h
Member #11,829
April 2010

Hi All,

I'm moving apps which I made work under windows with mingw + allegro 4.4.1.1 and last included dirextX to linux, I set up the same allegro version and use the current build-essential under my favorite distro.

the first thing deals with the mouse behavior

My first remark is the mouse cursor in windows disappear as soon as I'm moving into the allegro window, that leads me to create my own sprite to see what I'm doing inside. This is different under linux as far as the system cursor stays all the time with or without my own sprite. As result I remove my sprite.

Is it normal ? be honest with all what I could read I never noticed something about that.

My second remark is the directX driver under windows is less strict that x11 one, I leave some old acquire_screen that I did not see , and it did not let me any chance :D because it provokes some deadlocks. Unlike the first remark I read a lot about that, so i paid a lot of attention to remove all acquire_screen, and manage the show_mouse()correctly;

the last thing is I have some refresh issue with the mouse sprite, if I click somewhere and I do not move, all is ok when the mouse.c driver update mouse he what was behind the mouse sprite at the same place but if I move the mouse there is an offset and make the screen dirty what was not the case under windows.

I draw all directly to the screen so I suspect conflict with mouse and sprite to access to screen.

I started to use buffer and do a better refresh loop but when I put on something I want it refresh strait away

let me know about your experience on linux to lead me to make better thing

I would appreciate help about that

here my code to allow you to understand

#SelectExpand
1clear(screen); 2isPressed=0; 3blit(pwdPanel, screen, 0, 0, 0, 0, pwdPanel->w, pwdPanel->h); 4show_mouse(screen); 5 do { 6 if(mouse_b & 1) { 7 if(hasBeenPressed == -1) { 8 // not pressed before 9 hasBeenPressed = whatPressed(mouse_x, mouse_y); 10 push_button(hasBeenPressed); 11 isPressed = 1; 12 } else { 13 // check that still good one pressed 14 justPressed = whatPressed(mouse_x, mouse_y); 15 if(justPressed != hasBeenPressed) { 16 release_button(hasBeenPressed); 17 isPressed = 0; 18 hasBeenPressed = -1; 19 } 20 } 21 } 22 23 if(!(mouse_b & 1) && isPressed == 1) { 24 pressed = whatPressed(mouse_x, mouse_y); 25 release_button(pressed); 26 isPressed =0; 27 } 28 29 if (pressed >= 0 && isPressed == 0) { 30 exit_loop = do_action(pressed); 31 if (exit_loop == -2) { 32 draw_sprite(screen, failed[1], failed_area[0], failed_area[1]); 33 } 34 hasBeenPressed = -1; 35 pressed = -1; 36 } 37vsync(); 38} while (exit_loop != -1);

let me know

Matt

Evert
Member #794
November 2000
avatar

On Linux, you should normally just let the OS draw the cursor for you. To do that, call enable_hardware_cursor() before show_mouse(). You then never need to worry about hiding the mouse when you draw to the screen again.

matt.h
Member #11,829
April 2010

Hi,

thanks a lot for your help ;)

it did not change a lot aspect be honest :D but after I have a crazy slowness I passed 4 hours on it just for a vsync() :( and windows just did not pay attention to that !!!!

crazy

I remove all acquire_screen so it seems no more dead_lock that good.

I all most finished the transition now, but it stays all last issue with the mouse sprite. Actually the cursor is behind the hardware cursor, and when I click the button pushed is blit but when I release it I blit the release button but when I move the mouse (I think this is the update function in mouse.c) blit the old button part behind the mouse before move and it makes me a little square in the middle with the part of old picture.

this is really dirty, I worked with a background I print and after I start loop

do you have any idea why I could have it under linux but not under windows ?

let me know

Matt

Evert
Member #794
November 2000
avatar

matt.h said:

Actually the cursor is behind the hardware cursor, and when I click the button pushed is blit but when I release it I blit the release button but when I move the mouse (I think this is the update function in mouse.c) blit the old button part behind the mouse before move and it makes me a little square in the middle with the part of old picture.

Don't draw your own mouse cursor.
Set a hardware cursor in Allegro and use set_mouse_sprite() to let the OS draw the cursor for you.

If you are drawing your own cursor (or use Allegro's software cursor), make sure you hide/scare the cursor before drawing to that region of the screen.

Quote:

do you have any idea why I could have it under linux but not under windows ?

WIndows may use a hardware cursor by default in windowed mode.

You can tell which of the two is being used because Allegro's software cursor is clipped to the edge of the window whereas the OS hardware cursor is not.

Tobias Dammers
Member #2,604
August 2002
avatar

Evert said:

Don't draw your own mouse cursor.

IMO, drawing your own cursor is actually a viable choice if you do it right. Assuming you have a proper frame buffering scheme in place already (double buffer or whatever), it's as easy as drawing the sprite of your choice onto the back buffer, at the current mouse position, as part of your drawing routine. There are only two downsides as opposed to a OS-handled mouse cursor: your own mouse cursor will remain visible when the mouse leaves your window (which is only an issue in windowed mode), and when your frame rate goes down, mouse movement gets as choppy as the rest of your game.
OTOH, you can use practically any sprite you like, including wildly animated ones, and depending on the capabilities of your graphics engine, you can add all sorts of effects - shadows, lighting, transparency, particles, you name it.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

LennyLen
Member #5,313
December 2004
avatar

OTOH, you can use practically any sprite you like, including wildly animated ones, and depending on the capabilities of your graphics engine, you can add all sorts of effects - shadows, lighting, transparency, particles, you name it.

Indeed.

video

video

Evert
Member #794
November 2000
avatar

IMO, drawing your own cursor is actually a viable choice if you do it right

Yes. If.

Tobias Dammers
Member #2,604
August 2002
avatar

With a proper drawing infrastructure in place, doing it yourself is easy and fairly fool-proof. The hardware cursor approach is also quite easy, but everything in between (the methods that require scare_mouse() or such) I would not recommend.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

matt.h
Member #11,829
April 2010

Thanks a lot,

finally I choose to use the hardware cursor, I remove all show_mouse() and to avoid the issue with blitting I used scare and unscare on function where I had issue.

the only thing stays is I would like potentially remove the hardware cursor in Allegro window

any idea :D

I would appreciate help ;)

let me know thanks a lot

Evert
Member #794
November 2000
avatar

matt.h said:

finally I choose to use the hardware cursor, I remove all show_mouse() and to avoid the issue with blitting I used scare and unscare on function where I had issue.

the only thing stays is I would like potentially remove the hardware cursor in Allegro window

I think you got things mixed up somewhere, because that doesn't make sense to me.

A hardware cursor, in Allegro-speak, is a custom cursor (ie, with a bitmap that you provide) that is drawn by the OS. Not by you or by Allegro. Because the OS draws it, you don't have to worry about mouse tails or anything like that, you never need to hide or scare the mouse. Things generally just work.
You can call set_mouse_sprite()/show_mouse() and never worry about a thing afterwards.

If you're never calling show_mouse(), then you don't need scare/unscare_mouse(), because there is no mouse cursor.

The standard system mouse cursor, in Allegro-speak, is called a system or OS cursor. This is never visible if you use a hardware cursor, because when you set a "hardware cursor" you're changing the system mouse cursor.

It doesn't look like this is what you did from your message, but I can't work out what it is that you did do. Can you clarify?
Post code if you have to.

matt.h
Member #11,829
April 2010

Hi,

I made some test and better understood what you mean :)

I declare nothing except install mouse driver and it use the hardware cursor because all work without scare and unscare so it seems that just declare the install_mouse and enable_hardware_.. and that is all after all is ok

will go on to make some test

will let you know thanks a lot

Matt

Dario ff
Member #10,065
August 2008
avatar

LennyLen, those effects aren't convincing enough. ;)

Here's one reason for drawing the cursor yourself, taken from my CH entry. (Zoomed of course)

video

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Go to: