I am trying to create an OpenGL application on windows. As far as I can understand, one of the first things I must acquire is a Device Context, which must be passed on to a couple of functions that choose and set a pixel format and create a rendering context. I used the OpenGL wiki to get a rough idea about what I should do. My code is something like:
#include <iostream>
#include <windef.h>
#include <wingdi.h>
HDC hdc;
int main() {
hdc = wglGetCurrentDC();
std::cout << "HDC: " << hdc << std::endl;
return 0;
}
This prints
HDC: 0
I assumed a Device Context refers to a physical device, but I read somewhere that it refers to any drawable "surface". In both cases is my question: how can I obtain a non-null DC? Or should I perform a completely different set of steps in order to set up this whole OpenGL system?
I found a lot of tutorials online, but they all use GLUT, GLEW, GLFW, X11, SDL etc. which are libraries. Libraries make certain things easier, but they usually do not perform tasks that are impossible without using them. This time, I want to try to do things the hard way and therefore use no libraries, just plain OpenGL.
I found, at last, a tutorial that only used the windows libraries for creating a window.
wglGetCurrentContext. - Nicol BolaswglGetCurrentDC()will not help here. If you look at its documentation, it "... obtains a handle to the device context that is associated with the current OpenGL rendering context...". Meaning that you can only use it after you created an OpenGL context. This all requires quite a lot more code. You'll have to create a window first, then go through various steps to get a DC, choose a pixel format, create an OpenGL context, etc. Beyond the scope of an answer here, at least for me... Start with studying how to write a basic app with just Win32, and then add the OpenGL pieces. - Reto Koradi