Recent

Author Topic: creating openGL context in a unit whithout modifying the main program source  (Read 1160 times)

Key-Real

  • Full Member
  • ***
  • Posts: 185
I wanna open an openGL context in a separate unit and leave my main program source like this:

uses myUnit;
begin
 openGLcontext;
 repeat
  draw;
 until keypress;
 closeGLcontext;
end.


the whole jni stuff with the mainactivity called from java should be in the myUnit.

is this possible?

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Onur Cinar "Pro Android C++ with the NDK"
Retabouil "Android NDK"
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

TRon

  • Hero Member
  • *****
  • Posts: 2433
Onur Cinar "Pro Android C++ with the NDK"
Retabouil "Android NDK"
Which in practice would boil down to: https://www.learnopengles.com/calling-opengl-from-android-using-the-ndk/ (same as my other link in the other thread but with a sexy layout  :) )

Key-Real

  • Full Member
  • ***
  • Posts: 185
I found this:

https://github.com/android/ndk-samples/tree/main/native-activity

this is exactly what I'm trying to do in pascal.

they have a magic entry point:
 void android_main(struct android_app* state)

Is it possible to convert this entry point to freepascal?
« Last Edit: January 23, 2023, 10:59:01 am by Key-Real »

TRon

  • Hero Member
  • *****
  • Posts: 2433
@Key_Real:
If not mistaken then: https://github.com/android/ndk-samples/blob/main/native-activity/app/src/main/cpp/CMakeLists.txt

tells that there is some glue.... I have a suspicion that this "glue" is jsut some wrapper function(s) inside a library (but you really would have to take a look at it yourself).

In principle: if it can be done in any other language it can be done with Pascal/FPC.

edit: 2 searches later: https://developer.android.com/ndk/samples/sample_na
« Last Edit: January 23, 2023, 11:15:03 am by TRon »

Key-Real

  • Full Member
  • ***
  • Posts: 185
The whole libraries including android_native_app_glue are in

lazarusSRC/lcl/interfaces/customdraw/android

TRon

  • Hero Member
  • *****
  • Posts: 2433
I do not have android target installed, hence why you are probably need to figure things out on your own.

The link I posted confirms my suspicion it still requires JAVA. Your native code (still) resides inside a library.

I do not really grasp why that is or would be a problem as all your code is running natively, it is only the the startup that is invoked from a JVM. How that looks at the native side depends on the wrapper being used. And you made your preferences clear so i can only suggest to replicate the wrappers to such an extend so that they meet your expectations/requirements.

I do not have any experience with custom drawn android controls but i do know there are people around here on the forum (probably absent for a while) that are able to tell you more about it.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
TRon, java не обязателен. Есть возможность в самом деле создавать абсолютно нативные приложения, без java-кода.

Key-Real, в тех каталогах должен быть полный нативный пример.
Но, я уже писал, по какой причине не стоит этим заниматься. Не было полностью всё реализовано всё для нативного исполнения. Даже внутренний цикл, надо переделывать. Очень многих функций не реализовано нативным методом. Многие функции приходится вызывать посредством jni - а это означает что всё равно приходится использовать java-код. Какую-то часть вы сможете реализовать, даже OpenGL. Но чем глубже вы будете погружаться, тем больше будет проблем.
Даже разработчики NDK не стали делать нормальных примеров для использования нативных методов.

Но сделать можно всё! Если вам захочется абсолютно всё сделать в нативном виде, то вам придётся переписывать драйвера с java-кода на Паскаль. И тестировать данные драйвера.
Если вы захотите использовать своё приложение для множества устройств, то вам придётся писать одни и те же драйвера для разных устройств. Потому что устройств тысячи. И драйвера выполняющие одни и те же функции на разных устройствах разные.
И только по этой причине все стараются реализовать через java-код. Потому что нет полной поддержки нативных методов реализации всех драйверов.

Так же вы можете посмотреть как это сделано в Castle Game Engine. И не забывайте про книги которые я скидывал. Там тоже показаны абсолютно нативные методы.

Я, когда делал полностью нативное приложение, использовал как примеры код C/C++.


Google translate:
TRon, java is optional. It is possible to actually create absolutely native applications, without java code.

Key-Real, there should be a full native example in those directories.
But, I already wrote, for what reason you should not do this. Everything was not fully implemented for native execution. Even the inner loop needs to be redone. A lot of functions are not implemented natively. Many functions have to be called via jni - which means that you still have to use java code. Some part you can implement, even OpenGL. But the deeper you go, the more problems there will be.
Even the NDK developers did not make normal examples for using native methods.

But everything can be done! If you want to do absolutely everything in a native form, then you will have to rewrite drivers from java code to Pascal. And test driver data.
If you want to use your application for multiple devices, then you will have to write the same drivers for different devices. Because there are thousands of devices. And the drivers that perform the same functions on different devices are different.
And for this reason alone, everyone is trying to implement through java code. Because there is no full support for native methods of implementing all drivers.

You can also see how it's done in the Castle Game Engine. And do not forget about the books that I threw off. It also shows absolutely native methods.

When I made a completely native application, I used C / C ++ code as examples.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL


Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
https://youtu.be/Vj3xPsK8kBU

В общем я нашёл видео, где делал полностью нативное приложение. Под самим видео выложен проект, что был сделан до меня. На видео я показываю как его можно собрать.

Google translate:
In general, I found a video where I made a completely native application. Under the video itself, there is a project that was made before me. In the video I show how to assemble it.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Key-Real

  • Full Member
  • ***
  • Posts: 185
Yes, thx for the Video.

I'm working on the same but building from the command line.

As soon I success I'll post...

 

TinyPortal © 2005-2018