aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-08-02 12:23:05 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-08-02 12:23:05 +0200
commit0152099c912785ea4d10b8672374e3ad9d79f317 (patch)
tree79711746fefd15ff03197318fff2f5ba3203eafd /src
parentb0d9d0b87f8884639001d69f3a79d4bb41f019f4 (diff)
downloadglutin-0152099c912785ea4d10b8672374e3ad9d79f317.tar.gz
glutin-0152099c912785ea4d10b8672374e3ad9d79f317.zip
Correctly handling pixel format and fullscreen resolution on Win32
Diffstat (limited to 'src')
-rw-r--r--src/win32/ffi.rs23
-rw-r--r--src/win32/init.rs32
2 files changed, 49 insertions, 6 deletions
diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs
index 73ade51..40dec56 100644
--- a/src/win32/ffi.rs
+++ b/src/win32/ffi.rs
@@ -193,6 +193,26 @@ pub static FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
// ?
pub static PFD_TYPE_RGBA: BYTE = 0;
pub static PFD_TYPE_COLORINDEX: BYTE = 1;
+pub static PFD_MAIN_PLANE: BYTE = 0;
+pub static PFD_OVERLAY_PLANE: BYTE = 1;
+pub static PFD_UNDERLAY_PLANE: BYTE = (-1);
+pub static PFD_DOUBLEBUFFER: DWORD = 0x00000001;
+pub static PFD_STEREO: DWORD = 0x00000002;
+pub static PFD_DRAW_TO_WINDOW: DWORD = 0x00000004;
+pub static PFD_DRAW_TO_BITMAP: DWORD = 0x00000008;
+pub static PFD_SUPPORT_GDI: DWORD = 0x00000010;
+pub static PFD_SUPPORT_OPENGL: DWORD = 0x00000020;
+pub static PFD_GENERIC_FORMAT: DWORD = 0x00000040;
+pub static PFD_NEED_PALETTE: DWORD = 0x00000080;
+pub static PFD_NEED_SYSTEM_PALETTE: DWORD = 0x00000100;
+pub static PFD_SWAP_EXCHANGE: DWORD = 0x00000200;
+pub static PFD_SWAP_COPY: DWORD = 0x00000400;
+pub static PFD_SWAP_LAYER_BUFFERS: DWORD = 0x00000800;
+pub static PFD_GENERIC_ACCELERATED: DWORD = 0x00001000;
+pub static PFD_SUPPORT_COMPOSITION: DWORD = 0x00008000;
+pub static PFD_DEPTH_DONTCARE: DWORD = 0x20000000;
+pub static PFD_DOUBLEBUFFER_DONTCARE: DWORD = 0x40000000;
+pub static PFD_STEREO_DONTCARE: DWORD = 0x80000000;
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
pub static SW_FORCEMINIMIZE: libc::c_int = 11;
@@ -638,6 +658,9 @@ extern "system" {
pub fn ChangeDisplaySettingsExW(lpszDeviceName: LPCWSTR, lpDevMode: *mut DEVMODE, hwnd: HWND,
dwFlags: DWORD, lParam: LPVOID) -> LONG;
+ // http://msdn.microsoft.com/en-us/library/dd318284(v=vs.85).aspx
+ pub fn ChoosePixelFormat(hdc: HDC, ppfd: *const PIXELFORMATDESCRIPTOR) -> libc::c_int;
+
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx
pub fn CreateWindowExW(dwExStyle: DWORD, lpClassName: LPCWSTR, lpWindowName: LPCWSTR,
dwStyle: DWORD, x: libc::c_int, y: libc::c_int, nWidth: libc::c_int, nHeight: libc::c_int,
diff --git a/src/win32/init.rs b/src/win32/init.rs
index efa27fd..d2aec5e 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -81,13 +81,14 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
// changing device settings
let mut screen_settings: ffi::DEVMODE = unsafe { mem::zeroed() };
screen_settings.dmSize = mem::size_of::<ffi::DEVMODE>() as ffi::WORD;
- screen_settings.dmPelsWidth = 1024;
- screen_settings.dmPelsHeight = 768;
- screen_settings.dmBitsPerPel = 32;
+ screen_settings.dmPelsWidth = (rect.right - rect.left) as ffi::DWORD;
+ screen_settings.dmPelsHeight = (rect.bottom - rect.top) as ffi::DWORD;
+ screen_settings.dmBitsPerPel = 32; // TODO: ?
screen_settings.dmFields = ffi::DM_BITSPERPEL | ffi::DM_PELSWIDTH | ffi::DM_PELSHEIGHT;
let result = unsafe { ffi::ChangeDisplaySettingsExW(monitor.get_system_name().as_ptr(),
&mut screen_settings, ptr::mut_null(), ffi::CDS_FULLSCREEN, ptr::mut_null()) };
+
if result != ffi::DISP_CHANGE_SUCCESSFUL {
tx.send(Err(format!("ChangeDisplaySettings failed: {}", result)));
return;
@@ -140,11 +141,30 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {
};
// getting the pixel format that we will use
- // TODO: use something cleaner which uses hints
let pixel_format = {
- let mut output: ffi::PIXELFORMATDESCRIPTOR = unsafe { mem::uninitialized() };
+ // initializing a PIXELFORMATDESCRIPTOR that indicates what we want
+ let mut output: ffi::PIXELFORMATDESCRIPTOR = unsafe { mem::zeroed() };
+ output.nSize = mem::size_of::<ffi::PIXELFORMATDESCRIPTOR>() as ffi::WORD;
+ output.nVersion = 1;
+ output.dwFlags = 0; // TODO: PFD_GENERIC_ACCELERATED? PFD_DOUBLEBUFFER? PFD_STEREO?
+ output.iPixelType = ffi::PFD_TYPE_RGBA;
+ output.cColorBits = 24;
+ output.cAlphaBits = 8;
+ output.cAccumBits = 0;
+ output.cDepthBits = 24;
+ output.cStencilBits = 8;
+ output.cAuxBuffers = 0;
+ output.iLayerType = ffi::PFD_MAIN_PLANE;
+
+ let pf_index = unsafe { ffi::ChoosePixelFormat(dummy_hdc, &output) };
+
+ if pf_index == 0 {
+ tx.send(Err(format!("ChoosePixelFormat function failed: {}",
+ os::error_string(os::errno() as uint))));
+ return;
+ }
- if unsafe { ffi::DescribePixelFormat(dummy_hdc, 1,
+ if unsafe { ffi::DescribePixelFormat(dummy_hdc, pf_index,
mem::size_of::<ffi::PIXELFORMATDESCRIPTOR>() as ffi::UINT, &mut output) } == 0
{
tx.send(Err(format!("DescribePixelFormat function failed: {}",