Hot answers tagged

41

It's not just about speed of execution, but also about simplicity. Although the software rendering used in this example would be a lot slower than using hardware acceleration (i.e. a GPU), drawing a few bitmaps on screen is such a trivial task that you would not notice the performance drop. However, low-level activity like triangle rasterisation, depth sort ...


40

My name is Kevin, and I'm a programmer/designer at Klei. I wrote a bunch of the animation stuff that we used in the Shank series, Mark of the Ninja, and Don't Starve. Our animators work in Flash. We have a concept of a character 'build' which is a set of body-part symbols with multiple views. Depending upon the fidelity of the given game, there are more or ...


25

My question is: why even bother using something like open gl, sfml, sdl when all you have to do is simply allocate some buffer, pass a bitmap and draw it to the screen? Short: Because its fast (OpenGL, DirectX). Long: You may think you can do this all yourself. Draw pixels to a screen. You might write a small library to draw shapes, like quads or ...


24

While you can implement this using SDL_WarpCursor(), I've run into problems with that method on some platforms. I've had real problems with some platforms not reliably performing the WarpCursor() action, particularly when I've been calling it every frame. Also, remember that on many platforms, the cursor is handled at a higher frequency than your app. ...


22

Split this into several layers. At the lowest layer you have raw input events from the OS. SDL keyboard input, mouse input, joystick input, etc. You might have several platforms (SDL is a least-common-denominator lacking several input forms, for instance, which you might later care about). You can abstract these with a very low-level custom event type, ...


19

This is a very broad question, but generally particle system features can be broken down into a few categories. Here are some general ideas for the sorts of things you might want to have. Emission features define how, when, and where particles are emitted. Continuously generate particles at a fixed rate, or generate a cluster all at once when triggered by ...


17

SDL is a library. OpenGL is kinda library. DirectX is a collection of libraries. None of these are engines. Engines are built with some or all of these though. Understand that you are looking at this in a way which won't allow you to fully understand the scope of these technologies. The term library is thrown around a lot, and it does little here to help ...


15

If your frame time is unpredictable (whether or not this is your fault; the OS may be using resources occasionally, etc), capping to a predictable frame rate that is somewhat lower than your achievable framerate will do a lot for predictable latency, which can make the game feel a lot better. Changing how long between when you process input and render ...


14

When reading the code-example provided by SDL on the SDL_GetPerformanceFrequency I could easily find out how you could calculate a deltatime using these functions. It should basically come down to this for you: Uint64 NOW = SDL_GetPerformanceCounter(); Uint64 LAST = 0; double deltaTime = 0; while (somebool) { LAST = NOW; NOW = ...


12

Since asked by the thread starter, I elaborate on event managers. I think this is a good way to handle input in a game. An event manager is a global class which allows to both register callback functions to keys and to fire off those callbacks. The event manager stores registered functions in a private list grouped by their key. Each time a key gets fired, ...


12

You will end up using a lot less CPU (multi taskers will thank you) and people on mobile devices will appreciate this, too.


11

An SDL_KEYDOWN event is only sent when the key is first pressed. You will receive an SDL_KEYUP event when it's released. You'll want to handle moving in code which gets called every frame, not in response to an event. Inside Avatar::handle_input, you'll instead want to set variables to tell you whether each key is up or down, and update those variables as ...


11

You should use SDL_Image API, it has one simple function that loads everything: SDL_Surface *IMG_Load(const char *file); More precisely, it loads ICO(Icon)/CUR(Cursor)/BMP, PNM (PPM/PGM/PBM), XPM, LBM(IFF ILBM), PCX, GIF, JPEG, PNG, TGA, TIFF, and XV thumbnail formats. It also has individual format functions such as IMG_isPNG and IMG_LoadPNG_RW. This lib ...


11

What he does is called software rendering, what OpenGL does is called GPU rendering What's the difference between them? Speed and memory. Rasterization (filling out triangles on screen) takes some time. If you do it on the CPU, you essentially take that time away from game logic, especially if it's not optimized well. And doesn't matter, how small the ...


10

The solution is SDL_SetRelativeMouseMode. How can I have missed that.


10

You should never, ever, ever, ever, ever use Sleep to control framerate. This has been gone over before and I'll refer you to the other question for discussion of the reasons why. One thing not mentioned there is that at the typical modern refresh rate of 60Hz, and with the typical 1 millisecond granularity of Sleep calls, it's actually impossible to Sleep ...


10

SDL2 doesn't need any functionality to be added for either of those items. Texture batching You yourself can sort the sprites by texture used. The SDL backends can already do draw call batching if they wish to (nothing requires that the Copy command be executed immediately; the only requirement is that it be executed by the time any side effects are ...


9

You could use the TMX map format used by the Tiled editor (as well as several other map editors). Even if you don't use Tiled yourself, the TMX format supports all the functionality you mentioned and it has several existing loaders/parsers for a variety of languages. It's also very easy to understand the format and extend it for your own game.


9

On tile based GPUs (commonly seen in mobile hardware) it is beneficial to clear the renderer, as it allows the GPU to dispose of the existing cached frame data. Here's a quote from OpenGL Insights, dealing with the benefits of clearing the framebuffer on a tile based renderer: "On a tile-based architecture, avoiding clears can be disasterous for ...


9

Yes, it's possible. No its not a dumb idea. In fact many of the older racing games did something similar. Super Mario Kart is one example. The rendering uses 2d sprites in 3d space instead of polygons, but the physics engine is all 2d.


8

A singleton for your main engine class is perfectly normal. It's even quite acceptable to have one singleton for each of your game's major systems, like graphics and input. I personally prefer a single Engine singleton with all systems as members of that object, but really there's very little difference. A singleton can just be a static global object, ...


8

Do you think it would be a good idea to have each part of the screen (game session) handled by different thread? When it comes to rendering: No! OpenGL and multithreading don't mix well. It's best practice to keep all OpenGL operations to one single thread.


8

"What should I be concerned about in terms of rendering when I do this?" - not much. A co-ordinate system is just a convention, not a hard-and-fast rule, and this is a perfectly legal and valid thing to do. Just make sure that you are consistent in your own usage and everything will work fine.


8

The SDL documentation says that SDL_BlitSurface saves the final rectangle to dstrect after blitting. Reseting the where variable fixes the problem.


8

Your clock code comes from #include <ctime> and OutputDebugString comes from #include <windows.h>. OutputDebugString will not print anything if there is no debugger available. If you want platform independent code you might want to take a look at boost timers. If you don't like boost and need nano precision on multiple platforms, the keyword ...


8

Don't render text directly with SDL_TTF. It's not efficient, at all. Use SDL_TTF to generate a glyph atlas, or use a tool like AngelCode BMFont. You can get glyph metrics (Width, Height, x advance, etc.) using TTF_LineSkip to find the vertical distance, and TTF_GlyphMetrics. At this point, you can render text yourself. By putting the font glyphs into an ...


8

There is one more possibility, if performance doesn't matter much, and you are willing to use the newer version SDL2_TTF(available from the official hg.libsdl.org mercurial repository). SDL2_TTF has new functions including TTF_RenderText_Blended_Wrapped, where you can specify a wraplength parameter, which specifies in pixels the maximal width( the surface ...


8

In the linker options add -static-libgcc or -static-libstdc++ ( -static-libgcc worked for me ) Alternatively add the libstdc++6.dll from the compiler bin folder to the folder where your exe resides.( Assuming we are talking about MingW/Gcc it's in mingw/bin/)


8

I know how you feel, SDL2 is somewhat different from the earlier one, to make it easier, I'll explain how SDL_Renderer, SDL_Window, and SDL_Texture works. //CREATE WINDOW SDL_Window *window = SDL_CreateWindow("Title", 100, 100, 400, 600,SDL_WINDOW_SHOWN); /*You have created a variable named window which is in the type of SDL_Window, SDL_Create Window ...


8

What you may wish to do in this case is check the timer when you started printing the text on the screen and decide on an amount of time that it will take to print each letter in the paragraph. Then each frame check the time and print this portion of the text: int charsToPrint = (time - started) / amount; if (amount < originalText.length()){ ...


Only top voted, non community-wiki answers of a minimum length are eligible