PDA

View Full Version : OpenGL Windows Init more simple



KILE
08-26-2002, 10:45 AM
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. http://www.opengl.org/discussion_boards/ubb/wink.gif
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_PELSWID TH|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);

davepermen
08-26-2002, 10:58 AM
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

davepermen
08-26-2002, 11:00 AM
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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif)

oh, and the DEVMODE as well http://www.opengl.org/discussion_boards/ubb/biggrin.gif

t0y
08-26-2002, 11:33 AM
Might be wrong about this, but since he declares those structs inside function defs, aren't they allocated on the stack?

davepermen
08-26-2002, 11:34 AM
dunno.. but i think you're right..

Humus
08-26-2002, 02:38 PM
Yes they are, unless you specify them as static.

jwatte
08-26-2002, 06:43 PM
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;

rIO
08-27-2002, 05:03 AM
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