Display code has been corrected. Pulls in an image and displays it properly.

This commit is contained in:
Matt McWilliams 2024-04-02 18:03:14 -04:00
parent 55ce42ef61
commit fadb04a29c
1 changed files with 17 additions and 3 deletions

View File

@ -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();