We are developing a historical strategy game and want to use some shading on some part of the map to write text on it (general names, messages, etc). You can check it at: http://www.48.hu (it is in Hungarian, but you can have a look at the screens - Letoltes section). - We are not yet ready financially to employ someone with DirectX experience to do the engine, so we are trying to build it ourselves (us means a Delphi programmer plus me, we are fine with Delphi but very little experience in DirectX).

We use Delphix and Delphi 5.0. We also use TurboPixels from turbo.gamedev.net

Our shading routine (darkens a rectangular area) looks like this:

procedure TGamesForm.Arnyek(kx, ky, vx, vy: integer);
var i,j:integer;
color:cardinal;
begin
turbolock(DXDraw.Surface);
for i:=kx to kx+vx do begin
for j:=ky to ky+vy do begin
color:=turbogetpixel16(i,j);
turboSetPixel16rgb(i,j, r16(color) div 2, g16(color) div 2, b16(color) div 2);
end;
end;
end;
turbounlock;
end;

R16, G16 and B16 calculate the RGB colors individually.
It looks very nice, but unfortunately it also results a BIG framerate hit. We tried to replace the content of the inner loop with this:

if (i+j) mod 2 =0 then begin
turboSetPixel16RGB(i,j, R_ARNYEK, G_ARNYEK, B_ARNYEK);

This also achieves shading without a significant framerate hit by drawing the color ARNYEK on every other pixel. However this is MUCH uglier.

It seems that what slows us down is turbogetpixel16:

function turboGetPixel16(const x, y: Integer): cardinal;
begin
result := 0;
if (X < 0) or (X > xmax) or // Clip to DelphiX Surface
(Y < 0) or (Y > ymax) then Exit;
result := pword(integer(LockedSurfaceDesc.lpsurface) + // surface pointer
y * LockedSurfaceDesc.lpitch + x * 2)^;
end;

Is there any way to speed this up?

I read a lot of threads on this forum, but did not get much closer. I tried to change our DxDraw surface to system memory, but that resulted in an even worse framerate hit.

And some other questions:
1. How easy would it be to transfer our project to PowerDraw and what would be the benefits?
2. We use the procedure textout for the text functions (seems good enough so far). Would it be much faster to use a bitmap font and TurboPixel (or some other tool)?


Thanks,

BlackVoid (Bulcsu Varhegyi)
Designer/Developer
HydroGame