# Thread: Unable to open file 'triangles.vert'

1. ## Unable to open file 'triangles.vert'

Hi all,

After too much effort I could make the code below on VS 2017 run:

Code :
#include <std_lib_facilities_4.h>
using namespace std;
#include "vgl.h"

enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//--------------------------------------------------------------------
//
// init
//
void
init(void)
{
static const GLfloat vertices[NumVertices][2] =
{
{ -0.90, -0.90 }, // Triangle 1
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 }, // Triangle 2
{ 0.90, 0.90 },
{ -0.85, 0.90 }
};
glCreateBuffers(NumBuffers, Buffers);
glNamedBufferStorage(Buffers[ArrayBuffer], sizeof(vertices),
vertices, 0);
{ GL_NONE, NULL }
};
glUseProgram(program);
glGenVertexArrays(NumVAOs, VAOs);
glBindVertexArray(VAOs[Triangles]);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glVertexAttribPointer(vPosition, 2, GL_FLOAT,
GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}
//--------------------------------------------------------------------
//
// display
//
void
display(void)
{
static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
glClearBufferfv(GL_COLOR, 0, black);
glBindVertexArray(VAOs[Triangles]);
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
}
//--------------------------------------------------------------------
//
// main
//
int
main(int argc, char** argv)
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(640, 480, "Triangles", NULL,
NULL);
glfwMakeContextCurrent(window);
gl3wInit();
init();

while (!glfwWindowShouldClose(window))
{
display();
glfwSwapBuffers(window);
glfwPollEvents();
}

glfwDestroyWindow(window);
glfwTerminate();
}

Now it shows the output as below, but on the Windows cmd this message has been written:
Unable to open file 'triangles.vert'

Would you please test that code on your system? Does it show that for you too?
Is a problem that I must solve?

2. I think you are not putting triangles.vert in local folder where your all .cpp files are present. If you are triangles.frag is loading properly open that file see where it is and in same location copy your triangles.vert.

3. Thank you.
I even don't know what file it is. I just copied the code from the book into the project. I try to find more about it.

4. Well, looks like your problem is already solved. But I thought I'd mention my response anyways.

As PixelClear mentioned, your triangles.vert file may be in the wrong directory. Or you don't have the file.

Another cause could be that you're trying to run the .exe file you built outside of Visual Studio, which causes differences in path searching. I don't have VS 2017. I have VS 2015, but I assume that how paths work when running in or outside either version are the same. In VS 2015, you build/run the current project in the solution. It's also known as the startup project. I guess it's called "start up" because when you click Debug->Start Debugging or Debug->Start Without Debugging, it starts up the build from your project that you're interested in running (assuming it's an .exe. If you're building a .lib static library or a .dll dynamic library in your startup project, it wouldn't make sense to run it). I also guess it's called "start up" because it's the first project that's built in a VS solution, which can matter depending on if a project depends on other projects in the same solution.

Anyways, assuming that this is your startup project (you right click on your project and click "Set as Startup Project"), in Windows, when you run your project from Visual Studio, it seems that it runs a command from command prompt relative to your project's current directory, not where your built .exe file is. So far, what I know is that if a command is run from command prompt like this, the .exe by default searches for files to load (if it needs to) from that directory where the command was run, if you didn't specify an absolute directory in your program. Interestingly, I don't even think cmd searches for files in the same directory as the .exe itself (even if you use relative "." notation in Windows .cpp programs)

=====
So for example, if I had a solution open and my project folder was here:

C:\Users\<My Name>\Desktop\Scripts\learnogl2\modern_ogl\diffuse _cube

and my Debug .exe was built here:

C:\Users\<My Name>\Desktop\Scripts\learnogl2\Debug

If I ran my project from Visual Studio, the command prompt command could look something like this:

C:\Users\<My Name>\Desktop\Scripts\learnogl2\modern_ogl\diffuse _cube>C:\Users\<My Name>\Desktop\Scripts\learnogl2\Debug\diffuse_cube .exe

or maybe even this, given the directories I put here, if Visual Studio is more for relative directories:

C:\Users\<My Name>\Desktop\Scripts\learnogl2\modern_ogl\diffuse _cube>..\..\Debug\diffuse_cube.exe

Nonetheless, in either case, given this command, diffuse_cube.exe will look only in my modern_ogl\diffuse_cube folder, and not in its own directory, to look for any relative files if it needs to load them.
=====

=====
The above would all work fine, if I put my extra files in my project folder, but if I only ran my .exe from my its own current directory (either via Windows Explorer or cmd), I'd get an error somewhere if I didn't move any files to that directory at that time. The cmd command of interest would be:

C:\Users\<My Name>\Desktop\Scripts\learnogl2\Debug>diffuse_cube .exe
=====

-------------------------
As a post-note, I remember replying to you in some "Starting OpenGL" post. I checked on some of your past posts (sorry, that sounds a little creepy, was just wondering what you were doing to make your solution), and apparently, you're using the "OpenGL Programming Guide 9th Edition" book. I think that's a bit too much too start off with. Are you sure you want to do that? I've looked at some sample pages from the 9th edition book in Amazon, and I think it's pretty advanced for someone starting off, in my opinion.

I think it's cool to be able to work with the latest versions of OpenGL, but as I've posted to you back in the "Starting OpenGL" post, sooner or later you'll find yourself needing to analyze the specification, regardless of how many books/tutorials are there. And the 4.5 core specification is huge, at 805 pages. (note this even doesn't count the GLSL) While the 3.3 core spec, the one used by the LearnOpenGL tutorial I mentioned a while back, is at around 425 pages. Still a lot, but more manageable, in my opinion. In my experience, as someone still relatively new to OpenGL and wanting to understand the specification more, having less pages to analyze is a good thing. Less features, but more room to think about how certain functions work. I'm thinking it could be a good idea for you too to just stick to the LearnOpenGL tutorials at 3.3 core and then, when you feel very comfortable with it, use a newer version. 3.3 core and 4.5 core both use shaders, so it'd be a friendly transition.

OpenGL 3.3 core is already powerful as it is. Games-wise, a lot of amazing games in my opinion have already been made before that spec was released in 2010, like Dead Space 2 and Mirror's Edge (yes, they probably used DirectX instead for PC, but this is just to put it in perspective with OpenGL). I'm not sure if you're using OpenGL for visualization or games, but if it's for games, I think 3.3 core can produce some pretty nice results, even with less features than 4.5.

Lastly, as 4.5 is a newer version (4.5 core says it came out this June 2017, 4 months ago), only newer graphics cards support it. Some people on this forum may not be able to run your code if their graphics card can't support that version. My laptop for example can't run your code, even if it's logically correct (you used glNamedBufferStorage in the code you posted, which automatically means a graphics card must support at least 4.5 to work with it). My graphics card can only run to 4.0. I think you'd be able to get more people to try to run your code and maybe even give an answer to your question if you stuck to a lower OpenGL version. And you can reach a wider product audience if you use a lower OpenGL versions, if you're making a product, as there are probably still a lot of people that can only run lower versions. Again, you'd get less OpenGL functionality, but in my opinion, you can already do a lot with something like 3.3 core, and I think you'll satisfy a lot of people already, given the graphics you can make with it. But this and my thoughts on released games is more opinionated, just to admit it. I don't know what you need, graphics-wise, and I don't know how many people right now can run 4.5/4.6 code.

Anyways, hope that helps. Looks like if you can run your code, you already have 4.5. But if you're planning to sell your product or something to customers, thought it'd be nice to mention the OpenGL Extensions Viewer here. It's a Windows app that can check what version of OpenGL you have. Could help if someone using your product has trouble making it work.

By the way, what are you using OpenGL for? Just curious. I wrote some stuff about product audience. I've never done something like that before, like to sell it, but since you mentioned your LinkedIn a while back, I'm assuming you're a programmer, career-wise, and intend to make a product. If it's just for curiosity's sake, then well, as a side-note, you're lucky you have 4.5. I'll get to upgrade to it one day, haha.

5. Hi,

I've created an Empty C++ project and pasted the code above and after adjusting the project's properties fields I ran it.

The problem was about giving paths!
I found the both files and changes the code to:
Code :
...
...

Although it should have no problem this time, but it writes some other message! By the way, the book has written the code for that example in a few pages but they are equal!!

And about my previous issue, I solved that. If your're interested in the solution I can express it.

you'll find yourself needing to analyze the specification
What do you mean by this please?

I accept that the book is by no way easy. It's new a rather complete and although it's sophisticated, I will find solutions for that. But thanks for your good talks.

Well, you must be right. My Graphic card can handle OpenGL 4.4 while the book is 4.5. I hope I face the least issues in this case.
About https://learnopengl.com/, it seems good but I really don't know it's better than that book. By the way, books are at the highest level of validity compared to other sources. I also don't like to regret preferring that tut to that book.

Yes, I'm a programmer (like you, I assume), and need it for my future tasks. That's all.
Thanks.

6. Well, looks like you already said in a recent post that you'll try LearnOpenGL (which is great, hope you like it), but I'll still post this:

---

Oh ok, it was an incorrect path input.

---

I'm not sure what you mean by "the book has written the code for that example in a few pages but they are equal". Do you mean the example source code is the same as the book code? If so, that's a good thing.

---

For your solution, if you can summarize it, that'd be great. I can't use OpenGL 4.5, but I'm still interested in how the setup works. The new headers seem interesting, like gl3.h.

---

About the specification: if you're looking for the complete, official "documentation" describing OpenGL, look for the specification. What I know so far is that it's meant for both both implementers (the people who write the libraries that directly access the hardware. I believe in Windows, a team programmed a dll called opengl32.dll to do so), and programmers (people who are just interested in using the functions). There's nothing more complete than that. It's like the C++ standard for C++ (I haven't read it. I just know about it. Maybe glanced a little at it for curiosity, C++/books tutorials are plenty already for me for now). It's complete, but it's very hard to read, and is not something you want to start off with as a beginner, in my opinion. And like I mentioned earlier, it's also why I think you should try out a lower version. Because when you feel like you'd like to see OpenGL completely, you'll meet a shorter spec, which invites more time for analyzing things.

For starting off, tutorials like LearnOpenGL are plenty enough to get stuff working, and I think that's a good starting point for beginners. Sure, it may not be 100% complete, and there may be a mistake or two (in that case, make sure to contact the author so he/she can correct it!), but it's helpful nonetheless, and has nice tips.

That may be true, books probably have a lot of validity if they are approved for publication and possibly checked by an editor. Plus, looking at the programming guide sample pages, it seems like those authors have worked at Google and AMD. But their target audience may vary. I don't know if they mention it, but looking at the first few pages, it looks like the guide's audience is people who are already comfortable with opaque data types like buffers and maybe even hardware access. That doesn't sound beginner friendly, in my opinion. For me, just getting comfortable with the idea of "opaqueness" (and finding out that word exists for data types too, haha) was a lot. While LearnOpenGL is not as complete, and the author, Joey De Vries, is only a computer graphics enthusiast, according to his about page, his target audience is more towards beginners. He even mentions in his Introduction that while that tutorial is for C++ programmers, he tries to offer C++ tips when he can. (Also, he did mention about being a university student. That's good validity too, in my opinion!)

So still, I recommend just starting off with LearnOpenGL. Unless you really are that familiar with low-level hardware programming already, I think that's a good place to start. Nonetheless, it's up to you to choose something comfortable.

7. Originally Posted by DragonautX
I'm not sure what you mean by "the book has written the code for that example in a few pages but they are equal".
Sorry, my bad. I should have written "aren't" rather than "are" there.
That is, the source code (of the example 1) is written in several parts of the book, but they are "not" the same, i.e, the reader can't decide which one to use. Besides, the source of that example in source code examples directory accompanying the book, "isn't" again the same as the ones written in the book either!!!

For your solution, if you can summarize it

About the specification: if you're looking for the complete, official "documentation" describing OpenGL, look for the specification. What I know so far is that it's meant for both both implementers (the people who write the libraries that directly access the hardware. I believe in Windows, a team programmed a dll called opengl32.dll to do so), and programmers (people who are just interested in using the functions). There's nothing more complete than that. It's like the C++ standard for C++ (I haven't read it. I just know about it. Maybe glanced a little at it for curiosity, C++/books tutorials are plenty already for me for now). It's complete, but it's very hard to read, and is not something you want to start off with as a beginner, in my opinion. And like I mentioned earlier, it's also why I think you should try out a lower version. Because when you feel like you'd like to see OpenGL completely, you'll meet a shorter spec, which invites more time for analyzing things.

For starting off, tutorials like LearnOpenGL are plenty enough to get stuff working, and I think that's a good starting point for beginners. Sure, it may not be 100% complete, and there may be a mistake or two (in that case, make sure to contact the author so he/she can correct it!), but it's helpful nonetheless, and has nice tips.
Yes you're right, learnopengl is better for beginners. I agree. And it's much more user-friendly.
For the specifications, I might go for them after finishing the learnopengl book. I think that would be OK for that time.
By the way, are you a programmer of OpenGL, or C++?

8. About the book code: That doesn't seem so convenient, but I don't have the book, so I can't see for myself. Again, maybe their intended audience was people already comfortable with graphics programming and are fine with incomplete/modified samples. Different window management APIs have different methods of setting up OpenGL, so maybe their intention was to focus less on complete source code and more on highlighting OpenGL functions, to be neutral about those APIs and not force all their readers to understand what seems to be GLFW for that edition.

----

---

I'm learning OpenGL on C++. I'm not sure what you mean by "OpenGL, or C++". I need both. I'm not a full-time developer on either OpenGL or C++, only an enthusiast.

9. Of course I do work on my imagination projects for each chapter and also analise the code on the site when reading it. Fortunately the tut has exercises for each chapter and if needed I will also ask forum members to as a favor offer a good exercise for each chapter to me and I will post the result on the forum as well.

I meant whether you're learning pure C++, for example using a book/tut or, you've learnt C++ and you are now working on OpenGL.

10. Ok, that's good. I'm learning OpenGL, but occasionally I may be learning C++ too if I find something new.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•