Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / very quick q, how do you get a RGB value from a screen pixel? for heightmap image to matrix

Author
Message
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 13:25
it's all in title

i'd like to be able to convert an image heightmap to matrix height values

i'm thinking just paint image on screen, sync, and grab pixel color?
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 13:39
do i have to use GET PIXELS POINTER for this? i don't understand how that works
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Aug 2010 13:41
Memblocks are better, because the point command is so damn slow - but anyway, load your heightmap in as a bitmap, then step through the coordinates and use....

col=POINT(X,Y)
R=RGBR(col)

Then R should be a value from 0-255, representing the red colour. Often it's possible to use other colour channels, like the green or blue channel to do other things.

Some people even use all 3, and work out a much more detailed heightmap (like 0-16million instead of 0-255). Once you have all the data, I suggest just saving it out as an array.

Health, Ammo, and bacon and eggs!
wyrleywolves
23
Years of Service
User Offline
Joined: 6th May 2003
Location:
Posted: 3rd Aug 2010 13:42
colour=POINT(X,Y)
this is the command you need I believe.
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 13:49
i found a code snippet and adapted it a bit

that's what i'm doing. i can't see the matrix though
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 14:03
eh i can see the matrix after tweaking the scales, but i don't think it went through right computationally. it was upside down so i just multiplied each height value by -1. but it's still not the heightmap i'm wanting

(it's a greyscale image btw)

what would the easiest way be of writing a function that would automatically get the size of a specified image, and generate a matrix from it?
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 14:10 Edited at: 3rd Aug 2010 14:19
i tried it with grabbing the color values. however all the values for the matrix heights are zero. here is what i wrote

rgbr is returning zero, it won't return anything else

do i need to define "col" as a certain type of variable?

i tried "local col as dword" at the start of function but nothing
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Aug 2010 14:32 Edited at: 3rd Aug 2010 14:32
No, you've just got a "sync" in the wrong place.

Try this code with the attached image (I've made some minor changes to your code - the only important change is marked ***)

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 3rd Aug 2010 15:35 Edited at: 3rd Aug 2010 15:57
There is a command,

MAKE TERRAIN Terrain Number, Heightmap Filename

that makes a terrain matrix for you. It might not be what you need, but you could check it and see.

This code takes Green Gandalf's image and makes a terrain from it:



and this code makes an object out of the terrain. You can use most of the object commands on it, like saving it, moving it, etc.



MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 15:55
WOW!!!
i am so glad i came across this.

here is what i made in like 45 seconds

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 15:56
holy crap dude!


CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 15:57 Edited at: 3rd Aug 2010 16:00
wanted to include my heightmap image for you

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 15:57
can someone add texture generation and smoothing of textures to this?!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 15:57 Edited at: 3rd Aug 2010 16:03
holy crap me!? ahahaha

if you have a tablet like i do this is great!
the pen is pressure sensitive so i color background black
use white as my drawing color
with a fading brush and the harder i push the higher the hills.

its so easy. i love this code!!!

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 16:01
can someone create a random matrix landmass generator that textures it, and smooths it?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 16:06
to do anything useful with that you would need code to save the matrix to a file or something when you (randomly) got the matrix you wanted.

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 16:07
nvm. i found a terrain generator from smaas

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 16:10
does it "randomly" generate or what?
where can i find it?

metal is not music but a way of life...all hail to the reigning king METALLICA!!! [EDIT] ...well... up until "Load" came out.
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 16:18
in the wip post

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 16:19
thanks

metal is not music but a way of life...all hail to the reigning king METALLICA!!! [EDIT] ...well... up until "Load" came out.
Mugen Wizardry
User Banned
Posted: 3rd Aug 2010 16:22
np

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 16:34
thanks i got it working
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 16:38
>>n someone create a random matrix landmass generator that textures it, and smooths it?>>

hit me up when i really get working on my space game. i'll be making an auto-generator for worlds so there are hundreds or thousands of worlds one can visit

i know about the terrain commands... i'm just more familiar with matrices so i went that way

i coded with DB a lot back in the day, i'm getting back into it and there are two really cool projects i want to get finished (never really finished a large project lol)

this one (with the matrix heightmap) being a turn based strategy game, not a huge project... the other one (also will use heightmapping and mathematical algorithms to create landforms etc) will be a space exploration game (will take a long time to complete)
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 17:03
anyway if you want to see some preliminary results from helping me out with this...

behold europe!



of course, this is VERY preliminary. it'll look better, and there shall be thousands of little infantry men shooting eachother

it will be multiplayer (not on multiple comps) turn based... order units around manage cities, was going to do hexagon based but a grid seems simpler especially with the matrix commands... you could do 1v1 (one player could control allies, another axis or central powers depending on time period / units) or 3v2(ww2) 3v3(ww1) 3-8+ player diplomacy at any tech level, etc
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Aug 2010 20:03
Europe? Looks flipped East to West to me.

Looks like good progress though.
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 20:18 Edited at: 3rd Aug 2010 20:20
I have to go for now,
I wanted to show you some tests i was doing with this code.

here is screen shot 1
(skull island)

there doesn't seem to be a good angle for it without textures and this far zoomed out

metal is not music but a way of life...all hail to the reigning king METALLICA!!! [EDIT] ...well... up until "Load" came out.
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 3rd Aug 2010 20:19 Edited at: 3rd Aug 2010 20:21
and screenie #2
(pretty lady land)

"her" face got a little tweaked in the transition...
maybe too much detail with too few polygons

metal is not music but a way of life...all hail to the reigning king METALLICA!!! [EDIT] ...well... up until "Load" came out.
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 3rd Aug 2010 22:26 Edited at: 3rd Aug 2010 22:29
funny idea about the lady. while we're playing around with matrices,

3d graph of z = sin( abs(x) + abs(y) )

and something on the back burner


the grapher has a 2d grapher and string parser (for the variable equation) built in so i'll dig up that code and post it here. probably some useful functions in there

if i had a motivated state of mind all the time... i'd have unleashed so much awesomeness on the world in terms of software

but as it stands i have yet to finish a large project :/

and yes europe is currently backwards
MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 4th Aug 2010 04:23
haha yeah i hear you with the LARGE project thing.

Its funny... given the appropriate time i can make DBPro do just about
any SINGLE task that i want it to BUT...

Ive found that when i try and make anything LARGE, everything goes
great for about three days...then the variables quit making sense
and everything becomes a mess.

...about the skull and lady (maps)...
you can actually draw pictures and then make them "grayscale" It pretty much works itself out... I think thats so cool

metal is not music but a way of life...all hail to the reigning king METALLICA!!! [EDIT] ...well... up until "Load" came out.

Login to post a reply

Server time is: 2026-07-26 01:26:10
Your offset time is: 2026-07-26 01:26:10