Jump to content
  • Advertisement
Sign in to follow this  
Acharis

SDL2 + OpenGL how to open screen properly (Win 8.1 problems)

This topic is 998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get a rare bug with Window 8.1 (on some computers only) regarding fullscreen. The screen is "cut" (right part is not displayed) and/or mouse does not map properly on the screen (but that one is rarer). It's on some machines only and I'm unable to recreate the bug.

 

The problem is identical for SDL_WINDOW_FULLSCREEN_DESKTOP and SDL_WINDOW_FULLSCREEN.

 

 

Here is what my open screen code does:

 

SDL_init()
SDL_GL_SetAttribute()
SDL_GetDesktopDisplayMode() to get desktop width & height
flags = SDL_WINDOW_OPENGL & SDL_WINDOW_FULLSCREEN_DESKTOP
SDL_CreateWindow("Unnamed window",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, ..., flags)
SDL_SetWindowMinimumSize()
SDL_GL_CreateContext(sdlWindow);
SDL_GL_SetSwapInterval( enablevsync ); to enable/disable vsync
GL clear, GL hints, GL viewport, GL perspective, etc
SDL_SetWindowTitle();
SDL_SetWindowIcon()
SDL_SetWindowGrab(sdlWindow,SDL_FALSE);

Share this post


Link to post
Share on other sites
Advertisement

Can you show the actual code you use to do this. Also do you have any info about the computers that have this problem, do they have multiple monitors or anything? Seeing your full initialisation code will help.

Share this post


Link to post
Share on other sites

I suppose that & should be a | instead? This pseudo-pseudo-code really isn't helping...

 

Also by any chance does DPI have an influence on it? Since I'm not seeing you marking the window as high DPI aware.

Share this post


Link to post
Share on other sites

Can you show the actual code you use to do this. Also do you have any info about the computers that have this problem, do they have multiple monitors or anything? Seeing your full initialisation code will help.

Just standard stuff, like a laptop, no suspicious features (except posession of the Win 8.1 biggrin.png). Besides, I use it on dual monitors without problems, so unles Win 8.1 handles it differently it should not be the problem.

 

 

 

The code (yes, I know it's messy smile.png):

int easydrawInit(int w, int h,int fullscreen,int enableaudio)
{
    Config.screenwidth=w; Config.screenheight=h; Config.fullscreen=fullscreen;
    EasyDrawSystem.gldrawpixelsmode=0; // Always in this version!
    int enablevsync=Config.vsync;
    if(!enablevsync) Debug("Vsync disabled.\n");

    //SDL_putenv("SDL_VIDEODRIVER=directx"); //! PORTABILITY PROBLEM !
    //SDL_putenv("SDL_VIDEODRIVER=opengl"); //! PORTABILITY PROBLEM !
    //SDL_SetEnv(SDL_VIDEODRIVER,"directx");
    //SDL_envvars();
    //SDL_SetHint(SDL_HINT_RENDER_VSYNC,0);
    //SDL_putenv("SDL_VIDEO_CENTERED=center");
    //SDL_SetHint(SDL_HINT_RENDER_VSYNC,0);
    //SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 );

    if(enableaudio) {if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) return 0;}
    else {if(SDL_Init(SDL_INIT_VIDEO) < 0 ) return 0;}

    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

    if(strlen(SDL_GetError())) {Debug("easydrawInit() '%s'",SDL_GetError()); SDL_ClearError();}

    // Create an application window with the following settings:
    int flags=SDL_WINDOW_OPENGL;
    if(fullscreen==0) flags|=SDL_WINDOW_RESIZABLE;
    if(fullscreen==2) flags|=SDL_WINDOW_FULLSCREEN;
    //if(fullscreen==1) flags|=SDL_WINDOW_FULLSCREEN_DESKTOP;
    if(fullscreen==1) flags|=SDL_WINDOW_BORDERLESS;
    if(fullscreen==1)
    {
        SDL_DisplayMode dm;
        if(SDL_GetDesktopDisplayMode(0, &dm) != 0)    {Log.e("easydrawInit()  SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());}
        Config.screenwidth=dm.w;
        Config.screenheight=dm.h;
    }
    if(fullscreen<0 || fullscreen>2) {Log.fe("easydrawInit() invalid 'fullscreen' param.\n");}

    sdlWindow = SDL_CreateWindow("Unnamed window",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, Config.screenwidth,Config.screenheight, flags); // will be renamed in UpdateWindow below
    if(sdlWindow==NULL) {Debug("Could not create window: %s\n", SDL_GetError()); return 0;}
    SDL_SetWindowMinimumSize(sdlWindow,Config.minscreenwidth,Config.minscreenheight);

    SDL_GLContext glcontext = SDL_GL_CreateContext(sdlWindow);
    SDL_GL_SetSwapInterval( enablevsync );

    easydrawUpdateWindow(); // set OpenGL, set window icon, etc

    Config.newscreenwidth=Config.screenwidth; Config.newscreenheight=Config.screenheight; Config.newfullscreen=Config.fullscreen; Config.newvsync=Config.vsync; Config.newconfinemousetowindow=Config.confinemousetowindow;

    //char buf[256]; SDL_VideoDriverName(buf,256); Debug("VideoDriverName: %s\n",buf);
    Debug("Screen Opened %dx%d Fullscreen:%d Flags:%d\n",Config.screenwidth,Config.screenheight, Config.fullscreen,flags);
       Debug("Platform: %s\n", SDL_GetPlatform());
    Debug("OpenGL Vendor: %s\n", glGetString( GL_VENDOR ) );
    Debug("OpenGL Renderer: %s\n", glGetString( GL_RENDERER ) );
    Debug("OpenGL Version: %s\n", glGetString( GL_VERSION ) );
    //Debug("OpenGL Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
    int value;    SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &value );    Debug("SDL_GL_ACCELERATED_VISUAL: %d\n", value );
    //SDL_GL_GetAttribute( SDL_GL_SWAP_CONTROL, &value );    Debug("SDL_GL_SWAP_CONTROL: %d\n", value );
    //const SDL_VideoInfo* ptr = SDL_GetVideoInfo(); Debug("VRAM: %dKb\n",ptr->video_mem); Debug("SDL Hardware acceleration status: %d,%d,%d,%d\n",ptr->hw_available, ptr->blit_hw, ptr->blit_hw_A, ptr->blit_hw_CC);
    Debug("OpenGLExtension GL_ARB_texture_rectangle: %d\n", easydrawINTERNAL_glQueryExtension("GL_ARB_texture_rectangle"));
    Debug("OpenGLExtension ARB_texture_non_power_of_two: %d\n", easydrawINTERNAL_glQueryExtension("ARB_texture_non_power_of_two"));
    //GLint texture_units; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &texture_units); Debug("GL_MAX_TEXTURE_IMAGE_UNITS: %d\n", texture_units); // per shader?
    //GLint combined_texture_units; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &combined_texture_units); Debug("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d\n", combined_texture_units); // total?
    GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); Debug("OpenGL Max texture size: %d\n", texSize);
    //GLint maxLights; glGetIntegerv(GL_MAX_LIGHTS , &maxLights); Debug("OpenGL MAX_LIGHTS: %d\n", maxLights);
    Debug("VideoDriver: %s\n",SDL_GetCurrentVideoDriver());
    Debug("NumVideoDrivers: %d NumVideoModes: %d NumDisplayModes: %d\n",SDL_GetNumVideoDrivers(),SDL_GetNumVideoDisplays(),SDL_GetNumDisplayModes(0));
    //Debug("[config] glDrawPixelsMode: %d\n",EasyDrawSystem.gldrawpixelsmode);
    Debug("Number of logical CPU cores: %d\nSystem Memory: %d MB\n", SDL_GetCPUCount(),SDL_GetSystemRAM());

    SDL_version compiled_version,link_version; SDL_VERSION(&compiled_version); SDL_GetVersion(&link_version);
    Debug("SDL_version - CompiledVersion: %d.%d.%d  ", compiled_version.major,compiled_version.minor,compiled_version.patch);
    Debug("LinkedVersion: %d.%d.%d\n", link_version.major, link_version.minor, link_version.patch);


    //Initialize PNG loading
    #ifdef EASYDRAW_ENABLE_SDLIMAGE
    {
    int imgFlags = IMG_INIT_PNG;
    if(!(IMG_Init(imgFlags) & imgFlags)) {Debug( "SDL_image could not initialize! SDL_image Error: %s\n",IMG_GetError());}
    SDL_version compile_version; SDL_IMAGE_VERSION(&compile_version); const SDL_version *link_version=IMG_Linked_Version();
    Debug("SDL_image_version - CompiledVersion: %d.%d.%d  ", compile_version.major, compile_version.minor, compile_version.patch);
    Debug("LinkedVersion: %d.%d.%d\n", link_version->major, link_version->minor, link_version->patch);
    }
    #endif

    //Config.logeasydraw=Config.logfont=1; Debug("[notice] Changed Config to allow logging (in easydrawInit()).\n");
    if(!Config.logeasydraw) Debug("Disabled log easydraw.\n");
    if(!Config.logfont) Debug("Disabled log font.\n");

    if(strlen(SDL_GetError())) {Debug("easydrawInit() '%s'",SDL_GetError()); SDL_ClearError();}

    return 1;
}



void easydrawUpdateWindow() // Run it after window resize/screen resolution change
{
	/*
	1. GL clear, GL hints, GL viewport, GL perspective, etc
	2. SDL_SetWindowTitle(sdlWindow,buf);
	3. SDL_SetWindowIcon()
	4. SDL_SetWindowGrab(sdlWindow,SDL_FALSE);
	*/

	int width=Config.screenwidth; int height=Config.screenheight;
	Debug("easydrawUpdateWindow(%dx%d)\n",width,height);

	// OpenGL
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glEnable(GL_BLEND);     // Turn Blending On
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glShadeModel(GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);                         // The Type Of Depth Testing To Do
	glClearDepth(1.0f);                         // Depth Buffer Setup
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);          // Really Nice Perspective
    /* Our shading model--Gouraud (smooth). */
    glShadeModel( GL_SMOOTH );
    /* Culling. */
    glCullFace( GL_BACK );
    glFrontFace( GL_CCW );
    glEnable( GL_CULL_FACE );
    /* Set the clear color. */
    glClearColor( 0, 0, 0, 0 );

    /* Setup our viewport. */
    glViewport( 0, 0, width, height );

    /* Change to the projection matrix and set our viewing volume.  */
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );

	float ratio = (float) width / (float) height;
    gluPerspective( 60, ratio, 1.0, 1024.0 );

    // SDL (app icon and window name)
    char buf[256]; snprintf(buf,255,"%s %s",GAMENAME,GAMEVERSION);	SDL_SetWindowTitle(sdlWindow,buf);
  	SDL_SetWindowIcon(sdlWindow,IMG_Load("data/images/system/icon.png"));
	// Window grab (confine mouse to window)
  	if(Config.confinemousetowindow && Config.fullscreen!=0) SDL_SetWindowGrab(sdlWindow,SDL_TRUE); else SDL_SetWindowGrab(sdlWindow,SDL_FALSE);

  	if(strlen(SDL_GetError())) {Debug("easydrawUpdateWindow() '%s'",SDL_GetError()); SDL_ClearError();}
}

Share this post


Link to post
Share on other sites

Found a dirty fix, go to file's compatibility tab and echeck 'Disable display scaling on high DPI settings'. It fixes it.

 

Is there a way to do it on the SDL level? Tried to add "SDL_WINDOW_ALLOW_HIGHDPI" to openwindow flags but it does not do the trick...

Share this post


Link to post
Share on other sites

Got it.To anyone having the same problem, use: SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED,"1");

Share this post


Link to post
Share on other sites

Windows 8.1 has three versions (latest was Update 3 when I upgraded to Windows 10) , maybe check if it's latest one might reveal that it's already fixed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!