Hi Matthew,
Good to see you after time
I was nervous brother-in-OpenGL left the forums ;D
Nice demo!
Bye,
Petr
This Programme will display a Cylinder on your Screen and Rotate it.
[code=thinbasic]
' Cylinder in thinBASIC using TBGL...
'
uses "TBGL" ' thinBASIC OpenGL Library
uses "MATH" ' Used for Trigonometry
' Create, Show Our Window and Reset Status of all Keys...
'
Dim hWnd As dword = tbgl_createwindow("Cylinder - Press 'Esc' to Quit")
tbgl_showwindow
tbgl_getasynckeystate(-1)
' Dimension and Initialize any Variables...
'
dim Xrot, Yrot, Zrot as single ' X,Y and Z Rotation Variables
dim CylinderRadius, CylinderHeight as integer ' Radius and Height of Cylinder
dim CylinderShade as single ' Level of Brightness
dim i as integer ' Polygon Drawing Loop Variable
' Main Programme Loop
'
while tbgl_iswindow(hWnd)
tbgl_clearframe ' Clear Screen
tbgl_resetmatrix ' Clear the Current Matrix
tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
tbgl_translate 0.0, 0.0, -5.0 ' Move Object into Screen by 5.0
tbgl_Rotate Xrot, 1.0, 0.0, 0.0 ' Rotation around the X-Axis
tbgl_Rotate Yrot, 0.0, 1.0, 0.0 ' Rotation around the Y-Axis
tbgl_Rotate Zrot, 0.0, 0.0, 1.0 ' Rotation around the Z-Axis
CylinderRadius = 1
CylinderHeight = 4
tbgl_color 128, 128, 128 ' Cylinder Top, Grey.
tbgl_beginpoly %gl_polygon
for i = 0 to 36
tbgl_vertex CylinderRadius * cos(degtorad(i*10)), (CylinderHeight / 2) * -1, CylinderRadius * Sin(degtorad(i*10))
next
tbgl_endpoly
tbgl_color 255, 255, 255 ' Set Colour to White
tbgl_beginpoly %gl_quad_strip
' Draw Actual Cylinder in 10 Degree Steps...
'
for i = 0 to 36
' Shade Surface of Cylinder...
'
CylinderShade = abs(13.25 * (18-i))
tbgl_color CylinderShade, CylinderShade, CylinderShade
' Draw Top Vertex...
'
tbgl_vertex CylinderRadius * Cos(degtorad(i*10)), (CylinderHeight / 2) * -1, CylinderRadius * Sin(degtorad(i*10))
' Draw Bottom Vertex...
'
tbgl_vertex CylinderRadius * cos(degtorad(i*10)), (CylinderHeight / 2), CylinderRadius * Sin(degtorad(i*10))
next
tbgl_endpoly
' Draw Bottom of Cylinder...
'
tbgl_color 128, 128, 128
tbgl_beginpoly %gl_polygon
for i = 0 to 36
tbgl_vertex CylinderRadius * cos(degtorad((36-i))*10), CylinderHeight / 2, CylinderRadius * Sin(degtorad((36-i)*10))
next
tbgl_endpoly
tbgl_drawframe ' Swap the Drawing Buffers
Xrot = Xrot + 0.1 ' X axis rotation
Yrot = Yrot + 0.2 ' Y axis rotation
Zrot = Zrot + 0.05 ' Z axis rotation
if tbgl_getwindowkeystate(hWnd, %vk_escape) then exit while
wend
tbgl_destroywindow ' Closes OpenGL Window
[/code]
Operating System: Windows 10 Home 64-bit
CPU: Intel Celeron N4000 CPU @ 1.10GHz
Memory: 4.00GB RAM
Graphics: Intel UHD Graphics 600
Hi Matthew,
Good to see you after time
I was nervous brother-in-OpenGL left the forums ;D
Nice demo!
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Thanks for sharing Matthew.
@Mike - Thank's Mike.
I visit the thinBASIC Forum everyday but I don't bother posting if I haven't written a Programme.Originally Posted by Psch
Operating System: Windows 10 Home 64-bit
CPU: Intel Celeron N4000 CPU @ 1.10GHz
Memory: 4.00GB RAM
Graphics: Intel UHD Graphics 600
[code=thinbasic]
tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
tbgl_resetmatrix ' Clear the Current Matrix
[/code]
Shouldnt that be.
[code=thinbasic]
tbgl_resetmatrix ' Clear the Current Matrix
tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
[/code]
You reset the matrix then do your translations, rotation and camera stuff.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
^^
Yeah, when I first started using thinBASIC I used to make that mistake. :P
Source Updated.
Operating System: Windows 10 Home 64-bit
CPU: Intel Celeron N4000 CPU @ 1.10GHz
Memory: 4.00GB RAM
Graphics: Intel UHD Graphics 600
And to make it even more complicated ,
just:
[code=thinbasic]
tbgl_ClearFrame
tbgl_Camera 0,0,1,0,0,0
[/code]
is enough! TBGL_ClearFrame handles the matrix reset automatically.
But this is just mini problem, I still like the sample
Thanks,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks