From fadb04a29c220f7e1fd4d568c9646330456d6555 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 2 Apr 2024 18:03:14 -0400 Subject: [PATCH] Display code has been corrected. Pulls in an image and displays it properly. --- main.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index e47bdaf..9322cd7 100644 --- a/main.cpp +++ b/main.cpp @@ -25,19 +25,32 @@ GLint screenWidth = 0; GLint screenHeight = 0; time_stamp ts; +/** + * rows = height + * cols = width + **/ void loadTexture (GLuint& imageTexture1) { string image_path = samples::findFile("chart.png"); Mat loaded = imread(image_path, IMREAD_COLOR); - Mat image = Mat::zeros(screenWidth, screenHeight, CV_8UC3); + Mat image = Mat::zeros(screenHeight, screenWidth, CV_8UC3); + //Mat resized = Mat::zeros(1080, 1280, CV_8UC3) cout << "created image" << endl; if (image.empty()) { cout << "image empty" << endl; } else { cout << "loaded " << image_path << endl; cout << " dim " << loaded.cols << "x" << loaded.rows << endl; - loaded.copyTo(image(Rect(0, 0, loaded.cols, loaded.rows))); + + //resize(loaded, resized, Size(1280, 1080)); + cout << " image " << image.cols << "x" << image.rows << endl; + //cout << "resized " << resized.cols << "x" << resized.rows << endl; + //resized.copyTo(image(Rect(0, 0, resized.cols, resized.rows))); + uint32_t offsetX = (image.cols - loaded.cols) >> 1; + uint32_t offsetY = (image.rows - loaded.rows) >> 1; + loaded.copyTo(image(Rect(offsetX, offsetY, loaded.cols, loaded.rows))); flip(image, image, 0); + #if (CV_VERSION_MAJOR >= 4) cvtColor(image, image, cv::COLOR_BGR2RGB); #else @@ -87,7 +100,7 @@ void display(void) glViewport(0, 0, screenWidth, screenHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBindTexture(GL_TEXTURE_2D, imageTexture); glBegin(GL_QUADS); // front face @@ -97,6 +110,7 @@ void display(void) glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); //bottom left glEnd(); glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); glutSwapBuffers(); //glFlush();