Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. openGL SwapBuffers

openGL SwapBuffers

Scheduled Pinned Locked Moved Graphics
graphicsquestioncomgame-devannouncement
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nishad S
    wrote on last edited by
    #1

    I would like to check the following idea having problems or not... :) 1. Initiates openGL with double buffer enabled 2. Render something to back buffer and call SwapBuffers. 3. Render the same again. (To fill the other buffer) 4. Called SwapBuffers only for handling WM_PAINT. That is, no repeated rendering since there is no change in what to draw. So the point is that, rendering is done when needed to modify the drawing. But whenever repainting is needed the buffer is just swapped to retain the painting. I checked the same and its working fine. But rendering need to be done two times to update both front and back buffers. Is this way OK? If so how can I avoid the rendering two times?

    - NS - [ODBaseBtn]

    D 1 Reply Last reply
    0
    • N Nishad S

      I would like to check the following idea having problems or not... :) 1. Initiates openGL with double buffer enabled 2. Render something to back buffer and call SwapBuffers. 3. Render the same again. (To fill the other buffer) 4. Called SwapBuffers only for handling WM_PAINT. That is, no repeated rendering since there is no change in what to draw. So the point is that, rendering is done when needed to modify the drawing. But whenever repainting is needed the buffer is just swapped to retain the painting. I checked the same and its working fine. But rendering need to be done two times to update both front and back buffers. Is this way OK? If so how can I avoid the rendering two times?

      - NS - [ODBaseBtn]

      D Offline
      D Offline
      Dan 0
      wrote on last edited by
      #2

      No need to render twice, render once and copy.

      // Back buffer to front.
      glReadBuffer(GL_BACK);
      glDrawBuffer(GL_FRONT);
      glCopyPixels(GL_COLOR);

      // Front buffer to back.
      glReadBuffer(GL_FRONT);
      glDrawBuffer(GL_BACK);
      glCopyPixels(GL_COLOR);

      N 1 Reply Last reply
      0
      • D Dan 0

        No need to render twice, render once and copy.

        // Back buffer to front.
        glReadBuffer(GL_BACK);
        glDrawBuffer(GL_FRONT);
        glCopyPixels(GL_COLOR);

        // Front buffer to back.
        glReadBuffer(GL_FRONT);
        glDrawBuffer(GL_BACK);
        glCopyPixels(GL_COLOR);

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        Thank you very much... I am just entering to the world of openGL :) Could you please tell me that the idea of doing SwapBuffer only, in response to WM_PAINT, is good? Is there any problem in that? Or is there any better solution? Thank you.

        - NS - [ODBaseBtn]

        D 1 Reply Last reply
        0
        • N Nishad S

          Thank you very much... I am just entering to the world of openGL :) Could you please tell me that the idea of doing SwapBuffer only, in response to WM_PAINT, is good? Is there any problem in that? Or is there any better solution? Thank you.

          - NS - [ODBaseBtn]

          D Offline
          D Offline
          Dan 0
          wrote on last edited by
          #4

          Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:

          bool quit = false;
          while(!quit) {
              PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE);
              if (msg.message == WM\_QUIT) {
                  quit = true;
          
              } else {
                  DoRendering();
                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
              }
          }
          

          Or you can simply swap buffers when u only render, not on every paint.

          N 2 Replies Last reply
          0
          • D Dan 0

            Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:

            bool quit = false;
            while(!quit) {
                PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE);
                if (msg.message == WM\_QUIT) {
                    quit = true;
            
                } else {
                    DoRendering();
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
            

            Or you can simply swap buffers when u only render, not on every paint.

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            Thank you for the reply. I got it. Actually I don't need to update the rendering continuously. That's why I decided to move the SwapBuffers to wm_paint. Drawing need to be updated only at some events say mouse click, etc.

            - ns -

            1 Reply Last reply
            0
            • D Dan 0

              Matters on what you are trying to do, you don't need to use wm_paint at all, you can update the render whenever you feel you need to. If you need to continually update the window, u can use a pump, ie:

              bool quit = false;
              while(!quit) {
                  PeekMessage(&msg, hwnd, NULL, NULL, PM\_REMOVE);
                  if (msg.message == WM\_QUIT) {
                      quit = true;
              
                  } else {
                      DoRendering();
                      TranslateMessage(&msg);
                      DispatchMessage(&msg);
                  }
              }
              

              Or you can simply swap buffers when u only render, not on every paint.

              N Offline
              N Offline
              Nishad S
              wrote on last edited by
              #6

              Now got another problem... if we lock windows and then unlock the drawing in the buffers are lost... What should be done to handle windows lock/unlock conditions? Thank you.

              - ns -

              D 1 Reply Last reply
              0
              • N Nishad S

                Now got another problem... if we lock windows and then unlock the drawing in the buffers are lost... What should be done to handle windows lock/unlock conditions? Thank you.

                - ns -

                D Offline
                D Offline
                Dan 0
                wrote on last edited by
                #7

                I get the feeling that the best approach for you is to use a FBO and do offscreen rendering. Google "opengl render to texture", you can bind a frame buffer at the start of your rendering, then blit it as needed.

                N 1 Reply Last reply
                0
                • D Dan 0

                  I get the feeling that the best approach for you is to use a FBO and do offscreen rendering. Google "opengl render to texture", you can bind a frame buffer at the start of your rendering, then blit it as needed.

                  N Offline
                  N Offline
                  Nishad S
                  wrote on last edited by
                  #8

                  Thank you very much. I shall try for that. :)

                  - ns -

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups