Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to draw a screen composed of rectangular colored pixels ?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    3

    How to draw a screen composed of rectangular colored pixels ?

    Hello,

    In an emulator project, I would like to draw a "screen" composed of rectangular colored pixels (around 300x200 or perhaps more).

    I see two options:

    Option1:
    Draw a set of colored quads.

    Option 2:
    Draw one textured quad and modify the texture pixels when needed.

    Which one is the best ?

    I have implemented option 1 and it works well.
    But with this option, each pixel (quad) has:
    - 4 * vec4 for the position;
    - 4 times the same color.
    Which is a lot for this simple object.

    From the application side, the API should be something like:
    setPixel(int x, int y, color).

    Do you think it is possible for the vertex shader, to generate the quad, based only on x, y and color, supposing it has the "screen layout info" ?

    What do you think ?

    Thanks,

    Olivier

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,146
    The Option 2 is simpler to implement and is faster AFAIK. Updating a small portion of a texture with glTexSubImage2D() is immensely fast. You could just call it in setPixel() defining offsets with x and y, and content with color.

    You could also generate quads (or better triangle strips) using gl_VertexID, without need to send attributes for each one. But, there is no need for that. The previous solution is much simpler.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    3
    Thanks for your reply. I will test option 2 ! By the way, is option 2 can run efficiently on recent Android devices ?
    Thanks.

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,146
    I have no experience with Android platforms, but on desktops it works fine.
    And, of course, I hope you will not call 6000 times glTexSubImage2D() in each draw-call. Just when some "pixel" has changed its color.
    Also, try to group multiple "pixels" and substitute it with a single
    glTexSubImage2D() per draw-call.

Posting Permissions

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