JOGL Primitives

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: -

PrimitiveDescription
GL_LINESIt treats each pair of vertices as line segment.
GL_LINES_STRIPConnects group of line segment with each other.
GL_LINES_LOOPConnects group of line segment in a loop i.e. from first to last and then back to the first.
GL_TRIANGLEEach vertices of triplet behaves as an independent triangle
GL_TRIANGLE_FANCreates a connected group of triangle where each triangle is defined for a particular vertex presented after the first two vertex.
GL_TRIANGLE_STRIPConnects group of triangle with each other.
GL_QUADSEach group of four vertices behaves as an independent quadrilateral.
GL_QUAD_STRIPConnects group of quadrilateral with each other.
GL_POLYGONDraws a single, convex polygon.

Display() Method

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.

BasicLine.java

Output:

JOGL Primitives Output