General Usage: Rendering
Most of the time, we will interface with Telescope through its public C shared library, which only contains a limited number of functions. Usually, a telescope main will look like this:
main of a C++ application using Telescope#include <telescope.h>
int main()
{
TS_Init("<window title>", 500, 500);
while (something)
{
TS_VkBeginDrawPass();
// draw sprites here using TS_VkCmdDraw* commands
// manipulate physics using TS_Bt* commands
TS_VkEndDrawPass(0, 0, 0, 1);
}
TS_Quit();
}
Let’s talk through each of the functions used here, one by one:
Initialization & Shutdown
To initialize the telescope state, we first need to call TS_Init. This function takes three arguments:
-
void TS_Init(const char *ttl, int wdth, int hght)
initialize the state
- Parameters
ttl – title of the window
wdth – window width, in pixels
hght – window height, in pixels
Afterwards, at the end of our application, we call TS_Quit to safely quit the state and deallocate all physics and render objects
-
void TS_Quit()
quit the state
Drawing: Render Cycle
Each frame, Telescope will go through what is called a draw pass. <explain what that is here I have no idea>.
This always begins with TS_VkBeginDrawPass, and ends with TS_VkEndDrawPass
Of course, we don’t just want to draw a solid color. You can draw things on the screen using the TS_VkCmdDraw* functions.
-
void TS_VkCmdDrawRect(float r, float g, float b, float alpha, float x, float y, float width, float height)
draw a rectangle
- Parameters
r – red component of the color (in RGBA)
g – green component of the color (in RGBA)
b – blue component of the color (in RGBA)
alpha – transparency component of the color (in RGBA)
x – x-position of the upper left corner of the rectangle
y – y-position of the upper left corner of the rectangle
width – size along the x-dimension
height – size along the y-dimension
-
void TS_VkCmdDrawSprite(const char *image_path, float r, float g, float b, float alpha, int region_x, int region_y, int region_width, int region_height, int cell_w, int cell_h, int cell_index_i, int cell_index_j, float position_x, float position_y, float scale_x, float scale_y)
draw a sprite
- Parameters
image_path – path to image on disk
r – red component of the color (in RGBA)
g – green component of the color (in RGBA)
b – blue component of the color (in RGBA)
alpha – transparency component of the color (in RGBA)
region_x – x-coordinate of the top left corner of the subregion
region_y – y-coordinate of the top left corner of the subregion
region_width – size of the subregion along the x-dimension
region_height – size of the subregion along the x-dimension
cell_w – width of each cell of the grid
cell_h – height of each cell of the grid
cell_index_i – x-index of the cell
cell_index_j – y-index of the cell
position_x – x-coordinate of the top left corner of the sprite
position_y – y-coordinate of the top left corner of the sprite
scale_x – scale along the x-dimension
scale_y – scale along the y-dimension