PDA

View Full Version : How to open files dynamically in opengl



vijaykiran
01-15-2003, 08:54 AM
Hi,
With a little thought of whether this forum is correct for my question, i posted it finally.
In my OpenGL programs, I had to read in few data files before i start rendering to screen. Until now, I include the file name directly in my program using a file pointer. I would like to know if there is any possible way to open a file from my local computer by clicking a button followed by going to the directory i wanted and then selecting the file I wanted - Just like other applications in windows or for that matter any platform. I would just have to provoke the file open window from my local system, using opengl. I have both GLUT & GLUI with me. I could even use it in my code if necessary. I appreciate if some one could help me out from my situation. I do coding using an SGI environment in C programming language (not C++).

If I am not clear, here goes an example. I need to render something on the screen after reading the coordinate positions from one of the data files residing in my local computer. Through some kind of call back, I have to provoke file open function of the OS and select the file I needed through a list of directories. I render something on the screen after reading the file I select it from the file open function. Once rendering is done, if I need to render some other data file, I again need to provoke the file open function through a call back and render the newly opened file now. I hope i was clear enough. Can any one help me?

Thanks,
Vijay.

Coriolis
01-15-2003, 10:17 AM
I'm not familiar with SGI machines, but I expect you do it the same way you would in any other program. Looking up info about writing file dialog code on SGI machines would be the place where I'd start.

dorbie
01-15-2003, 12:03 PM
Yes there are GUI functions to let the user specify a filename. A common approach is to accept a filename on the command line (in OS' with no command line this happens when a file is dragged onto the application too). If you want the user to specify a file then you need to use a file browser widget. These are high level functions that create a gui, support directory browsing and return a string as the filename, typically with a full path to the file.

Most GUI toolkits have such a widget. Which GUI you use depends on your preferences.

jwatte
01-16-2003, 06:42 PM
Most UI toolkits have an easy way of hooking when a user drops a file onto the contents of a window. Thus, go looking for this (OS-dependent) hook, and when it gets called on you / you get the event / whatever your OS uses to deliver this stuff, nuke whatever data you previously loaded (if appropriate) and load the data from the file just dropped.