# Would it be inefficient to call LWJGL from C++?

I like LWJGL, but Java? Not so much. I recently found out a way to call Java methods from C++. But would this be inefficient? I mean, calling a C/C++ DLL from Java, just to be called back again into C++? I don't know the native method names in LWJGL. I find it better then GLFW, SDL, and all those libraries. But other than my preferences, how slow would it be?

• Isn't LWJGL just a Java "port" of the OpenGL API? In that case, why not use the standard C OpenGL API? I have never used LWJGL myself, so I might be completely wrong. May 16 '13 at 6:42
• It's a multiplatform port of the native API for Windows, Mac, and Linux that handles the whole window with OpenGL. May 16 '13 at 6:54
• Are there no C++ libraries that do the same LWJGL does? May 16 '13 at 13:09
• @user1870398 There are FreeGLUT and SDL. May 20 '13 at 21:39

Yes it would be inefficient. However it's up to you to decide if it is too inefficient. It depends on how often you would be calling LWJGL.

See https://stackoverflow.com/questions/7699020/what-makes-jni-calls-slow and http://192.9.162.55/docs/books/performance/1st_edition/html/JPNativeCode.fm.html. Chapter 9.2 Examining JNI Costs from the second link provides a benchmark result where Native->Java calls were almost 10 times slower than Java->Native calls.

Inefficient compared to what?

Considering that LWJGL3 is mostly a collection of JNI and JNA bindings to C and C++ libraries it would be inefficient indeed, as you would create an overhead of having to have a JVM running and piping each method call to java and back to C++ again (mostly at runtime even), at almost no usability win whatsoever as LWJGL3 mostly mimicks the method calls and structures of the wrapped libraries. Instead of calling LWJGL3 from C++ you should instead directly use the libraries that LWJGL3 depends upon.

In that case, and indeed your case, that would be GLFW which is used by LWJGL3 to do all the windowing, input, OpenGL stuff and other heavy lifting. If you've been using any other of the bindings offered by LWJGL such as the STB libs you can find a full list of them and links to respective repositories on the LWJGL3 GitHub repo README.

You don't have to use LWJGL. LWJGL is specific for Java.

You could just use bare OpenGL or libraries such as FreeGLUT and SDL.