Home » JOGL Primitives

JOGL Primitives

by Online Tutorials Library

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

Primitive Description
GL_LINES It treats each pair of vertices as line segment.
GL_LINES_STRIP Connects group of line segment with each other.
GL_LINES_LOOP Connects group of line segment in a loop i.e. from first to last and then back to the first.
GL_TRIANGLE Each vertices of triplet behaves as an independent triangle
GL_TRIANGLE_FAN Creates a connected group of triangle where each triangle is defined for a particular vertex presented after the first two vertex.
GL_TRIANGLE_STRIP Connects group of triangle with each other.
GL_QUADS Each group of four vertices behaves as an independent quadrilateral.
GL_QUAD_STRIP Connects group of quadrilateral with each other.
GL_POLYGON Draws 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.



JOGL Primitives Output

Next TopicJOGL Hello World

You may also like