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
#2
(11-06-2025, 03:13 PM)MasterGy Wrote: 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.

Yeah, but that's the bit I enjoy about _MAPTRIANGLE(3D)!!
Reply
#3
(11-06-2025, 03:43 PM)Magdha Wrote:
(11-06-2025, 03:13 PM)MasterGy Wrote: 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.

Yeah, but that's the bit I enjoy about _MAPTRIANGLE(3D)!!

I don't want to take away your enthusiasm! Smile If you look at my library, you will see many 3D programs. _maptriangle sets strong limits in rendering. (it's slow, there is no light, it is not parameterizable at all). You take a triangle and a texture, and it draws it. That's it. In retrospect, I regret not studying OpenGL sooner, because if my programs had been built on OpenGL, they would have been much more spectacular (and not run at 25 FPS). _maptriangle is enough to draw a triangle, but if you want more, OpenGL will be inevitable. Another advantage of OpenGL is that it is a standard, and you can use it in other systems. If you are seriously interested in 3D, then OpenGL! If you insist on _maptriangle, then I understand, it was more comfortable for me too. You know.
Reply
#4
It would be good for a new section on OpenGL Tutorials to appear in the Learning Resource Section.  So, do Unseen, MasterGy & Petr need to get together & form a plan?
I remember on the old .org site, Ashish was going to do an OpenGL Tutorial resource, but other things happened.
I think that the weaker folk amongst us (I am very much in this Venn diagram subset) will always struggle with OpenGL.  When you go through the Wiki pages on QB64 statement, everything in QB and QB64 statements remain very like QB, but OpenGL just looks very different (as it has to).  When you start at the very beginning - "a vey good place to start", the first alphabetic OpenGL statement is: 
  • _glAccum (statement) operates on the accumulation buffer
I don't know what any of that means.  It's a different world.
Reply
#5
https://nehe.gamedev.net/

See the legacy tutorials, they're in C++ but it s done step by step and is where i learnt from in the beginning.

John 

p.s. @MasterGY - GLList handles should be dimmed as _Unsigned Long's and if youre up for it why not convert the first 10 tutorials from the site ive linked to Qb64? That would provided everyone with a REAL solid basis to learn/build upon.
Reply
#6
Thanks for sharing, @MasterGy! 

I am completely new to real 3D, pretty much my only attempt at "3D" was this mess which took WAY too much work considering how little it does. 

There were a couple of things I've been wanting to make in QB64 with 3D, like this infinite shape generator or maybe a game for 3D glasses, but I'm not much of a math person and after that last experience, 3D seemed a little beyond my reach.

I look forward to playing with your code - just one question: 
There is a routine Sub _GL but I don't see what's calling it?
Reply
#7
@madscijr

Sir, please take a look reading from here OpenGL sub
Reply
#8
Will do - thanks!
Reply


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)