|
In full screen mode, the display stretches to full screen |
Alexander Zhirov
Member #17,695
May 2020
|
Allegro display resolution 4x3. Monitor resolution 16x9. How to make the display not stretch to full screen in fullscreen mode? So that there are indents on the sides of the monitor if the formats do not match. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Here's some simple code I use to make an image fit within a rectangle. 1void EagleGraphicsContext::DrawImageFit(EagleImage* img , Rectangle dest , EagleColor tint , int flags) {
2 EAGLE_ASSERT(img && img->Valid() && img->Area());
3
4
5 const double hratio = dest.W() / (double)img->W();
6 const double vratio = dest.H() / (double)img->H();
7 const double minratio = (hratio < vratio)?hratio:vratio;
8
9 const double imgw = img->W() * minratio;
10 const double imgh = img->H() * minratio;
11
12 Rectangle dest2(dest.CX() - imgw/2.0 ,
13 dest.CY() - imgh/2.0 ,
14 imgw ,
15 imgh
16 );
17
18// Clipper clip(img , dest);
19
20 DrawTintedStretched(img , dest2 , tint , flags);
21
22}
The display takes whatever resolution you set it to. You have to scale / pad the image on the display yourself. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Alexander Zhirov
Member #17,695
May 2020
|
1struct MainScreen* scr_create_mainscreen(float factor, bool fullscreen, bool resolution, unsigned short width, unsigned short height)
2{
3 struct MainScreen* mainScreen = (struct MainScreen*)malloc(sizeof(struct MainScreen));
4 show_message_error(mainScreen, "Не удалось выделить место для MainScreen");
5
6 Display* display = XOpenDisplay(NULL);
7 show_message_error(display, "Не удалось открыть XDisplay");
8
9 Screen* screen = XDefaultScreenOfDisplay(display);
10
11 mainScreen->display = NULL;
12 mainScreen->FPS = 60;
13 mainScreen->full_width = screen->width;
14 mainScreen->full_height = screen->height;
15
16 if((float)factor >= 0.1 && (float)factor < 1.0)
17 mainScreen->factor = factor;
18 else if((float)factor >= 1.0)
19 {
20 mainScreen->fullscreen = true;
21 mainScreen->factor = 1.0;
22 }
23 else
24 mainScreen->factor = 0.5;
25
26 if(resolution)
27 {
28 if(width >= 320)
29 mainScreen->width = width;
30 else
31 mainScreen->width = 320;
32
33 if(height >= 240)
34 mainScreen->height = height;
35 else
36 mainScreen->height = 240;
37 }
38 else
39 {
40 mainScreen->width = mainScreen->full_width * mainScreen->factor;
41 mainScreen->height = mainScreen->full_height * mainScreen->factor;
42 }
43
44 if(!mainScreen->fullscreen)
45 mainScreen->fullscreen = fullscreen;
46
47 if(mainScreen->fullscreen)
48 {
49 mainScreen->scale_factor_x = (float)mainScreen->full_width / mainScreen->width;
50 mainScreen->scale_factor_y = (float)mainScreen->full_height / mainScreen->height;
51 }
52
53 XCloseDisplay(display);
54
55 return mainScreen;
56}
57
58void scr_free(struct MainScreen* mainScreen)
59{
60 al_destroy_display(mainScreen->display);
61 free(mainScreen);
62}
63
64void scr_create_display(struct MainScreen* mainScreen)
65{
66 if(mainScreen->fullscreen)
67 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
68
69 mainScreen->display = al_create_display(mainScreen->width, mainScreen->height);
70 show_message_error(mainScreen->display, "Не удалось инициализировать дисплей");
71
72 if(mainScreen->fullscreen) // если фуллскрин
73 {
74 ALLEGRO_TRANSFORM t;
75 al_identity_transform(&t);
76 al_scale_transform(&t, mainScreen->scale_factor_x, mainScreen->scale_factor_y);
77 al_use_transform(&t);
78 }
79}
I use scaling. I just don’t understand how to fit a square image into a rectangular one so that it does not stretch to the full screen. If the resolution is true, then I want to use the resolution passed by the width and height parameters. But my image is stretched to full screen and distorted. I want it to be in the center. So that in full screen there are indents on the sides. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Calculate the scale for the width and height and use the minimum value for your scaling. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
MikiZX
Member #17,092
June 2019
|
Possibly you need to, once the switch to fullscreen mode is made, re-create Allegro's display in the 16:9 monitor's native resolution (or at least 16:9 aspect ratio) and then draw your Allegro 4:3 content centered on the screen and scalled appropriately. |
Alexander Zhirov
Member #17,695
May 2020
|
Well, after a few days, I still implemented a mechanism for changing the resolution of the display image. Here is a demo, and here is the source code. P.S.Please do not swear::) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Why don't you just check the resolution of the monitor and set your allegro display accordingly using allegro? 1#include "allegro5/allegro.h"
2
3int main(int argc , char** argv) {
4 (void)argc;
5 (void)argv;
6
7 if (!al_init()) {return -1;}
8 const int NMON = al_get_num_video_adapters();
9 for (int i = 0 ; i < NMON ; ++i) {
10 ALLEGRO_MONITOR_INFO info;
11 al_get_monitor_info(i , &info) {
12 printf("Adapter #%d is %d x %d at %d,%d\n" , i , info.x2 - info.x1 , info.y2 - info.y1 , info.x1 , info.y1);
13 }
14 }
15
16 return 0;
17}
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Alexander Zhirov
Member #17,695
May 2020
|
Edgar Reynaldo said: Why don't you just check the resolution of the monitor and set your allegro display accordingly using allegro? Oh, how could that be? I did not even know that Allegro has its own methods of obtaining information about the monitor. I will take advantage of your offer. Thanks!:) |
Chris Katko
Member #1,881
January 2002
|
It's fine to have an algorithmic solution but have you considered just using your graphics drivers to do it? In Windows, nVidia (and 99% sure AMD) let you set the scaling mode for lower size resolutions. For nvidia it's under Adjust Desktop Size and Position. -----sig: |
Niunio
Member #1,975
March 2002
|
That would be a solution, Chris, but most people just don't deal with driver configuration (or even know it is possible to) and blame the game because it doesn't look nice. My engine gets monitor resolution or the window size and the desired resolution, then creates a backbuffer with the desired resolution and scales it properly drawing in the correct position. This code calculates the size and offset while this other is the actual rendering. ----------------- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
To be fair, this is driver dependent behavior. Nothing allegro can do about it but adapt. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|