GLUT first program using linux
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.
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.
Then you can include the glut.h. It's also located in the GL subdirectory.(which is /usr/include/GL/glut.h).so,
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.
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++.
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 ,
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--
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
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>
Code:
#include <GL/glut.h>
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
to execute it , invoke ,
Code:
# ./first
[img] http://img191.imageshack.us/img191/9...eenshot3wd.png
[/img]

So try it yourself.
--Happy Coding--
Total Comments 0











