Warning: strpos() [function.strpos]: needle is not a string or an integer in /home/www/6c0b12205eaced73565c8eab34735279/web/jegx/index.php on line 61
JeGX's DevBlog - Embedded Your Shader Souce Code In Your C/C++ Apps
Embedded Your Shader Souce Code In Your C/C++ Apps 
Sunday, March 18, 2007, 10:58 AM - Programming
The NVIDIA developer blog shows a way to include shaders codes to your
windows exe: http://blogs.nvidia.com/developers/2007 ... ader.html.

But this example is not fully operational. I slightly modified the code to make it totally operational (I compiled it on vc++ 6.0):


1) Add a define to your resource.h file:
#define IDF_SHADEFILE 1000

2) Add an entry in your resource.rc file:
IDF_SHADERFILE RCDATA DISCARDABLE "myShader.glsl"

3) Use the resource in your code:
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResource = FindResource(hModule, (LPCTSTR)IDF_SHADERFILE, RT_RCDATA);
if(hResource)
{
DWORD dwSize = SizeofResource(hModule, hResource);
HGLOBAL hGlobal = LoadResource(hModule, hResource);
if(hGlobal)
{
LPVOID pData = LockResource(hGlobal);
if(pData)
{
// Cast pData to a char * and you have your shader
char *shader_code = (char *)pData;

// Now do whatever you want with shader_code pointer.
// Do not forget that shader_code is not a zero-terminated string!
// Use dwSize to handle that.

}
}
}


SimplePHPBlog sucks a little bit because it can't display properly a preformated block of code. I have to use the pre tag and tidy up manually the code :thumbdown:
view entry ( 3705 views )   |  0 trackbacks   |  permalink   |   ( 3 / 1962 )


<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next> Last>>