Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Drawing a grid of pixels on a 2D screen

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2015

    Question Drawing a grid of pixels on a 2D screen

    I have a 2D situation:

    gDC:=GetDC(Handle); {Windows handle}

    Now I want to draw a grid of pixels on the screen. I already read that GL_POINTS would be rather slow for setting pixels. If I have a FullHD window and every 3rd pixel is set, I have to draw 230,000 pixel actions. Quite a lot

    In reality the pixel pitch is not every 3rd pixel but let's say every 3.258th pixel. Has anyone got an idea for a better solution?

    Thanks, Bernd

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Several options spring to mind:

    1. Draw a screen-sized quad with a fragment shader which tests gl_FragCoord.
    2. Draw full-height vertical lines every 3.258 pixels in the X direction, and full-width horizontal lines every 3.258 pixels in the Y direction, the latter using glLogicOp(GL_AND) (or blending, or stencilling).
    3. Generate a 1920x1 texture and a 1x1080 texture containing the correct patterns, and draw a pair of screen-sized quads, each stretching the texture in one direction, the latter using glLogicOp(GL_AND) (or blending, or stencilling or multi-texture).
    4. Create a 2x2 chequerboard texture, draw 4 screen-sized quads with the appropriate scaling, with and without 1-pixel offsets in each direction. Use logical/stencil/multi-texture operations to ensure that only the correct pixels are affected (I can't be bothered figuring out the details right now).

    Option #1 is probably the simplest approach (it doesn't require that you start with a blank screen, or use additional buffers), but requires an OpenGL version which supports shaders.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2015
    Hi GClements,

    thanks for your 4 suggestions None of them sounds really easy. I tested and found out that drawing 230,000 GL_POINTS is rather quick, though. I have not been working with shaders, stencils and textures yet. So I will leave it the way it is for the moment.

    Coming from GDI it is not that easy to get used to OpenGL. Thanks for your help and time. I see that shaders, stencils and textures are very powerful features. I will get back to them.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts