Posts: 250
Threads: 44
Joined: May 2022
Reputation:
28
I'll say straight away that I literally only passed very light OpenGL. Still, I have a few absolutely basic things to post here.
The first program is completely primitive. Draws a triangle and a square in 2D, without texture.
Code: (Select All) $Resize:On
Screen _NewImage(800, 600, 32)
Do While InKey$ <> Chr$(27)
_Limit 20
Loop
Sub _GL
_glViewport 0, 0, 800, 600
_glMatrixMode _GL_PROJECTION '// set projection matrix
_glLoadIdentity ' // Reset matrix
_gluPerspective 45.0F, 800 / 600, 0.1F, 100.0F ' claculate perspective
_glMatrixMode _GL_MODELVIEW ' set matrix _GL_MODELVIEW
_glLoadIdentity
_glShadeModel _GL_SMOOTH ' allow smooth shading
_glClearColor 0.0F, 0.0F, 0.0F, 0.5F
_glClearDepth 1.0F ' set depth buffer
_glEnable _GL_DEPTH_TEST ' allow depth testing
_glDepthFunc _GL_LEQUAL ' depth testing type
_glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ' set the best projection correction
_glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity ' matrix reset
' Sem kresli primitivy
_glTranslatef -1.5F, 0.0F, -6.0F 'Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glBegin _GL_TRIANGLES ' Begin draw triangle
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glEnd ' End draw triangle
_glTranslatef 3.0F, 0.0F, 0.0F ' we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a square
_glBegin _GL_QUADS ' Square draw begin
_glVertex3f -1.0F, 1.0F, 0.0F ' left upper point
_glVertex3f 1.0F, 1.0F, 0.0F ' right upper point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glEnd ' end draw square
End Sub
[size=1]182 / 5 000
[/size]
This source code shows how to draw a pyramid in color with blending colors on the walls, as well as how to draw a cube with walls of one color and how to rotate these objects.
Code: (Select All) $Resize:On
Screen _NewImage(800, 600, 32) '
Dim Shared rquad As _Float: rquad = 7
Dim Shared rtri As _Float: rtri = 7
Do While InKey$ <> Chr$(27)
_Limit 20
Loop
Sub _GL
_glViewport 0, 0, _Width, _Height
_glMatrixMode _GL_PROJECTION ' Set projection matrix
_glLoadIdentity ' Matrix reset
_gluPerspective 45.0F, _Width / _Height, 0.1F, 100.0F ' Perspective calculation
_glMatrixMode _GL_MODELVIEW ' set modelview matrix
_glLoadIdentity
_glShadeModel _GL_SMOOTH ' allow smooth shading
_glClearColor 0.0F, 0.0F, 0.0F, 0.5F
_glClearDepth 1.0F ' set depth buffer
_glEnable _GL_DEPTH_TEST ' allow depth testing
_glDepthFunc _GL_LEQUAL ' set depth testing method
_glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ' set nicest projection matrix
_glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity ' matrix reset
' draw primitives here
_glTranslatef -1.5F, 0.0F, -6.0F ' Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glRotatef rtri, 0.0F, 1.0F, 0.0F ' Rotate the triangle around the y-axis
_glBegin _GL_TRIANGLES ' The beginning of drawing the PYRAMID
_glColor3f 1.0F, 0.0F, 0.0F ' Red color (it is as _glColor3f Red, Green, Blue and values can be calculated as 1 / 255)
_glVertex3f 0.0F, 1.0F, 0.0F ' Upper point
_glColor3f 0.0F, 1.0F, 0.0F ' Green color
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point
_glColor3f 1.0F, 0.0F, 0.0F ' red color
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (right wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F 'left point (right wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' right point (right wall) '
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (rear wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' left point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'right point (rear wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (back wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'left point (left wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f -1.0F, -1.0F, 1.0F ' right point (left wall)
_glEnd 'triangle draw end
_glTranslatef 3.0F, 0.0F, 0.0F 'we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a quad
'FOR THE ENTIRE OBJECT IN ONE COLOR:
_glLoadIdentity ' we call it to align the X Y Z axes to the original direction, without it it would default to the previous rotated state
_glTranslatef 1.5F, 0.0F, -7.0F ' The displacement of the origin is higher than in a quad
_glRotatef rquad, 1.0F, 1.0F, 1.0F 'Rotate the quad around the x-axis
_glBegin _GL_QUADS ' begin draw quad
_glColor3f 0.0F, 1.0F, 0.0F ' green color
_glVertex3f 1.0F, 1.0F, -1.0F ' left upper point
_glVertex3f -1.0F, 1.0F, -1.0F ' right upper point
_glVertex3f -1.0F, 1.0F, 1.0F ' right bottom point
_glVertex3f 1.0F, 1.0F, 1.0F ' left bottom point
_glColor3f 1.0F, 0.5F, 0.0F ' orange color
_glVertex3f 1.0F, -1.0F, 1.0F ' right upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (bottom wall)
_glVertex3f 1.0F, -1.0F, -1.0F ' right bottm point (bottom wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 1.0F, 1.0F, 1.0F ' right upper point (front wall)
_glVertex3f -1.0F, 1.0F, 1.0F ' Left upper point (front wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point (front wall)
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point (front wall)
_glColor3f 1.0F, 1.0F, 0.0F ' yellow
_glVertex3f 1.0F, -1.0F, -1.0F ' right upper point (rear wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left upper point (rear wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left bottom point (rear wall)
_glVertex3f 1.0F, 1.0F, -1.0F ' right bottom point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, 1.0F, 1.0F ' right upper point (left wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left upper point (left wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (left wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' right bottom point (left wall)
_glColor3f 1.0F, 0.0F, 1.0F ' purple
_glVertex3f 1.0F, 1.0F, -1.0F ' right upper point (right wall)
_glVertex3f 1.0F, 1.0F, 1.0F ' left upper point (right wall)
_glVertex3f 1.0F, -1.0F, 1.0F 'Left bottom point (right wall)
_glVertex3f 1.0F, -1.0F, -1.0F 'Right bottom point (right wall)
_glEnd 'quad draw end
rtri = rtri + 0.52F 'Incrementing the angle of rotation of the triangle
rquad = rquad - 0.515F 'Incrementing the angle of rotation of the quad
'it is important to RESET THE AXES so that they are rotated to the basic setting (otherwise the X axis can move to the Y axis) using _glLoadIdentity,
'and it is EXTREMELY IMPORTANT to always move in the scene to the beginning of the scene using _glTranslateF
'moving the object in openGL is not done by recalculating _glVertex, but by moving the start of rendering using _glTranslatef
End Sub
More examples will follow.
Posts: 2
Threads: 0
Joined: Mar 2023
Reputation:
1
loved it!
Posts: 1,581
Threads: 59
Joined: Jul 2022
Reputation:
52
Posts: 250
Threads: 44
Joined: May 2022
Reputation:
28
Hi, @AshishKingdom, nice to see you here!
Posts: 250
Threads: 44
Joined: May 2022
Reputation:
28
Alphabet in OpenGL example.
This program create and display standard US characters using Open GL:
Code: (Select All) ' ESC for end
Restore bfont
Block = 96 * 16 '16 records x 95 lines in DATA block, font size is as in Bios 8 x 16 pixels
Dim Shared fontbios(Block) As _Unsigned _Byte
For loadarray = 0 To Block - 1
Read bios$
b$ = "&H" + Right$(bios$, 2)
fontbios(loadarray) = Val(b$)
Next
r = Timer + 10 'time delay to start effect
bfont:
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00: 'DATA (points) in HEX for character CHR$(32) (" ")
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x3c,0x3c,0x3c,0x18,0x00,0x00: ' for character CHR$(33) ("!")
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x66,0x66,0x66,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,0x00
Data 0x00,0x00,0x18,0x18,0x7c,0xc6,0x86,0x06,0x06,0x7c,0xc0,0xc2,0xc6,0x7c,0x18,0x18: 'by owerwriting this block you can create your own national
Data 0x00,0x00,0x00,0x00,0x86,0xc6,0x60,0x30,0x18,0x0c,0xc6,0xc2,0x00,0x00,0x00,0x00: 'character in OpenGL graphic. Its unlimited,it can be Japanese,
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xdc,0x76,0x38,0x6c,0x6c,0x38,0x00,0x00: 'or Chinese or Russian... How to create it demonstrate this
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x30,0x30,0x30,0x00: 'demo: http://www.glprogramming.com/red/chapter08.html
Data 0x00,0x00,0x00,0x00,0x0c,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x18,0x30,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x80,0xc0,0x60,0x30,0x18,0x0c,0x06,0x02,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x38,0x6c,0xc6,0xc6,0xd6,0xd6,0xc6,0xc6,0x6c,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x78,0x38,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc0,0x60,0x30,0x18,0x0c,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0x3c,0x06,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1e,0x0c,0x0c,0x0c,0xfe,0xcc,0x6c,0x3c,0x1c,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0xfc,0xc0,0xc0,0xc0,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xfc,0xc0,0xc0,0x60,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x18,0x0c,0x06,0x06,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0x7c,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0x0c,0x06,0x06,0x06,0x7e,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x06,0x0c,0x18,0x30,0x60,0x30,0x18,0x0c,0x06,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x0c,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc0,0xdc,0xde,0xde,0xde,0xc6,0xc6,0x7c,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfc,0x66,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3a,0x66,0xc6,0xc6,0xde,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0xcc,0xcc,0xcc,0x0c,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x6c,0x78,0x78,0x6c,0x66,0x66,0xe6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x60,0x60,0x60,0x60,0x60,0xf0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xd6,0xfe,0xfe,0xee,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xce,0xde,0xfe,0xf6,0xe6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x0e,0x0c,0x7c,0xde,0xd6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x6c,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0x06,0x0c,0x38,0x60,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x5a,0x7e,0x7e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xee,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0x6c,0x7c,0x38,0x38,0x7c,0x6c,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x3c,0x66,0x66,0x66,0x66,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc2,0x60,0x30,0x18,0x0c,0x86,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x02,0x06,0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x10
Data 0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0x30
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0x7c,0x0c,0x78,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0x66,0x66,0x66,0x66,0x6c,0x78,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0x6c,0x3c,0x0c,0x0c,0x1c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xfe,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0xf0,0x60,0x64,0x6c,0x38,0x00,0x00
Data 0x00,0x78,0xcc,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x66,0x76,0x6c,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x18,0x18,0x00,0x00
Data 0x00,0x3c,0x66,0x66,0x06,0x06,0x06,0x06,0x06,0x06,0x0e,0x00,0x06,0x06,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x6c,0x78,0x78,0x6c,0x66,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xd6,0xd6,0xd6,0xd6,0xfe,0xec,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf0,0x60,0x60,0x7c,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x1e,0x0c,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x66,0x76,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x0c,0x38,0x60,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1c,0x36,0x30,0x30,0x30,0x30,0xfc,0x30,0x30,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x3c,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x38,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf8,0x0c,0x06,0x7e,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0x60,0x30,0x18,0xcc,0xfe,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x0e,0x18,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x0e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x70,0x18,0x18,0x18,0x18,0x0e,0x18,0x18,0x18,0x70,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdc,0x76,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0xfe,0xc6,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00,0x00,0x00
_FullScreen
Do While InKey$ <> Chr$(27)
_Limit 25
Loop
Sub _GL Static
Shared r, rr
_glClearColor 0.0F, 0.0F, 0.0F, 0.0F 'backround color
_glPixelStorei _GL_UNPACK_ALIGNMENT, 1
_glViewport 0, 0, _DesktopWidth, _DesktopHeight
_glMatrixMode _GL_PROJECTION
_glLoadIdentity
_glOrtho 0, _DesktopWidth, 0, _DesktopHeight, -1, 1 'coordinates maping (translate from -1....1 to 0....._DESKTOP....)
onDisplay
If Timer > r Then rr = rr + .1
End Sub
Sub drawString (red As _Float, green As _Float, blue As _Float, x As Integer, y As Integer, char As String)
Shared rr
_glColor3f red, green, blue ' set color for string.
_glRasterPos2i x, y ' set coordinates position for first character in string
For v = 1 To Len(char$) ' I read every character from string as one character and searching record with number as is ASC this character
cha$ = Left$(Mid$(char$, v), 1)
If Asc(cha$) >= 32 And Asc(cha$) <= 128 Then ' if ASC this character > 32 (DATA contains US characters ASC from 32 to 128)
For search = LBound(fontbios) To UBound(fontbios) Step 16 ' Every record contains info about 16 points for character, start for it is every 16 step
If Asc(cha$) - 32 = search / 16 Then ' in array is 16 record for every character. Its record for every point.
_glBitmap 8, 16, rr + 0.0F, 0.0 - rr, 9.0 - rr, rr + 0.0F, _Offset(fontbios(search)) 'erase rr or comment line 128 to delete effect in the end.
End If
Next search
End If
Next v
End Sub
Sub onDisplay
_glClear _GL_COLOR_BUFFER_BIT '
drawString 1.0F, 0.0F, 0.1F, 10, 10, "abcdefghijklmnopqrstuvwxyz"
drawString 0.7F, 0.0F, 0.4F, 10, 26, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
drawString 0.4F, 0.0F, 0.7F, 10, 42, "0123456789-=`~_+,./?;':|\\"
drawString 0.1F, 0.0F, 1.0F, 10, 58, "!@#$%^&*()[]{}<>"
drawString 1.0F, 1.0F, 1.0F, 100, 100, "hello world"
drawString 1.0F, 0.3F, .34F, _DesktopWidth / 2 - (11 * 8), _DesktopHeight / 2 - 4, "For Q64 community Petr"
_glFlush
End Sub
Next program (is not OpenGL program, but it is QB64 program) explains how the characters that were displayed in the previous case are stored using binary notation in the DATA block in the previous program (understanding will help to be able to change the characters as you need)
Code: (Select All) 'about gluBITMAP without openGL (how it works)
ReDim x, y, cx, cy
array = 96 * 16 ' bytes in DATA, total DATA size
arraysize = array / 2 ' is readed by two bytes, we needed only half lopp and because in OpneGl is begin in left downer corner, is next FOR NEXT loop writed as you see
Type GLB
od As String * 8
do As String * 8
End Type
Dim Shared GLB(arraysize) As GLB
Screen _NewImage(1024, 768, 256)
For pole = 0 To arraysize - 1
Read hodnotaOD$, hodnotaDO$
valueOD = Val("&H" + Right$(hodnotaOD$, 2))
valueDO = Val("&H" + Right$(hodnotaDO$, 2))
GLB(pole).od = DECtoBIN$(valueOD): GLB(pole).do = DECtoBIN$(valueDO) 'this convert values from DATA block to QB64 usable form - from 0x00 to 00 - then DecToBin convert byte 0 to bites
Next pole ' GLB(pole).od contains odd rows, GLB(pole).do contains even rows, both saved as string
_FullScreen
Print "Text output: (it show you, how are chacters created in binary form. Press any key)" '
Sleep
For pole = arraysize To 0 Step -1 '
A$ = GLB(pole).do: B$ = GLB(pole).od '
For poda = 1 To 8 '
At$ = Left$(Mid$(A$, poda), 1)
Bt$ = Left$(Mid$(B$, poda), 1) '
' Two block FOR: First create upper image for character (1x8 pixels) [odd row]
If At$ = "1" Then Color 5: Print At$; Else Color 7: Print At$; ' Second crete downer image for character (1x8 pixels) [even row]
Color 9 ' characters image format in DATA is font width = 8 pixels, font height = 16 pixels.
Next poda
Print
For pod = 1 To 8
Bt$ = Left$(Mid$(B$, pod), 1)
If Bt$ = "1" Then Color 5: Print Bt$; Else Color 7: Print Bt$;
Color 9
Next pod
_Delay .05
Print
If pole Mod 8 = 0 Then
Print "--------": Locate , 1
Print "Press key...": Sleep
Print
End If
Next pole
Print
Print "Press key..."
Sleep
t:
Cls
Color 7
Print "Graphic output:"
y = 50
x = 50
For pole = arraysize To 0 Step -1
For pod = 1 To 8
A$ = Left$(Mid$(GLB(pole).do, pod), 1)
x = x + 1
If A$ = "1" Then PSet (x + cx, y + cy)
'x = x + 1
Next pod
y = y + 1
x = 0
For pod = 1 To 8
A$ = Left$(Mid$(GLB(pole).od, pod), 1)
x = x + 1
If A$ = "1" Then PSet (x + cx, y + cy)
'x = x + 1
Next pod
x = 0
y = y + 1
If pole Mod 8 = 0 Then cx = cx + 12: cy = cy - 16
If cx > _Width - 20 Then cx = 0: cy = cy + 16
Next pole
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00: 'DATA (points) in HEX for character CHR$(32) (" ")
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x3c,0x3c,0x3c,0x18,0x00,0x00: ' for character CHR$(33) ("!")
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x66,0x66,0x66,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,0x00
Data 0x00,0x00,0x18,0x18,0x7c,0xc6,0x86,0x06,0x06,0x7c,0xc0,0xc2,0xc6,0x7c,0x18,0x18: 'by owerwriting this block you can create your own national
Data 0x00,0x00,0x00,0x00,0x86,0xc6,0x60,0x30,0x18,0x0c,0xc6,0xc2,0x00,0x00,0x00,0x00: 'character in OpenGL graphic. Its unlimited,it can be Japanese,
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xdc,0x76,0x38,0x6c,0x6c,0x38,0x00,0x00: 'or Chinese or Russian... How to create it demonstrate this
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x30,0x30,0x30,0x00: 'demo: http://www.glprogramming.com/red/chapter08.html
Data 0x00,0x00,0x00,0x00,0x0c,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x18,0x30,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x80,0xc0,0x60,0x30,0x18,0x0c,0x06,0x02,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x38,0x6c,0xc6,0xc6,0xd6,0xd6,0xc6,0xc6,0x6c,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x78,0x38,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc0,0x60,0x30,0x18,0x0c,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0x3c,0x06,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1e,0x0c,0x0c,0x0c,0xfe,0xcc,0x6c,0x3c,0x1c,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0xfc,0xc0,0xc0,0xc0,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xfc,0xc0,0xc0,0x60,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x18,0x0c,0x06,0x06,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0x7c,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0x0c,0x06,0x06,0x06,0x7e,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x06,0x0c,0x18,0x30,0x60,0x30,0x18,0x0c,0x06,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x0c,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc0,0xdc,0xde,0xde,0xde,0xc6,0xc6,0x7c,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfc,0x66,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3a,0x66,0xc6,0xc6,0xde,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0xcc,0xcc,0xcc,0x0c,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x6c,0x78,0x78,0x6c,0x66,0x66,0xe6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x60,0x60,0x60,0x60,0x60,0xf0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xd6,0xfe,0xfe,0xee,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xce,0xde,0xfe,0xf6,0xe6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x0e,0x0c,0x7c,0xde,0xd6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x6c,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0x06,0x0c,0x38,0x60,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x5a,0x7e,0x7e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xee,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0x6c,0x7c,0x38,0x38,0x7c,0x6c,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x3c,0x66,0x66,0x66,0x66,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc2,0x60,0x30,0x18,0x0c,0x86,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x02,0x06,0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x10
Data 0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0x30
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0x7c,0x0c,0x78,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0x66,0x66,0x66,0x66,0x6c,0x78,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0x6c,0x3c,0x0c,0x0c,0x1c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xfe,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0xf0,0x60,0x64,0x6c,0x38,0x00,0x00
Data 0x00,0x78,0xcc,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x66,0x76,0x6c,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x18,0x18,0x00,0x00
Data 0x00,0x3c,0x66,0x66,0x06,0x06,0x06,0x06,0x06,0x06,0x0e,0x00,0x06,0x06,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x6c,0x78,0x78,0x6c,0x66,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xd6,0xd6,0xd6,0xd6,0xfe,0xec,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf0,0x60,0x60,0x7c,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x1e,0x0c,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x66,0x76,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x0c,0x38,0x60,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1c,0x36,0x30,0x30,0x30,0x30,0xfc,0x30,0x30,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x3c,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x38,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf8,0x0c,0x06,0x7e,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0x60,0x30,0x18,0xcc,0xfe,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x0e,0x18,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x0e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x70,0x18,0x18,0x18,0x18,0x0e,0x18,0x18,0x18,0x70,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdc,0x76,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0xfe,0xc6,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00,0x00,0x00
Function DECtoBIN$ (vstup) 'DEC to BIN ok vystup je string, vstup je integer decimal to binary number convertor - FROM QB64WIKI
Shared BINARY$
' BINARY$ = ""
For rj = 7 To 0 Step -1
If vstup And 2 ^ rj Then BINtoDE$ = BINtoDE$ + "1" Else BINtoDE$ = BINtoDE$ + "0"
Next rj
DECtoBIN$ = BINtoDE$
End Function
If you rush into editing records in the DATA block, notice the way the bit position in the byte is written, what is shown on the left on the monitor is the first bit, i.e. the eighth from the left after the byte is broken down into bite and if we count from one. Also note that since the DATA block is for open GL, the line positions are read from end to begin, i.e. bottom to top. Ascii table with binary decomposition will come in handy for modification - next program.
Code: (Select All) Screen _NewImage(1980, 1050, 32)
X = 1
Y = 1
_ControlChr Off
For A = 0 To 255
Locate Y + 0, X: Print "----------------"
Locate Y + 1, X: Print "ASC:"; Str$(A); " CHR$:"; Chr$(A)
Locate Y + 2, X: Print "HEX$:"; Hex$(A); " OCT$:"; Oct$(A)
Locate Y + 3, X: Print "Binary: "; DECtoBIN$(A)
Locate Y + 4, X: Print "----------------"
Y = Y + 5
If Y = 61 Then
Y = 1
X = X + 18
End If
If A = 155 Then
Print "Press key..."
Sleep
Cls
X = 1
End If
Next
Function DECtoBIN$ (vstup) 'DEC to BIN ok vystup je string, vstup je integer decimal to binary number convertor - FROM QB64WIKI
Shared BINARY$
' BINARY$ = ""
For rj = 7 To 0 Step -1
If vstup And 2 ^ rj Then BINtoDE$ = BINtoDE$ + "1" Else BINtoDE$ = BINtoDE$ + "0"
Next rj
DECtoBIN$ = BINtoDE$
End Function
This program will print out the hexadecimal and binary form of the values in an ascii table, so that a completely new character can be created by suitable composition.
For example - let's say I want to use a symbol that doesn't appear in the ascii table - I just want to draw a rectangle in the entire cell - that means set all the pixels on the edges to 1. The first one will be written 0xff - that's CHR 255, which is 11111111 in binary - so the entire bottom of the cell will be colored. Now I want to lighten the borders in the cell up to the penultimate row, so I'll choose 0x81, that's CHR 129, which is 10000001 in binary, so the left and right borders will be lit. I put that in there 14 times because the characters are 16 pixels tall. And in the last place, I insert the top line, again 0xff, to light up the entire row:
Code: (Select All) 'about gluBITMAP without openGL (how it works)
ReDim x, y, cx, cy
array = 96 * 16 ' bytes in DATA, total DATA size
arraysize = array / 2 ' is readed by two bytes, we needed only half lopp and because in OpneGl is begin in left downer corner, is next FOR NEXT loop writed as you see
Type GLB
od As String * 8
do As String * 8
End Type
Dim Shared GLB(arraysize) As GLB
Screen _NewImage(1024, 768, 256)
For pole = 0 To arraysize - 1
Read hodnotaOD$, hodnotaDO$
valueOD = Val("&H" + Right$(hodnotaOD$, 2))
valueDO = Val("&H" + Right$(hodnotaDO$, 2))
GLB(pole).od = DECtoBIN$(valueOD): GLB(pole).do = DECtoBIN$(valueDO) 'this convert values from DATA block to QB64 usable form - from 0x00 to 00 - then DecToBin convert byte 0 to bites
Next pole ' GLB(pole).od contains odd rows, GLB(pole).do contains even rows, both saved as string
_FullScreen
Print "Text output: (it show you, how are chacters created in binary form. Press any key)" '
Sleep
For pole = arraysize To 0 Step -1 '
A$ = GLB(pole).do: B$ = GLB(pole).od '
For poda = 1 To 8 '
At$ = Left$(Mid$(A$, poda), 1)
Bt$ = Left$(Mid$(B$, poda), 1) '
' Two block FOR: First create upper image for character (1x8 pixels) [odd row]
If At$ = "1" Then Color 5: Print At$; Else Color 7: Print At$; ' Second crete downer image for character (1x8 pixels) [even row]
Color 9 ' characters image format in DATA is font width = 8 pixels, font height = 16 pixels.
Next poda
Print
For pod = 1 To 8
Bt$ = Left$(Mid$(B$, pod), 1)
If Bt$ = "1" Then Color 5: Print Bt$; Else Color 7: Print Bt$;
Color 9
Next pod
_Delay .05
Print
If pole Mod 8 = 0 Then
Print "--------"
Print "Press key...": Sleep
Print
End If
Next pole
Print
Print "Press key..."
Sleep
t:
Cls
Color 7
Print "Graphic output:"
y = 50
x = 50
For pole = arraysize To 0 Step -1
For pod = 1 To 8
A$ = Left$(Mid$(GLB(pole).do, pod), 1)
x = x + 1
If A$ = "1" Then PSet (x + cx, y + cy)
'x = x + 1
Next pod
y = y + 1
x = 0
For pod = 1 To 8
A$ = Left$(Mid$(GLB(pole).od, pod), 1)
x = x + 1
If A$ = "1" Then PSet (x + cx, y + cy)
'x = x + 1
Next pod
x = 0
y = y + 1
If pole Mod 8 = 0 Then cx = cx + 12: cy = cy - 16
If cx > _Width - 20 Then cx = 0: cy = cy + 16
Next pole
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00: 'DATA (points) in HEX for character CHR$(32) (" ")
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x3c,0x3c,0x3c,0x18,0x00,0x00: ' for character CHR$(33) ("!")
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x66,0x66,0x66,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,0x00
Data 0x00,0x00,0x18,0x18,0x7c,0xc6,0x86,0x06,0x06,0x7c,0xc0,0xc2,0xc6,0x7c,0x18,0x18: 'by owerwriting this block you can create your own national
Data 0x00,0x00,0x00,0x00,0x86,0xc6,0x60,0x30,0x18,0x0c,0xc6,0xc2,0x00,0x00,0x00,0x00: 'character in OpenGL graphic. Its unlimited,it can be Japanese,
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xdc,0x76,0x38,0x6c,0x6c,0x38,0x00,0x00: 'or Chinese or Russian... How to create it demonstrate this
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x30,0x30,0x30,0x00: 'demo: http://www.glprogramming.com/red/chapter08.html
Data 0x00,0x00,0x00,0x00,0x0c,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x18,0x30,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x80,0xc0,0x60,0x30,0x18,0x0c,0x06,0x02,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x38,0x6c,0xc6,0xc6,0xd6,0xd6,0xc6,0xc6,0x6c,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x78,0x38,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc0,0x60,0x30,0x18,0x0c,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0x3c,0x06,0x06,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1e,0x0c,0x0c,0x0c,0xfe,0xcc,0x6c,0x3c,0x1c,0x0c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x06,0x06,0x06,0xfc,0xc0,0xc0,0xc0,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xfc,0xc0,0xc0,0x60,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x18,0x0c,0x06,0x06,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0x7c,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0x0c,0x06,0x06,0x06,0x7e,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x30,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x06,0x0c,0x18,0x30,0x60,0x30,0x18,0x0c,0x06,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x0c,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc0,0xdc,0xde,0xde,0xde,0xc6,0xc6,0x7c,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfc,0x66,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x68,0x78,0x68,0x62,0x66,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3a,0x66,0xc6,0xc6,0xde,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x78,0xcc,0xcc,0xcc,0x0c,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x6c,0x78,0x78,0x6c,0x66,0x66,0xe6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0x66,0x62,0x60,0x60,0x60,0x60,0x60,0x60,0xf0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xd6,0xfe,0xfe,0xee,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xce,0xde,0xfe,0xf6,0xe6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x0e,0x0c,0x7c,0xde,0xd6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x6c,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0x06,0x0c,0x38,0x60,0xc6,0xc6,0x7c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x5a,0x7e,0x7e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xee,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xc6,0x6c,0x7c,0x38,0x38,0x7c,0x6c,0xc6,0xc6,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x3c,0x66,0x66,0x66,0x66,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0xc2,0x60,0x30,0x18,0x0c,0x86,0xc6,0xfe,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x02,0x06,0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x10
Data 0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0x30
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0x7c,0x0c,0x78,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0x66,0x66,0x66,0x66,0x6c,0x78,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0x6c,0x3c,0x0c,0x0c,0x1c,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xfe,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0xf0,0x60,0x64,0x6c,0x38,0x00,0x00
Data 0x00,0x78,0xcc,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x66,0x66,0x66,0x76,0x6c,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x18,0x18,0x00,0x00
Data 0x00,0x3c,0x66,0x66,0x06,0x06,0x06,0x06,0x06,0x06,0x0e,0x00,0x06,0x06,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xe6,0x66,0x6c,0x78,0x78,0x6c,0x66,0x60,0x60,0xe0,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x38,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0xd6,0xd6,0xd6,0xd6,0xfe,0xec,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf0,0x60,0x60,0x7c,0x66,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x1e,0x0c,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xf0,0x60,0x60,0x60,0x66,0x76,0xdc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x7c,0xc6,0x0c,0x38,0x60,0xc6,0x7c,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x1c,0x36,0x30,0x30,0x30,0x30,0xfc,0x30,0x30,0x10,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x3c,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x6c,0xfe,0xd6,0xd6,0xd6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x38,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0xf8,0x0c,0x06,0x7e,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0xfe,0xc6,0x60,0x30,0x18,0xcc,0xfe,0x00,0x00,0x00,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x0e,0x18,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x0e,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x70,0x18,0x18,0x18,0x18,0x0e,0x18,0x18,0x18,0x70,0x00,0x00
Data 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xdc,0x76,0x00,0x00
'Data 0x00,0x00,0x00,0x00,0x00,0xfe,0xc6,0xc6,0xc6,0x6c,0x38,0x10,0x00,0x00,0x00,0x00
Data 0xff,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xff
Function DECtoBIN$ (vstup) 'DEC to BIN ok vystup je string, vstup je integer decimal to binary number convertor - FROM QB64WIKI
Shared BINARY$
' BINARY$ = ""
For rj = 7 To 0 Step -1
If vstup And 2 ^ rj Then BINtoDE$ = BINtoDE$ + "1" Else BINtoDE$ = BINtoDE$ + "0"
Next rj
DECtoBIN$ = BINtoDE$
End Function
Do not forget that we read the data from the end, therefore only the last line in the DATA block was modified, therefore the rectangle appears immediately as the first character.
Posts: 64
Threads: 12
Joined: Apr 2022
Reputation:
5
DON'T STOP! Keep it up!
Ashish ( https://ashishkingdom.github.io/OpenGL-Tutorials/intro/ ) had great stuff but didn't keep going.
I'll be looking forward to your posts. Didactic! Thanks!
___________________________________________________________________________________
I am mostly grateful for the people who came before me. Will the people after me be grateful for me?
Posts: 1,270
Threads: 118
Joined: Apr 2022
Reputation:
100
(03-29-2023, 03:35 PM)dcromley Wrote: DON'T STOP! Keep it up!
Ashish ( https://ashishkingdom.github.io/OpenGL-Tutorials/intro/ ) had great stuff but didn't keep going.
I'll be looking forward to your posts. Didactic! Thanks!
That tutorial is off to a GREAT start! I would love to see it finished so I can point my tutorial users to it.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 2
Threads: 0
Joined: Mar 2023
Reputation:
1
I will try to start working on OpenGL Tutorials again this summer..!
Posts: 250
Threads: 44
Joined: May 2022
Reputation:
28
03-31-2023, 02:31 PM
(This post was last modified: 03-31-2023, 02:42 PM by Petr.)
I'm glad to hear that, your tutorial is worked out nicely and clearly, and a lot of details always come in handy. If you keep the format you started, it will be great.
Here is a sample - the first texture. I wrote a function for maximum simplification and I immediately solved the freeing of memory when the program was terminated, and I added an example with DisplayOrder to make it clear how the layers of the image are rendered one after the other.
Please use correct file name on row 34.
Code: (Select All) Type GL_Loader
PointerGL As Long
End Type
ReDim Shared GLL(0) As GL_Loader
Dim Shared GL_InitInfo As _Byte
_Title "Use texture!"
Screen _NewImage(600, 600, 32)
Dim Shared t 'bad solution, it is just for this use
_DisplayOrder _GLRender , _Software 'in background run OpenGL screen, in foreground run Software (QB64 standard) screen
Do
Locate 1
Print Time$
_Limit 40
If _Exit Then
'if program end, this is step 2. Step 1 is in _GL Sub, in this place program just end.
System
End If
Loop
Sub _GL ()
if t = 0 then t = LoadTexture("dum03.jpg") 'function load texture from valid file and return OpenGL Handle for this texture
_glEnable _GL_TEXTURE_2D 'enable texture mapping
_glClearColor 0, 0, 0, 1 'set color to solid black - here it is in range 0 to 1 - in QB64 it is in range 0 to 255, so 0.5 here is the same as 127 in QB64
_glClear _GL_COLOR_BUFFER_BIT
_glBindTexture _GL_TEXTURE_2D, t '<--------------- this handle is used here
_glBegin _GL_QUADS 'simply draw a quad
_glTexCoord2f 0, 1
_glVertex2f -0.5, 0.5 'top-left
_glTexCoord2f 1, 1
_glVertex2f 0.5, 0.5 'top-right
_glTexCoord2f 1, 0
_glVertex2f 0.5, -0.5 'bottom right
_glTexCoord2f 0, 0
_glVertex2f -0.5, -0.5 'bottom left
_glEnd
_glFlush
If _Exit Then
DeleteTexture t 'if program end, first free texture from memory, then exit from GL and return to main loop
Exit Sub
End If
End Sub
Sub GL_Init
If GL_InitInfo = 0 Then
_glViewport 0, 0, _Width, _Height
GL_InitInfo = 1
End If
End Sub
Sub DeleteTexture (nr As Long)
For P = LBound(GLL) To UBound(GLL)
If GLL(P).PointerGL = nr Then
Dim DEL As Long
DEL = GLL(P).PointerGL
_glDeleteTextures 1, _Offset(DEL)
Exit Sub
End If
Next
End Sub
Function LoadTexture (image As String)
If GL_InitInfo = 0 Then GL_Init
If _FileExists(image) Then
tex& = _LoadImage(image$, 32)
texinv& = _NewImage(_Width(tex&), _Height(tex&), 32)
_PutImage (0, _Height(tex&) - 1)-(_Width(tex&) - 1, 0), tex&, texinv&
_FreeImage tex&
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&)
_glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _Width(texinv&), _Height(texinv&), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
U = UBound(GLL)
GLL(U).PointerGL = Texture
ReDim _Preserve GLL(U + 1) As GL_Loader
_MemFree m
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_S, _GL_REPEAT
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_T, _GL_REPEAT
'set out texture filtering
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_NICEST 'for scaling up
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST 'for scaling down
Else
Print "LoadTexture Error: "; image$; " - file not found."
End If
LoadTexture = Texture
End Function
Posts: 250
Threads: 44
Joined: May 2022
Reputation:
28
03-31-2023, 03:12 PM
(This post was last modified: 03-31-2023, 03:13 PM by Petr.)
Another sample with texture - this time in combination with the colors from the previous examples. Texture and color gradient can be combined. I made an adjustment in the LoadTexture sub, because writing IF t = 0 Then... seems silly to me. So for now, I solved the memory leak protection so that if the program tries to load the same texture again (that is, a file with the same name) that already has a texture assigned, then the LoadTexture function returns the original handle to the already created texture, without recreated this texture as new in memory. I am aware that this solution will be a significant drag in complex programs, so I will think about an improvement.
Code: (Select All) Type GL_Loader
PointerGL As Long
TextureName As String
End Type
ReDim Shared GLL(0) As GL_Loader, t As Long
Dim Shared GL_InitInfo As _Byte
Dim Shared ExitSignal As _Byte
_Title "Use texture!"
Screen _NewImage(600, 600, 32)
_DisplayOrder _GLRender , _Software 'in background run OpenGL screen, in foreground run Software (QB64 standard) screen
Do
Locate 1
Print Time$
If ExitSignal Then System
_Limit 40
Loop
Sub _GL ()
t = LoadTexture("dum03.jpg") 'function load texture from valid file and return OpenGL Handle for this texture,
' if handle exists, return it and do not next.
_glEnable _GL_TEXTURE_2D 'enable texture mapping
_glClearColor 0, 0, 0, 1 'set color to solid black - here it is in range 0 to 1 - in QB64 it is in range 0 to 255, so 0.5 here is the same as 127 in QB64
_glClear _GL_COLOR_BUFFER_BIT
_glBindTexture _GL_TEXTURE_2D, t '<--------------- this handle is used here
_glBegin _GL_QUADS 'simply draw a quad
_glTexCoord2f 0, 1
_glColor3f 1.0F, 0.0F, 0.0F
_glVertex2f -0.5, 0.5 'top-left
_glTexCoord2f 1, 1
_glColor3f 0.0F, 0.5F, 0.0F
_glVertex2f 0.5, 0.5 'top-right
_glTexCoord2f 1, 0
_glColor3f 1.0F, 1.0F, 0.0F
_glVertex2f 0.5, -0.5 'bottom right
_glTexCoord2f 0, 0
_glColor3f 0.3F, 0.0F, 0.5F
_glVertex2f -0.5, -0.5 'bottom left
_glEnd
_glFlush
If _Exit Then
DeleteTexture t 'if program end, first free texture from memory, then exit from GL and return to main loop
_glClear _GL_COLOR_BUFFER_BIT
ExitSignal = Not 0
Exit Sub
End If
End Sub
Sub GL_Init
If GL_InitInfo = 0 Then
_glViewport 0, 0, _Width, _Height
GL_InitInfo = 1
End If
End Sub
Sub DeleteTexture (nr As Long)
For P = LBound(GLL) To UBound(GLL)
If GLL(P).PointerGL = nr Then
Dim DEL As Long
DEL = GLL(P).PointerGL
_glDeleteTextures 1, _Offset(DEL)
Exit Sub
End If
Next
End Sub
Function LoadTexture (image As String)
If GL_InitInfo = 0 Then GL_Init
If _FileExists(image) Then
TT = 0
Do Until TT = UBound(GLL)
If GLL(TT).TextureName = image$ Then
LoadTexture = GLL(TT).PointerGL 'prevent memory leak loading next and next texture again and angain...
Exit Function
End If
TT = TT + 1
Loop
tex& = _LoadImage(image$, 32)
texinv& = _NewImage(_Width(tex&), _Height(tex&), 32)
_PutImage (0, _Height(tex&) - 1)-(_Width(tex&) - 1, 0), tex&, texinv&
_FreeImage tex&
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&)
_glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _Width(texinv&), _Height(texinv&), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
U = UBound(GLL)
GLL(U).PointerGL = Texture
GLL(U).TextureName = image
ReDim _Preserve GLL(U + 1) As GL_Loader
_MemFree m
'set our texture wrapping
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_S, _GL_REPEAT
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_WRAP_T, _GL_REPEAT
'set out texture filtering
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_NICEST 'for scaling up
_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST 'for scaling down
Else
Print "LoadTexture Error: "; image$; " - file not found."
End If
LoadTexture = Texture
End Function
|