DIM SHARED AllowSubGL
'we'll set this after we finish our setup immediately below, just in case 'there is anything here (there isn't currently though) that SUB _GL will depend on
TYPE DONT_USE_GLH_Handle_TYPE
REDIM SHARED DONT_USE_GLH_Handle
(1000) AS DONT_USE_GLH_Handle_TYPE
LINE (200, 200)-(500, 500), _RGBA(0, 255, 255, 0), BF
'create a see-through window (press 1)
AllowSubGL = 1
'This is our program's main loop
c
= c
+ 1:
PRINT "Mainloop has done nothing"; c;
"times" PRINT "Press 1[GL behind], 2[GL on top] or 3[GL only, good for speed] to switch rendering order."
'this specially named sub "_GL" is detected by QB64 and adds support for OpenGL commands
'it is called automatically whenever the underlying software deems an update is possible
'usually/ideally, this is in sync with your monitor's refresh rate
'STATIC was used above to make all variables in this sub maintain their values between calls to this sub
'timing is everything, we don't know how fast the 3D renderer will call this sub to we use timers to smooth things out
ET# = T# - ETT#
ETT# = T#
sub_gl_called = 1 'we only need to perform the following code once
i = TextToImage("Hello QB64!", 16, &HFFFF0000, &H00000000, 1)
mytex = GLH_Image_to_Texture(i) 'this helper function converts the image to a texture
'These settings affect how OpenGL will render our content
'!!! THESE SETTINGS ARE TO SHOW HOW ALPHA CAN WORK, BUT IT IS 10x FASTER WHEN ALPHA OPTIONS ARE DISABLED !!!
'*** every setting must be reset because SUB _GL cannot guarantee settings have not changed since last time ***
_gluPerspective 45, _WIDTH(0) / _HEIGHT(0), 1, 100 'QB64 internally supports this GLU command for convenience sake, but does not support GLU _glBlendFunc _GL_SRC_ALPHA
, _GL_ONE_MINUS_SRC_ALPHA
'how alpha values are interpretted _glAlphaFunc _GL_GREATER
, 0.5 'dont do anything if alpha isn't greater than 0.5 (or 128) '**************************************************************************************************************
GLH_Select_Texture mytex
_glRotatef rotation1
, 0, 1, 0 'spin, spin, spin...
_glBegin _GL_QUADS
'we will be drawing rectangles aka. QUADs
_glBegin _GL_TRIANGLES
'the png (almost) only consumes a triangular region of its rectangle
rotation1 = rotation1 + 100 * ET# / 4
rotation2 = rotation2 + 100 * ET# / 4
'QB64 OPEN-GL HELPER MACROS (aka. GLH macros)
'text$ is the text that we wish to transform into an image.
'font& is the handle of the font we want to use.
'fc& is the color of the font we want to use.
'bfc& is the background color of the font.
'Mode 1 is print forwards
'Mode 2 is print backwards
'Mode 3 is print from top to bottom
'Mode 4 is print from bottom up
'Mode 0 got lost somewhere, but it's OK. We check to see if our mode is < 1 or > 4 and compensate automatically if it is to make it one (default).
'print the text lengthwise
'print the text vertically
'Print text forward
'Print text backwards
temp$ = ""
temp$
= temp$
+ MID$(text$
, LEN(text$
) - i
, 1) 'Print text upwards
'first lets reverse the text, so it's easy to place
temp$ = ""
temp$
= temp$
+ MID$(text$
, LEN(text$
) - i
, 1) 'then put it where it belongs
fx
= (w&
- _PRINTWIDTH(MID$(temp$
, i
, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better 'Print text downwards
fx
= (w&
- _PRINTWIDTH(MID$(text$
, i
, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
SUB GLH_Select_Texture
(texture_handle
AS LONG) 'turn an image handle into a texture handle _glBindTexture _GL_TEXTURE_2D
, DONT_USE_GLH_Handle
(texture_handle
).handle
FUNCTION GLH_Image_to_Texture
(image_handle
AS LONG) 'turn an image handle into a texture handle h = DONT_USE_GLH_New_Texture_Handle
GLH_Image_to_Texture = h
FUNCTION DONT_USE_GLH_New_Texture_Handle
handle&& = 0
DONT_USE_GLH_New_Texture_Handle = handle&&
IF DONT_USE_GLH_Handle
(h
).in_use
= 0 THEN DONT_USE_GLH_Handle(h).in_use = 1
DONT_USE_GLH_Handle(h).handle = handle&&
DONT_USE_GLH_New_Texture_Handle = h
DONT_USE_GLH_Handle(h).in_use = 1
DONT_USE_GLH_Handle(h).handle = handle&&
DONT_USE_GLH_New_Texture_Handle = h