What is wrong with this function?
I know that we aren't going to include this, but for my own edification and enlightenment, I would like to know what I did wrongly here, as it doesn't seem to be pulling the user bitmap, and blitting it; or if it is, then there is something clearly broken.
Code:
//Bitmap Quad()
void do_bmpdrawquadr(BITMAP *bmp, int *sdci, int xoffset, int yoffset)
{
//sdci[1] = layer
int x1 = sdci[2]/10000; //vectorset x1[]
int y1 = sdci[3]/10000; //y1[]
int x2 = sdci[4]/10000; //x2[]
int y2 = sdci[5]/10000; //y2[]
int x3 = sdci[6]/10000; //x3[]
int y3 = sdci[7]/10000; //y3[]
int x4 = sdci[8]/10000; //x4[]
int y4 = sdci[9]/10000; //y4[]
int w = sdci[10]/10000; //w arg, used in vectorsey
int h = sdci[11]/10000; // ... h ; otherwise hardcoded to 256
int color = sdci[12]/10000; //not used
int flip=(sdci[13]/10000)&3; //not used
int bitmapIndex = sdci[14]/10000; //the user bitmap ID.
int polytype = sdci[15]/10000; //render mode
//sdci 16 and 17 reserved and set in globalsymbols as TYPE_FLOAT
//Grab the user bitmap from sdci[14]
BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
//if that bitmap is invalid, exit
if(!sourceBitmap)
{
Z_message("Warning: Screen->DrawBitmapQuad(%d) contains invalid data or is not initialized.\n", bitmapIndex);
Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
return;
}
//make a bitmap pointer and try to get a subbitmap
BITMAP* subBmp = script_drawing_commands.AquireSubBitmap(256, 256);
//Safety net
bool mustDestroyBmp = false;
//if we couldn't grab an available sub bitmap, make one, and clear it.
if(!subBmp)
{
mustDestroyBmp = true;
subBmp = create_bitmap_ex(8, 256, 256);
clear_bitmap(subBmp);
}
//blit the user bitmap to the sub bitmap
masked_stretch_blit(sourceBitmap, subBmp, 0, 0, 256, 256, 0, 0, 256, 256);
//populate the vectors
V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, 0 };
V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), 0 };
V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h),0 };
V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, 0 };
//log the event
Z_message("BitmapQuad() : Trying to draw Bitmap ID", bitmapIndex);
// Draw the quad using the sub bitmap as the render source, to the screen 'bmp'
quad3d_f(bmp, polytype, subBmp, &V1, &V2, &V3, &V4);
//if we created a new bitmap, purge it
if ( mustDestroyBmp )
destroy_bitmap(subBmp);
} //end
This is the ZScript code that I used to call it:
Code:
import "std.zh"
global script q{
void run(){
//Arrays for the vector sets of BitmapQuad()
int x[4] = {0, 255, 0, 255};
int y[4] = {0, 0, 175, 175};
int t; //A variable to modify with user input.
int a = RT_BITMAP1; //To display the ID, or to allow changing it.
while(true){
//Allow user input to change the shape of our quad.
if(Link->PressL)
t = (t+1)%4;
if(Link->InputUp)
y[t]--;
else if(Link->InputDown)
y[t]++;
else if(Link->InputLeft)
x[t]--;
else if(Link->InputRight)
x[t]++;
if ( Link->PressEx2 ) a = vbound(a-1, 0, 5);
if ( Link->PressEx1 ) a = vbound(a+1, 0, 5);
//Render to user bitmap RT_BITMAP1
Screen->SetRenderTarget(a);
//Draw a screen with tiles on it to the user bitmap
Screen->DrawScreen(0, 1, 0, 0, 0, 0);
//Change the rendering back to the screen.
Screen->SetRenderTarget(RT_SCREEN);
//Draw the quad.
Screen->BitmapQuad(6, x[0], y[0], x[1], y[1], x[2], y[2], x[3], y[3], 512, 512, 0, 0, a, PT_PTEXTURE,0,0);
//Draw the bitmap target ID to the screen as a reminder.
Screen->DrawInteger(7, 50, 0, 0, 1, 0, 0, 0, a, 0, 128);
Waitdraw();
Waitframe();
}
}
}
It draws a quad with a single colour shade, not the texture of the drawscreen, grabbed from the user bitmap.
It is important to me to know why it doesn't work, and more than this, to ensure that it won;t be a problem with our future bitmap enqueuing.