I'm trying to embed images and shaders in a single opengl executable file by adding this:
FUNCTION(ADD_RESOURCES out_var)
SET(result)
FOREACH(in_f ${ARGN})
FILE(RELATIVE_PATH src_f ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${in_f})
SET(out_f "${PROJECT_BINARY_DIR}/${in_f}.o")
ADD_CUSTOM_COMMAND(OUTPUT ${out_f}
COMMAND ld -r -b binary -o ${out_f} ${src_f}
DEPENDS ${in_f}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Building object ${out_f}"
VERBATIM
)
LIST(APPEND result ${out_f})
ENDFOREACH()
SET(${out_var} "${result}" PARENT_SCOPE)
ENDFUNCTION()
ADD_RESOURCES(RES
shaders/test.vert
shaders/test.frag
misc/a.tga
)
extern const char _binary_shaders_test_vert_start, _binary_shaders_test_vert_end;
extern const char _binary_shaders_test_frag_start, _binary_shaders_test_frag_end;
extern const unsigned char _binary_misc_a_tga_start, _binary_misc_a_tga_end;
The problem is that loaded shaders work well, but tga can't be loaded. After looking into the log, I found that &_binary_misc_a_tga_endand&_binary_misc_a_tga_start did exist though the value of these address are all 0.
To make it clear, &_binary_misc_a_tga_endand&_binary_misc_a_tga_start are like those shader objects, nothing strange. The value from _binary_misc_a_tga_end to _binary_misc_a_tga_start are 0 which is strange.
misc/a.tga.o did exist. I also tried nm command whose result turned out to be
000000000092a212 D _binary_misc_a_tga_end
00000000000c0012 A _binary_misc_a_tga_size
000000000086a200 D _binary_misc_a_tga_start
00000000004d0c84 t _ZN12_GLOBAL__N_118tga_decompress_RLEEPhPKhS2_iii
Why this doesn't work on image file and is there any solution?