Help!
I actually have two issues to report the first concerns trying to use dbGetPixelsPointer or dbGetPixelsPitch. These don't seem to work without having first drawn to the screen canvas.
The second problem: after drawing to a created bitmap (e.g ID =1), then setting the current bitmap back to the screen, any "direct" drawing using dbGetPixelsPointer will draw to the bitmap and not the screen. The following code snippet illustrates both issues (and essentially the aqua line should not be visible!)
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
//Set screen
dbSetDisplayMode(800, 600, 32);
//First bug. Take out this line and the screen (bitmap) canvas is not initialised
//i.e. dbGetPixelsPitch and dbGetPixelsPointer will not work
//So this is a work around
dbCircle(1,1,1);
//Create a bitmap
int iWidth = dbScreenWidth();
int iHeight = dbScreenHeight();
dbCreateBitmap(1, iWidth-1, iHeight-1);
dbSetCurrentBitmap(1);
dbCLS();
//Draw orange circle on it
dbInk(0xFFFF9900, 0xFFFF9900);
dbCircle(40,40,20);
//Reset drawing output to screen
dbSetCurrentBitmap(0);
//Second bug. This is being drawn to the created bitmap ID = 1, not the screen. Why?
//Draw direct to canvas using dbGetPixelsPointer should be pointing at the screen bitmap.
DrawLineDirect(0xFF66FFFF, 0, iHeight-1, iWidth-1, 0);
while ( LoopGDK ( ) )
{
dbCLS();
dbCopyBitmap(1,0);
dbSync ( );
}
return;
}
Also, here is the code for my DrawLineDirect function and macros:
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define round(a, b) (((int)(pow(10.0f,b) * a + 0.5f)) / pow(10.0f,b))
void DrawLineDirect(int Colour, int x1, int z1, int x2, int z2)
{
//DECLARE
DWORD ptr = 0;
DWORD *pointer = 0;
int pixels_pitch = 0;
int bitmap_depth = 0;
//ASSIGN
ptr = dbGetPixelsPointer();
pixels_pitch = dbGetPixelsPitch();
bitmap_depth = dbBitmapDepth()/8;
if (pixels_pitch == 0)
return;
//y= mx + b
//m = (z2-z1)/(x2-x1)
float m = 0.0f;
if ((x2-x1) != 0)
m = ((float)z2-(float)z1)/((float)x2-(float)x1);
float b = (float)z1 - m*(float)x1;
int SWidth = dbScreenWidth();
int SHeight = dbScreenHeight();
int xHigh = min(max(x1,x2), SWidth-1);
int xLow = max(min(x1,x2), 0);
int zHigh = min(max(z1,z2), SHeight-1);
int zLow = max(min(z1,z2), 0);
dbLockPixels();
for (int x = xLow; x <= xHigh; x++)
{
int y = (int)round(m*x + b, 0);
if (y >= 0 && y < SHeight)
{
pointer = (DWORD *)(ptr + y * pixels_pitch + x * bitmap_depth);
*pointer = Colour;
}
}
for (int y = zLow; y <= zHigh; y++)
{
int x = x1;
if (m != 0)
x = (int)round((y-b)/m, 0);
if (x >= 0 && x < SWidth)
{
pointer = (DWORD *)(ptr + y * pixels_pitch + x * bitmap_depth);
*pointer = Colour;
}
}
dbUnLockPixels();
}
Thanks in advance and I hope there is something I am doing wrong rather than a bug.
Cheers.