Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenGL lesson 1 !
#1
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. Smile

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
Reply


Messages In This Thread
OpenGL lesson 1 ! - by MasterGy - 11-06-2025, 03:13 PM
RE: OpenGL lesson 1 ! - by Magdha - 11-06-2025, 03:43 PM
RE: OpenGL lesson 1 ! - by MasterGy - 11-06-2025, 04:02 PM
RE: OpenGL lesson 1 ! - by Magdha - 11-06-2025, 05:19 PM
RE: OpenGL lesson 1 ! - by Unseen Machine - 11-06-2025, 05:45 PM
RE: OpenGL lesson 1 ! - by madscijr - 11-06-2025, 09:17 PM
RE: OpenGL lesson 1 ! - by TempodiBasic - 11-07-2025, 02:08 AM
RE: OpenGL lesson 1 ! - by madscijr - 11-07-2025, 02:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  OpenGL Lighting Issue aadityap0901 11 1,978 10-02-2024, 12:57 PM
Last Post: aadityap0901

Forum Jump:


Users browsing this thread: 1 Guest(s)