Threaded Graphics

Just starting out? Need help? Post your questions and find answers here.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Threaded Graphics

Post 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
- chris -
New User
New User
Posts: 9
Joined: Sun Jun 06, 2010 10:43 am

Re: Threaded Graphics

Post 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

PB v5.62 x86/x64
Windows 10 Pro
Post Reply