---
title: "OpenGL syntax: parallelogram"
subject: "Computer Graphics"
chapter: 9
key: "semester_5/computer_graphics:opengl-parallelogram-syntax"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/opengl-parallelogram-syntax
site: BCT Engineering
---

# OpenGL syntax: parallelogram

Computer Graphics · Chapter 9: Introduction to Open GL

- Asked in: 2071 Shrawan, 4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/opengl-parallelogram-syntax
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-9

## Question

Explain OpenGL syntax to draw a parallelogram having vertices (0.0, 0.0), (1.0, 0.0), (1.5, 1.2) and (0.5, 1.2).

## Short answer

Call glBegin(GL_POLYGON); list the vertices in counter‑clockwise order with glVertex2f: (0.0,0.0), (1.0,0.0), (1.5,1.2), (0.5,1.2); then glEnd() and glFlush().

## Answer

A parallelogram is a four-sided polygon, so it can be drawn with `GL_POLYGON` or `GL_QUADS` between `glBegin()` and `glEnd()`, with the vertices given in order (counter-clockwise) using `glVertex2f(x, y)`.

```c
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0f, 0.6f, 1.0f);          // fill colour
    glBegin(GL_POLYGON);                   // or GL_QUADS
        glVertex2f(0.0f, 0.0f);
        glVertex2f(1.0f, 0.0f);
        glVertex2f(1.5f, 1.2f);
        glVertex2f(0.5f, 1.2f);
    glEnd();
    glFlush();
}
```

Explanation:
- `glBegin(GL_POLYGON)` starts a convex polygon; `glEnd()` ends it.
- `glVertex2f` takes floating-point x and y (z is taken as 0).
- Vertices are listed in order around the figure, so the sides are (0,0)-(1,0), (1,0)-(1.5,1.2), (1.5,1.2)-(0.5,1.2) and (0.5,1.2)-(0,0).
- To get only the outline, use `GL_LINE_LOOP` instead of `GL_POLYGON`. The viewing volume must include x up to 1.5 and y up to 1.2 (for example, `gluOrtho2D(-1, 2, -1, 2)`).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which primitive can draw the parallelogram?
   A. GL_POINTS
   B. GL_LINES
   C. GL_POLYGON or GL_QUADS
   D. GL_TRIANGLES only
   Answer: C. It is a four-sided polygon. (Key point: Primitive)

2. Which call specifies the vertex (1.5, 1.2)?
   A. glVertex3f(1.5f)
   B. glVertex(1.5, 1.2)
   C. glVertex2f(1.2f, 1.5f)
   D. glVertex2f(1.5f, 1.2f)
   Answer: D. glVertex2f takes x and y. (Key point: Vertex call)

3. How must the vertices be listed?
   A. In order around the figure
   B. In any random order
   C. Sorted by x
   D. Only diagonals first
   Answer: A. Order (0,0),(1,0),(1.5,1.2),(0.5,1.2) follows the boundary. (Key point: Order)

4. Which mode draws only the outline?
   A. GL_QUADS
   B. GL_LINE_LOOP
   C. GL_POLYGON
   D. GL_POINTS
   Answer: B. It joins the vertices in a closed loop. (Key point: Outline)

## Related in Computer Graphics

- [OpenGL syntax: 3D vertex](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aopengl-3d-float-vertex-syntax) — Computer Graphics, chapter 9
- [Drawing primitives in OpenGL](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aopengl-draw-primitives-2d) — Computer Graphics, chapter 9, asked 4×
- [Construct geometric table, 6 vertices](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Ageometric-table-construct-6-vertices) — Computer Graphics, chapter 6
