Пример #1
0
bool DisplayManager::Direct3DOccluded(HWND hWnd) {
    IDirect3D9Ex *pDirect3DEx;
    LPDIRECT3DDEVICE9EX pDeviceEx;
    DWORD behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    D3DPRESENT_PARAMETERS d3dpp = { 0 };
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

    Direct3DCreate9Ex(D3D_SDK_VERSION, &pDirect3DEx);
    HRESULT hr = pDirect3DEx->CreateDeviceEx(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hWnd,
        behaviorFlags,
        &d3dpp,
        NULL,
        &pDeviceEx);

    hr = pDeviceEx->CheckDeviceState(NULL);
    bool occluded = (hr == S_PRESENT_OCCLUDED);

    pDeviceEx->Release();
    pDirect3DEx->Release();

    return occluded;
}
Пример #2
0
void D3D9_SwapBuffers() {
    if (has9Ex) {
        deviceEx->EndScene();
        deviceEx->PresentEx(NULL, NULL, NULL, NULL, 0);
        deviceEx->BeginScene();
    } else {
        device->EndScene();
        device->Present(NULL, NULL, NULL, NULL);
        device->BeginScene();
    }
}
Пример #3
0
// this is the function used to render a single frame
void render_frame(void)
{
    HRESULT hr;
    static int col = 0;
    hr = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, col++), 1.0f, 0);
    if (FAILED(hr)) ERR("Clear\n");

    hr = d3ddev->BeginScene();
    if (FAILED(hr)) ERR("BeginScene\n");

    // select which vertex format we are using
    hr = d3ddev->SetFVF(CUSTOMFVF);
    if (FAILED(hr)) ERR("SetFVF\n");

    // select the vertex buffer to display
    hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
    if (FAILED(hr)) ERR("SetStreamSource\n");

    // copy the vertex buffer to the back buffer
    hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
    if (FAILED(hr)) ERR("DrawPrimitive\n");

    hr = d3ddev->EndScene();
    if (FAILED(hr)) ERR("EndScene\n");

    hr = d3ddev->Present(NULL, NULL, NULL, NULL);
    if (FAILED(hr)) ERR("Present\n");
}
Пример #4
0
void init_graphics(void)
{
    // create a vertex buffer interface called v_buffer
    d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX),
        0,
        CUSTOMFVF,
        D3DPOOL_MANAGED,
        &v_buffer,
        NULL);

    load_triangle(SCREEN_WIDTH, SCREEN_HEIGHT, v_buffer);
}
Пример #5
0
static bool set_window_size(SDL_Window* Window, int w, int h, bool fullscreen)
{
    D3DDISPLAYMODEEX mode;
    D3DPRESENT_PARAMETERS d3dpp;
    fillin_present_parameters(Window, w, h, fullscreen, d3dpp, mode);

    HRESULT hr = d3ddev->ResetEx(&d3dpp, &mode);
    if (FAILED(hr)) {
        ERR("Resize failed\n");
        return false;
    }

    return true;
}
Пример #6
0
int main(int argc, char **argv)
{
    bool fullscreen = false;

    if (SDL_Init(0) != 0){
        ERR("SDL_Init\n");
        return 1;
    }

    SDL_Window* Window = SDL_CreateWindow("SDL Nine", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
    if (!Window) {
        ERR("SDL_CreateWindow\n");
        return 1;
    }

    d3d = SDL_Direct3DCreate9Ex(Window);
    if (!d3d) {
        ERR("X11_Direct3DCreate9\n");
        return 1;
    }

    {
        HWND FakeWnd= (HWND)Window;

        D3DDISPLAYMODEEX mode;
        D3DPRESENT_PARAMETERS d3dpp;
        fillin_present_parameters(Window, SCREEN_WIDTH, SCREEN_HEIGHT, fullscreen, d3dpp, mode);

        // create a device class using this information and the info from the d3dpp stuct
        HRESULT hr = d3d->CreateDeviceEx(D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            FakeWnd,
            D3DCREATE_HARDWARE_VERTEXPROCESSING,
            &d3dpp, &mode, 
            &d3ddev);

        if (FAILED(hr)) {
            ERR("X11_Direct3DCreate9\n");
            return 1;
        }
    }

    init_graphics();    // call the function to initialize the triangle

    Uint32 MainWindowID = SDL_GetWindowID(Window);
    bool quit = false;
    SDL_Event e;

    //While application is running
    while (!quit)
    {
        //Handle events on queue
        while (SDL_PollEvent(&e) != 0)
        {
            //User requests quit
            if (e.type == SDL_QUIT)
            {
                quit = true;
            }
            else if (e.type == SDL_WINDOWEVENT && e.window.windowID == MainWindowID)
            {
                switch (e.window.event) {
                case SDL_WINDOWEVENT_SIZE_CHANGED:
                    {
                        int width = e.window.data1;
                        int height = e.window.data2;

                        bool ok = set_window_size(Window, width, height, fullscreen);
                        if (ok)
                            load_triangle(width, height, v_buffer);
                    } break;
                }
            }
            else if (e.type == SDL_KEYDOWN && e.window.windowID == MainWindowID && e.key.keysym.sym == SDLK_F11 && e.key.state == SDL_PRESSED)
            {
                fullscreen = !fullscreen;
                bool ok = set_window_size(Window, SCREEN_WIDTH, SCREEN_HEIGHT, fullscreen);
                if (ok)
                    load_triangle(SCREEN_WIDTH, SCREEN_HEIGHT, v_buffer);
            }
        }

        //Render quad
        render_frame();
    }

    // clean up DirectX
    {
        v_buffer->Release();    // close and release the vertex buffer
        d3ddev->Release();    // close and release the 3D device
        d3d->Release();    // close and release Direct3D
    }

    SDL_Quit();

    return 0;
}