Powoli
Powoli

Reputation: 23

How get screen dimension on Android SDL2.0 NDK C?

In my program in SDL I must get screen size. How I can to do it? On android I cant use

error: initializer element is not constant
 int height = Android_ScreenHeight;

is possible initialising it in ndk?

Upvotes: 1

Views: 566

Answers (1)

brainsandwich
brainsandwich

Reputation: 492

You can get screen buffer size :

void android_main(struct android_app* state) {
  ...

  ANativeWindow* window = state->window;
  ANativeWindow_Buffer buffer;

  // Try lock buffer
  if (ANativeWindow_lock(window, &buffer, 0) < 0)
    return;

  LOGI("buffer info: width = %d height = %d", buffer.width, buffer.height);

  // Unlock buffer
  ANativeWindow_unlockAndPost(window);

  ...
}

I know you can also get screen info through other NDK stuff, but this works!

Upvotes: 1

Related Questions