Handmade Network»Forums
Jay
4 posts
Requesting help with an OpenGL issue [SwapBuffers() kills my OpenGL context] [full code included] [Solved]
Edited by Jay on
*Edit*
Solution found by @Martins on the Handmade discord:
"you should not getdc/releasedc all the time - you should us same DC you used to set pixel format, otherwise bad things will happen
it's not supposed to work like that at all, but depending on workarounds in GL driver, it may work (like it does sometimes for you)"

So for me SwapBuffers(DeviceContext) was not the issue, it was the getDC/releaseDC I put around the call to SwapBuffers(DeviceContext).
After making sure I removed them and only used the DeviceContext I got from the pixelformat it started to work again.

https://hero.handmade.network/for...ers_only_after_the_window_resizes
*End of edit*

I have a simple OpenGL program that renders a triangle.
The issue is that the triangle renders fine for the first frame then dissapears on either the second or third frame.
This happens on my Windows 10 Computer but on some other (Win7 and Win10 computers) it works fine.

What seems to happen is that the call to
SwapBuffers(DeviceContext);
Completely destroys my OpenGL Context.

The clues to it being the OpenGL context that dies is that the clearcolor is set to black and
glValidateProgram(Program);
produces an error in GL_VALIDATE_STATUS


Any help with ways to troubleshoot the cause of the problem or any way forward would be very appreciative.

The source code can be found here if anyone wanna try to build and run it
https://textuploader.com/1e8pp

Compile in cmd with:

@echo off
REM If not building via visual studios console window you need to invoke vcvarsall.bat x64 before compiling
REM Visual studio can put vcvarsall.bat at different locations, but this is mine for vs 2019:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
cl /Zi -nologo source_fille.cpp /link -incremental:no user32.lib gdi32.lib opengl32.lib



Abner Coimbre
318 posts / 1 project
Founder
Requesting help with an OpenGL issue [SwapBuffers() kills my OpenGL context] [full code included] [Solved]
Thank you for updating your post to include Martins answer.