Jump to content
  • Advertisement


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


Asm horizontal line

This topic is 6195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I''m trying to write a very fast polygon procedure to my 3d engine. It takes four 2D points and write the X distance on the PolyBuffer array for each Y of polygon. So I get these values and write directly to a DirectDrawSurface (Outp), 16 bits color. A buffer of Y values of screen is made on engine initialization, the ScanWidth. (for c:=0 to 239 do ScanWidth[c] := (TheSurfaceDesc.lPitch*c) TheSurfaceDesc.dwSize:=SizeOf(TDDSurfaceDesc); Outp.IDDSurface4.Lock(nil,TheSurfaceDesc,DDLOCK_SURFACEMEMORYPTR+DDLOCK_WAIT,0); for counter := Ymin to Ymax do begin XA := PolyBuffer[counter,1]; XB := PolyBuffer[counter,2]; I := ScanWidth[counter] + (XA shl 1); while XA < XB do begin PWord(integer(TheSurfaceDesc.lpsurface)+I)^ := color; I := I+2; Inc(XA); end; end; Outp.IDDSurface4.Unlock(TheSurfaceDesc.lpSurface); Works fast and ok, but when a Y value of polygon are negative the screen make weird effects, like drawing one line yes and one no. When the a X of polygon value are negative the computer lock. Is this the right way to draw a horizontal line??? I tryied to alter the well know PixelCore''s function PutPixel16 without success procedure PutPixel16(x,y,color : integer); { on entry: x = eax, y = edx, color = ecx } asm push esi mov esi,TheSurfaceDesc.lpSurface shl eax,1 add esi,eax // description similar to PutPixel8 mov eax,[TheSurfaceDesc.lpitch] mul edx add esi,eax mov ds:[esi],cx pop esi ret end; Anyone knows how to code a horizontal line function in assembly, with the optimization of ScanWidth buffer or know how to make my function work??? Thanks guys, all helps and ideas will be welcome!!! Till the next! =)

Share this post

Link to post
Share on other sites
inline void hline_asm(int x1, int x2, int y, char c)
mov edi,dword ptr[VidMem];
add edi,dword ptr[x1];
mov ecx,dword ptr[x2];
sub ecx,dword ptr[x1];
mov eax, dword ptr[y];
mul dword ptr[Width];
add edi,eax;
mov al,byte ptr[c];
mov [edi],al;
inc edi;
dec cx;
jnz L1;

This is my 8 BPP horizontal line drawer. It''s reasonably fast, and it could probably be adapted to 16 BPP fairly easily.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!