{"id":53,"date":"2007-03-18T10:58:14","date_gmt":"2007-03-18T09:58:14","guid":{"rendered":"http:\/\/www.ozone3d.net\/blogs\/lab\/?p=53"},"modified":"2008-02-01T08:23:37","modified_gmt":"2008-02-01T07:23:37","slug":"embedded-your-shader-souce-code-in-your-cc-apps","status":"publish","type":"post","link":"https:\/\/www.ozone3d.net\/blogs\/lab\/20070318\/embedded-your-shader-souce-code-in-your-cc-apps\/","title":{"rendered":"Embedded Your Shader Souce Code In Your C\/C++ Apps"},"content":{"rendered":"<p>The NVIDIA developer blog shows a way to include shaders codes to your<br \/>\nwindows exe: <a href=\"http:\/\/blogs.nvidia.com\/developers\/2007\/03\/inlining_shader.html\">blogs.nvidia.com\/developers\/2007\/03\/inlining_shader.html<\/a>.<\/p>\n<p>But this example is not fully operational. I slightly modified the code to make it totally operational (I compiled it on vc++ 6.0):<\/p>\n<pre>\r\n1) Add a define to your resource.h file:\r\n#define IDF_SHADEFILE 1000\r\n\r\n2) Add an entry in your resource.rc file:\r\nIDF_SHADERFILE RCDATA DISCARDABLE \"myShader.glsl\"\r\n\r\n3) Use the resource in your code:\r\nHMODULE hModule = GetModuleHandle(NULL);\r\nHRSRC hResource = FindResource(hModule, (LPCTSTR)IDF_SHADERFILE, RT_RCDATA);\r\nif(hResource) \r\n{\r\n  DWORD dwSize = SizeofResource(hModule, hResource);\r\n  HGLOBAL hGlobal = LoadResource(hModule, hResource);\r\n  if(hGlobal) \r\n  {\r\n    LPVOID pData = LockResource(hGlobal);\r\n    if(pData) \r\n    {\r\n\t\/\/ Cast pData to a char * and you have your shader\r\n\tchar *shader_code = (char *)pData;\r\n\t\r\n        \/\/ Now do whatever you want with shader_code pointer. \r\n\t\/\/ Do not forget that shader_code is not a zero-terminated string!\r\n\t\/\/ Use dwSize to handle that.\r\n\t\t\t\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The NVIDIA developer blog shows a way to include shaders codes to your windows exe: blogs.nvidia.com\/developers\/2007\/03\/inlining_shader.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 &#8220;myShader.glsl&#8221; 3) Use the &hellip; <a href=\"https:\/\/www.ozone3d.net\/blogs\/lab\/20070318\/embedded-your-shader-souce-code-in-your-cc-apps\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Embedded Your Shader Souce Code In Your C\/C++ Apps<\/span> <span class=\"meta-nav\">&raquo;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[112,130],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c","tag-shader"],"aioseo_notices":[],"views":1202,"_links":{"self":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ozone3d.net\/blogs\/lab\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}