Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a color map with opengl

989 views
Skip to first unread message

Tim Carden

unread,
Jan 8, 2010, 4:33:59 AM1/8/10
to
Hi all,

I got a grid of nxm values which i want to represent with a color. So
the at first i would get grid where the are nxm point with different
colors. But you all know weather maps[1]. Is there any possibility to
plot this with openGL, are there any predefined functions i can use (as
for example in matlab).

Everything should be on a 2D surface.

Thanks for your help or ideas.

Tim

[1]http://www.zeigen.com/blog/wp-content/weather-map.jpg

Wolfgang Draxinger

unread,
Jan 8, 2010, 9:13:00 AM1/8/10
to
Tim Carden wrote:

> Hi all,
>
> I got a grid of nxm values which i want to represent with a color. So
> the at first i would get grid where the are nxm point with different
> colors.

Well, that's an image then. If you want to remap image colors to say false
colours, this can be done using a fragment shader.

> But you all know weather maps[1]. Is there any possibility to
> plot this with openGL,

Yes of course, but that's not an function of OpenGL itself. You just use the
API to get the desired result.

> are there any predefined functions i can use (as
> for example in matlab).

Definitely not. OpenGL is an API do the graphics hardware. Nothing more,
nothing less.

--
OpenGL tip #42:
How to exactly map texture texels to screen pixels:
<http://preview.tinyurl.com/cgndc8>

jbwest

unread,
Jan 8, 2010, 11:59:53 PM1/8/10
to

"Wolfgang Draxinger" <wdrax...@darkstargames.de> wrote in message
news:hi7ehc$m1$1...@news.eternal-september.org...

Look for a plotting package rather than OpenGL directly. I'm sure that you
can find something suitable that will plot your data directly (using OpenGL,
Open Source too).

-jbw


Tim Carden

unread,
Jan 11, 2010, 8:46:15 AM1/11/10
to
Thanks,

so I think i will create this image, which isn`t so difficult at all.

But also if its kind of off topic:

How do i calculate the color value (rgb)?

I would like to use the matlab colors, meaning the lowest value blue and
the hightest red visiting yellow on its way.

I normalize the values to range 0...1 and afterwards?

Hopefully someone knows.

Tim

jbwest schrieb:

Jonathan Campbell

unread,
Jan 11, 2010, 10:46:04 AM1/11/10
to
Tim Carden wrote:
> Thanks,
>
> so I think i will create this image, which isn`t so difficult at all.
>
> But also if its kind of off topic:
>
> How do i calculate the color value (rgb)?
>
> I would like to use the matlab colors, meaning the lowest value blue and
> the hightest red visiting yellow on its way.
>
> I normalize the values to range 0...1 and afterwards?
>
> Hopefully someone knows.
>

I assume you have an nR x nC image 'gim' of grey values; probably in the
range [0, 255].

int nR, nC;
GLubyte gim[nR][nC];

GLubyte image[nR][nC][4];

Now you need a lookup table of the form:

GLubyte lut[4][256] = {{0, 0, 0, 255;}
1, 2, 2, 255;}
...
}

to enable you to convert the gray level value to RGBA and write into
'image'. Loop over every pixel ...

Can you trick MATLAB into divulging lookup table? Or find one on the
web, or find a formula?

Here is the display function:

void display(){
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels(nR, nC, GL_RGBA, GL_UNSIGNED_BYTE, image);
glFlush();
}

In any case, just to demonstrate that you can display an image, first
display as grey level --- i.e. make 'image' from 'gim' by copying the
grey level into R, G, and B, with 255 in A.

As Wolfgang says, these days it would be an obvious thing to do in a
fragment shader, but maybe you don't want to bother with shaders?

Best regards,

Jon C.

--
Jonathan Campbell www.jgcampbell.com BT48, UK.

0 new messages