Calling InitializeGL in WebGL context

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

jadh2001

  • Posts: 2
  • Joined: Thu Mar 07, 2024 9:05 pm
  • Real Name: Jad Harkous

Calling InitializeGL in WebGL context

PostThu Mar 07, 2024 9:37 pm

Hello,

I am currently working on a node.js application where I want to display the frames captured by a DeckLink Mini Recorder 4K connected to a camera. I am trying to mimic the logic used in the CapturePreview sample of the SDK, but I am creating a WebGL context instead of an OpenGL one. I have a canvas in a html file and the following class for the canvas in the associated typescript file:

Code: Select all
class PreviewWindow {
    canvas: HTMLCanvasElement;
    gl: WebGLRenderingContext;
 
    constructor(public cameraControl: CameraControlService) {
        // Initialize canvas and WebGL context
        this.canvas = document.createElement('canvas'); 
        this.canvas.id = 'glCanvas';

        const previewBox = document.getElementById('previewBox');
        previewBox?.appendChild(this.canvas);

        this.gl = this.canvas.getContext('webgl') as WebGLRenderingContext;
        this.cameraControl.initScreenPreviewHelper();

        if (!this.gl) {
            console.error('Unable to initialize WebGL. Your browser may not support it.');
            // Handle initialization failure
            this.showErrorMessage("This application was unable to initialise the preview window", "Error");
        }
    }
 
    init(): void {
        // Set WebGL rendering context attributes       
        this.gl.pixelStorei(this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); // Enable alpha premultiplication       
        this.gl.enable(this.gl.BLEND);         
        this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA);
        this.gl.clearColor(0.0, 0.0, 0.0, 1.0);
        this.gl.clear(this.gl.COLOR_BUFFER_BIT);
    }
 
    showErrorMessage(message: string, title: string): void {
        console.error(title + ": " + message);
    }
}


In the CapturePreview sample, the DeckLink screen preview helper is created in
Code: Select all
 bool PreviewWindow::init(CStatic *previewBox)
and the function InitializeGL() is called in
Code: Select all
 bool PreviewWindow::initOpenGL
. To basically replicate this, I made a PreviewWindow cpp class (like the PreviewWindow class in the CapturePreview sample) and I wrote this function in it that is called from the WebGL context in the previously mentioned typescript file with the help of Node-API:

Code: Select all
void FrameCallback::initScreenPreviewHelper(){
    // Create the DeckLink screen preview helper
    bool result = CoCreateInstance(CLSID_CDeckLinkGL3ScreenPreviewHelper, NULL, CLSCTX_ALL, IID_IDeckLinkGLScreenPreviewHelper, (void**)&_deckLinkScreenPreviewHelper) != S_OK;
    // Result should be false
    std::cout << std::boolalpha << "CoCreateInstance result: " << result << std::endl;
   
    // Result should be true
    bool result2 = _deckLinkScreenPreviewHelper->InitializeGL() == S_OK;
    std::cout << std::boolalpha << "deckLinkScreenPreviewHelper->InitializeGL result: " << result2 << std::endl;
}


When testing this, the result of CoCreateInstance is false as it should be, but I can't figure out why the result from my InitializeGL line is false. From what I understand, InitializeGL is a pure virtual function so it should be overriden somewhere to provide an implementation for it, but I don't see such an implementation in the CapturePreview sample so I'm having trouble figuring out what to do to use InitializeGL correctly. What should I do?
Offline

jadh2001

  • Posts: 2
  • Joined: Thu Mar 07, 2024 9:05 pm
  • Real Name: Jad Harkous

Re: Calling InitializeGL in WebGL context

PostTue Mar 12, 2024 4:53 pm

I realize that my initial post might be difficult to help with, but essentially I would like to know if InitializeGL (as well as the other functions that must be called with an OpenGL context set : PaintGL, SetFrame) can really only be used when an OpenGL context is set or if a WebGL one could work too.

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 19 guests