Stratos: Punto de Encuentro de Desarrolladores

¡Bienvenido a Stratos!

Acceder

Foros





Inicializando D3d Con 16 Bits...

Iniciado por [HiDDeN], 30 de Enero de 2004, 12:51:30 AM

« anterior - próximo »

[HiDDeN]

 Hola a todos!

Estoy empezando a hacerme una sencilla librería, y he empezado por la inicialización de D3D.
Cuando inicializo el BackBuffer en 32 bits, no hay problema, pero si lo hago en 16 bits (cualquiera de las modalidades), no inicializa bien el device, y al final, al hacer el Release, me peta dando un error de violación de acceso (porque no se llegó a inicializar).

El error que me dá es D3DERR_NOTAVAILABLE
He mirado en el Caps Viewer, y en el listado salen los formatos D3DFMT_X8R8G8B8 (el de 32 bits, me rula bien) y D3DFMT_R5G6B5 (el de 16 bits, me falla).

¿Alguien sabe qué pasa? Adjunto un paste del código en el link de abajo.

Gracias!  :)


Código con el problema

[HiDDeN]

 Parece ser que me inicializa bien en 32 bits porque tengo el escritorio en esa profundidad de color.

Creo que tengo que pillar la información del escritorio, y cambiarlo a los bits que me interese... 16 o 32, pero cómo lo hago? Estoy buscando bastante, y recorriéndome muchas funciones de la API de win32, y no doy con ello...

tewe76

 Creo q lo q tienes q hacer es, antes de inicializar DX, cambiar los bpp de la pantalla. Se hace con la API:

Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

Parametros:
· lpDevMode
Pointer to a DEVMODE structure that describes the graphics mode to switch to. The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The following fields in the DEVMODE structure are used:
dmBitsPerPel
Bits per pixel
dmPelsWidth
Pixel width
dmPelsHeight
Pixel height
dmDisplayFlags
Mode flags
dmDisplayFrequency
Mode frequency

In addition to setting a value in one or more of the preceding DEVMODE members, you must also set the appropriate flags in the dmFields member. The flags indicate which members of the DEVMODE structure are used for the display settings change. If the appropriate bit is not set in dmFields, the display setting will not be changed. Set one or more of the following flags:
DM_BITSPERPEL
Use the dmBitsPerPel value.
DM_PELSWIDTH
Use the dmPelsWidth value.
DM_PELSHEIGHT
Use the dmPelsHeight value.
DM_DISPLAYFLAGS
Use the dmDisplayFlags value.
DM_DISPLAYFREQENCY
Use the dmDisplayFrequency value.

If lpDevMode is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the lpDevMode parameter is the easiest way to return to the default mode after a dynamic mode change.

· dwflags
Indicates how the graphics mode should be changed. May be one of the following:
0
The graphics mode for the current screen will be changed dynamically.
CDS_UPDATEREGISTRY
The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The mode information is stored in the USER profile.
CDS_TEST
The system tests if the requested graphics mode could be set.

If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_RESTART is returned.
Windows NT: If the information could not be stored in the registry, the graphics mode is not changed and DISP_CHANGE_NOTUPDATED is returned.
Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to change to that graphics mode.


Ejemplo: (en VB)
Option Explicit
Const WM_DISPLAYCHANGE = &H7E
Const HWND_BROADCAST = &HFFFF&
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_UPDATEREGISTRY = &H1
Const CDS_TEST = &H4
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const BITSPIXEL = 12
Private Type DEVMODE
   dmDeviceName As String * CCDEVICENAME
   dmSpecVersion As Integer
   dmDriverVersion As Integer
   dmSize As Integer
   dmDriverExtra As Integer
   dmFields As Long
   dmOrientation As Integer
   dmPaperSize As Integer
   dmPaperLength As Integer
   dmPaperWidth As Integer
   dmScale As Integer
   dmCopies As Integer
   dmDefaultSource As Integer
   dmPrintQuality As Integer
   dmColor As Integer
   dmDuplex As Integer
   dmYResolution As Integer
   dmTTOption As Integer
   dmCollate As Integer
   dmFormName As String * CCFORMNAME
   dmUnusedPadding As Integer
   dmBitsPerPel As Integer
   dmPelsWidth As Long
   dmPelsHeight As Long
   dmDisplayFlags As Long
   dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim OldX As Long, OldY As Long, nDC As Long
Sub ChangeRes(X As Long, Y As Long, Bits As Long)
   Dim DevM As DEVMODE, ScInfo As Long, erg As Long, an As VbMsgBoxResult
   'Get the info into DevM
   erg = EnumDisplaySettings(0&, 0&, DevM)
   'This is what we're going to change
   DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
   DevM.dmPelsWidth = X 'ScreenWidth
   DevM.dmPelsHeight = Y 'ScreenHeight
   DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
   'Now change the display and check if possible
   erg = ChangeDisplaySettings(DevM, CDS_TEST)
   'Check if succesfull
   Select Case erg&
       Case DISP_CHANGE_RESTART
           an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
           If an = vbYes Then
               erg& = ExitWindowsEx(EWX_REBOOT, 0&)
           End If
       Case DISP_CHANGE_SUCCESSFUL
           erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
           ScInfo = Y * 2 ^ 16 + X
           'Notify all the windows of the screen resolution change
           SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, ByVal Bits, ByVal ScInfo
           MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
       Case Else
           MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
   End Select
End Sub
Private Sub Form_Load()
   'KPD-Team 1999
   'URL: http://www.allapi.net/
   'E-Mail: KPDTeam@Allapi.net
   Dim nDC As Long
   'retrieve the screen's resolution
   OldX = Screen.Width / Screen.TwipsPerPixelX
   OldY = Screen.Height / Screen.TwipsPerPixelY
   'Create a device context, compatible with the screen
   nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
   'Change the screen's resolution
   ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
   'restore the screen resolution
   ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
   'delete our device context
   DeleteDC nDC
End Sub
Tewe
www.TAPAZAPA.com : Funny and easy to play games for all ages! - Fairy Match - Brain Crash
www.LaRebelionDelBiberon.com : Experiencias de unos padres primerizos

Loover

 En modo ventana usa:

D3DDISPLAYMODE mDisplayMode;
Device->GetAdapterDisplayMode (D3DADAPTER_DEFAULT, &mDisplayMode))
Para obtener los datos del escritorio.

Te recomiendo que leas algún tutorial de inicialización como los de http://nexe.gamedev.net/News/News.asp
en concreto este:
http://nexe.gamedev.net/tutorials/ViewTuto...Tutorial2.myxml

Un saludo!
IndieLib Libreria 2.5d utilizando aceleración por hardware para la programación de juegos 2d.
Indie Rover The monkeys are reading!






Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.