Loading a File

Hi!

I’ve got a little problem. Can anybody tell me how I can load a file in opengl through a dialog, so I can choose which file I want to open and don’t have to use the absolute path?

Thank you.

OpenGL graphics API, handles only graphics.
If you are working in windows you need to look at the windows API(MFC) for how to use a dialog box and file access.

I am guessing you are using C/C++, which also you will need to look at how file I/O functions work in C/C++.

As for path, if a path is not indicated the file will be expected to be in the same directory in which the .exe file is located.

Originally posted by Teddy:
[b]Hi!

I’ve got a little problem. Can anybody tell me how I can load a file in opengl through a dialog, so I can choose which file I want to open and don’t have to use the absolute path?

Thank you.[/b]

If you examine Display3DS you should be able to simply copy and paste the file selection dialog code. Here’s a synopsis, but as always, Use The Source, Luke!

.
.
.
// Register event handler in your Window class
afx_msg void OnFileOpen();

// add this to your window’s BEGIN_MESSAGE_MAP:

ON_COMMAND (ID_FILE_OPEN,OnFileOpen)

// here are some string variables:
CString FileName (“Sample.3DS”); // Filename default
const char FileNameExt[] = “3DS”; // Filename extension
const char FileNameFilter[]= “3D Studio Files|*.3DS|”; // Filename filter for 3D Studio mesh files

// here’s a sample OnFileOpen routine:

void CMyAppWindow::OnFileOpen()
{
CFileDialog fileDialog (TRUE,
FileNameExt,
NULL,
OFN_FILEMUSTEXIST,
FileNameFilter);

  	if	(fileDialog.DoModal() == IDOK)
  		{
  		FileName	= fileDialog.GetPathName();
  		
  		}
  	}

Or, just look at the Display3DS.cpp mainline, not the scary 3DS mesh loading code.

Good luck,
/p2

If you want to use the standard “Open File” dialog for Windows w/o MFC, you should look at the Win32 API function called GetOpenFileName().