Page 1 of 1

Threaded Graphics

Posted: Wed Sep 19, 2012 9:28 am
by chris319
I am trying to draw 2D graphics from within a thread using OpenGL on Windows 7. I can successfully draw directly to the window output, but if I draw to an image and try to copy that image to the window, no joy. What am I doing wrong? The code in question is in the procedure Decode1(). I have also tried the default graphics library.

Code: Select all

#H_RES = 1024
#V_RES = 768

Global imHeight, imWidth, semaphore1, threadID1, imageID0, null = 0

Procedure Decode1(null)
Repeat
WaitSemaphore(semaphore1)

StartDrawing(WindowOutput(1))
;StartDrawing(ImageOutput(imageID0))
Box(0,0,400,400, $0000ff)
StopDrawing()

;StartDrawing(WindowOutput(1))
;DrawImage(imageID0, 0, 0)
;StopDrawing()

ForEver
EndProcedure

Procedure DrawPicture()

SignalSemaphore(semaphore1)
While threadFlag1 = #True: Delay(2): Wend

EndProcedure

OpenWindow(1, -3, 65, #H_RES, #V_RES, "R-Y B-Y 4-2-2 v2", #PB_Window_SystemMenu)

imageID0 = CreateImage(#PB_Any, #H_RES, #V_RES)
If imageID0 = 0
  MessageRequester("Error", "Unable to load image.")
  End
EndIf
imHeight = ImageHeight(imageID0) - 1: imWidth = ImageWidth(imageID0) - 1

semaphore1 = CreateSemaphore(0)
threadID1 = CreateThread(@Decode1(), null)
DrawPicture()

Repeat
event = WaitWindowEvent()
Select event

Case #PB_Event_CloseWindow
  CloseWindow(1)
  FreeImage(imageID0)
  End

EndSelect
ForEver

Re: Threaded Graphics

Posted: Wed Sep 19, 2012 10:05 am
by - chris -
you have to use ImageID(imageID0)

Code: Select all


Procedure Decode1(null)
Repeat
WaitSemaphore(semaphore1)

; StartDrawing(WindowOutput(1))
; ;StartDrawing(ImageOutput(imageID0))
; Box(0,0,400,400, $0000ff)
; StopDrawing()

StartDrawing(WindowOutput(1))
DrawImage(ImageID(imageID0), 0, 0)
StopDrawing()

ForEver
EndProcedure