0
votes

I'm trying to learn opengl programming on windows and while I initially started with SDL, I've decided to ditch it in order to learn how to start an OpenGL context myself using WGL.

I'm using nanovg as a quick shape drawing library and with SDL everything rendered fine, however, now that I've removed SDL and created my own window and OpenGL context I'm finding that the title bar for the window is overlapping the rendering area. As if the origin (0, 0) for the rendering area is at the top left of the whole window instead of just below the title bar, if that makes sense?

The shapes are rendering fine, but if I render a rectangle at the position 0, 0 with the height of 20, initially I wont see, however, if I increase the height of the window it will eventually appear.

What do I have to do to get the origin of the rendering area to just below the title bar?

I've set the glViewport to 0, 0 and the width and height of the window at start up, if that helps anything.

Edit: This is the OpenGL context creation code, the WindowSize.Width and WindowSize.Height properties you see are the same height and width given to the WinAPI CreateWindow function.

const int PixelFormatAttributeList[] =
                {
                    WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
                    WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
                    WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
                    WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
                    WGL_COLOR_BITS_ARB, 32,
                    WGL_DEPTH_BITS_ARB, 32,
                    WGL_STENCIL_BITS_ARB, 32,
                    0 
                };

int ContextAttributes[] =
                {
                    WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
                    WGL_CONTEXT_MINOR_VERSION_ARB, 3,
                    WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
                    0 
                };

wglChoosePixelFormatARB(WindowDeviceContext, PixelFormatAttributeList, NULL, 1, &PixelFormat, &FormatCount);

SetPixelFormat(WindowDeviceContext, PixelFormat, &PFD);

OpenGLContext = wglCreateContextAttribsARB(WindowDeviceContext, 0, ContextAttributes);                  
wglMakeCurrent(WindowDeviceContext, OpenGLContext);

glViewport(0, 0, WindowSize.Width, WindowSize.Height);

nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);

Thanks,

1
You should post some of your code. It's probably something to do with your viewport setup or camera position.markt
I've provided the OpenGL context creation code, the funny part is, if I put 30 as a value in the Y parameter for glViewport, all the content moves up instead of down, I think I may not understand how these viewports are workingWalter
@user1435899 Are you aware that in OpenGL, x+ points to the right, y+ points upwards, and z+ points away from the screen, towards the user?Xirema
Yeah I did, but I didn't expect its viewports to work like that, I thought 0, 0 was top left, I now know its actually bottom left. That explains a lot, but not the size discrepancies, I'm not sure if the problem here is windows or OpenGLWalter

1 Answers

0
votes

Okay so it turns out this had more to do with my ignorance of windows than with OpenGL itself (but it also had very much to do with my ignorance of OpenGL too). The size of a window in windows includes its title bar, and setting the size of the viewport to the size of the window is what caused the issue of shapes being rendered beneath the title bar, what solved it was retrieving the client rectangle of the window, and using that to set the viewport instead.