Now that all the resources have been created, I can actually draw
something: A simple bouncing ball. It starts with the WM_PAINT
message: First I try to create all the DX resources, then update, and
finally show. If any of these steps fail, fall back to a simple GDI
fill.
MsgPaint():
int PxlShader::MsgPaint(void) {
int Err= ERR_OK;
PAINTSTRUCT Pnt;
GetClientRect(hWnd,&rWnd);
if(BeginPaint(hWnd,&Pnt)) {
if(IsErr(Err= DrawCreate())) {
Err= Warn(Err,"PxlShader:MsgPaint: DrawCreate() failed.");
} else if(IsErr(Err= DrawUpdate())) {
Err= Warn(Err,"PxlShader:MsgPaint: DrawUdpate() failed.");
} else if(IsErr(Err= DrawShow())) {
Err= Warn(Err,"PxlShader:MsgPaint: DrawPaint() failed.");
}
if(IsErr(Err)) {
// Fall back to GDI paint.
// If I see RED, it means DrawCreate(), DrawUpdate(), or DrawShow() failed.
HBRUSH hbrFill= CreateSolidBrush(RGB(255,0,0));
FillRect(Pnt.hdc,&Pnt.rcPaint,hbrFill);
DeleteObject(hbrFill);
}
EndPaint(hWnd,&Pnt);
}
ValidateRect(hWnd,0);
return(1);
}
I should now be able to watch the ball bounce around the
window smoothly. This provides the basic DirectX/Direct2D
framework for adding the pixel shader.
I want to make one change before moving on to the gory details of
IEffect. The obvious way to move the bouncing ball is to change the
center point of the ellipse. However, this means I will need to change
the coordinates of everything that is associated with the ball -- not
a concern right now, but it will complicate things down the road.
Instead, I will create a single Transform matrix, apply the movement
to the Transform once, and then let that transform apply automagically
to everything else. Now I can always draw the ball in the same
position, making the code much simpler and clearer.
Comments are moderated. Anonymous comments are not visible
to others until moderated. Comments are owned by the author but may be
removed or reused (but not modified) by this site at any time without notice.