Get screen width and height after fullscreen started

This commit is contained in:
mmcwilliams 2024-04-01 11:09:59 -04:00
parent 801a56a78f
commit 0f42160ee9
1 changed files with 21 additions and 11 deletions

View File

@ -20,9 +20,27 @@ using namespace std;
Mat image;
GLuint imageTexture;
GLint screenWidth = 0;
GLint screenHeight = 0;
void displayMe(void)
{
if (screenWidth == 0 && screenHeight == 0) {
GLint dims[4] = {0};
glGetIntegerv(GL_VIEWPORT, dims);
screenWidth = dims[2];
screenHeight = dims[3];
cout << screenWidth << "," << screenHeight << endl;
}
string image_path = samples::findFile("chart.png");
Mat image = imread(image_path, IMREAD_COLOR);
#if (CV_VERSION_MAJOR >= 4)
cvtColor(image, image, cv::COLOR_BGR2RGB);
#else
cvtColor(image, image, CV_BGR2RGB);
#endif
// Set every pixel in the frame buffer to the current clear color.
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
@ -38,23 +56,15 @@ void displayMe(void)
int main(int argc, char** argv)
{
string image_path = samples::findFile("chart.png");
Mat image = imread(image_path, IMREAD_COLOR);
#if (CV_VERSION_MAJOR >= 4)
cvtColor(image, image, cv::COLOR_BGR2RGB);
#else
cvtColor(image, image, CV_BGR2RGB);
#endif
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(1920, 1080);
glutInitWindowPosition(0, 0);
glutCreateWindow("opengl_opencv_example");
glutFullScreen();
glutDisplayFunc(displayMe);
glutMainLoop();
return 0;
}