BosonX/src/render.h

131 lines
4.0 KiB
C++

#ifndef __RENDERH__
# define __RENDERH__
#include "settings.h"
#include "util.h"
#include <utility>
#include <gint/display.h>
#include <libprof.h>
struct camera
{
//======= Fixed settings =======//
/* Vertical FOV, in degrees. */
num fov;
void set_fov(num fov);
/* Distance to the screen (world units). */
num screen_distance() const { return this->_sd; }
/* Distance to the near plane, for clipping.
TODO: Figure out a better choice of a near plane. */
num near_plane() const { return this->screen_distance() * num(0.25); }
//======= World data =======//
/* Position in space; always looking towards +z. */
vec3 pos;
/* Current platform (used to assign colors). */
int platform;
/* Vector canceling the player's angular rotation around z. */
vec2 angle_vector;
//======= Screen settings =======//
/* Screen size. */
vec2 screen_size;
private:
num _sd;
};
struct anim
{
/* Number of frames in the animation. */
int frame_count;
/* List of cropped frames. */
image_t **frames;
/* x/y offsets to add to desired render coordinates to render each frame
at the proper position. */
uint8_t *x_offsets;
uint8_t *y_offsets;
/* Position of the x and y anchors. */
int16_t x_anchor;
int16_t y_anchor;
};
struct player;
/* Move the camera to track behind a player. */
void camera_track(struct camera *, struct player const *);
/* Project a world point to the screen as viewed through a camera. The returned
vector has its x/y members set to screen coordinates stored as num; the z
member is kept unchanged. */
vec3 camera_project_point(struct camera *, vec3 point);
/* Optimized camera_project_point() that projects an entire prect, frect or
srect in-place. */
void camera_project_prect(struct camera *, struct prect *rect);
void camera_project_frect(struct camera *, struct frect *frect);
void camera_project_srect(struct camera *, struct srect *srect);
/* Compute the platform's color based on the camera's angle. */
int camera_platform_color(struct camera const *camera, int platform_id);
//======= Rendering tools =======//
/* Initialize/precompute globals. */
void render_init(void);
/* Color of a blue platform at the specified world time. */
uint16_t render_color_blue_platform(num t);
/* Color of the provided platform viewed from the provided camera at the given
world time. */
uint16_t render_platform_color(struct platform const *p,
struct camera const *camera, num t);
/* Queue an Azur command to render the triangle defined by p1/p2/p3. Only the
x/y coordinates are used, z is ignored. */
void render_triangle(vec3 *p1, vec3 *p2, vec3 *p3, int color);
/* Queue Azur commands to render a list of dots. Only x/y coordinates are
used, z is ignored. */
void render_dots(std::initializer_list<vec3> const &&points);
/* Render an energy string (energy font, characters supported: 0-9.%) */
void render_energy_str(int x, int y, int halign, char const *str);
/* Render a frame of an animation. */
void render_anim_frame(int x, int y, struct anim *anim, int frame);
/* Render the blue platform particle effect at time t. If *image is NULL,
creates it automatically. */
void render_effect_bpp(image_t **image, num t);
/* Render the death particles at time t. */
void render_effect_dp(int x, int y, int count, num t, int color);
/* Blend from c1 to c2 (t in [0..32]). */
uint16_t render_blend(uint16_t c1, uint16_t c2, int t);
/* Render full game.
perf_comp: Performance counter for platform projection and commands. */
void render_game(struct game &game, prof_t *perf_comp);
//======= Custom shaders =======//
/* Alpha blend an opaque color over the full screen (alpha = 0..31) */
void shader_fsblend(uint16_t color, int alpha);
/* "Particule trace" graphics on end screen */
void shader_ptrace(int x, int y, uint16_t color, uint16_t bgcolor,
bool successful, num t);
/* Reset the shader (to be called once per death, for randomness and stuff) */
void shader_ptrace_reset(void);
#endif /* __RENDERH__ */