C++ and glut in MS Visual C++ 6.0

I think this is a beginners problem.

I have a opengl book where the code examples are in C. I don’t know C but I do know C++.

The problem is that when I create a Win32 project in MS Visual C++ 6.0 the compiler seems to want WinMain() instead of just main.

In the code examples they use: int main(int argc, char **argv).
Well, if I write that I get an error message: berror LNK2001: unresolved external symbol _WinMain@16

In the book they use the main parameters as arguments to glutInit() and other glut functions.

I want to able to use glut instead of windows specific functions.

What should I write to get the code working with C++?.

If you don’t understand, ask me questions.

Thank’s.

[This message has been edited by Chris.W (edited 02-18-2004).]

Be sure to create a Win32 Console Application when using GLUT.

There is no problem with compiling a C program under C++.

Winmain is used when compiling a windows based appication, but since glut is handling your windowing functions you need to compile it as a console program when creating the project.

This problem is not a c or C++ problem.
You choose to create Win 32 app, but book is writed for Win32 console app.
Type this code there where you wrote main function. When you write this your program will work.

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

I agree, the first thing you should do is create a win32 CONSOLE application, in the MS VC++ wizard for a new project.

You will then be asked the type of application, where you can choose between empty project, hello world application or an application which supports MFC. The hello world application works for me most (all) of the times I’m using glut.

Dev studio then will provide 3 files, one of which (nameOfApp.cpp) will have the main function. This will feel like home © for you. If you’re thinking of writing cross-platform code, I’d suggest to work towards removing the other two files (stdafx.cpp, .h, or something, you’ll only need to add the library includes above your main function, and change the setting of precompiled header files (in project setting, c++) to something other than 'using precompiled headers through stdafx.h, which I think is the default).

You may find various tutorials useful, when it comes to setting and compilation options, as the book itself is focussed (and correctly I should think) to the OpenGL library itself. Note that there are a lot of examples/tutorials on how to use OpenGL (without glut) under Win32 and/or MFC, something I’d suggest you avoid for now, until you have your glut application up and running and you’re ready to do some OpenGL.

mad

Thank’s this was helpful.