(Termuxo Sdl rendering simple message box but not created window

So I’m following Handmade Hero purely off my phone during downtime and basing off of handmade penguin’s adaptation over to linux.

I get execution properly blocking the console on the simple message box dialog, and it renders in termux x11 if i move the mouse over to its location in the x11 app, but I’m never able to see the window render directly after.

❯ ./out/handmade
INFO: Starting application with verbose logging...
DEBUG: Couldn't load font -*-*-medium-r-normal--*-120-*-*-*-*-*-*
DEBUG: That operation is not supported
INFO: OpenGL shaders: ENABLED
INFO: Created renderer: opengl
INFO: Created renderer: software

No clue about the font issue, is that possibly the cause? The last 4 log entries happen directly after the SDL renderer gets called in

Source:

int main(int argc, char *argv[]) {
  SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
  SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
  SDL_Log("Starting application with verbose logging...");
                                                                        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello", "Hello
, World!", 0);

  bool sdlInitialised = SDL_Init(SDL_INIT_VIDEO) == 0;
  if (!sdlInitialised) {                                                  SDL_Log("Failed SDL Init %s\n", SDL_GetError());
    return Quit();
  }

  SDL_Window *Window =
      SDL_CreateWindow("Handmade",
          0, 0, 320, 480,
          SDL_WINDOW_RESIZABLE);

  if (!Window) {
    SDL_Log("Post Window SDL Error: %s\n", SDL_GetError());
    return Quit();
  }

  SDL_Renderer *Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER
_SOFTWARE);

  if (!Renderer) {
    SDL_Log("Post Renderer SDL Error: %s\n", SDL_GetError());
    return Quit();
  }

  for(;;)
  {
    SDL_Event Event;
    SDL_WaitEvent(&Event);
    if (HandleEvent(&Event))
    {
        break;
    }
  }
}

I’ll try pasting the link to repo but I don’t trust my phone not to lose this writeup while I hunt around for it.

Actual source: Handmade/code/sdl_handmade.cpp at b4ead74f07824e579eedecec929a6684598beb34 · BenVella/Handmade · GitHub

Please add RenderPresent() and RenderClear() in your function HandleWindowEvent() like the following code:

bool HandleWindowEvent(SDL_WindowEvent *winEvent) {
  switch (winEvent->event) {
    case SDL_WINDOWEVENT_RESIZED: {
      printf("SDL_WINDOWEVENT_RESIZED (%d, %d)\n", winEvent->data1, winEvent->data2);
    } break;
    case SDL_WINDOWEVENT_EXPOSED:
    {
      SDL_Window *Window = SDL_GetWindowFromID(winEvent->windowID);
      SDL_Renderer *Renderer = SDL_GetRenderer(Window);
      static bool IsWhite = true;
      if (IsWhite)
      {
        SDL_SetRenderDrawColor(Renderer, 0, 255, 0, 255);
      }
      else
      {
        SDL_SetRenderDrawColor(Renderer, 255, 0, 0, 255);
      }
      SDL_RenderPresent(Renderer); // add this
      SDL_RenderClear(Renderer); // two lines
      IsWhite = !IsWhite;
    } break;

  }
  return false;
}

1 Like

Thanks! That worked to render without issue! It looks like the font and unsupported platform error do persist and I have no way of resizing the resizable window since it just doesn’t show anything besides the rendered colors, but that’s not such a big deal