-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Context an opaque type and add a (stupid) example
- Loading branch information
1 parent
54b68a2
commit 60e1efc
Showing
7 changed files
with
84 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <SFML/Window/Context.hpp> | ||
#include <cstdint> | ||
|
||
extern "C" sf::Context *sfContext_new(void) { | ||
return new sf::Context; | ||
} | ||
|
||
extern "C" void sfContext_del(sf::Context *context) { | ||
delete context; | ||
} | ||
|
||
extern "C" bool sfContext_setActive(sf::Context *context, bool active) { | ||
return context->setActive(active); | ||
} | ||
|
||
extern "C" const sf::ContextSettings *sfContext_getSettings(const sf::Context *context) { | ||
return &context->getSettings(); | ||
} | ||
|
||
extern "C" uint64_t sfContext_getActiveContextId() { | ||
return sf::Context::getActiveContextId(); | ||
} | ||
|
||
extern "C" const sf::Context *sfContext_getActiveContext() { | ||
return sf::Context::getActiveContext(); | ||
} | ||
|
||
extern "C" sf::GlFunctionPointer sfContext_getFunction(const char *name) { | ||
return sf::Context::getFunction(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use sfml::{window::Context, SfResult}; | ||
|
||
fn main() -> SfResult<()> { | ||
// We have no active context, so this should be null | ||
assert_eq!(Context::active_context(), std::ptr::null()); | ||
{ | ||
// Let's create a context | ||
let mut ctx = Context::new()?; | ||
// I guess the active context should now be the same as what we have | ||
assert_eq!(Context::active_context(), &*ctx); | ||
eprintln!("Active context id: {}", Context::active_context_id()); | ||
let settings = ctx.settings(); | ||
eprintln!("Settings of created context: {settings:#?}"); | ||
ctx.set_active(false)?; | ||
// Deactivated context, so this should be null | ||
assert_eq!(Context::active_context(), std::ptr::null()); | ||
eprintln!("Active context id: {}", Context::active_context_id()); | ||
ctx.set_active(true)?; | ||
// Activated once again | ||
assert_eq!(Context::active_context(), &*ctx); | ||
eprintln!("Active context id: {}", Context::active_context_id()); | ||
} | ||
// Once again, no active context, so this should be null | ||
assert_eq!(Context::active_context(), std::ptr::null()); | ||
// Try to query a random OpenGL function | ||
dbg!(Context::get_function(c"glWhatever")); | ||
eprintln!("Okay then... Goodbye!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters