Sign in to follow this  

OpenGL opengl win and linux

Recommended Posts

Hy. I have some little experience in dx 10 . I would start to programming opengl 3. How i can write a portable(win and linux)c++ project? I see that there are some .so in linux and dll in win that are inconpatible(win don't use .so and linux dont use .dll) How i configure a portable project? Thanks

Share this post

Link to post
Share on other sites
Well i have a project template that i've put together so that all my projects work both in windows and linux. So I can explain the way do it:
Firstly, I use SDL as my windowing manager both in linux and windows (rather than the win32 api stuff).

I do all the windows library references using preprocessor directives and also specify it to use a console subsystem. So my project's main source file contains:

#ifdef _WIN32
# pragma comment(linker, "/SUBSYSTEM:CONSOLE /ENTRY:WinMainCRTStartup")
# pragma comment(lib, "opengl32")
# pragma comment(lib, "glu32")
# pragma comment(lib, "glew32")
# pragma comment(lib, "sdl")
# define WIN32_LEAN_AND_MEAN
# include "windows.h"

In linux, my makefile will handle the compilation and library references with something like:

g++ -o linux_out/myapp -lSDL -lGLEW myapp.cpp

All the code must use functions available in both OS'.. If it's not, then use an ifdef to choose. For example the WinMain signature should be main(..) in linux, so i have:

#ifdef _WIN32
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmd, int nShowCmd){
int main(int argc, char *argv[]){

I can't think of anything else that's important right now. It'll take a bit of fiddling, but that should help. By using GLUT or SDL(in my case) one can avoid all the OS specific window/input handling.

good luck

EDIT: As for the shared libraries/dlls, ld in linux should be able to locate any needed shared libraries, but in windows you may wanna keep the dll's in the same directory, or in the system path(though distribution may be harder then).

Share this post

Link to post
Share on other sites
You can't use glut or glfw?

If you wish to make your own framework (which is quite educative and rewarding in my opinion =)), simply abstract the work needed to be done on both systems. Such as:

open window
render to window
read input
etc ...

Then implement everyting on both platforms. One header, differenct .c (or .cpp) files - this is approach I take.

I also try to keep myself to as much ansi C and iso C++ as possible. Using only one compiler - gcc only, might be of great help, instead of targetting several compilers at once.

As for the tip above, it is correct. But don't ever use WinMain. That is common missunderstanding that every win32 application HAS to start in WinMain. It has not!

It is just a convenience used by microsoft. You can start any win application in standard main. You gain nothing by using winmain. You rather loose on portability and some convenience such as console io, and it is common to see questions on how to "enable" console in windows applications, and unnecessary code like this:

Check my post here:

There is a tiny little demo that will open a window and prepare it for rendering. It starts in main, but it is very "windowsh".

For some more abstracted thing, check here: where you can see how to abstract some win32 details about window creation and such. I have glx version (linux) working as well, and once I get time to write a few words about it I will post a blog entry and maybe a tutorial on it. But in next 2 or 3 weeks I won't have time to do it.

If you are planning to make it C++, templates and virtual functions are your friends. Interface programming is really great thing when it comes to modelling, abstractions and different implementations of common modell.

Also take a look at glut and glfw source ... or numerous others. Anything you will have to write ia already written :-).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this