Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
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:
C++
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:

C++
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:

C++
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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900