Exemplo n.º 1
0
SubCanvas::SubCanvas(Canvas &canvas, RasterPoint _offset, PixelSize _size)
  :relative(_offset)
{
  assert(canvas.offset == OpenGL::translate);
  offset = canvas.offset + _offset;
  
  /* sub canvas bottom right limits can't be outside "parent" canvas. */
  size.cx = std::min<PixelScalar>(_size.cx, canvas.GetSize().cx - _offset.x) ;
  size.cy = std::min<PixelScalar>(_size.cy, canvas.GetSize().cy - _offset.y) ;

  if (relative.x != 0 || relative.y != 0) {
    OpenGL::translate += _offset;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#else
    glPushMatrix();
#ifdef HAVE_GLES
    glTranslatex((GLfixed)relative.x << 16, (GLfixed)relative.y << 16, 0);
#else
    glTranslatef(relative.x, relative.y, 0);
#endif
#endif /* !USE_GLSL */
  }
  
  if ((relative.x + size.cx < canvas.GetSize().cx) 
          || (relative.y + size.cy < canvas.GetSize().cy)) {

    /* Enable Clipping */
    push_scissor = std::make_unique<GLPushScissor>();
    scissor = std::make_unique<GLCanvasScissor>(*this);
  }
}
Exemplo n.º 2
0
void
BufferWindow::OnPaint(Canvas &canvas)
{
#ifdef ENABLE_OPENGL
  if (!buffer.IsDefined()) {
    buffer.Create(canvas.GetSize());
    dirty = true;
  }

  if (dirty) {
    dirty = false;
    buffer.Begin(canvas);
    OnPaintBuffer(buffer);
    buffer.Commit(canvas);
  } else
    buffer.CopyTo(canvas);

#else

  if (dirty) {
    dirty = false;
    OnPaintBuffer(buffer);
  }

  canvas.Copy(buffer);
#endif
}
  virtual void OnPaint(Canvas &canvas) override {
    canvas.ClearWhite();

    const GeoPoint a(Angle::Degrees(7.70722),
                     Angle::Degrees(51.052));
    const GeoPoint b(Angle::Degrees(11.5228),
                     Angle::Degrees(50.3972));

    WindowProjection projection;
    projection.SetScreenOrigin(canvas.GetWidth() / 2, canvas.GetHeight() / 2);
    projection.SetGeoLocation(a.Middle(b));
    projection.SetScreenSize(canvas.GetSize());
    projection.SetScaleFromRadius(fixed(400000));
    projection.UpdateScreenBounds();

    canvas.SelectBlackPen();
    canvas.SelectHollowBrush();

    RasterPoint pa = projection.GeoToScreen(a);
    canvas.DrawCircle(pa.x, pa.y, 4);

    RasterPoint pb = projection.GeoToScreen(b);
    canvas.DrawCircle(pb.x, pb.y, 4);

    RenderFAISector(canvas, projection, a, b, false, settings);
  }
void
TerrainPreviewWindow::OnPaint(Canvas &canvas)
{
  const GlueMapWindow *map = UIGlobals::GetMap();
  if (map == nullptr)
    return;

  MapWindowProjection projection = map->VisibleProjection();
  if (!projection.IsValid()) {
    /* TODO: initialise projection to middle of map instead of bailing
       out */
    canvas.ClearWhite();
    return;
  }

  projection.SetScreenSize(canvas.GetSize());
  projection.SetScreenOrigin(canvas.GetWidth() / 2, canvas.GetHeight() / 2);

  Angle sun_azimuth(Angle::Degrees(-45));
  if (renderer.GetSettings().slope_shading == SlopeShading::SUN &&
      CommonInterface::Calculated().sun_data_available)
    sun_azimuth = CommonInterface::Calculated().sun_azimuth;

  renderer.Generate(projection, sun_azimuth);

#ifdef ENABLE_OPENGL
  /* enable clipping because the OpenGL terrain renderer uses a large
     texture that exceeds the window dimensions */
  GLCanvasScissor scissor(canvas);
#endif

  renderer.Draw(canvas, projection);
}
Exemplo n.º 5
0
void
BufferCanvas::Begin(Canvas &other)
{
  assert(IsDefined());
  assert(!active);

  Resize(other.GetSize());

  if (frame_buffer != NULL) {
    /* activate the frame buffer */
    frame_buffer->Bind();
    texture->AttachFramebuffer(FBO::COLOR_ATTACHMENT0);

    if (OpenGL::render_buffer_stencil == OpenGL::render_buffer_depth_stencil)
      /* we don't need a depth buffer, but we must attach it to the
         FBO if the stencil Renderbuffer has one */
      stencil_buffer->AttachFramebuffer(FBO::DEPTH_ATTACHMENT);

    stencil_buffer->AttachFramebuffer(FBO::STENCIL_ATTACHMENT);

    /* save the old viewport */
    old_translate = OpenGL::translate;
    old_size = OpenGL::screen_size;
    glPushMatrix();

    /* configure a new viewport */
    OpenGL::SetupViewport({GetWidth(), GetHeight()});
    OpenGL::translate = {0, 0};
  } else {
    offset = other.offset;
  }

  active = true;
}
//----------------------------------------------------------------------------
void EditRenderView_Scene::_ZoomCamera(float zoom)
{
	Canvas *canvas = PX2_PROJ.GetSceneCanvas();
	const Sizef &size = canvas->GetSize();

	Scene *scene = PX2_PROJ.GetScene();
	if (!scene) return;

	CameraActor *camActor = scene->GetUseCameraActor();

	if (camActor)
	{
		APoint position = camActor->LocalTransform.GetTranslate();
		AVector dir = camActor->GetCamera()->GetDVector();
		dir.Normalize();

		if (VT_PERSPECTIVE == mViewType)
		{
			position += dir*zoom;
			camActor->LocalTransform.SetTranslate(position);
		}
		else if (VT_TOP == mViewType)
		{
			float rMin = 0.0f;
			float rMax = 0.0f;
			float uMin = 0.0f;
			float uMax = 0.0f;
			float dMin = 0.0f;
			float dMax = 0.0f;
			float orthoFrustumMin = 1.0f;
			camActor->GetCamera()->GetFrustum(dMin, dMax, uMin, uMax, rMin, rMax);
			uMin += (zoom * 1.0f);
			if (uMin > -orthoFrustumMin)
				uMin = -orthoFrustumMin;
			uMax = -uMin;
			rMin = uMin * size.Width / size.Height;
			rMax = -rMin;

			camActor->GetCamera()->SetFrustum(dMin, dMax, uMin, uMax, rMin, rMax);
		}
		else if (VT_FRONT == mViewType)
		{
			float rMin = 0.0f;
			float rMax = 0.0f;
			float uMin = 0.0f;
			float uMax = 0.0f;
			float dMin = 0.0f;
			float dMax = 0.0f;
			float orthoFrustumMin = 1.0f;
			camActor->GetCamera()->GetFrustum(dMin, dMax, uMin, uMax, rMin, rMax);
			uMin += (zoom * 1.0f);
			if (uMin > -orthoFrustumMin)
				uMin = -orthoFrustumMin;
			uMax = -uMin;
			rMin = uMin * size.Width / size.Height;
			rMax = -rMin;

			camActor->GetCamera()->SetFrustum(dMin, dMax, uMin, uMax, rMin, rMax);
		}
	}
}
Exemplo n.º 7
0
 void Create(const Canvas &canvas) {
   Create(canvas, canvas.GetSize());
 }
Exemplo n.º 8
0
void
BufferCanvas::Create(const Canvas &canvas)
{
  Create(canvas, canvas.GetSize());
}
Exemplo n.º 9
0
void
BufferCanvas::Begin(Canvas &other)
{
  assert(IsDefined());
  assert(!active);

  Resize(other.GetSize());

  if (frame_buffer != nullptr) {
    /* activate the frame buffer */
    frame_buffer->Bind();
    texture->AttachFramebuffer(FBO::COLOR_ATTACHMENT0);

    if (OpenGL::render_buffer_stencil == OpenGL::render_buffer_depth_stencil)
      /* we don't need a depth buffer, but we must attach it to the
         FBO if the stencil Renderbuffer has one */
      stencil_buffer->AttachFramebuffer(FBO::DEPTH_ATTACHMENT);

    stencil_buffer->AttachFramebuffer(FBO::STENCIL_ATTACHMENT);

    /* save the old viewport */

#ifdef HAVE_GLES
    /* there's no glPushAttrib() on GL/ES; emulate it */
    glGetIntegerv(GL_VIEWPORT, old_viewport);
#else
    glPushAttrib(GL_VIEWPORT_BIT);
#endif

#ifdef USE_GLSL
    old_projection_matrix = OpenGL::projection_matrix;
    OpenGL::projection_matrix = glm::mat4();
#else
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
#endif

    old_translate = OpenGL::translate;
    old_size = OpenGL::viewport_size;

#ifdef SOFTWARE_ROTATE_DISPLAY
    old_orientation = OpenGL::display_orientation;
    OpenGL::display_orientation = DisplayOrientation::DEFAULT;
#endif

    /* configure a new viewport */
    OpenGL::SetupViewport({GetWidth(), GetHeight()});
    OpenGL::translate = {0, 0};

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#endif
  } else {
    offset = other.offset;
  }

#ifndef NDEBUG
  active = true;
#endif
}