# How to position objects responsively in SDL?

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.

• 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. Dec 3 '17 at 17:00
• 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; Dec 3 '17 at 22:58
• 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. Dec 3 '17 at 23:00
• 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. Dec 3 '17 at 23:26
• 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? Dec 4 '17 at 4:34

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).