Skip to content
Andrea Ellinger edited this page Sep 28, 2021 · 4 revisions

This section contains all functions relating to CP_Font.

Table Of Contents

CP_Font_GetDefault

Gets the default CP_Font used by CProcessing.

Function

CP_Font CP_Font_GetDefault();

Parameters

This function has no parameters

Return

  • CP_Font - The default font of CProcessing.

Example

void update()
{
    CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));

    CP_Font default = CP_Font_GetDefault();
}

Related

CP_Font_Load

Loads a CP_Font from the given filepath.

Function

CP_Font CP_Font_Load(const char* filepath);

Parameters

  • filepath (const char*) - The filepath to the font that you want to load.

Return

  • CP_Font - The font loaded from the given filepath, will be NULL if no font could be loaded.

Example

CP_Font myFont;

void init()
{
    myFont = CP_Font_Load("Assets/Justins_Font.ttf");
}

void update()
{
    CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));

    CP_Font_Set(myFont);
    CP_Font_DrawText("Hi Justin!", 100, 100);
}

void shutdown()
{
    CP_Font_Free(myFont);
}

Related

CP_Font_Set

Sets a given CP_Font as the font to use when drawing text.

Function

void CP_Font_Set(CP_Font font);

Parameters

  • font (CP_Font) - The font that you want to use when drawing text.

Return

This function does not return anything.

Example

CP_Font myFont;

void init()
{
    myFont = CP_Font_Load("Assets/Justins_Font.ttf");
}

void update()
{
    CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));

    CP_Font_Set(myFont);
    CP_Font_DrawText("Hi Justin!", 100, 100);
}

void shutdown()
{
    CP_Font_Free(myFont);
}

Related

CP_Font_DrawText

Draws the given text to the screen using the current CP_Font.

Function

void CP_Font_DrawText(const char* text, float x, float y);

Parameters

  • text (const char*) - The text you want to display on the screen.
  • x (float) - The x position of the text.
  • y (float) - The y position of the text.

Return

This function does not return anything

Example

#include <stdio.h>
#include <stdlib.h>

void update()
{
    CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));

    CP_Settings_Fill(CP_Color_Create(0, 0, 0, 255));
    CP_Settings_TextSize(20.0f);

    char buffer[50] = { 0 };
    sprintf_s(buffer, _countof(buffer), "Frame count: %i", CP_System_GetFrameCount());
    CP_Font_DrawText(buffer, 30, 30);

    CP_Font_DrawText("Hi Justin!", 100, 200);
}

Related

CP_Font_DrawTextBox

Draws the given text onto the screen within a text box using the current CP_Font.

Function

void CP_Font_DrawTextBox(const char* text, float x, float y, float rowWidth);

Parameters

  • text (const char*) - The text you want to display on the screen.
  • x (float) - The x position of the text.
  • y (float) - The y position of the text.
  • rowWidth (float) - The width of each row.

Return

This function does not return anything

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));

  CP_Font_DrawTextBox("Hi Justin!", 100, 100, 20);
}

Related