12-19-2025, 10:49 PM
A collection of subs, declares and consts for using OpenGL in QB64, made by the community and curated here for ease!
If youd like to add to the lib here are the RULES :
Prefix for commands and UDTS - GL_ (i.e, GL_Vertex, GL_Model etc...)
COMMENT your code
Provide a demo
USE the standardised GL types in making your UDTS
Here is a BASIC setup for handling GL in QB64...it contains the DECLARE LIBRARY bindings for the GLU bits we will need for perspective and ortho camera modes and textures.
Here is Galleons (slightly moded by me) texture loader. It automatically creates MipMaps too! (MipMaps are basically textures of differing levels of detail. GL automatically uses the best ones based on distance from the viewer, far way = less detail = FASTER!)
Please share anything youve got that can expand and reduce the FEAR of GL!
Unseen
If youd like to add to the lib here are the RULES :
Prefix for commands and UDTS - GL_ (i.e, GL_Vertex, GL_Model etc...)
COMMENT your code
Provide a demo
USE the standardised GL types in making your UDTS
Here is a BASIC setup for handling GL in QB64...it contains the DECLARE LIBRARY bindings for the GLU bits we will need for perspective and ortho camera modes and textures.
Code: (Select All)
'//////////////////////////////////////////////////////////////////////////////////////////////////////
CONST False = 0, True = 1
DIM SHARED Allow_GL AS _BYTE
'//////////////////////////////////////////////////////////////////////////////////////////////////////
SCREEN _NEWIMAGE(800, 600, 32)
_SCREENMOVE _MIDDLE
_DISPLAYORDER _GLRENDER , _SOFTWARE
Allow_GL = True
'//////////////////////////////////////////////////////////////////////////////////////////////////////
'// Main Loop
DO
CLS
IF _KEYDOWN(27) THEN EXIT DO
_LIMIT 60
_DISPLAY
LOOP
'//////////////////////////////////////////////////////////////////////////////////////////////////////
SUB _GL
IF Allow_GL = False THEN EXIT SUB
_GLCLEARCOLOR 0, 0, 0, 1
_GLCLEAR _GL_COLOR_BUFFER_BIT OR _GL_DEPTH_BUFFER_BIT
_GLLOADIDENTITY
_DISPLAY
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// GLU Lib Decleration
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DECLARE DYNAMIC LIBRARY "glu32"
SUB gluBuild2DMipmaps (BYVAL eg_GL_TEXTURE_2D&, BYVAL eg_GL_RGBA&, BYVAL sx&, BYVAL sy&, BYVAL eg_GL_RGBA&, BYVAL eg_GL_UNSIGNED_BYTE&, offset&)
SUB gluLookAt (BYVAL eyex#, BYVAL eyey#, BYVAL eyez#, BYVAL centerx#, BYVAL centery#, BYVAL centerz#, BYVAL upx#, BYVAL upy#, BYVAL upz#)
SUB gluOrtho2D (BYVAL left#, BYVAL right#, BYVAL bottom#, BYVAL top#)
END DECLARE
Here is Galleons (slightly moded by me) texture loader. It automatically creates MipMaps too! (MipMaps are basically textures of differing levels of detail. GL automatically uses the best ones based on distance from the viewer, far way = less detail = FASTER!)
Code: (Select All)
'//////////////////////////////////////////////////////////////////////////////////////////////////////
FUNCTION GL_MAKE_TEXTURE& (File&)
Sx% = _WIDTH(File&)
Sy% = _HEIGHT(File&)
DIM h AS LONG, LoadTexture_Buffer(Sx% * Sy%) AS LONG, LoadTexture_Buffer2(Sx% * Sy%) AS LONG
OldSrc& = _SOURCE
_SOURCE File&
GET (0, 0)-(Sx% - 1, Sy% - 1), LoadTexture_Buffer(0)
_SOURCE OldSrc&
FOR y% = 0 TO Sy% - 1
FOR x% = 0 TO Sx% - 1
clr~& = LoadTexture_Buffer(PXCnt&)
LoadTexture_Buffer2(PXCnt&) = ((clr~& \ 65536) AND 255) + (clr~& AND &HFF00&) + ((clr~& AND 255) * 65536)
PXCnt& = PXCnt& + 1
NEXT
NEXT
_GLGENTEXTURES 1, _OFFSET(h)
_GLBINDTEXTURE _GL_TEXTURE_2D, h
gluBuild2DMipmaps _GL_TEXTURE_2D, _GL_RGBA, Sx%, Sy%, _GL_RGBA, _GL_UNSIGNED_BYTE, LoadTexture_Buffer2(0)
_GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
_GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR_MIPMAP_LINEAR
GL_MAKE_TEXTURE = h
END FUNCTION
FUNCTION GL_Load_Texture& (FileName$)
GL_Load_Texture& = GL_MAKE_TEXTURE(_LOADIMAGE(FileName$, 32))
END FUNCTION
Please share anything youve got that can expand and reduce the FEAR of GL!
Unseen

