Code Monkey home page Code Monkey logo

fortran-sdl2_gfx's Introduction

fortran-sdl2_gfx

Fortran bindings for SDL2_gfx (https://www.ferzkopp.net/Software/SDL2_gfx/Docs/html/index.html) to be used in conjunction with: https://github.com/interkosmos/fortran-sdl2

WIP - busy refactoring the library

fpm build

fpm build

fpm run

Add the following to your fpm.toml file:

[build]
link = ["SDL2", "SDL2_gfx"]
[dependencies]
fortran-sdl2.git = "https://github.com/interkosmos/fortran-sdl2.git"
fortran-sdl2_gfx.git = "https://github.com/freevryheid/fortran-sdl2_gfx.git"

example

The app applies each of the gfx primitive functions:

sdl2_gfx example

fortran-sdl2_gfx's People

Contributors

freevryheid avatar

Watchers

 avatar  avatar

fortran-sdl2_gfx's Issues

An issue drawing text

Usually my programs show a textual menu (in the terminal) to change parameters and when done the user type R to run the graphical part. In this way, the graphics is initialized and closed more times. Now, when I draw text, it is displayed at the first run but not in the next run. The following example reproduce this issue.

It show a short menu (R-run, Q-quit). The user type R <ENTER> a window shows up with the text Hello, World. The user type ESC, the window is closed. Then the user re-type R <ENTER> another window shows up but the text is not displayed.

Notice this regard only the text not other things. Indeed you can see RED pixels displayed at each RUN on upper-left corner. Only the text appears once.

After the first call, string() returns a negative code..

Any idea for which this occurs?

TIA

!
! BUILDING IN MSYS2/MINGW64
!
! rm -rf {*.mod,../../modules/*}; \
! gfortran -march=native -Wall -std=f2018 -fmax-errors=1 -O3 \
!   -J ../../modules ../../sdl2-fortran/src/{c_util,sdl2/{sdl2_stdinc,\
!   sdl2_audio,sdl2_blendmode,sdl2_cpuinfo,sdl2_gamecontroller,sdl2_error,\
!   sdl2_events,sdl2_filesystem,sdl2_hints,sdl2_joystick,sdl2_keyboard,\
!   sdl2_log,sdl2_messagebox,sdl2_rect,sdl2_pixels,sdl2_platform,\
!   sdl2_scancode,sdl2_surface,sdl2_render,sdl2_keycode,sdl2_mouse,\
!   sdl2_rwops,sdl2_thread,sdl2_timer,sdl2_version,sdl2_video,\
!   sdl2_opengl},sdl2}.f90 \
!   ../../sdl2_gfx-fortran/src/{sdl2_gfx_misc,primitives,framerate,\
!   sdl2_gfx}.f90 sdl2_gfx_text_test.f90 -o sdl2_gfx_text_test-static.out \
!   -lmingw32 -lSDL2_gfx -lSDL2main -lSDL2 \
!   -lws2_32 -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 \
!   -lole32 -loleaut32 -lshell32 -lversion -luuid -lcomdlg32 -lhid \
!   -lsetupapi; rm -rf {*.mod,../modules/*}
!
!
! BUILDING IN WSL
!
! rm -rf {*.mod,../../modules/*}; \
!   gfortran -march=native -Wall -std=f2018 -fmax-errors=1 -O3 \
!     -J ../../modules ../../sdl2-fortran/src/{c_util,sdl2/{sdl2_stdinc,\
!     sdl2_audio,sdl2_blendmode,sdl2_cpuinfo,sdl2_gamecontroller,\
!     sdl2_error,sdl2_events,sdl2_filesystem,sdl2_hints,sdl2_joystick,\
!     sdl2_keyboard,sdl2_log,sdl2_messagebox,sdl2_rect,sdl2_pixels,\
!     sdl2_platform,sdl2_scancode,sdl2_surface,sdl2_render,sdl2_keycode,\
!     sdl2_mouse,sdl2_rwops,sdl2_thread,sdl2_timer,sdl2_version,\
!     sdl2_video,sdl2_opengl},sdl2}.f90 \
!     ../../sdl2_gfx-fortran/src/{sdl2_gfx_misc,primitives,framerate,\
!     sdl2_gfx}.f90 sdl2_gfx_text_test.f90 -o sdl2_gfx_text_test-wsl.out \
!     -lSDL2_gfx -lSDL2; rm -rf {*.mod,../modules/*}
!

program sdl2_gfx_text_test
  implicit none

  character :: key = ' '
  integer :: ikey = ichar(' ')

  do while (ikey /= ichar('Q'))

     ! SHOW Menu
     write(*,*) 'Choose item:'
     write(*,*) '  R : RUN'
     write(*,*) '  Q : QUIT'

     write(*,'(a)',ADVANCE='NO') 'Choice : '
     read(*,*) key

     ! Convert in upcase if not
     if ('a' <= key .and. key <= 'z') then
        ikey = ichar(key)-32
     else
        ikey = ichar(key)
     end if

     write(*,*)

     select case (ikey)
     case (ichar('R'))
        call run()
     end select

     write(*,*)

  end do

contains

  subroutine run()
    use :: sdl2_gfx_misc
    use :: sdl2_gfx

    integer, parameter :: SCREEN_WIDTH = 640
    integer, parameter :: SCREEN_HEIGHT = 480
    integer, parameter :: FONT_SIZE = 8

    integer, parameter :: RED = int(z'FF0000FF')
    integer, parameter :: GREEN = int(z'FF00FF00')

    character(len=*), parameter :: MSG = &
         'Hello, World!'

    type(sdl) :: window
    type(sdl) :: renderer
    type(sdl_event) :: event

    integer :: i, j, rc
    logical :: done = .false.

    ! initialise SDL
    if (sdl_init(SDL_INIT_VIDEO) < 0) then
       write (stderr, *) 'SDL Error: ', sdl_get_error()
       stop
    end if

    ! create the SDL window
    window = sdl_create_window(c_str('SDL2_GFX_TEXT_TEST'), &
         SDL_WINDOWPOS_UNDEFINED, &
         SDL_WINDOWPOS_UNDEFINED, &
         SCREEN_WIDTH, &
         SCREEN_HEIGHT, &
         SDL_WINDOW_SHOWN)

    if (.not. sdl_associated(window)) then
       write (stderr, *) 'SDL Error: ', sdl_get_error()
       stop
    end if

    ! create the renderer
    renderer = sdl_create_renderer(window, -1, &
         ior(SDL_RENDERER_ACCELERATED, SDL_RENDERER_TARGETTEXTURE))

    i = (SCREEN_WIDTH-string_length(MSG,FONT_SIZE))/2
    j = SCREEN_HEIGHT/2

    rc = pixel(renderer,10,10,RED)
    rc = pixel(renderer,11,11,RED)
    rc = pixel(renderer,12,12,RED)
    rc = pixel(renderer,13,13,RED)
    rc = pixel(renderer,14,14,RED)
    rc = pixel(renderer,15,15,RED)

    rc = string(renderer,i,j,MSG,GREEN)
    print *, rc

    if (rc < 0) then
       write(*,*) 'SDL Error: ', sdl_get_error()
       !stop
    end if

    call sdl_render_present(renderer) ! Render to screen

    done = .false.
    do while (.not. done)
       do while (sdl_poll_event(event) > 0)
          select case (event%type)
          case (SDL_QUITEVENT)
             done = .true.
          case (SDL_KEYDOWN)
             select case (event%key%key_sym%scan_code)
             case (SDL_SCANCODE_ESCAPE)
                done = .true.
             end select
          end select
       end do
    end do

    ! cleanup and quit
    call sdl_destroy_renderer(renderer)
    call sdl_destroy_window(window)
    call sdl_quit()

  end subroutine run

end program sdl2_gfx_text_test

add topics

I suggest adding topics such as graphics, sdl2, opengl in the About section.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.