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

This is a discussion on [OpenGL] Best approach to setting every pixel's color within the Game Programming forums, part of the General Programming Boards category; I'm working on a 2D surface, where n kinds of lighting spheres move along with my mouse. 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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,499
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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, 11: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, 08:08 PM
  4. Extracting color from 32-bit pixel...
    By Cheeze-It in forum Game Programming
    Replies: 6
    Last Post: 07-31-2005, 08:53 AM
  5. Changing pixel color
    By jwhitaker3 in forum C Programming
    Replies: 1
    Last Post: 01-28-2003, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21