glutCall

Hello,

I am trying to modify a given gui and add a
window to it.

But then I get “undefined reference to glutInit”

Why? I have all the necessary libraries!

Thanks//longhey

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

#define PRINTV3(v) do { printf("(%3.2f, %3.2f, %3.2f)", v[0], v[1], v[2]); }\
                   while(0)

void display() ;
int getIndex(int j) ;
void idle() ;
void matriceEC1(float *c, double *from) ;
void matriceEC2(float *c, double *from, double *at) ;
void multMatrices(float *c, float *o, float *m) ;


void camera(double from[3], double at[3], double up[3], double viewAngle)
{
    printf("Camera parameters:
");
    printf("	From: ");
    PRINTV3(from);
    printf("
	At: ");
    PRINTV3(at);
    printf("
	Up: ");
    PRINTV3(up);
    printf("
	Viewing angle: %3.2f
", viewAngle);

	
	float coords[3] ;
	coords[0] = 2 ; 
	coords[1] = 4 ;
	coords[2] = 4 ;
	int i ;
	float myNew[3] ;
	float other[9] ;

	matriceEC1(other, from) ;
	multMatrices(coords, other, myNew) ;
	for(i = 0 ; i < 3 ; i++)
	{
		printf("camera i = %d", i) ;
		printf("*%f*
", myNew[i]) ;
	}

}

void light(double ambientIntensity[3], double pointPosition[3],
           double pointIntensity[3])
{
    printf("Lighting parameters:
");
    printf("	Ambient light intensity: ");
    PRINTV3(ambientIntensity);
    printf("
	Point light position: ");
    PRINTV3(pointPosition);
    printf("
	Point light intensity: ");
    PRINTV3(pointIntensity);
    printf("
");
}


void material(double ambientCoefficient[3], double diffuseCoefficient[3],
              double specularCoefficient[3], double phongConstant)
{
    printf("Material parameters:
");
    printf("	Ambient coefficient: ");
    PRINTV3(ambientCoefficient);
    printf("
	Diffuse coefficient: ");
    PRINTV3(diffuseCoefficient);
    printf("
	Specular coefficient: ");
    PRINTV3(specularCoefficient);
    printf("
	Phong constant: %f
", phongConstant);
}
/**********GUI callbacks*************/

//called by setWindows
void display() 
{

}

//function returns the index for myNew 
int getIndex(int j) 
{
	if (j < 3)
	{
		return 0 ;
	}
	else if ((2 < j)&&(j < 6))
	{
			
		return 1 ;
		
	}
	else  
	{
		return 2 ;
	}
}


void idle() 
{

}

//Om man vet storlekarna innan borde detta inte vara något problem
// coords = new btw
void multMatrices(float *c, float *o, float *m) 
{	
	
	int i, j = 0; 
	while(j < 9)
	{ 
		for(i = 0 ; i < 3 ; i++)
		{
			if(i == 0) //ie no element has been stored yet so += op cannot be applied
			{	
				m[getIndex(j)] = c[i]*o[j] ;
				
			}
			else 
			{
				m[getIndex(j)] += c[i]*o[j] ;
				if ((i == 2)&&(j == 8))
					printf("%f plats 1 i myNew ", m[2]) ;
				if (j == 7)
				printf("if %d", getIndex(j)) ;
			}
			j++ ; 
		}
	}

	for(j = 0 ; j < 3 ; j++)
		printf("%f hej", m[j]) ;
	printf("slut") ;

}//multMatrices

/*
void reshape(int width, int height)
{
   // glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, width, height, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
*/

void toggles(int flipNormals, int lightedMode, int showNormals,
             int colorbackFaces)
{
    printf("%s flip normals
", flipNormals ? "Do" : "Don't");
    printf("Render model as %s
",
           lightedMode ? "solid lighted" : "wireframe");
    printf("%s show normals
", showNormals ? "Do" : "Don't");
    printf("%s backfaces
", colorbackFaces ? "Color" : "Cull");
}

void readOff(char *offFileName)
{
    printf("Open the OFF file '%s'
", offFileName);
}

void placeViewport()
{
    printf("Place viewport now
");
}

//transforms world coords to eye coords
void matriceEC1(float *c, double *from) 
{
	
	float coords[3] ;
	float myNew[3] ;
	float other[9] ;
	//initiating other 4x4 = 16 fack
	other[0] = 1.0;//1a raden
	other[1] = 0.0 ;
	other[2] = 0.0 ;
	other[3] = -from[0] ;
	other[4] = 0.0; //2e raden
	other[5] = 1.0 ;
	other[6] = 0.0 ;
	other[7] = -from[1] ;
	other[8] = 0.0; //3e raden
	other[9] = 0.0 ;
	other[10] = 1.0 ;
	other[11] = -from[2] ;
	other[12] = 0.0 ;//4e raden
	other[13] = 0.0 ;
	other[14] = 0.0 ;
	other[15] = 1.0 ;
}

//transforms world coords to eye coords
void matriceEC2(float *c, double *from, double *at) 
{
	
	float coords[3] ;
	float myNew[3] ;
	float other[9] ;
	//initiating other 3x3 = 16 fack
	other[0] =  (at[1]*from[2] - at[2]*from[1])/abs((at[1]*from[2] - at[2]*from[1])) ;//1a raden
/*
	other[1] = (at[2]*from[0] - at[0]*from[2])/abs((at[2]*from[0] - at[0]*from[2])) ;
	other[2] = (at[0]*from[1] - at[1]*from[0])/abs((at[0]*from[1] - at[1]*from[0]))
	other[3] = 0.0 ;

//2a raden initieras sist för att den beror av 3e raden

	other[8] = (from[0] - at[0])/abs(from[0] - at[0]) ; //3e raden
	other[9] = (from[1] - at[1])/abs(from[1] - at[1]) ;
	other[10] = (from[2] - at[2])/abs(from[2] - at[2]) ;
	other[11] = 0.0 ;
	other[12] = 0.0 ;//4e raden
	other[13] = 0.0 ;
	other[14] = 0.0 ;
	other[15] = 1.0 ;


//se kommentar ovan
	other[4] = (other[9]*other[2] - other[9]*other[1]) ; //2e raden
	other[5] = (other[10]*other[0] - other[8]*other[2]) ;
	other[6] = (other[8]*other[1] - other[9]*other[0]) ;
	other[7] = 0.0 ;
*/
}

/*
void setupWindows(int width, int height)
{

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 
    glutInitWindowSize(width, height);
    glutInitWindowPosition(10, 10);
    glutCreateWindow("Project 2 graphics");

    reshape(width, height);

    glClearColor(1.0, 1.0, 1.0, 1.0); 

    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutReshapeFunc(reshape);
}

*/

int main(int argc, char **argv)
{
    double from[] = {3.0, -0.5, 2.1};
    double at[] = {0, 0, 0};
    double up[] = {0, 0, 1};
    double viewingAngle = 45;
    double ambientIntensity[] = {0.5, 0.2, 0};
    double pointIntensity[] = {1, 1, 1};
    double ambientCoefficient[] = {0.5, 0.5, 0};
    double diffuseCoefficient[] = {0.5, 0.2, 0};
    double specularCoefficient[] = {0.8, 0.8, 0.8};
    double pointPosition[] = {2, 0, 1};
    unsigned int phongConstant = 2;

    proj2gui(camera, light, material, toggles, readOff, placeViewport);
    setCamera(from, at, up, viewingAngle);
    setLight(ambientIntensity, pointPosition, pointIntensity);
    setMaterial(ambientCoefficient, diffuseCoefficient, specularCoefficient,
                phongConstant);
    setToggles(0, 0, 0, 0);
    
  //  glutInit(&argc, argv);
   // setupWindows(640, 480);
    while(tickGUI());
    
    return 0;
}

Your glut initialization code is atypical and not clearly defined.

A typical glut configuration might go something like this:

int main( int argc, char** argv )
{
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA );
	glutInitWindowPosition( 0, 0 );
	glutInitWindowSize( 800, 600 );
	glutCreateWindow( argv[0] );

        initMyOpenGLState();

	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(special);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	glutDisplayFunc(display);

	glutMainLoop();
	return 0;
}

Try searching for glut demos to get more ideas.

I didn’t really look at the rest of your code, as it seems to be more or less series of comments and bodiless functions with questionable relevancy.

The error you get means you didn’t link against the glut library.

For example using gcc you have to add “-lglut” to the compile commandline.

Ah, yes. Link errors. They can be frightfully trying indeed!