Comments (8)
Uh, this applies to any type from the binding it seems.
When I added a color_type
variable, the single texture I had stopped rendering.
from fortran-raylib.
Is the behaviour related to this raylib issue? Does it occur with raylib 4.5 and 5.x alike?
from fortran-raylib.
@interkosmos It only occurs in your binding.
I am using it for a project of making a bunnymark in each binding, and it is the only binding I tried that has this problem (and I have tried like 10 of them now).
from fortran-raylib.
The binding is set to use my system raylib in /usr/lib/libraylib.so, which is 5.1-dev, and in other bindings and in C it works fine.
from fortran-raylib.
I cannot reproduce your issue. Could you provide more information, for instance, a minimal example?
from fortran-raylib.
! Shark Jumpy - a Flappy Bird, but reversed
! CODE TAKEN FROM https://masuday.github.io/fortran_tutorial/random.html
! modified a bit
subroutine random_stduniform(u)
implicit none
real,intent(out) :: u
real :: r
call random_number(r)
u = 1 - r
end subroutine random_stduniform
real function randint(a,b)
implicit none
real,intent(in) :: a,b
real :: u
call random_stduniform(u)
randint = (b-a)*u + a
end function randint
! END BORROWED CODE
module game_data
use :: raylib
type :: t_entity
real :: x
real :: y
integer :: width
integer :: height
end type t_entity
type, extends(t_entity) :: t_player
real :: speed
real :: gravity
type(texture2d_type) :: tex
type(texture2d_type) :: tex_flap
end type t_player
type, extends(t_entity) :: t_pipe
real :: speed
type(color_type) :: colour
end type t_pipe
type :: game
integer :: width = 800
integer :: height = 600
integer :: score = 0
character(15) :: caption = "Jumpy Shark"
type(t_player) :: thePlayer
type(t_pipe) :: pipes(16)
integer :: pipes_len = 16
end type game
contains
! player
subroutine player_init(this)
type(t_player), intent(out) :: this
this%x = 50
this%y = 50
this%width = 32
this%height = 32
this%speed = 4.2
this%gravity = -4.0
! load the texture
this%tex = load_texture("player.png")
this%tex_flap = load_texture("playerFlap.png")
end subroutine player_init
subroutine player_update(this)
type(t_player), intent(inout) :: this
this%gravity = this%gravity - 0.5
this%y = this%y - this%gravity
if (is_key_pressed(KEY_SPACE)) then
this%gravity = 10.0
end if
end subroutine player_update
subroutine player_paint(this)
type(t_player), intent(in) :: this
if (this%gravity < 0.0) then
call draw_texture(this%tex, int(this%x), int(this%y), WHITE)
end if
if (this%gravity > 0.0) then
call draw_texture(this%tex_flap, int(this%x), int(this%y), WHITE)
end if
!call draw_rectangle(int(this%x), int(this%y), this%width, this%height, RED)
end subroutine player_paint
subroutine player_unload(this)
type(t_player), intent(in) :: this
call unload_texture(this%tex)
call unload_texture(this%tex_flap)
end subroutine player_unload
! pipe
subroutine pipe_init(this, x, y, is_up, colour)
type(t_pipe), intent(inout) :: this
real, intent(in) :: x
real, intent(in) :: y
integer, intent(in) :: is_up
type(color_type), intent(in) :: colour
this%x = x
this%y = y
this%colour = colour
this%width = 40
if (is_up == 1) then ! true
this%height = int(randint(100.0, 150.0))
end if
this%height = 350
if (is_up == 0) then ! false
end if
end subroutine pipe_init
subroutine pipe_update(this)
type(t_pipe), intent(inout) :: this
end subroutine pipe_update
subroutine pipe_paint(this)
type(t_pipe), intent(inout) :: this
call draw_rectangle(int(this%x), int(this%y), this%width, this%height, this%colour)
end subroutine pipe_paint
subroutine pipe_unload(this)
type(t_pipe), intent(in) :: this
end subroutine pipe_unload
! utility functions
function strtol(i) result(res)
integer, intent(in) :: i
character(10) :: res
write(res, '(i5)') i
end function strtol
end module game_data
! program functions
subroutine init(jumpy)
use :: game_data
use :: raylib
type(game), intent(inout) :: jumpy
integer :: i = 0
! initialize the window
call set_trace_log_level(LOG_ERROR)
call init_window(jumpy%width, jumpy%height, jumpy%caption)
call set_target_fps(60)
call set_exit_key(0)
! initialize the player
call player_init(jumpy%thePlayer)
! initialize the pipes
do while (i < pipes_len)
i = i + 1
end do
end subroutine init
subroutine unload(jumpy)
use :: game_data
use :: raylib
type(game), intent(inout) :: jumpy
call close_window()
end subroutine unload
subroutine update(jumpy)
use :: game_data
type(game), intent(inout) :: jumpy
integer :: i = 0
call player_update(jumpy%thePlayer)
end subroutine update
subroutine paint(jumpy)
use :: game_data
use :: raylib
type(game), intent(inout) :: jumpy
integer :: i
call clear_background(RAYWHITE)
call player_paint(jumpy%thePlayer)
call draw_text(strtol(jumpy%score), jumpy%width / 2 - 100, 15, 50, RED)
end subroutine
program shark
use, intrinsic :: iso_c_binding, only: c_null_char
use :: raylib
use :: game_data
implicit none
type(game) :: jumpy
call init(jumpy)
do while (.not. window_should_close())
call update(jumpy)
call begin_drawing()
call paint(jumpy)
call end_drawing()
end do
call unload(jumpy)
end program shark
With each texture being a 32x32 png image. When only one of them is present, it works perfectly. With two, it does not render.
from fortran-raylib.
You have forgotten to null-terminate the strings you pass to raylib, as written in the compatibility section of the README:
- Make sure to properly null-terminate all character strings passed to raylib with
c_null_char
from moduleiso_c_binding
or simplyachar(0)
.
For texture loading:
use, intrinsic :: iso_c_binding, only: c_null_char
type(t_player), intent(out) :: this
! [...]
! load the texture
this%tex = load_texture('player.png' // c_null_char)
this%tex_flap = load_texture('playerFlap.png' // c_null_char)
And for window creation:
use, intrinsic :: iso_c_binding, only: c_null_char
! [...]
! initialize the window
call set_trace_log_level(LOG_ERROR)
call init_window(jumpy%width, jumpy%height, jumpy%caption // c_null_char)
from fortran-raylib.
Oh thanks now it works.
from fortran-raylib.
Related Issues (3)
- Problem with compiling HOT 10
- FPM not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fortran-raylib.