problems loading tga

I get the following linker error when trying to run my code

menu.obj : error LNK2001: unresolved external symbol “int __cdecl loadTGA(char *,int)” (?loadTGA@@YAHPADH@Z)
Debug/menu_background.exe : fatal error LNK1120: 1 unresolved externals

here is my code:-

#include “tga.h”
#include <cstdlib> // standard definitions
#include <iostream> // C++ I/O
#include <cstdio> // C I/O (for sprintf)
#include <cmath>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <gl/glut.h>
#include <gl/glaux.h>
#include <stdio.h>

#define APP_NAME “menu + background”

using namespace std; // make std accessible

int winW = 800; /* window width /
int winH = 600; /
window height */
int d=1;

//-----------------------------------------------------------------------
void myinit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 800.0, 0.0, 600.0);
glEnable(GL_FLAT);
glEnable (GL_TEXTURE_2D);

if (loadTGA (“sky.tga”, 13) != 1)
printf("TGA error
");
}
//-----------------------------------------------------------------------
void output(int x, int y, char *string) //this function is used to output the text that
{ //we want in the position we want using x , y
int len, i; //coordinates

glRasterPos2f(x, y);
len = (int) strlen(string);
for (i = 0; i < len; i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string);
}
}
//-----------------------------------------------------------------------
void menu (void)
{
d=1;
glColor3f(1.0, 1.0, 1.0);
output(350, 440, “-------”);
output(330, 400, “START GAME”); //all text to be displayed in the menu
output(335, 350, “CONTROLS”);
output(355, 300, “STORY”);
output(365, 250, “EXIT”);
output(350, 210, “-------”);
glEnd();
glFlush();
}
//-----------------------------------------------------------------------
void start(void)
{
glClear(GL_COLOR_BUFFER_BIT); //link to start of main game code
d=4;
}
//-----------------------------------------------------------------------
void controls(void)
{
d=2;
glColor3f(0.6, 0.6, 0.6);
output(115, 440, “* TO MAKE THE PLANE ACCELERATE PRESS THE UP ARROW ");
output(115, 400, "
TO MAKE THE PLANE PITCH UP PRESS THE RIGHT ARROW "); //all controls text
output(110, 350, "
TO MAKE THE PLANE DIVE DOWN PRESS THE LEFT ARROW ");
output(220, 300, "
TO FIRE PRESS THE SPACE BAR ");
glColor3f(1.0, 1.0, 1.0);
output(365, 200, “BACK”);
glEnd();
glFlush();
}
//-----------------------------------------------------------------------
void story(void)
{
d=3;
glColor3f(0.6, 0.6, 0.6);
output(115, 440, "
TO MAKE THE PLANE ACCELERATE PRESS THE UP ARROW ");
output(115, 400, "
TO MAKE THE PLANE PITCH UP PRESS THE RIGHT ARROW "); //story text
output(110, 350, "
TO MAKE THE PLANE DIVE DOWN PRESS THE LEFT ARROW ");
output(220, 300, "
TO FIRE PRESS THE SPACE BAR *”);
glColor3f(1.0, 1.0, 1.0);
output(365, 200, “BACK”);
glEnd();
glFlush();
}
//----------------------------------------------------------------------- keyboard function can be deleted
void myKeyboard(unsigned char c, int x, int y) // keyboard callback
{
switch ©
{ // c is the key that is hit
case ‘w’:
d=1;
menu();
break;
}
}
//-----------------------------------------------------------------------
void myMouse(int b, int s, int x, int y) // mouse click callback
{

if (s == GLUT_DOWN)
{
cout << “Mouse click detected at coordinates x=” //info displayed to dos box can go
<< x << " and y=" << y << endl;
}

cout << "d= "<< d << endl;

if (d==1)
{
if (x>=330 && x<=450 && y>=185 && y<=200) //start
{
glClear(GL_COLOR_BUFFER_BIT);
start();
}
if (x>=335 && x<=440 && y>=235 && y<=250) //controls
{
glClear(GL_COLOR_BUFFER_BIT);
controls();
}
if (x>=335 && x<=420 && y>=285 && y<=300) //story
{
glClear(GL_COLOR_BUFFER_BIT);
story();
}
if (x>=365 && x<=405 && y>=335 && y<=350) //exit
{
exit(1);
}
}

if (d==2)
{
if (x>=365 && x<=405 && y>=385 && y<=400) //back(controls)
{
glClear(GL_COLOR_BUFFER_BIT);
menu();
}
}

if (d==3)
{
if (x>=365 && x<=405 && y>=385 && y<=400) //back(story)
{
glClear(GL_COLOR_BUFFER_BIT);
menu();
}
}
}
//-----------------------------------------------------------------------
void background (void)
{
glBindTexture (GL_TEXTURE_2D, 13); /* bind to our texture, has id of 13 */

glBegin (GL_POLYGON);
glTexCoord2f (-400,-300); /* lower left corner of image /
glVertex3f (-400, -300, 0);
glTexCoord2f (400, -300); /
lower right corner of image /
glVertex3f (400, -300, 0);
glTexCoord2f (400, 300); /
upper right corner of image /
glVertex3f (400, 300, 0);
glTexCoord2f (-400, 300); /
upper left corner of image */
glVertex3f (-400, 300, 0);

glEnd ();
}
//-----------------------------------------------------------------------
void maindisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

background();
menu();

glutSwapBuffers();
glFlush();
}
//-----------------------------------------------------------------------
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (winW,winH);
glutCreateWindow (APP_NAME);
glutDisplayFunc(maindisplay);
myinit();
glutMouseFunc(myMouse);
glutKeyboardFunc(myKeyboard);
glutMainLoop();
}

if anyone can help would be appreciated this is just the menu system of a game and a background image.

thx

Your linker doesn’t know where to find the loadTGA function. Either you are using a library and didn’t link the library in, or you have your loadTGA function in a separate source file and didn’t include that in the project.

strange thing tho is i have got both the tga loder cpp and the .h file for them added in the project but i still get this error.

And if it is a libary that is missing i dont have a clue which one it is im already adding these as extra:-

glaux.lib opengl32.lib glu32.lib

[This message has been edited by ajp17th (edited 12-01-2003).]

Well… that function is not part of any of those libraries.

Is loadTGA in your tga loader’s .cpp file? Does it have the same prototype? Is it possible that you are trying to use it with a different calling convention? (e.g. maybe you need an extern “c” in front of its declaration in the .h file.)

What compiler are you using? The error looks kind of like one generated by VC++.

can scrap the linker errors now for some reason its likin the files now, just giving me a few convertion errors cannot see why at the moment as iv got the image stuff by itself working fine with the same coding o well will see if i can sort it

If your running VC++ you should go to project properties -> linker -> input and tell it to include the library. As for you not knowing which one is it try searching …/VC98/Lib (or …/VC7/PlatformSDK/Lib for VStudio 2003). You should find a .lib file hopefully with the name tga somewhere in the filename. Try opening the header file tga.h and see what’s in it. Maybe you have to create another project with only the tga.cpp and tga.h and create a .dll and a .lib (this means creating a project not for .exe but for .dll). There’s (almost) nothing to it. Then put your .dll somewhere you can find it(windows\system32) and the .lib in the aforementioned directories (…VC…). Hope this helps!

figured out what i did to get rid of the linker errors hehe should realy coment what im doin as i go but im in a rush this is a uni assignment for thursday =s

all i did was #include “tga.c” which aint right im sure but if i do this i get convertion errors if i dont have it in i get the linker errors…and yes all thing are declared and used correctly iv been throught that with a fine tooth comb if you want to see the code ill happly post it up if you fancy checkin for me aswell.

im running microsoft (wish i wasnt) visual c++ 6.0

[This message has been edited by ajp17th (edited 12-01-2003).]

If you don’t want to #include “tga.c” you should add it to your project instead. That’s usually a better way of using multiple source files as well.

Also, what sort of “conversion errors?” I’m guessing since you have tga.c, and you said your loader was .cpp, you probably don’t have something like this in tga.h…

#ifndef TGA_H
#define TGA_H

#ifdef __cplusplus
extern “C” {
#endif /* __cplusplus */

// function prototypes
int loadTGA(char* s, int n);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* TGA_H */

You need the extern “C” in there so that when the .cpp file is compiled it knows not to mangle the function name C++ style…

You need the #ifdef __cplusplus check in there because when the .c file is compiled, it won’t like extern “C”…

[This message has been edited by Deiussum (edited 12-01-2003).]

this is what i have in my “tga.h” file

/* Error Codes /
#define TGA_FILE_NOT_FOUND 13 /
file was not found /
#define TGA_BAD_IMAGE_TYPE 14 /
color mapped image or image is not uncompressed /
#define TGA_BAD_DIMENSION 15 /
dimension is not a power of 2 /
#define TGA_BAD_BITS 16 /
image bits is not 8, 24 or 32 /
#define TGA_BAD_DATA 17 /
image data could not be loaded */

int loadTGA (char name, int id); / id is the texture id to bind too */

wont post the “tga.c” file unless u realy wana c it all the tga.c does is load the image an convert it to a texture blah blah.

all these files that i am using are added to the same project.

[This message has been edited by ajp17th (edited 12-02-2003).]

Deiussum i have edited my .h putting in some of the things you say and now it all works only problem is that its all of a suden decided to load the image and paste it as thousands of tiny images which means you cannot see the image properly, you see more of a constant colour.

i have now found that it is this command that is making the image show up wrong glMatrixMode(GL_PROJECTION);
but i need this command so that my text is show on the screen, so im not sure what to do now

[This message has been edited by ajp17th (edited 12-02-2003).]

I’m not quite sure what you mean about needing to set the matrix mode to GL_PROJECTION in order to make your text appear on the screen. The ONLY things that should be put on the PROJECTION matrix are things like glFrustum/gluPerspective, or glOrtho/gluOrtho2D.

There are a number of things that could be causing texturing problems. There could be problems with your loading routine, you might not be using the appropriate texture coordinates, etc. Read through some tutorials on texture loading to see if they help. Also, look at the Technical FAQ on this site in the Quick Links dropdown.

got it all sorted now everything works (sort of) what i get now is the pick displayed as a background but it is split into 4 for some reason

[This message has been edited by ajp17th (edited 12-02-2003).]

Those look like 4 different cloud images, so likely not a tiling problem. Are you sure they aren’t just on the same TGA like that?

Is it a single quad being displayed in the background? Are you using the appropriate texture coordinates? In your code example you are using things like 400, -300. Your texture coordinates should be in the range 0-1, and should only exceed 1 if you are tiling the texture.

arrr that may be where im goin wrong then my texture coordinates are matchin my vertex ones thaught that if i used same coordinates it must all reach same positions.

thx for that will have a mess with it an see what happens

thx for that help m8y it works well now pic is on its side but i know what i done wrong there uv been great help ta verry much

[This message has been edited by ajp17th (edited 12-02-2003).]