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.
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.
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.
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.
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 :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With