Thread: [OpenGL] Best approach to setting every pixel's color

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    [OpenGL] Best approach to setting every pixel's color

    I'm working on a 2D surface, where n kinds of lighting spheres move along with my mouse. Every pixel's color got to be calculated per movement, since it is obtained by the distance between the pixel and all of the sphere's centers. This way, I have n * width * height calculations per frame, and that's a lot of work when trying to reach 60 fps with a 1024x768 resolution and with n = 3 or so.

    I want to know the fastest (doesn't mean the easiest) way to do such thing in OpenGL.

    Thanks

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Antony Kossoski View Post
    I want to know the fastest (doesn't mean the easiest) way to do such thing in OpenGL.
    Write a fragment shader in glsl.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Any time you need to touch texels or pixels you should do so in a shader regardless if you using Direct3D or OpenGL. Doing this in any other place is going to impact performance. Note that although shaders are blazing fast you can slow them down by adding texel fetches when they are not needed.

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    5
    Thank you both for the answers.

    Because I want the pixels to be update per mouse movement, shoud I declare 2 uniform variables (x, y) in my fragment shader and update them every frame with glUniform...?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. setting a single pixel
    By megafiddle in forum Windows Programming
    Replies: 8
    Last Post: 03-24-2011, 10:38 AM
  2. reading color of pixel
    By wannabe723 in forum C++ Programming
    Replies: 8
    Last Post: 01-01-2009, 07:40 PM
  3. Get the color of a pixel
    By maxorator in forum Windows Programming
    Replies: 5
    Last Post: 09-06-2006, 07:08 PM
  4. Extracting color from 32-bit pixel...
    By Cheeze-It in forum Game Programming
    Replies: 6
    Last Post: 07-31-2005, 07:53 AM
  5. Changing pixel color
    By jwhitaker3 in forum C Programming
    Replies: 1
    Last Post: 01-28-2003, 09:46 AM