×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Direct Draw back buffer problem

Direct Draw back buffer problem

Direct Draw back buffer problem

(OP)
I am new at using directX and am clueless as to why my GetAttachedSurface returns an error. This program works just fine with only one surface. I have included my WinMain function.


int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine, int nCmdShow)
{
    DDSURFACEDESC2 ddsd;
    HRESULT hRet;

    MSG msg;
    HWND hWnd;
    WNDCLASS wc;

    LONGLONG cur_time;
    DWORD time_count;
    LONGLONG perf_cnt;
    bool perf_flag=false;
    LONGLONG next_time=0;
    LONGLONG last_time=0;
    double time_elapsed;
    double time_scale;

    wc.style        =CS_HREDRAW|CS_VREDRAW;
    wc.lpfnWndProc    =(WNDPROC)WindowProc;
    wc.cbClsExtra    =0;
    wc.cbWndExtra    =0;
    wc.hInstance    =hInstance;
    wc.hIcon        =LoadIcon(hInstance,"Rouslan");
    wc.hCursor        =LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName    =MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName="Rouslan";
    if(!RegisterClass(&wc))return false;

    if(QueryPerformanceFrequency((LARGE_INTEGER*)&perf_cnt))
    {
        perf_flag=true;
        time_count=perf_cnt/30;
        QueryPerformanceCounter((LARGE_INTEGER*)&next_time);
        time_scale=1.0/perf_cnt;
    }else{
        next_time=timeGetTime();
        time_scale=0.001;
        time_count=33;
    }
    last_time=next_time;

    hInst=hInstance;

    hWnd = CreateWindow(lpszAppName,lpszTitle,WS_POPUP,0,0,
        GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL);

    if(!hWnd)return false;

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

    hRet=DirectDrawCreateEx(NULL,(LPVOID*)&lpDD,IID_IDirectDraw7,NULL);
    if(hRet != DD_OK)return false;

    hRet = lpDD->SetCooperativeLevel(hWnd,DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE);
    if(hRet != DD_OK)return false;

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

    /*hRet=lpDD->CreateClipper(NULL,&lpClip,NULL);
    if(hRet != DD_OK)
    {
        ErrStr=Err_CreateClip;
        return false;
    }
    lpClip->SetHWnd(0,hWnd);*/

    ZeroMemory(&ddsd,sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
    ddsd.dwBackBufferCount=1;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
    hRet=lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
    if(hRet != DD_OK)return false;

    /////////GOOD UP TO HERE///////////

    DDSCAPS2 ddscaps;
    ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
    hRet=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);
    if(hRet!=DD_OK)
    {
        MessageBox(hWnd,"This message gets called","Hmm",MB_OK);
        return false;
    }

    /////////BREAK DOWN HERE///////////
    

    //lpDDSPrimary->SetClipper(lpClip);
    bInit=true;

    GAME.SetWndData(&hWnd,&hInst);

    while(true)
    {
        if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
        {
            if(!GetMessage(&msg,NULL,0,0))return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }else{
            if(perf_flag)QueryPerformanceCounter((LARGE_INTEGER*)&cur_time);
            else cur_time=timeGetTime();

            if(cur_time>next_time)
            {
                time_elapsed=(cur_time-last_time)*time_scale;
                last_time=cur_time;
                GAME.Action();
                SCREEN.DrawScreen(&GAME,&hWnd);
                next_time=cur_time+time_count;
            }
        }
    }
    return(msg.wParam);
}

RE: Direct Draw back buffer problem

Well I'm not really sure, this is just a gues:

Three lines after /////////GOOD UP TO HERE///////////, try inserting

ddsCaps.dwCaps2 = 0;

The DDSCAPS structure actually has 4 members, (only dwCaps and dwCaps2 are used, though.) Since dwCaps2 wasn't getting initialized, it probably had a random value like 0xCCCCCCCC, which could cause GetAttachedSurface to fail when it tries to get a back buffer with a whole bunch of capabilities declared in dwCaps2.

Sorry if it doesn't work, this is just my guess-- I've actually been off the DirectDraw7 scene since DirectX 8 came out, so I'm a bit rusty in that subject.

Happy gaming

RE: Direct Draw back buffer problem

(OP)
Thanks for trying but that didn't help. Anyways when I checked which error message it turned out to be DDERR_NOTFOUND. That seems strange to me.

RE: Direct Draw back buffer problem

(OP)
Never mind. I just switched to Direct X 8 and couldn't be happier.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close