Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Drawing Lines in DirectDraw


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 November 1999 - 01:01 PM

Hello everybody. I have a teensy little
question.

In DirectDraw I am writing a dodgy asteroids
clone. Now what I need is the ability to
draw straight lines, even quickly if possible.

Does Direct-X supply primitives?
How else could I do it? GDI?

I have little windows programming experience,
but if it's there's no quick way availble I
can always do a port of my DOS code.


Sponsor:

#2 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 November 1999 - 12:22 AM

DirectDraw doesn't support line drawing... Check CGPP or preferably Abrash' black book of graphics programming for a really fast line drawing algorithm (it also has a fast one for antialiased lines)...

/Niels


#3 Machaira   Moderators   -  Reputation: 1028

Like
Likes
Like

Posted 05 November 1999 - 03:15 AM

You can draw your own lines by plotting pixels on a surface. I can dig up some functions if you need them, but at least 3 books I've seen on DirectX go into this.

#4 Cruxis   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 November 1999 - 03:35 AM

Well. You want to draw lines.
And you have access to D3DIM?

Use DrawPrimitive with the LINE function.

If you dont have the D3DIM ( which you should have, its very simple to do lines with it ) , you either lock the surface
down and pixel it. Or you use the the GDI.

Locking the surface down and using a line
drawing routine would be the best if you
dont use D3DIM.



#5 Matthew Allen   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 November 1999 - 03:48 AM

Well, I hope this helps some. It just draws a straight vertical line. Pretty uselesse, but its just a few lines of code away from what you want

//--------------------------------------------------------------------------------------------
// Draw_VLine()
//--------------------------------------------------------------------------------------------
BOOL Draw_VLine( LPDIRECTDRAWSURFACE4 lpDDSTemp, int x, int y, int y2, WORD rgbColor )
{
int index;
WORD *wPixels;
DDSURFACEDESC2 ddsd;

ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );

if ( FAILED (lpDDSTemp->Lock( NULL, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL ) ) )
return Error( "> Error: Couldn't lock the Temp surface.\n> Function: Draw_Pixel().\n", DEBUG );

wPixels = ( WORD * )ddsd.lpSurface;

for ( index = 0; index <= ( y2 - y ); index++ )
wPixels[( y + index ) * ( ddsd.lPitch >> 1 ) + x] = rgbColor;

if ( FAILED (lpDDSTemp->Unlock( NULL ) ) )
return Error( "> Error: Couldn't unlock the Temp surface.\n> Function: Draw_Pixel().\n", DEBUG );

return TRUE;
}

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/


#6 Reaver   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 November 1999 - 01:53 PM

Here's some more! line drawing routines. Even though these are not written in
assembly, they might actually be faster than ones written in assembly if
you have VC++6.0 and optimizations turned on.

Don't ask me why this is faster, I guess MSVC++ can write better
assembly than me.

The locking/unlocking of the surface is done outside the function, so
you can use them several times if you need to draw more than one line, like
a rectangle. surface_buffer is your pointer to the DD surface. Oh yeah,
these were written for 16-bit color.

But, if you want to speed it up even more, just move everything
into one function.

code:

//
// Draw a horizontal line (dy=0) from left to right.
//
void
Draw_Primitive_HLine_No_Clip(INT width, WORD color, WORD *surface_buffer) {

while(width--) {

// set the color and advance one pixel
*surface_buffer++ = color;
}
}


code:

//
// Draw a vertical line (dx=0) from top to bottom.
//
void
Draw_Primitive_VLine_No_Clip(INT height, WORD color, WORD *surface_buffer, DWORD pitch) {

while(height--) {

// set the pixel
*surface_buffer = color;

// move to the next scanline pixel
surface_buffer += pitch;
}
}



Reaver

[This message has been edited by Reaver (edited November 05, 1999).]


#7 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 November 1999 - 01:01 PM

Personally, I wouldn't trust the VC optimizer, I got a double up in speed by handcoding a few inner loops (compared to optimized C++), and I'm NOT a Ix86 ASM wizard.

And I still recommend reading Abrash' black book - He starts out with plain Bresenhams line drawing, covers "run-length slice drawing", and ends up antialiasing it... Check it out - that book can not be recommended enough !

/Niels





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS