Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
Getting colour of pixel underneath mouse position
Print
Pages: [
1
]
Author
Topic: Getting colour of pixel underneath mouse position (Read 4126 times)
0 Members and 2 Guests are viewing this topic.
darekg11
Full Member
Posts: 127
Getting colour of pixel underneath mouse position
«
on:
June 14, 2013, 01:07:04 pm »
I can't find any function that allows me to get r,g,b from current pixel. I might just not see it in documentation, any tip would be appreciated.
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Getting colour of pixel underneath mouse position
«
Reply #1 on:
June 14, 2013, 01:41:05 pm »
There's no such function. Reading drawn pixels is extremely expensive (it must go all the way back from the GPU to the CPU). Why do you want to do that?
Logged
Laurent Gomila - SFML developer
darekg11
Full Member
Posts: 127
Re: Getting colour of pixel underneath mouse position
«
Reply #2 on:
June 14, 2013, 02:06:15 pm »
In my game I would like to use isometric titles.
So first I load it, use mask on it to hide pink background so it will be transparent and I want to check if my mouse cursor is over title(by checking if color under the mosue is different than black) or over background (black)
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Getting colour of pixel underneath mouse position
«
Reply #3 on:
June 14, 2013, 02:34:00 pm »
Reading the screen is possible (window.capture()) but strongly disadvised for this kind of computation, you should not rely on what you've drawn, but rather create and use your own optimized data structure for these tests.
Logged
Laurent Gomila - SFML developer
darekg11
Full Member
Posts: 127
Re: Getting colour of pixel underneath mouse position
«
Reply #4 on:
June 14, 2013, 02:48:45 pm »
I see, I will figure something else. Thank You.
Logged
Nexus
SFML Team
Hero Member
Posts: 6287
Thor Developer
Re: Getting colour of pixel underneath mouse position
«
Reply #5 on:
June 14, 2013, 02:52:28 pm »
You could just create a bitfield using
std::vector<bool>
,
std::bitset
or
boost::dynamic_bitset
.
Or a
std::vector<BiggerIntegralType>
and take care of the bit operations yourself.
Logged
Zloxx II
: action platformer
Thor Library
: particle systems, animations, dot products, ...
SFML Game Development
:
darekg11
Full Member
Posts: 127
Re: Getting colour of pixel underneath mouse position
«
Reply #6 on:
June 14, 2013, 03:33:54 pm »
You mean like during loading of map create 800x600 array of bools and for each pixel assign true or false depending on color and then comparing mouse coordinates with according array value? If so that's really good idea. I will try it out, thank You.
Logged
Nexus
SFML Team
Hero Member
Posts: 6287
Thor Developer
Re: Getting colour of pixel underneath mouse position
«
Reply #7 on:
June 14, 2013, 07:52:00 pm »
Yes, but don't use raw arrays, rather one of the data structures from my last post. They'll do the whole work for you and are optimized (either towards memory consumption or speed).
Logged
Zloxx II
: action platformer
Thor Library
: particle systems, animations, dot products, ...
SFML Game Development
:
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
Getting colour of pixel underneath mouse position