Added DisplayMode and PixelFormat.
This commit is contained in:
parent
d7c1b47657
commit
c02ad6d7fb
33
display.go
33
display.go
@ -5,14 +5,43 @@ import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Display represents a display
|
||||
// Display represents a display.
|
||||
type Display struct {
|
||||
display *C.ALLEGRO_DISPLAY
|
||||
}
|
||||
|
||||
// DisplayMode contains information about a fullscreen display mode.
|
||||
type DisplayMode struct {
|
||||
Width int
|
||||
Height int
|
||||
Format PixelFormat
|
||||
RefreshRate int
|
||||
}
|
||||
|
||||
// DisplayMode returns all available fullscreen display modes.
|
||||
func DisplayModes() []DisplayMode {
|
||||
n := int(C.al_get_num_display_modes())
|
||||
var modes []DisplayMode
|
||||
var mode C.ALLEGRO_DISPLAY_MODE
|
||||
for i := 0; i < n; i++ {
|
||||
C.al_get_display_mode(C.int(i), &mode)
|
||||
modes = append(modes, DisplayMode{
|
||||
Width: int(mode.width),
|
||||
Height: int(mode.height),
|
||||
Format: PixelFormat(mode.format),
|
||||
RefreshRate: int(mode.refresh_rate),
|
||||
})
|
||||
}
|
||||
weight := func(m DisplayMode) int { return (m.Width*m.Height)*10000 + (m.RefreshRate * 100) + int(m.Format) }
|
||||
sort.Slice(modes, func(i, j int) bool { return weight(modes[i]) < weight(modes[j]) })
|
||||
return modes
|
||||
}
|
||||
|
||||
// NewDisplayOptions sets options for creating a new display.
|
||||
type NewDisplayOptions struct {
|
||||
Fullscreen bool
|
||||
Resizable bool
|
||||
@ -24,7 +53,7 @@ type NewDisplayOptions struct {
|
||||
OpenGL bool
|
||||
}
|
||||
|
||||
// NewDisplay creates a display
|
||||
// NewDisplay creates a display.
|
||||
func NewDisplay(width, height int, options NewDisplayOptions) (*Display, error) {
|
||||
var flags C.int = C.ALLEGRO_WINDOWED
|
||||
if options.Fullscreen {
|
||||
|
41
pixelformat.go
Normal file
41
pixelformat.go
Normal file
@ -0,0 +1,41 @@
|
||||
package allg5
|
||||
|
||||
// #include <allegro5/allegro.h>
|
||||
import "C"
|
||||
|
||||
// PixelFormat describes the components a pixel.
|
||||
type PixelFormat int
|
||||
|
||||
const (
|
||||
PixelFormatAny PixelFormat = C.ALLEGRO_PIXEL_FORMAT_ANY
|
||||
PixelFormatAnyNoAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA
|
||||
PixelFormatAnyAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA
|
||||
PixelFormatAny15NoAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_15_NO_ALPHA
|
||||
PixelFormatAny16NoAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_16_NO_ALPHA
|
||||
PixelFormatAny16Alpha = C.ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA
|
||||
PixelFormatAny24NoAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA
|
||||
PixelFormatAny32NoAlpha = C.ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA
|
||||
PixelFormatAny32Alpha = C.ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA
|
||||
PixelFormatARGB8888 = C.ALLEGRO_PIXEL_FORMAT_ARGB_8888
|
||||
PixelFormatRGBA8888 = C.ALLEGRO_PIXEL_FORMAT_RGBA_8888
|
||||
PixelFormatARGB4444 = C.ALLEGRO_PIXEL_FORMAT_ARGB_4444
|
||||
PixelFormatRGB888 = C.ALLEGRO_PIXEL_FORMAT_RGB_888
|
||||
PixelFormatRGB565 = C.ALLEGRO_PIXEL_FORMAT_RGB_565
|
||||
PixelFormatRGB555 = C.ALLEGRO_PIXEL_FORMAT_RGB_555
|
||||
PixelFormatRGBA5551 = C.ALLEGRO_PIXEL_FORMAT_RGBA_5551
|
||||
PixelFormatARGB1555 = C.ALLEGRO_PIXEL_FORMAT_ARGB_1555
|
||||
PixelFormatABGR8888 = C.ALLEGRO_PIXEL_FORMAT_ABGR_8888
|
||||
PixelFormatXBGR8888 = C.ALLEGRO_PIXEL_FORMAT_XBGR_8888
|
||||
PixelFormatBGR888 = C.ALLEGRO_PIXEL_FORMAT_BGR_888
|
||||
PixelFormatBGR565 = C.ALLEGRO_PIXEL_FORMAT_BGR_565
|
||||
PixelFormatBGR555 = C.ALLEGRO_PIXEL_FORMAT_BGR_555
|
||||
PixelFormatRGBX8888 = C.ALLEGRO_PIXEL_FORMAT_RGBX_8888
|
||||
PixelFormatXRGB8888 = C.ALLEGRO_PIXEL_FORMAT_XRGB_8888
|
||||
PixelFormatABGRF32 = C.ALLEGRO_PIXEL_FORMAT_ABGR_F32
|
||||
PixelFormatABGR8888LE = C.ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE
|
||||
PixelFormatRGBA4444 = C.ALLEGRO_PIXEL_FORMAT_RGBA_4444
|
||||
PixelFormatSingleChannel8 = C.ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8
|
||||
PixelFormatCompressedRGBADXT1 = C.ALLEGRO_PIXEL_FORMAT_COMPRESSED_RGBA_DXT1
|
||||
PixelFormatCompressedRGBADXT3 = C.ALLEGRO_PIXEL_FORMAT_COMPRESSED_RGBA_DXT3
|
||||
PixelFormatCompressedRGBADXT5 = C.ALLEGRO_PIXEL_FORMAT_COMPRESSED_RGBA_DXT5
|
||||
)
|
Loading…
Reference in New Issue
Block a user