11-06-2025, 03:13 PM
I think many people want to get into 3D ,OpenGL programming, but they don't know how to start.
UnseenMachine opened my eyes to a fast rendering option called "GL_LIST".
To understand how it works, I wrote myself a rudimentary drawing that uses GL_LIST.
If someone wants to start, it's worth building on this scheme to start with.
-There is a space!
-We are in this space somewhere. We can use _gltranslatef to determine where (this is a shift). Where are we looking? _glrotatef .
-What do we see?
Everything that is a triangle between _glbegin and _glend. Color+3 vertices, this will form a triangle in space. The number of vertices can be any. This way, any shape can be described with many triangles.
There is no need to reply to this post. This is just an inspiration. It shows how simple it is. Of course, there are many other things besides that, textures, light, and lots of adjustment options. But if you understand how this short code works, everything comes easily from there. So if you understand how this works, you can easily add it later. Of course, you need a little spatial insight, but I think anyone who deals with programming is born with it.
A tip that I write from experience: if you are really interested in 3D, then don't build on _maptriangle .! You have to write a lot of coordinate transformations yourself! OpenGL provides easy options to easily rotate/translate/scale without more complicated mathematics.
I know from experience that at first it is really difficult and incomprehensible. But once you start, the thing sucks you in, and you can't stop with it, and suddenly you understand the whole thing.
UnseenMachine opened my eyes to a fast rendering option called "GL_LIST".
To understand how it works, I wrote myself a rudimentary drawing that uses GL_LIST.
If someone wants to start, it's worth building on this scheme to start with.
-There is a space!
-We are in this space somewhere. We can use _gltranslatef to determine where (this is a shift). Where are we looking? _glrotatef .
-What do we see?
Everything that is a triangle between _glbegin and _glend. Color+3 vertices, this will form a triangle in space. The number of vertices can be any. This way, any shape can be described with many triangles.
There is no need to reply to this post. This is just an inspiration. It shows how simple it is. Of course, there are many other things besides that, textures, light, and lots of adjustment options. But if you understand how this short code works, everything comes easily from there. So if you understand how this works, you can easily add it later. Of course, you need a little spatial insight, but I think anyone who deals with programming is born with it.

A tip that I write from experience: if you are really interested in 3D, then don't build on _maptriangle .! You have to write a lot of coordinate transformations yourself! OpenGL provides easy options to easily rotate/translate/scale without more complicated mathematics.
I know from experience that at first it is really difficult and incomprehensible. But once you start, the thing sucks you in, and you can't stop with it, and suddenly you understand the whole thing.
Code: (Select All)
Dim Shared mon, gl_counter
Dim Shared gl_list_c, gl_list(10)
mon = _NewImage(800, 600, 32)
Screen mon
_DisplayOrder _GLRender , _Software
Do: _Limit 25
_Display
If InKey$ = Chr$(27) Then System
Loop
Sub _GL () Static
gl_counter = gl_counter + 1
_glMatrixMode _GL_PROJECTION
_glLoadIdentity
_gluPerspective 60, _Width(mon) / _Height(mon), .02, 20
_glMatrixMode _GL_MODELVIEW
_glClear _GL_COLOR_BUFFER_BIT Or _GL_DEPTH_BUFFER_BIT
_glLoadIdentity
_glTranslatef Sin(Timer), 0.0, -3.0
render_red_triangle
_glLoadIdentity
_glTranslatef Sin(Timer + 3.1415 / 2), 0.0, -3.0
render_blue_triangle
_glFlush
End Sub
Sub render_red_triangle
Static insub_gllist As Long
Static gl_list_created
If gl_list_created Then
_glCallList insub_gllist
Else
insub_gllist = _glGenLists(1)
_glNewList insub_gllist, _GL_COMPILE
_glBegin _GL_TRIANGLES
_glColor3f 1.0, 0.0, 0.0 ' red
_glVertex3f 0.0, 1.0, 0.0 ' top point
_glVertex3f -1.0, -1.0, 0.0 ' left point
_glVertex3f 1.0, -1.0, 0.0 ' right point
_glEnd
_glEndList
gl_list_created = 1
End If
End Sub
Sub render_blue_triangle
Static insub_gllist As Long
Static gl_list_created
If gl_list_created Then
_glCallList insub_gllist
Else
insub_gllist = _glGenLists(1)
_glNewList insub_gllist, _GL_COMPILE
_glBegin _GL_TRIANGLES
_glColor3f 0.0, 0.0, 1.0 ' blue
_glVertex3f 0.0, 1.0, 0.0 'top point
_glVertex3f -1.0, -1.0, 0.0 'left point
_glVertex3f 1.0, -1.0, 0.0 'right point
_glEnd
_glEndList
gl_list_created = 1
End If
End Sub


