ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
668 stars 151 forks source link

undefined symbols when compiling a opengl project using gl4es with emscripten #364

Closed RavikumarTulugu closed 2 years ago

RavikumarTulugu commented 2 years ago

I am getting below undefined symbol errors while compiling a linux opengl project. please advise. I am passing -s FULL_ES2=1 to the emscripten during linking. I am following the documentation and might be missing some thing trivial. Please advise. error: undefined symbol: emscripten_GetProcAddress (referenced by top-level compiled C/C++ code) error: undefined symbol: gl4es_glActiveTextureARB (referenced by top-level compiled C/C++ code) warning: _gl4es_glActiveTextureARB may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: glCallList (referenced by top-level compiled C/C++ code) warning: _glCallList may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: gluBuild2DMipmaps (referenced by top-level compiled C/C++ code) warning: _gluBuild2DMipmaps may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: gluProject (referenced by top-level compiled C/C++ code) warning: _gluProject may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluBuild2DMipmaps (referenced by top-level compiled C/C++ code) warning: _mgluBuild2DMipmaps may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluDeleteTess (referenced by top-level compiled C/C++ code) warning: _mgluDeleteTess may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluNewTess (referenced by top-level compiled C/C++ code) warning: _mgluNewTess may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessBeginContour (referenced by top-level compiled C/C++ code) warning: _mgluTessBeginContour may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessBeginPolygon (referenced by top-level compiled C/C++ code) warning: _mgluTessBeginPolygon may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessCallback (referenced by top-level compiled C/C++ code) warning: _mgluTessCallback may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessEndContour (referenced by top-level compiled C/C++ code) warning: _mgluTessEndContour may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessEndPolygon (referenced by top-level compiled C/C++ code) warning: _mgluTessEndPolygon may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessNormal (referenced by top-level compiled C/C++ code) warning: _mgluTessNormal may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library error: undefined symbol: mgluTessVertex (referenced by top-level compiled C/C++ code) warning: _mgluTessVertex may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library Error: Aborting compilation due to previous errors

RavikumarTulugu commented 2 years ago

I found out that some of the undefined references are not defined in the code. for ex: include/GL/glu_mangle.h:35:#define gluBuild2DMipmaps mgluBuild2DMipmaps mgluBuild2DMipMaps has no definition in the code.

ptitSeb commented 2 years ago

Many of the symbol listed here are libGLU symbols, not gl4es. You will need to build and import libGLU also (or maybe try to remove the dependancy if it's only used for MipMap computation, but it seems you are missing more than just that). There seems to be 2 symbols from gl4es (_gl4es_glActiveTextureARB and _glCallList), I'll try to have a look at that later.

RavikumarTulugu commented 2 years ago

Thank you so much, i will try to include libGLU and see if it solves.

RavikumarTulugu commented 2 years ago

if defined(USE_MGL_NAMESPACE)

include "glu_mangle.h"

endif

if defined(EMSCRIPTEN) || defined(APPLE)

define USE_MGL_NAMESPACE 1

define GL_GLEXT_PROTOTYPES 1

define MANGLE(x) gl4es_gl##x

endif

if defined(USE_MGL_NAMESPACE)

include "gl_mangle.h"

endif

USE_MGL_NAMESPACE is hardcoded for EMSCRIPTEN in the library , libGLU doesnt provide the mgl* routines. let me relax this hardcoding and link with libGLU.

RavikumarTulugu commented 2 years ago

I am actually building foobillardplus , i see some links but the steps are missing on how to build with emsccripten. i have downloaded the foobillardplus package from sourceforge.net

ptitSeb commented 2 years ago

For glu, did you try the version on my github: https://github.com/ptitSeb/GLU ?

foobillardplus works with gl4es, but I never tried with emscripten. I hope you'll succeed, it would be a cool page to see :)

RavikumarTulugu commented 2 years ago

i am trying glu-9.0.2 downloaded from some link. let me try this one as well.

RavikumarTulugu commented 2 years ago

The below patch will make gl4es compile on linux with emscripten.

*** gl4es-1.1.4/include/GL/gl.h 2020-06-22 21:48:46.000000000 +0530
--- /home/vj/work/opensource/base/gl4es-1.1.4/include/GL/gl.h   2021-12-02 17:51:46.000000000 +0530
***************
*** 27,33 ****
  #ifndef __gl_h_
  #define __gl_h_

! #if defined(__EMSCRIPTEN__) || defined(__APPLE__)
  #define USE_MGL_NAMESPACE    1
  #define GL_GLEXT_PROTOTYPES  1
  #define MANGLE(x)            gl4es_gl##x
--- 27,34 ----
  #ifndef __gl_h_
  #define __gl_h_

! //#if defined(__EMSCRIPTEN__) || defined(__APPLE__)
! #if defined(__APPLE__)
  #define USE_MGL_NAMESPACE    1
  #define GL_GLEXT_PROTOTYPES  1
  #define MANGLE(x)            gl4es_gl##x
diff -rc gl4es-1.1.4/src/gl/attributes.h /home/vj/work/opensource/base/gl4es-1.1.4/src/gl/attributes.h
*** gl4es-1.1.4/src/gl/attributes.h     2020-06-22 21:48:46.000000000 +0530
--- /home/vj/work/opensource/base/gl4es-1.1.4/src/gl/attributes.h       2021-12-02 18:15:08.000000000 +0530
***************
*** 12,18 ****
  #endif // EXPORT

  #ifndef AliasExport
!  #if defined(__EMSCRIPTEN__) || defined(__APPLE__)
    #define AliasExport(name)
   #else
    #define AliasExport(name)   __attribute__((alias(name))) EXPORT
--- 12,19 ----
  #endif // EXPORT

  #ifndef AliasExport
! // #if defined(__EMSCRIPTEN__) || defined(__APPLE__)
! #if defined(__APPLE__)
    #define AliasExport(name)
   #else
    #define AliasExport(name)   __attribute__((alias(name))) EXPORT
ptitSeb commented 2 years ago

This patch is already applied on current sources right? Maybe I need to create a v1.1.6 tag.

RavikumarTulugu commented 2 years ago

I am not sure, but it was not compiling out of the box with out the above patch. you can ignore if its already fixed.

midzer commented 1 year ago

I dont want to open a new issue, maybe you read this @ptitSeb.

Trying to build https://en.wikipedia.org/wiki/Chromium_B.S.U. with Emscripten.

I got it to link properly over 1 month ago. But now after a recompile I got this:

warning: undefined symbol: glPopAttrib (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glPopClientAttrib (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glPushAttrib (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glPushClientAttrib (referenced by top-level compiled C/C++ code)

I rebuilt all dependencies (including libGL.a) as well.

Thanks for your help in advance!

ptitSeb commented 1 year ago

I don't see any reason why those 4 symbols would be gone. Also, gl4es hasn't changed much in the last month (it hasn't, last commit it's from october the 1st).

midzer commented 1 year ago

Yeah, to be honest, I don't know why those symbols are missing now. Here are my compile and link flags for Emscripten:

-s USE_FREETYPE=1 -s FULL_ES2=1 -I./gl4es/include -lGL -s USE_SDL=2 -s USE_SDL_MIXER=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png","jpg"]' -o index.html -s WASM=1 -s ASYNCIFY -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s LEGACY_GL_EMULATION=1 --preload-file data
ptitSeb commented 1 year ago

Are you sure the -lGL will pick gl4es? Isn't it safer to directly point to the libGL.a archive?

midzer commented 1 year ago

Yes, after compile I (try to) link the whole program with

EM_CONFIG=$HOME/.emscripten emcc *.o libftgl.a libGL.a -g -O2 -s USE_FREETYPE=1 -s FULL_ES2=1 -I./gl4es/include -lGL -s USE_SDL=2 -s USE_SDL_MIXER=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png","jpg"]' -o index.html -s WASM=1 -s ASYNCIFY -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s LEGACY_GL_EMULATION=1 --preload-file data
ptitSeb commented 1 year ago

Try to use the full path to libGL.a to be sure it's the right version maybe?

midzer commented 1 year ago

Thanks again for your reply, @ptitSeb.

Meanwhile I found out, that above symbols are missing in linked static library libftgl.a actually. I compiled ftgl again using gl4es and now the link error is gone. Hurray!

ptitSeb commented 1 year ago

Aaah, ok. Good to see it fixed :)

Will you publish that build of Chromium B.S.U. on some website?

midzer commented 1 year ago

Yeah, it builds and links fine. But now there are WebGL runtime errors I have to investigate.

Sure, I'm gonna release this to the public and share the code once it's done.

midzer commented 1 year ago

Update:

Looks like game is running now (with grapical glitches), except:

GL_INVALID_OPERATION: Texture format does not support mipmap generation.

Somehow, the .jpg or .png textures can't be loaded.

More info from console:

LIBGL: Initialising gl4es
(index):1237 LIBGL: v1.1.5 built on Feb 27 2023 00:08:52
(index):1237 LIBGL: Using GLES 2.0 backend
(index):1237 LIBGL: Hardware test disabled, nothing activated...
(index):1237 LIBGL: Targeting OpenGL 2.1
(index):1237 LIBGL: Not forcing NPOT support
(index):1237 LIBGL: Not trying to batch small subsequent glDrawXXXX
(index):1237 LIBGL: try to use VBO
(index):1237 LIBGL: Force texture for Attachment color0 on FBO
(index):1237 LIBGL: Hack to trigger a SwapBuffers when a Full Framebuffer Blit on default FBO is done
(index):1237 LIBGL: Current folder is:/
ptitSeb commented 1 year ago

a mipmap issue. a LIBGL_MIPMAP=3 env. var. would be ideal. Using emscripten, you might need to alter the source code directly.

midzer commented 1 year ago

Awesome, this error went way!

Now, theres

WebGL: INVALID_VALUE: texImage2D: invalid internalformat

left. I'm playing around with those glHint() parameters right now.

midzer commented 1 year ago

Another update: I've managed to remove all gl warnings.

This is current status: https://chromium-bsu.netlify.app/

PNGs still not showing correctly...

midzer commented 1 year ago

I finally managed to get it working by dropping SDL2 Image and using libpng dependency.