Changing to OpenGL

Started by
5 comments, last by trippytarka 13 years, 11 months ago
Hi, I've been doing some game programming using XNA for the past year, and this past semester I took a graphics class where we used OGL to make some elementary 3D graphics. Well, that kind of inspired me to try writing a game in OpenGL instead, especially because of the cross-platform capabilities (I'm tired of my mac friends not being able to play my games!). I'm just starting out with it, trying to write a 2D platformer, and I'm kinda getting stuck in some technicalities, such as trying to disable window resizing and getting Ctrl presses and such. It seems some of the more elegant solutions (from the user standpoint) involve writing it as a windows program. Right now, I just have it set up as a win32 console application. If I make it into a windows program, will I lose the cross-platform capabilities? Is it better to do that and port it to mac later? I'm really quite lost as far as cross-platform stuff goes.
Advertisement
A common solution to writing cross-platform (e.g. OS X, Windows, Linux) OpenGL applications is to use a cross-platform windowing library such as SDL, SFML, GLFW, etc. (This will allow you to handle the things you mentioned - window management, input, etc. - in a portable way.)
Cool, thanks a lot! So there are a lot of choices there. Which do you recommend?
Quote:Which do you recommend?
I don't have much experience with GLFW. As for SDL and SFML, I'd just use whichever seems most appealing to you. (SDL has a C-based API, and version 1.2.x, having been around for a while, is pretty stable. SFML is newer and has an object-oriented C++ API. SFML is ostensibly cross-platform, but I'm not sure what the status of the OS X version of SFML is currently.)
It is relatively easy to write a thin "windows" layer which does things like recv windows messages and translate them into "keypressed(int)" calls into a class which is the core part of your game.

It can also setup GL using WGL and then call "render()" and all your game window has to do is draw in GL then.

Later on, when you come to need cross-platform, you can write another thin layer for X11 or for Mac.

These layers can then provide other OS specific services (eg; creating a TCP socket or opening an image file off disk).

The OpenGL superbible contains much of the code you'd need to get this set up. There's a chapter for each of the big three OSes.

The main risk of this is that by the time you've finished, you'll have re-written SDL... :-)





Another option would be to use Qt, which will happily create you windows and get keypresses and so on, but contains tons of other cross-platform support.

Okay, so I'm looking at SDL and it looks decent enough. The only thing is, if it can handle the 2D graphics, and I'm writing a 2D rendered game, is there really any reason to keep OpenGL involved in the process?
SDL can handle the 2D rendering for you, but doing it yourself in OpenGL would give you access to the hardware acceleration. SFML uses OpenGL for all it's 2D stuff IIRC, so you get HW acceleration out of the box.

This topic is closed to new replies.

Advertisement