c++ - hardware buffering using SDL, question about how it works -


I'm deciding to make my first game, it's going to be simple, but I want to use c ++ I have selected SDL and I have my learning. So my question is how "buffers" are handled when writing the code. I will post your related code below.

Okay, so basically the way I think is that SDL takes care of that buffer is actually being pulled on the screen. When I write buffer, it is always the backbuffer I am writing, or buffer is not currently being dragged on the screen. Therefore, when I call the SDL_flip (screen), it "smokes" the surface of my screen on the backbuffer, then the buffer is dragging the pointer which the backfather, which I was working on, and the old The buffer that was showing now becomes the backbuffer. At this point if I call the SDL_FillRect (logic) then it will be back on the buffer?

I am going to post the full "heart beating" of my learning game because it can help clarify my question:

  // when The user has not left (except == incorrect) {// If there is an event to handle (SDL_PollEvent (and event)) / If any key was pressed (event.type == SDL_KEYDOWN) {/ / Proper message surface switch (event.key.keysym.sym) {Case Set SDLK_UP: message = upMessage; break; Case SDLK_DOWN: message = downMessage; break; Case SDLK_LEFT: Message = Left Message; break; Case SDLK_RIGHT: Message = Correct Message; break; }} And if (event.type == SDL_QUIT) // if the user clicks a little X in the upper right corner {Quit = true; }} // If the message needs to be displayed (message! = Null) {// clear back buffer SDL_FillRect (SDL_GetVideoSurface (), NULL, 0); // Behind back buffer, backgrawer driver. Apply_surface (0, 0, background, screen); // Back to Buffer "Message" Draw Apply_surface ((SCREEN_WIDTH - Message- & gt; W) / 2, (SCREEN_HEIGHT - Message- & gt; H) / 2, Message, Screen); // tap surface indicator message = faucet; } // Swap existing and back buffer if (SDL_flip (screen) == -1) {return1; }}  

It depends on your system (i.e. x11, linux frame buffer , Windows), and backend SDL uses to interact with it. Besides that which goes to the SDL_SetVideoMode flag you are basically the software surfaces that sit in the area of ​​memory in your program, and the surface of the hardware which is in the memory of the graphical card, the description that I describe seems to be a double buffer, If you pass SDL_HWSURFEES, then it is enabled. SDL_DOUBLEBUF for SDL Just remember that this is not supported on all platforms and configurations, and you can find something different instead.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -