rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

add support for off-screen render at linux without glx #261

Closed joshuafc closed 2 years ago

joshuafc commented 2 years ago

also add predefine macro to prevent include glew.h while build without GLEW

build pass with command

cmake .. -Dfreetype-gl_BUILD_DEMOS=OFF -Dfreetype-gl_BUILD_TESTS=OFF -Dfreetype-gl_OFF_SCREEN=ON -Dfreetype-gl_BUILD_SHARED=ON -Dfreetype-gl_WITH_GLEW=OFF
make
rougier commented 2 years ago

What is glvnd exactly?

joshuafc commented 2 years ago

At linux, one can create a OpenGL context without X through EGL(https://www.khronos.org/egl/),

for more detail about glvnd: cmake --help-module FindOpenGL

Linux-specific
^^^^^^^^^^^^^^

Some Linux systems utilize GLVND as a new ABI for OpenGL.  GLVND separates
context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and
contexts are defined in "libGLX" or "libEGL".  GLVND is currently the only way
to get OpenGL 3+ functionality via EGL in a manner portable across vendors.
Projects may use GLVND explicitly with target ``OpenGL::OpenGL`` and either
``OpenGL::GLX`` or ``OpenGL::EGL``.

Projects may use the ``OpenGL::GL`` target (or ``OPENGL_LIBRARIES`` variable)
to use legacy GL interfaces.  These will use the legacy GL library located
by ``OPENGL_gl_LIBRARY``, if available.  If ``OPENGL_gl_LIBRARY`` is empty or
not found and GLVND is available, the ``OpenGL::GL`` target will use GLVND
``OpenGL::OpenGL`` and ``OpenGL::GLX`` (and the ``OPENGL_LIBRARIES``
variable will use the corresponding libraries).  Thus, for non-EGL-based
Linux targets, the ``OpenGL::GL`` target is most portable.

A ``OpenGL_GL_PREFERENCE`` variable may be set to specify the preferred way
to provide legacy GL interfaces in case multiple choices are available.
The value may be one of:

``GLVND``
 If the GLVND OpenGL and GLX libraries are available, prefer them.
 This forces ``OPENGL_gl_LIBRARY`` to be empty.
 This is the default if components were requested (since components
 correspond to GLVND libraries) or if policy ``CMP0072`` is
 set to ``NEW``.

``LEGACY``
 Prefer to use the legacy libGL library, if available.
 This is the default if no components were requested and
 policy ``CMP0072`` is not set to ``NEW``.

For EGL targets the client must rely on GLVND support on the user's system.
Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets.  Using GLES*
libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this
module does not currently support that; contributions welcome.

``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of
GLVND.  For non-GLVND Linux and other systems these are left undefined.
rougier commented 2 years ago

Ok, thanks.

joshuafc commented 2 years ago

I found there is a issue at my commit about glew , after add the macro WITH_GLEW, if user has not define WITH_GLEW before include freetype-gl's headers, glew.h will not be included.

One way to solve the problem is let cmake generate a config.h by cmake variable status, then include the config.h at opengl.h, so when user compile there applications, they can get the macro which exists when build freetype-gl .

If you agree that solution, I will make a new pull request.

rougier commented 2 years ago

Ok. One small comment in your new PR.