0

I'm trying to test a simple SDL2 application. The app runs without any errors. However, no window shows up.

I'm using Ubuntu18.04 on a VMWare machine. I also tried to compile SDL from the source but got the same result. I am unsure if the cause of the problem is related to my OS or because of executing from a virtual machine.

Here is a simple application from docs (I just added SDL_GetNumDisplayModes to make sure the display mode is OK- returns 1)

// Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>

// Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main(int argc, char *args[])
{

    // The window we'll be rendering to
    SDL_Window *window = NULL;

    // The surface contained by the window
    SDL_Surface *screenSurface = NULL;

    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    }
    else
    {
        int res = SDL_GetNumDisplayModes(0);
        printf("SDL_GetNumDisplayModes: %d\r\n", res);
        // Create window
        window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == NULL)
        {
            printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
        }
        else
        {
            // Get window surface
            screenSurface = SDL_GetWindowSurface(window);

            // Fill the surface white
            SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));

            // Update the surface
            SDL_UpdateWindowSurface(window);

            // Hack to get window to stay up
            SDL_Event e;
            bool quit = false;
            while (quit == false)
            {
                while (SDL_PollEvent(&e))
                {
                    if (e.type == SDL_QUIT)
                    {
                        quit = true;
                    }
                }
            }
        }
    }

    // Destroy window
    SDL_DestroyWindow(window);

    // Quit SDL subsystems
    SDL_Quit();

    return 0;
}
Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67
  • does this VM have GPU available? – user7860670 Feb 06 '23 at 11:13
  • Move your redraw to main loop (right after `while(PollEvent){}`) (all 3 lines, get surface, fill, present). If problem persists, try dumping events you're getting (at least `e.type`) and add result to question. What SDL version do you use? Can you reproduce this problem on other system? Does it happen on your non-vm OS? – keltar Feb 06 '23 at 12:30
  • @user7860670 What do you mean? I don't think VMWare supports dedicated GPU. – Masoud Rahimi Feb 07 '23 at 12:47
  • I doubt that SDL applications can run without hardware GPU. – user7860670 Feb 07 '23 at 12:58
  • @keltar I tried what you said, but no luck. BTW the code has been copied from the docs. The version is 2.28, and I tried that on other VMs and got the same behavior. I think the problem is with the VM. Unfortunately, I don't have a UNIX host. – Masoud Rahimi Feb 07 '23 at 13:04
  • @user7860670 The only option VMWare has is "3D graphics" which I already turned it on. Without it I will get `VMWare: No 3D enabled` error. – Masoud Rahimi Feb 07 '23 at 13:05

0 Answers0