# Pyraylib not loading custom font

**URL:** <https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449>\
**Category:** Python Help\
**Tags:** help\
**Created:** [April 20, 2024, 7:41am UTC](https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449 "2024-04-20T07:41:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bzox](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bzox/32/16733_2.png) [@bzox](https://discuss.python.org/u/bzox)\
**Post date:** [April 20, 2024, 7:41am UTC](https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449/1 "2024-04-20T07:41:14Z")

</div>

I am trying to load custom font but it doesn’t load at first i tried this code

```python
from pyray import *
init_window(900,900,"Hello")
font = load_font_ex("main.ttf", 32, 0, 250)

while not window_should_close():
    begin_drawing()
    clear_background(WHITE)
    draw_text_ex(font, "Hello", Vector2(100, 100), 68, 10, BLACK)
    end_drawing()

```

It throwed the error ` font = load_font_ex("main.ttf", 32, 0, 250) File "/home/himanshu/.local/lib/python3.10/site-packages/pyray/ __init__.py", line 76, in wrapped_func raise TypeError( TypeError: Argument must be a ctype int, please create one with: pyray.ffi.new('int *', 1)`

Then I tried the below thing

```python
from pyray import *
import pyray
from raylib import *

init_window(900,900,"Hello")

font_size = pyray.ffi.new('int *', 32)
font_style = pyray.ffi.new('int *', 0)
font_spacing = pyray.ffi.new('int *', 250)

font = load_font_ex("main.ttf".encode(),font_size, font_style, font_spacing)
while not window_should_close():
    begin_drawing()
    clear_background(WHITE)
    draw_text_ex(font, "Hello", Vector2(100, 100), 68, 10, BLACK)
    end_drawing()

```

then it throws this error

 ![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/3/5/355169f75227a0a47ba12969f88efdc6f723427e.png)

I want to just load a simple ttf file which is clear and not blurr because when i tried on windows it was blurr. someone please help

---

<div class="post-metadata">

**Author:** ![onePythonUser](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/onepythonuser/32/19158_2.png) [@onePythonUser](https://discuss.python.org/u/onePythonUser)\
**Post date:** [April 20, 2024, 2:40pm UTC](https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449/2 "2024-04-20T14:40:34Z")

</div>

Hi,

first, begin by not importing libraries open-ended. That is, don’t import libraries using the `*` sign. The reason is that you want to avoid potential race conditions between the objects being imported from libraries and names already in your current program/script.

At the top, use the following:

```python
import pyray as pr
import raylib as rlib

```

Then, update your code to account for these changes.

From the error generated, there is an issue with the following line:

```python
font = load_font_ex("main.ttf".encode(),font_size, font_style, font_spacing)

```

From documentation:

 ![font_issue](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/4/9/49eed1145aa2c528aa579f48d1339bb1a3f003c3.png)

Thus, the `load_font_ex` class/function takes in four argument types:

1. str
2. int
3. any
4. int

A quick way to check that the correct argument types are being passed in is to include some temporary print statements to verify the types generated by the `font` centric variables:  
`print(font_size)`; `print(type(font_size))`  
`print(font_style)` ; `print(type(font_style))`  
`print(font_spacing)` ; `print(type(font_spacing))`

I also referenced the library here:  
[https://electronstudio.github.io/raylib-python-cffi/pyray.html#pyray.load\_font\_ex](https://electronstudio.github.io/raylib-python-cffi/pyray.html#pyray.load_font_ex)

I did not find a reference for `ffi`. Can you double check that this is a valid attribute and that your code is using the correct variable names.

Regarding the first argument passed in, is the `.encode()` necessary? Can you try only passing in `main.ttf`?

**UPDATE:**

Here is an example that I found on GitHub:

> <https://github.com/electronstudio/raylib-python-cffi/blob/master/tests/test_hello_world.py>

It is similar in form to the original example that you provided. Test it to see if it works and see if you can modify it to suit your needs.

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [April 20, 2024, 4:04pm UTC](https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449/3 "2024-04-20T16:04:41Z")

</div>

> [@bzox](#):
>
> It throwed the error ` font = load_font_ex("main.ttf", 32, 0, 250) File "/home/himanshu/.local/lib/python3.10/site-packages/pyray/ __init__.py", line 76, in wrapped_func raise TypeError( TypeError: Argument must be a ctype int, please create one with: pyray.ffi.new('int *', 1)`

Right. That doesn’t mean _every_ argument. It means whichever argument was the first one to be affected by the problem. I.e., at least one, possibly others. An exception can really only ever tell you about one problem at a time.

To know _which_ argument, we need to read the documentation.

---

<div class="post-metadata">

**Author:** ![bzox](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bzox/32/16733_2.png) [@bzox](https://discuss.python.org/u/bzox)\
**Post date:** [April 22, 2024, 1:09pm UTC](https://discuss.python.org/t/pyraylib-not-loading-custom-font/51449/4 "2024-04-22T13:09:23Z")

</div>

> [@onePythonUser](#):
>
> ```python
> draw_text_ex(font, "hellow font", (300, 300), 30, 0, BLACK)
> draw_text("Hello world", 190, 200, 20, VIOLET)
> 
> ```

thanks this worked i think the issues was draw\_text\_ex and with that i need not use `pyray.ffi.new('int *', some_number)` this is the final code that gave the desired output

```python
import pyray as pr, raylib as rl, os

rl.SetConfigFlags(rl.FLAG_WINDOW_RESIZABLE)
pr.init_window(800, 450, "Hello")

font = font = pr.load_font_ex((os.getcwd()+"/main.ttf").encode(),30,None,0)

while not pr.window_should_close():
    pr.begin_drawing()
    pr.clear_background(pr.WHITE)
    pr.draw_text_ex(font, "hellow font", (300, 300), 30, 0, pr.BLACK)
    pr.draw_text("Hello world", 190, 200, 20, pr.VIOLET)
    pr.end_drawing()
pr.close_window()

```

But one issue still persists is the blurry font when the size is set to `90` or something greater which is clearly visible by user.

UPDATE :  
i found that i must load the text in higher size e.g. `200` and then `draw_text_ex` in lower size e.g. `90` . This solved the blurry text problem
