[問題] SDL2 RenderPresent 的敘述看不太懂

作者: ResolaQQ (ResolaQQ)   2016-02-19 07:39:34
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
SDL2
問題(Question):
SDL_RenderPresent 的敘述如下
SDL's rendering functions operate on a backbuffer; that is, calling a rendering
function such as SDL_RenderDrawLine() does not directly put a line on the
screen, but rather updates the backbuffer. As such, you compose your entire
scene and present the composed backbuffer to the screen as a complete picture.
Therefore, when using SDL's rendering API, one does all drawing intended for
the frame, and then calls this function once per frame to present the final
drawing to the user.
The backbuffer should be considered invalidated after each present; do not
assume that previous contents will exist between frames. You are strongly
encouraged to call SDL_RenderClear() to initialize the backbuffer before
starting each new frame's drawing, even if you plan to overwrite every pixel.
我不太理解文中的 backbuffer 是指什麼,像底下這應該是錯誤的
SDL_RenderClear(renderer) // 清除繪圖內容
SDL_RenderDrawLine(renderer, 0, 0, 100, 100) // 畫條斜線從 (0,0) 到 (100,100)
SDL_RenderPresent(renderer) // 顯示到螢幕上
SDL_RenderPresent(renderer) // 錯誤,顯示到螢幕上後,繪圖內容應該被假設為無效
但底下這個有沒有問題呢?我就不確定了
SDL_SetRenderTarget(renderer, texture) // 把繪圖目標設定到 texture 上
SDL_RenderDrawLine(renderer, 0, 0, 100, 100) // 畫條斜線從 (0,0) 到 (100,100)
SDL_SetRenderTarget(renderer, NULL) // 把繪圖目標設定回預設值
SDL_RenderCopy(renderer, texture, NULL, NULL) // 把 texture 的內容拷貝進去
SDL_RenderPresent(renderer) // 顯示到螢幕上
SDL_RenderCopy(renderer, texture, NULL, NULL) // 這時候,texture 是有效的嗎?
SDL_RenderPresent(renderer) // 是否可以這樣把之前繪製過的圖形再次顯示出來?
texture 似乎是一小塊顯示卡的記憶體
不知道敘述裡的 backbuffer 有沒有包含 texture?
還是僅止於預設的繪圖目標?
作者: azureblaze (AzureBlaze)   2016-02-19 07:54:00
預設目標而已
作者: ResolaQQ (ResolaQQ)   2016-02-19 13:54:00
感謝,這樣就沒問題了。一直有點怕怕的,不敢繼續寫下去

Links booklink

Contact Us: admin [ a t ] ucptt.com