OpenScreen & OpenScreenTags ... Why do they don't work ?

This forum is for general developer support questions.

OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby AmiDARK » Thu Dec 13, 2018 10:40 pm

When I want to create a screen, I encounter issues ...
I am with a Sam440Flex.
I allocate bitmap :
Code: Select all
   displayCore.mainBitMap = IGraphics->AllocBitMap( 640, 480, 32, BMF_INTERLEAVED, NULL );
Sometimes it does return a NULL Pointer.

Then if I create bitmap this way it don't work :
Code: Select all
      struct NewScreen mainScreenDefine = {
            0, 0,
            640, 480,
            32,
            1, 0,
            HIRES,
            PUBLICSCREEN,
            NULL,
            displayCore.DefaultDisplayTitle,
            NULL,
            displayCore.mainBitMap
      };
      displayCore.mainScreen = IIntuition->OpenScreen( &mainScreenDefine );


If I try this :
Code: Select all
      displayCore.mainScreen = IIntuition->OpenScreenTags( &mainScreenDefine,
            SA_Left, 0,       SA_Top, 0,
            SA_Width, 640,         SA_Height, 480,
            SA_Depth, 32,
            SA_DetailPen, 1, SA_BlockPen, 0,
            SA_Title, *displayCore.DefaultDisplayTitle,
            SA_BitMap, displayCore.mainBitMap,
            SA_Type, PUBLICSCREEN,
            SA_Draggable, TRUE,
            TAG_END   );

It don't work too .. .Even if I put NULL in place of &mainScreenDefine.

Can someone help me with a precise sample opening a Screen (without SDL or others stuff ... Only IGraphics & IIntuition) ?
Regards,
Sam440EP - AmigaOS 4.1 Final Edition
AmiDARK
 
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby thomasrapp » Fri Dec 14, 2018 12:10 am

Well. graphics.library is still backwards compatible with the classic Amiga native chip set.

This means that without specifying a special RTG pixel format you are limited to a depth of 8.

To get an RTG bitmap with a higher depth than 8 you have to specify a pixel format (for AllocBitMap) or a display ID (for OpenScreen) which supports that depth.
User avatar
thomasrapp
 
Posts: 277
Joined: Sun Jun 19, 2011 12:22 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby AmiDARK » Fri Dec 14, 2018 1:46 am

Thank you Thomasrapp for your answer.

I tried to use IGraphics->BestModeID to detect a 32bit compatible mode ID ... Without Success.
Screen only open if I set depth=8

Code: Select all
void egeDisplay_OpenScreen( int Width, int Height, int Depth ){
   
   // 1. Check for BestModeID
   int BestModeID = IGraphics->BestModeID( BIDTAG_Depth, Depth,
         BIDTAG_DesiredWidth, Width, BIDTAG_DesiredHeight, Height,
         BIDTAG_NominalWidth , Width, BIDTAG_NominalHeight, Height,
         TAG_END);

   if ( BestModeID != 0 ){
      debugMessage( " BestModeID found\n" );

      // 2. Alloc Bitmap for screen
      displayCore.mainBitMap = IGraphics->AllocBitMap( Width,   Height, Depth,
               BMF_INTERLEAVED || BMF_CLEAR || BMF_DISPLAYABLE,
               NULL );

      if ( displayCore.mainBitMap != NULL ){
         debugMessage( " AllocBitMap succeess\n" );

         // 3. Create NewScreen structure to receive data needed to open the Screen
         struct NewScreen mainScreenDefine = {
               0, 0, Width, Height, Depth,
               displayCore.DetailPen, displayCore.BlockPen,
               SPRITES,
               CUSTOMSCREEN ,
               NULL, /* Font Option */
               displayCore.DefaultDisplayTitle, /* Title of the Screen */
               NULL, /* Gadget Option */
               displayCore.mainBitMap
         };

         // 4. Open the new Screen using IIntuition.
         displayCore.mainScreen = IIntuition->OpenScreenTags( &mainScreenDefine,
               SA_DisplayID, BestModeID,
               TAG_END );

         if ( displayCore.mainScreen != NULL ){
            displayCore.setupScreen = &mainScreenDefine;
            debugMessage( "+ Screen opened successfully\n" );
         // Screen was not opened.
         }else{
            debugMessage( "- Screen was not correctly opened\n" );
         }

      // Error message for faulty AllocBitmap
      }else{
         debugMessage( "- AllocBitMap did return a NULL Pointer value\n" );
      }
   // Error message for faulty BestModeID
   }else{
      debugMessage( "- BestModeID did not return any useable ID\n" );
   }
}


Should I Use P96 or CGX method for BestModeID ?
Sam440EP - AmigaOS 4.1 Final Edition
AmiDARK
 
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby thomasrapp » Fri Dec 14, 2018 3:47 pm

There are at least two errors in your code:

Firstly the mode ID is a 32 bit unsigned value. You should use uint32 as its type. Just "int" is too vague.

Secondly 0 is a valid mode ID. You should check the returned ID against INVALID_ID and not against 0.

Also I would drop the usage of struct NewScreen. This is a compatibility layer for very old OS versions (1.x). You should rather use OpenScreenTags with a NULL NewScreen pointer and supply only the required values as tags. You can omit all the default values, for example Width and Height. They are determined by the mode ID.

Find attached a working example.

Note that 32bit screens only work if the gfx card supports them. For example a classic Amiga with a PicassoIV won't run the program.
Attachments
rtgscreen.zip
(1.4 KiB) Downloaded 54 times
User avatar
thomasrapp
 
Posts: 277
Joined: Sun Jun 19, 2011 12:22 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby AmiDARK » Fri Dec 14, 2018 10:27 pm

Hello Thomasrapp.
Thank you for all your advices.
I will look your sample and update my code with your advices.
Regards,
Sam440EP - AmigaOS 4.1 Final Edition
AmiDARK
 
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby AmiDARK » Sat Dec 15, 2018 10:27 am

Hello,

I did changes to my "OpenScreen" method using your advices and sample.
It gives this result :
Code: Select all
BOOL egeDisplay_OpenScreen( int Width, int Height, int Depth ){
   BOOL success = FALSE;
   debugMessage( "CALL: egeDisplay_OpenScreen\n" );

   // 1. Check for BestModeID
   ULONG myBestModeID = IGraphics->BestModeID(
         BIDTAG_NominalWidth, Width, BIDTAG_NominalHeight, Height,
         BIDTAG_Depth, Depth, TAG_END );

   // 2.A If BestModeID success.
   if ( myBestModeID != INVALID_ID ){
      debugMessage( " BestModeID found\n" );

      displayCore.mainScreen = IIntuition->OpenScreenTags( NULL,
            SA_Title, displayCore.DefaultDisplayTitle,
            SA_DisplayID, myBestModeID,
            SA_Depth, displayCore.Depth,
            // SA_Pens, displayCore.DetailPen, pointer to a pens array finished by {0} ... Ex : static const UWORD pens[] = {~0};
            SA_ErrorCode, &displayCore.Error,
            TAG_END );

      if ( displayCore.mainScreen != NULL ){
         debugMessage( "+ Screen opened successfully\n" );
         success = TRUE;
      // Screen was not opened.
      }else{
         debugMessage( "- Screen was not correctly opened\n" );
         printf( "error code = %lu\n", displayCore.Error );
      }

   }else{
      debugMessage( "- BestModeID did return INVALID_ID\n" );
   }
   return success;
}

But I always get the message "BestModeID did return INVALID_ID"..
I am on Sam440EP with Amiga OS 4.1 Finale Edition.
The resolutions I use is defined in my prefs.
Sam440EP - AmigaOS 4.1 Final Edition
AmiDARK
 
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby broadblues » Sat Dec 15, 2018 3:31 pm

What screen size and depth are you requesting?

Edit: I see from the first post that your trying for 640x480x32 Well that should be fine, ofcourse. Try verifying that you really are passing those values by extending your debug output.

Check in the screenmode prefs that those values are in fact available. If you asked for 32bit mode and you only have 16bit modes available for some reason then it might fail.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 591
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby xenic » Sat Dec 15, 2018 6:40 pm

broadblues wrote:What screen size and depth are you requesting?

Edit: I see from the first post that your trying for 640x480x32 Well that should be fine, ofcourse. Try verifying that you really are passing those values by extending your debug output.

Check in the screenmode prefs that those values are in fact available. If you asked for 32bit mode and you only have 16bit modes available for some reason then it might fail.


I wrote a short test program that calls BestModeIDTags() and prints the result. It fails like AmiDark's code. I also compiled the example program that thomasrapp attached to his post and it fails with this error: "cannot get proper screen mode for 640 x 480 x 32". I also tried getting other modes like '1024x768x32' which also fail. All the modes I tested are shown in my Prefs/Screenmode window.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1160
Joined: Sun Jun 19, 2011 1:06 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby AmiDARK » Sat Dec 15, 2018 7:51 pm

@broadblues : 640x480x32 is the requested mode.
I have from 640x480 to 1280x1024 screen modes availables in my prefs with 8, 16 and 32 bits modes.
I tried fixed values (entering directly the 640, 480 and 32 values in the methods parameters ... same result.

@Xenic : Happy to see that I'm not alone.
In previous tests (few days sooner), the BestModeID did randomly gives INVALID_ID (from one run to another) when trying 8 bits display... without explanations.
Sam440EP - AmigaOS 4.1 Final Edition
AmiDARK
 
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: OpenScreen & OpenScreenTags ... Why do they don't work ?

Postby thomasrapp » Sat Dec 15, 2018 8:13 pm

AmiDARK wrote:I have from 640x480 to 1280x1024 screen modes availables in my prefs with 8, 16 and 32 bits modes.


Well, no, actually you don't. BGRA32 ias the name of the pixel format, not the depth.

Attached is a program which lists all available screen modes. As you can see all the 32 bit modes have a depth of 24. Only uaegfx adds its modes with a depth of 32, which from now on should be considered a bug.

The alpha channel is ignored anyway, so 24 is the correct depth from that point of view.
Attachments
modelist.lha
(3.06 KiB) Downloaded 49 times
User avatar
thomasrapp
 
Posts: 277
Joined: Sun Jun 19, 2011 12:22 am

Next

Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 1 guest