OpenGL Windows Init more simple

Hi all. I’m developing a 4kb intro using opengl and c++. I want to know if there’re another way to create an opengl windows than the code that I poste here. Beceause this code grow a lot my final exe.
Thanks to all

//-------------------------------------------------------------------------
// CREATING OPENGL WINDOWS
//-------------------------------------------------------------------------
WNDCLASS wc;
DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
DWORD dwStyle = WS_OVERLAPPEDWINDOW;

RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;	
WindowRect.top=(long)0;	
WindowRect.bottom=(long)height;	

wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = "GL";

RegisterClass(&wc);

	DEVMODE dmScreenSettings;
	memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	
	dmScreenSettings.dmSize=sizeof(dmScreenSettings);
	dmScreenSettings.dmPelsWidth	= width;
	dmScreenSettings.dmPelsHeight	= height;
	dmScreenSettings.dmBitsPerPel	= 32;	
	dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

	ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);

	dwExStyle=WS_EX_APPWINDOW;
	dwStyle=WS_POPUP;
	ShowCursor(FALSE);

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

hWnd=CreateWindowEx(	dwExStyle,
                    "GL", "Ak",
                    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
                    0, 0,	
                    WindowRect.right-WindowRect.left,
                    WindowRect.bottom-WindowRect.top,
                    NULL,
                    NULL, hInstance, NULL) ;


// set the pixel format for the DC
PIXELFORMATDESCRIPTOR pfd;

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;


int	iFormat = ChoosePixelFormat(hDC, &pfd ); // exit if failure...
SetPixelFormat(hDC, iFormat, &pfd );
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);

you don’t need to adjust the window rect for a fullscreen window (it has no border nor titlebar), just send the rect directly in CreateWindow

you could put WNDCLASS and PIXELFORMATDESCRIPTOR in a union, as you never need both at the same time.
or allocate them at runtime, possibly that saves even more (again, with just one pointer )

oh, and the DEVMODE as well

Might be wrong about this, but since he declares those structs inside function defs, aren’t they allocated on the stack?

dunno… but i think you’re right…

Yes they are, unless you specify them as static.

I don’t think he’s worried about RAM footprint; I think he’s worried about executable (code/data) size.

I notice that he sets all the members with code. It might be better to make them initialized globals; that’ll probably save a bit on code size.

Even so, you’ll probably see a fair bit of exe size bloat. You’ll probably end up having to put the structures in BSS (0-initialized memory) and using some compressed version of the data that you un-compress at load time. One trick is to put all your needed global data structures in one big struct, and declare a global union between this struct and an array of char; makes it easy to compress and decompress. The linker will still generate absolute references when you do &myUnion.myBigStruct.myPixelFormatDescriptor;

This is (quite) the same code I use for 4k, but the best optimizations are done tuning the project settings (libraries and useless definitions) and the paying attention at the rest of the code. Do not loose time after the init code, this one it’s exact.

Contact me, I’ll be glad to share my 4k skeleton.
My smallest exe is about 3kb.

rIO.sK