RenderDrawLines does not seem to work
my-little-repository opened this issue · 2 comments
my-little-repository commented
I am using SimpleDirectMediaLayer v0.1.1 with julia version 1.1.0
The functions RenderDrawLines, RenderDrawPoints don't plot anything, and do not output any errors.
Here is an example.
import SimpleDirectMediaLayer
const SDL2 = SimpleDirectMediaLayer
SDL2.Init(SDL2.INIT_EVERYTHING)
win = SDL2.CreateWindow("", Int32(0),Int32(0), Int32(400), Int32(400), UInt32(0))
ren = SDL2.CreateRenderer(win, Int32(-1), UInt32(0))
SDL2.SetRenderDrawColor(ren,0,0,0,255)
SDL2.RenderClear(ren)
triangle = [SDL2.Point(Int32(100),Int32(100)), SDL2.Point(Int32(300),Int32(300)),
SDL2.Point(Int32(20), Int32(300)), SDL2.Point(Int32(100),Int32(100))]
SDL2.SetRenderDrawColor(ren,255,255,255,255)
SDL2.RenderDrawLine(ren, triangle[1].x, triangle[1].y, triangle[2].x, triangle[2].y)
SDL2.RenderDrawLines(ren, triangle, Int32(4))
SDL2.RenderPresent(ren)
SDL2.Delay(UInt32(5000))
SDL2.DestroyRenderer(ren)
SDL2.DestroyWindow(win)
SDL2.Quit()
The RenderDrawLine function draws the side of the triangle but the RenderDrawLines has no effect.
Wrapping the triangle in a pointer() call does not help. What am I doing wrong?
albinahlback commented
For some reason, you can't call it by an array of Point
s. Instead you have to call like
p1 = [100; 100]
p2 = [200; 200]
p3 = [100; 200]
triangle = Int32.([p1; p2; p3; p1])
SDL2.RenderDrawLines(ren, triangle, Int32(4))
Gnimuc commented
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)
triangle = [SDL_Point(Int32(100),Int32(100)), SDL_Point(Int32(300),Int32(300)),
SDL_Point(Int32(20), Int32(300)), SDL_Point(Int32(100),Int32(100))]
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_RenderDrawLines(renderer, triangle, Int32(4))
#SDL_RenderDrawLine(renderer, triangle[1].x, triangle[1].y, triangle[2].x, triangle[2].y)
SDL_RenderPresent(renderer)
SDL_Delay(1000 ÷ 60)
end
finally
SDL_DestroyRenderer(renderer)
SDL_DestroyWindow(win)
SDL_Quit()
end