-In this lesson we're going to take a look at a quick and easy way to get some content into the window that we've created. We're going to do this with something called immediate mode, or the fixed function pipeline. This is Legacy old-school OpenGL, and it's actually been deprecated as a version three, so we're not going to talk about it too much; however, I do find it's useful for de-bugging purposes, and it's really useful for you to be able to recognize it when you see it. So, let's get started.
On line 27 we call a draw function. In the draw function, we have four new GL commands I'd like to introduce you to. The first is GL begin. GL begin takes as an argument a type of GL primitive. This could be triangles, lines, points. We'll talk about the different options in a little bit. GL color three f takes three floating point values, one for the red, one for the green, and one for the blue. In this case on line 30 we're specifying the color red.
GL vertex three f takes three floating point values that specify a coordinate, one for the x, one for the y, and one for the z value. In this case on line 31 we're specifying something on the left-hand side of the screen as we're facing it. We specify two more colors and two more vertices, and then we call GL end. Let's take a look at what this makes. So here we have a triangle with three different colors on its three different vertices.
The first vertex is red at the negative one position. The second vertex is green at the zero one zero position. That's positive y. And third one is blue at the one zero zero position. That's positive x over here. We'll talk a little bit more about open GL coordinates later on. Let's close this window and take a look at where the draw function actually gets called.
We want the draw function to get called in our main loop while the window is open. So we put it here on line 70. The other thing to note is that I've moved GL view port in to the draw loop. In the previous lesson it was up here. Why did we do this? Well, I want the view port to be able to be updated every frame. Why? In case I re-size the window. That way every time I draw I can get the new updated width and height of the screen.
GLFW, get frame buffer size, takes a window and two variables and sets them to be the width and height of the current window. So, we've set width and height up here as variables to begin with, but then every frame, if we re-size the window, we get new width and a new height, and we set the view port to it. So now when we compile the code whenever we re-size the window, the new frame buffer width and the new frame buffer height are sent to the view port.
That's how we make sure that the triangle always stays within our view port. In this lesson we've seen how to render a triangle into our OpenGL context using Legacy OpenGL and the fixed function pipeline.
- What is OpenGL?
- Setting up an OpenGL workflow
- Creating a window with GLFW
- Working with geometric primitives
- Rotating, translating, and scaling
- Understanding matrix transformations
- Creating mesh data structures
- Buffering mesh data
- Getting mouse and keyboard input
Skill Level Intermediate
Q: Why am I getting errors saying I don’t have GLEW installed when I try to create the Xcode projects with Cmake?
1) Download, Install, and Run Xcode
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew install glew
./bootstrap && make && make install
brew install cmake
cd Exercise Filesmkdir xcodecd xcodecmake -G "Xcode" ..