2D shape using OpenGL

41 views
Skip to first unread message

Henan Zhao

unread,
Sep 29, 2016, 10:40:49 AM9/29/16
to omegalib
Hi,

I'd like to draw a 2D shape on the screen using OpenGL.

I tried to use gluUnProject, but I cannot get the correct coordinates of the objects. Also, if I drew a horizontal line, the line has the slope instead of a horizontal one.
Our cave is the part of one cylinder, maybe 1/4.

Could you please help me about that?

Thanks a lot.

Alessandro Febretti

unread,
Sep 30, 2016, 12:37:43 PM9/30/16
to omegalib
Hi Henan,
what are you doing exactly to draw in 2D?

the correct way is to do it inside a renderpass render method, on the OverlayDrawTask draw phase. During that render call, the draw context passed to the render method contains all the information you need to set up 2D drawing.

You basically want to do:


YourRenderPass::render(DrawContext& context)
{
   
if(context.task == DrawContext::OverlayDrawtask && context.eye == DrawContext::EyeCyclop)
   
{
 
DrawInterface* di = getClient()->getRenderer();
 di
->beginDraw2D(context);
// Do your drawing here
di
->endDraw();
   
}
}



An important note: beginDraw2D only works on OpenGL compatibility profiles since it uses legacy openGL functions to pass the transforms to the render pipeline. If you run omegalib with coreProfile = true; in the display section to request a forward-compatible openGL profile, that call won't  do anything and you will have to pass the transforms to your shaders manually. An example of 2D drawing fully compatible with modern OpenGL is here: https://github.com/omega-hub/overlay/blob/master/overlay.cpp

Henan Zhao

unread,
Mar 21, 2017, 3:05:15 PM3/21/17
to omegalib
Hi Alessandro,

Thanks.
I have a new problem. Can you please give me some example how I can integrate 2D and 3D visualization? 
For example, I have a 2D image, or some basic shapes like 2D rectangles and circles and also 3D visualization, like volume rendering. 
Is it possible that both SceneDrawTask and OverlayDrawtask co-exist in one render pass?

Thank you very much.
Henan

Alessandro Febretti

unread,
Mar 23, 2017, 10:24:09 AM3/23/17
to omegalib
Yes you can render 3D (in a scene render pass) and 2D (in an overlay render pass).

The widgets in the OmegaToolkit UI are rendered this way.

You can also check the on-screen console rendering code https://github.com/uic-evl/omegalib/blob/master/src/omega/Console.cpp

Or this overlay rendering module (designed for OpenGL 4 forward profiles) https://github.com/omega-hub/overlay/blob/master/overlay.cpp



Henan Zhao

unread,
Mar 24, 2017, 11:43:27 AM3/24/17
to omegalib
Hi Alessandro,

Thanks a lot.
I haven't tried that but will do that soon.

Thank you again.
Henan
Reply all
Reply to author
Forward
0 new messages