Main Page | Report this Page
Computers Forum Index  »  Computer - Graphics - API (Opengl)  »  Embed Opengl textures in executable file?...
Page 1 of 1    

Embed Opengl textures in executable file?...

Author Message
bob...
Posted: Mon Sep 14, 2009 7:10 pm
Guest
I have some opengl textures in .bmp files which I load on start up, but
on the windows version of my program I need to embed these in the
executable like a "resource" (specified in a .rc file). Does anyone know
how to do that?

thanks,
Bob
 
fungus...
Posted: Mon Sep 14, 2009 7:10 pm
Guest
On Sep 14, 5:10 pm, bob <bobs... at (no spam) xyzzy.com> wrote:
Quote:
I have some opengl textures in .bmp files which I load on start up, but
on the windows version of my program I need to embed these in the
executable like a "resource" (specified in a .rc file). Does anyone know
how to do that?


You can do it with .rc files if you want but
you say "the windows version" so I assume you
work on other platforms and want portability.

I convert all my embedded data files to C source
code and use #include to get them in the program.
It's completely portable and you don't need to
learn lots of Windows function calls.


--
<\___/>
/ O O \
\_____/ FTB.

http://www.topaz3d.com/ - New 3D editor for real time simulation
 
Charles E Hardwidge...
Posted: Mon Sep 14, 2009 7:36 pm
Guest
"bob" <bobself at (no spam) xyzzy.com> wrote in message
news:X1trm.176013$cf6.123988 at (no spam) newsfe16.iad...
Quote:
I have some opengl textures in .bmp files which I load on start up, but
on the windows version of my program I need to embed these in the
executable like a "resource" (specified in a .rc file). Does anyone know
how to do that?

Ask in the windows developer groups about resource editors.

--
Charles E Hardwidge
 
bob...
Posted: Mon Sep 14, 2009 10:09 pm
Guest
On Mon, 14 Sep 2009 08:55:53 -0700, fungus wrote:


Quote:
You can do it with .rc files if you want but you say "the windows
version" so I assume you work on other platforms and want portability.

I convert all my embedded data files to C source code and use #include
to get them in the program. It's completely portable and you don't need
to learn lots of Windows function calls.

This sounds like what I need. Yes I have a linux version. Do you just
rename the .bmp (or whatever) file to a .c file? Can you give any more
detail about how to do this? Or a link to an example?

Bob
 
Wolfgang Draxinger...
Posted: Mon Sep 14, 2009 10:48 pm
Guest
bob wrote:

Quote:
I have some opengl textures in .bmp files which I load on start up, but
on the windows version of my program I need to embed these in the
executable like a "resource" (specified in a .rc file). Does anyone know
how to do that?

Here you go. This code is from the stone ages though and originates from a
program where I did my first steps in OpenGL. You put ordinary DIB .bmp
files into a "TEXTURE" resource section.

int rcDibTextureLoadGlTex(UINT nID)
{
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
DWORD dwSize = 0;

HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(nID), "TEXTURE");
HGLOBAL hData = LoadResource(NULL, hRes);
char *lpData = LockResource(hData);

if(lpData) {
memcpy(&bmfh, lpData, sizeof(bmfh));
memcpy(&bmih, lpData + sizeof(bmfh), sizeof(bmih));
dwSize = bmfh.bfSize - bmfh.bfOffBits;

if( bmih.biCompression != BI_RGB ||
bmih.biBitCount != 24 )
return 0;

glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
bmih.biWidth, bmih.biHeight, 0, GL_BGRA,
GL_UNSIGNED_BYTE, lpData + bmfh.bfOffBits );

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
return 1;
}

The DIB must fullfill the constraints of OpenGL (dimensions being powers of
two) and be in 24 bits per pixel, uncompressed format. In a 24 bits per
pixel DIB each pixel takes 4 bytes, however in normal DIBs the 4th byte is
garbage/padding. Based on the loader above, I also implemented a small
tool, which puts alpha (transparency) values there.

In general to read any form of data from the resource section, one uses

HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(nID), "TEXTURE");
HGLOBAL hData = LoadResource(NULL, hRes);
char *lpData = LockResource(hData);

This also works with any other file/data format, so you could put JPEG or
PNG files there too; both libpng and libjpeg can decompress from memory, so
do the multiformat libraries DevIL and imlib2.


Wolfgang
--
OpenGL tip #42:
How to exactly map texture texels to screen pixels:
<http://preview.tinyurl.com/cgndc8>
 
Jean-Pierre Gygax...
Posted: Mon Sep 14, 2009 11:00 pm
Guest
bob wrote:
Quote:
On Mon, 14 Sep 2009 08:55:53 -0700, fungus wrote:


You can do it with .rc files if you want but you say "the windows
version" so I assume you work on other platforms and want portability.

I convert all my embedded data files to C source code and use #include
to get them in the program. It's completely portable and you don't need
to learn lots of Windows function calls.

This sounds like what I need. Yes I have a linux version. Do you just
rename the .bmp (or whatever) file to a .c file? Can you give any more
detail about how to do this? Or a link to an example?

Bob

Look for "bin2hex" at the following URL:

http://www.chami.com/tips/keywords/programming.html

-- Jean-Pierre
 
fungus...
Posted: Tue Sep 15, 2009 1:56 am
Guest
On Sep 14, 8:09 pm, bob <bobs... at (no spam) xyzzy.com> wrote:
Quote:
On Mon, 14 Sep 2009 08:55:53 -0700, fungus wrote:
You can do it with .rc files if you want but you say "the windows
version" so I assume you work on other platforms and want portability.

I convert all my embedded data files to C source code and use #include
to get them in the program. It's completely portable and you don't need
to learn lots of Windows function calls.

This sounds like what I need. Yes I have a linux version. Do you just
rename the .bmp (or whatever) file to a .c file? Can you give any more
detail about how to do this? Or a link to an example?


You have to write a little program to convert
them to ASCII hexadecimal.

eg. It might look like this:

#define imageDataSize 298
static const byte imageData[imageDataSize] = {
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,
0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
0x00,0x00,0x00,0x10,0x00,0x00,0x00,...
};
 
Vladimir Jovic...
Posted: Tue Sep 15, 2009 11:48 am
Guest
bob wrote:
Quote:
On Mon, 14 Sep 2009 08:55:53 -0700, fungus wrote:


You can do it with .rc files if you want but you say "the windows
version" so I assume you work on other platforms and want portability.

I convert all my embedded data files to C source code and use #include
to get them in the program. It's completely portable and you don't need
to learn lots of Windows function calls.

This sounds like what I need. Yes I have a linux version. Do you just
rename the .bmp (or whatever) file to a .c file? Can you give any more
detail about how to do this? Or a link to an example?

You can open the bmp image using GIMP, then save as header or source file.
 
Sam Brown...
Posted: Wed Sep 16, 2009 3:06 am
Guest
"bob" <bobself at (no spam) xyzzy.com> wrote in message
news:X1trm.176013$cf6.123988 at (no spam) newsfe16.iad...
Quote:
I have some opengl textures in .bmp files which I load on start up, but
on the windows version of my program I need to embed these in the
executable like a "resource" (specified in a .rc file). Does anyone know
how to do that?

My current method is to just cat any data files I want onto the end of the
executable as a post-build step. I wrote myself a little utility that tacks
on any files I want with a unique identifier for each one that I can
reference in code, along with its size. It's basically what the Windows
resource stuff does anyway.

- Sam B
 
 
Page 1 of 1    
All times are GMT
The time now is Sat Dec 05, 2009 4:46 am