Compiling and running under Windows and Linux

Started by
12 comments, last by okonomiyaki 20 years, 3 months ago
I''m making a cross-platform application that must both compile and run under windows and linux. In the Linux version, of course I can''t include "windows.h". How do you setup OpenGL on Linux? I thought this was a trivial problem but I went to do it and realized I wasn''t sure how. Thanks a lot for the help!
Advertisement
I'm working on a project mainly in linux, although it's pretty platform independent. I use SDL for the input handling and window creation because it allows my code to be much more platform independent (the SDL library does the platform-specific stuff). Check it out, at least.

To deal with the windows.h issue, when I need the windows version to include it, I just do something like:
#ifdef WIN_32  // I think WIN_32 is right, not WIN32, not sure...#include <windows.h>#endif//Rest of includes here   

Not really pretty pretty, but it works. With SDL, that's almost the only situation I need to do and #ifdef's. I do some windows specific stuff to load extensions, since my linux library is opengl 1.4.

[edit]re-Fixed link, sorry again.[/edit]

[edited by - Mr Grinch on January 12, 2004 3:32:23 PM]

[edited by - Mr Grinch on January 13, 2004 2:50:31 AM]
You will probably want to look into using SDL, or Simple DirectMedia Layer. It provides a simple means for initializing an OpenGL window that is cross-platform and easy to use. Or, you could use GLUT, though I personally do not like it.

Creating an OpenGL window for Linux (or, more specifically, XFree86) in the general (non-SDL case) involves the use of the GLX extension to OpenGL, as well as some XLib stuff that gets pretty ugly. You can check out GLX documentation for examples on using GLX/XLib to open a window, but using SDL is simpler and allows you to create an application that can be built for Linux and Windows both (as well as a number of other platforms).

Josh
vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
Use SDL and the supplied SDL_opengl.h header, it takes care of that for you. If you''re not using SDL, do the macro check.

quote:Original post by Mr Grinch
#ifdef WIN_32  // I think WIN_32 is right, not WIN32, not sure...#include <windows.h>#endif//Rest of includes here  



No, the VC++ 2003 macro is _WIN32.



Ah, cool, that''s exactly what I was looking for. Thanks! I knew that I was going to have to get into the XLib stuff, just wasn''t sure where to begin..
There always GLUT as well... but you may as well use SDL... the GLUT leaves a lot to be desired with input, etc., and doesn''t handle sound. It''s incredibly simple though.
Holy cow, is SDL really something that I can use without problems? I just got the libraries and called an init function or two and there pops up my screen... I guess I''m used to the hundred lines of code that is required to set up a screen and initialize in C++... is it feasible to use SDL to setup my opengl screen and use it with input too? I won''t find any problems with it down the road will I?
Shouldn''t have too many problems. SDL was begun specifically for the purpose of providing a framework for porting games to Linux by the Loki Games crew, so they designed with games in mind. SDL provides input and event handling, joystick handling, graphics, etc... You can even get a basic sound system up and running with SDL_mixer, though I would personally recommend going with OpenAL for that particular task, for greater power.

I use SDL in all of my projects, and I haven''t run into any problems yet.


Josh
vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
I haven''t found any problems so far, and I''m using it to do input, window management, and even using SDL_image for image loading. I really like it. I''m even planning on using SDL libraries for sound and networking (eventually). I''d still consider my project to be pretty young, but it has been used in some commercial linux ports (the SDL webpage uses Civilization: Call To Power as an example).

This topic is closed to new replies.

Advertisement