PDA

View Full Version : Problem about glTools.h.....



Voltaire
03-22-2012, 07:39 AM
hi. i've started studying OpenGL Please help me.
i'm studying OpenGL Superbible 3rd edition. This source code was quoted by chapter 4.

Source Code
--------------------------
// Transform.c
// OpenGL SuperBible
// Demonstrates manual transformations
// Program by Richard S. Wright Jr.

#include "../../Common/OpenGLSB.h" // System and OpenGL Stuff
#include "../../Common/GLTools.h" // OpenGL toolkit
#include <math.h>


// Draw a torus (doughnut), using the current 1D texture for light shading
void DrawTorus(GLTMatrix mTransform)
{
GLfloat majorRadius = 0.35f;
GLfloat minorRadius = 0.15f;
GLint numMajor = 40;
GLint numMinor = 20;
GLTVector3 objectVertex; // Vertex in object/eye space
GLTVector3 transformedVertex; // New Transformed vertex
double majorStep = 2.0f*GLT_PI / numMajor;
double minorStep = 2.0f*GLT_PI / numMinor;
int i, j;

for (i=0; i<numMajor; ++i)
{
double a0 = i * majorStep;
double a1 = a0 + majorStep;
GLfloat x0 = (GLfloat) cos(a0);
GLfloat y0 = (GLfloat) sin(a0);
GLfloat x1 = (GLfloat) cos(a1);
GLfloat y1 = (GLfloat) sin(a1);

glBegin(GL_TRIANGLE_STRIP);
for (j=0; j<=numMinor; ++j)
{
double b = j * minorStep;
GLfloat c = (GLfloat) cos(b);
GLfloat r = minorRadius * c + majorRadius;
GLfloat z = minorRadius * (GLfloat) sin(b);

// First point
objectVertex[0] = x0*r;
objectVertex[1] = y0*r;
objectVertex[2] = z;
gltTransformPoint(objectVertex, mTransform, transformedVertex);
glVertex3fv(transformedVertex);

// Second point
objectVertex[0] = x1*r;
objectVertex[1] = y1*r;
objectVertex[2] = z;
gltTransformPoint(objectVertex, mTransform, transformedVertex);
glVertex3fv(transformedVertex);
}
glEnd();
}
}


// Called to draw scene
void RenderScene(void)
{
GLTMatrix transformationMatrix; // Storeage for rotation matrix
static GLfloat yRot = 0.0f; // Rotation angle for animation
yRot += 0.5f;

// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Build a rotation matrix
gltRotationMatrix(gltDegToRad(yRot), 0.0f, 1.0f, 0.0f, transformationMatrix);
transformationMatrix[12] = 0.0f;
transformationMatrix[13] = 0.0f;
transformationMatrix[14] = -2.5f;

DrawTorus(transformationMatrix);

// Do the buffer Swap
glutSwapBuffers();
}

// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Bluish background
glClearColor(0.0f, 0.0f, .50f, 1.0f );

// Draw everything as wire frame
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
{
// Redraw the scene with new coordinates
glutPostRedisplay();
glutTimerFunc(33,TimerFunction, 1);
}



void ChangeSize(int w, int h)
{
GLfloat fAspect;

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;

glViewport(0, 0, w, h);

fAspect = (GLfloat)w / (GLfloat)h;

// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set the clipping volume
gluPerspective(35.0f, fAspect, 1.0f, 50.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char* argv[])
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("Manual Transformations Demo");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);

SetupRC();
glutTimerFunc(33, TimerFunction, 1);

glutMainLoop();

return 0;
}






error message
----------------------------------
Ld "/Users/jinhoyang/Library/Developer/Xcode/DerivedData/Practice_OpenGL-cusspakgjvccnldyomumkgqhzjsq/Build/Products/Debug/Practice OpenGL" normal x86_64
cd "/Users/jinhoyang/Desktop/Practice OpenGL"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/jinhoyang/Library/Developer/Xcode/DerivedData/Practice_OpenGL-cusspakgjvccnldyomumkgqhzjsq/Build/Products/Debug "-L/Users/jinhoyang/Desktop/Practice OpenGL/.." -F/Users/jinhoyang/Library/Developer/Xcode/DerivedData/Practice_OpenGL-cusspakgjvccnldyomumkgqhzjsq/Build/Products/Debug -filelist "/Users/jinhoyang/Library/Developer/Xcode/DerivedData/Practice_OpenGL-cusspakgjvccnldyomumkgqhzjsq/Build/Intermediates/Practice OpenGL.build/Debug/Practice OpenGL.build/Objects-normal/x86_64/Practice OpenGL.LinkFileList" -mmacosx-version-min=10.6 -framework GLUT -framework OpenGL -o "/Users/jinhoyang/Library/Developer/Xcode/DerivedData/Practice_OpenGL-cusspakgjvccnldyomumkgqhzjsq/Build/Products/Debug/Practice OpenGL"

Undefined symbols for architecture x86_64:
"_gltTransformPoint", referenced from:
_DrawTorus in Transform.o
"_gltRotationMatrix", referenced from:
_RenderScene in Transform.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


I use Xcode 4. What's the problem? please help me...