Results 1 to 3 of 3

Thread: Examing pixels in 2D openGL game

  1. #1
    Member Newbie
    Join Date
    Jul 2006
    Posts
    39

    Examing pixels in 2D openGL game

    I am working on a 2D game & using openGL with ortho view . I have these sprites which i display as textured quads. However some of these images i need to examine pixel by pixel looking for a specific color.Then instead of this color i put the appropriate 'Player Color' of the unit i am putting on screen. Imagine i have colors numbered from 0 to 255.
    Then i have this special color 255 which when found in a pixel always results in the appropriate player color(say red/green/yellow for 3 players...which might be say the color 24/145/234 respec) being put in the frame buffer instead of the original pixel color. So basically i cant bind the texture right away. I need to EXAMINE EACH PIXELS & PUT THEM ON THE QUAD PIXEL BY PIXEL replacing the pixels color in the image with player color whereever a 255(indication of player color) is found.
    But is this possible. What is the most fastest &most efficient way of doing this ? Could i simply write to a texture or something which i heard openGL can do. One thing is certain i need to access the pixels in a for-loop & write them out again...how hard will my frame rate be hit? i heard glDrawPixels() is slow...i need a fast method or maybe some sort of mask whatever

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Examing pixels in 2D openGL game

    What is the most fastest &most efficient way of doing this ?
    On the CPU.

    Pixel-perfect collision detection is best not done on the GPU. The round-trip travel time from CPU-to-GPU-to-CPU is far more than just doing it in software.

  3. #3
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Examing pixels in 2D openGL game

    A solution that comes to my mind is to use aplha-blending. You can define alpha of your '255' pixels to be 0 with the rest of the pixels using alpha of 255. You then bind a second texture (just solid color) and set the combiners to alpha blend. This way you will aotomatically get your result. Or, you can also use the alpha function and do it in two pass.

Similar Threads

  1. OpenGL's Suitability for drawing pixels yourself
    By galaxies in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-26-2015, 09:13 PM
  2. How does OpenGL rasterize pixels?
    By shapeare in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-11-2012, 01:01 AM
  3. How to draw pixels in OpenGL ES 2.0
    By JasonBecker in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-23-2010, 09:09 AM
  4. opengl coordinates to pixels
    By Hylke Donker in forum OpenGL: General
    Replies: 2
    Last Post: 10-20-2004, 10:00 AM
  5. Get the pixels from the OpenGL context.
    By huangzl99 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-16-2002, 01:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean