# Viewport maping issue

**URL:** <https://discourse.libcinder.org/t/viewport-maping-issue/1169>\
**Category:** Using Cinder\
**Created:** [May 9, 2018, 3:22pm UTC](https://discourse.libcinder.org/t/viewport-maping-issue/1169 "2018-05-09T15:22:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![VincentPham](https://avatars.discourse-cdn.com/v4/letter/v/9fc348/32.png) [@VincentPham](https://discourse.libcinder.org/u/VincentPham)\
**Post date:** [May 9, 2018, 3:22pm UTC](https://discourse.libcinder.org/t/viewport-maping-issue/1169/1 "2018-05-09T15:22:47Z")

</div>

I have a problem on understanding how view port work. The view port seems mapping wrong but I can’t understand why.  
Everything is just fine until I try to mapping the scene to a specific area on a window by using view port.

Let’s check my source code.

> [@](#):
>
> void drawScene() {  
> static Rectf theRect(50, 50, 200, 100);  
> gl::color(0, 0, 1);  
> gl::drawSolidTriangle(theRect.getLowerLeft(), theRect.getLowerRight(), theRect.getUpperRight());  
> gl::color(0, 1, 0);  
> gl::drawSolidTriangle(theRect.getLowerLeft(), theRect.getUpperLeft(), theRect.getUpperRight());  
> }
> 
> static Rectf windowPort(30, 20, 130, 170);  
> static Area viewPort(100, 30, 300, 330);
> 
> void drawWindow1() {  
> gl::clear();
> 
> ```
> // draw the scene
> drawScene();
> 
> // draw window port area
> gl::color(1, 0, 0);
> gl::drawStrokedRect(windowPort, 3);
> 
> ```
> 
> }
> 
> void drawWindow2() {  
> gl::clear();
> 
> ```
> // clipping by using ortho projection
> gl::ScopedProjectionMatrix projectionMatrixScope;
> CameraOrtho orthoCam;
> orthoCam.setOrtho(windowPort.x1, windowPort.x2, windowPort.y2, windowPort.y1, 1, -1);
> gl::setProjectionMatrix(orthoCam.getProjectionMatrix());
> 
> // draw the scene
> drawScene();
> 
> ```
> 
> }
> 
> void drawWindow3() {  
> gl::clear();
> 
> ```
> // draw view port area
> gl::color(1, 0, 0);
> gl::drawStrokedRect(Rectf(viewPort), 3);
> 
> // mapping scene to view port area
> gl::ScopedViewport scopeViewPort(viewPort.getUL(), viewPort.getSize());
> 
> // clipping by using ortho projection
> gl::ScopedProjectionMatrix projectionMatrixScope;
> CameraOrtho orthoCam;
> orthoCam.setOrtho(windowPort.x1, windowPort.x2, windowPort.y2, windowPort.y1, 1, -1);
> gl::setProjectionMatrix(orthoCam.getProjectionMatrix());
> 
> drawScene();
> 
> ```
> 
> }

And the results:

 ![Capture](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/e33754fcc4382e892b1de35967b5088f38a5384c.JPG)

Let see on window 3, the scene is seem mapping wrong place.  
Actually, it’s location changes when I resize the window.  
Could anyone help me?
