News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Using palettes in DirectDraw 7

Started by satpro, July 01, 2012, 10:39:27 AM

Previous topic - Next topic

satpro

Hi all,
I'm having difficulty changing the palette in a program I'm writing in DD7.  My dev machine is Win7.  I can CreatePalette and SetPalette without errors, using a pre-filled structure containing 256 colors, mostly web-safe and gray-scale colors, but it seems like the system palette is still there when I do screen fills.  In other words, the colors I get do not match mine in the palette structure.  They're not even close (reverse byte order, etc).  Color 0 is black, 1 is red, 255 is white and so on, no matter what I set them to, even though I used the ALLOW_256 flag.  Does Win7 allow the palette to be changed?  When I call CreateSurface and add the DDSCAPS_PALETTE flag I get an error--take it out, everything's fine.  Do I need to set a PIXELFORMAT in addition to to the 8 bpp in SetDisplayMode?
Any help or insight would be greatly appreciated.  I feel like I'm missing something here.
Thanks,
Bert

dedndave

some code would help   :P

you may want to use CreateDIBSection or something to create a DIB to select into a DC

satpro

The project is sort of an updated c64 with a 65816 and 32mb ram (16mb code, 16mb data).  The cpu is already written and works fine.  Even has mult & div instructions, using the WDM opcode.  So it's not exactly a 65816.
The program asks the user if they want a 16:9 or 4:3 screen.  It correctly picks the proper resolution and defaults to 1024x768 (if the graphics card will do it-otherwise just exits) in order to handle a 800x600 screen with border.  I transfer the 800x600 screen, along with 16 sprites to the backbuffer & flip 50x/sec.  No problems.  Originally I used 32-bit color but want to make it a little more authentic and use 256 colors.  I understand I could still use a 256-color software palette using on the fly translation, or even 16-bit color, and that may be where this is headed if I can't work with the real palette.
The code below is just the relevant parts creating the primary surface, the palette, and attaching the palette.


(It's in GoAsm--msgbox error stuff removed)

;   CREATE PRIMARY SURFACE

;PREPARE TO CREATE PRIMARY SURFACE
;CLEAR SURFACE DESCRIPTION STRUCTURE

x3:
mov ecx, SIZEOF structSURFDESCPri     ;index
mov eax, ADDR structSURFDESCPri       ;DEST
mov dl, 0                           ;POKE value

x3.1:
mov [eax], dl           ;POKE (DEST)
inc eax                 ;inc DEST
dec ecx                 ;dec index
jnz <x3.1               ;until index = 0

;FILL VALID PARAMS
;CREATE A PRIMARY SURFACE WITH A BACK BUFFER

mov D[structSURFDESCPri.dwSize], SIZEOF structSURFDESCPri

mov D[structSURFDESCPri.dwFlags], DDSD_CAPS | DDSD_BACKBUFFERCOUNT

mov D[structSURFDESCPri.ddsCaps.dwCaps], \
DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX                        ;| DDSCAPS_PALETTE (doesn't work)

mov D[structSURFDESCPri.dwBackBufferCount], 1   


CoInvoke(ptrIDirectDraw, IDirectDraw7.CreateSurface, \
        ADDR structSURFDESCPri, ADDR ptrISurfacePri, NULL)

cmp eax, DD_OK
je >x4                      ;surface created successfully
                            ;could not create, so display error message and quit


;CREATE THE PALETTE

x4:
CoInvoke(ptrIDirectDraw, IDirectDraw7.CreatePalette, \
    DDPCAPS_8BIT | DDPCAPS_ALLOW256, \
        ADDR ecPALETTE, ADDR ptrIPalette, NULL)
cmp eax, DD_OK
je >x4.1

;ATTACH THE PALETTE TO THE PRIMARY SURFACE

x4.1:
CoInvoke(ptrISurfacePri, IDirectDrawSurface7.SetPalette, [ptrIPalette])
cmp eax, DD_OK
je >>x5




This all works and I get the right thing up on the screen--except for the color, which is always the same, regardless of what is in the palette table.  I'm wondering if I have the right flags set in these particular calls.

sinsi

This is from a gamer's perspective, but some older DX7 games that use a 256-colour palette need a compatability flag in the registry to get correct colours.
Playing the old Age of Empires II gave me weird colours (purple sea, yellow grass etc.) but using a program called directdrawfix fixed the problem.
The steps the fix does are:
- run the game until it creates the main window
- kill the game
- get the last run DirecrDraw program ID from the registry
- write ID and flags to HKLM\Software\Microsoft\DirectDraw\Compatibility\game.exe

dedndave

sorry, Bert
ignore my previous post - lol
i missed an important part of your first post...
"DD7"

i have no experience with DirectDraw
perhaps Marinus, Farabi, Edgar, Yves, or one of the other guys can help

satpro

Thanks dave, sinsi.  I remember reading somewhere about those fixes.  I have this weird feeling the 256-color idea is doomed.  Oh, well.  This thing's cpu is 16-bit, so 32-bit color makes no sense and would be hard on a user to program it.  I'll probably just go with 16-bit color.  Now I have to read up on the CAPS bit masks...  Thanks again.

satpro

Well, the output (16:9 or 4:3) is up to the user, the res is hard-coded 1280x720x32 or 1024x768x32, and the video itself comes from data banks 248-255 and is a soft-palette 800x600x8 (the original 16 C= colors) for now.  Probably will add a few more colors to the lookup table.  One video byte is translated on-the-fly into a 32-bit color from the table.  It's a 40x25/80x50 display with 10x12 or 20x24 px characters.  So, problem solved.