

OpenGL likes it when you define your vertices in counter-clockwise order. So, use these coordinates to define where your triangle’s vertices will be drawn – anywhere you like! However, do remember this important point: So as you can see, the X-axis goes left to right, the Y-axis bottom to top, and the Z-axis far to near. This is how OpenGL handles screen coordinates: But anyway, you may have also wondered how we specify where on the screen our vertices are?

Why not use double? Basically because GPUs still prefer to use floats – and doubles might slow things down because of conversions and all. We’ll have to define each corner, or vertex.įor now, we’ll do this by making an array of twelve floats – three values for each vertex. First of all though, we need to define the triangle that we want to draw. If not, then also great – OpenGL’s interface just functions similarly to one. If you’ve used a C-like language before, great. I’ll explain how OpenGL works as we go along. You can call those methods whatever you like. We’ll also want two new methods – one for setting up the triangle we want to draw (which we’ll call within run(), right before our loop), and then another one which will actually draw it to the screen (which we’ll have to call every iteration of our loop). We want to implement the Runnable interface, and therefore make a method run() in our class. Today, we’re going to make it a bit more interesting by using OpenGL to draw a triangle on it! Before we do that though, there are a few small changes that we have to make to our class. If your API doesn't draw quads, build a reusable index list that allows you to render quads as indexed triangles.So, last time we managed to create an amazing blank window. Expect it to use an average of ~270 bytes per character.

If the buffer isn't large enough, it will truncate. If you pass in NULL for color, it becomes 255,255,255,255. This format was chosen in the hopes it would make it easier for you to reuse existing

You can ignore z and color if you get them from elsewhere. The vertices are stored in an interleaved format: x:float there are four vertices in the vertex buffer for each quad. The vertex data is divided into quads, i.e. Takes a string (which can contain '\n') and fills out a vertex buffer with renderable data to draw the string.
