I finally broke down and above all understood how the little piece of _glLists works. It is important to note that when creating displaylists it is not enough to just place a texture on an object. It is also necessary to set the graphic position to the place where the next DisplayList will start to be rendered (using the glTranslatef command) - look to sub BuildFont.
This is not the program that didn't work for me, but a different one with the same command. And here was the breakthrough. I tried to comment everything in the program, there were a few things that gave me trouble (because I'm working with OpenGL only now, because there are many things with a question mark regarding implantation in QB64, for example calling the sub with the transfer of the field from QB64 to OpenGL caused me compilation error and it took me an hour to figure out why the compiler doesn't like it).
Like this. Its my bug, if I did it more often I would know, right? God Save QB64!
ZIP file contains: source code (mnrvovrfc will surely appreciate) and two textures. EXE file is not included. The letter sizes in the file names match
This is not the program that didn't work for me, but a different one with the same command. And here was the breakthrough. I tried to comment everything in the program, there were a few things that gave me trouble (because I'm working with OpenGL only now, because there are many things with a question mark regarding implantation in QB64, for example calling the sub with the transfer of the field from QB64 to OpenGL caused me compilation error and it took me an hour to figure out why the compiler doesn't like it).
Like this. Its my bug, if I did it more often I would know, right? God Save QB64!
ZIP file contains: source code (mnrvovrfc will surely appreciate) and two textures. EXE file is not included. The letter sizes in the file names match
Code: (Select All)
Declare CustomType Library
Sub gluBuild2DMipmaps (BYVAL Target As _Unsigned Long, BYVAL iFormat As Long, BYVAL Wdth As Long, BYVAL Hght As Long, BYVAL format As _Unsigned Long, BYVAL typ As _Unsigned Long, BYVAL dat As _Offset)
End Declare
_Title "_glLists and 2D & 3D in one"
Type GL_Loader
PointerGL As Long
TextureName As String
Filtering As _Unsigned _Byte
End Type
ReDim Shared GLL(0) As GL_Loader, t As Long
Dim Shared GL_InitInfo As _Byte
Dim Shared ExitSignal As _Byte, Blend As _Byte
'---------------------------------------------------
image$ = "font.gif"
Dim Shared Img(255) As Long
Dim Shared Textures(255) As Long
Dim Shared Baze, PreInit
Dim Shared Diamond As Long
Screen _NewImage(1024, 768, 32)
Do
_Limit 20
Loop
Sub _GL
Static cnt1, cnt2
Init2 'load images and create displaylists and textures
'drawing
_glClear _GL_COLOR_BUFFER_BIT And _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity 'matrix reset
'We'll select the texture created from bumps.bmp, move it five units inward, and rotate it by 45 on the Z axis. This clockwise rotation will give the appearance of a diamond instead of two squares.
_glMatrixMode _GL_PROJECTION ' Set projection matrix - TRY comment this five rows and then run it. Black screen occur. For view just something then must be depth set to -1 (Z parameter in _glTranslateF)
_glLoadIdentity ' Reset matrix
_gluPerspective 45.0F, _Width / _Height, 0.1F, 100.0F ' Perspective calculation
_glMatrixMode _GL_MODELVIEW ' set modelview matrix
_glBindTexture _GL_TEXTURE_2D, Diamond 'diamond texture select
_glTranslatef 0.0F, 0.0F, -5.0F ') shift to screen
_glRotatef 45.0F, 0.0F, 0.0F, 1.0F
'We will perform another rotation on the X and Y axes, which is dependent on the variable cnt1*30. It has the effect of rotating the object around, just as a diamond rotates in one place.
_glRotatef cnt1 * 30.0F, 1.0F, 1.0F, 0.0F ' Rotation in axis X and Y
'Since we want it to appear solid, we'll turn off blending and set the color to white. We will render a texture-mapped quadrilateral.
_glDisable _GL_BLEND 'disable blending
_glColor3f 1.0F, 1.0F, 1.0F 'white color
_glBegin _GL_QUADS 'quad drawing
_glTexCoord2d 0.0F, 0.0F
_glVertex2f -1.0F, 1.0F
_glTexCoord2d 1.0F, 0.0F
_glVertex2f 1.0F, 1.0F
_glTexCoord2d 1.0F, 1.0F
_glVertex2f 1.0F, -1.0F
_glTexCoord2d 0.0F, 1.0F
_glVertex2f -1.0F, -1.0F
_glEnd 'quad end
'Next, we rotate it by 90 degrees on the X and Y axes. We draw a quadrilateral again. This new one intersects the first drawn in the middle and is perpendicular to it (90 degrees). Nice symmetrical shape..
_glRotatef 90.0F, 1.0F, 1.0F, 0.0F 'rotation in axcis X and Y up to 90 degrees
_glBegin _GL_QUADS 'quad drawing
_glTexCoord2d 0.0F, 0.0F
_glVertex2f -1.0F, 1.0F
_glTexCoord2d 1.0F, 0.0F
_glVertex2f 1.0F, 1.0F
_glTexCoord2d 1.0F, 1.0F
_glVertex2f 1.0F, -1.0F
_glTexCoord2d 0.0F, 1.0F
_glVertex2f -1.0F, -1.0F
_glEnd 'quad end
'Let's turn on the blending and start writing the text.
_glEnable _GL_BLEND 'enable blending
_glLoadIdentity 'matrix reset
_glColor3f 1.0 * Cos(cnt1), 1.0 * Sin(cnt2), 1.0 - 0.5 * Cos(cnt1 + cnt2)
glPrint (280 + (250 * Cos(cnt1))), (235 + (200 * Sin(cnt2))), "NeHe", 0 'print text
_glColor3f 1.0 * Sin(cnt2), 1.0 - 0.5 * (Cos(cnt1 + cnt2)), 1.0 * Cos(cnt1)
glPrint (280 + (230 * Cos(cnt2))), (235 + (200 * Sin(cnt1))), "OpenGL", 1 'print text
_glColor3f .2 + Cos(cnt1), 0.7 * Sin(cnt2), Sin(cnt1 - cnt2)
glPrint (280 + (200 * Sin(cnt2))), (235 + (200 * Cos(cnt1))), "To QB64 rewrited Petr", 0 'print text
_glColor3f 0.0F, 0.0F, 1.0F 'blue color
glPrint (240 + (200 * Cos(cnt2 + cnt1) / 5)), 2, "Giuseppe D'Agata", 0 'first author this program
_glColor3f 1.0F, 1.0F, 1.0F 'white color
glPrint (242 + (200 * Cos(cnt2 + cnt1) / 5)), 2, "Giuseppe D'Agata", 0
cnt1 = cnt1 + 0.01
cnt2 = cnt2 + 0.0081
End Sub
Sub Init2
If GL_InitInfo = 0 Then
LoadCharactersFromImage "font.gif", 16, 16, Img&()
GL_InitInfo = 1
For MakeTexture = 0 To 255
Textures(MakeTexture) = LoadTexture_Array(Img&(MakeTexture), 2)
Next
BuildFont
Dim d(0) As Long
d(0) = _LoadImage("diam.png", 32)
Diamond = LoadTexture_Array(d(0), 1) 'this is how get around it so that don't have to add a loader from a file like in previous programs
_FreeImage d(0)
' u nej init GL
Exit Sub
End If
_glClearColor 0.0F, 0.0F, 0.0F, 0.0F 'black background
_glClearDepth 1.0 'depth buffer settings
_glDepthFunc _GL_LEQUAL 'depth testing type
_glBlendFunc _GL_SRC_ALPHA, _GL_ONE 'set blending type
_glShadeModel _GL_SMOOTH 'allow smooth shading
_glEnable _GL_TEXTURE_2D 'enable texture mapping
'---------------------
End Sub
Sub BuildFont
' Static Baze
Baze = _glGenLists(255) ' 256 display lists
For i& = 0 To 255
_glNewList Baze + i&, _GL_COMPILE
_glBindTexture _GL_TEXTURE_2D, Textures(i&)
_glBegin _GL_QUADS
a = -1: b = 0 'if is texture bad set, characters are then viewed more than 1x. (try rewrite b to 1)
c = 16
_glTexCoord2f a, b: _glVertex2i 0, c ' 0,15 levy horni <--- _glVertex2i use standard coordinates as in QB64
' dest source
'in case you want to map textures directly from one file, without them being pre-loaded as in this program, the procedure is as follows:
'1) you load the entire texture as one texture, let it be converted to a texture.
'2) then the _glTexCoord2f coordinates are calculated as: width of the image / number of pixels that are mapped to the rectangle - so in this case it is 16/256
'(the width of the image with letters is 256, the width of the letter is 16)
_glTexCoord2f b, b: _glVertex2i c, c '15,15 pravy horni 'glTexCoord2f cte takto: chces namapovat 16 pixelu z obrazku o width = 256 pixelu, tedy: 16/256 = 0.625
_glTexCoord2f b, a: _glVertex2i c, 0 '15, 0 pravy dolni
_glTexCoord2f a, a: _glVertex2i 0, 0 '0, 0 levy dolni
_glEnd
_glTranslatef 16, 0, 0 'shift to the place from where the next displaylist will be painted!
'you are here in RELATIVE coordinate system, therefore _glTranslatef here is for setting place from where is next display list draw. If you comment it, all characters comming to the same place.
_glEndList
Next i&
End Sub
Sub KillFont
_glDeleteLists Baze, 256
End Sub
Sub glPrint (Xpos, Ypos, S As String, set As _Unsigned _Byte)
If set > 0 Then set = 1 Else set = 0
_glBindTexture _GL_TEXTURE_2D, Textures(0) 'texture select
_glDisable _GL_DEPTH_TEST
_glMatrixMode _GL_PROJECTION 'matrix select
_glPushMatrix 'save projection matrix
_glLoadIdentity 'matrix reset
_glOrtho 0, _Width, 0, _Height, -1, 1 'Vertical projection settings
_glMatrixMode _GL_MODELVIEW 'matrix select
_glPushMatrix 'save matrix
_glLoadIdentity 'reset matrix
'shift to print position
_glTranslated Xpos, Ypos, 0 '
_glListBase (Baze - 32 + (128 * set)) 'set - set normal or italic characters
_glCallLists Len(S$), _GL_BYTE, _Offset(S$) 'so this little scum works as expected!
_glMatrixMode _GL_PROJECTION 'select projection matrix
_glPopMatrix 'Restoring a saved projection matrix
_glMatrixMode _GL_MODELVIEW 'select matrix modelview
_glPopMatrix 'restoring saved modelview matrix
_glEnable _GL_DEPTH_TEST 'enable depth testing
End Sub
Sub LoadCharactersFromImage (filename As String, xstep As Integer, ystep As Integer, img() As Long) 'standard QB64 - load small 16x16 icons from image font.gif and place it to img() array as images
If _FileExists(filename$) Then
I& = _LoadImage(filename$, 32)
If I& < -1 Then 'is supported image format
For y = 0 To _Height(I&) - ystep Step ystep
For x = 0 To _Width(I&) - xstep Step xstep
img&(imi) = _NewImage(xstep, ystep, 32)
_PutImage (0, 0)-(xstep, ystep), I&, img&(imi), (x, y)-(x + xstep, y + ystep)
imi = imi + 1
Next x
Next y
Else Print "This image file "; filename$; "is not in suported format.": System
End If
Else
Print "Error: File "; filename$; "not found.": System
End If
End Sub
Function LoadTexture_Array& (image As Long, filter) 'create textures from images
D = _Dest
S = _Source
texinv& = _NewImage(_Width(image&), _Height(image&), 32)
_PutImage (0, _Height(image&))-(_Width(image&), 0), image&, texinv&
ni& = _CopyImage(texinv&, 32)
Dim Texture As Long
_glGenTextures 1, _Offset(Texture) 'generate our texture handle (reserve place in memory for new texture)
_glBindTexture _GL_TEXTURE_2D, Texture 'select our texture handle (set this texture for use)
Dim m As _MEM
m = _MemImage(texinv&)
Dim n As _MEM
n = _MemImage(ni&)
Select Case filter
Case -1
'set our texture wrapping
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_S, _GL_REPEAT
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_T, _GL_REPEAT
Case 0
'set out texture filtering
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_NEAREST 'for scaling up
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST 'for scaling down
Case 1
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR 'for scaling up
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR 'for scaling down
Case 2 'works....not sure, if this output is correct
'gluBuild2DMipmaps(GL_TEXTURE_2D, pic->bpp/8, pic->width, pic->height, textureType, GL_UNSIGNED_BYTE, pic->data);
gluBuild2DMipmaps _GL_TEXTURE_2D, 4, 16, 16, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _Offset(Texture) 'need own memory block (n - MEM) in combination with m - MEM program crash... why? ? ? ? ? ?
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR_MIPMAP_NEAREST 'for scaling up
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR ' IF IS USED _GL_LINEAR_MIMAP_NEAREST here, texture is white. Is it correct? -?- just God know...
'
_glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _Width(ni&), _Height(ni&), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, n.OFFSET
_MemFree n
_FreeImage ni&
GoTo saveit
End Select
_glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _Width(texinv&), _Height(texinv&), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
saveit:
U = UBound(GLL)
GLL(U).PointerGL = Texture
GLL(U).TextureName = "ARRAY!"
GLL(U).Filtering = filter
ReDim _Preserve GLL(U + 1) As GL_Loader
_MemFree m
LoadTexture_Array& = Texture
_Dest D
_Source S
End Function