Center the display on top of the checkerboard.

This commit is contained in:
Unknown W. Brackets 2013-09-22 20:40:13 -07:00
parent 4021acd3f8
commit 0ad5bcf1df
3 changed files with 10 additions and 3 deletions

View file

@ -147,7 +147,7 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
if (bufferResult) {
if (buffer.GetFormat() == GE_FORMAT_8888) {
frameWindow->Draw(buffer.GetData(), buffer.GetStride(), buffer.GetHeight(), SimpleGLWindow::RESIZE_SHRINK_FIT);
frameWindow->Draw(buffer.GetData(), buffer.GetStride(), buffer.GetHeight(), SimpleGLWindow::RESIZE_SHRINK_CENTER);
} else {
ERROR_LOG(COMMON, "Non-8888 buffers not yet supported.");
frameWindow->Clear();

View file

@ -224,7 +224,8 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
glsl_bind(drawProgram_);
float fw = (float)w, fh = (float)h;
if (resize == RESIZE_SHRINK_FIT) {
float x = 0.0f, y = 0.0f;
if (resize == RESIZE_SHRINK_FIT || resize == RESIZE_SHRINK_CENTER) {
float wscale = fw / w_, hscale = fh / h_;
// Too wide, and width is the biggest problem, so scale based on that.
@ -235,8 +236,13 @@ void SimpleGLWindow::Draw(u8 *data, int w, int h, ResizeType resize) {
fw /= hscale;
fh = (float)h_;
}
if (resize == RESIZE_SHRINK_CENTER) {
x = ((float)w_ - fw) / 2;
y = ((float)h_ - fh) / 2;
}
}
const float pos[12] = {0,0,0, fw,0,0, fw,fh,0, 0,fh,0};
const float pos[12] = {x,y,0, x+fw,y,0, x+fw,y+fh,0, x,y+fh,0};
const float texCoords[8] = {0,1, 1,1, 1,0, 0,0};
const GLubyte indices[4] = {0,1,3,2};

View file

@ -27,6 +27,7 @@ struct SimpleGLWindow {
enum ResizeType {
RESIZE_NONE,
RESIZE_SHRINK_FIT,
RESIZE_SHRINK_CENTER,
};
SimpleGLWindow(HINSTANCE hInstance, HWND hParent, int x, int y, int w, int h);