Reputation:
I have always wanted to start creating a simple window from scratch in C++ but the only results I've found on the internet are either using the Win32 API, DirectX or OpenGL. I want to make it without any of those APIs. Also would Win32 be compatible with other operating systems other than Windows. I want to make one program that is compatible with all operating systems that doesn't use any API except from plain C++ that creates a window.
Upvotes: 4
Views: 9542
Reputation: 618
On Windows, you can't avoid the Win32 API if you want to create a window. Everything you use will ultimately be using Win32 API calls to create your window for you.
That said, use a good graphics library or GUI library to create the window you want. I personally recommend Allegro 5 (http://liballeg.org), but you can also use SDL, SFML, ClanLib, Qt, WxWidgets, or any of many other libraries to create a window for you.
In Allegro 5, creating and displaying a window is as simple as :
#include "allegro5/allegro.h"
int main(int argc , char** argv) {
if (!al_init()) {return -1;}
ALLEGRO_DISPLAY* display = al_create_display(800,600);
if (!display) {return -2;}
al_clear_to_color(al_map_rgb(255,255,255));
al_flip_display();
al_rest(5.0);
return 0;
}
Upvotes: 6
Reputation: 1243
I think you misunderstand the purpose of these APIs. You cannot simply make a window in "Plain C++". Ultimately, this task requires co-ordination with the operating system (Windows) or a window manager that sits on top of the operating system. The only way you can co-ordinate with the OS is by using the APIs it provides (On Windows, Win32 does exactly this).
If you are striving for portable code that will be able to display windows on many platforms, you can use a library like the Qt framework, wxWidgets, or any other such cross-platform GUI library. These libraries will communicate with the OS and/or window manager on your behalf. They will wrap up all the different Windows/Mac/Linux APIs for creating and displaying windows and will give you one consistent and relatively easy to use API that works on all platforms. Underneath, they will use the API for the platform the application was compiled for.
Upvotes: 13