SlideShare a Scribd company logo
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

Turing machine
Turing machineTuring machine
Turing machine
Захір Райхан
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machine
Mian Munib
 
AI: Planning and AI
AI: Planning and AIAI: Planning and AI
AI: Planning and AI
DataminingTools Inc
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
ABHISHEK KUMAR
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
Abhishek Singh
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AI
Kirti Verma
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
Radhakrishnan Chinnusamy
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
arunsingh660
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
Akhil Kaushik
 
Reconfigurable computing
Reconfigurable computingReconfigurable computing
Reconfigurable computing
Sudhanshu Janwadkar
 
Artificial Intelligence by B. Ravikumar
Artificial Intelligence by B. RavikumarArtificial Intelligence by B. Ravikumar
Artificial Intelligence by B. Ravikumar
Garry D. Lasaga
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
 
Hardware Acceleration for Machine Learning
Hardware Acceleration for Machine LearningHardware Acceleration for Machine Learning
Hardware Acceleration for Machine Learning
CastLabKAIST
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
19magnet
 
Production System in AI
Production System in AIProduction System in AI
Production System in AI
Bharat Bhushan
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Memory Protection Unit (MPU) (1).pptx
Memory Protection Unit                 (MPU) (1).pptxMemory Protection Unit                 (MPU) (1).pptx
Memory Protection Unit (MPU) (1).pptx
VarunP31
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
Munawar Ahmed
 
Lecture_16_Self-supervised_Learning.pptx
Lecture_16_Self-supervised_Learning.pptxLecture_16_Self-supervised_Learning.pptx
Lecture_16_Self-supervised_Learning.pptx
Karimdabbabi
 

What's hot (20)

Turing machine
Turing machineTuring machine
Turing machine
 
Moore and mealy machine
Moore and mealy machineMoore and mealy machine
Moore and mealy machine
 
AI: Planning and AI
AI: Planning and AIAI: Planning and AI
AI: Planning and AI
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AI
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Reconfigurable computing
Reconfigurable computingReconfigurable computing
Reconfigurable computing
 
Artificial Intelligence by B. Ravikumar
Artificial Intelligence by B. RavikumarArtificial Intelligence by B. Ravikumar
Artificial Intelligence by B. Ravikumar
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Hardware Acceleration for Machine Learning
Hardware Acceleration for Machine LearningHardware Acceleration for Machine Learning
Hardware Acceleration for Machine Learning
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
Production System in AI
Production System in AIProduction System in AI
Production System in AI
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Memory Protection Unit (MPU) (1).pptx
Memory Protection Unit                 (MPU) (1).pptxMemory Protection Unit                 (MPU) (1).pptx
Memory Protection Unit (MPU) (1).pptx
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Lecture_16_Self-supervised_Learning.pptx
Lecture_16_Self-supervised_Learning.pptxLecture_16_Self-supervised_Learning.pptx
Lecture_16_Self-supervised_Learning.pptx
 

Similar to Graphics Programming OpenGL & GLUT in Code::Blocks

Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
AnandM62785
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
HIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
HIMANKMISHRA2
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
Girish Ghate
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
vineet raj
 
Open gl
Open glOpen gl
Open gl
ch samaram
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
ch samaram
 
Open GL Programming Training Session I
Open GL Programming Training Session IOpen GL Programming Training Session I
Open GL Programming Training Session I
NEEVEE Technologies
 
CGLabLec6.pptx
CGLabLec6.pptxCGLabLec6.pptx
CGLabLec6.pptx
Mohammad7Abudosh7
 
01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt
EngrZamaan
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
AbdelrahmanElewah1
 
The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202
Mahmoud Samir Fayed
 
Ctrl-C redesign for gcc cauldron in 2022 in prague
Ctrl-C redesign for gcc cauldron in 2022 in pragueCtrl-C redesign for gcc cauldron in 2022 in prague
Ctrl-C redesign for gcc cauldron in 2022 in prague
ssuser866937
 
BYO3D 2011: Rendering
BYO3D 2011: RenderingBYO3D 2011: Rendering
BYO3D 2011: Rendering
Matt Hirsch - MIT Media Lab
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
Mark Kilgard
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
Kunal Verma
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
opengl.ppt
opengl.pptopengl.ppt
opengl.ppt
Subiksha57
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.ppt
adil104135
 

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

Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
Open gl
Open glOpen gl
Open gl
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
Open GL Programming Training Session I
Open GL Programming Training Session IOpen GL Programming Training Session I
Open GL Programming Training Session I
 
CGLabLec6.pptx
CGLabLec6.pptxCGLabLec6.pptx
CGLabLec6.pptx
 
01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180The Ring programming language version 1.5.1 book - Part 52 of 180
The Ring programming language version 1.5.1 book - Part 52 of 180
 
The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202The Ring programming language version 1.8 book - Part 60 of 202
The Ring programming language version 1.8 book - Part 60 of 202
 
Ctrl-C redesign for gcc cauldron in 2022 in prague
Ctrl-C redesign for gcc cauldron in 2022 in pragueCtrl-C redesign for gcc cauldron in 2022 in prague
Ctrl-C redesign for gcc cauldron in 2022 in prague
 
BYO3D 2011: Rendering
BYO3D 2011: RenderingBYO3D 2011: Rendering
BYO3D 2011: Rendering
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
opengl.ppt
opengl.pptopengl.ppt
opengl.ppt
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.ppt
 

More from Budditha Hettige

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
Budditha Hettige
 
Sorting
SortingSorting
Link List
Link ListLink List
Link List
Budditha Hettige
 
Queue
QueueQueue
02 Stack
02 Stack02 Stack
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
Budditha Hettige
 
Drawing Fonts
Drawing FontsDrawing Fonts
Drawing Fonts
Budditha Hettige
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
Budditha Hettige
 
Lighting
LightingLighting
Viewing
ViewingViewing
OpenGL 3D Drawing
OpenGL 3D DrawingOpenGL 3D Drawing
OpenGL 3D Drawing
Budditha Hettige
 
2D Drawing
2D Drawing2D Drawing
2D Drawing
Budditha Hettige
 
Introduction to Computer Graphics
Introduction to Computer GraphicsIntroduction to Computer Graphics
Introduction to Computer Graphics
Budditha Hettige
 
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentalsComputer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentals
Budditha Hettige
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
Budditha Hettige
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
Budditha Hettige
 
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressingComputer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressing
Budditha Hettige
 
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performanceComputer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performance
Budditha Hettige
 
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technologyComputer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technology
Budditha Hettige
 
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architectureComputer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architecture
Budditha Hettige
 

More from Budditha Hettige (20)

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Sorting
SortingSorting
Sorting
 
Link List
Link ListLink List
Link List
 
Queue
QueueQueue
Queue
 
02 Stack
02 Stack02 Stack
02 Stack
 
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
 
Drawing Fonts
Drawing FontsDrawing Fonts
Drawing Fonts
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
 
Lighting
LightingLighting
Lighting
 
Viewing
ViewingViewing
Viewing
 
OpenGL 3D Drawing
OpenGL 3D DrawingOpenGL 3D Drawing
OpenGL 3D Drawing
 
2D Drawing
2D Drawing2D Drawing
2D Drawing
 
Introduction to Computer Graphics
Introduction to Computer GraphicsIntroduction to Computer Graphics
Introduction to Computer Graphics
 
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentalsComputer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentals
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
 
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressingComputer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressing
 
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performanceComputer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performance
 
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technologyComputer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technology
 
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architectureComputer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architecture
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 

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