Various API/SDK questions
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    Hi!

    Porting my game-engine to MorphOS is going well in general. Gfx, sound, music, mouse- and keyboard-control, online-scores are working fine already, so I actually can play our games already. Took about one day to get that far :-)
    But... some questions remain. For your information: my test-system is an antique PowerMac G4 with a Radeon 9000.

    1. Joystick control
    Do I have to use lowlevel-lib? There is that sensor-lib that appears to be the more modern approach. But either I'm blind or there is no documentation / sample-code for this?! Any hints?
    Answer: use lowlevel.library

    2. TinyGL I
    I have it working, but only after I added the (pretty much undocumented) function GLAReinitializeContextWindowed to my window-resize-code. Without that function call the output will become distorted when I resize the window to a certain degree (distorted means pixel-garbage at some areas plus wrong viewport position). Is that behaviour normal? Is my usage of GLAReinitializeContextWindowed correct?
    Answer: sounds correct

    3. TinyGL II
    When the window is rather large (>= 1280 x 900 or so) things get damn slow all of a sudden. Is that a known performance limitation of my system? The max. viewport-size of a Radeon9000 should be 2048x2048 I think, so I'm still inside valid boundaries here.

    4. TinyGL III
    On my test-system it looks as if GL_CLAMP_TO_EDGE wasn't properly supported, it behaves like GL_CLAMP, bleeding the border-color inside. Of course this effect is most noticable with tiny textures that are mapped on large polygons. Is that a known problem? Or am I missing something?
    Answer: This is a bug in the R200- and R300-drivers introduced with MorphOS 3.0. GL_CLAMP behaves like GL_CLAMP_TO_EDGE and vice versa. For now I added a tooltype to my programs so users can manually toggle the behaviour if graphics are corupt on their system. The bug will be fixed with MorphOS 3.5.

    5. Screensaver
    How do I disable the screensaver? In the SDK-docs the function HIDInput is mentioned. In intuition.library (?). But it's not in the headers?!
    Answer: SetAttrs(screen, SA_StopBlanker, TRUE, TAG_DONE);
    For games this isn't necessary though, since all kinds of user-inputs prevent the screensaver from kicking in.

    6. launching the default browser with an http-URL
    On AmigaOS4 this is really trivially and nicely done by simply opening a file on the device URL:
    On my MorphOS setup this isn't working. Is that type of URL-opening not supported by MorphOS or is my system misconfigured or is there another way to achieve this?
    Answer: use openurl.library, URL_Open

    7. out of curiosity:
    Is there something like AmigaOS4's compositing engine on MorphOS? To be concrete: is there an API that can draw textured, alpha-blended, filtered triangle-lists apart from TinyGL? Hardware-accelerated functions only.
    Answer: apparently no triangles, but for rectangular areas BitMapScale(), BltBitMapRastPortAlpha(), BltBitMapAlphaProcessPixelArray and ProcessPixelArray are available.

    8. mouse-pointer picture
    The function SetWindowPointer doesn't work for me. It simply has no effect when called for my window. Isn't that syntax correct?
    SetWindowPointer(window_handle,WA_PointerType,POINTERTYPE_BUSY,TAG_DONE);
    Defining one initial pointer-type for the window during OpenWindow works.
    Am I missing some special init-code for SetWindowPointer to work as expected?
    Answer: Don't use SetWindowPointer() but SetAttrs(): SetAttrs(window, WA_PointerType, POINTERTYPE_BUSY, TAG_DONE);

    9. TinyGL IV:
    GLASetSync has no effect. No matter if I use a screen-context or window-context and no matter when I call GLASetSync, it has zero effect, the GL output is always not vsynced. Is this a known limitation/bug on my Radeon9000-system? Or is there some additional setup I need to do?
    As a workaround I tried WaitTOF, but this seems to misbehave just like it does on AmigaOS4/RadeonHD: it doesn't do a real vsync but just seems to wait for some 1/70 seconds or so (you can spot a nice tearing moving down the screen), not useful at all.
    Answer: Window-contexts are not vsynced, only double-buffered screen-contexts, but those are synced by default. WaitTOF should never be used.
    Nevertheless the problem that the screen-context was not vsynced remained.
    The reason was that I accidentially called GLAReinitializeContextWindowed on the context... making it a window context again... :-P

    10. ASL screen mode requester
    ASLSM_MinDepth is ignored on my system. I explicitely request screen-modes with a depth of at least 16 bits through that attribute, but the requester also shows 8 bit palette modes. System bug?
    Answer: System bug. It looks like ASLSM_MinDepth only sets minimum depth to the depth slider. It does not filter any screenmodes according to MinDepth/MaxDepth setting.

    11. Mouse Capture
    Is there a better way to capture the mouse to stay inside the application's main window than to reposition it via DoIO? At least on my system this results in a huge performance penalty (in fullscreen mode this is not needed and therefore no issue, luckily).
    Answer: Install an interrupt-handler to catch the IECLASS_RAWMOUSE events before they are delivered to the normal event-handler. Extract the x/y deltas and then set the event's coordinates to zero, which will effectively cancel any mouse-pointer movement. Check FodQuake sources, file in_morphos.c . An alternative would be to use WM_ObtainEvents and WM_ReleaseEvents.

    Thanks for your help!
    Daniel

    -
    Edited to integrate answers.
  • »09.12.13 - 13:25
    Profile Visit Website
  • MorphOS Developer
    itix
    Posts: 1520 from 2003/2/24
    From: Finland
    Quote:


    1. Joystick control
    Do I have to use lowlevel-lib? There is that sensor-lib that appears to be the more modern approach. But either I'm blind or there is no documentation / sample-code for this?! Any hints?



    Use lowlevel.library. It supports (transparently) old style joystick ports and USB controllers and it supports both digital and analog controllers.

    Quote:


    5. Screensaver
    How do I disable the screensaver? In the SDK-docs the function HIDInput is mentioned. In intuition.library (?). But it's not in the headers?!



    Use SA_StopBlanker attribute found in screens.h:

    SetAttrs(screen, SA_StopBlanker, TRUE, TAG_DONE);

    Intuition screens are BOOPSI objects in MorphOS. You must set it false before you quit and this call nests.

    Quote:


    6. launching the default browser with an http-URL
    On AmigaOS4 this is really trivially and nicely done by simply opening a file on the device URL:
    On my MorphOS setup this isn't working. Is that type of URL-opening not supported by MorphOS or is my system misconfigured or is there another way to achieve this?



    You must go through openurl.library API.
    1 + 1 = 3 with very large values of 1
  • »09.12.13 - 14:32
    Profile
  • MorphOS Developer
    geit
    Posts: 1054 from 2004/9/23
    Quote:

    Do I have to use lowlevel-lib? There is that sensor-lib that appears to be the more modern approach. But either I'm blind or there is no documentation / sample-code for this?! Any hints?


    You probably can look up example code in this OpenSource racer. No clue if the example is in SDK by now and will be released with next SDK.

    Quote:

    How do I disable the screensaver? In the SDK-docs the function HIDInput is mentioned. In intuition.library (?). But it's not in the headers?!


    intuition/screens.h

    #define SA_StopBlanker /* *S* */ (SA_Dummy + 121)

    Most documentation can be found in headers itself.

    Quote:

    On AmigaOS4 this is really trivially and nicely done by simply opening a file on the device URL:
    On my MorphOS setup this isn't working. Is that type of URL-opening not supported by MorphOS or is my system misconfigured or is there another way to achieve this?


    It works the same way it would work on OS2.x and OS3.x using openurl.library. No clue why OS4 developers added an additional way. It is just OpenLibrary(), OpenURL and CloseLibrary() as simple as using some fancy device which is using OpenURL anyway. From shell you can use the OpenURL or the Open command. Open is performing a double click and using openurl when a link was detected.

    Quote:

    Is there something like AmigaOS4's compositing engine on MorphOS? To be concrete: is there an API that can draw textured, alpha-blended, filtered triangle-lists apart from TinyGL? Hardware-accelerated functions only.


    All system functions are using compositing engine. All you need to do is to enable alpha rendering using SetRPAttrsA() with RPTAG_AlphaMode, TRUE before rendering.

    No clue about TinyGL :)

    Geit
  • »09.12.13 - 14:46
    Profile
  • MorphOS Developer
    itix
    Posts: 1520 from 2003/2/24
    From: Finland
    Quote:

    Daytona675x wrote:
    7. out of curiosity:
    Is there something like AmigaOS4's compositing engine on MorphOS? To be concrete: is there an API that can draw textured, alpha-blended, filtered triangle-lists apart from TinyGL? Hardware-accelerated functions only.



    BitMapScale() and BltBitMapRastPortAlpha() and BltBitMapAlpha() are hardware accelerated where available but scaling is better done with TinyGL due to better control. ProcessPixelArray() provides more gfx ops which are hardware accelerated but I cant remember which operations. Supported operations:

    /*
    * Operations for ProcessPixelArray() (v50)
    *
    */

    #define POP_BRIGHTEN 0
    #define POP_DARKEN 1
    #define POP_SETALPHA 2
    #define POP_TINT 3
    #define POP_BLUR 4
    #define POP_COLOR2GREY 5
    #define POP_NEGATIVE 6
    #define POP_NEGFADE 7
    #define POP_TINTFADE 8
    #define POP_GRADIENT 9
    #define POP_SHIFTRGB 10
    1 + 1 = 3 with very large values of 1
  • »09.12.13 - 14:51
    Profile
  • MorphOS Developer
    itix
    Posts: 1520 from 2003/2/24
    From: Finland
    Quote:

    Daytona675x wrote:

    2. TinyGL I
    I have it working, but only after I added the (pretty much undocumented) function GLAReinitializeContextWindowed to my window-resize-code. Without that function call the output will become distorted when I resize the window to a certain degree (distorted means pixel-garbage at some areas plus wrong viewport position). Is that behaviour normal? Is my usage of GLAReinitializeContextWindowed correct?



    I know very little about TinyGL/OpenGL but it sounds correct. In SDL I am calling GLAReinitializeContextWindowed() on window resize.
    1 + 1 = 3 with very large values of 1
  • »09.12.13 - 15:38
    Profile
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @itix
    @geit

    Thanks for your help!
    I edited my initial post to show your answers in case somebody else is looking for similar info.

    @itix
    Regarding SA_StopBlanker and SetAttrs.
    So this is no "global" setting but per-screen? So let's asume I deactivate the blanker for my game-screen, then the blanker will still kick in in case the workbench-screen is currently the topmost screen?

    In the meantime one more question came up, regarding SetWindowPointer :-)
  • »09.12.13 - 16:55
    Profile Visit Website
  • Moderator
    Kronos
    Posts: 2431 from 2003/2/24
    Quote:

    Daytona675x wrote:

    So this is no "global" setting but per-screen? So let's asume I deactivate the blanker for my game-screen, then the blanker will still kick in in case the workbench-screen is currently the topmost screen?



    Which seems reasonable to me....

    a) pause game/switch to WB

    b) fall asleep after watching p.....

    c) screenblanker kicks in
  • »09.12.13 - 17:01
    Profile
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @Kronos
    Quote:

    Which seems reasonable to me....

    Indeed, if it works that way it's a nice feature. Just want to make sure I really get it right :-)
  • »09.12.13 - 17:05
    Profile Visit Website
  • MorphOS Developer
    itix
    Posts: 1520 from 2003/2/24
    From: Finland
    Quote:

    Daytona675x wrote:
    8. mouse-pointer picture
    The function SetWindowPointer doesn't work for me. It simply has no effect when called for my window. Isn't that syntax correct?
    SetWindowPointer(window_handle,WA_PointerType,POINTERTYPE_BUSY,TAG_DONE);
    Defining one initial pointer-type for the window during OpenWindow works.



    Do not use SetWindowPointer() but SetAttrs():

    SetAttrs(window, WA_PointerType, POINTERTYPE_BUSY, TAG_DONE);

    Would be logical if WA_PointerType was supported by SetWindowPointer(), though.
    1 + 1 = 3 with very large values of 1
  • »09.12.13 - 17:07
    Profile
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @itix
    Ah, thanks, works!
  • »09.12.13 - 17:28
    Profile Visit Website
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Zylesea
    Posts: 2061 from 2003/6/4
    Quote:



    I edited my initial post to show your answers in case somebody else is looking for similar info.



    That's nice from you. Makes obtaining the key information indeed easier.
    --
    http://via.bckrs.de

    Whenever you're sad just remember the world is 4.543 billion years old and you somehow managed to exist at the same time as David Bowie.
    ...and Matthias , my friend - RIP
  • »09.12.13 - 22:14
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3195 from 2003/3/5
    From: Canada
    Quote:

    Daytona675x wrote:


    1. Joystick control

    lowlevel.library is indeed the old way to go and will be obsoleted since it cannot give you access to all the fun stuff new controllers have.

    5. Screensaver
    How do I disable the screensaver? In the SDK-docs the function HIDInput is

    You do not want to do that in a game, really. There's no reason to - user input feeds games after all and it also does prevent blankers from starting. You do want them to start when the user leaves for a while after all. So - unless you have long periods of user inactivity as part of your game, there's no reason to use this stuff.

    8. mouse-pointer picture

    There's an example in the SDK in Examples/intuition/argpointer.c - remember to use MM_GetPointerBounds and mind that not every card supports argb mouse pointer - the old ones do not.

    [ Edited by jacadcaps 10.12.2013 - 09:56 ]
  • »10.12.13 - 09:50
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @jacadcaps

    Quote:

    lowlevel.library is indeed the old way to go and will be obsoleted since it cannot give you access to all the fun stuff new controllers have.

    Yes, but since I didn't find any real documentation of the sensor-lib so far I'll stick with lowlevel.lib for now.

    Screensaver:
    Quote:

    There's no reason to - user input feeds games after all and it also does prevent blankers from starting.

    I am new to MorphOS so I don't know its behaviour here in detail yet. On other systems (Windows for example) this is not (always) true, sadly. Joystick-input via DirectInput won't prevent the screensaver from kicking-in. Really annoying, therefore we had feedback from users requesting screensaver-disabling and I ended up adding that feature (same thing on AmigaOS4 IIRC), although rather "smart": when the game is paused or in a "uncritical" state like the main-menu then the screen-safer is allowed to activate.

    Anyway, if MorphOS behaves differently here and doesn't launch the screensaver when using joysticks via lowlevel-lib, then I won't add a blanker-blocker - otherwise I will.

    Quote:

    There's an example in the SDK in Examples/intuition/argpointer.c

    Thanks for the hint. I'll not need that though, I'll stick with the default pointers MorphOS supplies.

    [ Editiert durch Daytona675x 10.12.2013 - 11:21 ]
  • »10.12.13 - 11:21
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3195 from 2003/3/5
    From: Canada
    Quote:

    Daytona675x wrote:
    Anyway, if MorphOS behaves differently here and doesn't launch the screensaver when using joysticks via lowlevel-lib, then I won't add a blanker-blocker - otherwise I will.


    Yes, joystick input is regarded as user activity and therefore ensures a blanker will not kick in.
  • »10.12.13 - 11:27
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @jacadcaps

    Great, less work then ;-)
  • »10.12.13 - 11:32
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    Just answered question 4 myself :-)
  • »17.12.13 - 10:51
    Profile Visit Website
  • MorphOS Developer
    bigfoot
    Posts: 510 from 2003/4/11
    Quote:

    3. TinyGL II
    When the window is rather large (>= 1280 x 900 or so) things get damn slow all of a sudden. Is that a known performance limitation of my system? The max. viewport-size of a Radeon9000 should be 2048x2048 I think, so I'm still inside valid boundaries here.


    HyperZ only works when the total screen area is less than 2^21 (2097152) pixels, and furthermore has some width/height alignment restrictions which could slightly reduce the maximum supported screen area. However, 1280x900 is only a bit over halfway to that limit...

    Quote:

    4. TinyGL III
    On my test-system it looks as if GL_CLAMP_TO_EDGE wasn't properly supported, it behaves like GL_CLAMP, bleeding the border-color inside. Of course this effect is most noticable with tiny textures that are mapped on large polygons. Is that a known problem? Or am I missing something?
    Answer: TinyGL-bug, use GL_CLAMP instead. At least on my Radeon 9000 setup the behaviour is mixed up: GL_CLAMP acts like GL_CLAMP_TO_EDGE and vice-versa... :P I just hope that this mis-behaviour is at least the same on all supported gfx-cards...


    More likely a bug in the driver, actually. Is there any way I could get you to send me a simple test app? That would make testing and fixing it a lot easier for me.
    I rarely log in to MorphZone which means that I often miss private messages sent on here. If you wish to contact me, please email me at [username]@asgaard.morphos-team.net, where [username] is my username here on MorphZone.
  • »17.12.13 - 11:33
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @bigfoot
    Quote:

    HyperZ...

    The context has no z-buffer.

    Quote:

    More likely a bug in the driver, actually. Is there any way I could get you to send me a simple test app? That would make testing and fixing it a lot easier for me.

    Well, actually it's quite simple:

    turn on texturing etc., disable lighting, glColor4f(1,1,1,1), create a 16x16 purely while RGBA texture, turn on bilinear filtering for that texture, use GL_CLAMP_TO_EDGE for that texture, map in on a big triangle with UVs 0,0 / 1,0 / 1,1.

    If the triangle is not 100% white but shows a blackish border then GL_CLAMP_TO_EDGE behaves like GL_CLAMP (and on my system you get a pure white triangle like it's supposed to be with _TO_EDGE if you (incorrectly) set it to GL_CLAMP...).

    But yes, I may post some code if that really helps.
  • »17.12.13 - 13:10
    Profile Visit Website
  • MorphOS Developer
    bigfoot
    Posts: 510 from 2003/4/11
    Quote:

    The context has no z-buffer.


    Well, then there's no easy explanation for a sudden performance drop above a certain resolution. My best guess would then be that you're reaching a point where the Radeon's internal caches are no longer very effective.

    Quote:

    Well, actually it's quite simple:

    [...]

    But yes, I may post some code if that really helps.


    Please do. It is often not quite as simple as it looks, and I am often not able to reproduce problems that have only been described in basic terms. You giving me a small test program that shows the problem ensures that I have code that is known to show a problem for you, rather than maybe wasting a lot of time trying to recreate an example on my end which might not even give any problem for me.
    I rarely log in to MorphZone which means that I often miss private messages sent on here. If you wish to contact me, please email me at [username]@asgaard.morphos-team.net, where [username] is my username here on MorphZone.
  • »17.12.13 - 13:30
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @bigfoot

    Alright, here you go.

    Here you can download source and executable for a little program that incorrectly displays that on my Radeon 9000 equipped system:

    clamp_bug.png

    As you can easily see this is not what you'd expect with GL_CLAMP_TO_EDGE.
    This is how GL_CLAMP should look like.
    In contrast to that GL_CLAMP_TO_EDGE should result in a perfectly white triangle.
    Actually GL_CLAMP_TO_EDGE was invented to avoid such border artifacts.

    And as being mentioned:
    if I use GL_CLAMP then I incorrectly get a completely white triangle.
    The effect of those two attributes is simply vice versa on my system.

    I suppose this went unnoticed until now because most unexperienced OpenGL programmers use GL_CLAMP when they actually mean GL_CLAMP_TO_EDGE ;-)

    [ Editiert durch Daytona675x 17.12.2013 - 15:40 ]
  • »17.12.13 - 15:36
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @bigfoot
    I hope this bug is consistent among all supported gfx-cards?

    If it is consistent you should probably keep the current wrong GL_CLAMP behaviour since changing that now would most likely break many (if not all) existing TGL-programs. Better just fix GL_CLAMP_TO_EDGE to act like it is supposed to.

    The correct behaviour of GL_CLAMP (= what you see above) is of very little real-world-use anyway. If you want to support it then maybe just add a new define like GL_CLAMP_FIXED or whatever for that rare case.
  • »18.12.13 - 08:21
    Profile Visit Website
  • MorphOS Developer
    bigfoot
    Posts: 510 from 2003/4/11
    Thanks for the test app. I'll make sure this problem gets fixed for the next MorphOS release.

    Quote:

    I hope this bug is consistent among all supported gfx-cards?


    Nope. The bug is in the driver this time :)

    Quote:

    If it is consistent you should probably keep the current wrong GL_CLAMP behaviour since changing that now would most likely break many (if not all) existing TGL-programs. Better just fix GL_CLAMP_TO_EDGE to act like it is supposed to.


    The bug was introduced in MorphOS 3.0, and I'd guess that most TGL programs are from before then. In any case, it doesn't seem to have had a very big effect in real life as it has gone unnoticed until now.
    I rarely log in to MorphZone which means that I often miss private messages sent on here. If you wish to contact me, please email me at [username]@asgaard.morphos-team.net, where [username] is my username here on MorphZone.
  • »18.12.13 - 08:36
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    @bigfoot
    Quote:

    Nope. The bug is in the driver this time

    Damn! So, what am I supposed to do to get the desired behaviour (= without black border)?
    Shall I use GL_CLAMP_TO_EDGE although it produces artifacts on some machines right now?
    Or is there a reliable glGetString I can use to select the appropriate wrap-mode depending on driver-version and card-type?

    Hm, maybe I'll add a Tooltype so people can modify the behaviour themselfs in case they got a buggy system.

    [ Editiert durch Daytona675x 18.12.2013 - 10:01 ]
  • »18.12.13 - 08:58
    Profile Visit Website
  • Acolyte of the Butterfly
    Acolyte of the Butterfly
    Daytona675x
    Posts: 109 from 2013/12/5
    Three more questions, 9 to 11, regarding GLASetSync, ASLSM_MinDepth and mouse-capturing :-) Thanks!

    [ Editiert durch Daytona675x 20.12.2013 - 14:01 ]
  • »20.12.13 - 13:30
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    BSzili
    Posts: 560 from 2012/6/8
    From: Hungary
    To answer 11. check out the MorphOS port of FodQuake by bigfoot. You can use an interrupt to capture input events and nuke them after you put them in your queue.
    This is just like television, only you can see much further.
  • »20.12.13 - 15:25
    Profile Visit Website