PDA

View Full Version : difficulty opening file



technologist
08-04-2017, 07:20 AM
Hi,

I am trying to open 2 files in my main.cpp

GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );

that will ultimately produce a red triangle. The only problem is that when main.cpp opens it, it throws a flag and a circle thingy when the external shader loader code is here:

// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
std::cout<<"Opening file system"<<std::endl; //!!!!<------------here it prints the flag and nothing //after it
// Read the Vertex Shader code from the file
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if(VertexShaderStream.is_open()){
std::string Line = "";
while(getline(VertexShaderStream, Line))

my main.cpp, shader.cpp, SimpleFragmentShader.fragmentshader, SimpleVertexShader.vertexshader are in the same directory.
Can this be rescued before an attempt at hardcoding?

mhagain
08-04-2017, 09:45 AM
Doesn't matter what directory your CPPs are in, it's the directory your executable is in that's important.

technologist
08-04-2017, 12:10 PM
Doesn't matter what directory your CPPs are in, it's the directory your executable is in that's important.

Thank you for your reply. I don't know where its going though. Yes, building a dynamic version for example would require a DLL in the .exe folder. But can you please expand on what you mean by your comments ( : ??
I don't understand. I am new to openGl but not c++. I need your help to read this shaderloader file.

Silence
08-06-2017, 11:38 PM
What mhagain told you is that once the executable built, your sources file locations are not important (except for debugging purpose, but this is another story).
Just keep your resource files in the same location than your binaries.

john_connor
08-07-2017, 09:49 AM
I am new to openGl but not c++. I need your help to read this shaderloader file.

then you should know what the "default" arguments are in your "int main(...)" function:
int main(int argc, char* argv[])
{
/* here your GL stuff etc ... */
return 0;
}

why dont you print the location where the .exe is executed ?
int main(int argc, char* argv[])
{
cout << ".exe location: " << argv[0] << endl;

/* here your GL stuff etc ... */
return 0;
}

argv[0] gives you the location where your program is executed.

another "tip":


GLuint LoadShaders(string, string);

... allocates a resource (program object, maybe some shaders too), but doesnt give you a hint if an error occured or not, it'd be better to use a function like:


bool LoadShadersIntoProgram(GLuint program, string vs, string fs);

it gives you "true" on success, or "false" on failure, it expects you to allocate the resource (program object) externally, not within the function.

Silence
08-07-2017, 11:19 PM
argv[0] gives you the location where your program is executed.

This depends on the OS and how the program has been launched. So it might not reference the full path.