{"id":84,"date":"2021-06-08T10:31:06","date_gmt":"2021-06-08T10:31:06","guid":{"rendered":"http:\/\/athenswonder.com\/?p=84"},"modified":"2021-06-08T10:44:32","modified_gmt":"2021-06-08T10:44:32","slug":"first-opengl-program-in-linux-mint-17-with-gcc-and-code-blocks","status":"publish","type":"post","link":"https:\/\/athenswonder.com\/?p=84","title":{"rendered":"FIRST OPENGL PROGRAM IN LINUX MINT 17 WITH GCC AND CODE BLOCKS"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/nexon7.files.wordpress.com\/2014\/09\/firstglprogramlinux.jpg?w=470\" alt=\"firstglprogramlinux\" class=\"wp-image-1025\"\/><\/figure>\n\n\n\n<p><strong>1. Basic Program<\/strong><\/p>\n\n\n\n<p><strong>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<\/strong><\/p>\n\n\n\n<p><strong>Install C and C++ Compilers in Linux Mint<\/strong><\/p>\n\n\n\n<p>sudo aptitude install build-essential<\/p>\n\n\n\n<p>or<\/p>\n\n\n\n<p>sudo apt-get install build-essential<\/p>\n\n\n\n<p>This will install all the required packages for C and C++ compilers<\/p>\n\n\n\n<p>Compiling Your first C Programs \u2013<\/p>\n\n\n\n<p>Now you need to open first.c file<\/p>\n\n\n\n<p>sudo gedit first.c<\/p>\n\n\n\n<p>add the following lines save and exit the file<\/p>\n\n\n\n<p>#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p>int main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>printf(\u201cHello world\\n\u201d);<\/p>\n\n\n\n<p>return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>or<\/p>\n\n\n\n<p>right click in \/home\/[UserName]<\/p>\n\n\n\n<p>Create New Document -&gt; Empty Document<\/p>\n\n\n\n<p>name file icheck.cpp<\/p>\n\n\n\n<p>paste this program<\/p>\n\n\n\n<p>\/\/ Hello World<\/p>\n\n\n\n<p>#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p>main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>printf(\u201cHello, world!\\n\u201d);<\/p>\n\n\n\n<p>return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>Or this program<\/p>\n\n\n\n<p>\/\/ C program to check whether a given integer is odd or even<\/p>\n\n\n\n<p>#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p>int main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>int ival, remainder;<\/p>\n\n\n\n<p>printf(\u201cEnter an integer : \u201c);<\/p>\n\n\n\n<p>scanf(\u201c%d\u201d, &amp;ival);<\/p>\n\n\n\n<p>remainder = ival % 2;<\/p>\n\n\n\n<p>if (remainder == 0)<\/p>\n\n\n\n<p>printf(\u201c%d is an even integer\\n\u201d, ival);<\/p>\n\n\n\n<p>else<\/p>\n\n\n\n<p>printf(\u201c%d is an odd integer\\n\u201d, ival);<\/p>\n\n\n\n<p>return 1;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>(UserName is scott)<\/p>\n\n\n\n<p>Open Terminal (Hotkey \u2013 Control + Alt + T)<\/p>\n\n\n\n<p>gcc \/home\/scott\/icheck.cpp<\/p>\n\n\n\n<p>\/home\/scott\/a.out&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (a.out is defult output file if no name is supplied, and is created in \/home\/scott folder by default)<\/p>\n\n\n\n<p>Or<\/p>\n\n\n\n<p>gcc -o hello hello.c<\/p>\n\n\n\n<p>where hello is the name of output file<\/p>\n\n\n\n<p>\/home\/scott\/hello<\/p>\n\n\n\n<p>now do input and output in terminal.<\/p>\n\n\n\n<p><strong>Code Blocks \u2013<\/strong><\/p>\n\n\n\n<p>File -&gt; New project -&gt; Console Application<\/p>\n\n\n\n<p>folder \u2013 \/home\/scott\/ hw\/hw_basic<\/p>\n\n\n\n<p>path \u2013 \/home\/scott\/hw\/hw_basic\/hw_basic.cpp<\/p>\n\n\n\n<p>see \u2013 hw_basic.cpp for source code<\/p>\n\n\n\n<p>Set path \u2013 \/home\/scott\/hw\/hw_basic\/hw_basic.cpp<\/p>\n\n\n\n<p>Use F9 or compile button in toolbar to run the program<\/p>\n\n\n\n<p>compiled Exe (hw_basic) is in \u2013 \/home\/scott\/hw\/hw_basic\/bin\/Release<\/p>\n\n\n\n<p>Start Terminal<\/p>\n\n\n\n<p>\/home\/scott\/hw\/hw_basic\/bin\/Release\/hw_basic<\/p>\n\n\n\n<p><strong>&nbsp;2.&nbsp;OpenGL Program<\/strong><\/p>\n\n\n\n<p><strong>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<\/strong><\/p>\n\n\n\n<p><strong>Nividia Driver instalation in Linux Mint 17<\/strong><\/p>\n\n\n\n<p><strong>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2013<\/strong><\/p>\n\n\n\n<p>You need to connected to internet, you should be able to download 70 \u2013 100 MB in reasonable time. (3G, Broadband connection is preferred)<\/p>\n\n\n\n<p>Start Menu \u2013 Administration \u2013 Driver Manager<\/p>\n\n\n\n<p>select \u2013 nvidia 331 (recommended)<\/p>\n\n\n\n<p>[Apply changes]<\/p>\n\n\n\n<p>Above step installs working proprietary nvidia drivers. After that you can install latest nvidia drivers. This step also removes the problem of noveau interferring with installation if latest driver (run file from nvidia) is directly installed.<\/p>\n\n\n\n<p>Optional \u2013 (If you want latest drivers)<\/p>\n\n\n\n<p>Then Download the latest driver like \u201cNVIDIA-Linux-x86_64-340.32.run\u201d from nvidia website.<\/p>\n\n\n\n<p>Save it in \u201c\/home\/nea\/drv\/n340.run\u201d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (change name for easy typing in terminal)<\/p>\n\n\n\n<p>Start Terminal (Ctrl + Alt + T)<\/p>\n\n\n\n<p>sudo service mdm stop<\/p>\n\n\n\n<p>You will go to command line. Login Again.<\/p>\n\n\n\n<p>sudo telinit 3<\/p>\n\n\n\n<p>sudo sh \/home\/nea\/drv\/n340.run<\/p>\n\n\n\n<p>Now the driver will install. Accept, Rebuild Modules or Script<\/p>\n\n\n\n<p>sudo service mdm start (very important)<\/p>\n\n\n\n<p>If X Sever does not start or system hangs or Command Line, press Ctrl + Alt + Del to restart. Or restart from restart button.<\/p>\n\n\n\n<p>After restart. Login, Check Driver version from Start Menu -&gt; Preference -&gt; Nvidia X Server Settings. You can change resolution here.<\/p>\n\n\n\n<p><strong>Code Blocks<\/strong><\/p>\n\n\n\n<p><strong>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<\/strong><\/p>\n\n\n\n<p>Using Code Blocks is must for big Cross Platform software development.<\/p>\n\n\n\n<p><strong>Install C and C++ Compilers in Linux Mint \u2013<\/strong><\/p>\n\n\n\n<p>Start Terminal and type<\/p>\n\n\n\n<p>sudo aptitude install build-essential&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ all the required packages for C and C++ compilers (gcc)<\/p>\n\n\n\n<p><strong>Intall Code Blocks \u2013<\/strong><\/p>\n\n\n\n<p>sudo apt-get install codeblocks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Code Blocks<\/p>\n\n\n\n<p>or<\/p>\n\n\n\n<p>search \u201ccode blocks in linux mint\u201d in google<\/p>\n\n\n\n<p>go to \u2013 codeblocks \u2013 Linux Mint Community<\/p>\n\n\n\n<p>install from there<\/p>\n\n\n\n<p>or<\/p>\n\n\n\n<p>read instructions from codeblocks page and install if you want nightly builds<\/p>\n\n\n\n<p><strong>Install reuired development libraries \u2013<\/strong><\/p>\n\n\n\n<p>sudo apt-get install libx11-dev&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ x11 for window<\/p>\n\n\n\n<p>sudo apt-get install libgl -dev&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ OpenGL<\/p>\n\n\n\n<p>sudo apt-get install libopenal -dev&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ OpenAL<\/p>\n\n\n\n<p>Nothing will be installed or upgraded if the package is already installed.<\/p>\n\n\n\n<p>File -&gt; New project -&gt; Open GL Project<\/p>\n\n\n\n<p>folder \u2013 \/home\/scott\/gl\/gl_basic<\/p>\n\n\n\n<p>path \u2013 \/home\/scott\/gl1\/gl_basic\/gl_basic.cpp<\/p>\n\n\n\n<p>see \u2013 gl_basic.cpp for source code<\/p>\n\n\n\n<p>Set path \u2013 \/home\/scott\/gl1\/gl_basic\/gl_basic.cpp<\/p>\n\n\n\n<p>Use F9 or compile button in toolbar to run the program<\/p>\n\n\n\n<p>compiled Exe (gl_basic) is in \u2013 \/home\/scott\/gl1\/gl_basic\/bin\/Release<\/p>\n\n\n\n<p>double click it to run the program<\/p>\n\n\n\n<p>or<\/p>\n\n\n\n<p>Start Terminal<\/p>\n\n\n\n<p>\/home\/scott\/gl1\/gl_basic\/bin\/Release\/gl_basic<\/p>\n\n\n\n<p>Compile whole program with static lib to get your Exe working without problems on other machines.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Basic Program \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014- Install C and C++ Compilers in Linux Mint sudo aptitude install build-essential or sudo<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/athenswonder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=84"}],"version-history":[{"count":1,"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/athenswonder.com\/index.php?rest_route=\/wp\/v2\/posts\/84\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/athenswonder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/athenswonder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/athenswonder.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}