Advertisement

my own mouse cursor

Started by January 18, 2000 05:01 AM
6 comments, last by ferceg 25 years, 1 month ago
Hello ! I''d like to apologize for my bad English first (I''m from Hungary). I''m totally new to DX, so don''t laugh at me if I ask stupid questions... So.. I tried to write my very first DX program: I have a fixed background, and a transparent mouse cursor moves on it. I created the primary surface with 1 backbuffer, and I also have an offscreen buffer to store the background picture in it. (This is larger than the primary srf, because I store the mouse cursor with colorkey in this surface, too). I didn''t manage to avoid having to blt the full bgpic to the backbuffer then blt the cursor using colorkey to the current mouse position (and then I flip, of course). If I tried to do a restore-bg-save-bg-put-cursor thing, the entire screen was flashing as I moved the mouse. Could anyone explain me, how the flipping exactly works ? I started to experiment: I did: -init DDraw -load a bmp to an offscr. srf. -blt to primary -blt to back -and just flip on mousemove the result: flashing screen. (one of them contains the correct bgpic, the other''s some horrible purple colored...) why ?????????? thanks, Hajdu Ferenc
i''m also new in DX, (anyone) correct me if i''m wrong.

the primary-surface is what the screen is showing.
the back-surface is what working behind the scene.
i seldom see any blt occur in primary-surf (izzit?), most are done in back-surf.
so, after all blt are done on the back-surf, do a flip.
a flip will switches the primary&back surfaces, making your back-surf becoming primary & vice versa (again, izzit?)... resulting the screen showing what u want to show.
this operation is called double-buffering. normally used in game & is one of the known methods to reduce sprites (not screen) flickering.

my suggestion is that try to blit everything to the back surface, and then do a flip. Something like:
- init DD
- load bitmap to offscreen-surf
- blit background to back-surf
- blit mouse cursor to back-surf
- flip

BTW, what u blt to the primary-srf?
"after many years of singularity, i'm still searching on the event horizon"
Advertisement
Well DerekSaw, you seem to be pretty much on track, but you left out when to flip. A monitor draws an image from left to right and top to down. When the beam reaches the bottom right, it has to move back up to the top left. This is called the vertical retrace. When you are performing page flipping, flip the pages during the vertical retrace so you don't see it while drawing (this may be your problem ferceg). Here's some code in DX7 that will wait until the retrace and flip.

// Flip Our Surfaces
while (FAILED(g_lpDDS7_Front->Flip(NULL, DDFLIP_WAIT)));

Also ferceg, you may try moving your mouse cursor to irs own surface. That should help simplify your code.

Edited by - I-Shaolin on 1/18/00 8:08:18 AM
Thx for the answers.
I understand that I shouldn''t blt to the primary surface.
But if I blt the bgpic to the backbuffer and then the mouse cursor onto it and then I flip, I will have an empty backbuffer and I have to blt the whole bgpic again.
And this is what I''d like to avoid.
(just restore-save-putmousecursor on mousemove)

Another problem:

why doesn''t this code work ?

ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth=100;
ddsd.dwHeight=100;

ddrval=lpDD->CreateSurface(&ddsd,&lpDDSBG,NULL);

I always get a DDERR_INVALIDPARAMS...

thx again,

ferceg
You forgot
ddsd.dwSize = sizeof (ddsd);  


You could create another surface for backuping the stuff behind your mouse cursor. I've never tested it, but I think it will work.

Cya

Edited by - Melo on 1/21/00 6:22:13 AM
Yes, that was it... thanx.

Another question:
I load a truecolor bmp with DDLoadBitmap (ddutil.cpp) (my primary surface is in 16 bit)
Is the offscreen surface in 32 bit and will the blt do the conversion ? (Or is it already 16-bit ?)

ferceg
Advertisement
all your offscreen/video memory surfaces will be in the same colordepth as your primary surface. so yes, its already in 16-bit mode (DDLoadBitmap will take care of the conversion between 32 and 16-bits).

Edited by - Staffan on 1/22/00 6:22:51 PM
But if you create surfaces with several pixel formats, the Blt/BltFast functions do not convert ''em.

This topic is closed to new replies.

Advertisement