Hi all,
anyone good at Tier 2 with C++ that could give me a quick hand?
I am trying to do a line by line conversion of an AGK2 program and am a bit stuck as it has been a loooong time since I have done any C stuff.
This is the AppGameKit code:
imgWidth = 1150
imgHeight = 800
drawImageScrNum = 1
drawImage = LoadImage ( "/media/pages/PIC1.png" )
fillImage = LoadImage ( "/media/pages/PIC1fill.png" )
memBlockcol = CreateMemblockFromImage ( drawImage )
memBlockfill = CreateMemblockFromImage ( fillImage )
DeleteImage (fillImage)
SetVirtualResolution( imgWidth, imgHeight )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate ( 60, 0 )
CreateSprite ( drawImageScrNum, drawImage )
SetSpritePosition ( drawImageScrNum, 0, 0 )
Sync ()
// ***** Main Game Loop *****
do
if GetPointerPressed()=1
mouseX = GetPointerX()
mouseY = GetPointerY()
// Waits for the pointer to be released before filling area so doesn't constantly fill
while GetPointerReleased()=0
Sync()
endwhile
// Checks pointer is in the main screen area to fill picture
if mouseX >= 0 and mouseX <= imgWidth and mouseY >= 0 and mouseY <= imgHeight
pixelcheck = GetPixel ( memBlockfill, mouseX, mouseY, imgWidth )
if pixelcheck <> 0
red = Random(1, 255)
green = Random(1, 255)
blue = Random(1, 255)
alpha = 255
nRGB = red + (green << 8) + (blue << 16) + (alpha << 24)
//SetSpriteColor(drawImageScrNum,red,green,blue,alpha)
FloodFill ( memBlockfill, memBlockcol, mouseX, mouseY, imgWidth, imgHeight, nRGB, pixelcheck )
DeleteImage(fillImage)
fillImage = CreateImageFromMemblock( memBlockcol )
SetSpriteImage ( drawImageScrNum, fillImage )
endif
endif
endif
Print(pixelcheck)
Sync()
loop
// ******************** Functions **********************
// function to obtain colour value (RGBA)
function GetPixel ( memBlock, x, y, width )
offsetPixel = 12 + (( x + ( y * width )) * 4 )
PixelColourRGB = GetMemBlockByte ( memBlock, offsetPixel )
endfunction PixelColourRGB
// Function to fill area with colour inside the memblock
function FloodFill ( memBlockSRC, memBlockOUT, x, y, width, height, nRGB, pixelcheck )
starth = 1: startw = 1: heightend = height : widthend = width
for rows = starth to heightend
RowAddress= 12 + ((( rows-1) * width )*4)
for columns = startw to widthend
offsetPixel = RowAddress + ((columns-1) * 4 )
if GetMemBlockByte ( memBlockSRC, offsetPixel ) = pixelcheck
//offsetPixel = RowAddress + ((columns-1) * 4 )
SetMemblockInt( memBlockOUT, offsetPixel, nRGB )
endif
next columns
next rows
endfunction
This is what I have done in C++ so far but is not correct because of the function calls which I know wont work like they are, I just cut and pasted to convert.
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
unsigned int drawImageScrNum;
unsigned int drawImage;
unsigned int fillImage;
unsigned int memBlockcol;
unsigned int memBlockfill;
int mouseX;
int mouseY;
int red;
int green;
int blue;
int alpha;
int nRGB;
void app::Begin(void)
{
agk::SetVirtualResolution (1150, 800);
agk::SetClearColor( 151,170,204 );
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
drawImageScrNum = 1;
drawImage = agk::LoadImage ("/media/pages/pic1.png");
fillImage = agk::LoadImage ("/media/pages/pic1fill.png");
memBlockcol = agk::CreateMemblockFromImage (drawImage);
memBlockfill = agk::CreateMemblockFromImage (fillImage);
agk::DeleteImage (fillImage);
agk::CreateSprite ( drawImageScrNum, drawImage );
agk::SetSpritePosition ( drawImageScrNum, 0, 0 );
agk::Sync ();
}
void app::Loop (void)
{
if ( agk::GetPointerPressed()==1 ) {
mouseX = agk::GetPointerX();
mouseY = agk::GetPointerY();
do
{
agk::Sync()
}while (agk::GetPointerReleased()==0);
if ( mouseX >= 0 && mouseX <= imgWidth && mouseY >= 0 && mouseY <= imgHeight ) {
pixelcheck = GetPixel ( memBlockfill, mouseX, mouseY, imgWidth );
if ( pixelcheck <> 0 ) {
red = agk::Random(1, 255);
green = agk::Random(1, 255);
blue = agk::Random(1, 255);
alpha = 255;
nRGB = agk::MakeColor(red,green,blue);
FloodFill ( memBlockfill, memBlockcol, mouseX, mouseY, imgWidth, imgHeight, nRGB, pixelcheck );
agk::DeleteImage(fillImage);
fillImage = agk::CreateImageFromMemblock( memBlockcol );
agk::SetSpriteImage ( drawImageScrNum, fillImage );
}
}
}
agk::Print(pixelcheck);
agk::Sync();
}
void app::End (void)
{
}
These are the 2 functions I am trying to add, I guess I will have to try and put them in a class however I can't remember how to do it!
function GetPixel ( memBlock, x, y, width )
offsetPixel = 12 + (( x + ( y * width )) * 4 )
PixelColourRGB = GetMemBlockByte ( memBlock, offsetPixel )
endfunction PixelColourRGB
function FloodFill ( memBlockSRC, memBlockOUT, x, y, width, height, nRGB, pixelcheck )
starth = 1: startw = 1: heightend = height : widthend = width
for rows = starth to heightend
RowAddress= 12 + ((( rows-1) * width )*4)
for columns = startw to widthend
offsetPixel = RowAddress + ((columns-1) * 4 )
if GetMemBlockByte ( memBlockSRC, offsetPixel ) = pixelcheck
//offsetPixel = RowAddress + ((columns-1) * 4 )
SetMemblockInt( memBlockOUT, offsetPixel, nRGB )
endif
next columns
next rows
endfunction
Oh and by the way my images won't load in either to display a sprite as it just has the square box image.
Thanks if you can help.
Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C C++ / now also AGK2! - Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga - Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles