Problem with initializing directx
hi!
after reading about half of "tricks of the windows game programming gurus", i decided to both start writing actuall directx code and to make my own library rather than use the t3d ones. newayz, in my game_init() function, which looks like this:
int Game_Init()
{
if(FAILED(DirectDrawCreate(NULL,&lpdd, NULL)))
{
//error!!
return(0);
}
if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4,
(LPVOID *)&lpdd4)))
{
//error!!
return(0);
}
if(lpdd)
{
lpdd->Release();
lpdd = NULL;
}
if(FAILED(lpdd4->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
{
//error!!
return(0);
}
if(FAILED(lpdd4->SetDisplayMode(SCREEN_WIDTH,
SCREEN_HEIGHT,SCREEN_BPP,0,0)))
{
//error!!
return(0);
}
}
i come across a few errors that are somewhat strange while compiling. first, it says that IID_IDIRECTDRAW4 is an "unrefrencecd identifier". when looking in the directxsdk help, it says that a "Reference identifier of the interface being requested" should be passed... im a little confused there whether i have to declare iid_idirectdraw4 and define it somehow or it''s a flag or somethin else (oww my head hurts from all this!)
the second error says that there isn''t 5 parameters in queryinterface(), which i know has 5... any help wud be appreciated!
thanx,
~~KaMiKaZ~~
your going about it all wrong.
here is my init function:
HRESULT InitDirectDraw()
{
// Obtain a pointer to an IDirectDraw7 interface.
DirectDrawCreateEx(NULL, (VOID**)&lpDirectDraw, IID_IDirectDraw7, NULL);
// Set the cooperative level.
lpDirectDraw->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN|DDSCL_ALLOWREBOOT);
// Change the display mode.
lpDirectDraw->SetDisplayMode(nWidth, nHeight, nBPP, 0, 0);
DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX|DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount = 1;
// Create the primary surface with one back buffer.
lpDirectDraw->CreateSurface(&ddsd, &lpddsPrimary, NULL);
DDSCAPS2 ddscaps; ZeroMemory(&ddscaps, sizeof(DDSCAPS2));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
// Get a pointer to the back buffer.
lpddsPrimary->GetAttachedSurface(&ddscaps, &lpddsBack);
return D3D_OK;
}
here is my init function:
HRESULT InitDirectDraw()
{
// Obtain a pointer to an IDirectDraw7 interface.
DirectDrawCreateEx(NULL, (VOID**)&lpDirectDraw, IID_IDirectDraw7, NULL);
// Set the cooperative level.
lpDirectDraw->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN|DDSCL_ALLOWREBOOT);
// Change the display mode.
lpDirectDraw->SetDisplayMode(nWidth, nHeight, nBPP, 0, 0);
DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX|DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount = 1;
// Create the primary surface with one back buffer.
lpDirectDraw->CreateSurface(&ddsd, &lpddsPrimary, NULL);
DDSCAPS2 ddscaps; ZeroMemory(&ddscaps, sizeof(DDSCAPS2));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
// Get a pointer to the back buffer.
lpddsPrimary->GetAttachedSurface(&ddscaps, &lpddsBack);
return D3D_OK;
}
oh ya and make sure to link with dxguid.lib and ddraw.lib
example:
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")
#include <windows.h>
#include <ddraw.h>
example:
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "ddraw.lib")
#include <windows.h>
#include <ddraw.h>
annon, i think ur way wud work if i waz using directx 7 or 8 or somethin, but r/now im using directx 6.0, so there is no directdrawcreateex function.. everything else applies, but that doesn''t really help 2 much... thanx neway. can ne1 else using v 6.0 help me?
thanx,
~~KaMiKaZ~~
thanx,
~~KaMiKaZ~~
aaaaaah! now the compiler doesn''t recognize LPDIRECTDRAW4 as a data type... somethin''s not right! i set the compiler to link to ddraw.lib and dxguid.lib, and also included ddraw.h . i have version 6.1 of the sdk installed.. grrrrrrrrrrrrrrrrrrr... any help wud b appreciated... the sooner the beter!
thanx,
~~KaMiKaZ~~
thanx,
~~KaMiKaZ~~
the code I posted is for DirectDraw 7.
dd7 is what you should be using.
and if you''re using version 6 you shouldnt be trying to obtain a pointer to a version 4 interface.
that makes no sense.
dd7 is what you should be using.
and if you''re using version 6 you shouldnt be trying to obtain a pointer to a version 4 interface.
that makes no sense.
annon... thanx but no thanx. i''m trying to learn directx 6 first! at v 6.0, all the interface versions were not caught up (ie some interfaces might be version 1, some 4, some 2, etc...) so that''s why directdraw is @ version 4. pleaz ne1 else know how to fix this?? it makes no sense at all. for the record, im using msoft visual c++ 6.0 introductary edition, and i''ve manually included ddraw.h, and linked to dxguid.lib and ddraw.lib thru the project->settings->link.
thanx
~~KaMiKaZ~~
thanx
~~KaMiKaZ~~
Never link to a library file through the projects->settings->link, you should always manually include then in your project. Don''t ask me why, just do it.
X4J
X4J
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement