/*
makes up a list of all valid display-modes
*/
void win_makeup_modes( void )
{
display_mode_t *new_mode;
DEVMODE test_mode;
int mode_num = 0;
con_printf( "
fetching all valid display modes…" );
while( EnumDisplaySettings( NULL, mode_num, &test_mode ) )
{
if( ChangeDisplaySettings( &test_mode, CDS_TEST ) == DISP_CHANGE_SUCCESSFUL ) {
new_mode = (display_mode_t*) malloc( sizeof( display_mode_t ) );
new_mode->height = test_mode.dmPelsHeight;
new_mode->width = test_mode.dmPelsWidth;
new_mode->bpp = test_mode.dmBitsPerPel;
new_mode->mode_num = mode_num;
new_mode->next = root_display;
root_display = new_mode;
}
mode_num++;
}
con_printf( " found %u modes", mode_num );
return;
}
void win_create_glwindow( void )
{
WNDCLASSEX window_class;
int width, height, bpp, fullscreen;
get_data_from_var( current_disp_settings, &width, &height, &bpp, &fullscreen );
// Register my Window classes
app_instance = GetModuleHandle( NULL );
memset( &window_class, 0, sizeof(WNDCLASSEX) );
window_class.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; //Fensterstile
window_class.lpfnWndProc = win_winproc; //Fensterprozedur
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = app_instance;
window_class.hIcon = LoadIcon( app_instance, NULL); //Icons aus der Resourcedatei laden
window_class.hCursor = LoadCursor(NULL, IDC_ARROW); //Mauszeiger laden
window_class.hbrBackground = NULL; //Hintergrundfarbe festlegen
window_class.lpszClassName = “win_class”; //Klassenname festlegen
window_class.cbSize = sizeof( WNDCLASSEX );
if ( !RegisterClassEx(&window_class) ) { //Haupt-Fensterklasse registrieren
MessageBox(NULL, “Error: Unable to register window-class”, “Fehler”, MB_OK);
return;
}
if( fullscreen ) {
window_handle = CreateWindow(
“win_class”, //Klassenname
“ConsoleNT - fullscreen”, //Titel
WS_POPUPWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
0, 0, //Position der linken oberen Ecke
width, height, //Breite, Höhe
NULL, //Kein Parent
NULL, //Kein Child
app_instance, //Instanz
NULL
);
} else {
window_handle = CreateWindow(
“win_class”, //Klassenname
“ConsoleNT - windowed”, //Titel
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
0, 0, //Position der linken oberen Ecke
width+8, height+26, //Breite, Höhe
NULL, //Kein Parent
NULL, //Kein Child
app_instance, //Instanz
NULL
);
}
if( !window_handle ) MessageBox( NULL, “Fehler!”, “Fehler”, MB_OK );
PIXELFORMATDESCRIPTOR desired_format = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
bpp, // 16-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
16, // 16-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, 0, 0 // 0 , reserved, layer masks ignored
};
int context_num;
window_context = GetDC( window_handle );
context_num = ChoosePixelFormat( window_context, &desired_format );
if( !context_num ) {
con_printf( "
Unable to find matching pixel-format" );
return;
}
SetPixelFormat( window_context, context_num, &desired_format);
opengl_context = wglCreateContext( window_context );
if( !opengl_context ) {
con_printf( "
wglCreateContext() failed" );
}
if( !wglMakeCurrent( window_context, opengl_context ) ) {
con_printf( "
wglMakeCurrent() failed" );
}
ShowWindow( window_handle, SW_SHOW );
SetForegroundWindow( window_handle );
SetFocus( window_handle );
}
void win_destroy_glwindow( void )
{
DestroyWindow( window_handle );
UnregisterClass( “win_class”, app_instance );
wglMakeCurrent( NULL, NULL );
wglDeleteContext( opengl_context );
ReleaseDC( window_handle, window_context );
DestroyWindow( window_handle );
UnregisterClass(“win_class”,app_instance);
}