mandragora's picture

Display 2D image data as 3D surface ...

Hi guys,

after my problem with the glControl refresh (thanks to everybody for the help), I've another little (...) problem!

Is present OpenTK a method similar to the Matlab Surface(...) funcion?
The problem that I've is to diplay a 2D image as a 3D surface. So for example I would like to be able to represent a 2D depht image map as a surface.
is that possible?
If not what is the correct way to do that?

Thanks a lot in advance

Have a nice day

Ben


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
iliak's picture

Any screen shot ?

Hortus Longus's picture
mandragora wrote:

Is present OpenTK a method similar to the Matlab Surface(...) funcion?

Hey, OpenTK is the OpenGL-Wrapper, not Paintx :-)

mandragora wrote:

If not what is the correct way to do that?

As usual: read your image, go through the x-y-coords and use the z-value as height.
Have a look at http://nehe.gamedev.net, OpenGL Tutorial #34

mandragora's picture

:-(

oppss!!!

Thanks a lot and please excuse me for the stupid question that I've posted and for all the other ones that I'll post :-)))
I was pretty sure that the correct way was to use the image values as the height of the surface, but I didn't know how to do that.
I'll have a look on the nehe tutorial and I'll post my results.

Thanks again for helping me!!!

Ben

mandragora's picture

Hi,

I've found this on the OpenTK website ...

http://www.opentk.com/node/618

This is exactly what I need !!! :-)))

Thanks

Ben

mandragora's picture

Hi All,

after reading the nehe tutorial and the one present in the OpenTK web site,
I've managed to .... get a light blue glControl !!! :-)))

here is the code that I'm using:

        void glControl3_Paint(object sender, PaintEventArgs e)
        {
            if (!glControl3.Context.IsCurrent)
            {
                glControl3.MakeCurrent();
            }
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
 
            GL.Begin(BeginMode.Quads);
 
            for (int bx = 0; bx < (size.Width - RenderSteps); bx += RenderSteps)
            {
                for (int bz = 0; bz < (size.Height - RenderSteps); bz += RenderSteps)
                {
                    // Paint the current primitive based on the heightmap's color value
                    GL.Color3(heightTable[bx, bz], heightTable[bx, bz], heightTable[bx, bz]);
 
                    // 0,0
                    GL.Vertex3(bx, heightTable[bx, bz], bz);
                    // 1,0
                    GL.Vertex3(bx + RenderSteps, heightTable[bx + RenderSteps, bz], bz);
                    // 1,1
                    GL.Vertex3(bx + RenderSteps, heightTable[bx + RenderSteps, bz + RenderSteps], bz + RenderSteps);
                    // 0,1
                    GL.Vertex3(bx, heightTable[bx, bz + RenderSteps], bz + RenderSteps);
 
                    //diagVertices += 4;
                }
            }
 
            GL.End();
 
            glControl3.SwapBuffers();
        }
 
        void glControl3_Load(object sender, EventArgs e)
        {
 
            // Set up opengl scene
            GL.ClearColor(Color.SteelBlue);	// Set color
            GL.PointSize(3f);				// Set size of points
            GL.Enable(EnableCap.DepthTest);	// Enable depth test capabilities
 
            // Load heightmap
            LoadHeightMap("c:\\heightmap.png");
        }

What I'm doing wrong this time? How do I set up the camera position?

Thanks a lot

Ben

mandragora's picture

Hi All,

I've managed to display my height map here is the code that I'm using:

        void glControl3_Load(object sender, EventArgs e)
        {
 
            // Set up opengl scene
            GL.ClearColor(Color.SteelBlue);	// Set color
            GL.PointSize(3f);				// Set size of points
            GL.Enable(EnableCap.DepthTest);	// Enable depth test capabilities
 
            int w = glControl3.Width;
            int h = glControl3.Height;
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            // Camera
            double cameraPositionX = 0.0, cameraPositionY = 0.0, cameraPositionZ = 0.0;
            OpenTK.Graphics.Glu.LookAt(cameraPositionX, cameraPositionY, cameraPositionZ, 256, 0, 256,   0.0, 1.0, 0.0);
            GL.Ortho( 0, w, 0, h, -127, 127); // Bottom-left corner pixel has coordinate (0, 0)
            GL.Viewport(0, 0, w, h); // Use all of the glControl painting area
 
            // Load heightmap
            LoadHeightMap("c:\\heightmap.png");
        }

Could someone please exlain me the link between the following likes of code ?

 
OpenTK.Graphics.Glu.LookAt(cameraPositionX, cameraPositionY, cameraPositionZ, 256, 0, 256,   0.0, 1.0, 0.0);
GL.Ortho( 0, w, 0, h, -127, 127); // Bottom-left corner pixel has coordinate (0, 0)

Also I saw that the use of Glu.LookAt is deprecated, what I should use instead?

Thanks a lot for your help

Ben

Hortus Longus's picture
mandragora wrote:

Could someone please exlain me the link between the following likes of code ?

 
OpenTK.Graphics.Glu.LookAt(cameraPositionX, cameraPositionY, cameraPositionZ, 256, 0, 256,   0.0, 1.0, 0.0);
GL.Ortho( 0, w, 0, h, -127, 127); // Bottom-left corner pixel has coordinate (0, 0)

Well, both points have to do with "Looking", but in my eyes this combination is uncommon. Where did you find it?
But I understand your question not correctly, ask again from another Lookat. ;-)

Quote:

Also I saw that the use of Glu.LookAt is deprecated, what I should use instead?

Yes, it is, but simply use it.
If the successor is finished, you will hear it.

Btw: for understanding OpenGL, you should go through the NeHe-Lessions, from Lesson 2 on, not beginning in the middle. It will be your tool for years. ;-)

the Fiddler's picture

The successor is OpenTK.Matrix4.LookAt, which can be used like this:

Matrix4 lookat = Matrix4.LookAt(cameraPositionX, cameraPositionY, cameraPositionZ, 256, 0, 256,   0.0, 1.0, 0.0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
mandragora's picture

Hi Hortus,

thanks for the reply.

Well, both points have to do with "Looking", but in my eyes this combination is uncommon. Where did you find it?
Well ... nowhere ! :-) I've just wrote them in order to make something appear in the glControl. I was just playing a bit :-)))

Hi Fiddler thanks a lot for the info about the new version of Glu.Lookat(...)

I'll have a look on the NeHe tutorials, and do some more experimentations and I'll post my results.

Thanks again for all of your help

Have a nice day

Ben

Hortus Longus's picture
the Fiddler wrote:

The successor is ...

Yes. :-)
In my head, I was thinking about the project Successor.Glu. ;-)