Use SDL2 instead of win32 api

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Use SDL2 instead of win32 api

Postby linarcx » Mon Feb 08, 2021 9:03 am

Hi.

I want to use SDL2 instead of win32 api, most specifically to create a window and handle events.Here is what i'v done so far:
https://gist.github.com/LinArcX/0e9653b ... 9b50282114

Application compiled successfully but when i want to run it, it crashes.

SDL: 2.0.14
CMAKE: 3.18.4
Visual Studio: 2019
CEF: 88.2.1+g0b18d0b+chromium-88.0.4324.146
Windows: 7
linarcx
Newbie
 
Posts: 8
Joined: Sat Feb 06, 2021 8:10 am

Re: Use SDL2 instead of win32 api

Postby linarcx » Mon Feb 08, 2021 9:37 am

I debug the program and realized that in this line, the `renderer` always is null:

Code: Select all
auto renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
linarcx
Newbie
 
Posts: 8
Joined: Sat Feb 06, 2021 8:10 am

Re: Use SDL2 instead of win32 api

Postby ndesktop » Mon Feb 08, 2021 9:59 am

Did you tried with SDL_CreateSoftwareRenderer ?
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: Use SDL2 instead of win32 api

Postby linarcx » Tue Feb 09, 2021 1:19 am

@ndesktop Thanks. Now it's not null anymore, but i can't see the homePage(www.google.com).

Edit: I really don't want to use software renderer. If anybody knows how can i solve this issue related to hardware_rendering, please let me know.
linarcx
Newbie
 
Posts: 8
Joined: Sat Feb 06, 2021 8:10 am

Re: Use SDL2 instead of win32 api

Postby ndesktop » Tue Feb 09, 2021 2:58 am

Are you trying inside a VM? That would explain why software is working and acceleration is not.
Other than that - I'm not SDL expert - you might look at this, or try to pass SDL_WINDOW_OPENGL as flag to SDL_CreateWindow.
The best would be to enumerate drivers with SDL_GetNumRenderDrivers and then get the capabilities for each with SDL_GetRenderDriverInfo, and check if there is support for acceleration by checking SDL_RendererInfo .flags & SDL_RENDERER_ACCELERATED.
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: Use SDL2 instead of win32 api

Postby linarcx » Fri Feb 12, 2021 4:11 am

@ndesktop
Are you trying inside a VM?

No. It's on real hardware.

try to pass SDL_WINDOW_OPENGL as flag to SDL_CreateWindow.

I've test it on another machine that has Nvidia graphic driver. It works(the `renderer` isn't null anymore!). but i got a black screen.

The best would be to enumerate drivers with SDL_GetNumRenderDrivers and then get the capabilities for each with SDL_GetRenderDriverInfo, and check if there is support for acceleration by checking SDL_RendererInfo .flags & SDL_RENDERER_ACCELERATED.


Nice tip. I did it on my machine that has nvidia:
Code: Select all
  int drivers = SDL_GetNumRenderDrivers();
  if (drivers) {
    for (int i = 0; i < drivers; i++) {
      SDL_RendererInfo info = {0};
      if (SDL_GetRenderDriverInfo(i, &info) != 0) {
        printf("Couldn't get RendererInfo: %s", SDL_GetError());

      } else {
        printf("SDL_Renderer: %s", info.name);
        if (info.flags & SDL_RENDERER_SOFTWARE) {
          printf("SDL_RENDERER_SOFTWARE");
        }
        if (info.flags & SDL_RENDERER_ACCELERATED) {
          printf("SDL_RENDERER_ACCELERATED");
        }
        if (info.flags & SDL_RENDERER_PRESENTVSYNC) {
          printf("SDL_RENDERER_PRESENTVSYNC");
        }
        if (info.flags & SDL_RENDERER_TARGETTEXTURE) {
          printf("SDL_RENDERER_TARGETTEXTURE");
        }
      }
    }
  }

It returns 4 drivers:
1. direct3d
2. opengl
3. opengles2
4. software
All of them except `software`, support acceleration. As i said, if i pass SDL_WINDOW_OPENGL to SDL_CreateWindow, it won't be null, but i got a black screen.
linarcx
Newbie
 
Posts: 8
Joined: Sat Feb 06, 2021 8:10 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 47 guests