PDA

View Full Version : GL/glut.h: No such file or directory



mccarun
03-21-2009, 09:28 PM
Hi all,

I'm a beginner to openGL. I'm using latest version of ubuntu to run my openGL code and I have nvidia Gefore 8600M GT card and I have the drivers installed. Here is the code that I'm using.

#include <stdlib.h>

/* opengl and glut includes */

#if defined(_CYGWIN_) /* CYGWIN */



#include <gl/gl.h>

#include <gl/glu.h>

#include <gl/glut.h>



#elif defined(_LINUX_) /* LINUX */



#include <GL/gl.h>

#include <GL/glu.h>

#include <GL/glut.h>



#endif





/* prototypes */

void init(void);

void display(void);



/*---------------*/

/* main function */

/*---------------*/

int main(int argc,char **argv)

{

/* GLUT management */

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(600,600);

glutInitWindowPosition(100,100);

glutCreateWindow("Hello CSI703");



/* call the initialization function */

init();



/* drawing function */

glutDisplayFunc(display);



/* get in the infinite loop */

glutMainLoop();



return 0;

}



/*-------------------------*/

/* initialization function */

/*-------------------------*/

void init(void)

{

/* set backgroung color RGB plus alpha */

glClearColor(0.1,0.1,0.1,0.0);



/* selects the projection matrix to work */

glMatrixMode(GL_PROJECTION);

/* loads the identity */

glLoadIdentity();

/* specifies the projection type => ortho */

/* left right bottom top near far */

glOrtho( 0.0, 3.0, 0.0, 3.0, -1.0, 1.0);



return;

}



/*------*/

/* draw */

/*------*/

void display(void)

{

/* clean all pixels */

glClear(GL_COLOR_BUFFER_BIT);



/* set color for polygon */

glColor3f(0.5,0.5,0.0);



/* draw polygon */

glBegin(GL_POLYGON);

glVertex3f(0.25,0.25,0.0);

glVertex3f(0.75,0.25,0.0);

glVertex3f(0.75,0.75,0.0);

glVertex3f(0.25,0.75,0.0);

glEnd();



/* set color for triangle */

glColor3f(0.1,0.5,0.0);



/* draw a triangle */

glBegin(GL_TRIANGLES);

glVertex3f(1.00,1.00,0.0);

glVertex3f(2.00,1.00,0.0);

glVertex3f(1.00,0.25,0.0);

glEnd();



glFlush();



return;

}


I'm getting the following error...

gcc -c -Wall -pedantic -O3 -D_LINUX_ open_window.c
open_window.c:26:21: error: GL/glut.h: No such file or directory
open_window.c: In function ‘main’:
open_window.c:41: warning: implicit declaration of function ‘glutInit’
open_window.c:42: warning: implicit declaration of function ‘glutInitDisplayMode’
open_window.c:42: error: ‘GLUT_SINGLE’ undeclared (first use in this function)
open_window.c:42: error: (Each undeclared identifier is reported only once
open_window.c:42: error: for each function it appears in.)
open_window.c:42: error: ‘GLUT_RGB’ undeclared (first use in this function)
open_window.c:43: warning: implicit declaration of function ‘glutInitWindowSize’
open_window.c:44: warning: implicit declaration of function ‘glutInitWindowPosition’
open_window.c:45: warning: implicit declaration of function ‘glutCreateWindow’
open_window.c:51: warning: implicit declaration of function ‘glutDisplayFunc’
open_window.c:54: warning: implicit declaration of function ‘glutMainLoop’
make: *** [open_window.o] Error 1

This code runs perfectly on other linux machine but not on my laptop. I have been trying to fix this for the past one week, but I couldn't able to find a solution.I have mesa-common-dev, freeglu installed.

This is the make file that I'm using..

SRC1=open_window.c

OBJ1=open_window.o

EXE1=open_window
# ----------------------------------

CC=gcc

DEBUG= -g

OPT= -O3

CFLAGS= -c -Wall -pedantic $(OPT) -D_LINUX_

LFLAGS= $(OPT) -lglut -lGLU -lGL

LFLAGS_NO_OPENGL= $(OPT)

all: $(EXE1)
$(EXE1): $(OBJ1)

$(CC) $(OBJ1) $(LFLAGS) -o $(EXE1)



$(OBJ1): $(SRC1)

$(CC) $(CFLAGS) $(SRC1)
clean:

rm -f *.o *.exe $(EXE1)


It will be nice if you guys can help me out to fix this issue.

Looking forward for reply from you guys.

Thanks in advance.

Arun

enunes
03-21-2009, 09:47 PM
Hi,

i guess it's something with your Makefile.

gcc -c -Wall -pedantic -O3 -D_LINUX_ open_window.c
is not including -lglut -lGLU -lGL.

Try compiling it manually:
gcc -c -Wall -pedantic -O3 -D_LINUX_ open_window.c -lglut -lGLU -lGL
and if it works, fix your Makefile.

mccarun
03-21-2009, 09:59 PM
Thank you for ur response..
I tried the command now..I'm getting the same error...

arun@arun-laptop:~/examples_week03_OpenGL$ gcc -c -Wall -pedantic -O3 -D_LINUX_ open_window.c -lglut -lGLU -lGL
open_window.c:26:21: error: GL/glut.h: No such file or directory
open_window.c: In function ‘main’:
open_window.c:41: warning: implicit declaration of function ‘glutInit’
open_window.c:42: warning: implicit declaration of function ‘glutInitDisplayMode’
open_window.c:42: error: ‘GLUT_SINGLE’ undeclared (first use in this function)
open_window.c:42: error: (Each undeclared identifier is reported only once
open_window.c:42: error: for each function it appears in.)
open_window.c:42: error: ‘GLUT_RGB’ undeclared (first use in this function)
open_window.c:43: warning: implicit declaration of function ‘glutInitWindowSize’
open_window.c:44: warning: implicit declaration of function ‘glutInitWindowPosition’
open_window.c:45: warning: implicit declaration of function ‘glutCreateWindow’
open_window.c:51: warning: implicit declaration of function ‘glutDisplayFunc’
open_window.c:54: warning: implicit declaration of function ‘glutMainLoop’

I used the same make only in other system and it worked...

ZbuffeR
03-22-2009, 02:35 AM
You meant 'freeglut installed' right ?
Anyway a quick 'locate glut.h' may help.

enunes
03-22-2009, 03:21 AM
Hi,

i tested your code and your Makefile and it compiles and runs just right. You probably haven't installed the proper libraries.

Still, you should revise your Makefile. Your 'clean' doesnt get called.

If by chance you are running Ubuntu, you can get it with
apt-get install glutg3-dev.

mccarun
03-22-2009, 07:24 AM
@enunes

I installed the glutg3-dev using synaptic package manager in ubuntu to install the package and its working now. Thank you very much

@Zbuffer
I tried to locate glut.h..but I'm not getting any results when I do that(before and after installing glutg3-dev)..y is that so? will that be a problem in future...

ZbuffeR
03-22-2009, 08:38 AM
locate is fast because it reads an index (and not the actual files).
This index is typically updated only once a day. If you retry the day after install glutg3-dev, you will find it.
You can also force an update of the index by running 'sudo updatedb'.

mccarun
03-22-2009, 11:07 AM
Thank you very much..
yes..I did updatedb and tried the locate command...and I got this..

arun@arun-laptop:~$ locate glut.h
/usr/include/GL/freeglut.h
/usr/include/GL/glut.h
/usr/share/doc/freeglut3-dev/freeglut.html

just out of curiosity..to know...

Can you briefly tell me what I updated and what that index is and how i got it now?

enunes
03-22-2009, 03:14 PM
Think of a big file containing the names of every single file in your system.

Performing a search in this file for a given file name is just way faster than looking for the actual files over your hard drive.

You updated that file.

mccarun
03-23-2009, 11:30 PM
I have one more problem with the below code..I'm trying to visualize the points from a file with small triangles that connect different points(similar to Triangular mesh) and color it with the values in the file.

I'm performing translation,rotation and zooming with the mouse buttons. Rotation and zooming working properly. But I'm facing problem with the translation. It just displays only half of the sphere in the window and other half goes beyond the window and when I move the mouse it only appears on the border of the window(thats the reason it displays only portion of the sphere).

can you guys tell me how to fix or any other way to perform translation the moves the object as the moves moves..

#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>

/*File name...*/
#define FILE_NAME "sphere_surf.zfem"

/*The three different operations the mouse can control for the canvas */
#define MOUSE_ROTATE_YX 0
#define MOUSE_TRANSLATE 1
#define MOUSE_ZOOM 2

/* The current mode the mouse is in */
int mouse_mode;

/* The last position of the mouse since the last callback */
extern int m_last_x, m_last_y;

/* Function declarations */
void myMouseButton(int button, int state, int x, int y);
void myMouseMotion(int x, int y);

/*Structure Declaration*/
struct points
{
double x;
double y;
double z;
}pts[2080];

struct shape
{
int x;
int y;
int z;
}shps[4160];

/* Function Declarations */
void myInit (int argc, char **argv);

void myDisplay (void);
void myReshape (int, int);
void myKeyHandler (unsigned char, int, int);

void resetCamera(void);
int endCanvas(int status);
/*void performanceTest(void);*/
void initLighting(void);
void drawSphere(void);
void drawtriangle(void);

/* The current vermal object */
/*int vr_object,nt;*/
int nt;

#define FALSE 0
#define TRUE 1

/************************************************** ***********
* Global Variables / Constants
/* The canvas's width and height, in pixels */
int win_width = 500;
int win_height = 500;


/* The dimensions of the viewing frustum */
GLfloat fleft = -1.0;
GLfloat fright = 1.0;
GLfloat fbottom = -1.0;
GLfloat ftop = 1.0;
GLfloat zNear = -1.0;
GLfloat zFar = -3.0;


/* Global zoom factor. Modified by mouse movement Initially 1.0 */
GLfloat zoomFactor = 1.0;

/* The current mode the mouse is in, based on button pressed */
int mouse_mode;

/* The last position of the mouse since the last callback */
int m_last_x, m_last_y;

/* Constants for specifying the 3 coordinate axes */
#define X_AXIS 0
#define Y_AXIS 1
#define Z_AXIS 2

/* Begin function definitions */

void myInit (int argc, char **argv) {
/*Reading the file and Storing it in Structure*/
char str[15] ;
FILE *f;
int i=0,n=0,pindx = 0,tindx = 0,num_points;
float values[100000];

f = fopen(FILE_NAME,"r");
while(!feof(f))
{
fscanf(f,"%s",str);
values[n++] = atof(str);
}
num_points = values[9];
for(i=10,pindx=0; pindx<num_points;pindx++)
{
pts[pindx].x = values[i++];
pts[pindx].y = values[i++];
pts[pindx].z = values[i++];
}

i = i+3;
nt = values[i++];

for(tindx=0; tindx<nt;tindx++)
{
shps[tindx].x = values[i++];
shps[tindx].y = values[i++];
shps[tindx].z = values[i++];
}
/* Set up a black background */
glClearColor(0.0, 0.0, 0.0, 0.0);
resetCamera();
}


/*
* The main drawing routine. Based on the current display mode, other
* helper functions may be called.
*/
void myDisplay (void) {

glEnable(GL_DEPTH_TEST); /* Use the Z - buffer for visibility */
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawSphere();
drawtriangle();
glFlush();
glutSwapBuffers();
}

void drawSphere(void)
{

int i=0;
glPushMatrix();
glColor3f(0.1,0.7,0.5); /* sets the color */

glBegin(GL_POINTS);
for(i=0;i<800;i++)
{
glVertex3f(pts[i].x,pts[i].y,pts[i].z);
}
glEnd();
glFlush();
return;
}

void drawtriangle(void)
{
int i=0,v1,v2,v3;
glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
for(i=0;i<nt;i++)
{
v1 = shps[i].x;
v2 = shps[i].y;
v3 = shps[i].z;
glColor3f(1.0,0,0);
glVertex3f(pts[v1].x,pts[v1].y,pts[v1].z);
glColor3f(0,1.0,0);
glVertex3f(pts[v2].x,pts[v2].y,pts[v2].z);
glColor3f(0,0,1.0);
glVertex3f(pts[v3].x,pts[v3].y,pts[v3].z);
}
glEnd();
}


/*
* Changes the size of the canvas's window, and will implicitly
* the function bound by glutReshapeFunc(), which should be
* Reshape().
*/
void myResize (int x, int y) {
glViewport(0,0,x,y);
glutReshapeWindow(x, y);
}


/* Stretch the image to fit the reshaped window */
void myReshape (int x, int y) {
glViewport(0,0,x,y);
}


/*
* The rotation is specified in degrees about a certain axis of
* the original model.
*
* AXIS should be either X_AXIS, Y_AXIS, or Z_AXIS.
*/
void rotateCamera(double deg, int axis) {
double x, y, z;

x = 0;
y = 0;
z = 0;

if (axis == X_AXIS) {
x = 1.0f;
} else if (axis == Y_AXIS) {
y = 1.0f;
} else if (axis == Z_AXIS) {
z = 1.0f;
}

glRotatef(deg, x, y, z);
}


/*
* Changes the level of zooming by adjusting the dimenstions of the viewing
* frustum.
*/

void zoomCamera(double delta) {
zoomFactor += delta;

if (zoomFactor <= 0.0) {
/* The zoom factor should be positive */
zoomFactor = 0.001;
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

/*
* use of glFrustum finction
*/
glFrustum(fleft*zoomFactor, fright*zoomFactor,
fbottom*zoomFactor, ftop*zoomFactor,
-zNear, -zFar);

}

/*
* Resets the viewing frustum and moves the drawing point to the center of
* the frustum.
*/
void resetCamera() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glFrustum(fleft, fright, fbottom, ftop, -zNear, -zFar);

/* Set the drawing point at the center of the frustum */
glMatrixMode(GL_MODELVIEW );
glLoadIdentity( );
glTranslatef(
(fleft + fright) / 2,
(fbottom + ftop) / 2,
(zNear + zFar) / 2);

zoomFactor = 1.0;
}



void myMouseButton(int button, int state, int x, int y) {
if (state == GLUT_DOWN) {
m_last_x = x;
m_last_y = y;

if (button == GLUT_LEFT_BUTTON) {
mouse_mode = MOUSE_ROTATE_YX;
}
else if (button == GLUT_MIDDLE_BUTTON) {
mouse_mode = MOUSE_ZOOM;
}
else if (button == GLUT_RIGHT_BUTTON) {
mouse_mode = MOUSE_TRANSLATE;
}
}
}


void myMouseMotion(int x, int y) {
double d_x, d_y; /* The change in x and y since the last callback */

d_x = x - m_last_x;
d_y = y - m_last_y;

m_last_x = x;
m_last_y = y;

if (mouse_mode == MOUSE_ROTATE_YX) {
/* scaling factors */
d_x /= 2.0;
d_y /= 2.0;

glRotatef(d_x, 0.0, 1.0, 0.0); /* y-axis rotation */
glRotatef(-d_y, 1.0, 0.0, 0.0); /* x-axis rotation */

} else if (mouse_mode == MOUSE_ZOOM) {
d_y /= 100.0;

zoomFactor += d_y;

if (zoomFactor <= 0.0) {
/* The zoom factor should be positive */
zoomFactor = 0.001;
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glFrustum(fleft*zoomFactor, fright*zoomFactor,
fbottom*zoomFactor, ftop*zoomFactor,
-zNear, -zFar);
}else if (mouse_mode == MOUSE_TRANSLATE) {

glMatrixMode(GL_PROJECTION);
glLoadIdentity();


/* Set the drawing point at the center of the frustum */
glMatrixMode(GL_MODELVIEW );
glLoadIdentity( );
glTranslatef(d_x,d_y,d_x/d_y);

zoomFactor = 1.0;

}

/* Redraw the screen */
glutPostRedisplay();
}


int main(int argc, char **argv)
{
glutInit(&argc, argv);

/* Set initial window size and screen offset */
glutInitWindowSize(win_width, win_height);
glutInitWindowPosition(50, 50);

/* Using: RGB, double buffering, z-buffer */
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("Circle");

/* Set the function callbacks */
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);

glutMouseFunc(myMouseButton);
glutMotionFunc(myMouseMotion);

/* User specific initialization */
myInit(argc, argv);

glutMainLoop();
return 0;
}