Take a look at this below main.cpp
taken from the book: OpenGL Superbible 7th.
#include "sb7.h"
class my_application : public sb7::application
{
void render(double currentTime)
{
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
DECLARE_MAIN(my_application);
Inside sb7.h
, the related piece of code about DECLARE_MAIN()
is
#if defined _WIN32
#define DECLARE_MAIN(a) \
sb7::application *app = 0; \
int CALLBACK WinMain(HINSTANCE hInstance, \
HINSTANCE hPrevInstance, \
LPSTR lpCmdLine, \
int nCmdShow) \
{ \
a *app = new a; \
app->run(app); \
delete app; \
return 0; \
}
#elif defined _LINUX || defined __APPLE__
#define DECLARE_MAIN(a) \
int main(int argc, const char ** argv) \
{ \
a *app = new a; \
app->run(app); \
delete app; \
return 0; \
}
#else
#error Undefined platform!
#endif
What is the benefit of using this kind of unusual approach? Definitely the way the code is structured jeopardizes the readability but I'm guessing there is a point behind this. Note that, the authors are using a third party glfw to handle the window and user's inputs such as from keyboard and mouse. I don't see why they need to use 'CALLBACK WinMain()` which I know it is related solely to Windows OS. I would like to be honest here. It is good to see different ways.