3 Replies - 831 Views - Last Post: 19 February 2017 - 02:09 PM

#1 mortye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-March 14

Draw a circular magnifying lens showing scaled underlying content (2D)

Posted 19 October 2016 - 05:07 PM

I have a 2D scene in Monogame with some primitives and sprites and I would like to create a magnifying glass effect with a circular lens showing a zoomed view of the content under it.

In Java2D (my background) I would create a Graphics object from a new BufferedImage, apply a scale transform corresponding to the zoom factor, draw my content in it with a clipping region matching the lens geometry and then draw the image in the paint method of my canvas or panel. I imagine the strategy is similar in Monogame/XNA, but I don't know the exact tools and API elements I can use to do that. I searched a bit on the web and it seems I might have to define a RenderTarget2D, draw my stuff in there with my rendering settings and then somehow draw it in the back buffer. Not sure how I would apply a scale transform and circular clipping region to it, though.

Thanks in advance for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Draw a circular magnifying lens showing scaled underlying content (2D)

#2 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: Draw a circular magnifying lens showing scaled underlying content (2D)

Posted 21 October 2016 - 01:34 AM

there is several ways to do this.

you can use a stencil to show a bigger version of what you are zooming into within your circle.

you can use a rendertarget 2d to draw onto a circle/sphere... maybe this isn't the best choice..

you can also do it with the pixel shader to make it super realistic and do exactly what you wish to fake.



if i were you i would just use a stencil mask... keep it simple
Was This Post Helpful? 1
  • +
  • -

#3 mortye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-March 14

Re: Draw a circular magnifying lens showing scaled underlying content (2D)

Posted 21 October 2016 - 02:03 PM

Thanks for the answer.

Stencil sounds good. Could you maybe be a bit more specific? From what I gathered, the stencil buffer typically allows you to do alpha masking, which would deal with the clipping, but I'm not sure how it handles the zooming. Could you maybe provide a few code lines that would get me on the way?
Was This Post Helpful? 0
  • +
  • -

#4 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: Draw a circular magnifying lens showing scaled underlying content (2D)

Posted 19 February 2017 - 02:09 PM

i am sorry i lost my videocard and my computer for a few months.

there's a sample for xna 2d zoom you can use somewhere online.

i think here

http://www.david-ama...m-and-rotation/



that's what u need to move forward with this, have a zoomed version and a nonzoomed version on top of it.
so when u move the mouse the image below pans and is zoomed. you would have to code this. shouldn't be hard. if the zoom is 2x then u should pan it twice as much as the mouse movement. (or maybe 4 times i can't remember how 2x area is when measuring it)


i am sure you have actually fixed this by now but maybe it will help someone else who needs to get a resource on 2d zoom i guess
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1