looking for the multithreaded gl cube example

Everything else that doesn't fall into one of the other PB categories.
cYanide
New User
New User
Posts: 9
Joined: Fri Aug 15, 2003 7:24 pm

looking for the multithreaded gl cube example

Post 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.
RonStyle
User
User
Posts: 10
Joined: Sat Jan 17, 2004 11:35 pm

Post 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. ;)
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post 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'.
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Post Reply