Hello World example without using Skia's main function

506 views
Skip to first unread message

Bryan Austin

unread,
Aug 12, 2014, 7:58:54 AM8/12/14
to skia-d...@googlegroups.com
Greetings wonderful Skia people,

I'm kinda stuck here. I've been trying to just do a hello world example without using Skia's main function, but every example I've seen uses it. This is what I have so far...

#include <iostream>

#include <SkOSWindow_Unix.h>
#include <SkCanvas.h>
#include <SkEvent.h>
#include <SkGraphics.h>


class MyWindow : public SkOSWindow {
public:
    MyWindow() : SkOSWindow(NULL) {
        std::cout << "Construct ";
        std::cout.flush();
        AttachmentInfo info;
        this->attach(SkOSWindow::kNativeGL_BackEndType, 0, &info);
    }

    SkCanvas* createCanvas() {
        std::cout << "Canvas ";
        std::cout.flush();
        return NULL;
    }

    void draw(SkCanvas* canvas) SK_OVERRIDE {
        std::cout << "Draw";
        std::cout.flush();
    }

protected:

    void onDraw(SkCanvas*) {
        std::cout << "On Draw ";
        std::cout.flush();
    }

    SkCanvas* beforeChildren(SkCanvas* canvas) {
        std::cout << "Before Children ";
        std::cout.flush();
        canvas->drawColor(0xFF0CC0FF);
        return canvas;
    }

    bool onEvent(const SkEvent& evt) {
        std::cout << "Event ";
        std::cout.flush();
        return true;
    }
};

int main() {
    SkGraphics::Init();
    SkEvent::Init();
    MyWindow* win = new MyWindow();
    win->loop();
    SkEvent::Term();
    SkGraphics::Term();
    return 0;
}


The only output showing is the constructor. And it seems it switched the back end from CPU to GPU alright. I just can't get any of the draw or canvas hooks to catch.
It might also just be a C++ issue. I only know the basics of C++.
Any help to steer me in the right direction would be appreciated.

-Bryan

Cary Clark

unread,
Aug 12, 2014, 8:37:16 AM8/12/14
to skia-d...@googlegroups.com
Hi Bryan

Your createCanvas() and draw() functions aren't called because they haven't been declared virtual.

If you haven't done this already, I recommend starting with an existing example that works, then removing as much as you can, testing as you go, to create your hello world example. 

Good luck!
Cary


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Bryan Austin

unread,
Aug 12, 2014, 12:07:54 PM8/12/14
to skia-d...@googlegroups.com
Hey Cary,

When I marked the functions as virtual like so....

    virtual SkCanvas* createCanvas() {

        std::cout << "Canvas ";
        std::cout.flush();
        return NULL;
    }

    virtual void draw(SkCanvas* canvas) {

        std::cout << "Draw";
        std::cout.flush();
    }


No change.
I haven't been able to find an example that uses a main function. If you know of one, that would help. I've been looking at the SampleApp.cpp (and related files) to get this far. Clearly I am missing something.

I just noticed onEvent is working! Progress. I can't be too far off.

-Bryan

Cary Clark

unread,
Aug 12, 2014, 12:33:17 PM8/12/14
to skia-d...@googlegroups.com
While still overly complicated, I would look at experimental/HelloSkiaExample.cpp . 

Reply all
Reply to author
Forward
0 new messages