Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single line is not straight #53

Open
albinahlback opened this issue Jan 14, 2021 · 1 comment
Open

Single line is not straight #53

albinahlback opened this issue Jan 14, 2021 · 1 comment

Comments

@albinahlback
Copy link

With the following example

using SimpleDirectMediaLayer
const SDL2 = SimpleDirectMediaLayer 

SDL2.init()
win = SDL2.CreateWindow("",
    Int32(0), Int32(0), Int32(200), Int32(100), UInt32(SDL2.WINDOW_SHOWN)
   )

renderer = SDL2.CreateRenderer(win,
    Int32(-1),
    UInt32(SDL2.RENDERER_ACCELERATED | SDL2.RENDERER_PRESENTVSYNC)
   )

SDL2.SetRenderDrawColor(renderer, 0, 0, 0, 255)
SDL2.RenderClear(renderer)

SDL2.SetRenderDrawColor(renderer, 255, 255, 255, 255)

# Regular format
SDL2.RenderDrawLine(renderer, 50, 25, 150, 25)

# Array format
SDL2.RenderDrawLines(renderer, Cint.([[50; 50]; [150; 50]]), Cint(2))

# Reverted line
SDL2.RenderDrawLines(renderer, Cint.([[150; 75]; [50; 75]]), Cint(2))

SDL2.RenderPresent(renderer)
sleep(5)
SDL2.Quit()

the right-most point get shifted a point up (-1 in y-value).

@Gnimuc
Copy link
Member

Gnimuc commented Oct 29, 2022

using SimpleDirectMediaLayer.LibSDL2

@assert SDL_Init(SDL_INIT_EVERYTHING) == 0 "error initializing SDL: $(unsafe_string(SDL_GetError()))"

win = SDL_CreateWindow("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_SHOWN)
SDL_SetWindowResizable(win, SDL_TRUE)

renderer = SDL_CreateRenderer(win, -1, 0)

    try
           close = false
           while !close
               event_ref = Ref{SDL_Event}()
               while Bool(SDL_PollEvent(event_ref))
                   evt = event_ref[]
                   evt_ty = evt.type
                   if evt_ty == SDL_QUIT
                       close = true
                       break
                   end
               end

               SDL_SetRenderDrawColor(renderer,0,0,0,255)
               SDL_RenderClear(renderer)
               SDL_SetRenderDrawColor(renderer,255,255,255,255)
               SDL_RenderDrawLine(renderer, 50, 25, 150, 25)
               SDL_RenderDrawLines(renderer, Cint.([[50; 50]; [150; 50]]), Cint(2))
               SDL_RenderDrawLines(renderer, Cint.([[150; 75]; [50; 75]]), Cint(2))
               SDL_RenderPresent(renderer)

               SDL_Delay(1000 ÷ 60)
           end
       finally
           SDL_DestroyRenderer(renderer)
           SDL_DestroyWindow(win)
           SDL_Quit()
       end

Screen Shot 2022-10-30 at 2 11 19

I don't see any shifts...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants