Cross-platform 2d C ++ hardware acceleration - application?

I know a decent amount of C ++, and now I wanted to explore the creation of the game. I was wondering what the best approach would be in terms of writing a hardware accelerated game that is still cross-platform (Windows / OSX / Linux). This will be a 2d game, but intense enough so that the rendering of the CPU would probably not reduce it.

I know that OpenGL, but I can not find any tutorials on how to use it in a cross-platform manner, they are all focused on one platform.

Using SDL is also possible, but I'm afraid that the game may not work if I use it. Is this necessarily true?

Finally, I saw libraries like http://www.sfml-dev.org/ that might have simplified, should I go down this route?

Thanks again.

+6
c ++ sdl opengl hardware-acceleration
source share
6 answers

This is nonsense guys.

OpenGL IS cross-platform. No need for Qt or such. Only a few parts need to be adapted: window APIs and input APIs, which are the only functions that depend on OS-specific routines.

You have several options:

  • collapse your own. I do not recommend this, since you will not learn anything interesting (unlikely)
  • SDL It has a flag to accelerate HW, so it is like any other
  • SFML It seems good, but not mature enough IMHO. Other parts (network, ...) are shells for other libraries, so I don't see the benefits
  • GLUT. This evil.
  • GLFW. It's really cool. I have been using it for many years. It is ideal from every point of view. The only limitation is that you can only have one openGL window, but since it should be good for the game.
+7
source share

Cross platform with hardware acceleration 2d c ++ app?

SDL + OpenGL. Maybe also glee or glew if you use shaders and / or extensions. Glee is easier to use, but it doesn't seem to support OpenGL versions after 3.0. You may need SDL_image to download images.

I know that OpenGL, but I can not find any tutorials on how to use it in a cross-platform manner, they are all focused on one platform.

SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);//disable vsync if (SDL_SetVideoMode(scrWidth, scrHeight, 32, SDL_OPENGL) == 0){ fprintf(stderr, "couldn't set mode %dx%d!\n", 640, 480); SDL_Quit(); return -1; } glewInit();//if you use glew, shaders, extensions. while(gameIsRunning()){//game loop glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //OpenGL rendering here glFlush(); SDL_GL_SwapBuffers(); } SDL_Quit(); 

See the sdl documentation for more details.

Using SDL is also possible, but I'm afraid that the game may not work if I use it. Is this necessarily true?

If vsync is disabled, you can get from a few hundred to a thousand frames per second. The exact performance depends on the complexity of your equipment and the complexity of the scene. I had 300 frames per second for a simple 3D dungeon finder that used opengl "RAW" without displaying vertex buffer lists / objects. In addition, if you use a mechanism with a fixed frame rate or a timer, you will not receive more frames per second than you requested.

SDL was used to port Unreal 2004 to Linux. It was also used on the Linux port Doom 3 / Quake 4. Therefore, it is thoroughly tested and well known.

See this list for more details.

+3
source share

If you want OpenGL on a cross-platform basis, you can embed it in a Qt application using QGLWidget.

+2
source share

There is also wxWidgets , which supports OpenGl .

+1
source share

For me, the question is not whether you should use libraries or not. This is the library you should use. If you want to write a game, find libraries that will solve most of the portability problems for you. This allows you to focus on what matters most: the game itself. Others gave more library suggestions that I could give you.

I think it's a mistake to worry about performance before you even started your project. Work on performance issues, such as any other problem that you encounter during development. Build your program to isolate libraries at the same level as the rest of your logic. If necessary, it will be easier to switch the implementation. This will even allow you to experiment with various implementations.

Those:

 // separate files class LowLevelGraphicStuff { // abstract }; class LowLevelGraphicStuff_SFML : public LowLevelGraphicsStuff { // actual SFML implementation }; class LowLevelGraphicsStuff_OGL : public LowLevelGraphicsStuff { // actual OpenGL implementation }; // main // Run the game with the SFML implementation. gameLoop(new LowLevelGraphicsStuff_SFML()); // Run the game with the OpenGL implementation. gameLoop(new LowLevelGraphicsStuff_OGL()); 
+1
source share

Yes, go with SFML. SDL is inherently not hardware accelerated.

OpenGL is really portable, but it has platform-specific methods for creating an OpenGL context. SFML decides that .

0
source share

All Articles