CSC 307 1.0
Graphics Programming
Budditha Hettige
Department of Statistics and Computer Science
Graphics Programming
Viewing
2Budditha Hettige
Translate
• void glTranslate{fd}(TYPE x, TYPE y, TYPE z);
3Budditha Hettige
Rotate
void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z);
glRotatef(45.0, 0.0, 0.0, 1.0) - rotation of 45 degrees
about the z-axis
4Budditha Hettige
Scale
void glScale{fd}(TYPE x, TYPE y, TYPE z);
Example: glScalef(2.0, –0.5, 1.0)
5Budditha Hettige
Viewing and Modeling
Transformations
• Rotating First or Translating First
6Budditha Hettige
Viewpoint
• Object and Viewpoint at the Origin
7Budditha Hettige
Viewpoint and the Object
• Separating the Viewpoint and the Object
• glTranslatef(0.0, 0.0, -5.0);
8Budditha Hettige
Using the gluLookAt()
void gluLookAt
(
GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz
);
9Budditha Hettige
Default Camera Position
10
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
Budditha Hettige
Using gluLookAt()
gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0);
11Budditha Hettige
Projection Transformations
• Perspective Projection
void glFrustum(GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far);
12Budditha Hettige
Orthographic Projection
void glOrtho(GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far);
13Budditha Hettige
Viewport Transformation
• Defining the Viewport
• void glViewport(GLint x, GLint y,
GLsizei width, GLsizei height);
14Budditha Hettige
The Transformed Depth Coordinate
• void glDepthRange(GLclampd near,
GLclampd far);
15Budditha Hettige
Animation
• Is an important part of computer graphics
• Taking a sequence of pictures and projecting
them at 24 frames per second on the screen
• void glutSwapBuffers(void);
16Budditha Hettige
Example
# include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
static GLfloat spin = 0.0;
void spinDisplay(void)
{
spin = spin + 0.05;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
17
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
spinDisplay();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}Budditha Hettige
Example
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
18Budditha Hettige
Building a Solar System
• planet example (planet.cpp)
19Budditha Hettige
Building an Articulated Robot Arm
• robotArm.cpp
20Budditha Hettige

More Related Content

PDF
Ins and Outs of GPIO Programming
 
PPT
14827 shift registers
DOCX
Convertidores ad
PPTX
Wi-Fi Esp8266 nodemcu
PPTX
Finite state machine
PDF
OpenGL 3D Drawing
PDF
Graphics Programming OpenGL & GLUT in Code::Blocks
PDF
Introduction to Computer Graphics
Ins and Outs of GPIO Programming
 
14827 shift registers
Convertidores ad
Wi-Fi Esp8266 nodemcu
Finite state machine
OpenGL 3D Drawing
Graphics Programming OpenGL & GLUT in Code::Blocks
Introduction to Computer Graphics

Similar to Viewing (20)

PDF
PPT
Opengl (1)
PDF
Drawing Fonts
PDF
2D Drawing
PPT
september11.ppt
PDF
Texture Mapping
PPT
Introduction to OpenGL modern OpenGL program
PDF
Open gl
PPT
Introduction to OpenGL.ppt
PPTX
OpenGL_summer2012.ccccccccccccccccccpptx
PPT
Computer Graphics involves technology to access. The Process transforms and p...
PDF
201707 SER332 Lecture10
PPT
CS 354 Introduction
PDF
CG mini project
PDF
Computer Graphics Programming Problem Solving And Visual Communication Dr Ste...
PPT
openGL basics for sample program (1).ppt
PPT
openGL basics for sample program.ppt
PPTX
Chapter02 graphics-programming
PDF
A graphic library and an application for simple curve manipolation
Opengl (1)
Drawing Fonts
2D Drawing
september11.ppt
Texture Mapping
Introduction to OpenGL modern OpenGL program
Open gl
Introduction to OpenGL.ppt
OpenGL_summer2012.ccccccccccccccccccpptx
Computer Graphics involves technology to access. The Process transforms and p...
201707 SER332 Lecture10
CS 354 Introduction
CG mini project
Computer Graphics Programming Problem Solving And Visual Communication Dr Ste...
openGL basics for sample program (1).ppt
openGL basics for sample program.ppt
Chapter02 graphics-programming
A graphic library and an application for simple curve manipolation
Ad

More from Budditha Hettige (16)

PDF
Algorithm analysis
PDF
PDF
Link List
PDF
PDF
Data Structures 01
PPTX
Computer System Architecture Lecture Note 9 IO fundamentals
PPTX
Computer System Architecture Lecture Note 8.1 primary Memory
PPTX
Computer System Architecture Lecture Note 8.2 Cache Memory
PPTX
Computer System Architecture Lecture Note 7 addressing
PPT
Computer System Architecture Lecture Note 6: hardware performance
PPT
Computer System Architecture Lecture Note 5: microprocessor technology
PPT
Computer System Architecture Lecture Note 3: computer architecture
PPT
Computer System Architecture Lecture Note 2: History
PPT
Computer System Architecture Lecture Note 1: introduction
PPT
Computer System Architecture Lecture Note 4: intel microprocessors
Algorithm analysis
Link List
Data Structures 01
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 1: introduction
Computer System Architecture Lecture Note 4: intel microprocessors
Ad

Recently uploaded (20)

PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
PDF
semiconductor packaging in vlsi design fab
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
English Textual Question & Ans (12th Class).pdf
PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Complications of Minimal Access-Surgery.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
My India Quiz Book_20210205121199924.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
Journal of Dental Science - UDMY (2022).pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
Climate and Adaptation MCQs class 7 from chatgpt
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Environmental Education MCQ BD2EE - Share Source.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
semiconductor packaging in vlsi design fab
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
English Textual Question & Ans (12th Class).pdf
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Complications of Minimal Access-Surgery.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
Journal of Dental Science - UDMY (2021).pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
My India Quiz Book_20210205121199924.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Journal of Dental Science - UDMY (2022).pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Climate and Adaptation MCQs class 7 from chatgpt

Viewing