Creating shader files - c++

I'm trying to learn some DirectX11 and I found good tutorial I'm following; however, for some reason the program crashes (The window appears but then a "not responding" message box appears), even though the build was successful. There were some thing about creating shader-files the author did specify on how to do, and i wanted to make sure I'm not making any errors there and that why my program crashes. So my questions are :
How do you create a shader files? In the tutorial we are using the extension .fx, but when you add a file in vs you can only choose from .h and .cpp . Do you only have to select .cpp and then add .fx in the end of the file name?
In what directory is the file suppose to be? (My files are currently in Source Files)

Yes that will work. Another way to do it is just to create a .txt then change the extention to .fx
(To show the file extention just open any folder, click on the organize button in the menu then choose "folder and search options". Uncheck the box "Hide extentions for know file types" under the tab view). After you change the extention you can open the document in notepad and write your code there
Go in to your project folder (in windows file system) and create a map called Data. Add you .fx file there. Then go to your solution explorer and rigth click on the project and choose properties. Go to Build Events -> Pre- Build Events. Add the line "xcopy /y /d "$(ProjectDir)Data" "$(OutDir)" in the box "Command Line". Now when building your project the files will be copied to the rigth place and you will be able to use your .fx file.

The .fx is associate it with an effect file. Meaning you have a combination of many shaders in the same file. Can you post some code of your render loop... also, are you calling the Present method?i.e.,
m_pSwapChain->Present(0, 0);

Related

Source file header file and other files are not displayed when I create empty C++ Project in visual studio 2019

I am very new to visual studio and I watched a couple of tutorials to understand how to use it, But I ran into a problem. Every person I watched on YT has a source file, header file, and other files when creating an empty Project but this isn't a case for me and I basically can't write anything.
when I try to add a CPP file it doesn't even show an option to add it, it only shows class and resource when I right click and press on add. Basically, I want the files to show so I can create my main program and play around with it.
Help is much appreciated.
First Create an empty project .
Second Go to solution explorer.
Third Right click the source file option.
Fourth Go to add and create a new item
Fifth Select .cpp file and press add.
And Congrats your .cpp file is created. Do the same procedure to create header file and class.

cpp file is being saved in wrong format and was unable to solve it

my notepad++ cpp is file shows an internet explorer sign as it is being saved, opens in internet explorer or I have not choose which software I want to use to open it, instead of just opening in notepadd++, but when ever I try to see the info about file it shows cpp I looked up and didn't find any such question to get answer from.
Maybe it's being saved with the wrong ending. are you hiding file extensions in explorer? Right click on the file and check the name in properties. Also you want to ensure that file extensions are always shown. Go into "view" in Windows Explorer and ensure that "file extensions" checkbox is on (later Windows versions). Or in earlier Windows/Windows in general, click into Folder Options/View and turn off "Hide Extensions for known files". As a developer you always want file extensions shown.
If you have the wrote file extension and it's hidden the file could be like "file.cpp.txt" or "file.cpp.html" or something instead of an actual cpp file.
Once you've double-checked the file extension and made sure file extensions are not hidden, if that isn't it, right click the desired file and look at "Open With", "Choose Another App/Program" (depending on Windows version), then look for the right program to open it with and make sure you click "always open with this program".

Cant open html resource file using ifstream::open - Visual Studio 2013

I am working on a project which requires me to open an HTML file and use its contents. I added it to Resource files but when I try to open it lie this:
std::ifstream templateFile;
templateFile.open("filename.html", std::ifstream::in);
The operation fails. I checked it by using templateFile.fail().
The above operation works when I provide the full path. The file lies in the project folder along with other files. I tried setting build action to content but still it doesnt work. Please Help.
Output directory, where your executable is compiled and put into differs from the source directory, where you create all your .cpp/.hpp files (I assume there is filename.html file). Local path filename.html is supposed to be local for your executable file, not the source file.
Read more about changing the output directory here: https://msdn.microsoft.com/en-us/library/ms165410.aspx
Under Configuration Properties / Debugging, see what your Working Directory is using the macros dialog box. Move your file into this folder.
Click the button shown in the figure. There, click either Edit or Browse. Browse will take you to the working directory. Edit will expose the link to open the macros box

"Error C1083: Cannot open source file" Shouldn't Be Looking For The File At All

I was trying to #include a cpp file with some functions so I can use that cpp file later with other projects. It gave me an 'already defined in .obj' error and since then that .cpp file was like binded with my project. (I understood that's not the way, the answer here helped me with the already defined)
If I exclude the .cpp file from the project, remove it from the directory and remove the #include line it still looks for it:
c1xx : fatal error C1083: Cannot open source file: 'std.cpp': No such file or directory
Diagnostic:
Outputs for D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\CBMAIN.CPP|D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\STD.CPP: (TaskId:15)
It shouldn't be looking for the std.cpp at all, I removed it! So is there a way I can reset the project and recompile so that the program doesn't look for it? I already tried Rebuild and Clear -> Build Project
When I ran across a similar problem with VS Express, I wound up having to open up the the .vcxproj file (which is just XML), and remove the offending
< ClInclude Include="FILEPATHANDNAME" > tags.
Many of the solutions here will not work
Fullproof method:
Open the vxproj file that is giving you trouble in a text editor.
remove all references to the file it cannot find.
OK, I have no idea how I did it but I'm still going to try to write what I did.
Save all and Close solution
Open the .vcxproj file (not .sln)
Build -> Clean [Project Name]
Save all and Close
Open the .sln file again.
Build -> Project Only -> Clean Only [Project Name]
Build -> Project Only -> Build Only [Project Name]
That's exactly what I did and worked for me. I think the main thing to do is clean, save, close, open, build, but I'm not sure.
In Solution Explorer you can select/deselect option "Show All Files".
Try both options and make sure excluded file is not included in project for both of them.
That's what I had:
I used "Show All Files" option (so you can see all the files in project directories). I excluded one of my .cpp files from project. However, it behaved as this file is in project.
That's how I managed to fix it:
I switched "Show All Files" off and saw this file still belongs to project! So I excluded this file once again.
As I see, that's a known issue.
This worked for me, hope it will be useful for someone else.
Try to verbose builder output to see exact steps of what's going on. I suppose, you use Visual Studio, right?
Go to menu "Tools -> Options"
In options dialog, select "Projects and Solutions -> Build and Run"
Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
Rebuild your project and investigate Output windows
Builder dump should shed more light on your current settings (I suspect you have more references to that file than you expect)
This happened to me because I renamed folder from inside the IDE. None of the above solutions worked. The only way to fix this is by opening vcproj in notepad and you should see the offending files in the <ItemGroup>. Just delete those lines.
Or sometimes, like in my case, the issue is simply in the naming of the folders in the location. I had a very long path with folders that I like to name with special characters so they show up at the top and it's easy to access them.
As soon as I put my solution in a folder just in D: drive, the issue was gone.
When I renamed a file, I found I had to go to SolutionExplorer, Source File, select the file, first exclude from Project, then re-add it to project, and rebuild the solution it lives in. It was still showing up as the old file name under Source Files for me.
I had the same problem, but I had another .sln worked fine. After tooling around with the Project->Properties-> to make them look identical, nothing worked. I opened both .vcxproj files and copied the contents of the working version into my non-working version. (I noticed that the two files had different lengths. The non-working version was longer by about 20 lines.) I just changed the RootNameSpace to the non-working version's name. I saved the non-working file and presto! It worked.
I removed those sources from Project and re-added them. Somehow, references were messed up after a hurry project refactoring.
For people having problem related to "error C1083: Cannot open source file":
Error is caused by settings in *.vcxproj file. Probably you deleted/moved source file by file explorer, not by Visual Studio's "Solution Explorer". Thus, your *.vcxproj file is corrupted. Fix is to manually correct settings in *.vcxproj file.
How Visual Studio settings files work
Visual Studio saves solution's info into file. This file is usually in project's solution directory, has extension .sln and base name is same as name of solution, f.ex.:
NameOfSolution.sln
Similarly, project's info is saved into one file (each project has its own file). Base name of this file is name of project, extension is .vcxproj, and usually is located in subdirectory named as your project, f.ex.:
NameOf1stProject/NameOf1stProject.vcxproj
NameOf2ndProject/NameOf2ndProject.vcxproj
Both *.sln and *.vcxproj files are textual files. You can open them by using Notepad.
How to fix problem
Find *.vcxproj file responsible for your project.
If you don't know where it is, open in Notepad the *.sln file of your solution. Search for name of your solution. You will find line like:
Project("{9AA9CEB8-8B4A-11D0-8D22-00B0C01AA943}") = "NameOf1stProject", "NameOf1stProject\NameOf1stProject.vcxproj", "{A8735D0A-25ED-4285-AB8F-AF578D8DB960}"
Value under "NameOf1stProject\NameOf1stProject.vcxproj" is location of *.vcxproj file of your project.
Open found *.vcxproj file by text editor (f.ex. Notepad).
Search for line on which is filename you are struggling with.
Example: if you are looking for "RemovedFile.cpp", then you should find line:
<ClCompile Include="RemovedFile.cpp" />
Delete that line.
If you have opened Visual Studio, it asks you if it should refresh solution - select yes. If it is not opened - just start using it.
In case of any problems, try to rebuild solution (top banner -> Build -> Rebuild Solution)
In my cases, it worked. 30 mins of trying to fix, <1 minute of fixing.
This helped in my case. To sum it up, my path to the project was too long, so I moved my project to something shorter i.e. D:\my_project and everything worked in a blink of an eye.
I had this same problem, but for me the issues was that I was using Bash on Windows (WSL) to clone the repository and then using VS to compile.
Once I deleted my clone and used Windows command line (cmd.exe) to clone the repo then the error 1083 went away.
This is caused by not removing/deleting the file properly. Go to Solution Explorer, select your solution, at the left corner, activate the icon: show all files.
(if you already removed the problem file, restore it from recycle bin)
Select the problem file, do remove and delete from within Solution Explorer and you should not have this problem. And remember to do it the proper way from now on.
This is on MS 2010
If you have that file in your project directory but you still got the error, on your IDE go to Solution explorer--> Remove that file-->then open the project directory on your file explorer-->Select that file and drop it on a specific location in IDE solution explorer. I fixed it this way. I use the Windows platform.
I got this error when I got a code from my peer and I tried directly running it on my system. Ideally to avoid such errors, I should have just copied the source and header files and should have created the VS solution of my own.
To resolve the errors I removed the files from the Solution Explorer and added them again. Following image shows the Solution Explorer window.
The remove option comes after right clicking on the file names.

Where does Xcode create .txt files to?

http://www.cplusplus.com/doc/tutorial/files/
I just finished executing this but I didn't get any file on my desktop.
So where does the .txt file get placed on my computer?
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Damn... I've seen this post never answered many times..
Here's the solution
In your project navigator when you're working in your current project there are many files. Try products (if I remember) and look for the executable file. Now go to the properties inspector or whatever is called. (Right side of your Xcode.)
There you will find somewhere a part called PATH the path that is written over there. It's the path where the executable runs. That means there is where you'll find all the files you create with your program.
Try it... that's how I manage and look my .txt files since sometimes I wanna give them some kind of formatting.
I hope I've solved your problem... cheers! ;)
Click on the executable in the Products tab on the left hand side, and you should see the path to it displayed on the right in the utilities section. This is where they are saved. On my computer this path is:
/Users/myName/Library/Developer/Xcode/DerivedData/CurrentXcodeProject-adsnvetbleazktcgitfymfcbhkkt/Build/Products/Debug/filename.txt
In the "current directory", meaning the working directory of the environment from which you ran the executable.
I can't tell you what that is, but in basic cases it may be the directory where the executable is located. In many other cases it may not be.
Performing a search for the file on your hard drive will reveal its location to you.
Right click on your product and select "Show in Finder". Thats opens the path to where the output files go. Also you can add input files there to be read in by your program.
Found best answer here:
File creation in C++ on Xcode
Basically you can specify a known directory so that all files created go there.
If you are on Mavericks Right click in your user folder with your documents and pictures and stuff (~/Users/yourusername)
Now right click and view options. Check "show library". Now follow to the path that the first user above said.
What I've always done when an application saves a file and I don't know where... is just go back to that application, and hit File>Save As...
So re-open Xcode and go to the "File" menu, and click "Save As..."
It will show you the same directory it just saved to.
I have checked the "Current Directory" but I believe I have to specify the location. Not even
~User/Desktop
will work.
What I do is create an empty file with a the correct name on my desktop then drag that file into my Xcode project to get its path. I then delete the file.
Same with adding files to my project. I can add them from the File menu, but I will need to drag them in to the spot in my code where I want to reference them.
It is kind of convoluted but it is the only system I have.
Some of the answers are confusing. Here's the simplest solution.
1. Expand your Products folder on the left-hand side
2. Right click on the terminal icon(sorry I do not know what it's called)
3. Click show in Finder.
You should be able to see your output file in there.
" Where does Xcode create .txt files to? "
You can decide where you want: follow these->
" Product->Scheme->EditScheme "
chose options tab in the new popup "options"
"working directory" tick "use coatroom working directory" and locate the folder where you want.
The .txt file that you "create", or that you want too "read" has to keep in this folder.
In 2022, click on the project name in the "breadcrumbs" area above the editor. Select the correct thing in "Products", then in the right area, see "Full Path".