Page 1 of 1
looking for the multithreaded gl cube example
Posted: Tue Jan 20, 2004 7:52 pm
by cYanide
hiya, i remember a while ago seeing the gl cube example using multithreading (so it didnt stop when the window was being moved etc)
now im just trying to find the threading bit, threads are being a lil evl to me atm, does anyone have this? i cant seem to find it anymore in search.
Posted: Wed Jan 21, 2004 2:28 am
by RonStyle
Just think of a thread as a unique program, yet a unique program that shares the same resources as the initiator.
Although I've not seen this demo, it's safe to assume, the gl stuff was a part of a thread. Hence not stopped when you paused the original thread by moving the window.
I think.

Posted: Wed Jan 21, 2004 4:58 am
by fsw
Maybe you search for this:
viewtopic.php?t=4461&highlight=opengl+thread
but Danilo's code does not work under 3v81.
I get a asm error:
---------------------------
PureBasic - Assembler error
---------------------------
PureBasic.asm [1702]:
EXTERN _PB_Window_Current
error: illegal instruction.
---------------------------
OK
---------------------------
I have an example here but it's not a cube...
This is a version that works with 3v81.
Code: Select all
; OpenGL Demo in PureBasic
;
; This is a THREAD Version now the object is rotating even if you move the window!
;
; (c) 2004 - Franco aka FSW
;
; the base code is made by Mark1up
; 'threading' and 'made it work with 3v81' by me
InitSprite()
InitKeyboard()
Structure WindowClass
wcstyle.b
EndStructure
wc.WindowClass
wc\wcstyle = #CS_OWNDC
RegisterClass_(wc)
Procedure Go(hDC)
pfd.PixelFormatDescriptor
pfd\nSize = SizeOf(PixelFormatDescriptor)
pfd\nVersion = 1
pfd\dwFlags = #PFD_DRAW_TO_WINDOW | #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER
pfd\iPixelType = #PFD_TYPE_RGBA
pfd\cColorBits = 24
pfd\cDepthBits = 16
pfd\iLayerType = #PFD_MAIN_PLANE
iFormat = ChoosePixelFormat_ (hDC, pfd)
SetPixelFormat_ (hDC, iFormat, pfd)
hRC.l = wglCreateContext_(hDC)
wglMakeCurrent_(hDC,hRC)
Theta.f = 0
WinEvt= WindowEvent()
While WinEvt <> #PB_EventCloseWindow
WinEvt= WindowEvent()
glClearColor_( 0.0, 0.0, 0.0, 0.0 )
glClear_( #GL_COLOR_BUFFER_BIT )
glPushMatrix_()
glRotatef_( Theta, 0.0, 0.0, 1.0 )
glBegin_( #GL_TRIANGLES )
glColor3f_( 1.0, 0.0, 0.0 )
glVertex2f_( 0.0, 1.0 );
glColor3f_( 0.0, 1.0, 0.0 )
glVertex2f_( 0.87, -0.5 )
glColor3f_( 0.0, 0.0, 1.0 )
glVertex2f_( -0.87, -0.5 )
glEnd_()
glPopMatrix_()
SwapBuffers_( hDC )
Theta = Theta + 1.0
Wend
EndProcedure
hWnd = OpenWindow(1, 20, 20, 600, 400, #PB_Window_SystemMenu, "OpenGL Demo")
hDC.l = GetDC_(hWnd)
CreateThread(@Go(),hDC)
WinEvt= WindowEvent()
While WinEvt <> #PB_EventCloseWindow
WinEvt= WindowEvent()
Delay(10)
Wend
wglMakeCurrent_(#NULL,#NULL)
wglDeleteContext_(hRC)
ReleaseDC_(hWnd, hDC)
CloseWindow(1)
End
hope this helps
Posted: Wed Jan 21, 2004 9:09 am
by Danilo
fsw wrote:
Maybe you search for this:
viewtopic.php?t=4461&highlight=opengl+thread
but Danilo's code does not work under 3v81.
I get a asm error:
---------------------------
PureBasic - Assembler error
---------------------------
PureBasic.asm [1702]:
EXTERN _PB_Window_Current
error: illegal instruction.
---------------------------
OK
---------------------------
The assembler changed from NASM to FASM, so you have to
replace '!EXTERN _PB_Window_Current' with '!extrn _PB_Window_Current'.