Jump to content
Sign in to follow this  
Ben Russell

OpenGL Scissors: Masking tape for your EFIS.

Recommended Posts

Ben,

Unfortunately gl.Scissor requires window coordinates, which makes alignment a pain in the a**.

Would be perfect if we could use this with panel coordinates.

Jim

Share this post


Link to post
Share on other sites

Would be perfect if we could use this with panel coordinates.

and this is how I do it (thanks to B. Supnik for his advice) in my C projects

x,y,w,h are in panel coordinates

DefineScissor(double x, double y, double w, double h){

//BEN's advice for SCISSOR

GLdouble    modelM[16];                        // Our current model view matrix

GLdouble    projM [16];                        // Our current projection matrix

GLint viewport[4];                       // The current viewport

glGetDoublev (GL_MODELVIEW_MATRIX  ,modelM);

glGetDoublev (GL_PROJECTION_MATRIX ,projM);

glGetIntegerv(GL_VIEWPORT          ,viewport);

double x0, y0, z0, x1, y1, z1;

gluProject(  x,  y, 0.0, modelM, projM, viewport, &x0, &y0, &z0);

gluProject(  w,  h, 0.0, modelM, projM, viewport, &x1, &y1, &z1);

glScissor(x0, y0, x1, y1);

}

Share this post


Link to post
Share on other sites

Thanks!

I am the one to say thank you...

About the code, I haven't yet spent enough time investigating whether the result of any of these calls can be cached across different frames (I call the scissor function once per frame):

  glGetDoublev (GL_MODELVIEW_MATRIX  ,modelM);

  glGetDoublev (GL_PROJECTION_MATRIX ,projM);

  glGetIntegerv(GL_VIEWPORT          ,viewport);

However it appears as if the impact on CPU/FPS is negligible.

(remember to release the scissor when done with yuor stuff, or you will trash the screen)

Share this post


Link to post
Share on other sites

I have wrapped the supplied code into an API call.

Usage:


gfx.setMaskingTape( x, y, w, h )
-- draw here
gfx.clearMaskingTape()

Hi,

I'm very new to all this Gizmo fun, big thanks to Ben for creating such an awesome API!

I'm attempting utilize the MaskingTape function to keep the OpenGL drawing within boundaries.

I've tried to use this function but seem unable to get in working:

Attached below code, objective is to setup a Masking area of 100 by 100 px.

Then draw a box of 200 by 200 px. If masking works then I should be only able to see the 100 by 100 section of this box, right?

When I load this up in X-Plane it still draws my full 200x200 filled box.

Another notable thing is gfx.texOff() placement, if this is placed inbetween the masking draw code, then the x-plane menu's and widgets will turn greyblack.

Am I doing something wrong here?


function OnDraw_Windows()
  sw, sh = gfx.getScreenSize()

  gfx.texOff() 

  gfx.setMaskingTape( sw/2, sh/2, 100, 100 )       
       gfx.setColor(1,0,0,1)
       gfx.drawFilledBox( sw/2, sh/2, 200, 200 )
  gfx.clearMaskingTape()
end

Share this post


Link to post
Share on other sites

Sorry for missing this.

The version available as of this post is 11.3.15.

The gfx.setMaskingTape(...) function will be available in the next version of Gizmo.

Regarding: gfx.texOff()

If you turn textures off Gizmo won't turn it back on for you.

So when you're done, before the end of the function, just call gizmo.texOn()

This is a fairly common practice in all of OpenGL programming, it allows for higher speed and more possibilities.

Sorry for the lag, hope that helps, a new version of Gizmo: 11.4.x is due out any day now.

Share this post


Link to post
Share on other sites

Yes, Ben.

I tried it out first thing after getting 11.4.24 with my previous code snippet.

It still draws the box which is outside the MaskingTape bounds.

Maybe I'm doing something terribly wrong?!

Anybody else used this MaskingTape function succesfully in their code?


function OnDraw_Windows()
  sw, sh = gfx.getScreenSize()

  gfx.texOff()

  gfx.setMaskingTape( sw/2, sh/2, 100, 100 )       
       gfx.setColor(1,0,0,1)
       gfx.drawFilledBox( sw/2, sh/2, 200, 200 )
  gfx.clearMaskingTape()

  gfx.texOn()
end

Share this post


Link to post
Share on other sites

Hi, Lightner

not sure about the impacts, but the C code  I use (ported into gizmo by Ben) works from a drawing callback, registered for

the "xplm_Phase_Gauges" phase.

You probably need to call this from a draw_2D_panel function.

I will check later.

Ciao

A.

Share this post


Link to post
Share on other sites

Hi x-alberto,

I have tried it using OnDraw_Gauges, but it still draws the box despite the MaskingTape.

Lightner

Update: drawing on the window with OnDraw_Windows() and gl.Scissor still works fine though:


function OnDraw_Windows()
 sw, sh = gfx.getScreenSize()

 gfx.texOff()
 gl.Enable('SCISSOR_TEST')
      gl.Scissor( sw/2, sh/2, 100, 100 )      
      gfx.setColor(1,0,0,1)
      gfx.drawFilledBox( sw/2, sh/2, 200, 200 )
 gl.Disable('SCISSOR_TEST')
 gfx.texOn()
end

Share this post


Link to post
Share on other sites

Hi x-alberto,

I have tried it using OnDraw_Gauges, but it still draws the box despite the MaskingTape.

Lightner

Update: drawing on the window with OnDraw_Windows() and gl.Scissor still works fine though:

Hi Lightner, I am not really able to perform any test today, but please note that the tape masking fuction is supposed to work based on

"panel coordinates", that you get with:

XPLMGetWindowGeometry(gMainWindow, &PanelWindowLeft, &PanelWindowTop, &PanelWindowRight, &PanelWindowBottom);

Not sure how they relate to screen coordinates.

Will follow up when possible.

Share this post


Link to post
Share on other sites

Playing with the Gizmo API version and not getting anything of use in any drawing phase.

..tinkering, but no promises. Sound API has a higher priority for any in-depth work.

Share this post


Link to post
Share on other sites

Fixed.

Error: No call was made to glEnable( GL_SCISSOR_TEST );

Changed the code to enable the scissor test and it works now.

Tested in 2D drawing and 3D drawing modes in-sim.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×