Skip to content

Commit fe107ab

Browse files
committed
Implement the OpenGL context on Windows
1 parent 2f7f177 commit fe107ab

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/win/window.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use winapi::um::winuser::{
1616
};
1717

1818
use std::cell::RefCell;
19-
use std::ffi::OsStr;
19+
use std::ffi::{c_void, OsStr};
2020
use std::marker::PhantomData;
2121
use std::os::windows::ffi::OsStrExt;
2222
use std::ptr::null_mut;
@@ -35,7 +35,7 @@ use crate::{
3535
use super::keyboard::KeyboardState;
3636

3737
#[cfg(feature = "opengl")]
38-
use crate::gl::GlContext;
38+
use crate::{gl::GlContext, window::RawWindowHandleWrapper};
3939

4040
unsafe fn generate_guid() -> String {
4141
let mut guid: GUID = std::mem::zeroed();
@@ -84,7 +84,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
8484
fn raw_window_handle(&self) -> RawWindowHandle {
8585
if let Some(hwnd) = self.hwnd {
8686
let mut handle = Win32Handle::empty();
87-
handle.hwnd = hwnd as *mut std::ffi::c_void;
87+
handle.hwnd = hwnd as *mut c_void;
8888

8989
RawWindowHandle::Win32(handle)
9090
} else {
@@ -483,8 +483,13 @@ impl Window {
483483
// todo: manage error ^
484484

485485
#[cfg(feature = "opengl")]
486-
let gl_context: Arc<Option<GlContext>> =
487-
Arc::new(todo!("Create the Windows OpenGL context"));
486+
let gl_context: Arc<Option<GlContext>> = Arc::new(options.gl_config.map(|gl_config| {
487+
let mut handle = Win32Handle::empty();
488+
handle.hwnd = hwnd as *mut c_void;
489+
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) };
490+
491+
GlContext::create(&handle, gl_config).expect("Could not create OpenGL context")
492+
}));
488493

489494
#[cfg(not(feature = "opengl"))]
490495
let handler = Box::new(build(&mut crate::Window::new(&mut Window { hwnd })));
@@ -583,7 +588,7 @@ impl Window {
583588
unsafe impl HasRawWindowHandle for Window {
584589
fn raw_window_handle(&self) -> RawWindowHandle {
585590
let mut handle = Win32Handle::empty();
586-
handle.hwnd = self.hwnd as *mut std::ffi::c_void;
591+
handle.hwnd = self.hwnd as *mut c_void;
587592

588593
RawWindowHandle::Win32(handle)
589594
}

src/x11/window.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use xcb::ffi::xcb_screen_t;
1111
use xcb::StructPtr;
1212

1313
use super::XcbConnection;
14-
use crate::window::RawWindowHandleWrapper;
1514
use crate::{
1615
Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, WindowEvent,
1716
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy,
@@ -20,7 +19,10 @@ use crate::{
2019
use super::keyboard::{convert_key_press_event, convert_key_release_event};
2120

2221
#[cfg(feature = "opengl")]
23-
use crate::gl::{platform, GlContext};
22+
use crate::{
23+
gl::{platform, GlContext},
24+
window::RawWindowHandleWrapper,
25+
};
2426

2527
pub struct WindowHandle {
2628
raw_window_handle: Option<RawWindowHandle>,

0 commit comments

Comments
 (0)