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. C / C++ / MFC
  4. DirectDraw Surface Flipping

DirectDraw Surface Flipping

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsgame-devperformancequestion
6 Posts 3 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.
  • A Offline
    A Offline
    Alan Chambers
    wrote on last edited by
    #1

    Hi all, I got a stupid problem regards flipping a DirectDraw surface. I have initialised DirectDraw (through CreateEx), set cooperative level and set the display mode, no probs. I can load in a graphic and blit it to the back buffer and display it by calling the flip() routine. Now heres the interesting part, if I now get the so called back buffer pointer again and draw to it, when I call flip() the page is blank. Doesn't matter what I do, its blank. I got a timer going which flips the page every 1sec, what you should see is a very small, crappy animation, but instead I get one picture and one blackness screen. great. I have looked in the DD7 SDK help and the code is very similar to mine. I get the back buffer by calling this (roughly): LPDIRECTDRAWSURFACE7 GetBackBuffer() { if (NumBuffers >0) { LPDIRECTDRAWSURFACE7 Buffer; DDSCAPS2 ddscaps = {DDSC_BACKBUFFER, 0, 0, 0}; PrimarySurface->GetAttachedSurface(&ddscaps, &Buffer) return Buffer; } return NULL; } I flip the code using PrimarySurface->Flip(NULL, DDFLIP_WAIT) and have included the necessary caps (PRIMARYSURFACE, COMPLEX, FLIP, DIRECT3D, VIDEOMEMORY) and flags (BACKBUFFER etc.) in the right places (As you can see cos I can write to the back buffer and flip it, but not to the back buffer after that. Again the one after that is ok, but not the one after that etc.). Don't know what the hell it is. I have DirectX 8.1 as my runtime and 7.0 as the SDK but even still, the 7.0 sample programs work! I would be eternally greatful if someone could have a go at answering my plea for help, thanks to all those who give it a go. Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????), the other is ok - strange eh?. Might have some connection with the other problem, maybe a memory pointer is not reallocated or something, don't know but surely someone out there has the answer... Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

    J 1 Reply Last reply
    0
    • A Alan Chambers

      Hi all, I got a stupid problem regards flipping a DirectDraw surface. I have initialised DirectDraw (through CreateEx), set cooperative level and set the display mode, no probs. I can load in a graphic and blit it to the back buffer and display it by calling the flip() routine. Now heres the interesting part, if I now get the so called back buffer pointer again and draw to it, when I call flip() the page is blank. Doesn't matter what I do, its blank. I got a timer going which flips the page every 1sec, what you should see is a very small, crappy animation, but instead I get one picture and one blackness screen. great. I have looked in the DD7 SDK help and the code is very similar to mine. I get the back buffer by calling this (roughly): LPDIRECTDRAWSURFACE7 GetBackBuffer() { if (NumBuffers >0) { LPDIRECTDRAWSURFACE7 Buffer; DDSCAPS2 ddscaps = {DDSC_BACKBUFFER, 0, 0, 0}; PrimarySurface->GetAttachedSurface(&ddscaps, &Buffer) return Buffer; } return NULL; } I flip the code using PrimarySurface->Flip(NULL, DDFLIP_WAIT) and have included the necessary caps (PRIMARYSURFACE, COMPLEX, FLIP, DIRECT3D, VIDEOMEMORY) and flags (BACKBUFFER etc.) in the right places (As you can see cos I can write to the back buffer and flip it, but not to the back buffer after that. Again the one after that is ok, but not the one after that etc.). Don't know what the hell it is. I have DirectX 8.1 as my runtime and 7.0 as the SDK but even still, the 7.0 sample programs work! I would be eternally greatful if someone could have a go at answering my plea for help, thanks to all those who give it a go. Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????), the other is ok - strange eh?. Might have some connection with the other problem, maybe a memory pointer is not reallocated or something, don't know but surely someone out there has the answer... Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

      J Offline
      J Offline
      Jason Henderson
      wrote on last edited by
      #2

      From my limited understanding of how page flipping works: When you flip buffers you are actually just swapping pointers. So the back buffer becomes the primary and the primary becomes the back. If you are not re-filling the back buffer in between flippings you will get a blank page. Alan Chambers wrote: Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????) Did you convert the bitmap to 32 bit before copying it to the back buffer? Also, did you set the surface to be 32 bit? It could also be a memory thing like you said.

      Jason Henderson
      quasi-homepage
      articles
      "Like it or not, I'm right!"

      A 1 Reply Last reply
      0
      • J Jason Henderson

        From my limited understanding of how page flipping works: When you flip buffers you are actually just swapping pointers. So the back buffer becomes the primary and the primary becomes the back. If you are not re-filling the back buffer in between flippings you will get a blank page. Alan Chambers wrote: Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????) Did you convert the bitmap to 32 bit before copying it to the back buffer? Also, did you set the surface to be 32 bit? It could also be a memory thing like you said.

        Jason Henderson
        quasi-homepage
        articles
        "Like it or not, I'm right!"

        A Offline
        A Offline
        Alan Chambers
        wrote on last edited by
        #3

        Thanks for your reply Jason. You're right about the pointer swapping stuff, the back buffer SHOULD become the primary and the primary SHOULD become the back buffer. But when trying to refill the back buffer here (so between flippings) it comes out blank, doesn't do it, f***s up. :mad: stupid. As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk. I'm pretty sure these problems are interwined, and it looks like it may be a memory thing (not a lack of it, but the pointer system isn't doing its job properly). Should I be clearing the buffer before using it maybe? Any more ideas on how I could go about resolving it would be great, or even links to web sites that may contain the answer. Cheers, Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

        R 1 Reply Last reply
        0
        • A Alan Chambers

          Thanks for your reply Jason. You're right about the pointer swapping stuff, the back buffer SHOULD become the primary and the primary SHOULD become the back buffer. But when trying to refill the back buffer here (so between flippings) it comes out blank, doesn't do it, f***s up. :mad: stupid. As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk. I'm pretty sure these problems are interwined, and it looks like it may be a memory thing (not a lack of it, but the pointer system isn't doing its job properly). Should I be clearing the buffer before using it maybe? Any more ideas on how I could go about resolving it would be great, or even links to web sites that may contain the answer. Cheers, Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

          R Offline
          R Offline
          Rage
          wrote on last edited by
          #4

          Alan Chambers wrote: As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk Be sure you use True Color in the Display settings. I had the same problems, and I changed the resolution, now it works perfectly. Also make sure, if you try to use graphs, that the correct palette was loaded, and the colorkey initialised. Alan Chambers wrote: But when trying to refill the back buffer here (so between flippings) it comes out blank Once you´ve done your flip, you have to blit all the objects on the back buffer. I´ll send you a good example, maybe it will help. Anyway, if it does not work, feel free to send me your code, i´ll throw an eye on it. ~RaGE();

          A 1 Reply Last reply
          0
          • R Rage

            Alan Chambers wrote: As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk Be sure you use True Color in the Display settings. I had the same problems, and I changed the resolution, now it works perfectly. Also make sure, if you try to use graphs, that the correct palette was loaded, and the colorkey initialised. Alan Chambers wrote: But when trying to refill the back buffer here (so between flippings) it comes out blank Once you´ve done your flip, you have to blit all the objects on the back buffer. I´ll send you a good example, maybe it will help. Anyway, if it does not work, feel free to send me your code, i´ll throw an eye on it. ~RaGE();

            A Offline
            A Offline
            Alan Chambers
            wrote on last edited by
            #5

            "Send you a good example" that would be brilliant. Thanks for the advice too. I do have some added info which completes this, officially, as THE strangest problem ever. If I write the code MessageBox(GetActiveWindow(), "Whatever", "Whatever", MB_OK) before I do any page flipping, the code works and I see this beautifully changing but crappy animation. Take it out and I get picture, blank, picture, blank etc. How stupid and strange is that! I mean what has messagebox got to do with anything? Also I notice that the primary surface always gets refreshed at application startup(made blank), whilst the back buffer retains the image that was in memory last (even if the application NEVER draws to it/clear it or anything). I take it this is normal? Many Thanks anyway Rage, Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

            R 1 Reply Last reply
            0
            • A Alan Chambers

              "Send you a good example" that would be brilliant. Thanks for the advice too. I do have some added info which completes this, officially, as THE strangest problem ever. If I write the code MessageBox(GetActiveWindow(), "Whatever", "Whatever", MB_OK) before I do any page flipping, the code works and I see this beautifully changing but crappy animation. Take it out and I get picture, blank, picture, blank etc. How stupid and strange is that! I mean what has messagebox got to do with anything? Also I notice that the primary surface always gets refreshed at application startup(made blank), whilst the back buffer retains the image that was in memory last (even if the application NEVER draws to it/clear it or anything). I take it this is normal? Many Thanks anyway Rage, Alan. "When I left you I was but the learner, now I am the master" - Darth Vader

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #6

              Alan Chambers wrote: I mean what has messagebox got to do with anything Well, if you are running DDraw windowed, you have to define clipping regions. Anyway, mixing GDI (i.e. messageBoxes) with DDraw is not trivial, so I suppose it is not anormal that sometimes strange things come out :-D ~RaGE();

              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