Skip to content

Getting an OpenGL widget to work #680

@jeannekamikaze

Description

@jeannekamikaze

I am unable to get an OpenGL widget working. I used opengl.d as a reference and I noticed that if I don't specify a padding or margins, the widget has 0 size. Moreover, the rect that gets passed in does not seem to map to the widget's location on the screen anyway.

Below is a minimal example where nothing gets drawn. If I replace the OpenGL widget with a button, however, the button does appear on the screen.

Any help on getting this example to work would be appreciated. Thank you.

import bindbc.opengl;
import dlangui;

mixin APP_ENTRY_POINT;

class MainView : VerticalLayout
{
    this(string id)
    {
        super(id);

        layoutWidth = FILL_PARENT;
        layoutHeight = FILL_PARENT;

        backgroundDrawable = DrawableRef(new OpenGLDrawable(&render));
    }

    void render(Rect windowRect, Rect rc)
    {
        // Clear the widget to pink.
        glEnable(GL_SCISSOR_TEST);
        glScissor(rc.left, rc.bottom, rc.width, rc.height);
        glClearColor(1, 0, 1, 0);
        glClear(GL_COLOR_BUFFER_BIT);
        glDisable(GL_SCISSOR_TEST);
    }
}

extern (C) int UIAppMain(string[] args)
{
    Window window = Platform.instance.createWindow("Game Maker", null);

    // Nothing gets rendered. The widget seems to have 0 size.
    window.mainWidget = new MainView("MainView");

    // The button does appear on the screen.
    //window.mainWidget = new Button("Button", "Click me"d);

    window.show();
    return Platform.instance.enterMessageLoop();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions