{"id":3057,"date":"2022-09-11T19:22:32","date_gmt":"2022-09-11T14:22:32","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=3057"},"modified":"2022-09-11T19:22:35","modified_gmt":"2022-09-11T14:22:35","slug":"how-to-draw-3d-house-animation-using-cpp-and-opengl","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/","title":{"rendered":"How to Draw 3D House Animation Using C++ and OpenGL"},"content":{"rendered":"\n<p>In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation software is given below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ OpenGL 3D House Animation Code<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">code.cpp<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n#include &lt;stdlib.h&gt;\n\n#ifdef __APPLE__\n#include &lt;OpenGL\/OpenGL.h&gt;\n#include &lt;GLUT\/glut.h&gt;\n#else\n#include &lt;GL\/glut.h&gt;\n#endif\n\nusing namespace std;\nvoid handleKeypress(unsigned char key, int x, int y) {\n    switch (key) {\n    case 27:\n        exit(0);\n    }\n}\nvoid initRendering() {\n    glEnable(GL_DEPTH_TEST);\n}\nvoid handleResize(int w, int h) {\n    glViewport(0, 0, w, h);\n    glMatrixMode(GL_PROJECTION);\n    glLoadIdentity();\n    gluPerspective(45.0, (double) w \/ (double) h, 1.0, 200.0);\n}\nfloat _angle = 45.0f;\nfloat _cameraAngle = 0.0f;\nvoid drawScene() {\n    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\n    glMatrixMode(GL_MODELVIEW);\n    glLoadIdentity();\n    glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f);\n    glTranslatef(-1.0f, -1.5f, -2.0f);\n    glPopMatrix();\n    glPushMatrix();\n    glTranslatef(1.0f, 1.0f, 0.0f);\n    glRotatef(_angle, 0.0f, 1.0f, 0.0f);\n    glScalef(1.0f, 1.0f, 1.0f);\n    glColor3f(1.0, 0.25, 1.0);\n    glColor3f (.5, 0.5, .25);\n\n    \/* main rec *\/\n    glClear (GL_COLOR_BUFFER_BIT);\n    glColor3f (.5, .75, .35);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.2, 0.1, 0.0);\n    glVertex3f (0.9, 0.1, 0.0);\n    glVertex3f (0.9, 0.575, 0.0);\n    glVertex3f (0.2, 0.575, 0.0);\n    glEnd();\n\n    \/*back rec*\/\n    glColor3f (.5, .75, .35);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.2, 0.1, 0.5);\n    glVertex3f (0.9, 0.1, 0.5);\n    glVertex3f (0.9, 0.575, 0.5);\n    glVertex3f (0.2, 0.575, 0.5);\n    glEnd();\n\n    \/* left rec *\/\n    glColor3f (.75, 0.75, .25);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.2, 0.1, 0.5);\n    glVertex3f (0.2, 0.1, 0.0);\n    glVertex3f (0.2, 0.575, 0.0);\n    glVertex3f (0.2, 0.575, 0.5);\n    glEnd();\n\n    \/* right rec *\/\n    glColor3f (.75, 0.75, .25);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.9, 0.1, 0.5);\n    glVertex3f (0.9, 0.1, 0.0);\n    glVertex3f (0.9, 0.575, 0.0);\n    glVertex3f (0.9, 0.575, 0.5);\n    glEnd();\n\n    \/* left tri *\/\n    glColor3f (.5, 0.5, .25);\n    glBegin(GL_TRIANGLES);\n    glVertex3f (0.9, 0.575, 0.0);\n    glVertex3f (0.9, 0.575, 0.5);\n    glVertex3f (0.9, 0.8, 0.25);\n    glEnd();\n\n    \/* right tri *\/\n    glColor3f (.5, 0.5, .25);\n    glBegin(GL_TRIANGLES);\n    glVertex3f (0.2, 0.575, 0.0);\n    glVertex3f (0.2, 0.575, 0.5);\n    glVertex3f (0.2, 0.8, 0.25);\n    glEnd();\n\n    \/* roof *\/\n    glColor3f (.55, 0.35, .2);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.2, 0.575, 0.0);\n    glVertex3f (0.9, 0.575, 0.0);\n    glVertex3f (0.9, 0.8, 0.25);\n    glVertex3f (0.2, 0.8, 0.25);\n    glEnd();\n\n    \/*back roof *\/\n    glColor3f (.55, 0.35, .2);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.2, 0.575, 0.5);\n    glVertex3f (0.9, 0.575, 0.5);\n    glVertex3f (0.9, 0.8, 0.25);\n    glVertex3f (0.2, 0.8, 0.25);\n    glEnd();\n\n    \/* door *\/\n    glColor3f (.15, 0.2, .3);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.47, 0.105, 0.0);\n    glVertex3f (0.65, 0.105, 0.0);\n    glVertex3f (0.65, 0.46, 0.0);\n    glVertex3f (0.47, 0.46, 0.0);\n    glEnd();\n\n    \/* window 1 *\/\n    glColor3f (.3, 0.2, .1);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.72, 0.25, 0.0);\n    glVertex3f (0.83, 0.25, 0.0);\n    glVertex3f (0.83, 0.4, 0.0);\n    glVertex3f (0.72, 0.4, 0.0);\n    glEnd();\n\n    \/* window 2 *\/\n    glColor3f (.3, 0.2, .1);\n    glBegin(GL_POLYGON);\n    glVertex3f (0.27, 0.25, 0.0);\n    glVertex3f (0.38, 0.25, 0.0);\n    glVertex3f (0.38, 0.4, 0.0);\n    glVertex3f (0.27, 0.4, 0.0);\n    glEnd();\n\n\n    glFlush ();\n    glPopMatrix();\n    glutSwapBuffers();\n}\nvoid update(int value) {\n    _angle += 1.0f;\n    if (_angle &gt; 360) {\n        _angle -= 360;\n    }\n    glutPostRedisplay();\n    glutTimerFunc(25, update, 0);\n}\nint main(int argc, char * * argv) {\n    glutInit( &amp; argc, argv);\n    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);\n    glutInitWindowSize(1000, 800);\n    glutCreateWindow(&quot;3D House Rotate&quot;);\n    initRendering();\n    glutDisplayFunc(drawScene);\n    glutKeyboardFunc(handleKeypress);\n    glutReshapeFunc(handleResize);\n    glutTimerFunc(25, update, 0);\n    glutMainLoop();\n    return 0;\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation software is given below. C++ OpenGL 3D House Animation Code code.cpp<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-3057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Draw 3D House Animation Using C++ and OpenGL<\/title>\n<meta name=\"description\" content=\"In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Draw 3D House Animation Using C++ and OpenGL\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-11T14:22:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-11T14:22:35+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Draw 3D House Animation Using C++ and OpenGL","description":"In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/","og_locale":"en_US","og_type":"article","og_title":"How to Draw 3D House Animation Using C++ and OpenGL","og_description":"In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation","og_url":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-09-11T14:22:32+00:00","article_modified_time":"2022-09-11T14:22:35+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"How to Draw 3D House Animation Using C++ and OpenGL","datePublished":"2022-09-11T14:22:32+00:00","dateModified":"2022-09-11T14:22:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/"},"wordCount":51,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/","url":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/","name":"How to Draw 3D House Animation Using C++ and OpenGL","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-09-11T14:22:32+00:00","dateModified":"2022-09-11T14:22:35+00:00","description":"In this tutorial, I will show you how to dram 3D house animation using C++ and OpenGL in the command line. The complete source code of 3D House Animation","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/how-to-draw-3d-house-animation-using-cpp-and-opengl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Draw 3D House Animation Using C++ and OpenGL"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=3057"}],"version-history":[{"count":1,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3057\/revisions"}],"predecessor-version":[{"id":3058,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3057\/revisions\/3058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=3057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=3057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=3057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}