Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
glow.h File Reference

Jo Engine glows: the halo of light around a lamp (a soft disc of its color, without edge, with or without a few thin rays of light; a lit rectangle; the outline of a rectangle, a neon), added to the image. More...

Go to the source code of this file.

Macros

#define JO_3D_GLOW_MAX
 Max glows (lamps).
#define JO_3D_GLOW_LAYER_SHOWN
 Glows drawn at the same time in the layer (JO_3D_GLOW_LAYER), the brightest ones.
#define JO_3D_GLOW_LAYER_RECTS
 Rectangles of clip in a frame in the layer (JO_3D_GLOW_LAYER, see jo_3d_glows_set_clip()): the glows clipped by another rectangle are not drawn.

Enumerations

enum  jo_3d_glow_shape { JO_3D_GLOW_STAR , JO_3D_GLOW_DISC , JO_3D_GLOW_RECT , JO_3D_GLOW_FRAME }
 Shapes of the glows (see jo_3d_glow_set_shape()). More...
enum  jo_3d_glow_mode { JO_3D_GLOW_VDP2 , JO_3D_GLOW_LAYER }
 Where the glows are drawn (see jo_3d_glows_set_mode()). More...

Functions

int jo_3d_glow_add (const jo_pos3D_fixed *const position, const unsigned char r, const unsigned char g, const unsigned char b, const int radius, const int intensity)
 Add a glow.
void jo_3d_glow_set_shape (const int id, const jo_3d_glow_shape shape, const int width, const int height)
 Change the shape of a glow.
void jo_3d_glow_set_anchor (const int id, const bool anchor)
 Place a glow to the pixel: the scroll of the layer puts the grid of the cells on it (the glow seen the most otherwise); for a rectangle that must stay on its lamps (the rear lamps of a car: a rectangle is placed on the cells, 8 pixels, it jumped from one cell to the next). The first anchored glow seen wins.
void jo_3d_glow_set_radius (const int id, const int radius)
 Change the size of a glow.
void jo_3d_glow_set_intensity (const int id, const int intensity)
 Change the intensity of a glow (a lamp that flickers, an alarm).
void jo_3d_glow_set_position (const int id, const jo_pos3D_fixed *const position)
 Move a glow.
void jo_3d_glow_set_color (const int id, const unsigned char r, const unsigned char g, const unsigned char b)
 Change the color of a glow.
void jo_3d_glows_clear (void)
 Remove all the glows.
void jo_3d_glows_set_rays (const int light, const int diagonal_light)
 The light of the rays of the glows (the star around the disc), before jo_3d_glows_enable() (its characters are built then).
void jo_3d_glows_set_mode (const jo_3d_glow_mode mode)
 Where the glows are drawn, before jo_3d_glows_enable() (or the glows turned off and on again).
bool jo_3d_glows_enable (const bool enabled)
 Turn the glows on or off: the VDP2 layers (see the remarks of this file: the 3D planes are hidden while they are on).
void jo_3d_glows_set_occlusion (bool(*hit)(const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, const jo_fixed max_t))
 The walls hide the glows behind them (a ray from the camera to the lamp, a few each frame).
void jo_3d_glows_set_clip (bool(*clip)(const jo_pos3D_fixed *const position, jo_3d_rect *const rect))
 The glows are seen only in a rectangle of the screen: the rectangle where the place of the lamp is seen (a lamp in a room seen through a door: its glow stays in the door, see jo_cells_view_rect_at()). The cells of the glow out of the rectangle are not shown (to 8 pixels).
void jo_3d_glows_draw (const jo_pos3D_fixed *const camera)
 Place the glows seen from the camera (once per frame, after the camera: its matrix is the current matrix).

Detailed Description

Jo Engine glows: the halo of light around a lamp (a soft disc of its color, without edge, with or without a few thin rays of light; a lit rectangle; the outline of a rectangle, a neon), added to the image.

Author
Johannes Fetz
  • The VDP1 blends at 50 % only: a half transparent sprite shows its edge (and darkens the dark walls around it). The glows are drawn by the VDP2 instead: NBG2 over the sprite layer, with the color calculation "add": the color of a glow is added to the 3D view (0 at its edge: no edge, like the light of a real lamp in a camera)
  • Up to 15 glows on the screen at the same time (the brightest seen; a glow fades in and out), each one its size, its color and its shape (see jo_3d_glow_set_shape()): the map of the layer is a canvas, each glow puts the cells of its shape there (16 to 128 pixels, 15 levels of light) with its palette; where 2 glows overlap their light is added. The cells are computed once (no CPU time per pixel but for the overlaps); a glow is placed within 2 to 8 pixels, the brightest one to the pixel (the scroll of the layer). NBG3 stays free
  • The layers change when the image of the frame is displayed (not when the frame is computed): the glow stays on its lamp when the camera turns
  • They use the VRAM bank B0 of the VDP2: the rotation screen (the 3D planes, see background.h) is hidden while the glows are on (for the places where the 3D planes are not seen: inside a building, underground...)
  • A wall between the camera and a lamp hides its glow (see jo_3d_glows_set_occlusion())

Usage: jo_3d_glows_enable(true), jo_3d_glow_add() for each lamp, then jo_3d_glows_draw() at each frame after the camera (its matrix is the current matrix)

Bug
No known bugs.

Macro Definition Documentation

◆ JO_3D_GLOW_LAYER_RECTS

#define JO_3D_GLOW_LAYER_RECTS

Rectangles of clip in a frame in the layer (JO_3D_GLOW_LAYER, see jo_3d_glows_set_clip()): the glows clipped by another rectangle are not drawn.

◆ JO_3D_GLOW_LAYER_SHOWN

#define JO_3D_GLOW_LAYER_SHOWN

Glows drawn at the same time in the layer (JO_3D_GLOW_LAYER), the brightest ones.

◆ JO_3D_GLOW_MAX

#define JO_3D_GLOW_MAX

Max glows (lamps).

Enumeration Type Documentation

◆ jo_3d_glow_mode

Where the glows are drawn (see jo_3d_glows_set_mode()).

Enumerator
JO_3D_GLOW_VDP2 
JO_3D_GLOW_LAYER 

◆ jo_3d_glow_shape

Shapes of the glows (see jo_3d_glow_set_shape()).

Enumerator
JO_3D_GLOW_STAR 
JO_3D_GLOW_DISC 
JO_3D_GLOW_RECT 
JO_3D_GLOW_FRAME 

Function Documentation

◆ jo_3d_glow_add()

int jo_3d_glow_add ( const jo_pos3D_fixed *const position,
const unsigned char r,
const unsigned char g,
const unsigned char b,
const int radius,
const int intensity )

Add a glow.

Parameters
positionPosition (world)
rRed (0 to 255): the color added at its middle with the intensity 256
gGreen
bBlue
radiusRadius (world units): its size on the screen changes with its distance (16 to 128 pixels)
intensityIntensity (0: off, 256: its color)
Returns
Id of the glow, -1 if there are too many

◆ jo_3d_glow_set_anchor()

void jo_3d_glow_set_anchor ( const int id,
const bool anchor )

Place a glow to the pixel: the scroll of the layer puts the grid of the cells on it (the glow seen the most otherwise); for a rectangle that must stay on its lamps (the rear lamps of a car: a rectangle is placed on the cells, 8 pixels, it jumped from one cell to the next). The first anchored glow seen wins.

Parameters
idId of the glow
anchortrue: placed to the pixel

◆ jo_3d_glow_set_color()

void jo_3d_glow_set_color ( const int id,
const unsigned char r,
const unsigned char g,
const unsigned char b )

Change the color of a glow.

Parameters
idId of the glow
rRed (0 to 255)
gGreen
bBlue

◆ jo_3d_glow_set_intensity()

void jo_3d_glow_set_intensity ( const int id,
const int intensity )

Change the intensity of a glow (a lamp that flickers, an alarm).

Parameters
idId of the glow
intensityIntensity (0: off, 256: its color)

◆ jo_3d_glow_set_position()

void jo_3d_glow_set_position ( const int id,
const jo_pos3D_fixed *const position )

Move a glow.

Parameters
idId of the glow
positionPosition (world)

◆ jo_3d_glow_set_radius()

void jo_3d_glow_set_radius ( const int id,
const int radius )

Change the size of a glow.

Parameters
idId of the glow
radiusRadius (world units, see jo_3d_glow_add()); a rectangle: the width of the light around it

◆ jo_3d_glow_set_shape()

void jo_3d_glow_set_shape ( const int id,
const jo_3d_glow_shape shape,
const int width,
const int height )

Change the shape of a glow.

Parameters
idId of the glow
shapeShape (JO_3D_GLOW_STAR when it is added)
widthWidth of the rectangle (RECT, FRAME: world units, facing the camera; its radius is the width of the light around it, 8, 16 or 24 pixels on the screen)
heightHeight of the rectangle
Remarks
A rectangle is placed on the cells of the layer (8 pixels), the discs within 2 to 4 pixels (the glow seen the most to the pixel)

◆ jo_3d_glows_clear()

void jo_3d_glows_clear ( void )

Remove all the glows.

◆ jo_3d_glows_draw()

void jo_3d_glows_draw ( const jo_pos3D_fixed *const camera)

Place the glows seen from the camera (once per frame, after the camera: its matrix is the current matrix).

Parameters
cameraPosition of the camera (world): the rays of the occlusion
Remarks
The layers change when the image of this frame is displayed

◆ jo_3d_glows_enable()

bool jo_3d_glows_enable ( const bool enabled)

Turn the glows on or off: the VDP2 layers (see the remarks of this file: the 3D planes are hidden while they are on).

Parameters
enabledtrue: the glows are displayed (the first call builds their characters in the VRAM)
Returns
false if the VDP2 memory is full (the glows stay off)

◆ jo_3d_glows_set_clip()

void jo_3d_glows_set_clip ( bool(* clip )(const jo_pos3D_fixed *const position, jo_3d_rect *const rect))

The glows are seen only in a rectangle of the screen: the rectangle where the place of the lamp is seen (a lamp in a room seen through a door: its glow stays in the door, see jo_cells_view_rect_at()). The cells of the glow out of the rectangle are not shown (to 8 pixels).

Parameters
clipGives the rectangle where a point is seen, false if it is not seen; JO_NULL: the whole screen

◆ jo_3d_glows_set_mode()

void jo_3d_glows_set_mode ( const jo_3d_glow_mode mode)

Where the glows are drawn, before jo_3d_glows_enable() (or the glows turned off and on again).

Parameters
modeJO_3D_GLOW_VDP2 (default) or JO_3D_GLOW_LAYER: a sprite of the VDP1 for each glow, in the transparency layer (jo/transparency.h, started by the program in the additive mode: jo_3d_transparency_set_blend(JO_VDP2_BLEND_ADD, 0)). Up to JO_3D_GLOW_LAYER_SHOWN glows, each one placed and sized to the pixel of the layer, sorted with the other objects of the layer (its masks hide them to the pixel); no VRAM of the VDP2 (the rotation screen stays), about 8 KB of the VRAM of the VDP1. Where 2 glows overlap, the nearer one is drawn over the other (the VDP1 doesn't add them). The occlusion (jo_3d_glows_set_occlusion()) and the clip (jo_3d_glows_set_clip()) work the same way: up to JO_3D_GLOW_LAYER_RECTS rectangles of clip in a frame

◆ jo_3d_glows_set_occlusion()

void jo_3d_glows_set_occlusion ( bool(* hit )(const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, const jo_fixed max_t))

The walls hide the glows behind them (a ray from the camera to the lamp, a few each frame).

Parameters
hitThe ray from origin along dir (unit vector) hits something before max_t (Q16.16), JO_NULL: always seen

◆ jo_3d_glows_set_rays()

void jo_3d_glows_set_rays ( const int light,
const int diagonal_light )

The light of the rays of the glows (the star around the disc), before jo_3d_glows_enable() (its characters are built then).

Parameters
lightLight of the 4 rays on the axes (0 to 256, in the middle of the glow; 150 by default, 0: no rays)
diagonal_lightLight of the 4 shorter rays on the diagonals (100 by default)