Jump to content

Graphics Overview: Difference between revisions

From OpenBOR
Hardware render update.
Line 1: Line 1:
OpenBOR uses a software-composited graphics system designed primarily for sprite-based games. Images, background layers, entities, text, primitive shapes, and scripted subscreens are collected into a drawing queue, ordered by layer, rendered into a 32-bit logical screen, and finally presented by the platform video backend.
== Introduction ==


This arrangement separates game graphics from the physical display. Creators define the logical resolution and visual composition of a project, while OpenBOR handles window sizing, fullscreen scaling, aspect ratio, filtering, and final presentation.
OpenBOR uses hardware rendering to draw and composite sprites, background layers, text, primitive shapes, subscreens, movie images, and mesh-map artwork. The GPU renders these graphics into a full-color logical screen, applies the selected output effects, and presents the result on the display.


The basic pipeline is:<pre>
Creators supply artwork and control positions, drawing layers, palettes, and effects through native settings or scripts. The CPU handles gameplay, asset decoding, drawing commands, sorting, and geometry preparation. The GPU handles image sampling, palette lookup, pixel composition, blending, and rendered output. Desktop versions use OpenGL, while Android uses OpenGL ES 3.0 or newer.
Source images and generated graphics
 
                |
Main scenes and script-created screens use RGB32 color. Indexed source artwork remains useful for palette selection and remapping, and the GPU resolves those indices into the full-color scene. The finished image is not restricted to one shared 256-color palette.
                v
 
      Load, trim, and cache assets
The module's logical resolution determines its drawing area. Window size, fullscreen fitting, and display filters determine how that finished composition appears on the physical display. See [[#Resolution|Resolution]] and [[#Resampling and Display Filters|Resampling and Display Filters]].
                |
                v
      Build the sprite drawing queue
                |
                v
        Sort by layer and sort ID
                |
                v
Compose into the 32-bit logical screen
                |
                v
Optional software scaling or filtering
                |
                v
Present through SDL or OpenGL backend
</pre>


== Source Graphics ==
== Source Graphics ==
Regular OpenBOR graphics use PNG images. Character frames and most other sprites normally use non-interlaced indexed PNG files. Indexed images allow palette replacement and efficient storage while the finished display is rendered in full color.


True-color PNG images are also supported for backgrounds and background layers.
Image requirements depend on the resource being loaded. Ordinary sprites use non-interlaced, 8-bit indexed PNG images. Primary backgrounds and mesh artwork also have true-color image paths. Separate companion images can supply opacity or drawing-depth data.
 
{| class="wikitable"
{| class="wikitable"
!Graphic type
!Graphic type
!Recommended format
!Source format
!Notes
!Use
|-
|-
|Character and entity sprites
|Character and entity sprites
|Indexed PNG
|Non-interlaced, 8-bit indexed PNG
|Supports palettes, remaps, and automatic transparent-border trimming.
|Animation frames, model palettes, remaps, and sprite effects.
|-
|-
|Icons, fonts, and interface sprites
|Icons, fonts, and interface sprites
|Indexed PNG
|Non-interlaced, 8-bit indexed PNG
|Drawn through the same sprite system as other graphic elements.
|Sprite-based interface elements and text glyphs.
|-
|Ordinary stage layers and panels
|Non-interlaced, 8-bit indexed PNG
|Layer artwork loaded through the regular sprite or indexed-screen path.
|-
|Primary background image
|Indexed PNG or true-color RGB PNG
|The main background image. Indexed backgrounds can also establish the global palette.
|-
|Mesh-map artwork
|8-bit indexed or 24-bit RGB PNG
|Texture applied to a mesh surface through its dedicated artwork loader. See [[Mesh Map]].
|-
|Alpha mask
|Non-interlaced, 8-bit grayscale or indexed PNG
|Per-pixel opacity data supplied separately from sprite artwork.
|-
|-
|Backgrounds and stage layers
|Drawing-depth mask
|Indexed or true-color PNG
|Single-channel, 16-bit grayscale PNG
|Indexed backgrounds may provide the module palette. True-color backgrounds are loaded through the 32-bit image path.
|Per-pixel drawing-Z adjustments for sprites, screens, or mesh artwork.
|-
|-
|Animated cutscenes
|Animated cutscene image
|Animated GIF
|Animated GIF
|Played through the cutscene system. GIF is not a general-purpose sprite format.
|Animated image playback through the cutscene and GIF systems.
|-
|Movie
|WebM containing VP8 video and optional Vorbis audio
|Movie playback into a screen or directly to the display. See [[Movie Player]].
|}
|}
Transparent borders surrounding a sprite are trimmed when the image is loaded. OpenBOR preserves the original alignment by recording the trimmed offset, so creators do not normally need to crop every frame manually.


Previously loaded sprites are cached and may share encoded image data when the same source image is used with different offsets.
Save ordinary indexed artwork with an actual 8-bit PNG sample depth. Images containing only a few colors can still be saved by an editor as a 1-, 2-, or 4-bit indexed PNG, which does not meet the regular sprite loader's format requirement.
 
The sprite loader trims transparent borders and records the resulting offsets to preserve alignment. Keep matching alpha and depth companions aligned to the original source canvas. Previously loaded artwork can be reused, including shared image data drawn with different offsets or palettes.
 
=== Indexed Sprites and Palettes ===
 
Indexed sprites store color indices, while palettes assign an RGB color to each index. The GPU uses the selected palette when drawing the image. Changing a color set can therefore reuse the same sprite artwork instead of requiring another image for every character or costume variation.
 
Models can have their own palettes and alternate color sets. Frames can also retain their own palettes where the model configuration permits it. Palette selection, remapping, tinting, and channel controls remain available within hardware rendering.
 
Palette index zero supplies ordinary sprite cutout transparency. Separate alpha masks and drawmethod settings provide additional control over opacity and blending. The regular sprite path uses image indices and palette data; embedded PNG transparency metadata does not replace these controls.


=== True-Color Sprites ===
=== True-Color Sprites ===
OpenBOR is intentionally designed to render individual sprites using indexed color. This compact representation is one reason its software-driven graphics pipeline can withstand immense sprite loads without frame-rate loss. Indexed sprites also provide efficient palette replacement, remapping, tinting, and color-channel manipulation.


When RGB color is required, OpenBOR can produce a true-color image by compositing a meta-sprite from three indexed sprites:
The standard animation-frame and <code>loadsprite()</code> paths use indexed source images. Full-color output is available through primary RGB backgrounds, RGB mesh artwork, subscreens, and compositions of multiple images.
 
For artwork assembled from indexed components, creators can combine aligned red, green, and blue channel images using drawmethod channel controls and blending. This is an optional composition technique for producing an RGB result from indexed sprite parts. The components use the same GPU drawing pipeline as other sprites.


* Red channel.
See [[Drawmethod]] for palette selection, color channels, opacity, and blending controls.
* Green channel.
* Blue channel.


Each component is drawn at the same position using the corresponding channel drawmethod. OpenBOR composites the red, green, and blue components into the final true-color image during normal rendering.
== Graphics Pipeline ==


'''Note:''' OpenBOR's software renderer is an artifact of an earlier console portability policy that has since been discontinued. Hardware-accelerated rendering and direct RGBA sprite support are currently in development.
The normal scene pipeline has five stages:


== Graphics Pipeline ==
{| class="wikitable"
!Stage
!Operation
|-
|Asset preparation
|Decode source files, preserve sprite alignment, and prepare reusable image and palette resources.
|-
|Drawing commands
|Native systems and scripts select images, geometry, positions, drawing layers, materials, and destination screens.
|-
|Ordering
|Sort queued entries by drawing layer and sort ID, retaining submission order for equal keys.
|-
|GPU composition
|Render into the logical screen or a subscreen with the selected transforms, sampling, colors, opacity, blending, and drawing depth.
|-
|Display presentation
|Apply the selected final-image effect, display scaling, and color adjustments before presenting the completed frame.
|}


=== Asset Loading ===
=== Asset Loading ===
OpenBOR decodes source images and converts them into an internal bitmap, sprite, or screen representation.


Sprites are trimmed and encoded for repeated drawing. Background images remain screen-like rectangular buffers. Indexed graphics retain palette information needed for palette replacement and other color effects.
OpenBOR decodes images into the source representation appropriate to the loader. Indexed sprites retain their indices and palette information; RGB images supply full-color pixels. GPU image and palette resources are cached for reuse.
 
Loading, decoding, and preparing an asset are separate from repeatedly drawing it. Normal scene rendering reuses the prepared resources. Palette changes can reuse an indexed image while changing the colors selected during drawing.


=== Drawing Queue ===
=== Drawing Queue ===
Game objects do not normally draw themselves directly to the physical display. Instead, OpenBOR submits drawing entries to the sprite queue.


Queue entries may include:
Native scene elements and ordinary script drawing submit commands to the sprite queue. Commands identify what to draw and how to draw it; they do not require creators to manage GPU textures or issue graphics-API calls.
 
Queued elements include:


* Sprites and animation frames.
* Sprites and animation frames.
* Background layers.
* Background and foreground layers.
* Text glyphs.
* Dots, lines, and boxes.
* Subscreens.
* Subscreens.
* Text glyphs.
* Textured mesh-map surfaces.
* Dots.
 
* Lines.
The queue holds up to 5,000 entries. Queued text normally contributes one entry per glyph. Entries submitted after the queue is full are not drawn. When a completed subscreen is submitted, that screen occupies one queue entry regardless of how many elements were composed into it.
* Boxes.


The queue supports up to 5000 entries. Text is also composed from sprites, so every displayed character contributes to the queue total. Entries submitted after the limit is reached are not drawn.
Scripts can also draw directly into a subscreen. See [[#Subscreens|Subscreens]].


=== Layer Sorting ===
=== Layer Sorting ===
Each queued item has a drawing layer, internally represented by its queue Z value. Items with lower values are drawn first, while items with higher values are drawn later and therefore appear in front.


When two items have the same layer, OpenBOR uses a secondary sort ID to determine their order.<pre>
Each queued item has a drawing layer, represented by its drawing-Z value. Under ordinary layer ordering, lower values are drawn first and higher values appear in front. Drawing depth is independent of the screen position where an image appears.
Lower layer
 
    |
OpenBOR sorts by drawing Z, then by the item's sort ID. Entries with equal values for both retain their submission order. Use explicit drawing layers to establish intentional foreground, background, and interface relationships.
    | Background scenery
 
    | Stage objects
Depth companions can adjust this priority for individual pixels. The original drawing layer remains the baseline, and the companion supplies the pixel's adjustment. See [[#Drawing Depth|Drawing Depth]].
    | Entities and effects
 
    | HUD and interface
=== GPU Composition ===
    v
Higher layer
</pre>This provides object-level Z ordering suitable for a game world with foreground and background depth.  


'''Tip:''' Use explicit layer adjustments for effects that must reliably appear in front of or behind another object. Submission order alone should not be treated as a substitute for layer control.
The GPU draws the ordered graphics into an RGB32 target. Main scenes and subscreens use the same rendering system. Shader operations perform palette lookup, image reconstruction, color effects, transparency, blending, and depth comparison where configured.


=== Software Composition ===
Transforms control the shape and placement submitted for drawing. Some effects use CPU-prepared geometry or sampling information, while the GPU renders the resulting pixels. Mesh artwork, curved images, sprites, and screens can use the shared material and sampling controls appropriate to their drawing paths.
Once sorted, the queue is rendered into OpenBOR's logical screen. The main logical screen is a 32-bit software buffer with the width and height selected by the module.


Draw effects, palette conversion, blending, transformations, clipping, and subscreen composition occur during this stage.
The rendered scene normally remains in GPU storage for further composition and presentation. Drawing one subscreen into another, copying a screen, or reusing a captured composition can therefore remain within the GPU renderer. Explicit pixel reads and other operations that need a CPU-visible image synchronize the relevant screen when required.


=== Final Presentation ===
=== Final Presentation ===
After composition, OpenBOR passes the finished logical screen to the platform video backend. The backend may perform color conversion, software filtering, texture upload, display scaling, brightness adjustment, and final presentation.


SDL and OpenGL are presentation backends. Core sprite composition remains software based.
After scene composition, the selected Final Filter can process the completed image. The display stage then fits that result to the window or device display, applies its scaling filter and color adjustments, and presents the frame.


This distinction is important:
These operations use the GPU. SDL provides platform, window, and graphics-context integration; it is not a separate software scene compositor selected from the video menu.


* Increasing the '''logical resolution''' provides more space and potential detail to the game.
Display presentation preserves the module's logical drawing coordinates. Enlarging the window changes the displayed size of the finished image. Changing the logical resolution changes the drawing area available to the game.
* Increasing the '''window or output size''' enlarges the finished image without changing the game's logical coordinate system.
* Display filtering changes how the enlarged image appears but does not add new source detail.


== Draw Effects ==
== Draw Effects ==
Drawmethod is the common collection of properties OpenBOR uses to alter an item while drawing it. Entities, animation frames, stage layers, scripted sprites, and subscreens can expose some or all of these properties.
 
Drawmethod is the shared collection of properties used to modify an image while drawing it. Entities, animation frames, stage layers, scripted sprites, screens, and mesh artwork expose the properties relevant to their drawing paths.
 
{| class="wikitable"
{| class="wikitable"
!Effect group
!Effect group
Line 128: Line 155:
|-
|-
|Palette and color set
|Palette and color set
|Replace an indexed sprite's palette or select one of the model's available color sets.
|Select or replace the palette used to resolve indexed artwork.
|-
|-
|Blend
|Opacity and blending
|Apply transparency and supported blend modes, including alpha, negative alpha, overlay, hard light, dodge, and average blending.
|Control transparency and use blend modes such as alpha, negative alpha, overlay, hard light, dodge, and average blending.
|-
|-
|Tint and channels
|Tint and channels
|Tint an image, reduce individual red, green, or blue channels, or fill visible pixels with a specified color.
|Tint an image, adjust individual red, green, and blue channels, or fill covered pixels with a selected color.
|-
|-
|Orientation
|Chroma and Substitute
|Flip an image horizontally or vertically.
|Select colors for chroma coverage rules or replace matching final-output colors.
|-
|-
|Scale
|Placement and orientation
|Resize an image independently along its horizontal and vertical axes.
|Flip, scale, rotate, shear, or position an image with an affine transform.
|-
|-
|Rotation
|Clipping and repetition
|Rotate an image around its drawing center.
|Restrict destination coverage or repeat supported images with configurable spacing.
|-
|-
|Shift
|Water and plane effects
|Skew the image horizontally.
|Apply wave displacement and perspective-plane transformations.
|-
|-
|Clipping
|Curved surfaces
|Restrict drawing to a rectangular area.
|Bend an image into a configurable curve with tilt, perspective, and texture scrolling.
|-
|-
|Repetition
|Resampling
|Repeat supported layers or screens with configurable spacing.
|Choose how source pixels are reconstructed after scaling or transformation.
|-
|-
|Water and plane transformation
|Drawing depth
|Apply sine-wave distortion, shear, and perspective-like scaling effects.
|Adjust per-pixel drawing priority with a depth companion and an optional range override.
|}
|}
Drawmethod effects are evaluated by the software renderer. Transforming a large image or full-screen buffer is consequently more expensive than transforming a small sprite.


Not every drawing item supports every property in the same way. Some effects also select different drawing paths and may not combine meaningfully with every other effect.
The GPU performs the rendered pixel operations selected by these controls. Geometry modes have their own combination rules, so select the intended transform path and combine its supported material effects. See [[Drawmethod]] for commands, properties, defaults, and examples.
 
=== Alpha Masks ===
 
Alpha masks provide per-pixel control over an image's contribution to the destination. The GPU samples the mask with the artwork and uses it during composition. Masked sprites can therefore contain fully visible, partially blended, and transparent regions within one image.
 
Masks are useful for soft edges, dissolves, selective highlights, reflections, lighting effects, and localized reveals. Combine them with drawmethods and subscreens to build the desired appearance.
 
The alpha mask is separate from the sprite's palette and from its drawing-depth companion. See [[Drawmethod]] for the mask format, interpretation, and assignment rules.


For property-level documentation and script access, see [[Drawmethod]].
=== Drawing Depth ===


=== Alpha Masks ===
Drawing-depth companions let different portions of one sprite, screen, or mesh texture appear in front of or behind other drawing. For example, a wall image can contain a far portion that actors cover and a near portion that covers those actors.
Alpha masks provide pixel-level control over blending. Instead of applying one transparency value uniformly across an entire sprite or screen, a mask determines the blending treatment of individual pixels.


This enables effects such as:
Each sample in the 16-bit grayscale companion supplies an adjustment to the draw's existing Z. The GPU compares the resulting per-pixel values within the applicable depth pass; greater drawing Z takes priority. The default mapping treats sample 32768 as zero adjustment, with lower samples supplying negative adjustments and higher samples supplying positive adjustments. Drawmethod can override the adjustment range.


* Soft or irregular transparency.
Ordinary queued drawing uses depth composition automatically when a companion is present. Immediate composition into a subscreen can use an explicit depth pass. Opaque and fully covered cutout pixels test and write depth; partially covered or blended pixels retain ordered composition while testing against depth.
* Dissolves and materialization effects.
* Selective reflections and highlights.
* Layered lighting and shadow masks.
* Complex silhouettes and partial reveals.
* Localized blending across sprites, backgrounds, or subscreens.


Combined with drawmethods, color channels, and subscreen composition, alpha masks provide many effects ordinarily associated with a shader-driven graphics pipeline.
Depth companions control drawing priority. Mesh geometry controls physical terrain and collision. See [[Drawmethod]] for drawing-depth authoring and [[Mesh Map]] for mesh geometry, textures, and their depth companions.


== Subscreens ==
== Subscreens ==


OpenBOR includes the ability to allocate self-contained 32-bit drawing surfaces called [[subscreens]].
Subscreens are script-owned RGB32 drawing surfaces. Creators can assemble sprites, text, primitives, captured queue layers, movies, and mesh artwork into a screen, then draw that screen as one image in another screen or the main scene.
 
Normal subscreen composition and reuse are GPU operations. Screens support drawing effects, filtering, and transformations, making them useful for custom interfaces, picture-in-picture views, split-screen layouts, mirrors, cached compositions, and localized effects.
 
Reuse a screen while its dimensions and purpose remain appropriate. Drawing a composed screen avoids rebuilding its contents when those contents have not changed. Reading its rendered pixels for script inspection can require synchronization with CPU-visible storage, so perform those reads when the values are actually needed.
 
See [[Subscreens]] for allocation, immediate drawing, queue capture, composition, ownership, and examples.
 
== Movies and Animated Images ==


Creators may assemble sprites, text, primitive shapes, captured queue layers, and other generated graphics independently, then insert the completed surface into the main drawing queue as a single item.
OpenBOR supports animated GIF playback and a WebM movie system. GIF decoding produces indexed image data that the GPU resolves through palettes and composes into a retained screen. WebM movies use VP8 video with optional Vorbis audio; the GPU performs video color conversion, resampling, and composition after decoding.


This makes subscreens useful for picture-in-picture displays, mirrors, custom interfaces, cached compositions, localized effects, cutscenes, perspective transformations, and other advanced rendering techniques. See [[Subscreens]] for allocation, direct drawing, queue capture, composition, drawmethod effects, lifecycle management, and examples.
Movies can be drawn into an RGB32 screen and participate in a composed scene, or use direct display presentation. Movies composed into the game scene receive that scene's final-image effect. Direct movie presentation has its own display path. See [[Movie Player]] for loading, playback control, drawing destinations, and supported formats.


== Resolution ==
== Resolution ==
OpenBOR distinguishes the module's logical resolution from the final display resolution.
 
Logical resolution and display resolution serve different purposes. Choose the logical resolution for the game's artwork, camera, and interface, then use display settings to fit the result to the player's screen.


=== Logical Resolution ===
=== Logical Resolution ===
The video setting in data/video.txt selects the width and height of the logical screen.


OpenBOR provides the following compatibility presets:
The <code>video</code> setting in <code>data/video.txt</code> selects the width and height of the main logical screen. The following presets are available:
 
{| class="wikitable"
{| class="wikitable"
!Mode
!Mode
Line 217: Line 254:
|960 × 540
|960 × 540
|}
|}
Example:<pre>
 
For the 960 × 540 preset:
 
<syntaxhighlight lang="text">
video 6
video 6
</pre>Custom logical resolutions use a width and height separated by a lowercase x:<pre>
</syntaxhighlight>
 
Custom dimensions use a width and height separated by a lowercase <code>x</code>:
 
<syntaxhighlight lang="text">
video 1280x720
video 1280x720
</pre>Preset resolutions are compatibility conveniences rather than graphical capability tiers. Custom dimensions allow projects to target widescreen, portrait, low-resolution pixel art, or other layouts.
</syntaxhighlight>


'''Note:''' Use widths divisible by four. OpenBOR's screen allocator aligns screen widths downward to a multiple of four.
Presets are convenient size selections. Custom dimensions support other landscape, portrait, or pixel-art layouts. Requested screen widths are preserved, including odd widths. Main screens and subscreens use RGB32; the <code>colourdepth</code> setting does not select a different scene format.


No single practical maximum resolution applies to every platform. Available memory, CPU performance, display backend texture limits, optional filter requirements, and target hardware all affect the usable size. Extremely large logical resolutions should therefore be tested on every supported platform.
When present on Windows or Linux, <code>data/videopc.txt</code> takes precedence over <code>data/video.txt</code>.


=== Display Resolution ===
=== Display Resolution ===
Window and fullscreen settings determine how the logical screen is presented. OpenBOR can enlarge or reduce the finished frame independently of the module's internal coordinates.


Display options include:
Window and device display settings determine how the finished logical image is presented. Desktop Window Scale ranges from 0.25× through 8× in quarter steps. Android provides Automatic fitting or a centered Display Scale. Fullscreen and automatic fitting can preserve the image's aspect ratio or stretch it to the available display area.
 
Preserving aspect ratio can leave unused borders where the logical and physical displays have different shapes. Stretching fills the selected display area and changes the image's proportions.


* Windowed or fullscreen output.
For example, a 320 × 240 scene at 4× window scale occupies 1280 × 960 display pixels while retaining its 320 × 240 logical drawing area. The final-image filter can change the appearance of that output without changing the scene coordinates or requesting another increase in window size.
* Adjustable window scaling.
* Preserved aspect ratio or stretching to the available display.
* Nearest-neighbor or linear presentation scaling, depending on backend and selected settings.
* Optional 2× software filters, including simple scaling, bilinear filtering, AdvanceMAME, scanlines, television simulation, and dot-matrix effects.
* SDL or OpenGL presentation where supported.


Preserving aspect ratio may produce unused borders when the logical and physical displays have different shapes. Stretching fills the display but may distort the image.
== Resampling and Display Filters ==


'''Tip:''' Select logical resolution according to the project's artwork, camera, interface, and target hardware. Use final display scaling to fit different monitors instead of rebuilding the game around every possible desktop resolution.
OpenBOR provides three separate controls for image reconstruction and filtering. Each operates at a different stage:
 
{| class="wikitable"
!Control
!What it affects
!Choices
|-
|Drawmethod resampling
|Individual images while they are drawn into a scene or subscreen.
|Nearest by default; Bilinear; cubic Catmull-Rom, Mitchell, and B-spline; Lanczos 2 and 3.
|-
|Final Filter
|The completed game scene before display scaling.
|Disabled, Bilinear, Advance Mame2x, Scanlines, Scanlines TV, TV 2x, or Dot Matrix.
|-
|Scaling Filter
|Sampling while fitting the completed image to the display.
|Nearest, Bilinear, or High Quality.
|}
 
Drawmethod resampling gives creators control over particular objects. Nearest preserves hard source-pixel boundaries. Other modes reconstruct the image from neighboring samples and can suit scaled, rotated, curved, or perspective artwork. The choice belongs to that drawing operation; display settings do not replace it.
 
Final Filter applies an appearance to the whole scene. Enabled final effects produce a GPU image at twice the logical width and height, then that result is fitted to the selected display size. On desktop, a selected final effect is active in fullscreen or when the window scale is at least 2×. Below that window scale, the selection remains stored but inactive. Android applies the selected effect through its scene presenter.
 
Scaling Filter controls the final fit. Nearest retains hard pixel edges, Bilinear interpolates adjacent pixels, and High Quality uses sharp-bilinear sampling to retain sharper pixel interiors while smoothing transitions during display scaling.
 
The Bilinear choices in Final Filter and Scaling Filter are separate controls. Final Filter selects a completed-scene effect; Scaling Filter selects display sampling. Neither changes the logical resolution. See [[Drawmethod]] for per-object resampling.


== Performance Considerations ==
== Performance Considerations ==
Graphics cost generally increases with the number of pixels processed, the number of queued items, and the complexity of effects applied to them.


For efficient rendering:
Hardware rendering makes transforms, palette effects, filtering, and subscreen composition part of the normal drawing pipeline. Useful authoring decisions still include resource reuse, the amount of image coverage, and how often scripts need to inspect rendered pixels.


* Choose a logical resolution appropriate for the artwork.
* Reuse loaded sprites and palettes when the artwork is unchanged. Use palette variation for color changes that do not require different shapes.
* Reuse subscreens rather than repeatedly allocating them.
* Retain and reuse subscreens. Rebuild cached compositions when their contents change.
* Keep temporary subscreens close to the required dimensions.
* Size temporary screens for the composition they need to hold.
* Avoid applying full-screen transformations when a smaller affected region is sufficient.
* Choose object resampling for the artwork and its transformation, independently of the final scene effect and display scaling.
* Remember that text consumes sprite queue entries.
* Use GPU drawing operations to assemble effects and inspect screen pixels when the script needs their values.
* Use explicit drawing layers instead of relying on incidental queue order.
* Account for queued text glyphs and other entries when building a complex interface. Subscreens can hold reusable interface compositions.
* Test blending, rotation, water effects, and multiple subscreens on lower-powered target devices.
* Establish ordinary ordering through drawing layers; use depth companions for artwork that needs local changes in drawing priority.
* Treat software filters and output scaling as presentation features rather than substitutes for suitable source artwork.
* Evaluate large areas of layered blending, repeated full-screen effects, and detailed filtering as part of the complete scene.
 
Display scaling changes the size and sampling of the completed image. Choose source artwork and logical resolution for the intended visual detail, then select display settings for its presentation.


== See Also ==
== See Also ==


* [[Drawmethod]]
* [[Drawmethod]]
* [[Layer]]
* [[Subscreens]]
* [[Background]]
* [[Mesh Map]]
* [[Video]]
* [[Movie Player]]
* [[Script]]
* [[Script Overview]]
 
[[Category:Graphics]]
[[Category:Graphics]]
[[Category:Openbor]]
[[Category:Openbor]]

Revision as of 00:50, 29 November 2026

Introduction

OpenBOR uses hardware rendering to draw and composite sprites, background layers, text, primitive shapes, subscreens, movie images, and mesh-map artwork. The GPU renders these graphics into a full-color logical screen, applies the selected output effects, and presents the result on the display.

Creators supply artwork and control positions, drawing layers, palettes, and effects through native settings or scripts. The CPU handles gameplay, asset decoding, drawing commands, sorting, and geometry preparation. The GPU handles image sampling, palette lookup, pixel composition, blending, and rendered output. Desktop versions use OpenGL, while Android uses OpenGL ES 3.0 or newer.

Main scenes and script-created screens use RGB32 color. Indexed source artwork remains useful for palette selection and remapping, and the GPU resolves those indices into the full-color scene. The finished image is not restricted to one shared 256-color palette.

The module's logical resolution determines its drawing area. Window size, fullscreen fitting, and display filters determine how that finished composition appears on the physical display. See Resolution and Resampling and Display Filters.

Source Graphics

Image requirements depend on the resource being loaded. Ordinary sprites use non-interlaced, 8-bit indexed PNG images. Primary backgrounds and mesh artwork also have true-color image paths. Separate companion images can supply opacity or drawing-depth data.

Graphic type Source format Use
Character and entity sprites Non-interlaced, 8-bit indexed PNG Animation frames, model palettes, remaps, and sprite effects.
Icons, fonts, and interface sprites Non-interlaced, 8-bit indexed PNG Sprite-based interface elements and text glyphs.
Ordinary stage layers and panels Non-interlaced, 8-bit indexed PNG Layer artwork loaded through the regular sprite or indexed-screen path.
Primary background image Indexed PNG or true-color RGB PNG The main background image. Indexed backgrounds can also establish the global palette.
Mesh-map artwork 8-bit indexed or 24-bit RGB PNG Texture applied to a mesh surface through its dedicated artwork loader. See Mesh Map.
Alpha mask Non-interlaced, 8-bit grayscale or indexed PNG Per-pixel opacity data supplied separately from sprite artwork.
Drawing-depth mask Single-channel, 16-bit grayscale PNG Per-pixel drawing-Z adjustments for sprites, screens, or mesh artwork.
Animated cutscene image Animated GIF Animated image playback through the cutscene and GIF systems.
Movie WebM containing VP8 video and optional Vorbis audio Movie playback into a screen or directly to the display. See Movie Player.

Save ordinary indexed artwork with an actual 8-bit PNG sample depth. Images containing only a few colors can still be saved by an editor as a 1-, 2-, or 4-bit indexed PNG, which does not meet the regular sprite loader's format requirement.

The sprite loader trims transparent borders and records the resulting offsets to preserve alignment. Keep matching alpha and depth companions aligned to the original source canvas. Previously loaded artwork can be reused, including shared image data drawn with different offsets or palettes.

Indexed Sprites and Palettes

Indexed sprites store color indices, while palettes assign an RGB color to each index. The GPU uses the selected palette when drawing the image. Changing a color set can therefore reuse the same sprite artwork instead of requiring another image for every character or costume variation.

Models can have their own palettes and alternate color sets. Frames can also retain their own palettes where the model configuration permits it. Palette selection, remapping, tinting, and channel controls remain available within hardware rendering.

Palette index zero supplies ordinary sprite cutout transparency. Separate alpha masks and drawmethod settings provide additional control over opacity and blending. The regular sprite path uses image indices and palette data; embedded PNG transparency metadata does not replace these controls.

True-Color Sprites

The standard animation-frame and loadsprite() paths use indexed source images. Full-color output is available through primary RGB backgrounds, RGB mesh artwork, subscreens, and compositions of multiple images.

For artwork assembled from indexed components, creators can combine aligned red, green, and blue channel images using drawmethod channel controls and blending. This is an optional composition technique for producing an RGB result from indexed sprite parts. The components use the same GPU drawing pipeline as other sprites.

See Drawmethod for palette selection, color channels, opacity, and blending controls.

Graphics Pipeline

The normal scene pipeline has five stages:

Stage Operation
Asset preparation Decode source files, preserve sprite alignment, and prepare reusable image and palette resources.
Drawing commands Native systems and scripts select images, geometry, positions, drawing layers, materials, and destination screens.
Ordering Sort queued entries by drawing layer and sort ID, retaining submission order for equal keys.
GPU composition Render into the logical screen or a subscreen with the selected transforms, sampling, colors, opacity, blending, and drawing depth.
Display presentation Apply the selected final-image effect, display scaling, and color adjustments before presenting the completed frame.

Asset Loading

OpenBOR decodes images into the source representation appropriate to the loader. Indexed sprites retain their indices and palette information; RGB images supply full-color pixels. GPU image and palette resources are cached for reuse.

Loading, decoding, and preparing an asset are separate from repeatedly drawing it. Normal scene rendering reuses the prepared resources. Palette changes can reuse an indexed image while changing the colors selected during drawing.

Drawing Queue

Native scene elements and ordinary script drawing submit commands to the sprite queue. Commands identify what to draw and how to draw it; they do not require creators to manage GPU textures or issue graphics-API calls.

Queued elements include:

  • Sprites and animation frames.
  • Background and foreground layers.
  • Text glyphs.
  • Dots, lines, and boxes.
  • Subscreens.
  • Textured mesh-map surfaces.

The queue holds up to 5,000 entries. Queued text normally contributes one entry per glyph. Entries submitted after the queue is full are not drawn. When a completed subscreen is submitted, that screen occupies one queue entry regardless of how many elements were composed into it.

Scripts can also draw directly into a subscreen. See Subscreens.

Layer Sorting

Each queued item has a drawing layer, represented by its drawing-Z value. Under ordinary layer ordering, lower values are drawn first and higher values appear in front. Drawing depth is independent of the screen position where an image appears.

OpenBOR sorts by drawing Z, then by the item's sort ID. Entries with equal values for both retain their submission order. Use explicit drawing layers to establish intentional foreground, background, and interface relationships.

Depth companions can adjust this priority for individual pixels. The original drawing layer remains the baseline, and the companion supplies the pixel's adjustment. See Drawing Depth.

GPU Composition

The GPU draws the ordered graphics into an RGB32 target. Main scenes and subscreens use the same rendering system. Shader operations perform palette lookup, image reconstruction, color effects, transparency, blending, and depth comparison where configured.

Transforms control the shape and placement submitted for drawing. Some effects use CPU-prepared geometry or sampling information, while the GPU renders the resulting pixels. Mesh artwork, curved images, sprites, and screens can use the shared material and sampling controls appropriate to their drawing paths.

The rendered scene normally remains in GPU storage for further composition and presentation. Drawing one subscreen into another, copying a screen, or reusing a captured composition can therefore remain within the GPU renderer. Explicit pixel reads and other operations that need a CPU-visible image synchronize the relevant screen when required.

Final Presentation

After scene composition, the selected Final Filter can process the completed image. The display stage then fits that result to the window or device display, applies its scaling filter and color adjustments, and presents the frame.

These operations use the GPU. SDL provides platform, window, and graphics-context integration; it is not a separate software scene compositor selected from the video menu.

Display presentation preserves the module's logical drawing coordinates. Enlarging the window changes the displayed size of the finished image. Changing the logical resolution changes the drawing area available to the game.

Draw Effects

Drawmethod is the shared collection of properties used to modify an image while drawing it. Entities, animation frames, stage layers, scripted sprites, screens, and mesh artwork expose the properties relevant to their drawing paths.

Effect group Capabilities
Palette and color set Select or replace the palette used to resolve indexed artwork.
Opacity and blending Control transparency and use blend modes such as alpha, negative alpha, overlay, hard light, dodge, and average blending.
Tint and channels Tint an image, adjust individual red, green, and blue channels, or fill covered pixels with a selected color.
Chroma and Substitute Select colors for chroma coverage rules or replace matching final-output colors.
Placement and orientation Flip, scale, rotate, shear, or position an image with an affine transform.
Clipping and repetition Restrict destination coverage or repeat supported images with configurable spacing.
Water and plane effects Apply wave displacement and perspective-plane transformations.
Curved surfaces Bend an image into a configurable curve with tilt, perspective, and texture scrolling.
Resampling Choose how source pixels are reconstructed after scaling or transformation.
Drawing depth Adjust per-pixel drawing priority with a depth companion and an optional range override.

The GPU performs the rendered pixel operations selected by these controls. Geometry modes have their own combination rules, so select the intended transform path and combine its supported material effects. See Drawmethod for commands, properties, defaults, and examples.

Alpha Masks

Alpha masks provide per-pixel control over an image's contribution to the destination. The GPU samples the mask with the artwork and uses it during composition. Masked sprites can therefore contain fully visible, partially blended, and transparent regions within one image.

Masks are useful for soft edges, dissolves, selective highlights, reflections, lighting effects, and localized reveals. Combine them with drawmethods and subscreens to build the desired appearance.

The alpha mask is separate from the sprite's palette and from its drawing-depth companion. See Drawmethod for the mask format, interpretation, and assignment rules.

Drawing Depth

Drawing-depth companions let different portions of one sprite, screen, or mesh texture appear in front of or behind other drawing. For example, a wall image can contain a far portion that actors cover and a near portion that covers those actors.

Each sample in the 16-bit grayscale companion supplies an adjustment to the draw's existing Z. The GPU compares the resulting per-pixel values within the applicable depth pass; greater drawing Z takes priority. The default mapping treats sample 32768 as zero adjustment, with lower samples supplying negative adjustments and higher samples supplying positive adjustments. Drawmethod can override the adjustment range.

Ordinary queued drawing uses depth composition automatically when a companion is present. Immediate composition into a subscreen can use an explicit depth pass. Opaque and fully covered cutout pixels test and write depth; partially covered or blended pixels retain ordered composition while testing against depth.

Depth companions control drawing priority. Mesh geometry controls physical terrain and collision. See Drawmethod for drawing-depth authoring and Mesh Map for mesh geometry, textures, and their depth companions.

Subscreens

Subscreens are script-owned RGB32 drawing surfaces. Creators can assemble sprites, text, primitives, captured queue layers, movies, and mesh artwork into a screen, then draw that screen as one image in another screen or the main scene.

Normal subscreen composition and reuse are GPU operations. Screens support drawing effects, filtering, and transformations, making them useful for custom interfaces, picture-in-picture views, split-screen layouts, mirrors, cached compositions, and localized effects.

Reuse a screen while its dimensions and purpose remain appropriate. Drawing a composed screen avoids rebuilding its contents when those contents have not changed. Reading its rendered pixels for script inspection can require synchronization with CPU-visible storage, so perform those reads when the values are actually needed.

See Subscreens for allocation, immediate drawing, queue capture, composition, ownership, and examples.

Movies and Animated Images

OpenBOR supports animated GIF playback and a WebM movie system. GIF decoding produces indexed image data that the GPU resolves through palettes and composes into a retained screen. WebM movies use VP8 video with optional Vorbis audio; the GPU performs video color conversion, resampling, and composition after decoding.

Movies can be drawn into an RGB32 screen and participate in a composed scene, or use direct display presentation. Movies composed into the game scene receive that scene's final-image effect. Direct movie presentation has its own display path. See Movie Player for loading, playback control, drawing destinations, and supported formats.

Resolution

Logical resolution and display resolution serve different purposes. Choose the logical resolution for the game's artwork, camera, and interface, then use display settings to fit the result to the player's screen.

Logical Resolution

The video setting in data/video.txt selects the width and height of the main logical screen. The following presets are available:

Mode Logical resolution
0 320 × 240
1 480 × 272
2 640 × 480
3 720 × 480
4 800 × 480
5 800 × 600
6 960 × 540

For the 960 × 540 preset:

video 6

Custom dimensions use a width and height separated by a lowercase x:

video 1280x720

Presets are convenient size selections. Custom dimensions support other landscape, portrait, or pixel-art layouts. Requested screen widths are preserved, including odd widths. Main screens and subscreens use RGB32; the colourdepth setting does not select a different scene format.

When present on Windows or Linux, data/videopc.txt takes precedence over data/video.txt.

Display Resolution

Window and device display settings determine how the finished logical image is presented. Desktop Window Scale ranges from 0.25× through 8× in quarter steps. Android provides Automatic fitting or a centered Display Scale. Fullscreen and automatic fitting can preserve the image's aspect ratio or stretch it to the available display area.

Preserving aspect ratio can leave unused borders where the logical and physical displays have different shapes. Stretching fills the selected display area and changes the image's proportions.

For example, a 320 × 240 scene at 4× window scale occupies 1280 × 960 display pixels while retaining its 320 × 240 logical drawing area. The final-image filter can change the appearance of that output without changing the scene coordinates or requesting another increase in window size.

Resampling and Display Filters

OpenBOR provides three separate controls for image reconstruction and filtering. Each operates at a different stage:

Control What it affects Choices
Drawmethod resampling Individual images while they are drawn into a scene or subscreen. Nearest by default; Bilinear; cubic Catmull-Rom, Mitchell, and B-spline; Lanczos 2 and 3.
Final Filter The completed game scene before display scaling. Disabled, Bilinear, Advance Mame2x, Scanlines, Scanlines TV, TV 2x, or Dot Matrix.
Scaling Filter Sampling while fitting the completed image to the display. Nearest, Bilinear, or High Quality.

Drawmethod resampling gives creators control over particular objects. Nearest preserves hard source-pixel boundaries. Other modes reconstruct the image from neighboring samples and can suit scaled, rotated, curved, or perspective artwork. The choice belongs to that drawing operation; display settings do not replace it.

Final Filter applies an appearance to the whole scene. Enabled final effects produce a GPU image at twice the logical width and height, then that result is fitted to the selected display size. On desktop, a selected final effect is active in fullscreen or when the window scale is at least 2×. Below that window scale, the selection remains stored but inactive. Android applies the selected effect through its scene presenter.

Scaling Filter controls the final fit. Nearest retains hard pixel edges, Bilinear interpolates adjacent pixels, and High Quality uses sharp-bilinear sampling to retain sharper pixel interiors while smoothing transitions during display scaling.

The Bilinear choices in Final Filter and Scaling Filter are separate controls. Final Filter selects a completed-scene effect; Scaling Filter selects display sampling. Neither changes the logical resolution. See Drawmethod for per-object resampling.

Performance Considerations

Hardware rendering makes transforms, palette effects, filtering, and subscreen composition part of the normal drawing pipeline. Useful authoring decisions still include resource reuse, the amount of image coverage, and how often scripts need to inspect rendered pixels.

  • Reuse loaded sprites and palettes when the artwork is unchanged. Use palette variation for color changes that do not require different shapes.
  • Retain and reuse subscreens. Rebuild cached compositions when their contents change.
  • Size temporary screens for the composition they need to hold.
  • Choose object resampling for the artwork and its transformation, independently of the final scene effect and display scaling.
  • Use GPU drawing operations to assemble effects and inspect screen pixels when the script needs their values.
  • Account for queued text glyphs and other entries when building a complex interface. Subscreens can hold reusable interface compositions.
  • Establish ordinary ordering through drawing layers; use depth companions for artwork that needs local changes in drawing priority.
  • Evaluate large areas of layered blending, repeated full-screen effects, and detailed filtering as part of the complete scene.

Display scaling changes the size and sampling of the completed image. Choose source artwork and logical resolution for the intended visual detail, then select display settings for its presentation.

See Also