Platform-specific functions
Windows
These functions are declared in the following header file:
#include <allegro5/allegro_windows.h>
al_get_win_window_handle
HWND al_get_win_window_handle(ALLEGRO_DISPLAY *display)
Returns the handle to the window that the passed display is using.
Examples:
al_win_add_window_callback
bool al_win_add_window_callback(ALLEGRO_DISPLAY *display,
bool (*callback)(ALLEGRO_DISPLAY *display, UINT message, WPARAM wparam,
void *userdata), void *userdata) LPARAM lparam, LRESULT *result,
The specified callback function will intercept the window’s message before Allegro processes it. If the callback function consumes the event, then it should return true. In that case, Allegro will not do anything with the event.
Optionally, you may use result
to customize what Allegro will return return in response to this event. By default, Allegro returns TRUE
.
The userdata
pointer can be used to supply additional context to the callback function.
The callbacks are executed in the same order they were added.
Returns true if the callback was added.
Since: 5.1.2
al_win_remove_window_callback
bool al_win_remove_window_callback(ALLEGRO_DISPLAY *display,
bool (*callback)(ALLEGRO_DISPLAY *display, UINT message, WPARAM wparam,
void *userdata), void *userdata) LPARAM lparam, LRESULT *result,
Removes the callback that was previously registered with al_win_add_window_callback. The userdata
pointer must be the same as what was used during the registration of the callback.
Returns true if the callback was removed.
Since: 5.1.2
Mac OS X
These functions are declared in the following header file:
#include <allegro5/allegro_osx.h>
al_osx_get_window
NSWindow* al_osx_get_window(ALLEGRO_DISPLAY *display)
Retrieves the NSWindow handle associated with the Allegro display.
Since: 5.0.8, 5.1.3
iPhone
These functions are declared in the following header file:
#include <allegro5/allegro_iphone.h>
al_iphone_set_statusbar_orientation
void al_iphone_set_statusbar_orientation(int o)
Sets the orientation of the status bar, which can be one of the following:
- ALLEGRO_IPHONE_STATUSBAR_ORIENTATION_PORTRAIT
- ALLEGRO_IPHONE_STATUSBAR_ORIENTATION_PORTRAIT_UPSIDE_DOWN
- ALLEGRO_IPHONE_STATUSBAR_ORIENTATION_LANDSCAPE_RIGHT
- ALLEGRO_IPHONE_STATUSBAR_ORIENTATION_LANDSCAPE_LEFT
Since: 5.1.0
al_iphone_get_view
UIView *al_iphone_get_view(ALLEGRO_DISPLAY *display)
Retrieves the UIView* (EAGLView*) associated with the Allegro display.
Since: 5.1.0
al_iphone_get_window
UIWindow *al_iphone_get_window(ALLEGRO_DISPLAY *display)
Retrieves the UIWindow* associated with the Allegro display.
Since: 5.1.0
Android
These functions are declared in the following header file:
#include <allegro5/allegro_android.h>
al_android_set_apk_file_interface
void al_android_set_apk_file_interface(void)
This function will set up a custom ALLEGRO_FILE_INTERFACE that makes all future calls of al_fopen read from the applicatons’s APK file.
Note: Currently, access to the APK file after calling this function is read only.
Since: 5.1.2
Examples:
al_android_set_apk_fs_interface
void al_android_set_apk_fs_interface(void)
This function will set up a custom ALLEGRO_FS_INTERFACE which allows working within the APK filesystem. The filesystem root is your assets directory and there is read-only access to all files within.
Note: Some things like querying file size or attributes are not supported by this. You can always use the PhysFS addon to open the APK file (it is just a regular .zip file) and get more complete information.
Since: 5.1.13
Examples:
al_android_get_os_version
const char *al_android_get_os_version(void)
Returns a pointer to a static buffer that contains the version string of the Android platform that the calling Allegro program is running on.
Since: 5.1.2
al_android_get_jni_env
void) JNIEnv *al_android_get_jni_env(
Returns the Android JNI environment used by Allegro to call into Java. As a convenience this function provides it to the user so there is no need to obtain it yourself.
For example if you have a Java method “void send(String message)” in your activity class, you could call it like this from C code:
JNIEnv * env = al_android_get_jni_env();
jclass class_id = (* env)->GetObjectClass(env, al_android_get_activity());"send",
jmethodID method_id = (* env)->GetMethodID(env, class_id, "(Ljava/lang/String;)V");
"Hello Java!");
jstring jdata = (* env)->NewStringUTF(env,
(* env)->CallVoidMethod(env, al_android_get_activity(), method_id, jdata); (* env)->DeleteLocalRef(env, jdata);
Since: 5.2.2
Unstable API: This API is new and subject to refinement.
al_android_get_activity
void) jobject al_android_get_activity(
Returns the Java Android activity used by Allegro. This is the same object created by Android from the class you specify in your manifest and either an instance of AllegroActivity or a derived class.
Since: 5.2.2
Unstable API: This API is new and subject to refinement.
al_android_open_fd
int al_android_open_fd(const char *uri, const char *mode)
Opens a file descriptor to access data under a Universal Resource Identifier (URI). This function accepts content:// and file:// URI schemes. You are responsible for closing the returned file descriptor.
The file mode
can be "r"
, "w"
, "rw"
, "wt"
, "wa"
or "rwt"
. The exact implementation of these modes differ depending on the underlying content provider. For example, "w"
may or may not truncate.
Returns a file descriptor on success or a negative value on an error. On an error, the Allegro errno is set.
Note: Remember to add to your manifest file the relevant permissions to your app.
Example:
const char *content_uri = "content://...";
int fd = al_android_open_fd(content_uri, "r");
if (fd >= 0) {
"r");
ALLEGRO_FILE *f = al_fopen_fd(fd,
if (f != NULL) {
do_something_with(f);
al_fclose(f);
}else {
handle_error(al_get_errno());
close(fd);
}
}else {
handle_error(al_get_errno()); }
Since: 5.2.10
See also: al_fopen_fd, al_get_errno
Unstable API: This API is new and subject to refinement.
X11
These functions are declared in the following header file:
#include <allegro5/allegro_x.h>
al_get_x_window_id
XID al_get_x_window_id(ALLEGRO_DISPLAY *display)
Retrieves the XID associated with the Allegro display.
Since: 5.1.12
al_x_set_initial_icon
bool al_x_set_initial_icon(ALLEGRO_BITMAP *bitmap)
On some window managers (notably Ubuntu’s Unity) al_set_display_icon doesn’t work and you need to use a .desktop file. But with this function you can set an icon before calling al_create_display. This works by setting the icon before XMapWindow.
Since: 5.2.3
Unstable API: New API.
Examples: