Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross platform hardware accelerated 2d C++ app? [closed]

I know a decent amount of C++, and now I wanted to explore making a game. I was wondering what the best approach would be in terms of writing a hardware accelerated game that's still cross-platform (Windows/OSX/Linux). It's going to be a 2d game, but intensive enough that a CPU renderer probably wouldn't cut it.

I know there's OpenGL, but I can't seem to find any tutorials on how to use it in a cross platform manner, they all focus on one platform.

Using SDL is also a possibility, but I'm afraid the game may not perform as well if I use it. Is this necessarily true?

Lastly, I've seen libraries like http://www.sfml-dev.org/ that supposedly make it easier, should I go down that route?

Thanks again.

like image 910
HFLW Avatar asked Aug 03 '10 02:08

HFLW


People also ask

How do I disable hardware acceleration on Android?

If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling setLayerType(View. LAYER_TYPE_SOFTWARE, null) . This way, you can still take advantage of hardware acceleration everywhere else.

How do I enable hardware acceleration?

If you're looking to enable—or re-enable—hardware acceleration, head back to chrome://settings/system and toggle “Use hardware acceleration when available” setting to the “On” position. Then, click “Relaunch” to apply the change.

Is OpenGL hardware accelerated?

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.


2 Answers

That's nonsense guys

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

You have several possibilities :

  • roll your own. I don't recommend this, since you won't learn anything interesting (hardly)
  • SDL. It has a flag to be HW accelerated, so it's as good as any other
  • SFML. This seems good but not mature enough IMHO. The other parts (networking, ...) are wrappers for other libraries so I don't really see the advantage
  • GLUT. This one is evil.
  • GLFW. This one is great, really. I've been using it for years now. It's perfect from every point of view. The only limitation is that you can only have one openGL window, but since it's for a game it should be ok.
like image 55
Calvin1602 Avatar answered Sep 30 '22 11:09

Calvin1602


Cross platform hardware accelerated 2d C++ app?

SDL + OpenGL. Maybe also glee or glew if you use shaders and/or extensions. Glee is easier to use, but it looks like it doesn't support OpenGL versions after 3.0. Also you might need SDL_image for loading images.

I know there's OpenGL, but I can't seem to find any tutorials on how to use it in a cross platform manner, they all focus 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 sdl documentation for more info.

Using SDL is also a possibility, but I'm afraid the game may not perform as well if I use it. Is this necessarily true?

With vsync disabled, you can get from few hundreds to thousand frames per second. Exact performance depends on your hardware and scene complexity - I had 300 fps reports for simple 3D dungeon crawler that used "RAW" opengl without display lists/vertex buffer objects. Also, if you use fixed framerate or timer-driven engine, you won't get more frames per second than you asked for.

SDL was used for porting Unreal 2004 to Linux. It also was used in Doom 3/Quake 4 linux port. So it is thoroughly tested and well known.

See this list for more info.

like image 34
SigTerm Avatar answered Sep 30 '22 11:09

SigTerm