{"id":153,"date":"2014-02-04T17:39:31","date_gmt":"2014-02-04T17:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=153"},"modified":"2015-07-19T09:02:05","modified_gmt":"2015-07-19T16:02:05","slug":"linux-opengl","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/opengl\/","title":{"rendered":"Building and Debugging OpenGL on Linux with Visual Studio"},"content":{"rendered":"<p>In this tutorial we create, build and debug a OpenGL application on Linux with Visual Studio.<\/p>\n<p>Before you begin, make sure that <a href=\"\/download\">VisualGDB 3.1<\/a> or later is installed.<\/p>\n<ol>\n<li>First let&#8217;s install the OpenGL libraries on the Linux machine. You can use the SSH client provided with VisualGDB for it. Start Visual Studio and go to <strong>Tools-&gt;SSH Host Manager<\/strong>.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/01-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/01-ssh.png\" alt=\"01-ssh\" width=\"670\" height=\"335\" \/><\/a><\/li>\n<li>Click on <strong>New Connection<\/strong>. Fill the host name, user name and password details to match the Linux machine details you intend to use. Check the box to setup public key authentication. Click on <strong>Create <\/strong> when done.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/02-newconnection.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/02-newconnection.png\" alt=\"02-newconnection\" width=\"542\" height=\"407\" \/><\/a><\/li>\n<li>Click on <strong>Open Console<\/strong>.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/04-openconsole.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/04-openconsole.png\" alt=\"04-openconsole\" width=\"670\" height=\"335\" \/><\/a><\/li>\n<li>Once the console is open. Use the following command.\n<pre>sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/05b-smartty.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/05b-smartty.png\" alt=\"05b-smartty\" width=\"698\" height=\"409\" \/><\/a><\/li>\n<li>Once installing completed, close the console and the SSH Host Manager. Go to <strong>File-&gt;New-&gt;Project<\/strong>. Select <strong>VisualGDB-&gt;Linux Project Wizard<\/strong>. Choose a name and location for the project. Click on <strong>OK<\/strong> when done.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/06-newproject.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/06-newproject.png\" alt=\"06-newproject\" width=\"700\" height=\"478\" \/><\/a><\/li>\n<li>Make sure that the options for a new application are checked. Click on <strong>Next<\/strong>. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/07-newapp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/07-newapp.png\" alt=\"07-newapp\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>Choose a remote computer for building, the connection made in the initial steps of this tutorial is listed there. Click on <strong>Next<\/strong>. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/08-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/08-ssh.png\" alt=\"08-ssh\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>Click on <strong>Finish<\/strong>. If prompted to cache the include folders from this machine, choose Yes. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/09-sources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/09-sources.png\" alt=\"09-sources\" width=\"696\" height=\"628\" \/><\/a><\/li>\n<li>Replace the main code file contents with the following code originating from <a href=\"http:\/\/ubuntuforums.org\/showthread.php?t=375425\">here<\/a>.\n<pre>#include &lt;iostream&gt;\r\n\r\n#include &lt;GL\/glut.h&gt;\r\n\r\n#define window_width 640\r\n#define window_height 480\r\n\r\n\/\/ Main loop\r\nvoid main_loop_function()\r\n{\r\n\/\/ Z angle\r\nstatic float angle;\r\n\/\/ Clear color (screen)\r\n\/\/ And depth (used internally to block obstructed objects)\r\nglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r\n\/\/ Load identity matrix\r\nglLoadIdentity();\r\n\/\/ Multiply in translation matrix\r\nglTranslatef(0,0, -10);\r\n\/\/ Multiply in rotation matrix\r\nglRotatef(angle, 0, 0, 1);\r\n\/\/ Render colored quad\r\nglBegin(GL_QUADS);\r\nglColor3ub(255, 000, 000); glVertex2f(-1, 1);\r\nglColor3ub(000, 255, 000); glVertex2f( 1, 1);\r\nglColor3ub(000, 000, 255); glVertex2f( 1, -1);\r\nglColor3ub(255, 255, 000); glVertex2f(-1, -1);\r\nglEnd();\r\n\/\/ Swap buffers (color buffers, makes previous render visible)\r\nglutSwapBuffers();\r\n\/\/ Increase angle to rotate\r\nangle+=0.25;\r\n}\r\n\r\n\/\/ Initialize OpenGL perspective matrix\r\nvoid GL_Setup(int width, int height)\r\n{\r\nglViewport( 0, 0, width, height );\r\nglMatrixMode( GL_PROJECTION );\r\nglEnable( GL_DEPTH_TEST );\r\ngluPerspective( 45, (float)width\/height, .1, 100 );\r\nglMatrixMode( GL_MODELVIEW );\r\n}\r\n\r\n\/\/ Initialize GLUT and start main loop\r\nint main(int argc, char** argv) \r\n{\r\nglutInit(&amp;argc, argv);\r\n\r\nglutInitWindowSize(window_width, window_height);\r\n\r\nglutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);\r\n\r\nglutCreateWindow(\"GLUT Example!!!\");\r\n\r\nglutIdleFunc(main_loop_function);\r\n\r\nGL_Setup(window_width, window_height);\r\nglutMainLoop();\r\n}<\/pre>\n<\/li>\n<li>If any IntelliSense errors appear with red underlines, then right-click on the project and select <strong>VisualGDB Project Properties<\/strong>.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/10-copysources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/10-copysources.png\" alt=\"10-copysources\" width=\"700\" height=\"459\" \/><\/a><\/li>\n<li>Go to the IntelliSense panel and make sure that <strong>\/usr\/include<\/strong> is present. <strong>Reload<\/strong> or <strong>Add Remote<\/strong> the directory. Click on <strong>OK<\/strong> to close the window. Rebuilding or editing the source file should fix any IntelliSense errors now. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/24-intellisense.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/24-intellisense.png\" alt=\"24-intellisense\" width=\"684\" height=\"616\" \/><\/a><\/li>\n<li>Open the <strong>flags.mak<\/strong> file and add the following libraries to the <strong>LIBRARY_NAMES<\/strong> variable.\n<pre>GL glut GLU<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/11-libraries.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/11-libraries.png\" alt=\"11-libraries\" width=\"700\" height=\"459\" \/><\/a><\/li>\n<li>Build the project. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/12-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/12-build.png\" alt=\"12-build\" width=\"700\" height=\"459\" \/><\/a><\/li>\n<li>Start debugging. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/17-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/17-debug.png\" alt=\"17-debug\" width=\"700\" height=\"552\" \/><\/a><\/li>\n<li>When prompted to build the project again, choose <strong>Yes <\/strong>and check the checkbox.The project will not actually get rebuilt if there are no changes, but choosing Yes allows make to make that decision. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/18-annoy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/18-annoy.png\" alt=\"18-annoy\" width=\"359\" height=\"323\" \/><\/a><\/li>\n<li>If prompted to find X Server, choose its install directory or let our autoinstaller install it. X Server is used to show Linux graphical applications in Windows. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/19-xserver.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/19-xserver.png\" alt=\"19-xserver\" width=\"537\" height=\"292\" \/><\/a><\/li>\n<li>The example will be shown on the Windows development machine as follows. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/20-glut.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/20-glut.png\" alt=\"20-glut\" width=\"656\" height=\"518\" \/><\/a><\/li>\n<li>If you want the graphical output instead to be displayed on the Linux machine, then go to <strong>VisualGDB Project Properties<\/strong> and choose the suitable option from the <strong>Program output<\/strong> category. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/23-showremotely.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/opengl\/23-showremotely.png\" alt=\"23-showremotely\" width=\"700\" height=\"494\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we create, build and debug a OpenGL application on Linux with Visual Studio. Before you begin, make<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[33,80],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/153"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/153\/revisions\/213"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}