Jump to content

2.3 DrawLine


Chris Paulson
 Share

Recommended Posts

My function: -

void tdDraw( TCamera cam, TVec3 s, TVec3 e )
{
TVec3 p1;
TVec3 p2;
p1 = CameraUnproject( cam, s );
p2 = CameraUnproject( cam, e );

if (p1.Z < 0 || p2.Z < 0) return;

DrawLine( p1.X, p1.Y, p2.X-p1.X, p2.Y-p1.Y );
}

 

 

Seems not to work correctly anymore, one end of the line seems to be in the correct place but the other is always top left.

 

Has it changed?

Link to comment
Share on other sites

Yes, it now takes the absolute coordinates X1 Y1 and X2 Y2, each pair is its own endpoint.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

If you are using C++, you might consider using gamelib's Line function instead, as it's about 10 times faster than LE's DrawLine:

inline void Color(double r, double g, double b, double a)
{
glColor4f(r,g,b,a);
}

inline void Line(int x, int y, int w, int h)
{
glBegin(GL_LINES);
glVertex2i(x,y);
if(0==w)w=1;
glVertex2i(x+w,y+h);
glEnd();
}

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Yeah, it's just a simple direct mode OpenGL command after all, but when it's called often, like in speed tests, the fact that the DLL call has to go through many more instructions (BlitzMax GC, C headers) than a C++ inline function (which is stored directly into the loop, not even calling the function internally (thus avoiding the stack, which is slow)), sums up in the speed difference.

 

Sure it's not a bottleneck, as nobody would call thousands of DrawLines per frame :)

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...