Skip to content

[QUESTION] Using SkiaSharp with an OpenGL context #1555

Description

@FireBanana

Hi, I'm trying to run SkiaSharp on an OpenGL context (in a console app) but all I see is a black screen. I'm not sure what I'm doing wrong as I'm new to this. Also, I'm using a GLFW wrapper for the OpenGL calls. Any help would be appreciated.

        GLFW.glfwInit();
        GL10.glHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
        GL10.glHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 3);
        GL10.glHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);

        var window = GLFW.glfwCreateWindow(800, 600, new byte[0], IntPtr.Zero, IntPtr.Zero);
        GLFW.glfwMakeContextCurrent(window);            
        GL10.glViewport(0, 0, 800, 600); 

        SKImageInfo imageInfo = new SKImageInfo(800, 600);

        var context = GRContext.CreateGl(GRGlInterface.CreateOpenGl((name) => new IntPtr(GLFW.glfwGetProcAddress(name))));

        using (SKSurface surface = SKSurface.Create(context, false, imageInfo, 1, GRSurfaceOrigin.TopLeft))
        {
            SKCanvas canvas = surface.Canvas;

            while (GLFW.glfwWindowShouldClose(window) == 0)
            {
                canvas.Clear(SKColors.Red);
                GLFW.glfwSwapBuffers(window);
                GLFW.glfwPollEvents();

            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions