Being an open graphic library, we can draw different shapes such as circle, triangle, square in JOGL. Hence, to draw these shapes Open GL provides primitives that facilitates JOGL to draw 2D as well as 3D dimension figures.
OpenGL Primitive provides various in-built parameters on the basis of which different shapes can be drawn. Each parameter has some specific role in drawing figure.
JOGL in-built Primitives
Following are the various OpenGL in-built parameter supported by JOGL: -
||It treats each pair of vertices as line segment.
||Connects group of line segment with each other.
||Connects group of line segment in a loop i.e. from first to last and then back to the first.
||Each vertices of triplet behaves as an independent triangle
||Creates a connected group of triangle where each triangle is defined for a particular vertex presented after the first two vertex.
||Connects group of triangle with each other.
||Each group of four vertices behaves as an independent quadrilateral.
||Connects group of quadrilateral with each other.
||Draws a single, convex polygon.
The display() method contains the code used to draw and display a shape. Follow the below steps to arrange the code systematically: -
- Initially, pass the object of GLAutoDrawable interface with display() method as its parameters.
- Generate the object of GL2 interface.
- Associate that object with glBegin() method and pass the type of primitive required as its parameter.
Here, we are providing GL_LINES primitive.
- Now, bound GL2 object with glVeretex2d() method and pass the specific coordinate with it.
- End up the line by invoking glEnd() method.
Example of Basic Line
In this example, we will learn how to draw a simple line using primitives.