introduction to computer graphics 1 principles of interactive graphics cmscd2012 dr david...

14
JMU Introduction to Computer Graphics 1 Principles of Interactive Graphics CMSCD2012 Dr David England, Room 711, ex 2271 [email protected] http://java.cms.livjm.ac.uk/homepage/ staff/cmsdengl Core for BSc Multimedia Systems Elective for other programmes - SE2, CS2 60% Coursework (2), 40% Exam

Upload: randolf-newton

Post on 05-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 1

Principles of Interactive Graphics CMSCD2012

Dr David England, Room 711, ex 2271 [email protected] http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl

Core for BSc Multimedia Systems Elective for other programmes - SE2, CS2 60% Coursework (2), 40% Exam

Page 2: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 2

Today’s Lecture and Lab

Introduce the aims and objectives of the module

Outline what you should already know

Outline the resources we will be using in the module

Introducing OpenGL Compile our first program Modify the program to do something interesting

… The rest of the module

Page 3: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 3

The Module … Aims

Aims To explain the principles underlying interactive

computer graphics - via practical examples and explanations of basic algorithms

To develop programming skills in Computer Graphics - using the OpenGL graphics library

Introduce input and display technologies for Computer Graphics

Page 4: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 4

The Module … Objectives

Learning Outcomes - once we have finished you should be able to

1 Identify the hardware and software needed for Computer Graphics applications

2 Solve problems in 2D graphics and interaction3 Develop applications using 2D graphics and 2D

input devices4 Explain the principles behind 2D and 3D graphics

The Coursework will test 2, 3 and 4 and the exam will test 1, 2 and 4

Page 5: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 5

The Module … Resources

You are expected to know C as taught in CD1003 and CD1004 (any direct entrants? ) You will need this knowledge for most of your other

Level 2 modules. So if in doubt, revise C now

Suggested revision topics: Functions and parameter passing Returning values from functions Arrays and struct data types Compiling and debugging Problem-solving by decomposition and

refinement

Page 6: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 6

The Module … Resources

OpenGL and Visual C++ in 6th and 7th Floor Labs. Using C++ as a “better C” staying a step behind the

OO Systems module. We will use the GLUT library with OpenGL so we are

independent of MS Windows. Examples should run on Linux with OpenGL (any

one using Linux at home? ) See www.opengl.org for how to run OpenGL on

Linux and for OpenGL online tutorials We are starting at a higher-level than most traditional

Computer Graphics courses

Page 7: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 7

The Module … Resources

Most of the information on OpenGL will come from handouts but you are expected to do your own reading e.g.

www.opengl.org Wright, OpenGL Superbible

Information on algorithms will come from handouts and from Foley and van Dam, Computer Graphics: Principles and

Practice (available in cheaper student edition) Hearn and Baker, Computer Graphics

If you think you going to get serious about Graphics in the future (e.g. CD3018) buy Foley and van Dam.

Page 8: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 8

Anatomy of an Interactive Graphics Program

Every interactive graphics program has the same basic outline:

Initialise the application data and graphics environment Create the contents of the display Paint the contents of the display on a window Set-up functions to handle input events Start an infinite loop to handle input events

This is event-driven programming

Page 9: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 9

A minimal OpenGL program … 1

First the necessary include files:

#include <windows.h> /* System specific */#include <GL/gl.h>#include <GL/glut.h> /* OpenGL utilities header file */#include <gl/glaux.h>#include <stdio.h>

Page 10: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 10

A minimal OpenGL program … 2

void main (int argc, char** argv){

glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);glutInitWindowSize(640, 480);glutInitWindowPosition(100,150);glutCreateWindow("my first attempt");

glutDisplayFunc(myDisplay); /* Draw something */myInit(); /* Initialise my

requirementsglutMainLoop(); /* The event handling

loop */}

Most of the above will be explained during the module ...

Page 11: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 11

A minimal OpenGL program … 3

void myInit(void){

glClearColor(1.0,1.0,1.0, 0.0);glColor3f(0.0f, 0.0f, 0.0f);glPointSize(4.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, 640.0, 0.0, 480.0);

}

Mostly setting colours, point sizes and viewing conditions

Page 12: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 12

A minimal OpenGL program … 4

void myDisplay(void){

glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_POINTS);

glVertex2i(100,50);glVertex2i(100, 130);glVertex2i(150, 130);

glEnd();glFlush();

}

Draw three dots ! (or vertices)

Page 13: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 13

The rest of the module

Intro to Computer Graphics II - History and definition of terms of 2/3-d technologies. (next week)

Introduction to 2D graphics - Raster-based output, graphics primitives and 2D graphics libraries (week 3)

Graphics hardware (week 4) 2D graphics I - Programming in a current graphics API using a

high-level programming language (weeks 5-6)

2D graphics II - Programming Animations (week 7)

2D graphics III - Handling event-driven user input.(week 8-9)

3D graphics concepts - Primitives, transformation, translation and rotation, materials and simple lighting models (weeks 10-12)

Page 14: Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 d.england@livjm.ac.uk

JMU Introduction to Computer Graphics 14

Next today ...

Compiling an OpenGL program with C++ Making some amendments to the program

Finish this before next week Revise any aspects of C (from slide 5) you are unsure

about