+ // This works by adding black borders around the screen to limit
+ // SCREEN_WIDTH/SCREEN_HEIGHT to max_width/max_height
+ int nw = w;
+ int nh = h;
+
+ if (SCREEN_WIDTH > max_width)
+ {
+ nw *= float(max_width)/SCREEN_WIDTH;
+ SCREEN_WIDTH = max_width;
+ }
+
+ if (SCREEN_HEIGHT > max_height)
+ {
+ nh *= float(max_height)/SCREEN_HEIGHT;
+ SCREEN_HEIGHT = max_height;
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ std::cout << (w-nw)/2 << " "
+ << (h-nh)/2 << " "
+ << nw << "x" << nh << std::endl;
+ glViewport(std::max(0, (w-nw)/2),
+ std::max(0, (h-nh)/2),
+ std::min(nw, w),
+ std::min(nh, h));