ElaKiri Community
Downloads
Go Back   ElaKiri Community > Blogs > sanzilla jackcat
Reload this Page GLUT first program using linux
Rate this Entry

GLUT first program using linux

Submit "GLUT first program using linux" to Digg Submit "GLUT first program using linux" to del.icio.us Submit "GLUT first program using linux" to StumbleUpon Submit "GLUT first program using linux" to Google Submit "GLUT first program using linux" to Facebook Submit "GLUT first program using linux" to Twitter
Posted 12-24-2010 at 07:37 AM by sanzilla jackcat

hi all,
today I'm going to teach you how to write your first glut program under debian linux.before you proceed you need the glut libraries and the helder files installed in your computer.Those helder files and the libraries are comes with most debain based/debain installation. To check whether do you have it or not just navigate to the directory /usr/include/GL/ and check for the glut.h helder file. If that helder is there then you are luckey and you don't have to install it.

if not then open the terminal window and change to the superuser mode (using su command) and type the bellow command to install glut package to your debain installation.

Quote:
# apt-get install freeglut3-dev
The it will install the helder files in the /usr/include/GL and library files in the /usr/lib/ directory.

You need to include the glut helder file in your C/C++ program inorder to use it's library calls.and before you including the glut.h you have to include the GL helder which is /usr/include/GL/gl.h , it's located at the subdirecotry GL relative to the GNU include path.So you have to include it like this.
Code:
#include <GL/gl.h>
Then you can include the glut.h. It's also located in the GL subdirectory.(which is /usr/include/GL/glut.h).so,
Code:
#include <GL/glut.h>
Then you can write your main method.In main method you can see we have lots of methods that starting with the 'glut' those are simply the library calls that are located in glut.h helder file or glut library.

oky let's write our first program.

Code:
// first.cpp
//   your first glut program
//
//  Author: Sanzilla Jackcat
//   Copyright: Feel free to copy as long as you code.
 
#include <GL/gl.h>
#include <GL/glut.h>
 
void renderScene();
 
int main(int argc,char **argv)
{
  glutInit(&argc,argv);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(500,500);
  glutInitDisplayMode(GLUT_DEPTH|GLUT_SINGLE|GLUT_RGBA);
  glutCreateWindow("My First Glut Program");
  glutDisplayFunc(renderScene);
  glutMainLoop();
  return 0;
}
 
void renderScene(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  glLineWidth(3);
  glEnable(GL_LINE_SMOOTH);
  glBegin(GL_LINE_LOOP);
   glVertex3f(-0.75,0.0,0.75);
   glVertex3f(0.75,-0.75,0);
   glVertex3f(0.0,0.9,0);
  glEnd();
  glFlush();
}

and you can see that there are also some methods that are starting with the prefix 'gl' such as glVertex3f(..) and glClear(..),those are the methods that are defined in the gl.h helder file or the GL library.

I'll explain you the code later now,for now write the code and compile it.

To compile your code under debian ,open the terminal and navigate to your working directory in my case /usr/src/exercises/glut/first.cpp , and invoke the following commands. (btw you need the g++/gcc to compile.).If you are using C++ you need g++.
Code:
# g++ -o first first.cpp -lglut
and if that command returned without an error then you can see your executable file called first in your working directory.

to execute it , invoke ,
Code:
# ./first
and then you can see a glut window will open in your screen and draws a traingle.Like this.

[img] http://img191.imageshack.us/img191/9...eenshot3wd.png
[/img]



So try it yourself.

--Happy Coding--
Posted in Uncategorized
Views 279 Comments 0 Edit Tags
« Prev     Main     Next »
Total Comments 0

Comments

 


Copyright © 2006 - 2011 ElaKiri™ Beta2.Evo vBulletin, vBa iBproArcade Subdreamer I-Magic MKv
Optimisation plugin by DBtech

Page generated in 0.12755 seconds with 16 queries