Android Native OGLES2: esLoadProgram not declared - android

I have following commands:
// Load the shaders and get a linked program object
userData->programObject = esLoadProgram( vShaderStr, fShaderStr );
...
// Generate the vertex data
userData->numIndices = esGenCube( 1.0, &userData->vertices,NULL, NULL, &userData->indices );
The program is in native C++ for Android 4, using only NativeActivity. So, project has no /src and java classes.
I put the information to NDK OGLES 2.0 about the version running as EGL_OPENGL_ES2_BIT, and Android.mk was also setup to -lGLESv2. In the file is also included:
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
And also AndroidManifest was informed that it runs OGLES 2.0.
When asked to run, the program gives the following message:
'esLoadProgram' was not declared in this scope
'esGenCube' was not declared in this scope
For some reason these commands that belong to OGLES 2 are not visible. Any suggestion why this?
All comments are highly appreciated.

esLoadProgram and esGenCube are not a part of OpenGL ES or EGL. They are just a helper functions (probably from http://code.google.com/p/opengles-book-samples/)
PS. I would not suggest to mix also GLES and GLES2 headers. If you want GL ES 2.0, then include only from <GLES2/...> (not <GLES/...>)

Related

android c++ undefined reference to eglGetCurrentContext

i am trying to get the current OpenGL context on android in c++.
but i get a compile time error, how can i get the current context?
the error:
undefined reference to eglGetCurrentContext()
the code:
#include <GLES2/gl2.h>
#include <EGL/egl.h>
void foo()
{
EGLContext ctx = eglGetCurrentContext();
}
You are missing libEGL from your make file library list.
Assuming you are using CMake files, you need something like this in your make file:
# Include libraries needed
target_link_libraries(
GLESv2
EGL)
Note GLESv2 not needed for this error, but given you include the GLES2 header, it's likely you'll need the GLESv2 library at some point ...

Building an Android executable gRPC server that uses protocol buffers (without APK)

I compiled the gRPC Android example from here.
I want to run the program as executable from adb shell.
Added these lines to grpc-helloworld.cc:
#include <iostream>
int main() {
std::cout << "qwerty" << std::endl;
return 0;
}
And these lines to its CMakeLists.txt:
add_executable(avocado
src/main/cpp/grpc-helloworld.cc)
target_include_directories(avocado
PRIVATE ${HELLOWORLD_PROTO_HEADERS})
target_link_libraries(avocado
helloworld_proto_lib
android
${log-lib})
Then I pushed the generated executable and libs file and tried to run it:
LD_LIBRARY_PATH=. ./avocado
I got the following error:
[libprotobuf FATAL
/home/buga/grpc/third_party/protobuf/src/google/protobuf/stubs/common.cc:79]
This program was compiled against version 3.0.0 of the Protocol Buffer
runtime library, which is not compatible with the installed version
(3.5.1). Contact the program author for an update. If you compiled
the program yourself, make sure that your headers are from the same
version of Protocol Buffers as your link-time library. (Version
verification failed in
"out/soong/.intermediates/frameworks/av/drm/libmediadrm/libmediadrm/android_arm64_armv8-a_kryo300_shared_core/gen/proto/frameworks/av/drm/libmediadrm/protos/plugin_metrics.pb.cc".)terminating
with uncaught exception of type google::protobuf::FatalException: This
program was compiled against version 3.0.0 of the Protocol Buffer
runtime library, which is not compatible with the installed version
(3.5.1). Contact the program author for an update. If you compiled
the program yourself, make sure that your headers are from the same
version of Protocol Buffers as your link-time library. (Version
verification failed in
"out/soong/.intermediates/frameworks/av/drm/libmediadrm/libmediadrm/android_arm64_armv8-a_kryo300_shared_core/gen/proto/frameworks/av/drm/libmediadrm/protos/plugin_metrics.pb.cc".)
Aborted
What am I doing wrong?
We realized that there is a version of the protobuf library called libprotobuf-cpp-full.so and libprotobuf-cpp-lite.so, and it seems that their version is 3.0.0. This is conflicting with our version (3.5.1) which is compiled into either a static lib, or as a shared lib.
I'm not quite sure why this happens. Something about once the linker loads helloworld_proto_lib, it overrides all loaded protobuf symbols, and for some reason another library that you had nothing to do with crashes your program. But that's not telling you anything new.
Here's one way to solve this problem:
1. Changes to grpc-helloworld.cc
Make the main extern "C", and change its name maybe. For example:
extern "C" int my_main() {
std::cout << "qwerty" << std::endl;
return 0;
}
2. Add file grpc-avocado.cc
This will contain the actual main of the executable, which will dynamically load the libraries helloworld_proto_lib and grpc-helloworld. Here's how to do it:
#include <iostream>
#include <android/dlext.h>
#include <dlfcn.h>
int main() {
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_FORCE_LOAD;
void* proto_lib = android_dlopen_ext("/path/to/libhelloworld_proto_lib.so", RTLD_LAZY, &extinfo);
void* helloworld = dlopen("/path/to/libgrpc-helloworld.so", RTLD_LAZY);
int (*my_main)() = (int (*)())dlsym(helloworld, "my_main");
return my_main();
}
The function android_dlopen_ext from #include <android/dlext.h>, and its flag argument, are described here: https://developer.android.com/ndk/reference/group/libdl . In the above code we pass the flag ANDROID_DLEXT_FORCE_LOAD, which is documented as:
When set, do not use stat(2) to check if the library has already been loaded.
This flag allows forced loading of the library in the case when for some reason multiple ELF files share the same filename (because the already-loaded library has been removed and overwritten, for example).
Note that if the library has the same DT_SONAME as an old one and some other library has the soname in its DT_NEEDED list, the first one will be used to resolve any dependencies.
I think the text in bold is what explains why this solution works.
3. Change CMakeLists.txt
Since you'll be loading helloworld_proto_lib dynamically, you can now remove it from the executable definition, and there's no need for any proto headers:
add_executable(avocado
src/main/cpp/grpc-avocado.cc)
target_link_libraries(avocado
android
${log-lib})
Build, push, and run
You can now build, push the executable avocado and the two libraries libgrpc-helloworld.so, libhelloworld_proto_lib.so, and run. You don't need LD_LIBRARY_PATH. Good luck with the rest of your project!

GLES 2 Functions Not Working in Visual Studio

I'm using Visual Studio Community 2017, but the native-activity in this version is the same as in Visual Studio Community 2015.
I have just created a new native activity project in Visual Studio 2017, using the default program that loads with this project choice. However, whenever I try to use a function exclusive to open gl es 2, Visual Studio responds with an error like "error : undefined reference to 'glCreateShader' " for each open gl es 2 function that I use. Strangely, the following code works, even though I deleted the line in the pch file that includes open gl es 1:
glClearColor(200, 200, 200, 1);
glClear(GL_COLOR_BUFFER_BIT);
The following function if put into the default native activity project (even after including GLES2/gl2.h, GLES2/gl2ext.h, and GLES2/gl2platform.h) results in the error described above:
int prepareShader(GLuint shaderType, const char * shaderCode) {
GLuint shader = glCreateShader(shaderType);
int len = strlen(shaderCode);
glShaderSource(shader, 1, &shaderCode, &len);
}
I remember a similar error occurring in Android Studio, which was fixed by adding the following to cmakelists.txt:
find_library(gl-lib
GLESv2 )
find_library(egl-lib
EGL )
target_link_libraries( # Specifies the target library.
native-lib
${egl-lib}
${gl-lib})
My Visual Studio project does not use CMake, however.
Can somebody please tell me how to successfully use open gl es 2 in Visual Studio 2017?
The solution to my problem is to load the open gl functions using eglGetProcAddress. This just means that each opengl es function must be set to a pointer before using them because GLES2/gl2.h does not define the functions (the functions are defined at run time).
Doing something like this for each function solves the problem. (However, I needed to delete the function prototypes in GLES2/gl2.h for this to work).
typedef GLuint(GL_APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
PFNGLCREATESHADERPROC glCreateShader = (PFNGLCREATESHADERPROC)eglGetProcAddress("glCreateShader");

How does Android source building #ifdefs work in compilation

I'm familiar with Android kernel programming but I'm a newbie at building the Android source. I'm wondering how to enable the #ifdefs in android source building. Are there any defconfig file in android source like in android kernel to choose what we want to compile in the compilation?.. How can i enable the codings defined with #ifdef to get compile during the Android source compilation?
Ex:
#ifdef USE_ION
int alloc_map_ion_memory(OMX_U32 buffer_size,
OMX_U32 alignment, struct ion_allocation_data *alloc_data,
struct ion_fd_data *fd_data,int flag);
void free_ion_memory(struct vdec_ion *buf_ion_info);
#else
bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
OMX_U32 alignment);
#endif
I want to make sure the ion part is being compiled not the pmem part.
Try add the line:
#error "USE_ION"
after #ifdef USE_ION
Build again, if the build failed, USE_ION is defined.

Can I use glu with Android NDK

I can't seem to include glu.h in my Android NDK project.
I'm trying to port existing C++ code to NDK, and it uses glu in a few places (notably gluErrorString).
Does OpenGLES not have glu?
Is there a port I can use?
If not I can probably remove the calls to things like gluPerspective and so on, but what do I do about gluErrorString?
Does OpenGL ES not have glu?
No, it doesn't. Look at this: Platform OpenGL Includes collection. Under Android there are only the following headers:
OpenGL ES 1.1:
#include <GLES/gl.h>
#include <GLES/glext.h>
OpenGL ES 2.0:
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
Is there a port I can use?
Yes, there is a partial port of GLU for Android - GLU ES (it supports gluErrorString, gluPerspective and numerous other functions):
GLU 1.3 partitial port (libutil and libtess components only) for
OpenGL ES 1.x (CM - Common profile) and above.
This port supports:
Quadrics: gluNewQuadric(), gluDeleteQuadric(), gluQuadricCallback(),
gluQuadricNormals(), gluQuadricTexture(), gluQuadricOrientation(),
gluQuadricDrawStyle(), gluCylinder(), gluDisk(), gluPartialDisk(),
gluSphere().
Registry: gluGetString(), gluCheckExtension(),
gluErrorString().
Projection matrix manipulation: gluOrtho2D(),
gluPerspective(), gluLookAt(), gluProject(), gluUnProject(),
gluUnProject4(), gluPickMatrix(). 2D Mipmaps: gluScaleImage(),
gluBuild2DMipmapLevels(), gluBuild2DMipmaps().
Tesselation:
gluBeginPolygon(), gluDeleteTess(), gluEndPolygon(),
gluGetTessProperty(), gluNewTess(), gluNextContour(),
gluTessBeginContour(), gluTessBeginPolygon(), gluTessCallback(),
gluTessEndContour(), gluTessEndPolygon(), gluTessNormal(),
gluTessProperty(), gluTessVertex().

Categories

Resources