Welcome, Guest. Please login or register.

Author Topic: Programming a Window in C to hold a picture/background  (Read 3122 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Programming a Window in C to hold a picture/background
« on: January 09, 2012, 04:35:16 AM »
I would like to learn how to load or program a picture into a window. ANyone have the necessary C code examples or tutorial for that?

I am trying my hand for the first time to program in the AmigaOS environment. I am familiar with most debugging messages and can muddle my through tutorials - I have only been at it for a week and have mad enough progress to say loosely  I have learned a fewthingd about Screens and windows. But I am trolling for mor information. I am Using Louis Se GCC environment - I really like the way it is set up and I am trying to get the basics down but this loading and keeping an image in a window is giving me trouble - mayhaps someone has a lexicon of sorts that explaina the GCC library structure as I am pretty sure I need a more developed Library cache - many of the examples I have found do not compile and the error list is mostly in something like assembler or the like. I am used to debugging: on line 57 etc etc but the errors i get look like this:


Any suggestions are greatly welcome and appreciated.:)
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline NovaCoder

Re: Programming a Window in C to hold a picture/background
« Reply #1 on: January 09, 2012, 05:08:08 AM »
Try this kind of thang...

Code: [Select]

    GfxBase = (struct GfxBase*)OpenLibrary( "graphics.library", 0L);
    if (!GfxBase) {
        error("Could not open the Graphics library");
    }

    IntuitionBase = (struct IntuitionBase*)OpenLibrary( "intuition.library", 0L);
    if (!IntuitionBase) {
        error("Could not open the Intuition library");
    }
Life begins at 100 MIPS!


Nice Ports on AmiNet!
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12114
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Programming a Window in C to hold a picture/background
« Reply #2 on: January 09, 2012, 08:14:18 AM »
Not sure where you are at... So I'll point you right at the start :)

http://www.liquido2.com/tutorial/hello_world.html

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Re: Programming a Window in C to hold a picture/background
« Reply #3 on: January 10, 2012, 12:12:58 AM »
Yep - been using those tutorials mostly - they are really a good place to learn but they only go as far as a simple selecter program - which is cool nd it will come in handy - the getting an image into a window is the heart of my frustration.

A little nudge in the code direction would be helpful.

Nova - that code, I am pretty sure is just an error trap - not very load-an-image based though. but thank anyway. If it does more would you mind explaining it to me?
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline Steady

Re: Programming a Window in C to hold a picture/background
« Reply #4 on: January 10, 2012, 02:01:56 AM »
These are linker errors.

The C environment accesses IntuitionBase, DataTypesBase and GfxBase as global variables, but they are not defined in any module.

This should be fixed by adding the following include references as they define the globals you need:

#include
#include
#include

Good luck.
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Re: Programming a Window in C to hold a picture/background
« Reply #5 on: January 10, 2012, 06:05:39 AM »
Quote from: Steady;675107
These are linker errors.

The C environment accesses IntuitionBase, DataTypesBase and GfxBase as global variables, but they are not defined in any module.

This should be fixed by adding the following include references as they define the globals you need:

#include
#include
#include

Good luck.


Code: [Select]



#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/datatypes.h>
#include <datatypes/pictureclass.h>

int main (void)

{
struct RDArgs *rdargs;
struct {
char *file;
char *pubscreen;
} args = {0};
int rc = RETURN_FAIL;
struct Screen *scr;
Object *dto;
struct BitMapHeader *bmhd;
struct BitMap *bm;
WORD winw,winh;
struct Window *win;
struct IntuiMessage *imsg;
BOOL cont;

rdargs = ReadArgs (&quot;FILE/A,PUBSCREEM/K&quot;,(LONG *)&args,NULL);
if (!rdargs)
{
PrintFault (IoErr(),NULL);
return (RETURN_FAIL);
}

if (scr = LockPubScreen (args.pubscreen))
{

if (dto = NewDTObject (args.file,DTA_GroupID,GID_PICTURE,PDTA_Remap,TRUE,PDTA_Screen,scr,TAG_END))
{
DoDTMethod (dto,NULL,NULL,DTM_PROCLAYOUT,NULL,TRUE);
GetDTAttrs (dto,(ULONG) PDTA_BitMapHeader,&bmhd,(ULONG) PDTA_BitMap,&bm,TAG_END);

if (bm && bmhd)
{
winw = bmhd->bmh_Width + scr->WBorLeft + scr->WBorRight;
winh = bmhd->bmh_Height + scr->WBorTop + scr->RastPort.TxHeight + 1 + scr->WBorBottom;

if (win = OpenWindowTags (NULL,
WA_Left, (scr->Width - winw) / 2,
WA_Top, (scr->Height - winh) / 2,
WA_Width, winw,
WA_Height, winh,
WA_Title, args.file,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_NOCAREREFRESH,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
TAG_END))
{
rc = RETURN_OK;

BltBitMapRastPort (bm,0,0,win->RPort,win->BorderLeft,win->BorderTop,win->GZZWidth,win->GZZHeight,0xc0);

cont = TRUE;
do {
if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
cont = FALSE;
while (imsg = (struct IntuiMessage *) GetMsg (win->UserPort))
{
switch (imsg->Class)
{
case IDCMP_VANILLAKEY:
if (imsg->Code == 0x1b) /* Esc */
cont = FALSE;
break;
case IDCMP_CLOSEWINDOW:
cont = FALSE;
break;
}
ReplyMsg ((struct Message *) imsg);
}
}
while (cont);
CloseWindow (win);
}

}
else
Printf (&quot;image cannot be rendered into the named pubscreen\n&quot;);

DisposeDTObject (dto);
}
else
{
Printf (GetDTString (IoErr()),args.file);
Printf (&quot;\n&quot;);
}

UnlockPubScreen (NULL,scr);
}
else
Printf (&quot;cannot lock pubscreen\n&quot;);

return (rc);
}


Thats the whole file - someone slid it to me in the effort to clarify my getting a picture into a window. As you can see the #includes are already there. I hope you have some more magic for me beecause all my spells have been spent hours ago.

Thanks:)
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Programming a Window in C to hold a picture/background
« Reply #6 on: January 10, 2012, 06:41:13 AM »
First of all, you should compile the app with -noixemul.

Additionally the code depends on the library bases being opened automagically so you may need to add libauto (-lauto). Some systems don't have working libauto in which case you need to open the library bases manually as described earlier.
 

Offline nyteschayde

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Programming a Window in C to hold a picture/background
« Reply #7 on: January 10, 2012, 08:04:00 AM »
Quote from: Piru;675122
First of all, you should compile the app with -noixemul.

Additionally the code depends on the library bases being opened automagically so you may need to add libauto (-lauto). Some systems don't have working libauto in which case you need to open the library bases manually as described earlier.


I was wondering about libauto. By some systems don't have it, do you mean that some compilers don't provide it or do you mean literally that like OS3 might not have it vs. OS 3.1?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Programming a Window in C to hold a picture/background
« Reply #8 on: January 10, 2012, 08:20:42 AM »
Quote from: nyteschayde;675128
I was wondering about libauto. By some systems don't have it, do you mean that some compilers don't provide it or do you mean literally that like OS3 might not have it vs. OS 3.1?


It's a link library, so it's down to the compiler to provide it.

Personally, I always manage opening libraries, devices etc. manually.

PS. long time no see!
int p; // A
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Re: Programming a Window in C to hold a picture/background
« Reply #9 on: January 12, 2012, 10:23:16 PM »
I have really been searching for information or code examples but I have found nothing that explains how to program a picture into an amiga window or screen... PLEASE - someone must have an idea where I can look or offer som sort of code that I can do this with. :furious:

The example I posted has proven to be useless btw.
« Last Edit: January 12, 2012, 10:25:43 PM by Morbane »
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline Louis Dias

Re: Programming a Window in C to hold a picture/background
« Reply #10 on: January 12, 2012, 11:38:04 PM »
Amiga needs Wine. ;-)
 

Offline Mazze

  • Full Member
  • ***
  • Join Date: Aug 2007
  • Posts: 133
    • Show only replies by Mazze
    • http://mazze-online.de
Re: Programming a Window in C to hold a picture/background
« Reply #11 on: January 13, 2012, 12:37:57 AM »
Quote from: Morbane;675514
The example I posted has proven to be useless btw.

Why? It loads a picture with the Datatypes system and blits it into a window. What do you expect?

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Re: Programming a Window in C to hold a picture/background
« Reply #12 on: January 13, 2012, 06:29:19 AM »
Quote from: Mazze;675531
Why? It loads a picture with the Datatypes system and blits it into a window. What do you expect?

I was hoping it would compile and run so I can learn something. I tried it in 3 compilers GCC , DEVCC, Codeblocks - no luck with all three, though DEVCC had the least amount of errors but I cant decipherthem. Damn.
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Programming a Window in C to hold a picture/background
« Reply #13 on: January 13, 2012, 06:43:51 AM »
Quote from: Morbane;675555
I was hoping it would compile and run so I can learn something. I tried it in 3 compilers GCC , DEVCC, Codeblocks - no luck with all three, though DEVCC had the least amount of errors but I cant decipherthem. Damn.

The example compiles just fine with gcc here if I specify -noixemul. I do have working libauto though. If I leave -noixemul out I get the same errors as you (as expected).
 

Offline MorbaneTopic starter

  • Newbie
  • *
  • Join Date: Jan 2012
  • Posts: 7
    • Show only replies by Morbane
Re: Programming a Window in C to hold a picture/background
« Reply #14 on: January 13, 2012, 12:57:05 PM »
Thanks for your input - this is what I am getting:


:confused:
If it makes sense - I will make it make no sense - or is that backwards -

Is remembering - backwards thinking or just another way of seeing the big picture?