10/25/07

Tiny OpenGL Windowing Code

Time for another framework update. Most of the framework stuff I have posted over on in4k was developed and optimised for dropper/apack. Last year hitchhiker released the first 1k using crinkler which is now the standard for 1ks (until Mentor releases a better compressor). So its time to update the OpenGL in a window framework code. Here it is. It opens an OGL window and also handles DEVMODE. I've added the DEVMODE bytes because shader performance varies so much on cards currently that its critical to control the screen size of the PC your into runs on. Besides, at 4k who would ever not use DEVMODE?

Tested under XP...Vista I don't know yet. If you try it, let me know OK?

So, Full screen, any resolution, ultra cheap GL window:


#include < windows.h >
#include < GL/gl.h >

static PIXELFORMATDESCRIPTOR pfd={
0, // Size Of This Pixel Format Descriptor... BAD coding, nothing new, saves 6 bytes
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 32, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0
};

static DEVMODE dmScreenSettings={
"",0,0,sizeof(dmScreenSettings),0,DM_PELSWIDTH|DM_PELSHEIGHT,
0,0,0,0,0,0,0,0,0,0,0,0,0,"",0,0,1024,768,0,0,0,0,0,0,0,0,0,0
};

void WINAPI WinMainCRTStartup()
{
ChangeDisplaySettings (&dmScreenSettings,CDS_FULLSCREEN);
HDC hDC = GetDC( CreateWindow("edit", 0, WS_POPUP|WS_VISIBLE|WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0) );
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, &pfd) , &pfd );
wglMakeCurrent ( hDC, wglCreateContext(hDC) );
ShowCursor(FALSE);
do {
// insert breakpoint winning 1k here
// pohar insert breakpoint winning 5k :-)
SwapBuffers(hDC);
} while ( !GetAsyncKeyState(VK_ESCAPE) );
}

2 comments:

  1. Anonymous26/10/07

    this one decreased a 4k intro filesize by ~30 byte for me, thx

    pohar

    ReplyDelete
  2. How does one give good Karma on your blog... :-)

    You rule.

    ReplyDelete