SlideShare ist ein Scribd-Unternehmen logo
1 von 3
#include<windows.h>
#include <GL/glut.h>
#include<iostream>
#include <stdlib.h>
using namespace std;
void handleKeypress(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
}
}
void initRendering()
{
glEnable(GL_DEPTH_TEST);
}
void handleResize(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(double)w/(double)h,1.0,200.0);
}
float _angle=0.0;
float _cameraangle=30.0;
void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(_cameraangle,0.0f,1.0f,0.0f); //rotate object by 30 degree
with respect to y-axis
glTranslatef(0.0f, 0.0f, -10.0f);
glPushMatrix();
glTranslatef(5.0f, -1.0f, 0.0f);
glScalef(2.0f,2.0f,2.0f);
glRotatef(_angle,1.0f,3.0f,2.0f); //rotating object continuously by 2
degree
glBegin(GL_QUADS);
glVertex3f(-0.7f,0.0f,0.0);
glVertex3f(0.7f,0.0f,0.0);
glVertex3f(0.5f,2.0f,0.0);
glVertex3f(-0.5f,2.0f,0.0);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void update(int value)
{
_angle+=2.0f;
if(_angle>360.f)
{
_angle-=360;
}
glutPostRedisplay();
glutTimerFunc(25,update,0);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("rotate");
initRendering();
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutTimerFunc(25,update,0);
//this call the function update in every 25 millsecond
//so value of angle of rotation change and object rotates continuously
glutMainLoop();
return 0;
}

Weitere ähnliche Inhalte

Was ist angesagt?

BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderer
tobias_persson
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
Cass Everitt
 

Was ist angesagt? (20)

OpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesOpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering Techniques
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
20221021_JP5.0.2-Webinar-JP_Final.pdf
20221021_JP5.0.2-Webinar-JP_Final.pdf20221021_JP5.0.2-Webinar-JP_Final.pdf
20221021_JP5.0.2-Webinar-JP_Final.pdf
 
Arduino presentation
Arduino presentationArduino presentation
Arduino presentation
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017NVIDIA OpenGL 4.6 in 2017
NVIDIA OpenGL 4.6 in 2017
 
Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019
 
あるRISC-V CPUの 浮動小数点数(異常なし)
あるRISC-V CPUの 浮動小数点数(異常なし)あるRISC-V CPUの 浮動小数点数(異常なし)
あるRISC-V CPUの 浮動小数点数(異常なし)
 
Corso c++
Corso c++Corso c++
Corso c++
 
BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderer
 
Arduino序列通訊應用
Arduino序列通訊應用Arduino序列通訊應用
Arduino序列通訊應用
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
 
Dbms3
Dbms3Dbms3
Dbms3
 
pixel SK6812 rgb led specification datasheet from hanron lighting
pixel SK6812  rgb led specification datasheet from hanron lightingpixel SK6812  rgb led specification datasheet from hanron lighting
pixel SK6812 rgb led specification datasheet from hanron lighting
 
Seminário - Linguagem Dart: Structured web apps
Seminário - Linguagem Dart: Structured web appsSeminário - Linguagem Dart: Structured web apps
Seminário - Linguagem Dart: Structured web apps
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
 
Arduino序列通訊
Arduino序列通訊Arduino序列通訊
Arduino序列通訊
 
FPGAスタートアップ資料
FPGAスタートアップ資料FPGAスタートアップ資料
FPGAスタートアップ資料
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptx
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 

Andere mochten auch (8)

[StockDice] Application for Stock Exchange Monitoring And Business Intelligen...
[StockDice] Application for Stock Exchange Monitoring And Business Intelligen...[StockDice] Application for Stock Exchange Monitoring And Business Intelligen...
[StockDice] Application for Stock Exchange Monitoring And Business Intelligen...
 
Setting up your first open gl program
Setting up your first open gl programSetting up your first open gl program
Setting up your first open gl program
 
Open gl
Open glOpen gl
Open gl
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL Animation
 
Open gl
Open glOpen gl
Open gl
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
Open gl basics
Open gl basicsOpen gl basics
Open gl basics
 
Iterative deepening search
Iterative deepening searchIterative deepening search
Iterative deepening search
 

Ähnlich wie Rotate an object in open gl(glut) sample example with source

animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdf
ambritgames
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.ppt
adil104135
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wire
René Domínguez
 
Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)
Robi Parvez
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp Open
MikeEly930
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flag
Robi Parvez
 
HCI302-Computer Graphics-Section 6 (1).pptx
HCI302-Computer Graphics-Section 6 (1).pptxHCI302-Computer Graphics-Section 6 (1).pptx
HCI302-Computer Graphics-Section 6 (1).pptx
nadinAlaa
 

Ähnlich wie Rotate an object in open gl(glut) sample example with source (20)

Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
Laporan modul2
Laporan modul2Laporan modul2
Laporan modul2
 
Practica
PracticaPractica
Practica
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cpp
 
animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdf
 
FLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - ExercisesFLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - Exercises
 
01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt01.Opengl_intro-2.ppt
01.Opengl_intro-2.ppt
 
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
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wire
 
Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)
 
computer graphics at openGL
computer graphics at openGLcomputer graphics at openGL
computer graphics at openGL
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
 
Working with Callbacks
Working with CallbacksWorking with Callbacks
Working with Callbacks
 
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp Open
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flag
 
HCI302-Computer Graphics-Section 6 (1).pptx
HCI302-Computer Graphics-Section 6 (1).pptxHCI302-Computer Graphics-Section 6 (1).pptx
HCI302-Computer Graphics-Section 6 (1).pptx
 
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Rotate an object in open gl(glut) sample example with source

  • 1. #include<windows.h> #include <GL/glut.h> #include<iostream> #include <stdlib.h> using namespace std; void handleKeypress(unsigned char key, int x, int y) { switch(key) { case 27: exit(0); } } void initRendering() { glEnable(GL_DEPTH_TEST); } void handleResize(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)w/(double)h,1.0,200.0); } float _angle=0.0; float _cameraangle=30.0; void drawScene() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(_cameraangle,0.0f,1.0f,0.0f); //rotate object by 30 degree with respect to y-axis glTranslatef(0.0f, 0.0f, -10.0f); glPushMatrix();
  • 2. glTranslatef(5.0f, -1.0f, 0.0f); glScalef(2.0f,2.0f,2.0f); glRotatef(_angle,1.0f,3.0f,2.0f); //rotating object continuously by 2 degree glBegin(GL_QUADS); glVertex3f(-0.7f,0.0f,0.0); glVertex3f(0.7f,0.0f,0.0); glVertex3f(0.5f,2.0f,0.0); glVertex3f(-0.5f,2.0f,0.0); glEnd(); glPopMatrix(); glutSwapBuffers(); } void update(int value) { _angle+=2.0f; if(_angle>360.f) { _angle-=360; } glutPostRedisplay(); glutTimerFunc(25,update,0); } int main(int argc,char**argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(600,600); glutCreateWindow("rotate"); initRendering(); glutDisplayFunc(drawScene); glutKeyboardFunc(handleKeypress); glutReshapeFunc(handleResize); glutTimerFunc(25,update,0);
  • 3. //this call the function update in every 25 millsecond //so value of angle of rotation change and object rotates continuously glutMainLoop(); return 0; }