Jump to content

Tutorial: OpenGL apps on OpenGL ES (gl4es)


jock

Recommended Posts

This mini-tutorial is for those interested in running OpenGL applications and games on OpenGL ES.

Most (maybe all?) SoCs around support OpenGL ES, which is almost a stripped down version of OpenGL. OpenGL ES is mainly used by smartphone apps, but on Linux and generally on desktop computer OpenGL clients are the most common.

This tutorial is very simple and will teach you on how to download and compile GL4ES (github: https://github.com/ptitSeb/gl4es), a nice piece of software that converts most OpenGL calls into OpenGL ES counterparts to achieve some degree of compatibility and let your apps run on our SoCs. The target of this tutorial is the Rockchip RK3288 SoC with Mali-760 MP4 GPU, but hopefully it runs on other GPUs as well.

 

1) First of all you need git and cmake, so on your Armbian distro run:

$ sudo apt update
$ sudo apt install git cmake

2) Now clone the GL4ES repository:

$ git clone 'https://github.com/ptitSeb/gl4es.git'

3) Run cmake to create the appropriate Makefile with our preferred configuration. We here use the ODROID profile and set OpenGL ES 2 as default (gl4es will look by default for OpenGLES_v2.so libary this way):

$ cd gl4es
$ cmake . -DODROID=1 -DDEFAULT_ES=2

4) Compile the code:

$ make GL

5) If everything went well, copy the library into /opt:

$ sudo mkdir -p /opt/gl4es
$ sudo cp lib/libGL.so.1 /opt/gl4es

6) Set the LIBGL_COPY environment variable in /etc/profile, so it will always be set at startup. This is needed because by default GL4ES applies a workaround for an issue in some drivers and the workaround is not needed on Mali drivers. Not setting this  variable will result in incredible slowdown on some scenes which use a particular OpenGL function:

$ su -c "echo export LIBGL_COPY=1 >> /etc/profile"

7) Reboot your system

 

This should be enough to run OpenGL 1.5/2 applications.

We run our preferred application setting the LD_LIBRARY_PATH environment variable pointing to /opt/gl4es, like this:

$ LD_LIBRARY_PATH=/opt/gl4es glxinfo

You should get something like this:

Spoiler

paolo@xt:~$ LD_LIBRARY_PATH=/opt/gl4es glxinfo 
LIBGL: Initialising gl4es
LIBGL: v1.0.9 built on Sep 28 2018 19:55:54
LIBGL: Using GLES 2.0 backend
LIBGL:loaded: libGLESv2.so
LIBGL:loaded: libEGL.so
LIBGL: Using GLES 2.0 backend
LIBGL: Hardware Limited NPOT detected and used
LIBGL: Extension GL_EXT_blend_minmax detected and used
LIBGL: FBO are in core, and so used
LIBGL: PointSprite are in core, and so used
LIBGL: CubeMap are in core, and so used
LIBGL: BlendColor is in core, and so used
LIBGL: Blend Substract is in core, and so used
LIBGL: Blend Function and Equation Separation is in core, and so used
LIBGL: Texture Mirrored Repeat is in core, and so used
LIBGL: Extension GL_OES_mapbuffer detected
LIBGL: Extension GL_OES_element_index_uint detected and used
LIBGL: Extension GL_OES_packed_depth_stencil detected and used
LIBGL: Extension GL_OES_depth24 detected and used
LIBGL: Extension GL_OES_rgb8_rgba8 detected and used
LIBGL: Extension GL_EXT_texture_format_BGRA8888 detected and used
LIBGL: Extension GL_OES_depth_texture detected and used
LIBGL: Extension GL_EXT_texture_rg detected and used
LIBGL: high precision float in fragment shader available and used
LIBGL: Max vertex attrib: 16
LIBGL: Extension GL_OES_standard_derivatives detected and used
LIBGL: Max texture size: 8192
LIBGL: Max Varying Vector: 15
LIBGL: Texture Units: 8(8), Max lights: 8, Max planes: 6
LIBGL: Hardware vendor is ARM
LIBGL: sRGB surface supported
LIBGL: No glCopyTexImage2D / glCopyTexSubImage2D hack
LIBGL: Targeting OpenGL 2.0
LIBGL: Forcing NPOT support by disabling MIPMAP support for NPOT textures 
LIBGL: glXMakeCurrent FBO workaround enabled
LIBGL: Current folder is:/home/paolo
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: ptitSeb
server glx version string: 1.4 GL4ES
server glx extensions:
    GLX_ARB_create_context, GLX_ARB_create_context_profile, 
    GLX_ARB_get_proc_address, GLX_ARB_multisample, 
    GLX_EXT_create_context_es2_profile, GLX_EXT_swap_control, 
    GLX_MESA_swap_control, GLX_SGI_swap_control
client glx vendor string: ptitSeb
client glx version string: 1.4 GL4ES
client glx extensions:
    GLX_ARB_create_context, GLX_ARB_create_context_profile, 
    GLX_ARB_get_proc_address, GLX_ARB_multisample, 
    GLX_EXT_create_context_es2_profile, GLX_EXT_swap_control, 
    GLX_MESA_swap_control, GLX_SGI_swap_control
GLX version: 1.4
GLX extensions:
    GLX_ARB_create_context, GLX_ARB_create_context_profile, 
    GLX_ARB_get_proc_address, GLX_ARB_multisample, 
    GLX_EXT_create_context_es2_profile, GLX_EXT_swap_control, 
    GLX_MESA_swap_control, GLX_SGI_swap_control
OpenGL vendor string: ptitSeb
OpenGL renderer string: GL4ES wrapper
OpenGL core profile version string: 2.0 gl4es wrapper 1.0.9
OpenGL core profile shading language version string: 1.10 via gl4es
OpenGL core profile extensions:
    GL_APPLE_texture_2D_limited_npot, GL_ARB_ES2_compatibility, 
    GL_ARB_draw_buffers, GL_ARB_draw_elements_base_vertex, 
    GL_ARB_draw_instanced, GL_ARB_fragment_shader, GL_ARB_framebuffer_object, 
    GL_ARB_instanced_arrays, GL_ARB_multisample, GL_ARB_multitexture, 
    GL_ARB_point_parameters, GL_ARB_point_parameters, GL_ARB_point_sprite, 
    GL_ARB_shader_objects, GL_ARB_shading_language_100, 
    GL_ARB_texture_border_clamp, GL_ARB_texture_compression, 
    GL_ARB_texture_cube_map, GL_ARB_texture_env_add, 
    GL_ARB_texture_env_combine, GL_ARB_texture_env_crossbar, 
    GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat, 
    GL_ARB_texture_rectangle, GL_ARB_vertex_array_object, 
    GL_ARB_vertex_buffer, GL_ARB_vertex_buffer_object, GL_ARB_vertex_shader, 
    GL_ATIX_texture_env_route, GL_ATI_texture_env_combine3, GL_EXT_abgr, 
    GL_EXT_bgra, GL_EXT_blend_color, GL_EXT_blend_equation_separate, 
    GL_EXT_blend_func_separate, GL_EXT_blend_minmax, GL_EXT_blend_subtract, 
    GL_EXT_compiled_vertex_array, GL_EXT_direct_state_access, 
    GL_EXT_draw_elements_base_vertex, GL_EXT_draw_range_elements, 
    GL_EXT_fog_coord, GL_EXT_framebuffer_object, GL_EXT_multi_draw_arrays, 
    GL_EXT_packed_depth_stencil, GL_EXT_packed_depth_stencil, 
    GL_EXT_packed_pixels, GL_EXT_point_parameters, GL_EXT_polygon_offset, 
    GL_EXT_rescale_normal, GL_EXT_secondary_color, 
    GL_EXT_separate_specular_color, GL_EXT_stencil_wrap, 
    GL_EXT_texture_compression_dxt1, GL_EXT_texture_compression_dxt3, 
    GL_EXT_texture_compression_dxt5, GL_EXT_texture_compression_s3tc, 
    GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp, 
    GL_EXT_texture_env_add, GL_EXT_texture_env_combine, 
    GL_EXT_texture_env_crossbar, GL_EXT_texture_env_dot3, 
    GL_EXT_texture_object, GL_EXT_vertex_array, GL_GL4ES_hint, 
    GL_NV_texture_env_combine4, GL_OES_texture_compression_S3TC, 
    GL_SGIS_generate_mipmap, GL_SGIS_texture_edge_clamp, 
    GL_SUN_multi_draw_arrays

OpenGL version string: 2.0 gl4es wrapper 1.0.9
OpenGL shading language version string: 1.10 via gl4es
OpenGL extensions:
    GL_APPLE_texture_2D_limited_npot, GL_ARB_ES2_compatibility, 
    GL_ARB_draw_buffers, GL_ARB_draw_elements_base_vertex, 
    GL_ARB_draw_instanced, GL_ARB_fragment_shader, GL_ARB_framebuffer_object, 
    GL_ARB_instanced_arrays, GL_ARB_multisample, GL_ARB_multitexture, 
    GL_ARB_point_parameters, GL_ARB_point_parameters, GL_ARB_point_sprite, 
    GL_ARB_shader_objects, GL_ARB_shading_language_100, 
    GL_ARB_texture_border_clamp, GL_ARB_texture_compression, 
    GL_ARB_texture_cube_map, GL_ARB_texture_env_add, 
    GL_ARB_texture_env_combine, GL_ARB_texture_env_crossbar, 
    GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat, 
    GL_ARB_texture_rectangle, GL_ARB_vertex_array_object, 
    GL_ARB_vertex_buffer, GL_ARB_vertex_buffer_object, GL_ARB_vertex_shader, 
    GL_ATIX_texture_env_route, GL_ATI_texture_env_combine3, GL_EXT_abgr, 
    GL_EXT_bgra, GL_EXT_blend_color, GL_EXT_blend_equation_separate, 
    GL_EXT_blend_func_separate, GL_EXT_blend_minmax, GL_EXT_blend_subtract, 
    GL_EXT_compiled_vertex_array, GL_EXT_direct_state_access, 
    GL_EXT_draw_elements_base_vertex, GL_EXT_draw_range_elements, 
    GL_EXT_fog_coord, GL_EXT_framebuffer_object, GL_EXT_multi_draw_arrays, 
    GL_EXT_packed_depth_stencil, GL_EXT_packed_depth_stencil, 
    GL_EXT_packed_pixels, GL_EXT_point_parameters, GL_EXT_polygon_offset, 
    GL_EXT_rescale_normal, GL_EXT_secondary_color, 
    GL_EXT_separate_specular_color, GL_EXT_stencil_wrap, 
    GL_EXT_texture_compression_dxt1, GL_EXT_texture_compression_dxt3, 
    GL_EXT_texture_compression_dxt5, GL_EXT_texture_compression_s3tc, 
    GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp, 
    GL_EXT_texture_env_add, GL_EXT_texture_env_combine, 
    GL_EXT_texture_env_crossbar, GL_EXT_texture_env_dot3, 
    GL_EXT_texture_object, GL_EXT_vertex_array, GL_GL4ES_hint, 
    GL_NV_texture_env_combine4, GL_OES_texture_compression_S3TC, 
    GL_SGIS_generate_mipmap, GL_SGIS_texture_edge_clamp, 
    GL_SUN_multi_draw_arrays

OpenGL ES profile version string: 2.0 gl4es wrapper 1.0.9
OpenGL ES profile shading language version string: 1.10 via gl4es
OpenGL ES profile extensions:
    GL_APPLE_texture_2D_limited_npot, GL_ARB_ES2_compatibility, 
    GL_ARB_draw_buffers, GL_ARB_draw_elements_base_vertex, 
    GL_ARB_draw_instanced, GL_ARB_fragment_shader, GL_ARB_framebuffer_object, 
    GL_ARB_instanced_arrays, GL_ARB_multisample, GL_ARB_multitexture, 
    GL_ARB_point_parameters, GL_ARB_point_parameters, GL_ARB_point_sprite, 
    GL_ARB_shader_objects, GL_ARB_shading_language_100, 
    GL_ARB_texture_border_clamp, GL_ARB_texture_compression, 
    GL_ARB_texture_cube_map, GL_ARB_texture_env_add, 
    GL_ARB_texture_env_combine, GL_ARB_texture_env_crossbar, 
    GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat, 
    GL_ARB_texture_rectangle, GL_ARB_vertex_array_object, 
    GL_ARB_vertex_buffer, GL_ARB_vertex_buffer_object, GL_ARB_vertex_shader, 
    GL_ATIX_texture_env_route, GL_ATI_texture_env_combine3, GL_EXT_abgr, 
    GL_EXT_bgra, GL_EXT_blend_color, GL_EXT_blend_equation_separate, 
    GL_EXT_blend_func_separate, GL_EXT_blend_minmax, GL_EXT_blend_subtract, 
    GL_EXT_compiled_vertex_array, GL_EXT_direct_state_access, 
    GL_EXT_draw_elements_base_vertex, GL_EXT_draw_range_elements, 
    GL_EXT_fog_coord, GL_EXT_framebuffer_object, GL_EXT_multi_draw_arrays, 
    GL_EXT_packed_depth_stencil, GL_EXT_packed_depth_stencil, 
    GL_EXT_packed_pixels, GL_EXT_point_parameters, GL_EXT_polygon_offset, 
    GL_EXT_rescale_normal, GL_EXT_secondary_color, 
    GL_EXT_separate_specular_color, GL_EXT_stencil_wrap, 
    GL_EXT_texture_compression_dxt1, GL_EXT_texture_compression_dxt3, 
    GL_EXT_texture_compression_dxt5, GL_EXT_texture_compression_s3tc, 
    GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp, 
    GL_EXT_texture_env_add, GL_EXT_texture_env_combine, 
    GL_EXT_texture_env_crossbar, GL_EXT_texture_env_dot3, 
    GL_EXT_texture_object, GL_EXT_vertex_array, GL_GL4ES_hint, 
    GL_NV_texture_env_combine4, GL_OES_texture_compression_S3TC, 
    GL_SGIS_generate_mipmap, GL_SGIS_texture_edge_clamp, 
    GL_SUN_multi_draw_arrays

...

 

The first lines (like "LIBGL: Initialising gl4es" and so on...) tells us that GL4ES library is being used and tells you what kind of extension is used too.

In particular, you should see gl4es in version string to be sure that gl4es will work.

 

If you want to see something moving, glxgears is the perfect candidate:

$ LD_LIBRARY_PATH=/opt/gl4es glxgears

 

A trick I found to be very powerful in some cases is setting the LIBGL_BATCH environment variable. This trick tries to reduce the calls to the driver batching vertices together in a single call. For some games this works wonderfully and gives a huge boost (Quake II, for example), on others it is harmful for performances (Quake III) and on others creates graphical glitches. Use it when appropriate:

$ LD_LIBRARY_PATH=/opt/gl4es LIBGL_BATCH=1000 glxgears

GL4ES has a lot of other environment variables that can be tested for various purposes. The complete list is available here

 

Last delicacy - Quake shareware

If all the steps have been done right, running Quake shareware should be a breeze:

$ sudo apt install quake quakespasm lhasa game-data-packager
$ game-data-packager -i quake
$ LD_LIBRARY_PATH=/opt/gl4es quake

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines