Hardcheese
Posts: 36
Joined: Sat Sep 01, 2012 12:25 pm

Embedding binary files in Opengl ES

Thu Oct 04, 2012 4:22 pm

Hi,

I have been trying to learn how to embed binary textures in my Opengl ES programs. However, when I use the following code:

#define TEXTUREREF(x) extern char _binary_data_ ## x ## _bmp_start
#define TEXTURE(x) texture_new(&_binary_data_ ## x ## _bmp_start)

The compilation just fails saying it can't find the textures. But I need the actual executable in the first place to embed the binary in my program. Are there any compilation commands I should be using to make this work?

blu
Posts: 55
Joined: Tue Jul 17, 2012 9:57 pm

Re: Embedding binary files in Opengl ES

Fri Oct 05, 2012 6:18 am

The code you quote above is C preprocessor code - those are basically convenience macros. Let's go in details:

#define is a preprocessor keyword for defining a macro. TEXTUREREF() and TEXTURE() are the names of the macros being defined. The first is an external variable declaration statement (i.e. extern char some_name) and the second is a function call statement (i.e. func(arg)). _binary_data_##x##_bmp_start is the name of the external variable the first macro refers to. It uses the ## preprocessor op to take the macro argument and embed it in the name, so if you passed down to the macro a value of foo you'd end up with the symbol _binary_data_foo_bmp_start.

To sum it up again: those preprocessor definitions are not doing anything on their own - they're just convenience macros. You actually need the _binary_data_<stuff>_bmp_start declarations and the texture_new(char*) (or texture_new(const char*)) function defined somewhere in your C/C++ modules.

Hardcheese
Posts: 36
Joined: Sat Sep 01, 2012 12:25 pm

Re: Embedding binary files in Opengl ES

Fri Oct 05, 2012 8:33 am

Thanks for your reply but I managed to solve the problem by compiling the binary into object code and compiling my program with it. :D

Return to “OpenGLES”