Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invert texture colours in OpenGL

I'm texturing a 2D object in OpenGL, and while I have the texture loading fine, I'm just not quite sure how to invert the colours. How do I access the colour information of the bitmap and invert it? Would this be done best in a shader or in the Main program?

I'm leaving this kind of open as I'm not looking for a "fix my code" type of answer, but rather "this is how you access the colour information of the bitmap".

like image 510
user5884993 Avatar asked Feb 04 '16 19:02

user5884993


1 Answers

Its s simple as

gl_FragColor = vec4(1.0 - textureColor.r,1.0 -textureColor.g,1.0 -textureColor.b,1) It is best to do this kind of thing in the shader, if you want to do it once and then reuse it for future draws just use render to texture. This is the fastest way to do color inversion.

EDIT: You use vec4 textureColor = texture2D(uSampler,vTexCoords) before your do gl_FragColor using .r ,.g,.b and .a access the red, green, blue and alpha values respectively.

like image 172
JustinWeq Avatar answered Sep 28 '22 07:09

JustinWeq