subski
subski

Reputation: 77

Raylib render is hidden when using a vibrant window

I'm on macOS Sonoma, and I was trying to setup a simple raylib window with some text and a semi transparent/blurry background window.

So I made a basic raylib window and get the window handle that I pass to an objective-c function which setup the vibrancy effect.

The effect is working correctly as intended except that when enabled, nothing drawn with raylib is displayed in the window. I only get a blurry background and that's it, no text, nothing.

I tried messing around with the NSVisualEffectView settings but nothing worked for me.

Code:

main.c

#include "raylib.h"

#define GLFW_INCLUDE_NONE
#define GLFW_EXPOSE_NATIVE_COCOA
#define GLFW_EXPOSE_NATIVE_NSGL
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <objc/objc-runtime.h>
#include "vibrancy.h"

int main(void)
{
    InitWindow(800, 450, "My Window");

    // Vibrancy effect
    id glfw_window = GetWindowHandle();
    AddVibrancyEffect(glfw_window);

    // App loop
    while (!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Congrats! You created your first window!", 10, 10, 20, (Color) { 200, 0, 0, 255 });
        EndDrawing();
    }

    CloseWindow();

    return 0;
}

vibrancy.m

#import <Cocoa/Cocoa.h>
#import "vibrancy.h"

void AddVibrancyEffect(id window) {
    NSWindow *nsWindow = (__bridge NSWindow *)window;

    NSVisualEffectView *vibrantView = [[NSVisualEffectView alloc] initWithFrame:[nsWindow.contentView bounds]];
    vibrantView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
    vibrantView.blendingMode = NSVisualEffectBlendingModeBehindWindow;
    vibrantView.material = NSVisualEffectMaterialMenu;
    vibrantView.state = NSVisualEffectStateFollowsWindowActiveState;
    
    [nsWindow.contentView addSubview:vibrantView positioned:NSWindowBelow relativeTo:nil];
}

Any ideas to fix this ?

Upvotes: 0

Views: 89

Answers (0)

Related Questions