Archived

This topic is now archived and is closed to further replies.

chlupp2000

DirectDraw Pixel Manipulation

Recommended Posts

chlupp2000    122
Hello! I have nearly all tried to get this thing working, but now I don''t know what to do. I am not able to manipulate a single pixel from a DirectDraw Surface. Here''s my code:
ddsd: TDDSurfaceDesc2;
Primary: IDirectDrawSurface7;
X,Y: Integer;

Primary.GetSurfaceDesc(ddsd);
if Primary.Lock(nil,ddsd, DDLOCK_SURFACEMEMORYPTR or DDLOCK_WAIT,0) = DD_OK then
  begin
    try
      begin
        for x:=0 to 1023 do
        begin
          for y:=0 to 767 do
          begin
            PByte(Integer(ddsd.lpSurface)+Y*ddsd.lpitch+X)^:= RGB(50,50,50);
          end;
        end;
      end;
    finally
      Primary.Unlock(nil);
    end;
  end;
 
Maybe someone can help me (and post his code)? thanks chlupp Starbyte Developments

Share this post


Link to post
Share on other sites
turbo    115
Try using...


pdword(integer(LockedSurfaceDesc.lpsurface) + // surface pointer
y * LockedSurfaceDesc.lpitch + x * 3)^ :=
(r shl 16) or (g shl 8) or b; // Could use RGB(r,g,b)
end;


Since RGB values are DWORDS not bytes. You also may have some locking issues. I use...


LockedRect := Rect(0, 0, LockedSurfaceDesc.dwWidth, LockedSurfaceDesc.dwHeight);
if LockedSurface.Lock(@LockedRect, LockedSurfaceDesc, DDLOCK_SURFACEMEMORYPTR + DDLOCK_WAIT,0) <> DD_OK then // etc...


but there are many ways to skin a cat

Share this post


Link to post
Share on other sites
LoreKeeper    152
Try looking at the Pixel code in TurboPixel or PixelCore... although they are mostly DelphiX related, the code still applies to the general case. And those pixel routines are still faster then the code above.

Share this post


Link to post
Share on other sites