@SiPlus-legacy (SiPlus) posted a new topic, subject "Drawing pixels". It read:

   Is there any fast way of drawing individual pixels on HUD in GMod? surface.DrawRect and surface.DrawLine are bad for that, because they create 2 polygons for each rectange/line, so even a small screen makes the game unbearably slow.

So @Chessnut-legacy (Chessnut) replied

    You shouldn't really draw pixels, they will impact your performance.  
    Those two mentioned seem like the only way.

So @SiPlus-legacy (SiPlus) replied

    Chessnut:
    
    > they will impact your performance.
    
    But textures don't really impact performance.

Then @CG_Scavenger-legacy (CG Scavenger) said

    Well ya textures wont be as bad but i think you might have mis-phrased your question. Are you asking how to draw a texture from like a vtf to the screen or individually drawing each pixel to make like 8-bit graphics? The later will not be good for performance.

Then @CmdrMatthew-legacy (CmdrMatthew) said

    The problem with what you want is it has to be done on the CPU. This makes it inherently slow, as it has to interface with the graphics card all the time for every pixel, every frame. To draw a 100x100 pixel image, it would have to tell the graphics card to draw 10,000 pixels individually or change the texture data on the graphics memory.
    
    The reason textures do not lag is because they are loaded into the graphics card memory once, then they are simply mapped onto the triangles with texture coordinates. Then they are drawn on a pixel by pixel basis in a pixel shader, a relatively fast process. Pixel shaders present a relatively constant overhead as they always have to do the same amount of work each frame, independent of the vertex count.
    
    The DrawRect function is slow because it is telling the graphics card to draw X _Y_ 2 triangles every single frame. First it has to send all that data and tell the graphics card to draw it, then the vertex shader has to process each and every one to map it to the pixel coordinates and such.
    
    Isn't this fun stuff?  
    [img_thumb]http://user.xmission.com/~legalize/book/preview/poster/pipeline-9.0.png[/img_thumb]

After which, @SiPlus-legacy (SiPlus) added

    Is it possible to set pixel colors using HLSL and material properties, and then drawing the material using DrawTextudredRect?

After which, @CmdrMatthew-legacy (CmdrMatthew) added

    You can't set pixel colors of textures using HLSL, all it can do is read them, but you may be able to edit the texture through the material system and draw it as you would any other texture.


{'source': 'discourse', 'url': 'https://forum.facepunch.com/t/drawing-pixels/102401', 'title': 'Drawing pixels', 'views': 822, 'has_accepted_answer': False, 'word_count': 401, 'like_count': 0, 'reply_count': 6, 'participant_count': 4, 'posts': 7, 'tags': '', 'author': '@SiPlus-legacy (SiPlus)', 'participants': '@SiPlus-legacy (SiPlus), @Chessnut-legacy (Chessnut), @CG_Scavenger-legacy (CG Scavenger), @CmdrMatthew-legacy (CmdrMatthew)', 'image_url': [None], 'created_at': '2012-02-29T11:33:23.000Z', 'last_posted_at': '2012-03-01T13:05:18.000Z'}