Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline Thomas

Re: Pixel isn't drawn
« on: October 25, 2010, 03:19:37 PM »
1. you didn't check for failure. ObtainBestPen will return -1 if no matching pen was found, unless you specify OBP_FailIfBad,FALSE in the tag list

2. you got the pen number, but you forgot to tell the drawing system about it. Add SetAPen(GameWindow->RPort,pen); before WritePixel

3. you placed these commands after the Wait() command in your game loop procedure. That means, the commands will only be executed when some input message arrives. You should draw the pixel before the game loop is entered, then it will be drawn first and then the program will wait for input.

4. You never release the pen you obtained. And the obtain is done in a loop, so sooner or later all pens will be occupied. You should call ObtainBestPen once for each needed color in the initialisation routine and call ReleasePen once for each obtained pen in the cleanup routine. Do not call ObtainBestPen again in your game loop.

5. Not sure about the ViewAddress() function, never used it myself. I don't know if it is valid in an Intuition environment. I'd rather use GameWindow->WScreen->ViewPort.ColorMap. This way you get exactly the viewport which is used by your window and not the one which is used by the frontmost screen. Your game's screen could be put into the back by the user, then ViewAddress()->ViewPort will point to another screen.

Offline Thomas

Re: Pixel isn't drawn
« Reply #1 on: October 25, 2010, 04:36:35 PM »
In addition to what Piru said, you may not call ReleasePen after you have closed graphics.library.

Put ReleasePen to the beginning of your cleanup routine.

Smilarly ObtainBestPenA will crash if the window couldn't be opened. You should put ObtainBestPenA into the else branch of the "if (GameWindow == NULL)".

Offline Thomas

Re: Pixel isn't drawn
« Reply #2 on: October 25, 2010, 05:24:48 PM »
It should be SetAPen, not SetPen. There is also a B pen and an OL pen.

Also the = in if (blue = -1) should be ==. = is always an assignment and == is always a comparison. If you mix them up, strange things will happen.

Edit: you should also set result to an error code if the pen could not be obtained.