Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

OpenGL i antialiasing

[es] :: 3D programiranje :: OpenGL i antialiasing

[ Pregleda: 2038 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Almedin

Član broj: 5895
Poruke: 425
*.dlp134.bih.net.ba.



+27 Profil

icon OpenGL i antialiasing22.07.2006. u 21:23 - pre 215 meseci
U postavkama za graficku kartu (NVidia) opciju 'Antialiasing settingd' mogu postaviti na 'Application-controlled', '2x' i '4x'. Kada postavim na 2x ili 4x scena koju radim u OpenGL izgleda ljepse. Mene interesuje kako iz aplikacije (koristim Delphi) ukljuciti antialiasing i kako provjeriti podrzava li graficka to.
 
Odgovor na temu

yooyo

Član broj: 4891
Poruke: 1101
*.beotel.net.



Profil

icon Re: OpenGL i antialiasing22.07.2006. u 22:03 - pre 215 meseci
Code:

typedef struct tagPixelFormat
{
    tagPixelFormat()
    {
        ColorDepth = 32;
        AlphaDepth = 8;
        ZDepth = 24;
        StencilDepth = 0;
        MultiSample = 0;

        FullScreen = false;
    }

    int ColorDepth, AlphaDepth, ZDepth, StencilDepth, MultiSample;
    bool FullScreen;
} tPixelFormat;


static void initEntryPoints(HWND hwnd, const PIXELFORMATDESCRIPTOR &pfd)
{
    HDC hdc = GetDC(hwnd);

    int nPixelFormat = ChoosePixelFormat(hdc, &pfd);
    SetPixelFormat(hdc, nPixelFormat, &pfd);

    HGLRC hglrc = wglCreateContext(hdc);
    wglMakeCurrent(hdc, hglrc);

// e, iza ovog poziva se nalazi mapiranje svih openGL extenzija, tako da ti treba Delphi ekvivalent. 
// Nadam se da framework koji koristis vec obavlja ovaj posao umesto tebe    
    InitOpenGLExtensions();

    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hglrc);
    ReleaseDC(hwnd, hdc);
}

#define elementsOf(x) (sizeof(x) / sizeof(x[0]))

static int GetPixelFormat(tPixelFormat& pf)
{
    PIXELFORMATDESCRIPTOR pfd = {
        sizeof (PIXELFORMATDESCRIPTOR), 1,
            PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
            PFD_TYPE_RGBA, pf.ColorDepth,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            pf.ZDepth, pf.StencilDepth,
            0, PFD_MAIN_PLANE, 0, 0, 0, 0
    };

    WNDCLASS wincl;
    wincl.hInstance = g_hInstance;
    wincl.lpszClassName = "PFrmt";
    wincl.lpfnWndProc = PFWinProc;
    wincl.style = 0;
    wincl.hIcon = NULL;
    wincl.hCursor = NULL;
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;
    wincl.hbrBackground = NULL;
    RegisterClass(&wincl);

    HWND hwnd = CreateWindow("PFrmt", "PFormat", WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 8, 8, HWND_DESKTOP, NULL, g_hInstance, NULL);
    initEntryPoints(hwnd, pfd);
    HDC hdc = GetDC(hwnd);

    int iAttribs[] = 
    {
            WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
            WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
    //        WGL_SWAP_METHOD_ARB,    WGL_SWAP_EXCHANGE_ARB,
            WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
            WGL_RED_BITS_ARB,       (pf.ColorDepth > 16)? 8 : 5,
            WGL_GREEN_BITS_ARB,     (pf.ColorDepth > 16)? 8 : 6,
            WGL_BLUE_BITS_ARB,      (pf.ColorDepth > 16)? 8 : 5,
            WGL_ALPHA_BITS_ARB,     (pf.ColorDepth > 16)? 8 : 0,
            WGL_DEPTH_BITS_ARB,     pf.ZDepth,
            WGL_STENCIL_BITS_ARB,   pf.StencilDepth,
            0
    };

    int pixelFormats[1024];
    int bestFormat = 0;
    int bestSamples = 0;
    unsigned int nPFormats;
    if (    EXTCAPS(WGL_ARB_pixel_format)
        &&  wglChoosePixelFormatARB(hdc, iAttribs, NULL, elementsOf(pixelFormats), pixelFormats, &nPFormats) 
        &&  nPFormats > 0)
    {
        int minDiff = 0x7FFFFFFF;
        int attrib = WGL_SAMPLES_ARB;
        int samples;

        // Find a multisample format as close as possible to the requested
        for (unsigned int i = 0; i < nPFormats; i++)
        {
            wglGetPixelFormatAttribivARB(hdc, pixelFormats[i], 0, 1, &attrib, &samples);
            int diff = abs(pf.MultiSample - samples);
            if (diff < minDiff)
            {
                minDiff = diff;
                bestFormat = i;
                bestSamples = samples;
            }
        }
    } 
    else 
    {
        SendMessage(hwnd, WM_CLOSE, 0, 0);
        DestroyWindow(hwnd);
        return ChoosePixelFormat(hdc, &pfd);
    }
    pf.MultiSample = bestSamples;
    SendMessage(hwnd, WM_CLOSE, 0, 0);
    DestroyWindow(hwnd);
    return pixelFormats[bestFormat];
}


Napravi primerak tPixelFormat i popuni zeljene vrednosti. Zatim pozovi gornju func i vratice ti pixelformat koji najvise odgovara trazenom.
Ako bas zelis da izlistas sve AA modove onda malo prepravi funkciju.

Inace, za ovo se koristi WGL_ARB_pixel_format ekstenzija ... http://oss.sgi.com/projects/og...istry/ARB/wgl_pixel_format.txt

yooyo

edit: uh.. tek sad videh da koristis Delphi... pokusaj da prepravis postojecu funkciju...


[Ovu poruku je menjao yooyo dana 22.07.2006. u 23:19 GMT+1]
 
Odgovor na temu

[es] :: 3D programiranje :: OpenGL i antialiasing

[ Pregleda: 2038 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.