Enabling Intellisense In Visual Studio for GLSL Code - visual-studio

I'm quite fond of all the interactive help Visual Studio gives when programming C++ code...
I find I'm doing more and more GLSL (OpenGL shader language) coding and I'd like to extend the Visual Studio editing goodness to GLSL source work.
I searched the web and didn't find any very good extensions or tweaks that provide decent Intellisense coloring, hovering, completion, etc. for GLSL specifically.
I've gotten a bit further by telling Visual Studio to treat .glsl files as C++ code, and piecing together a header file that defines some things that are provided by the GLSL environment, though I have some work to do to make it complete. It's not compiled into the actual shaders by virtue of a pre-processor condition:
#ifdef _WIN32
#include "GLSL_Intellisense_Hacks.h" // Facilitate Intellisense in the shader code
#endif
My question is this:
Is there a better way out there that I just haven't run across yet? A not-so-well-known extension, or an already developed "GLSL_Intellisense_Hacks.h" file?
Thanks for any knowledge you're willing to share on accomplishing more efficient GLSL coding.
-Noel

We used a hack file for a while, but it turns out we've finally been able to get virtually 100% coverage with Intellisense by adding the glm library, which defines objects that cover all the data and syntax used in shaders - including swizzled vector accesses.
The only statement that evokes one warning is the #version pre-processor statement. Haven't figured out how to avoid that one yet.

Related

C++ auto keyword: how to avoid breaking IDE features in qtcreator

It seems the world is generally very pro-auto:
How much is too much with C++11 auto keyword?
Having to work myself into the code base of a large project, I find it quite frustrating that the usage of auto breaks handy IDE features, mostly jumping to the declaration of a variable or function. Also refactoring seems to break here.
Is there a plug-in or anything that helps qtcreator deducing the types?
I am using QtCreator 4.2.0 and I am currently stuck with this, so, would need a solution that works there

DirectX & Oculus setup inside Visual Studio, main, precompiled headers, linker and files

Goal: I'm trying to develop my first simple Oculus rift application using visual studio.
Background: Computer Engineer/programmer of arbitrary languages-rusty at C++/very rusty at visual studio/inexperienced with 3D balls to the wall programming.
DirectX Progress: I found this excelent tutorial (http://3dgep.com/introduction-to-directx-11/) and I rebuilt it walking thru the code; this taught me a lot. My code never actually would run though, likely an issue with linkers or precompiled headers, so I reverted back to the original Demo File.
Oculus Progress: I've learned a lot about using the LibOVR, successfully compiled my first program which was to gather sensor data. Never ran it though.
Visual Studio: I currently have one solution setup, with two projects (DirectXTemplate and LibOVR). I'm thinking I should merge the two projects and turn the DirectXTemplate into a library so I can access all the functions defined in these files (though I will likely need to modify them as development progresses). How do I go about doing this? Is this the right thing to do?
I also have some general questions:
List item
Projects/Solutions: what is the difference and how should I lay things out to achieve my goal?
List item
My winAPI main function is in my own cpp file, it calls functions from directXtempalte... most of these are working except the LoadContent function fails about half way thru, I think due to the shaders. I'm really confused about the shaders in the tutorial, particularly walking about at compile time vs. at run time shaders and suspect its an issue with the Linker, precompiled headers, include directories or something like that. There are so many views of the properties tab in VS its causing more confusion and errors. So my real question here is how do I control this better? I mean, the properties window changes depending on what project/solution/file I select and it also changes based on the mode selected in the properties window... getting the properties window right for all these objects has proven to be a highly error prone process requiring iterative trial and error... this really really sucks and wastes tons of time... How can it be avoided?
List item
How do I turn the directX template in to a library like the LIBOVR and should I? Keep in mind the directX template/library will be updated massively as the project progresses but LIBOVER will not be. When all things are done, I'll be using the LIBOVR functions for to deal with the oculus (this is static but is updated by the Vendor) and DirectXTemplate/Library functions to deal with direct X (this will be custom build, using the template as the starting point.

Disable or fix #ifdef-sensitive colouring and intellisense in Visual Studio

The problem: My syntax highlighting and IntelliSense are broken. I have a C++ source file like this:
#include "stdafx.hpp"
#ifdef SOMETHING
do_some_stuff;
#endif
where stdafx.hpp (the precompiled header for the project) includes a .h file that says:
#ifdef DEFINE_SOMETHING
#define SOMETHING
#endif
and DEFINE_SOMETHING is defined in the project properties for the project (under C++ / Preprocessor).
Visual Studio is losing track, and displaying do_some_stuff; (which is actually lots of lines of code) in plain grey - I have neither syntax colouring nor IntelliSense.
The question: How can I either make Visual Studio get this right (unlikely) or switch off the fact that it's greying-out code that it thinks is #ifdef'd out?
(Rearranging the code is not an option - it's a large and complex system whose files are built in various environments, Visual Studio being only one of them. I'm using Visual Studio 2005, but I'd be interested to know whether this is fixed or workaroundable in a later version.)
If someone still interested - to turn off graying out #ifdef:
Go to Tools -> Options
Open Text Editor -> C/C++ -> Formatting
Uncheck Colorize inactive code blocks in a different color
In VS19, it's Tools / Options / Text Editor / C/C++ / View / Inactive Code / Show Inactive Blocks.
Following previous answer of aousov I check my VSCode and found this setting:
C_Cpp: Dim Inactive Regions
Controls whether inactive preprocessor blocks are colored differently than active code. This setting has no effect if IntelliSense is disabled or if using the Default High Contrast theme.
in Extensions / C/C++
This may be related to the version you are using (in my case 1.46.1).
Best,
Geoffroy
The problem you describe is par for the course in VS 2005. It is fixed in Visual Studio 2010 and later due to the completely redesigned Intellisense system. This is not directly applicable to your problem, but here's some info on the underlying architecture: http://blogs.msdn.com/b/vcblog/archive/2009/05/27/rebuilding-intellisense.aspx
There are some things you could try, and some project structure changes that can help minimize the problem's frequency, but whatever you do will be hit or miss, and the problem will eventually resurface again regardless. The only real solution is to use a newer IDE.
You can continue to use the VS 2005 build tools by installing VS 2010 along with Daffodil (http://daffodil.codeplex.com), then build your projects with the v80 platform toolset in VS 2010. This makes the migration fairly straightforward, with no need for any source code changes.
Since #define SOMETHING is defined inside stdafx.hpp, indicating that it's always defined since DEFINE_SOMETHING is defined in project configuration, would it be out of the question to also define SOMETHING explicitly in project configuration?
I used to have similar issues in VS2005 and 2008, and redundant explicit definitions sometimes helped.
I fixed this (in VSCode) by changing C_Cpp.default.intelliSenseMode
"C_Cpp.default.intelliSenseMode": "windows-gcc-x64"
I am building an ARM project on a micro-controller. Its not 64 bit either. But this does parse the directives correctly.
For Science I tried Widows-gcc-ARM and that also correctly lit up the regions that are truly active. I also know for a fact that gcc is setup and configured on my windows machine, and while I have clang and msvc, I dont use them and dont know that they work- so it could be why gcc works better for me.
You can experiment with this setting, but I am fairly certain the resolution resides in this option.
I do not know the equivalent VS option, I am sorry.

How to get VS 2010 to recognize certain CUDA functions

At the moment CUDA already recognizes a key CUDA C/C++ function such as cudaMalloc, cudaFree, cudaEventCreate, etc.
It also recognizes certain types like dim3 and cudaEvent_t.
However, it doesn't recognize other functions and types such as the texture template, the __syncthreads functions, or the atomicCAS function.
Everything compiles just fine, but I'm tired of seeing red underlinings all over the place and I want to the see the example parameters displayed when you type in any recognizable function.
How do I get VS to catch these functions?
You could create a dummy #include file of the following form:
#pragma once
#ifdef __INTELLISENSE__
void __syncthreads();
...
#endif
This should hide the fake prototypes from the CUDA and Visual C++ compilers, but still make them visible to IntelliSense.
Source for __INTELLISENSE__ macro: http://blogs.msdn.com/b/vcblog/archive/2011/03/29/10146895.aspx
You need to add CUDA-specific keywords like __syncthreads to the usertype.dat file for visual studio. An example usertype.dat file is included with the NVIDIA CUDA SDK. You also need to make sure that visual studio recognizes .cu files as c/c++ files as described in this post:
Note however that where that post uses $(CUDA_INC_PATH), with recent versions of CUDA you should use $(CUDA_PATH)/include.
Also, I would recommend Visual Assist X -- not free, but worth the money -- to improve intellisense. It works well with CUDA if you follow these instructions:
http://www.wholetomato.com/forum/topic.asp?TOPIC_ID=5481
http://forums.nvidia.com/index.php?showtopic=53690

complex.h workaround in Visual Studio

After some searching I've found that Microsoft Visual Studio does not provide the "complex.h" header file, but I have some C code that unfortunately uses it. I've tried using <complex> and compiling as C++ code; this requires changing
complex
to
_complex
I don't even know what I would need to change
long complex
to. Any ideas how I can get around this?
Have you tried this link?
If you can't use third-party libraries, then I think you're going to be compelled to re-implement complex functionality yourself. The good news is that most complex math is actually really simple to write, unless you need some fairly advanced features.

Resources