Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: difficulty opening file

  1. #1
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    difficulty opening file

    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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    Doesn't matter what directory your CPPs are in, it's the directory your executable is in that's important.

  3. #3
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    please expand

    Quote Originally Posted by mhagain View Post
    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.

  4. #4
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    429
    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.

  5. #5
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    445
    Quote Originally Posted by technologist View Post
    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:
    Code cpp:
    int main(int argc, char* argv[]) 
    {
    /* here your GL stuff etc ... */
    return 0;
    }

    why dont you print the location where the .exe is executed ?
    Code cpp:
    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":

    Code :
    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:

    Code :
    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.

  6. #6
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    429
    Quote Originally Posted by john_connor View Post
    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.

Posting Permissions

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