Skip to content

Commit

Permalink
added font file and license
Browse files Browse the repository at this point in the history
  • Loading branch information
captain0xff committed Oct 25, 2024
1 parent 1bdbb32 commit ed26252
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ if(SDLTTF_SAMPLES)
add_executable(testapp examples/testapp.c)
add_executable(testgputext examples/testgputext.c)

file(COPY examples/testgputext/fonts/NotoSansMono-Regular.ttf DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(TARGET OpenGL::OpenGL)
Expand Down
36 changes: 21 additions & 15 deletions examples/testgputext.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,6 @@ int main(int argc, char *argv[]) {
SDL_ReleaseGPUShader(context.device, vertex_shader);
SDL_ReleaseGPUShader(context.device, fragment_shader);

check_error_bool(TTF_Init());
TTF_Font *font = check_error_ptr(TTF_OpenFont("/usr/share/fonts/truetype/noto/NotoSansMono-Regular.ttf", 20));
TTF_SetFontWrapAlignment(font, TTF_HORIZONTAL_ALIGN_CENTER);
TTF_TextEngine *engine = check_error_ptr(TTF_CreateGPUTextEngine(context.device));
TTF_Text *text = check_error_ptr(TTF_CreateText_Wrapped(engine, font, "hello 1234\nSDL is cool!", 0, 0));
int w, h;
TTF_GetTextSize(text, &w, &h);
text->color = (SDL_FColor) {1.0f, 1.0f, 0.0f, 1.0f};

SDL_GPUBufferCreateInfo vbf_info = {
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
.size = sizeof(Vertex) * MAX_VERTEX_COUNT
Expand Down Expand Up @@ -331,12 +322,18 @@ int main(int argc, char *argv[]) {
geometry_data.vertices = SDL_calloc(MAX_VERTEX_COUNT, sizeof(Vertex));
geometry_data.indices = SDL_calloc(MAX_INDEX_COUNT, sizeof(int));

check_error_bool(TTF_Init());
TTF_Font *font = check_error_ptr(TTF_OpenFont("NotoSansMono-Regular.ttf", 50));
TTF_SetFontWrapAlignment(font, TTF_HORIZONTAL_ALIGN_CENTER);
TTF_TextEngine *engine = check_error_ptr(TTF_CreateGPUTextEngine(context.device));

SDL_Mat4X4 *matrices = (SDL_Mat4X4[]) {
SDL_MatrixPerspective(SDL_PI_F/2.0f, 800.0f/600.0f, 0.1f, 100.0f),
SDL_MatrixIdentity()
};

float rot_angle = 0;
char str[] = " \nSDL is cool";

while (running) {
SDL_Event event;
Expand All @@ -348,19 +345,30 @@ int main(int argc, char *argv[]) {
}
}

TTF_GPUAtlasDrawSequence *sequence = TTF_GetGPUTextDrawData(text);
queue_text(&geometry_data, sequence, &text->color);
for (int i = 0; i < 5; i++) {
str[i] = 65 + SDL_rand(26);
}

rot_angle = SDL_fmodf(rot_angle + 0.01, 2 * SDL_PI_F);

int tw, th;
TTF_Text *text = check_error_ptr(TTF_CreateText_Wrapped(engine, font, str, 0, 0));
check_error_bool(TTF_GetTextSize(text, &tw, &th));
text->color = (SDL_FColor) {1.0f, 1.0f, 0.0f, 1.0f};

// Create a model matrix to make the text rotate
SDL_Mat4X4 model;
model = SDL_MatrixIdentity();
model = SDL_MatrixMultiply(model, SDL_MatrixTranslation((SDL_Vec3) {0.0f, 0.0f, -80.0f}));
model = SDL_MatrixMultiply(model, SDL_MatrixScaling((SDL_Vec3) {0.5, 0.5, 0.5}));
model = SDL_MatrixMultiply(model, SDL_MatrixScaling((SDL_Vec3) {0.3, 0.3, 0.3}));
model = SDL_MatrixMultiply(model, SDL_MatrixRotationY(rot_angle));
model = SDL_MatrixMultiply(model, SDL_MatrixTranslation((SDL_Vec3) {-w/2.0f, h/2.0f, 0.0f}));
model = SDL_MatrixMultiply(model, SDL_MatrixTranslation((SDL_Vec3) {-tw/2.0f, th/2.0f, 0.0f}));
matrices[1] = model;

// Get the text data and queue the text in a buffer for drawing later
TTF_GPUAtlasDrawSequence *sequence = TTF_GetGPUTextDrawData(text);
queue_text(&geometry_data, sequence, &text->color);

set_geometry_data(&context, &geometry_data);

context.cmd_buf = check_error_ptr(SDL_AcquireGPUCommandBuffer(context.device));
Expand All @@ -370,8 +378,6 @@ int main(int argc, char *argv[]) {

geometry_data.vertex_count = 0;
geometry_data.index_count = 0;

SDL_Delay(10);
}

SDL_free(geometry_data.vertices);
Expand Down
Binary file not shown.
37 changes: 37 additions & 0 deletions examples/testgputext/fonts/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
License
Copyright 2022 The Noto Project Authors (https://github.com/notofonts/latin-greek-cyrillic)

This Font Software is licensed under the SIL Open Font License, Version 1.1 . This license is copied below, and is also available with a FAQ at: https://openfontlicense.org

SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
PREAMBLE

The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS

"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS

Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION

This license becomes null and void if any of the above conditions are not met.
DISCLAIMER

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

0 comments on commit ed26252

Please sign in to comment.