SlideShare a Scribd company logo
5
Most read
6
Most read
24
Most read
CSC 307 1.0
Graphics Programming
Budditha Hettige
Department of Statistics and Computer Science
Graphics Programming
OpenGL & GLUT in Code::Blocks
2Budditha Hettige
OpenGL & Code::block
• Download Code::Blocks
– http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/
• Download the GLUT bin file from
– http://www.xmission.com/~nate/glut.html
• Save files as
– Copy glut32.dll to
• C:windowssystem
– Copy glut32.lib to
• C:Program FilesCodeBlocksMinGWlib,
– Copy glut.h to
• C:Program FilesCodeBlocksMinGWincludeGL.
3Budditha Hettige
Code::Bolock Project
1. Start Code::Blocks and make a new project.
2. Select to make a new GLUT project and press Go to
continue.
3. Press Next at this menu
4
2 3
Budditha Hettige
Code::Bolock Project
4. Give a project title, and a location where to create
the project and then press Next
5. Tell Code::Blocks to where you stored your GL files,
then press Next
5
4 5
Budditha Hettige
Code::Bolock Project
• Set compiler as “GNU GCC Compiler”, and press
Finish.
• Open up the sample source file by double clicking on it
• Add #include <windows.h> at line 14
6Budditha Hettige
Code::Bolock Project
• Compile and build an application
7Budditha Hettige
Sample 01
# include <windows.h>
#include <GL/glut.h>
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutCreateWindow("simple");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
8Budditha Hettige
GLUT Functions
glutInit(int *argc, char** argv);
Initializes a window session.
glutCreateWindow(char *name);
Creates a window with title *name.
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
Sets the display mode to single buffered and RGB color.
glutInitWindowSize (GLsizei h, GLsizei w);
Sets initial window size to h x w.
glutInitWindowPosition(x,y);
Sets initial window position to (x, y).
9Budditha Hettige
GLUT Functions
• void glFlush()
force execution of GL commands in finite time
• void glutDisplayFunc(void (*func)(void));
sets the display callback for the current window.
• void glutMainLoop(void);
Enters the GLUT event processing loop
10Budditha Hettige
OpenGL Attributes
• glClearColor(1.0, 1.0, 1.0, 0.0);
– Sets background color to white
– Fourth argument is transparency; 0.0 is opaque
– Sets a state variable
• glPointSize(2.0);
– Sets point size to be 2 pixels wide
– Note that this is not a device-independent
attribute
– Sets a state variable
11Budditha Hettige
glClear
• Clearing the Color Buffer
– glClear(GL_COLOR_BUFFER_BIT);
• Values
– GL_COLOR_BUFFER_BIT
Indicates the buffers currently enabled for color
writing.
– GL_DEPTH_BUFFER_BIT
Indicates the depth buffer.
– GL_ACCUM_BUFFER_BIT
Indicates the accumulation buffer.
– GL_STENCIL_BUFFER_BIT
Indicates the stencil buffer.
12Budditha Hettige
13
OpenGL Geometric Primitives
GL_QUAD_STRIP
GL_POLYGON
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
GL_POINTS
GL_LINES
GL_LINE_LOOPGL_LINE_STRIP
GL_TRIANGLES
GL_QUADS
Budditha Hettige
OpenGL Primitive Syntax
glBegin ( type );
glVertex* ( );
.
.
.
.
glVertex* ( );
glEnd ( );
14
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, -10.0f);
glVertex3f(-1.0f,-1.0f, -10.0f);
glVertex3f( 1.0f,-1.0f, -10.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glEnd();
Budditha Hettige
Sample 02
# include <windows.h>
# include <GL/glut.h>
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0); //red
glBegin(GL_QUADS);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glColor3f (0.0, 0.0, 1.0); //blue
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glutSolidSphere(0.15,12,2); //draw a sphere
glFlush ();
}
15
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE |
GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
}
Budditha Hettige
Sample 02
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
16Budditha Hettige
glutInitDisplayMode
• Sets the initial display mode.
– glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
• Values
– GLUT_RGBA
– GLUT_RGB
– GLUT_INDEX
– GLUT_SINGLE
– GLUT_DOUBLE
– GLUT_ACCUM
– GLUT_ALPHA
– GLUT_DEPTH
– GLUT_STENCIL
– GLUT_MULTISAMPLE
– GLUT_STEREO
– GLUT_LUMINANCE
17Budditha Hettige
glColor
• Set the current color
– glColor3f (1.0, 0.0, 0.0);
• Example
– void glColor3i(GLint red, GLint green, GLint blue);
– void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
– glColor3f (1.0, 0.0, 0.0); //red
– glColor3f (0.0, 0.0, 1.0); //blue
18Budditha Hettige
Budditha Hettige 19
OpenGL Transformations
• Before applying modeling or viewing transformations,
need to set
glMatrixMode(GL_MODELVIEW)
• Before applying projection transformations, need to set
glMatrixMode(GL_Projection)
• Replacement by either following commands
glLoadIdentity();
glLoadMatrix(M);
• Multiple transformations (either in modeling or viewing)
are applied in reverse order
Projection Transformation
• Transformation from scene to image
• Orthographic projection
– glOrtho (left, right, bottom, top, near, far)
• Perspective projection
– glFrustum (left, right, bottom, top, near, far)
20Budditha Hettige
Setting Viewing Matrix
glMatrixMode(GL_PROJECTION);
Sets the switch so that loaded matrix goes into
the projection stack.
glLoadIdentity();
Pushes an identity matrix onto the stack;
gluOrtho2D(GLdouble left, Gldouble right,
Gldouble bottom, Gldouble top);
Sets the current view to an orthographic
projection with view volume bounded by x = left, x
= right, y = bottom, y = top, z = -1.0 and z = 1.0.
21Budditha Hettige
Viewport Transformation
MyWindow
x
y
h
w
void glViewport(Glint x, GLint y, GLsizei w, Glsizei h);
Default viewport corresponds to entire window drawable area.
Clipping
Window
Budditha Hettige 22
Example
• GL_POINTS
• GL_LINES
• GL_TRIANGLES
• GL_TRIANGLE_STRIP
• GL_QUAD_STRIP
• GL_LINE_STRIP
• GL_LINE_LOOP
• GL_QUADS
• GL_POLYGON
• GL_TRIANGLE_FAN
23Budditha Hettige
OpenGL applications
24Budditha Hettige

More Related Content

What's hot (20)

PPTX
HIGH PASS FILTER IN DIGITAL IMAGE PROCESSING
Bimal2354
 
PPTX
Digital Image Processing
Shaleen Saini
 
PPTX
Deep Learning in Computer Vision
Sungjoon Choi
 
PPT
1.8 discretization
Krish_ver2
 
PPTX
Autoencoders in Deep Learning
milad abbasi
 
PPTX
Fibonacci Heap
Taniya Anand
 
PDF
Machine Learning: Introduction to Neural Networks
Francesco Collova'
 
PPTX
Representation image
Zena Abo-Altaheen
 
PDF
OpenGL Introduction.
Girish Ghate
 
PPTX
Decision Tree - ID3
Xueping Peng
 
PDF
Deep learning
Mohamed Loey
 
PDF
Introduction to Neural Networks
Databricks
 
PDF
Machine Learning Course | Edureka
Edureka!
 
PPTX
Timing Attack paper--pres--v.01
anasz3z3
 
PDF
Loan approval prediction based on machine learning approach
Eslam Nader
 
PDF
Overview of Convolutional Neural Networks
ananth
 
PPTX
OpenGL Introduction
Jayant Mukherjee
 
PPTX
Fuzzy c means manual work
Dr.E.N.Sathishkumar
 
PPT
Character generation
Ankit Garg
 
PPTX
04 Multi-layer Feedforward Networks
Tamer Ahmed Farrag, PhD
 
HIGH PASS FILTER IN DIGITAL IMAGE PROCESSING
Bimal2354
 
Digital Image Processing
Shaleen Saini
 
Deep Learning in Computer Vision
Sungjoon Choi
 
1.8 discretization
Krish_ver2
 
Autoencoders in Deep Learning
milad abbasi
 
Fibonacci Heap
Taniya Anand
 
Machine Learning: Introduction to Neural Networks
Francesco Collova'
 
Representation image
Zena Abo-Altaheen
 
OpenGL Introduction.
Girish Ghate
 
Decision Tree - ID3
Xueping Peng
 
Deep learning
Mohamed Loey
 
Introduction to Neural Networks
Databricks
 
Machine Learning Course | Edureka
Edureka!
 
Timing Attack paper--pres--v.01
anasz3z3
 
Loan approval prediction based on machine learning approach
Eslam Nader
 
Overview of Convolutional Neural Networks
ananth
 
OpenGL Introduction
Jayant Mukherjee
 
Fuzzy c means manual work
Dr.E.N.Sathishkumar
 
Character generation
Ankit Garg
 
04 Multi-layer Feedforward Networks
Tamer Ahmed Farrag, PhD
 

Similar to Graphics Programming OpenGL & GLUT in Code::Blocks (20)

PPT
01.Opengl_intro-2.ppt
EngrZamaan
 
PPT
openGL basics for sample program (1).ppt
HIMANKMISHRA2
 
PPT
openGL basics for sample program.ppt
HIMANKMISHRA2
 
PPT
Open gl
ch samaram
 
PPT
Opengl (1)
ch samaram
 
PPT
Intro to Computer Graphics.ppt
adil104135
 
PPT
opengl.ppt
Subiksha57
 
PDF
Grafika komputer 2
Nur Fadli Utomo
 
PPTX
Computer Graphics with OpenGL presentation Slides.pptx
AnandM62785
 
PDF
18csl67 vtu lab manual
NatsuDragoneel5
 
PPT
Open Graphics Library
Azmeen Gadit
 
PPT
Introduction to OpenGL.ppt
16118MdFirozAhmed
 
PPT
Programming with OpenGL
Syed Zaid Irshad
 
PPT
Hill ch2ed3
Kunal Verma
 
PDF
graphics notes on computer science students to study various algorithmic-054-...
RavinderKSingla
 
PPT
september11.ppt
CharlesMatu2
 
DOCX
Lab Practices and Works Documentation / Report on Computer Graphics
Rup Chowdhury
 
PPTX
OpenGL_summer2012.ccccccccccccccccccpptx
arcse1
 
PPT
3.Computer graphics _ Opengl _ intro.ppt
dinasaif3
 
01.Opengl_intro-2.ppt
EngrZamaan
 
openGL basics for sample program (1).ppt
HIMANKMISHRA2
 
openGL basics for sample program.ppt
HIMANKMISHRA2
 
Open gl
ch samaram
 
Opengl (1)
ch samaram
 
Intro to Computer Graphics.ppt
adil104135
 
opengl.ppt
Subiksha57
 
Grafika komputer 2
Nur Fadli Utomo
 
Computer Graphics with OpenGL presentation Slides.pptx
AnandM62785
 
18csl67 vtu lab manual
NatsuDragoneel5
 
Open Graphics Library
Azmeen Gadit
 
Introduction to OpenGL.ppt
16118MdFirozAhmed
 
Programming with OpenGL
Syed Zaid Irshad
 
Hill ch2ed3
Kunal Verma
 
graphics notes on computer science students to study various algorithmic-054-...
RavinderKSingla
 
september11.ppt
CharlesMatu2
 
Lab Practices and Works Documentation / Report on Computer Graphics
Rup Chowdhury
 
OpenGL_summer2012.ccccccccccccccccccpptx
arcse1
 
3.Computer graphics _ Opengl _ intro.ppt
dinasaif3
 
Ad

More from Budditha Hettige (20)

PDF
Algorithm analysis
Budditha Hettige
 
PDF
Sorting
Budditha Hettige
 
PDF
Link List
Budditha Hettige
 
PDF
02 Stack
Budditha Hettige
 
PDF
Data Structures 01
Budditha Hettige
 
PDF
Drawing Fonts
Budditha Hettige
 
PDF
Texture Mapping
Budditha Hettige
 
PDF
Lighting
Budditha Hettige
 
PDF
Viewing
Budditha Hettige
 
PDF
OpenGL 3D Drawing
Budditha Hettige
 
PDF
2D Drawing
Budditha Hettige
 
PDF
Introduction to Computer Graphics
Budditha Hettige
 
PPTX
Computer System Architecture Lecture Note 9 IO fundamentals
Budditha Hettige
 
PPTX
Computer System Architecture Lecture Note 8.1 primary Memory
Budditha Hettige
 
PPTX
Computer System Architecture Lecture Note 8.2 Cache Memory
Budditha Hettige
 
PPTX
Computer System Architecture Lecture Note 7 addressing
Budditha Hettige
 
PPT
Computer System Architecture Lecture Note 6: hardware performance
Budditha Hettige
 
PPT
Computer System Architecture Lecture Note 5: microprocessor technology
Budditha Hettige
 
PPT
Computer System Architecture Lecture Note 3: computer architecture
Budditha Hettige
 
Algorithm analysis
Budditha Hettige
 
Link List
Budditha Hettige
 
Data Structures 01
Budditha Hettige
 
Drawing Fonts
Budditha Hettige
 
Texture Mapping
Budditha Hettige
 
OpenGL 3D Drawing
Budditha Hettige
 
2D Drawing
Budditha Hettige
 
Introduction to Computer Graphics
Budditha Hettige
 
Computer System Architecture Lecture Note 9 IO fundamentals
Budditha Hettige
 
Computer System Architecture Lecture Note 8.1 primary Memory
Budditha Hettige
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Budditha Hettige
 
Computer System Architecture Lecture Note 7 addressing
Budditha Hettige
 
Computer System Architecture Lecture Note 6: hardware performance
Budditha Hettige
 
Computer System Architecture Lecture Note 5: microprocessor technology
Budditha Hettige
 
Computer System Architecture Lecture Note 3: computer architecture
Budditha Hettige
 
Ad

Recently uploaded (20)

PPTX
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPTX
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
PDF
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
digestive system for Pharm d I year HAP
rekhapositivity
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 

Graphics Programming OpenGL & GLUT in Code::Blocks

  • 1. CSC 307 1.0 Graphics Programming Budditha Hettige Department of Statistics and Computer Science
  • 2. Graphics Programming OpenGL & GLUT in Code::Blocks 2Budditha Hettige
  • 3. OpenGL & Code::block • Download Code::Blocks – http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/ • Download the GLUT bin file from – http://www.xmission.com/~nate/glut.html • Save files as – Copy glut32.dll to • C:windowssystem – Copy glut32.lib to • C:Program FilesCodeBlocksMinGWlib, – Copy glut.h to • C:Program FilesCodeBlocksMinGWincludeGL. 3Budditha Hettige
  • 4. Code::Bolock Project 1. Start Code::Blocks and make a new project. 2. Select to make a new GLUT project and press Go to continue. 3. Press Next at this menu 4 2 3 Budditha Hettige
  • 5. Code::Bolock Project 4. Give a project title, and a location where to create the project and then press Next 5. Tell Code::Blocks to where you stored your GL files, then press Next 5 4 5 Budditha Hettige
  • 6. Code::Bolock Project • Set compiler as “GNU GCC Compiler”, and press Finish. • Open up the sample source file by double clicking on it • Add #include <windows.h> at line 14 6Budditha Hettige
  • 7. Code::Bolock Project • Compile and build an application 7Budditha Hettige
  • 8. Sample 01 # include <windows.h> #include <GL/glut.h> void mydisplay() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop(); } 8Budditha Hettige
  • 9. GLUT Functions glutInit(int *argc, char** argv); Initializes a window session. glutCreateWindow(char *name); Creates a window with title *name. glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); Sets the display mode to single buffered and RGB color. glutInitWindowSize (GLsizei h, GLsizei w); Sets initial window size to h x w. glutInitWindowPosition(x,y); Sets initial window position to (x, y). 9Budditha Hettige
  • 10. GLUT Functions • void glFlush() force execution of GL commands in finite time • void glutDisplayFunc(void (*func)(void)); sets the display callback for the current window. • void glutMainLoop(void); Enters the GLUT event processing loop 10Budditha Hettige
  • 11. OpenGL Attributes • glClearColor(1.0, 1.0, 1.0, 0.0); – Sets background color to white – Fourth argument is transparency; 0.0 is opaque – Sets a state variable • glPointSize(2.0); – Sets point size to be 2 pixels wide – Note that this is not a device-independent attribute – Sets a state variable 11Budditha Hettige
  • 12. glClear • Clearing the Color Buffer – glClear(GL_COLOR_BUFFER_BIT); • Values – GL_COLOR_BUFFER_BIT Indicates the buffers currently enabled for color writing. – GL_DEPTH_BUFFER_BIT Indicates the depth buffer. – GL_ACCUM_BUFFER_BIT Indicates the accumulation buffer. – GL_STENCIL_BUFFER_BIT Indicates the stencil buffer. 12Budditha Hettige
  • 14. OpenGL Primitive Syntax glBegin ( type ); glVertex* ( ); . . . . glVertex* ( ); glEnd ( ); 14 glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, -10.0f); glVertex3f(-1.0f,-1.0f, -10.0f); glVertex3f( 1.0f,-1.0f, -10.0f); glEnd(); glBegin(GL_LINES); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glEnd(); Budditha Hettige
  • 15. Sample 02 # include <windows.h> # include <GL/glut.h> void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 0.0, 0.0); //red glBegin(GL_QUADS); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glColor3f (0.0, 0.0, 1.0); //blue glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); glutSolidSphere(0.15,12,2); //draw a sphere glFlush (); } 15 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); } Budditha Hettige
  • 16. Sample 02 void init (void) { glClearColor (0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } 16Budditha Hettige
  • 17. glutInitDisplayMode • Sets the initial display mode. – glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); • Values – GLUT_RGBA – GLUT_RGB – GLUT_INDEX – GLUT_SINGLE – GLUT_DOUBLE – GLUT_ACCUM – GLUT_ALPHA – GLUT_DEPTH – GLUT_STENCIL – GLUT_MULTISAMPLE – GLUT_STEREO – GLUT_LUMINANCE 17Budditha Hettige
  • 18. glColor • Set the current color – glColor3f (1.0, 0.0, 0.0); • Example – void glColor3i(GLint red, GLint green, GLint blue); – void glColor3f(GLfloat red, GLfloat green, GLfloat blue); – glColor3f (1.0, 0.0, 0.0); //red – glColor3f (0.0, 0.0, 1.0); //blue 18Budditha Hettige
  • 19. Budditha Hettige 19 OpenGL Transformations • Before applying modeling or viewing transformations, need to set glMatrixMode(GL_MODELVIEW) • Before applying projection transformations, need to set glMatrixMode(GL_Projection) • Replacement by either following commands glLoadIdentity(); glLoadMatrix(M); • Multiple transformations (either in modeling or viewing) are applied in reverse order
  • 20. Projection Transformation • Transformation from scene to image • Orthographic projection – glOrtho (left, right, bottom, top, near, far) • Perspective projection – glFrustum (left, right, bottom, top, near, far) 20Budditha Hettige
  • 21. Setting Viewing Matrix glMatrixMode(GL_PROJECTION); Sets the switch so that loaded matrix goes into the projection stack. glLoadIdentity(); Pushes an identity matrix onto the stack; gluOrtho2D(GLdouble left, Gldouble right, Gldouble bottom, Gldouble top); Sets the current view to an orthographic projection with view volume bounded by x = left, x = right, y = bottom, y = top, z = -1.0 and z = 1.0. 21Budditha Hettige
  • 22. Viewport Transformation MyWindow x y h w void glViewport(Glint x, GLint y, GLsizei w, Glsizei h); Default viewport corresponds to entire window drawable area. Clipping Window Budditha Hettige 22
  • 23. Example • GL_POINTS • GL_LINES • GL_TRIANGLES • GL_TRIANGLE_STRIP • GL_QUAD_STRIP • GL_LINE_STRIP • GL_LINE_LOOP • GL_QUADS • GL_POLYGON • GL_TRIANGLE_FAN 23Budditha Hettige