Lucid83
October 10th, 2004, 05:56 PM
I am getting 2 error messages when I try to execute my code which I have provided below. Any insights would be appreciated.
Thanks
These are the error messages:
Project1.obj : error LNK2001: unresolved external symbol _display
Debug/Project1.exe : fatal error LNK1120: 1 unresolved externals
This is my code:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct vertex
{
float x,y,z;
float r,g,b;
struct vertex* next;
};
typedef struct vertex item;
void display(void);
void reshape(int, int);
void parseInput(char*, struct vertex* head);
int main(int argc, char** argv)
{
struct vertex* headptr;
headptr = (item*)malloc(sizeof(item));
glutInitWindowSize(400, 400);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("Project1");
if (argc == 2)
{
parseInput(argv[1], headptr);
}
else
{
printf("Usage: Project2 filename.txt\n\twhere filename.txt is the file to parse\n");
return 1;
}
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}
/** parseInput
@param filename - the name of the file to read from
@param vlist - an array of vertex type to store each vertex in
@param tlist - an array of triangle type to store each triangle in
@param num_vertices - use to return how many vertices were read
@param num_triangles - use to return how many triangles were read
@return void, but you must put the number of vertices and triangles read
in num_vertices and num_triangles;
**/
void parseInput(char* filename, struct vertex* head)
{
FILE* fp = fopen(filename, "rs");
char szLine[256];
struct vertex* current;
current = head;
/* initialize the number of vertices and triangles read to 0 */
while (!feof(fp))
{
/* read the next line */
fgets(szLine, 256, fp);
/* check for each of the 4 possible line beginnings */
/* check for comment */
if (szLine[0] == '#')
{
/* skip this line */
continue;
}
/* check for background */
else if (strncmp(szLine, "BACKGROUND", 10) == 0)
{
float red, green, blue;
sscanf(szLine, "BACKGROUND %f %f %f", &red, &green, &blue);
glClearColor(red, green, blue, 0);
}
/* check for vertex */
else if (strncmp(szLine, "VERTEX", 6) == 0)
{
float x, y, z;
sscanf(szLine, "VERTEX %f %f %f", &x, &y, &z);
current -> x = x;
current -> y = y;
current -> z = z;
/* debugging purpose */
printf ("%f %f %f\n", current -> x, current -> y, current -> z);
current -> next = (item*)malloc(sizeof(item));
current = current -> next;
current -> next = NULL;
}
}
fclose(fp);
}
/** glut display callback function. Every time the window needs to be drawn,
glut will call this function. This includes when the window size
changes, or when another window covering part of this window is
moved so this window is uncovered.
**/
//display is commented out on purpose---------------------------------
/*void display()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
//loop through and draw all of the scene triangles
for (i = 0; i < m_nTriangles; i++)
{
struct triangle t = scene_triangles[i];
struct vertex v = scene_vertices[t.v1];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
v = scene_vertices[t.v2];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
v = scene_vertices[t.v3];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
}
glEnd();
glutSwapBuffers();
}
*/
/** glut reshape callback function. GLUT calls this function whenever
the window is resized, including the first time it is created.
You can use variables to keep track the current window size.
**/
void reshape(int width, int height)
{
/* tell OpenGL we want to display in a recangle that is the
same size as the window
*/
glViewport(0,0,width,height);
/* switch to the projection matrix */
glMatrixMode(GL_PROJECTION);
/* clear the projection matrix */
glLoadIdentity();
/* set the camera view, orthographic projection in 2D */
gluOrtho2D(0,width,0,height);
/* switch back to the model view matrix */
glMatrixMode(GL_MODELVIEW);
}
Thanks
These are the error messages:
Project1.obj : error LNK2001: unresolved external symbol _display
Debug/Project1.exe : fatal error LNK1120: 1 unresolved externals
This is my code:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct vertex
{
float x,y,z;
float r,g,b;
struct vertex* next;
};
typedef struct vertex item;
void display(void);
void reshape(int, int);
void parseInput(char*, struct vertex* head);
int main(int argc, char** argv)
{
struct vertex* headptr;
headptr = (item*)malloc(sizeof(item));
glutInitWindowSize(400, 400);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("Project1");
if (argc == 2)
{
parseInput(argv[1], headptr);
}
else
{
printf("Usage: Project2 filename.txt\n\twhere filename.txt is the file to parse\n");
return 1;
}
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}
/** parseInput
@param filename - the name of the file to read from
@param vlist - an array of vertex type to store each vertex in
@param tlist - an array of triangle type to store each triangle in
@param num_vertices - use to return how many vertices were read
@param num_triangles - use to return how many triangles were read
@return void, but you must put the number of vertices and triangles read
in num_vertices and num_triangles;
**/
void parseInput(char* filename, struct vertex* head)
{
FILE* fp = fopen(filename, "rs");
char szLine[256];
struct vertex* current;
current = head;
/* initialize the number of vertices and triangles read to 0 */
while (!feof(fp))
{
/* read the next line */
fgets(szLine, 256, fp);
/* check for each of the 4 possible line beginnings */
/* check for comment */
if (szLine[0] == '#')
{
/* skip this line */
continue;
}
/* check for background */
else if (strncmp(szLine, "BACKGROUND", 10) == 0)
{
float red, green, blue;
sscanf(szLine, "BACKGROUND %f %f %f", &red, &green, &blue);
glClearColor(red, green, blue, 0);
}
/* check for vertex */
else if (strncmp(szLine, "VERTEX", 6) == 0)
{
float x, y, z;
sscanf(szLine, "VERTEX %f %f %f", &x, &y, &z);
current -> x = x;
current -> y = y;
current -> z = z;
/* debugging purpose */
printf ("%f %f %f\n", current -> x, current -> y, current -> z);
current -> next = (item*)malloc(sizeof(item));
current = current -> next;
current -> next = NULL;
}
}
fclose(fp);
}
/** glut display callback function. Every time the window needs to be drawn,
glut will call this function. This includes when the window size
changes, or when another window covering part of this window is
moved so this window is uncovered.
**/
//display is commented out on purpose---------------------------------
/*void display()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
//loop through and draw all of the scene triangles
for (i = 0; i < m_nTriangles; i++)
{
struct triangle t = scene_triangles[i];
struct vertex v = scene_vertices[t.v1];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
v = scene_vertices[t.v2];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
v = scene_vertices[t.v3];
glColor3f(v.r, v.g, v.b);
glVertex3f(v.x, v.y, v.z);
}
glEnd();
glutSwapBuffers();
}
*/
/** glut reshape callback function. GLUT calls this function whenever
the window is resized, including the first time it is created.
You can use variables to keep track the current window size.
**/
void reshape(int width, int height)
{
/* tell OpenGL we want to display in a recangle that is the
same size as the window
*/
glViewport(0,0,width,height);
/* switch to the projection matrix */
glMatrixMode(GL_PROJECTION);
/* clear the projection matrix */
glLoadIdentity();
/* set the camera view, orthographic projection in 2D */
gluOrtho2D(0,width,0,height);
/* switch back to the model view matrix */
glMatrixMode(GL_MODELVIEW);
}