Я использую коды OpenGL с использованием WinApi, но мои WinApi windows / кнопки / тексты не видны. Это можно увидеть под черным экраном / поверхностью. Точно так же он не появляется на кнопках. Короче говоря, я хочу использовать функции WinApi на поверхности OpenGL.
Можете ли вы исправить мой код?
Мои коды:
#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>
WNDCLASS wc = {0}, otherClass = {0};
HWND window, otherWindow;
MSG msg;
HDC dc;
HGLRC rc;
bool quit = false;
LRESULT CALLBACK WndProc(HWND window, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_DESTROY:
quit = true;
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch (wp) {
case 27:
quit = true;
PostQuitMessage(0);
break;
};
break;
default:
return DefWindowProc(window, msg, wp, lp);
break;
};
return DefWindowProc(window, msg, wp, lp);
};
LRESULT CALLBACK WndProcC(HWND window, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
default:
return DefWindowProc(window, msg, wp, lp);
break;
};
return DefWindowProc(window, msg, wp, lp);
};
int main() {
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "wc";
RegisterClass(&wc);
otherClass = wc;
otherClass.lpfnWndProc = WndProcC;
otherClass.hbrBackground = (HBRUSH) GetStockObject(DKGRAY_BRUSH);
otherClass.lpszClassName = "OtherClass";
RegisterClass(&otherClass);
window = CreateWindow("wc", "Window!", WS_OVERLAPPEDWINDOW,
100, 100, 512, 512,
NULL, NULL, NULL, NULL);
ShowWindow(window, true);
otherWindow = CreateWindow("OtherClass", "OtherWindow!", WS_CHILD | WS_OVERLAPPEDWINDOW,
100, 100, 256, 256,
window, NULL, NULL, NULL);
ShowWindow(otherWindow, true);
while (true) {
int f;
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
dc = GetDC(window);
f = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, f, &pfd);
rc = wglCreateContext(dc);
if (PeekMessage(&msg, NULL, 0, 0, 0x0001)) {
if (msg.message == WM_QUIT || msg.message == WM_DESTROY) {
break;
}else {
TranslateMessage(&msg);
DispatchMessage(&msg);
};
}else{
wglMakeCurrent(dc, rc);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw
SwapBuffers(dc);
};
wglMakeCurrent(NULL, NULL);
wglDeleteContext(rc);
ReleaseDC(window, dc);
};
return 0;
};