Browse Source

Fix draw callback for main/properties views

Drawing position wasn't being calculated correctly, viewport/ortho
should have been used instead.  It would cause items to render out of
position on the main viewport (though not on the actual output)
jp9000 11 years ago
parent
commit
9edde0b892
2 changed files with 30 additions and 8 deletions
  1. 17 4
      obs/window-basic-main.cpp
  2. 13 4
      obs/window-basic-properties.cpp

+ 17 - 4
obs/window-basic-main.cpp

@@ -406,11 +406,24 @@ void OBSBasic::ChannelChanged(void *data, calldata_t params)
 void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
 {
 	OBSBasic *window = static_cast<OBSBasic*>(data);
-	gs_matrix_push();
-	gs_matrix_scale3f(window->previewScale, window->previewScale, 1.0f);
-	gs_matrix_translate3f(-window->previewX, -window->previewY, 0.0f);
+	obs_video_info ovi;
+	int newCX, newCY;
+
+	obs_get_video_info(&ovi);
+
+	newCX = int(window->previewScale * float(ovi.base_width));
+	newCY = int(window->previewScale * float(ovi.base_height));
+
+	gs_viewport_push();
+	gs_projection_push();
+	gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
+			-100.0f, 100.0f);
+	gs_setviewport(window->previewX, window->previewY, newCX, newCY);
+
 	obs_render_main_view();
-	gs_matrix_pop();
+
+	gs_projection_pop();
+	gs_viewport_pop();
 
 	UNUSED_PARAMETER(cx);
 	UNUSED_PARAMETER(cy);

+ 13 - 4
obs/window-basic-properties.cpp

@@ -77,15 +77,24 @@ void OBSBasicProperties::DrawPreview(void *data, uint32_t cx, uint32_t cy)
 	uint32_t sourceCY = obs_source_getheight(window->source);
 
 	int   x, y;
+	int   newCX, newCY;
 	float scale;
 
 	GetScaleAndCenterPos(sourceCX, sourceCY, cx, cy, x, y, scale);
 
-	gs_matrix_push();
-	gs_matrix_scale3f(scale, scale, 1.0f);
-	gs_matrix_translate3f(-x, -y, 0.0f);
+	newCX = int(scale * float(sourceCX));
+	newCY = int(scale * float(sourceCY));
+
+	gs_viewport_push();
+	gs_projection_push();
+	gs_ortho(0.0f, float(sourceCX), 0.0f, float(sourceCY),
+			-100.0f, 100.0f);
+	gs_setviewport(x, y, newCX, newCY);
+
 	obs_source_video_render(window->source);
-	gs_matrix_pop();
+
+	gs_projection_pop();
+	gs_viewport_pop();
 }
 
 void OBSBasicProperties::resizeEvent(QResizeEvent *event)