OpenGL Shading Language Tutorials

Syntax Coloring in Visual Studio .NET


 

Adding Syntax Coloring for OGLSL to Visual Studio .NET is not that easy. The only way would be to create a component with OGLSL support. However, there is another way over the Visual Studio registry. It is possible to add extensions to the C++ definitions. After installing the registry hacks, Visual Studio treats the files like C++ files (but doesn't try to compile them).

 

Install the following to the registry: (.reg files available for download)

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions\.frag]
         @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions\.vert]
         @="{B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}"

Now Visual Studio uses same settings for ".frag" and ".vert" files like C++ programs. If you're using Visual Studio .NET 2002 you have to change 7.1 to 7. (both versions are included in download section).


The next step is adding keywords ("uniform, varying, attribute, vec2, vec3, ...") to Visual Studio. There is a serious drawback: if you add OGLSL keywords they would also highlight in C++ code... For me, this is a minor problem.

Put "usertype.dat" to "...\Common7\IDE\" dirctory of Visual Studio .NET. Usertype contains all OGLSL keywords.
Currently I only added data types and keywords: void, bool, int, float, vec2, vec3, vec4, bvec2, bvec3, ivec2, ivec3, ivec4, mat2, mat3, mat4, sampler1D, sampler2D, sampler3D, samplerCube, sampler1DShadow, sampler2DShadow,varying, attribute, uniform, in, out, inout, const, if, else, for, while, do, discard, return, break, continue.

You could also add other keywords like "gl_Color" etc.

 

Future work

It would be possible to create a syntax checker with 3Dlabs Open Source compiler and add it to Visual Studio. That way you could check possible errors in your source code without actually starting an OpenGL context.

 

 

 

© 2003 by Martin Christen. All Rights Reserved.
christen@clockworkcoders.com