Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resize the OpenGL view larger than the size passed to the initial SDL_SetVideoMode?
    primarykey
    data
    text
    <p>I use OpenGL with the SDL and I want to keep the scene adjusted to the window when the latter is resized. For an unknown reason the scene is cropped at the initial window size when the window becomes larger.</p> <p>The function used to adjust the view in response to a SDL_VIDEORESIZE is the following, where m_scene_{width,height} is the size of the view as seen by the game.</p> <pre><code>void screen::resize_view( width, height ) { // t will force the scene to be rendered with the top left corner matching the // one of the window. int t; if ( height &lt; m_size.y ) t = m_size.y - height; else t = 0; glViewport( 0, t, width, height ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0, m_scene_width, 0, m_scene_height, -1, 0 ); glMatrixMode(GL_MODELVIEW); } </code></pre> <p>To initialize the window, I call</p> <pre><code>SDL_SetVideoMode( m_scene_width, m_scene_height 32, SDL_OPENGL | SDL_RESIZABLE ); resize_view( m_scene_width, m_scene_height ); </code></pre> <p>With this code, I have an initial window whose size matches the size of the view. Then if I reduce the size of the window on one or both dimension, the scene is effectively stretched to fit the window, with the top-left corner staying fixed.</p> <p>But, if I enlarge the window on one or both dimensions, the scene becomes cropped on the right and the bottom as soon as the window become larger than the initial size passed to SDL_SetVideoMode(). Even if the content of the scene is effectively stretched to the expected size, these parts of the screen remain black.</p> <p>Note that if I set glClearColor() to red, these parts are still black.</p> <p>The only solution I have now is to call SDL_SetVideoMode() with the new size each time the window is resized, which is not acceptable since it invalidates the GL context on Windows and invalidates all the textures.</p> <p><strong>Edit:</strong> After some experiments I think that the black area is the result of the SDL_Surface initially created, that does not follow the size of the window. Thus, if I can resize this surface without destroying the GL context, I suppose it would solve my problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload