Studio.h FILE wont open .raw file

Using OpenGl and windows to create a little fog example in my compiler but im running into issues with opening a raw file to create terrain. heres the potion of code that corresponds to my problem:

how i caught the error in WINMAIN

1
2
3
4
5
6
7
8
//g_glRender is a dynamically allocated variable to my CGfxOpenGL class
    //call to my openGl class to initialize needed data, returns true/false upon finishing
    if(!g_glRender->Init())     
    {
        std::cout << "Init()";  //console reading out this error
        delete g_glRender;
        return 0;
    }


my Init() function in CGfxOpenGL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
///NAME OF FILE IM TRYING TO OPEN, NAMES MATCH EXACTLY
const char heightmapFilename[] = "heightmap.raw";

//code here, etc.. etc..

bool CGfxOpenGL::Init()
{
  myglFogCoordf = (PFNGLFOGCOORDFPROC) wglGetProcAddress("glFogCoordfEXT");

///--------------------------------------------------------
  FILE *pFile = fopen(heightmapFilename, "rb");
  if (!pFile)
    return false;

  fread(&heightmap, TERRAIN_SIZE * TERRAIN_SIZE, 1, pFile);
  fclose(pFile);
///---------------------------------------------------------
  glLineWidth(3.0);

  glEnable(GL_DEPTH_TEST);

  return true;
}



The raw file im using is copied over from a seperate folder that holds examples for the book im reading(not sure if that matters at all).
Last edited on
Is your program looking for heightmap.raw in the right place?
i placed the file directly in my main folder holding all my files, should i specify a specific location for it?
If you're using an IDE such as Visual Studio, I expect your executable is not running in the directory containing your source files.

Specify the complete path:

const char heightmapFilename[] = "C:/some/directory/heightmap.raw";
It should be in the working directory.
¿What does perror say?
thanks a ton moschops! i had to specify the directory as you just said. Got it working
I would rather recommend to change the working directory when running your program from the IDE (instead of hard-coding the path in code). In Visual Studio you can find it under Project Properties -> Debugging -> Working Directory.
I highly recommend using GetModuleFileName() and PathRemoveFileSpec() to get .EXE file directory, no matter what current directory is and without need to hardcode the path.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773748%28v=vs.85%29.aspx
Topic archived. No new replies allowed.