簡體   English   中英

使用自定義屏幕模式類構建SDL1-> SDL2分辨率列表

[英]SDL1 -> SDL2 resolution list building with a custom screen mode class

我的引擎最近被轉換為與SDL2一起運行,以用於輸入和視頻。 但是,我很難使分辨率模式列表構建正常工作。 我確實研究了《 SDL2遷移指南》以及大量的研究鏈接-我不確定該如何去做,后來又失敗了幾次。

因此,對於初學者來說,我有一個名為i_video.cc的文件,該文件處理SDL2視頻代碼。 99%的引擎在OpenGL中運行,因此SDL僅用於初始化窗口和設置任何變量。

因此,這是將分辨率引入屏幕模式類的舊方法。 作為參考,屏幕模式類在r_modes.cc中定義。

話雖如此,這是構建屏幕模式列表的基於SDL1的舊代碼,為了我的生命,我無法在SDL2下運行。 該代碼從i_video.cc中的第190行開始。 供參考,舊代碼:

// -DS- 2005/06/27 Detect SDL Resolutions
    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    SDL_Rect **modes = SDL_ListModes(info->vfmt,
        SDL_OPENGL | SDL_DOUBLEBUF | SDL_FULLSCREEN);
    if (modes && modes != (SDL_Rect **)-1)
    {
        for (; *modes; modes++)
        {
            scrmode_c test_mode;
            test_mode.width = (*modes)->w;
            test_mode.height = (*modes)->h;
            test_mode.depth = info->vfmt->BitsPerPixel;  // HMMMM ???
            test_mode.full = true;
            if ((test_mode.width & 15) != 0)
                continue;
            if (test_mode.depth == 15 || test_mode.depth == 16 ||
                test_mode.depth == 24 || test_mode.depth == 32)
            {
                R_AddResolution(&test_mode);
            }
        }
    }
    // -ACB- 2000/03/16 Test for possible windowed resolutions
    for (int full = 0; full <= 1; full++)
    {
        for (int depth = 16; depth <= 32; depth = depth + 16)
        {
            for (int i = 0; possible_modes[i].w != -1; i++)
            {
                scrmode_c mode;
                mode.width = possible_modes[i].w;
                mode.height = possible_modes[i].h;
                mode.depth = depth;
                mode.full = full;
                int got_depth = SDL_VideoModeOK(mode.width, mode.height,
                    mode.depth, SDL_OPENGL | SDL_DOUBLEBUF |
                    (mode.full ? SDL_FULLSCREEN : 0));
                if (R_DepthIsEquivalent(got_depth, mode.depth))
                {
                    R_AddResolution(&mode);
                }
            }
        }
    }

它已被注釋掉,您可以在其上方看到設置SDL_CreateWindow的SDL2代碼。 該視頻在游戲中效果很好,但是如果沒有建立分辨率,我們將無法在沒有加載程序之前就先傳遞命令行參數來獲得屏幕分辨率的更改。 我希望他們離開某種兼容層,因為SDL2似乎比我一直在SDL1下處理的方式略有學習。

我知道ListModes和VideoInfo不再存在,並且我嘗試用等效的SDL2函數(例如GetDisplayModes)替換它們,但是代碼無法正常工作。 我不確定應該怎么做,或者是否只需要完全重構r_modes.cc,但我要做的就是獲取視頻模式列表以填充我的scrmode_c類(在r_modes.cc中) 。

當我嘗試用SDL2替換所有內容時,我得到了從SDL_Rect *到SDL_Rect **的無效轉換,所以也許我只是做錯了。 我花了幾個月的時間嘗試使其正常運行,但它並不想這樣做。 我不太在乎設置每像素位數,因為現代計算機現在只能默認為24,而我們也不需要任何理由將其設置為16或8(如今,每個人都可以使用OpenGL卡高於16位BPP);)

任何建議,幫助...在這一點上將不勝感激=)

謝謝! -科林

使用SDL_GetNumDisplayModes和SDL_GetDisplayMode的組合,然后將它們推回到SDL_DisplayMode的向量中。

std::vector<SDL_DisplayMode> mResolutions;

int display_count = SDL_GetNumVideoDisplays();

SDL_Log("Number of displays: %i", display_count);

for (int display_index = 0; display_index <= display_count; display_index++)
{
    SDL_Log("Display %i:", display_index);

    int modes_count = SDL_GetNumDisplayModes(display_index);

    for (int mode_index = 0; mode_index <= modes_count; mode_index++)
    {
        SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };

        if (SDL_GetDisplayMode(display_index, mode_index, &mode) == 0)
        {
            SDL_Log(" %i bpp\t%i x %i @ %iHz",
                SDL_BITSPERPIXEL(mode.format), mode.w, mode.h, mode.refresh_rate);

            mResolutions.push_back(mode);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM