Welcome, Guest. Please login or register.

Author Topic: Pixel isn't drawn  (Read 2015 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Omega Space ProtonsTopic starter

  • Newbie
  • *
  • Join Date: Oct 2010
  • Posts: 41
    • Show all replies
Pixel isn't drawn
« on: October 25, 2010, 02:42:42 PM »
I have started coding my first game for the Amiga and am a bit stuck. I am trying to draw a single pixel on the screen using the WritePixel() function. However for some reason the pixel is not being drawn. The two line below sum it up:

Code: [Select]
/* set the pen color to blue */
pen = ObtainBestPenA(ViewAddress()->ViewPort->ColorMap, 0x0, 0x0, 0xFFFFFFFF, NULL);

 /* Draw the ball */
WritePixel(GameWindow->RPort, 100, 100);
Any assistance in this matter would be greatly appreciated.

Omega Space Protons

Update: see updated code below.
« Last Edit: October 25, 2010, 06:04:30 PM by Omega Space Protons »
 

Offline Omega Space ProtonsTopic starter

  • Newbie
  • *
  • Join Date: Oct 2010
  • Posts: 41
    • Show all replies
Re: Pixel isn't drawn
« Reply #1 on: October 25, 2010, 03:37:51 PM »
is this better for setting the color:
Code: [Select]
[FONT=monospace]
int game_init(void)
{
 
    int result = 0;
 
    /* First open the graphics.library */
    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
 
    /* was the graphics library opened? */
    if(GfxBase != NULL)
    {
 
        /* Second open the intuition.library. */
        IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0L);
 
        /* was the library opened? */
        if (IntuitionBase != NULL)
        {
 
            /* since the was opened, we can open a window. */
            GameWindow = (struct Window *)OpenWindowTags(NULL,
                         WA_Left, 20,
                         WA_Top, 20,
                         WA_Width, 200,
                         WA_Height, 200,
                         WA_Title, (ULONG)"Omega Space Protons",
                         WA_DepthGadget, TRUE,
                         WA_CloseGadget, TRUE,
                         WA_SizeGadget, TRUE,
                         WA_DragBar, TRUE,
                         WA_GimmeZeroZero, TRUE,
                         WA_ReportMouse, TRUE,
                         WA_IDCMP, IDCMP_CLOSEWINDOW,
                         TAG_END);
 
            /* was the window opened? */
            if (GameWindow == NULL)
            {
                /* The window was not opened so display a message. */
                printf("Unable to open the window!\n");
                result = -1;
            }
        }
        else
        {
            /* the library was not opened, so display a message */
            printf("Unable to open the intuition.library!\n");
            result = -2;
        }
    }
    else
    {
        /* The graphics.library was not opened so display amessage. */
        printf("Unable to open the graphics.library!\n");
    }
[/FONT]
     blue = ObtainBestPenA(GameWindow->WScreen->ViewPort.ColorMap, 0x0, 0x0, 0xFFFFFFFF, NULL);

    if(blue = -1)
   {
   printf("Unable to obtain pen for the color blue!\n");
   }
[FONT=monospace]
    return result;
}[/FONT]
then inside my game loop:

and in the cleanup function:
Code: [Select]
void clean_up(void)
{
 
    /* If thw window is open, close it */
    if(GameWindow != NULL)
    {
        CloseWindow(GameWindow);
    }
 
    /* If the intuition.library is open, close it */
    if(IntuitionBase != NULL)
    {
        CloseLibrary((struct Library *)IntuitionBase);
    }
 
    /* If the graphics.library is open, close it */
    if(GfxBase != NULL)
    {
        CloseLibrary((struct Library *)GfxBase);
    }

    ReleasePen(GameWindow->WScreen->ViewPort.ColorMap, blue);
 
    return;
}
finally in the game loop:
Code: [Select]
void game_loop(void)
{
 
    ULONG signals;
    ULONG window_signal;
    struct IntuiMessage *message;
    UWORD msg_code;
    ULONG msg_class;
    BOOL end = FALSE;
    LONG pen;
 
    /* define the window signal */
    window_signal = 1L << GameWindow->UserPort->mp_SigBit;
 
    /* Main game loop */
 
    /* Wait until the close button is pressed */
    while (!end && GameWindow)
    {
        signals = Wait(window_signal);
 
        /* check the signal bit forour message port. Will be trueif there is a message */
        if (signals & ( 1L << GameWindow->UserPort->mp_SigBit))
        {
 
            /* there may be more then one message, so keep processing messages until there are no more. */
            while (message = (struct IntuiMessage *)GetMsg(GameWindow->UserPort))
            {
 
                /* Copy the necessary infomation from the message. */
                msg_class = message->Class;
                msg_code = message->Code;
 
                /* Reply as soon as possible. */
                ReplyMsg( (struct Message *)message) ;
 
                /* Take the proper action in response to the message */
                switch(msg_class)
                {
                    /* User pressed the close window gadget */
                case IDCMP_CLOSEWINDOW:
                    end = TRUE;
                    break;
 
                    /* default action */
                default:
                    break;
                }
            }
        }
 
    /* set the pen color to blue */
    SetPen(GameWindow->RPort, blue);
 
    /* Draw the ball */
    WritePixel(GameWindow->RPort, 100, 100);
    }
 
    return;
}
« Last Edit: October 25, 2010, 03:45:27 PM by Omega Space Protons »
 

Offline Omega Space ProtonsTopic starter

  • Newbie
  • *
  • Join Date: Oct 2010
  • Posts: 41
    • Show all replies
Re: Pixel isn't drawn
« Reply #2 on: October 25, 2010, 04:42:13 PM »
Ok, I think I have it now, i made the necessary adjustments and would like to know if this code is correct before i finalize it. Attached is the modified code with the the suggested modifications awaiting your approval.

Omega Space Protons

Update: see updated code below.
« Last Edit: October 25, 2010, 06:04:08 PM by Omega Space Protons »
 

Offline Omega Space ProtonsTopic starter

  • Newbie
  • *
  • Join Date: Oct 2010
  • Posts: 41
    • Show all replies
Re: Pixel isn't drawn
« Reply #3 on: October 25, 2010, 06:02:36 PM »
I think this is it, as soon as get the ok, I will finalize it into the current code branch. Thank you everyone for helping me with this problem, you have saved me a lot of time.

Omega Space Protons
« Last Edit: October 25, 2010, 06:10:27 PM by Omega Space Protons »