Having some problems wiht directx...

Started by
1 comment, last by JSCFaith 23 years, 9 months ago
Hey all, Well, Im rather new at this directx stuff, and off course you guys have all probably been here, your code doesn't work, You don't know why, but you beat lots of other people could see it in a blink of an eye, well I have been reading "Inside Directx" and I have been reading the SDK Docs for Directx 7.0, but I dont see what I am doing wrong, I was trying to debug, but when I ran the program my comp would just crash, so I couldn't really debug it, if anyone could help me. If someone could tell me what I am doing wrong it would help me, the code is really short, it only starts directdraw, makes a fliping chane and creates one off screen surface and blts it to the back surface of the flip chane. // Here is the short sorce file... // I left out all the windows stuff to make it smaller... // This is the funtion I put in the windows message loop, to update every frame, I just call it game main. //Main Variables: LPDIRECTDRAW7 lpDD = NULL; LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL; LPDIRECTDRAWSURFACE7 lpDDSBack = NULL; LPDIRECTDRAWSURFACE7 lpDDSOffOne = NULL; HWND hwnd; long xpos = 0; long ypos = 0; int GameMain() { DDSURFACEDESC ddsd; RECT srcRect; RECT destRect; HRESULT ddrval; xpos += 5; ypos += 3; if( (ypos + 50) == 480) { ypos = 0; } if( (xpos + 50) == 640) { xpos = 0; } srcRect.top = 0; srcRect.left = 0; srcRect.right = 50; srcRect.bottom = 50; ddrval = lpDDSBack->BltFast( xpos, ypos, lpDDSBack, &srcRect, DDBLTFAST_DESTCOLORKEY ); while(1) { ddrval = lpDDSPrimary->Flip(NULL, 0); if(ddrval == DD_OK) { break; } if(ddrval == DDERR_SURFACELOST) { ddrval = lpDDSPrimary->Restore(); if(ddrval != DD_OK) { break; } } if(ddrval != DDERR_WASSTILLDRAWING) { break; } } return 0; } //Inits directx and loads a pic and stuff. int GameInit() { DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; HRESULT ddrval; RECT srcRect; RECT destRect; // Create the DirectDraw object -- we just need an IDirectDraw // interface so we won't bother to query an IDirectDraw2 if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpDD, IID_IDirectDraw7, NULL))) { } if(FAILED(lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN))) { } if(FAILED(lpDD->SetDisplayMode(640, 480, 8, 0, 0))) { } ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; if(FAILED(lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL)) ){ } ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack))) { } ZeroMemory( &ddsd, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_CKSRCBLT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight = 100; ddsd.dwWidth = 100; ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = RGB(65,40,254); if(FAILED( lpDD->CreateSurface(&ddsd, &lpDDSOffOne, NULL))) { } lpDDSOffOne = DDLoadBitmap(lpDD, "ship1.bmp", 0, 0); return 0; } //Releases all the objects static void ReleaseObjects( void ) { if ( lpDD != NULL ) { if ( lpDDSPrimary != NULL ) { if( lpDDSOffOne !=NULL ) { lpDDSOffOne->Release(); lpDDSOffOne = NULL; } lpDDSPrimary->Release(); lpDDSPrimary = NULL; } lpDD->Release(); lpDD = NULL; } } James, Thanks all, Edited by - JSCFaith on 7/13/00 11:56:49 PM
Advertisement
I didn''t read all of that, I don''t know if anybody else did, but a simple debugging hint: comment out parts of code to locate where the error(s) lie.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Take a look at this line in GameMain()

ddrval = lpDDSBack->BltFast( xpos, ypos, lpDDSBack, &srcRect, DDBLTFAST_DESTCOLORKEY );

I believe you are trying to blt from lpDDSBack to itself. I'm not sure if that is causing your error, but I don't think that's what you want to do. If I'm making an incorrect assumption, feel free to kick me. The third parameter of the BltFast function is the source surface (likely lpDDSOffOne in your program). I haven't read anymore yet, but you might try changing that.

*edit*
This is part of your game init function...
        // add this lineZeroMemory(&ddsd, sizeof(ddsd));// before these linesddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1;if(FAILED(lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL)) ){ }// and add this lineZeroMemory(&ddscaps, sizeof(ddscaps));// before these linesddscaps.dwCaps = DDSCAPS_BACKBUFFER;if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack))) { }        


Edited by - Matthew02 on July 14, 2000 1:27:20 AM

Edited by - Matthew02 on July 14, 2000 7:44:28 AM

This topic is closed to new replies.

Advertisement