Jump to content
  • Advertisement
Sign in to follow this  
sassa

OpenGL invert colors

This topic is 4909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I'm new in opengl and in this forum... is it possible to define a color that for the next shape drawed its color is the inverse of background color??? what I wanna do is: I have a list of objects. The user draw the objects whith the mouse(click and drag) e.g. a rectangle. What may I put on the mouseMove function?? I was intending to draw the rectangle inverting the colors of the background... at the next time the moseMove execute it draw again the rectangle at the previous position returning the background('erasing' the object) and then drawing in the new position. All this because it is expensive to draw all the list at mouseMove. can you help me?? Thanks Sassá

Share this post


Link to post
Share on other sites
Advertisement
XOR is possible see the imagesubset part of gl added in opengl1.2

though
Quote:
All this because it is expensive to draw all the list at mouseMove

most likely this is the quicker way

Share this post


Link to post
Share on other sites
This can be done with subtractive blending, so you'll have to use an extension for it:

Check out the specs for GL_EXT_blend_subtract at

http://oss.sgi.com/projects/ogl-sample/registry/EXT/blend_subtract.txt

Obviously, this means that your card/driver combo will have to support this extension. If you need to know if your card/driver will support this, use glGetString(GL_EXTENSIONS) and find out whether GL_EXT_blend_subtract is a part of this returned string.

Share this post


Link to post
Share on other sites
Quote:
Original post by FReY
This can be done with subtractive blending, so you'll have to use an extension for it:

Check out the specs for GL_EXT_blend_subtract at

http://oss.sgi.com/projects/ogl-sample/registry/EXT/blend_subtract.txt

Obviously, this means that your card/driver combo will have to support this extension. If you need to know if your card/driver will support this, use glGetString(GL_EXTENSIONS) and find out whether GL_EXT_blend_subtract is a part of this returned string.



yes, my card/driver support this extension.
I read this link and search on google about it, but i still dont know how to use it.
Is BlendEquationEXT a function? if yes, do I need any aditional library to use it??

if you post a code or a link for one it would help a lot.


remembering, I'm new in opengl... so sorry

Thanks for the help


Sassá

Share this post


Link to post
Share on other sites
Quote:

Is BlendEquationEXT a function? if yes, do I need any aditional library to use it??


Yes, this is an OpenGL function, but you can either setup the function pointer yourself or have an external library to do it for you. I highly recommend 'GLee' by Benjamin_Bunny. You can find it at:
http://elf-stone.com/glee.php

Download the 'GLee/GLee4_00.zip' file. Open the zip file and include the source files in your project. Then in the initialization of your program simply call GLeeInit();

Quote:

if you post a code or a link for one it would help a lot.


okay, I've personally never actually used this extension, but I think I can figure it out from the blend_minmax and the blend_subtract extension definitions.

The blend_minmax extension will give you the glBlendEquationEXT function. The blend_subtract extension allows you to change your blending equation from the form:
C' = (Cs * S) + (Cd * D)
to
C' = (Cs * S) - (Cd * D)

Using GLee you can easily query support for extensions and get hold of the functions required. However, you have to test if they're supported first.
You will want to do something like this:


if (GLEE_EXT_blend_subtract)
{
// subtractive blending is supported. Yay!
glBlendEquationEXT(GL_FUNC_SUBTRACT_EXT);
}
else
{
// subtractive blending is NOT supported. don't even try!
}

// do your subtractive blending rendering here. Do your quad rendering, but make sure your quad is white.
//This will give you 'white' - backgroundcolour which should be the inverse.
glBlendFunc(GL_ONE, GL_ONE);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS)
...
glEnd();


// change back to additive blending. this is important otherwise it will screw up the rest of your blend-modes
if (GLEE_EXT_blend_subtract)
{
// subtractive blending is supported. Yay!
glBlendEquationEXT(GL_FUNC_ADD_EXT);
}



Seriously, get GLee. It saves *so* much time it's not even funny.
Hope that helped you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!