9

I'm trying to learn OpenGL. I've got experience with C and C++, setting up a build environment, and all that jazz, but I'm trying to figure out a good starting point.

I'm aware of the fixed function pipeline that was prominent in OpenGL <= 2.1, and it seems relatively easy to get started with. However, the core profile that OpenGL pushes in OpenGL >= 3.1 makes me want to stay away from the FFP due to deprecation. But I'm confused as to how it all works in 3.1 and above. In 2.1 and below you have your glBegin(GL_WHATEVER) and glEnd() when you're drawing shapes. The first thing I noticed when looking through the core profile API, is that those two function calls are gone. I realize there's probably a simple replacement, but it's quite shocking to see something so (seemingly useful) taken out of such a basic task. It almost seems like deprecating printf() from the c standard library. And when I work through the newest Red Book, they still use the old deprecated code which further muddles my thinking.

When reading through various answers to similar questions I see the typical "shader based" or "it's all done with shaders" etc etc. If I want to draw a simple white square onto a black background (the first example in the newest Red Book), I don't understand how a shader is relevant to drawing a box at all. Shouldn't they do... well.. shading? I've looked into buying the Orange Book and the Blue Book, but I don't want to spend anymore money on something that's going to hide it all behind a library (the Blue Book) or something that's going to talk about programming a shader to perform some lighting task in a 3D environment (the Orange Book).

So where do I begin? How do I draw a box (or a cube or a pyramid or whatever) using nothing but the core profile. I'm not asking for a code snippet here, I'm looking for a expansive tutorial or a book or something that someone could point me to. If this has been answered previously and I didn't find it, please redirect me.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user1219820
  • 115
  • 1
  • 2
  • 4
    I would advice you to pick up a good "book" on modern OpenGL. My first recommendation would be http://www.arcsynthesis.org/gltut/ which is online and free. That should get you started. – Bart Jun 06 '12 at 19:22
  • 1
    You can use programmable pipeline in 2.0, too. Fixed-function is crappy and inefficient regardless of the version. – Cat Plus Plus Jun 06 '12 at 19:24
  • @CatPlusPlus That is the FIRST time I have heard of anyone refer to the fixed function pipeline as inefficient. :) You might want to reconsider that word. Crappy - I agree with. – Ani Jun 06 '12 at 19:26
  • @ananthonline: It is inefficient. Anyone who deals with GL will tell you that. You should limit the amount of drawing calls done in a frame, and with fixed-function it skyrockets exponentially (you issue 6 calls on a single *triangle* with texturing). Whereas with VBO 6 calls can do 2 whole *batches*. – Cat Plus Plus Jun 06 '12 at 19:28
  • 3
    Really? Have you heard of glDrawElements? glDrawArrays? Perhaps you're getting confused between immediate-mode rendering and the fixed pipeline. Fixed-function pipeline doesn't have vertex and pixel shaders, that is all. It can still do batched rendering. – Ani Jun 06 '12 at 19:29
  • @ananthonline: Ah, yes, I had immediate mode on mind. Ah well. – Cat Plus Plus Jun 06 '12 at 19:31
  • Yes, I've heard that it's inefficient, which is why I'm trying to avoid learning the deprecated code. And thanks for link @Bart, that seems really helpful. It also has a math primer, which is always a good thing. And I've seen that GLSL is at version 1.10 in GL 2.1? Or maybe some other version? But I have seen where some version of the GLSL is available. – user1219820 Jun 06 '12 at 19:44
  • -1: Welcome to Stack Overflow. Unfortunately, your question is too broadly specified. "How do I begin" questions are not appropriate on this site. – Nicol Bolas Jun 06 '12 at 20:06
  • @Nicol Bolas Im aware that this isn't a "beginners look here" site. But im also aware that a lot of people are as confused as I was when I posted the question. With so many outdated references to what is now known as 'The Compatibility Profile', I assumed that some experienced devs on stackoverflow would be able to point a fellow programmer in the right direction. If you have any input on the question (which everyone else seemed to know exactly what I meant) I would love to hear your input as well. Thanks – user1219820 Jun 06 '12 at 22:11
  • Very well. I'll pay more attention to the rules if I post another. – user1219820 Jun 06 '12 at 22:28
  • Voting to close as resource rec / too broad. See also: http://stackoverflow.com/questions/6733934/what-does-immediate-mode-mean-in-opengl – Ciro Santilli OurBigBook.com Mar 22 '16 at 14:51

1 Answers1

14

The reason for the sudden "complexity" in the core profile is the fact that the fixed functionality pipeline was not representative of what the GPU actually does for you. Much of the functionality was done on the CPU, and only the actual drawing happened on the GPU. The other problem with the fixed pipeline is that it's a losing battle. The fixed pipeline has sooooooo many knobs and switches! So, not only is it painfully complicated already, it will never keep up with the endless demand of new ways to draw scenes. Enter GLSL, and you have the ability to tell the GPU precisely how you want to draw your scene. This shifts the power to the developer and frees everyone from having to wait for OpenGL updates for new switches/knobs.

Now, regarding your frustration with the sudden loss of glBegin and glEnd... there are simple frameworks that mimic their behavior on the new core profile, and that is a good thing. Again, it shifts the power to developers to choose how they approach the pipeline. However, there is nothing wrong with practicing 3D on the FFP. You need to learn 3D math and concepts first anyway. Those concepts apply regardless of API. (Matrix math will save your life both in OpenGL and Direct3D.) So, first you practice with simple triangles and colors. Then you move onto textures (with texture coordinates). Then you add normals (with lighting). Then, after you understand all those concepts, you stop using glBegin/glEnd, and you start batching large amounts of vertex data into buffers. You will not understand glDrawElements all that well if you do not understand glBegin/glEnd anyway. So, it's OK to learn on those tools.

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
  • i agree, i think the way to go is read through the red book first edition (1993 i think) then jump into the latest orange book or whatever the 2015 hotness is... good to learn basics from a time when opengl was only 120 functions. –  Jun 01 '14 at 00:15
  • Thank you for this; it is one of the best answers I've ever seen. For a long time I have been honestly wondering how the entire OpenGL community seems to have lost its mind: everyone mindlessly repeating the mantra "the fixed pipeline was bad, you shouldn't use it" while advocating a much more complicated alternative with an incredibly steep learning curve and absolutely no evident advantage to the vast majority of users. This is the first thing I've ever read that gives a glimpse of what might actually be problematic about the fixed pipeline, and you give a clear and sane overall picture. – Don Hatch Sep 23 '15 at 12:22
  • You are welcome. Glad I could help. – TheBuzzSaw Sep 23 '15 at 16:12