Good day. I have a window with OWNDC and an Opengl context created. The glew library is also connected.
BOOL InitPixelFormat(HDC& _hDC, HWND& _hWnd)
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER ,
//PFD_SUPPORT_GDI,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32,
8,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if (!(_hDC = GetDC(_hWnd)))
{
MessageBox(NULL, L"Can't Create A GL Device Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
int pixelFormat = ChoosePixelFormat(_hDC, &pfd);
if (!pixelFormat)
{
MessageBox(NULL, L"Can't Find A Suitable PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if ((!SetPixelFormat(_hDC, pixelFormat, &pfd)))
{
MessageBox(NULL, L"Can't Set The PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
return TRUE;
}
BOOL InitOpenGL(HDC& _hDC, HGLRC& _hGLRC)
{
_hGLRC = wglCreateContext(_hDC);
if (!_hGLRC)
{
MessageBox(NULL, L"Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); return FALSE;
}
if (!(wglMakeCurrent(_hDC, _hGLRC)))
{
MessageBox(NULL, L"Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
return TRUE;
}
I output the opengl rendering code in the OpenGLPaint function via a while loop:
while (true)
{
/* check for messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
break;
}
else if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
OpenGLPaint();
}
}
Here is the code of the OpenGLPaint() function:
void OpenGLPaint()
{
glClearColor(1.0, 1.0, 1.0, 1.0);//white
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//sk_sp<const GrGLInterface> intf = nullptr;
sk_sp<const GrGLInterface> intf = GrGLMakeNativeInterface();
if (intf->validate()) cout << "Good" << endl;
sk_sp<GrDirectContext> context = GrDirectContext::MakeGL(intf);
SkImageInfo info = SkImageInfo::MakeN32Premul(glWindowWidth, glWindowHeight);
sk_sp<SkSurface> gpuSurface(SkSurface::MakeRenderTarget(context.get(), SkBudgeted::kNo, info));
if (!gpuSurface) cout << "gpu surface wasn't create properly" << endl;
SkCanvas* gpuCanvas = gpuSurface->getCanvas();
SkRect rect = SkRect::MakeXYWH(50, 50, 40, 60);
SkPaint paint;
paint.setStrokeWidth(20);
paint.setColor(SK_ColorRED);
gpuCanvas->drawRect(rect, paint);
glFlush();
SwapBuffers(hDC2);
Skia initializes successfully, but the rectangle is not output. What am I doing wrong? Opengl renders normally. I need to draw via skia in my opengl context, no other way.
I also tried initializing kia in a separate function, also doesn't work.