
set the subsystem to OpenGL
Code: Select all
IncludeFile #PB_Compiler_Home + "Examples\Sources - Advanced\OpenGL Cube\OpenGL.pbi"
InitKeyboard()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CompilerIf Subsystem("OpenGL") = #False
MessageRequester("Error", "Please set the subsystem to OpenGL")
End
CompilerEndIf
CompilerEndIf
If InitSprite() = 0
MessageRequester("Error", "Can't open screen & sprite environment!")
End
EndIf
OpenWindow(0, 0, 0, 640, 480, "8 Legs creature", #PB_Window_SystemMenu | #PB_Window_Invisible)
SetWindowColor(0, 0)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
HideWindow(0, #False)
Global spin.f, rot.f
Global Dim LightPos.f(4) ;Light Position
LightPos(0)= 0.0 : LightPos(1)= 5.0 : LightPos(2)=-4.0 : LightPos(3)= 1.0
Global Dim LightAmb.f(4) ;Ambient Light Values
LightAmb(0)= 0.2 : LightAmb(1)= 0.2 : LightAmb(2)= 0.2 : LightAmb(3)= 1.0
Global Dim LightDif.f(4) ;Diffuse Light Values
LightDif(0)= 0.6 : LightDif(1)= 0.6 : LightDif(2)= 0.6 : LightDif(3)= 1.0
Global Dim LightSpc.f(4) ;Specular Light Values
LightSpc(0)=-0.2 : LightSpc(1)=-0.2 : LightSpc(2)=-0.2 : LightSpc(3)= 1.0
Global Dim MatAmb.f(4) ;Material - Ambient Values
MatAmb(0)= 0.4 : MatAmb(1)= 0.4 : MatAmb(2)= 0.4 : MatAmb(3)= 1.0
Global Dim MatDif.f(4) ;Material - Diffuse Values
MatDif(0)= 1.0 : MatDif(1)= 0.6 : MatDif(2)= 0.0 : MatDif(3)= 1.0
Global Dim MatSpc.f(4) ;Material - Specular Values
MatSpc(0)= 0.0 : MatSpc(1)= 0.0 : MatSpc(2)= 0.0 : MatSpc(3)= 1.0
Global Dim MatShn.f(1) ;Material - Shininess
MatShn(0)= 0.0
glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)
glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);
glLightfv_(#GL_LIGHT1,#GL_POSITION,LightPos()) ;Set Light1 Position
glLightfv_(#GL_LIGHT1,#GL_AMBIENT,LightAmb()) ;Set Light1 Ambience
glLightfv_(#GL_LIGHT1,#GL_DIFFUSE,LightDif()) ;Set Light1 Diffuse
glLightfv_(#GL_LIGHT1,#GL_SPECULAR,LightSpc()) ;Set Light1 Specular
glEnable_(#GL_LIGHTING) ;Enable Lighting
glColorMaterial_(#GL_FRONT, #GL_AMBIENT_AND_DIFFUSE)
glEnable_(#GL_COLOR_MATERIAL) ; color tracking
glEnable_(#GL_NORMALIZE)
Procedure.l Spider_Render(spin.f)
glPushMatrix_();
;glColor3f_(1.0, 1.0, 0.0)
glPushMatrix_();
gluLookAt_(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotatef_(spin, 0.0, 1.0, 0.0);
rot=rot+0.1;
quad = gluNewQuadric_()
gluQuadricDrawStyle_(quad, #GL_FILL);
glPushMatrix_();
glTranslatef_(0.0, 0.6, 0.0);
gluSphere_( quad , 0.8 , 20 , 20 ); yello head
glColor3f_(1.0, 0.0, 0.0)
glTranslatef_(0.0, 0.1, 0.5)
gluSphere_( quad , 0.4 , 20 , 20 ); red eye
glColor3f_(1.0, 1.0, 0.0)
glPopMatrix_();
For i = 0 To 359 Step 45
glPushMatrix_();
glRotatef_( i, 0.0, 1.0, 0.0 );
For j = 1 To 3
;glRotatef_( 10+Sin(rot+i)*20, 1.0, 0.0, 0.0 )
glRotatef_( 10+Sin(ElapsedMilliseconds()/500+i+j)*40, 1.0, 0.0, 0.0 )
glPushMatrix_();
glRotatef_(-90, 0.0, 1.0, 0.0);
gluQuadricDrawStyle_(quad, #GL_FILL);
gluQuadricOrientation_(quad, #GL_SMOOTH);
gluCylinder_(quad, 0.2, 0.15, 2, 16, 10);
glPopMatrix_();
Next j
glTranslatef_(-2.0, 0.0, 0.0);
glRotatef_(30, 0.0, 0.0, 1.0);
glPushMatrix_();
glRotatef_(-90, 0.0, 1.0, 0.0);
gluCylinder_(quad, 0.15, 0.1, 1.5, 16, 10);
glPopMatrix_();
glTranslatef_(-1.5, 0.0, 0.0);
glRotatef_(30, 0.0, 0.0, 1.0);
glPushMatrix_();
glRotatef_(-90, 0.0, 1.0, 0.0);
gluCylinder_(quad, 0.1, 0.05, 1.0, 16, 10);
glPopMatrix_();
glPopMatrix_();
Next i
glPopMatrix_()
glFinish_()
glPopMatrix_();
EndProcedure
HideWindow(0, #False)
Procedure.l Spider_ini()
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_ ()
; viewing transformation
glTranslatef_(0.0, 0.0, -8.0);
gluLookAt_(5,5,5,0,1.5,0,0,1,0);
spin.f+0.6
Spider_Render(spin);
EndProcedure
Repeat
EventID = WindowEvent()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
running ! 1
EndIf
Spider_ini()
FlipBuffers()
Delay(1)
Until KeyboardPushed(#PB_Key_Escape) Or EventID = #PB_Event_CloseWindow
End

