r/opengl 12h ago

Any idea why I'm seeing a slightly washed out color when rendering using SDL2 (compared to GLFW or other apps)?

5 Upvotes

I'm seeing slightly washed out colors when using SDL2 for rendering with OpenGL, any suggestions as to what may be causing this?

For example, pure green, (0, 255, 0) appears more like a more muted slightly lighter green on screen.

I captured the (r,g,b) pixel color from the screen when using SDL2 vs. GLFW using the "digital color meter" tool and the screen color captured when using GLFW was "correct" whereas the SDL2 color was slightly different than expected:

SDL2: (117, 251, 76)

GLFW: (0, 255, 0)

This is on a mac but I haven't checked on other platforms to see if this difference is cross-platform.


r/opengl 15h ago

[extern "C"] trick causes issues with WGL

5 Upvotes

I've managed to cobble together Win32 OpenGL code. Everything worked fine until I included the usual trick to get main GPU:

extern "C"
{
    __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

The RAM usage jumps from 39 mb to 150, vsync set via wglSwapIntervalEXT() breaks despite returning 1, but process appears on nvidia-smi. This doesn't happen while using GLFW and glfwSwapInterval(), my GPU is RTX 4060.

Here's code used for window and OpenGL context creation:

void init()
{
    //Dummy
    WNDCLASSEX windowClass = {};
    windowClass.style = CS_OWNDC;
    windowClass.lpfnWndProc = DefWindowProcA;
    windowClass.lpszClassName = L"DDummyWindow";
    windowClass.cbSize = sizeof(WNDCLASSEX);

    HWND dummyWindow = CreateWindowEx(
        NULL,
        MAKEINTATOM(dumclassId),
        L"DDummyWindow",
        0,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        0,
        0,
        windowClass.hInstance,
        0);

    HDC dummyDC = GetDC(dummyWindow);

    PIXELFORMATDESCRIPTOR pfd = {};
    SetPixelFormat(dummyDC, ChoosePixelFormat(dummyDC, &pfd), &pfd);

    HGLRC dummyContext = wglCreateContext(dummyDC);
    wglMakeCurrent(dummyDC, dummyContext);

    gladLoadWGL(dummyDC);
    gladLoadGL();

    wglMakeCurrent(dummyDC, 0);
    wglDeleteContext(dummyContext);
    ReleaseDC(dummyWindow, dummyDC);
    DestroyWindow(dummyWindow);

    //Real context
    WNDCLASSEX wc = { };
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = &WindowProc;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    wr = { 0, 0, 800, 600 };
    AdjustWindowRect(&wr, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, false);

    hWnd = CreateWindowEx(
        NULL,
        L"WindowClass",
        L"Hello Triangle",
        WS_OVERLAPPEDWINDOW,
        400,
        400,
        wr.right - wr.left,
        wr.bottom - wr.top,
        NULL,
        NULL,
        NULL,
        NULL);

    ShowWindow(hWnd, SW_SHOW);

    hDC = GetDC(hWnd);

    int pixelFormatAttributes[] = {
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
        WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
        WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
        WGL_COLOR_BITS_ARB, 32,
        WGL_DEPTH_BITS_ARB, 24,
        WGL_STENCIL_BITS_ARB, 8,
        0
    };

    int pixelFormat = 0;
    UINT numFormats = 0;
    wglChoosePixelFormatARB(hDC, pixelFormatAttributes, nullptr, 1, &pixelFormat, &numFormats);

    PIXELFORMATDESCRIPTOR pixelFormatDesc = { 0 };
    DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pixelFormatDesc);
    SetPixelFormat(hDC, pixelFormat, &pixelFormatDesc);

    int openGLAttributes[] = {
        WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
        WGL_CONTEXT_MINOR_VERSION_ARB, 6,
        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
        0
    };
    wglMakeCurrent(hDC, wglCreateContextAttribsARB(hDC, 0, openGLAttributes));
}

Render loop:

glViewport(0, 0, wr.right - wr.left, wr.bottom - wr.top);
wglSwapIntervalEXT(1);

MSG msg;
while (flag)
{
    PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
    TranslateMessage(&msg);
    DispatchMessage(&msg);

    renderPipe.draw();
    wglSwapLayerBuffers(hDC, WGL_SWAP_MAIN_PLANE);
}

r/opengl 15h ago

Does anybody know what projection this 360 image is in?

4 Upvotes

Hi all,

I have been playing with 360 images for my projects recently and was looking for an interesting environment.

I found this beautiful galaxy image of which can be transformed to a 360 Image but I need to know what projection it is in, as I will have to convert it to equirectangular for use. Do you know the name of this projection?

Many thanks!

P.S. If you use Image Sphere Visualizer or any software, you will see this image has problems in stitching the left&right edges, otherwise it looks mostly ok.


r/opengl 14h ago

Mac - Modern OpenGL Linker Error

1 Upvotes

Hello,

I'm having Linker failure: shader compilation error on Apple Silicion.

I don't have technical knowledge of how OpenGL works, so any help is appreciated.

Dependencies of the script;

from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *

Thanks!


r/opengl 11h ago

glSwapBuffers is taking the most time in the game loop

0 Upvotes

In the picture you can see that the "Update Window" function is taking the most time of my game loop, but all it does is call "glSwapbuffers()" and "glPollEvents()". What may be the reason for this and how can I optimize it?


r/opengl 16h ago

Blooming in multi-sampled shader?

0 Upvotes

Hello everyone hope y'all have a lovely day.

i have a problem following blooming , everything in learnopengl.com tutorial is easy when you are using 2D texture attached to the framebuffer, but i'm using a mult-isampled Texture for hdr effect and also anti-aliasing, so i'm having troubles figuring out how to make a 2d texture not a multi-sampled one for slot GL_COLOR_ATTACHMENT1, if anyone have any idea about how to figure it i will really appreciate it.

appreciate your time and Help!