Hello, i was using Opengl and SDL to create some projects, and now i just wanted to use the windows API, reading some tutorials i was able to create a window class that handle the window and create the opengl context, but when i call SwapBuffers nothing happens, the only thing that change is the background color, i can't see anything on the window, can someone help me here? here is my code:
Creating the window and the opengl Context:
window = CreateWindow(className, title.c_str(), WS_OVERLAPPEDWINDOW, x, y, w, h, NULL, NULL, hInstance, NULL);
if (window == nullptr)
throw std::runtime_error("Failed to create the window!");
dc = GetDC(window);
if (dc == NULL)
throw std::runtime_error("Failed to get window device context!");
startOpenGL();
ShowWindow(window,5);
running = true;
the start opengl function:
setPixelFormat();
hglrc = wglCreateContext(dc);
if (hglrc == NULL)
throw std::runtime_error("Failed to create the openGL context!");
if (wglMakeCurrent(dc, hglrc) == false)
throw std::runtime_error("Couldn't make gl context current!");
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
The render functions:
void Window::render(){
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(-0.5f, 0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(-0.5f, -0.5f);
glEnd();
}
void Window::swapBuffers(){
SwapBuffers(dc);
}
Main loop:
window = new Window(hInstance, class_name);
window->create();
window->setText("WindowOpenGL");
window->setX(50);
window->setY(50);
window->setHeight(500);
window->setWidth(500);
while (window->isRunning()){
while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
window->render();
window->swapBuffers();
}
window->destroy();
i tested and there is no errors being returned from the functions on the render step
Thanks for attention