Struggling with OpenGL

I’m learning OpenGL for a project. I have to render a cube in 3D. I’m struggling because all the tutorials use totally different codes. Right now I can draw 2D objects in the main while loop function. However all the tutorials on 3D stuff don’t even include that said while loop where the first tutorial told me everything that is drawn will be there. So im lost.

Try the NeHe tutorials as they’re where I started my OpenGL journey many moons ago. They are a little out of date now with the advent of shaders but I think they’re still useful for beginners. Here is a link to the tutorial on 3D shape creation: