Posts: 27
Threads: 12
Joined: Mar 2005
Hello people !
If some of you are just curious about an other language basic
like and as easy as QB, you can have a look at my Yahoo Egroup to see what we can do in FBSL and especially using OPenGL stuff and more there :
http://groups.yahoo.com/group/fbsl/message/752
http://groups.yahoo.com/group/fbsl/message/751
Enjoy ! :bounce:
Posts: 27
Threads: 12
Joined: Mar 2005
Hi,
Have a look at this FBSL script please :
No dependencies into FBSL.EXE, just pure dynamic DLL calls aka pure APIcall
Enjoy
Code: ' ==============================================
' Derived from: OpenGL 3D Objects for PB/DLL 5.0 & ported to FBSL v3 by Mike LOBANOVSKY 03rd of August 2005
' ==============================================
'#################################################################################
' COMPILER OPTIONS
'#################################################################################
$AppType GUI
Option Explicit
'#################################################################################
'#################################################################################
' PROTOTYPES
'#################################################################################
#DllDeclare User32("GetDC","ReleaseDC","GetClientRect")
#DllDeclare Kernel32("GetTickCount")
#DllDeclare Gdi32("SwapBuffers","ChoosePixelFormat","DescribePixelFormat","SetPixelFormat")
#DllDeclare Glu32("gluPerspective")
#DllDeclare OpenGL32("glViewport","glLoadIdentity","glClear","glPushMatrix","glPopMatrix", _
"glTranslated","glBegin","glEnd","glColor3d","glVertex3d","glFinish", "glMatrixMode", "glRotated", _
"wglCreateContext","wglMakeCurrent","wglDeleteContext","glDepthFunc","glEnable","glHint")
'###########################################################################
'#################################################################################
' UNINITIALIZED DATA
'#################################################################################
Dim %hMainDC, %lPixelFormat
Dim %hRC, %lWidth, %lHeight
Dim %dwCurTime, %dwOldTime
Dim !dAspect, !i, !m, !cameraV
'#################################################################################
'#################################################################################
' INITIALIZED DATA
'#################################################################################
/* Fake Pixel format descriptor fields */
Begin Enum 'Enum is more convenient than Const here
nSize = 0
nVersion = 2
dwFlags = 4
iPixelType = 8
cColorBits
cRedBits
cRedShift
cGreenBits
cGreenShift
cBlueBits
cBlueShift
cAlphaBits
cAlphaShift
cAccumBits
cAccumRedBits
cAccumGreenBits
cAccumBlueBits
cAccumAlphaBits
cDepthBits
cStencilBits
cAuxBuffers
iLayerType
bReserved
dwLayerMask
dwVisibleMask = 32
dwDamageMask = 36
End Enum'len=40 bytes
Dim lpPixelFormat
FillString(lpPixelFormat, 40, 0)
Begin Const
PFD_SUPPORT_OPENGL = &H20
PFD_DRAW_TO_WINDOW = &H4
PFD_DOUBLEBUFFER = &H1
PFD_MAIN_PLANE = 0
PFD_TYPE_RGBA = 0
GL_LEQUAL = &H203
GL_DEPTH_TEST = &HB71
GL_PERSPECTIVE_CORRECTION_HINT = &HC50
GL_FASTEST = &H1101
GL_POLYGON = &H9
GL_DEPTH_BUFFER_BIT = &H100
GL_COLOR_BUFFER_BIT = &H4000
GL_MODELVIEW = &H1700
GL_PROJECTION = &H1701
End Const
Begin Const 'Fake RECT fields
nLeft = 0
nTop = 4
nRight = 8
nBottom = 12
End Const'len=16 bytes
Dim lpRect
FillString(lpRect, 16, 0)
Dim $szAppName = "FBSL OpenGL: Flying 3D Objects"
'#################################################################################
'#################################################################################
' BEGIN CODE SECTION
'#################################################################################
SetTimer(Me, 1, 10) 'Used instead of idle time section in the message pump
FBSL_SetText(Me,szAppName)
Resize(Me, 0, 0, 640, 480)
Center(Me)
hMainDC = GetDC(Me)
GoSub InitGL 'Initialize the engine
GoSub SetupPixelFormat 'Synchronize the window DC with OpenGL
GoSub CreateGLContext 'Create the rendering context
GoSub ResizeViewport 'Build the perspective
Show(Me)
'########################################################################
' Main Events Loop
'########################################################################
Begin Events
Select Case CBMSG
Case WM_TIMER
'===========================
' Redraw the two objects
'===========================
GoSub RenderWorld
Case WM_SIZE
'===========================
' Adjust the perspective
'===========================
GoSub ResizeViewport
Case WM_ERASEBKGND
'===========================
' Tell Windows we handled it
'===========================
Return 1
Case WM_CLOSE
'===========================
' Clean up
'===========================
wglMakeCurrent(NULL, NULL)
If hRC Then
wglDeleteContext(hRC)
End If
If hMainDC Then
ReleaseDC(Me, hMainDC)
ExitProgram(0)
End If
End Select
End Events
'########################################################################
'########################################################################
' Sub InitGL
'########################################################################
:InitGL
'===========================
' Rev it up!
'===========================
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
Return
'########################################################################
' End Sub InitGL
'########################################################################
'########################################################################
' Sub SetupPixelFormat
'########################################################################
:SetupPixelFormat
'===========================
' Fill in the pixelformat structure:
' all other fields are set to 0
' by FillString()
'===========================
SetMem(lpPixelFormat,40,nSize) '40 = size of lpPixelFormat
SetMem(lpPixelFormat,1,nVersion)
SetMem(lpPixelFormat,PFD_SUPPORT_OPENGL BOR PFD_DRAW_TO_WINDOW BOR PFD_DOUBLEBUFFER,dwFlags)
SetMem(lpPixelFormat,PFD_MAIN_PLANE,dwLayerMask)
SetMem(lpPixelFormat,PFD_TYPE_RGBA,iPixelType)
SetMem(lpPixelFormat,16,cColorBits)
SetMem(lpPixelFormat,16,cDepthBits)
'===========================
' Select it into the window DC
'===========================
lPixelFormat = ChoosePixelFormat(hMainDC, lpPixelFormat)
If lPixelFormat = 0 Then
MsgBox(0, "ChoosePixelFormat() failed", szAppName, 0)
Return
End If
DescribePixelFormat(hMainDC, lPixelFormat, 40, lpPixelFormat) '40 = size of lpPixelFormat
SetPixelFormat(hMainDC, lPixelFormat, lpPixelFormat)
Return
'########################################################################
' End Sub SetupPixelFormat
'########################################################################
'########################################################################
' Sub CreateGLContext
'########################################################################
:CreateGLContext
'===========================
' Create the rendering DC
'===========================
hRC = wglCreateContext(hMainDC)
If hRC = NULL Then
MsgBox(0, "wglCreateContext() failed", szAppName,0)
ExitProgram(-1)
End If
wglMakeCurrent(hMainDC, hRC)
Return
'########################################################################
' End Sub CreateGLContext
'########################################################################
'########################################################################
' Sub ResizeViewport
'########################################################################
:ResizeViewport
'===========================
' Adjust the perspective
' according to the new size
'===========================
GetClientRect(Me, lpRect)
lWidth = GetMem(lpRect, nRight, 4)
lHeight = GetMem(lpRect, nBottom, 4)
glViewport(0, 0, lWidth, lHeight)
dAspect = lWidth / lHeight
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(90 / dAspect, dAspect, 0.1, 360.0)
Return
'########################################################################
' End Sub ResizeViewport
'########################################################################
'########################################################################
' Sub RenderWorld
'########################################################################
:RenderWorld
dwOldTime = dwCurTime
dwCurTime = GetTickCount()
cameraV = cameraV + (dwCurTime - dwOldTime) / 100
'===========================
' Clear the backbuffer image
'===========================
glClear(GL_COLOR_BUFFER_BIT BOR GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
'===========================
' Rebuild matrices for the 2 objects
'===========================
glPushMatrix()
glTranslated(1.0, 0.0, -4.0)
glRotated(cameraV, 1.0, 0.0, 1.0)
glRotated(-cameraV, 0.0, 1.0, 0.0)
glBegin(GL_POLYGON)
For i = 0 To 359 Step 4 'Slow it down a bit
m = m + (dwCurTime - dwOldTime)/100000
'===========================
' Use explicit casts when passing
' expressions as double arguments!
'===========================
glColor3d(!Sin(i/180*PI-m*2), !Sin(i/180*PI-m), !Sin(i/180*PI+m))
glVertex3d(!Sin(i/180*PI), !Cos(i/180*PI)^3, !Sin(i/180*PI-m)^3)
Next i
glEnd()
glPopMatrix()
glPushMatrix()
glTranslated(-1.0, 0.0, -4.0)
glRotated(cameraV, 1.0, 0.0, 0.0)
glRotated(-cameraV, 0.0, 1.0, 0.0)
glRotated(cameraV, 0.0, 0.0, 1.0)
glBegin(GL_POLYGON)
For i = 0 To 359 Step 4 'Slow it down a bit
m = m + (dwCurTime - dwOldTime)/100000
'===========================
' Use explicit casts when passing
' expressions as double arguments!
'===========================
glColor3d(!Sin(i/180*PI-m*2), !Sin(i/180*PI-m), !Sin(i/180*PI+m))
glVertex3d(!Sin(i/180*PI), -!Cos(i/180*PI)^3, !Sin(i/180*PI-m)^3)
Next i
glEnd()
glPopMatrix()
'===========================
' Wait until we're done with OpenGL
'===========================
glFinish()
'===========================
' Flip the result to the window
'===========================
SwapBuffers(hMainDC)
Return
'########################################################################
' End Sub RenderWorld
'########################################################################
'#################################################################################
' END PROGRAM CODE
'#################################################################################
Posts: 27
Threads: 12
Joined: Mar 2005
Hello,
News from planet Mars !
FBSL now has a Tiny version that can compile tiny executable ( around 8 Kb ! )
The OPenGL3D stuff sample previously typed is about 16 Kb once compiled !
If you want to know more about FBSL v3, please check this out :
http://groups.yahoo.com/group/fbsl/message/775
Enjoy :bounce:
|