Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:01:28+00:00 2026-05-11T08:01:28+00:00

Background: I’m using the SlimDX C# wrapper for DirectX, and am drawing many 2D

  • 0

Background: I’m using the SlimDX C# wrapper for DirectX, and am drawing many 2D sprites using the Sprite class (traditionally from the Direct3DX extension in the underlying dlls). I’m drawing multiple hundreds of sprites to the screen at once, and the performance is awesome — on my quad core, it’s using something like 3-6% of the processor for my entire game, including logic for 10,000+ objects, ai routines on a second thread, etc, etc. So clearly the sprites are being drawing using full hardware acceleration, and everything is as it should be.

Issue: The problem comes when I start introducing calls to the Line class. As soon as I draw 4 lines (for a drag selection box), processor usage skyrockets to 13-19%. This is with only four lines!

Things I have tried:

  1. Turning line antialiasing off and on.
  2. Turning GLLines off and on.
  3. Manually calling the line.begin and line.end around my calls to draw.
  4. Omitting all calls to line.begin and line.end.
  5. Ensuring that my calls to line.draw are not inside a sprite.begin / sprite.end block.
  6. Calling line.draw inside a sprite.begin / sprite.end block.
  7. Rendering 4 lines, or rendering 300.
  8. Turning off all sprite and text rendering, and just leaving the line rendering for 4 lines (to see if this was some sort of mode-changing issue).
  9. Most combinations of the above.

In general, none of these had a significant impact on performance. #3 reduced processor usage by maybe 2%, but even then it’s still 8% or more higher than it should be. The strangest thing is that #7 from above had absolutely zero impact on performance — it was just as slow with 4 lines as it was with 300. The only thing that I can figure is that this is being run in software for some reason, and/or that it is causing the graphics card to continually switch back and forth between some sort of drawing modes.

Matrix Approach:

If anyone knows of any fix to the above issue, then I’d love to hear it!

But I’m under the assumption that this might just be an issue inside of directx in general, so I’ve been pursuing another route — making my own sprite-based line. Essentially, I’ve got a 1px white image, and I’m using the diffuse color and transforms to draw the lines. This works, performance-wise — drawing 300 of the ‘lines’ like this puts me in the 3-6% processor utilization performance range that I’m looking for on my quad core.

I have two problems with my pixel-stretch line technique, which I’m hoping that someone more knowledgeable about transforms can help me with. Here’s my current code for a horizontal line:

    public void DrawLineHorizontal( int X1, int X2, int Y, float HalfHeight, Color Color )     {         float width = ( X2 - X1 ) / 2.0f;         Matrix m = Matrix.Transformation2D( new Vector2( X1 + width, Y ), 0f, new Vector2( width, HalfHeight ),             Vector2.Zero, 0, Vector2.Zero );         sprite.Transform = m;          sprite.Draw( this.tx, Vector3.Zero, new Vector3( X1 + width, Y, 0 ), Color );     } 

This works, insofar as it draws lines of mostly the right size at mostly the right location on the screen. However, things appear shifted to the right, which is strange. I’m not quite sure if my matrix approach is right at all: I just want to scale a 1×1 sprite by some amount of pixels horizontally, and a different amount vertically. Then I need to be able to position them — by the center point is fine, and I think that’s what I’ll have to do, but if I could position it by upper-left that would be even better. This seems like a simple problem, but my knowledge of matrices is pretty weak.

This would get purely-horizontal and purely-vertical lines working for me, which is most of the battle. I could live with just that, and use some other sort of graphic in locations which I am currently using angled lines. But it would be really nice if there was a way for me to draw lines that are angled using this stretched-pixel approach. In other words, draw a line from 1,1 to 7,19, for instance. With matrix rotation, etc, it seems like this is feasible, but I don’t know where to even begin other than guessing and checking, which would take forever.

Any and all help is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:01:29+00:00Added an answer on May 11, 2026 at 8:01 am

    it sounds like a pipeline stall. You’re switching some mode between rendering sprites and rendering lines, that forces the graphics card to empty its pipeline before starting with the new primitive.

    Before you added the lines, were those sprites all you rendered, or were there other elements on-screen, using other modes already?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 184k
  • Answers 184k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I solved My Own Question isnt that good? $changed =… May 12, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer You probably want to look into signals: http://docs.djangoproject.com/en/dev/topics/signals/ In particular,… May 12, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer The startup script is bin/run.bat JBoss doesn't need installing, just… May 12, 2026 at 4:45 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
Background: I have a little video playing app with a UI inspired by the
Background: I need to reserve an amount of memory below 0xA0000 prior to my
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background I have a massive db for a SharePoint site collection. It is 130GB

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.