djk's picture


Over the last 20 years I have been using the Hoops3d graphics system from TechSoft to provide rendering and graphical selection of objects in a large engineering application. My last foray into OpenGl was 15 years ago on an SGI Onyx using the GLUT framework to render a simulation there was no picking required.

I have recently started with a new company that is chartered to create a similar engineering system as open source using the .Net framework. The requirements have lead us to OpenGL and the OpenTK GlControl has risen to the top of the list from the 3-4 open source C# OpenGl controls evaluated.

In the Hoops3d system one would apply a filter to the segment tree (scene graph) to specify what you were going to select, ie whole object, face of a shell, line/edge, or vertex. Every graphical item had a key which could be remapped to a reference to the object that generated it. Thus when you selected an item you accessed the key to get the underlying object to operate on.

I have tried to port several picking implementations from other C/C++ projects to the OpenTK GlControl without success, I am sure the issue is with my inability to get my head wrapped around the OpenGL picking model. Does anyone have an example app built on OpenTk's GlControl that implements picking that they would be willing to share?


SelectionExample.zip87.83 KB


Comment viewing options

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

Thanks, djk, good point. I changed the GL.LoadName(n) to GL.PushName(n), still nothing shows up in the ListBox.
I don't know if all that matrix transformation is correct, but when it renders in the window it displays the objects correctly.

djk's picture

Sorry, I missed the fact that you had a LoadName on one DrawVertex call.

The only two things I can think of is that the SwapBuffers might need to be after the rendering code, and at some point I put a Flush command.

hits = GL.RenderMode(RenderingMode.Render);

[Edit] I should probably point out that I have only recently come back to openGL after more than 20 years working with Hoops3d graphics, its been tough getting the hang of OpenGL's model and project matricies again. I still find myself going in circles because I mixed Hoops and OpenGL concepts.

triton's picture

Thanks for the example.

djk's picture

teichgraf, I had to make a couple changes to get the code to compile, not sure if its VS2005/VS2008 differences or not.

I think I finally get this method for selection. It just seemed so foreign a concept to me for 3d object selection. I can easily see how to extend it to select multiple object using shift/control key modifiers.

What's not obvious is how to implement selecting all the objects within an windowed selection? Do I need to iterate through all the pixels within the bounding box of the selection window and find all the unique colored pixels or is there a better aproach?


Technolithic's picture

djk, I tried out your suggestion with calling swap buffers after the rendering method as well as calling flush before I start processing hits, but the result is the same.

It is a lot of concepts to apply before the code actually provides a clue about how the solution is progressing, good or bad. I'll keep looking for the solution. After I figure this beast out, I might just write my own "how to" technical document. I think just write about the simplest implementation describing every step and what's really going on underneath.

A good sub-title, "for the noob by the noob". Sounds like a good moto for something bigger, LOL

djk's picture

Technolithic, I spent a fair bit of time playing with the example that teichgraf provided yesterday, and it makes alot of sense now that I see it in operation.

I mod'd his example to allow multiple selections with very liitle effort. I will be using it as model and changing out the selection mechanism in our project next week. I think I can hit all the remaining use cases that I deferred with much less effort than with the original mehod.

Fiddler, maybe there should be a 'OpenGL Techniques the OpenTk way' under under the Discussion topic, or would you prefer they be under the 'OpenTK -> Support or Tutorial' topics?

the Fiddler's picture

OpenTK->Tutorials is meant for topics such as these. I think the fewer forums, the better - they might be too many of them even now.

teichgraf's picture

djk:teichgraf, I had to make a couple changes to get the code to compile, not sure if its VS2005/VS2008 differences or not.
That's right, I've written the example using Visual C# Express 2008 with some features from C# 3.0 (automatic properties).

djk:[...] Do I need to iterate through all the pixels within the bounding box of the selection window and find all the unique colored pixels [...]
That should work.

By the way, I would be interessed to see your open source engineering system. Is there a URL?

djk's picture

teichgraf, the Framework to our system is known as TurksHead. The framework is open source (LPGL), and we are hopefully nearing the end of all the corporate paperwork to expose the source repository. While the company has supported the OSS concept without issue, they have a very strict set of procedures for IT security and they are helping us get setup so we don't create vulnerabilities or risk. When we go live I will post a link under the projects topic.

TurksHead provides what we call a smart product model, which in essence is the organization and attribution of an engineering model of a concept or design. The "smart" in the framework is provided by a variety of simulation tools on which domain specific simulations can be built. Examples of domain specific simulations would be ship hydrostatics calculation or simulation of six degree of freedom ship motions.

We do build commercial applications and applications for hire on this framework, this first commercial product can be scene at

Technolithic's picture

I finally got it to work with quite a bit of discussion with my Professor in how the various matrices work.

After reading all the tutorials, I find that I must have been missing something.
It's challenging (and time-consuming) to write a good technical document that produces all the answers. In interest in helping to fill the gap between technology and humanity, I'm curious to find out if there's a decent career to be made in producing documents that bring more people into the realm of technology, specifically in the open-source community.

Now that selection/picking is incorporated into my application, a new obstacle remains. Something with creating custom events and using delegates to get the information obtained in one object, subclass, back to another object, base class, using event firing to tell the base class object that it's time to call a method to return the data contained in the subclass. Perhaps this is a new topic or maybe it isn't technically related to this forum at all.

I've looked at tons of tutorials on the net, but I can't seem to wrap my brain around the idea. It seems that it's so simple that ample explanation is beyond the scope of the concept.