2
\$\begingroup\$

I have an SDL window using SDL_WINDOW_FULLSCREEN_DESKTOP (as opposed to SDL_WINDOW_FULLSCREEN, which doesn't work properly)

When I try to place stuff on the screen, it is placed in the wrong location on Fullscreen mode rather than windowed mode. Since fullscreen and windowed seem to have different proportions/placements, I'm wondering what the best way is to accurately place images on the screen in both windowed and fullscreen mode.

I need to "convert" or "adapt" placement from windowed to fullscreen, so it looks right when fullscreen is toggled.

\$\endgroup\$
  • 1
    \$\begingroup\$ You should show some code that you currently use to render the stuff on the screen. Images of the results in fullscreen and windowed mode would also help. \$\endgroup\$ – Tyyppi_77 Dec 3 '17 at 17:00
  • \$\begingroup\$ Code for rendering text to the screen: (This is the part where I try to compensate for fullscreen) dialogTex = SDL_CreateTextureFromSurface(renderer, message); SDL_QueryTexture(dialogTex, NULL, NULL, &texW, &texH); if (fullscreen == 1) { cout << "DIVISION" << endl; xpos += ADAPTATION; ypos -= ADAPTATION; } SDL_Rect destRect; destRect.x = xpos; destRect.y = ypos; destRect.w = texW; destRect.h = texH; \$\endgroup\$ – Eyesight Technology Dec 3 '17 at 22:58
  • \$\begingroup\$ The only thing that looks different is that when the text is rendered it is up and to the left of its should-be position. \$\endgroup\$ – Eyesight Technology Dec 3 '17 at 23:00
  • \$\begingroup\$ Nevermind, I found that specific issue. But nevertheless, I still need a reliable way to scale/position text and images in fullscreen AND windowed. Right now, I can't seem to come up with a reliable conversion/resize that works with everything. \$\endgroup\$ – Eyesight Technology Dec 3 '17 at 23:26
  • \$\begingroup\$ I think you need to specify where you're trying to render things and what kind of coordinate system you use. Percentage based positioning keeps distances relative, but might break a lot of things, if sizes are fixed. Fixed coordinates appear always at the same position no matter what the coordinates are, but things at the right and bottom might get clipped. What exactly are you trying to accomplish here? Responsive UI? Something else? \$\endgroup\$ – Tyyppi_77 Dec 4 '17 at 4:34
1
\$\begingroup\$

So the first step is to calculate positions using the size of the window. You probably want to use percentages to define the position of an object inside the window. That should result in relatively responsive UI design.

However, there's a small catch here. If you keep the origin of the object that you want to position in the top-left, you might end up with objects not fitting inside the window, and positioning in general can be a big pain.

A nice and generic way to fix this would be to add an anchor vector, that describes where the object's origin is. The vector values should be in the range [0, 1], where 0 is top/left and 1 is bottom/right.

So, if pos is the percentage position inside the window, and origin is the anchor position as described above, the final render position can be calculated as result = pos * windowSize - origin * objectSize; (component wise vector multiplication).

So centering an object would mean setting both pos and origin to vec2(0.5, 0.5).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.