2

I might not be searching for the correct terms, but I'll try to explain what I am looking for (probably common).

In Windows to create a window you usually go through WinMain(), but not all platforms (Linux, OS X, etc) use this function as an entry point to the program.

While I know there are a lot of libraries out there, I'm more curious about the implementation for educational reasons and not looking for a 3rd party library to handle this for me.

The implementation of this is huge I'm sure, but I'm curious on a more abstract level, how would you write your entry point to be able to handle window creation on multiple platforms.

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
  • 1
    Don't reinvent the wheel, particularly that one as it is *way more complicated* than you can imagine. Just use a portable windowing library (Qt, GTK, wxwidgets...) – David Rodríguez - dribeas Jul 14 '12 at 16:13
  • @DavidRodríguez-dribeas - I'm interested in how it works, not how to implement it. – afuzzyllama Jul 14 '12 at 16:14
  • ... and if you're interested in the implementation, read one of those existing implementations to start with – Useless Jul 14 '12 at 16:14
  • 1
    Typically a toolkit has a bunch of classes that represent windows, edit boxes, etc. and standard methods on them. Then they have a separate implementation for every platform of all the low-level bits of each of these classes. Creating such a toolkit is a huge job. – arx Jul 14 '12 at 16:18
  • 1
    @arx - I'm not interested in a toolkit, I'm interested in getting a blank window up to attach a DirectX or OpenGL context to. – afuzzyllama Jul 14 '12 at 16:21
  • @afuzzyllama: glut could be an option there... it is a toolkit, but somehow of a light one, and is cross platform. If your interest is just creating an OpenGL window for drawing in a multi platform way, you should really ask that, instead of the more vague and complex question you are asking here. – David Rodríguez - dribeas Jul 14 '12 at 16:23
  • @afuzzyllama "a separate implementation for every platform of all the low-level bits". There's no magic. Write windowing code for every platform you want to support or use a toolkit. – arx Jul 14 '12 at 16:23

1 Answers1

3

I'm curious on a more abstract level, how would you write your entry point to be able to handle window creation on multiple platforms.

The entry point of a C++ program is main, and that is cross platform. After that, you will need to use the specific library you need to create the windows and anything else. Different platforms/libraries can provide a main function for you that will perform the initialization and then call a specific function (WinMain in the case of windows)

You might want to take a look at this question regarding WinMain.

Community
  • 1
  • 1
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489