CodeBlocks offers an example program in C, that uses OpenGL. It draws a single multicoloured rotating triangle. I have been building on this example. I am a novice in C and in OpenGL. I believe that I am using an old style of OpenGL coding (possibly called "Immediate Mode ?") and I am trying to keep things as simple as possible. For example, I am not, to my knowledge, using VBOs, nor VAOs, nor GLSL. I am also not, as far as I know, using any helper libraries (if that's a right way to say it), such as GLEW, GLFW, GLut, etc.
I notice that the sides of the triangles are more jagged than they need to be, given the resolution of my laptop screen. Even if no multisampling were used (and I am not yet trying to use it), much smaller "jaggies" could be achieved, if OpenGL's raster array really corresponded to the physical pixel array. I took a "print screen" and opened it in MS Paint, saving it as a .bmp. When I zoomed in, it seemed that multisampling had been used, but to smooth the edges of the large jaggies ! If you see what I mean.
This shows that the text on the left (which is not from my OpenGL window) is rendered at a higher resolution than my triangley object on the right (which is in my OpenGL window).
My question is, how can I use the maximum resolution of the screen ?
Here are some excerpts from the code:
#include <windows.h>
#include <gl/gl.h>
#include <stdio.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
HWND hwnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
const int width = 768;
const int height = 768;
/* register window class */
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_OWNDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "GLSample";
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;
if (!RegisterClassEx(&wcex))
return 0;
/* create main window */
hwnd = CreateWindowEx(0,
"GLSample",
"OpenGL Sample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
/* enable OpenGL for the window */
EnableOpenGL(hwnd, &hDC, &hRC);
etc..
}
and the EnableOpenGL function:
void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC(hwnd);
/* set the pixel format for the DC */
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat(*hDC, &pfd);
SetPixelFormat(*hDC, iFormat, &pfd);
/* create and enable the render context (RC) */
*hRC = wglCreateContext(*hDC);
wglMakeCurrent(*hDC, *hRC);
}