Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

valg3

"Learn DirectX 7 in 24 Hours"

This topic is 6915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yea, I know, lame title. But has anyone else had problems learning DirectX from this book? I learned the first couple chapters with no problems whatsoever, got to chapter 3 about page flipping and hidden surfaces and my program is malfunctioning. I''ve checked and double checked and triple checked my code yet I don''t see anything wrong. It compiles and links with no problems. However, when I run it, it extends to full screen with the default background color, but then it disappears into only a fraction of the screen. It doesn''t disappear until I hit escape (just like its supposed to) but the pictures dont appear either. Only once in a while will the error window pop up saying CreateSurface() Failed. Any help will be appreciated. :-)

Share this post


Link to post
Share on other sites
Advertisement
I got this book too, and found it to be the best book ever. For chapter 3, just look at the code on the CD, it should compile perfectly, well, it did for me at least. Just look over your code a little more, and compare it to whats on the cd for reference.

After just reading only about 7 chapters in this book, i have been able to make a civ2 clone. And I had no game programming or windows programming experience ever. Just follow along with the book, and do a little inovation on your own, and you will get the hand of it very quickly.

Possibility

Share this post


Link to post
Share on other sites
Looks like your program shuts down DirectDraw immediately. The black thing, you can see on the screen may be your application-window. Call lpDD->Release (); after catching the Escape-Key.

If this is not the reason, i don''t know what''s wrong. Maybe, you can post some important things of your sourcecode, here.

Andreas

Share this post


Link to post
Share on other sites
I tried the lpDD->Release(); but it didnt make a difference. I already have it in there.

Possibility: I agree this is a GREAT book, but I think its my own fault in my code. I''m just blind to the error me thinks.

Here''s my Init function, I think that''s wherte my problem is.

////////////////////////////////////////////////////////////
static BOOL Init(HINSTANCE hInstance, int nCmdShow)
////////////////////////////////////////////////////////////
{
WNDCLASS wc;
HRESULT ddrval;

//setup and register the window class

wc.style = CS_HREDRAW/CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(DWORD);
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClass;

if(!RegisterClass(&wc))
{
ErrStr = Err_Reg_Class;
return false;
}

//get the dimensions of the display

int ScreenWidth= GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight= GetSystemMetrics(SM_CYSCREEN);

//create window and display

HWND hWnd;

hWnd = CreateWindow(szClass, szCaption, WS_VISIBLE/WS_POPUP,
0, 0, ScreenWidth,
ScreenHeight, NULL, NULL, hInstance, NULL);

if(!hWnd)
{
ErrStr = Err_Create_Win;
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

//clear image pointers

ZeroMemory(lpSlides,sizeof(lpSlides));

//create the main Direct Draw object

ddrval = DirectDrawCreateEx(NULL,(LPVOID*)&lpDD,IID_IDirectDraw7,NULL);

if(ddrval != DD_OK)
{
ErrStr = Err_DirectDrawCreate;
return false;
}

//set our cooperation level

ddrval = lpDD->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN);

if(ddrval != DD_OK)
{
ErrStr = Err_Coop;
return false;
}

//Set the display mode

ddrval = lpDD->SetDisplayMode(640,480,16,0,0);

if(ddrval != DD_OK)
{
ErrStr = Err_DispMode;
return FALSE;
}

//Create the primary surface with one back buffer
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;

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

if(ddrval != DD_OK)
{
ErrStr = Err_CreateSurf;
return FALSE;
}

//fetch back buffer interface

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval=
lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);

if(ddrval != DD_OK)
{
ErrStr = Err_CreateSurf;
return FALSE;
}

//load the first image

lpSlides[0] = bitmap_surface(file_names[0]);

if(!lpSlides[0])
return FALSE;

draw_slide();

//return success to caller
return TRUE;
}

Share this post


Link to post
Share on other sites
First of all, I bought this book about 2 months ago and realized that it''s not as good as I thought it was. First of all, all of the source code in the examples that you can install from the book are not DirectX7, more like DirectX6. There are even a number of technical errors that I''ve found while using this book and it''s source code. For all of you who own this, have a happy time finding errors in the author''s source code. =)

(P.S: The part about Direct3D was pretty good, but other than that, It was a big mistake buying this book).

JDemo
JDemo@icestorm.net

Share this post


Link to post
Share on other sites
I personally liked the book. It came with the full SDK and really is good for those starting to learn D3D. Simple and to the point. It does lack in more advanced things like texture stages that I really wished was in it, but all in all a good starting place.

As for the code, I notice a couple of things:
--------------------
ZeroMemory(lpSlides,sizeof(lpSlides));

I might be wrong in your case, but I don''t think this is right, as the size of lpSlides is 4 bytes. You are referring to the size of the pointer with this. You need to tell it the size of the structure or array you are pointing to with lpSlides.
------------------------

**** ADD THE NEXT LINE IN THERE *****
ZeroMemory(&ddsd, sizeof(ddsd));
...
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
ddrval = lpDD->CreateSurface(&ddsd,&lpDDSPrimary,NULL);

You should always clear out the structure before using it with a call to ZeroMemory.
------------------------------


See if that second fix helps. It seems to look right to me as I''m reading it really quick.

Jim Adams

Share this post


Link to post
Share on other sites
I want this book. I have been looking for a
book that can help someone start with direct 3d.

I already have a good one for 2d.. (that andre book)

I was searching though and can not find it. Anyone have a link ? I already searched amazon

Share this post


Link to post
Share on other sites
Sams Teach Yourself DirectX 7 in 24 Hours.

Published by: Sams
Published Year: 2000
Author: Robert Dunlop
ISBN: 0-672-31634-x

Try Amazon or Barnes and Noble (www.bn.com) and search for the ISNB.

Jim Adams

Share this post


Link to post
Share on other sites
The book is an excellent book for the very beginners. Theonly programming I had ever done was in a intro to C++ class and that was all on linux, this book showed me how to program in windows, and how to use VC++, which i knew nothing about, and i learned quickly from it. The 2D stuff and direct input were all excellent, even if they were actually directx6 instead of 7 (i never programmed in 6 or 7 or any directx before anyways).

Besides, what is the difference between directx 6 and 7? Is there much difference in the 2D area?

Possibility

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!