leif icon indicating copy to clipboard operation
leif copied to clipboard

Bulld not working on Mac due to error in "glad.h"

Open RainerXE opened this issue 1 year ago • 4 comments

To follow standard via "install-macos.h." The following error showed up at the gcc command: "In file included from vendor/glad/src/glad.c:25: vendor/glad/src/../include/glad/glad.h:89:10: fatal error: 'KHR/khrplatform.h' file not found 89 | #include <KHR/khrplatform.h>"

I fixed it by changing the glad.h file line 89 from: "#include </KHR/khrplatform.h>" to "#include <../KHR/khrplatform.h>

Hope this helps for others.

Rainer PS: I have also attached the corrected file. glad.h.zip

RainerXE avatar Jan 02 '25 22:01 RainerXE

I guess it will not work because this : https://github.com/cococry/runara/issues/1

calvin2021y avatar Jan 13 '25 11:01 calvin2021y

OpenGL 4.1 compatibility issues

leif/leif.c:380:3: error: call to undeclared function 'glCreateVertexArrays'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  380 |   glCreateVertexArrays(1, &state.render.vao);
      |   ^
leif/leif.c:383:3: error: call to undeclared function 'glCreateBuffers'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  383 |   glCreateBuffers(1, &state.render.vbo);
      |   ^
leif/leif.c:596:5: error: call to undeclared function 'glBindTextureUnit'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  596 |     glBindTextureUnit(i, state.render.textures[i].id);
      |     ^
leif/leif.c:1914:7: error: call to undeclared function 'glTextureParameteri'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 1914 |       glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      |       ^
leif/leif.c:1943:3: error: call to undeclared function 'glCreateTextures'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 1943 |   glCreateTextures(GL_TEXTURE_2D, 1, &tex.id);
      |   ^
leif/leif.c:1948:7: error: call to undeclared function 'glTextureParameteri'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 1948 |       glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      |       ^
leif/leif.c:2012:7: error: call to undeclared function 'glTextureParameteri'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 2012 |       glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      |       ^
leif/leif.c:2200:7: error: call to undeclared function 'glTextureParameteri'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 2200 |       glTextureParameteri(*id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      |       ^
8 errors generated.
make: *** [leif.o] Error 1

calvin2021y avatar Jan 13 '25 12:01 calvin2021y

try add patch to make 4.1 build for macOS, get this runtime error:

[LEIF ERROR]: Failed to compile vertex shader.
Leif: [INFO]: ERROR: 0:1: '' :  version '450' is not supported
ERROR: 0:1: '' : syntax error: #version
ERROR: 0:2: '' :  #version required and missing.
ERROR: 0:2: '0' : syntax error: integers in layouts require GLSL 140 or later

[LEIF ERROR]: Failed to compile fragment shader.
Leif: [INFO]: ERROR: 0:1: '' :  version '450' is not supported
ERROR: 0:1: '' : syntax error: #version
ERROR: 0:2: '' :  #version required and missing.

patch with:

   // Creating the shader for the batch renderer
   const char* vert_src =
-    "#version 450 core\n"
+    "#version 410 core\n"
     "layout (location = 0) in vec2 a_pos;\n"
     "layout (location = 1) in vec4 a_border_color;\n"
     "layout (location = 2) in float a_border_width;\n"
@@ -480,7 +481,7 @@ void renderer_init() {
     "}\n";
 
 
-  const char* frag_src = "#version 450 core\n"
+  const char* frag_src = "#version 410 core\n"
     "out vec4 o_color;\n"
     "in vec4 v_color;\n"
     "in float v_tex_index;\n"

get error:

[LEIF ERROR]: Failed to link shader program.
Leif: [INFO]: ERROR: Implementation limit of 16 active fragment shader samplers (e.g., maximum number of supported image units) exceeded, fragment shader uses 32 samplers

calvin2021y avatar Jan 13 '25 12:01 calvin2021y

patch

@@ -490,7 +491,7 @@ void renderer_init() {
     "flat in vec2 v_scale;\n"
     "flat in vec2 v_pos_px;\n"
     "in float v_corner_radius;\n"
-    "uniform sampler2D u_textures[32];\n"
+    "uniform sampler2D u_textures[16];\n"
     "uniform vec2 u_screen_size;\n"
     "in vec2 v_min_coord;\n"
     "in vec2 v_max_coord;\n"

no error report, but text not show inside window.

this is my opengl 4.1 patch, it work for windows. (macOS not show text)

void glCreateVertexArrays(GLsizei n, GLuint *arrays) {
    glGenVertexArrays(n, arrays);
    for (GLsizei i = 0; i < n; ++i) {
        glBindVertexArray(arrays[i]);
        glBindVertexArray(0);
    }
}

void glCreateBuffers(GLsizei n, GLuint *buffers) {
    glGenBuffers(n, buffers);
}

void glBindTextureUnit(GLuint unit, GLuint texture) {
    glActiveTexture(GL_TEXTURE0 + unit);
    glBindTexture(GL_TEXTURE_2D, texture);
}

void glTextureParameteri(GLuint texture, GLenum pname, GLint param) {
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D, pname, param);
}

void glCreateTextures(GLenum target, GLsizei n, GLuint *textures) {
    glGenTextures(n, textures);
    for (GLsizei i = 0; i < n; ++i) {
        glBindTexture(target, textures[i]);
        glBindTexture(target, 0);
    }
}

calvin2021y avatar Jan 13 '25 12:01 calvin2021y