Computer Graphics
  • 5CM507 Graphics 25-26
  • Module
  • Schedule
    • Term 1 Schedule
    • Term 2 Schedule
  • Assessments
    • Coursework 1 (CW1)
    • Coursework 2 (CW2)
  • Lectures A
    • L01 Overview of Computer Graphics
    • L02 Mathematics
  • Labs A
    • LabA0 Environment Setup
      • Using a Git Repository
      • Checking or Installing Software
      • Creating a Project Framework
    • LabA01 Drawing 2D Triangles
      • Early OpenGL
      • Modern OpenGL
    • LabA02 Load Meshes and Calculate Normals
      • How to Represent a Mesh
        • Mesh Data Structure in C++
        • Mesh Data Structure in WebGL
        • The OBJ Mesh Format
      • Normal Calculation
      • Calculating Normals in C++
    • LabA03 Transformations
    • LabA04 Scene Graph
    • LabA05 Projections
    • LabA06 Lighting
    • LabA07 Shaders
    • LabA08 Texture Mapping
  • Lectures B
  • Labs B
  • Resources
  • People
    • Module Leader
    • The Games Group@Derby
    • Senior External Consultants
Powered by GitBook
On this page
  • Lab Tutorial: Drawing Triangles with OpenGL, GLEW, and GLFW
  • Objective
  • Prerequisites
  • Tutorial
  • Exercises
  1. Labs A

LabA01 Drawing 2D Triangles

Lab Tutorial: Drawing Triangles with OpenGL, GLEW, and GLFW

Objective

This tutorial guides you through rendering triangles using OpenGL, Direct3D, WebGL or Vulkan

Prerequisites

  • C++ development environment (e.g., Visual Studio, Code::Blocks, or GCC)

  • OpenGL, GLEW, and GLFW installed


Tutorial

Step 1: Setting Up the Environment

Step 2: Drawing Raw Triangles

Step 3: Drawing Indexed Triangles

Step 4: Drawing Indexed Triangles with Vertex Colours


Exercises

Basic Exercises

  1. Modify the Triangle Colour – Change the colours of the triangle vertices to create a gradient effect.

  2. Change Triangle Positions – Adjust the vertex coordinates to move the triangle around the screen.

  3. Add More Triangles – Extend the program to render multiple triangles instead of just one.

  4. Resize the Window – Modify the viewport and projection settings to maintain the correct aspect ratio when resizing.

Intermediate Exercises

  1. Revise the code to draw a 3D pyramid (no need to touch projections)

  2. Revise the code to draw a 3D cube (no need to touch projections)

PreviousCreating a Project FrameworkNextEarly OpenGL

Last updated 3 months ago