I have created an OpenGL project to draw shapes. However, when I try to compile the program I get some errors. Here is the contents of Shapes.h:
#ifndef SHAPES_INCLUDE
#define SHAPES_INCLUDE
void Triangle(int x1, int y1, int x2, int y2, int x3, int y3 , float r, float g, float b);
#endif
Here is the contents of "Shapes.cpp":
#include "Shapes.h"
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glut.h>
void Triangle(int x1, int y1, int x2, int y2, int x3, int y3 , float r, float g, float b)
{
glColor3f(r,g,b);
glBegin(GL_TRIANGLES);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glVertex2i(x3,y3);
glEnd();
}
And for reference, here is the contents of my "main.cpp":
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glut.h>
// our libraries:
#include "libraries/Shapes.h"
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
void lineSegment()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2i(20,120);
glVertex2i(40,20);
glVertex2i(80,20);
glEnd();
glFlush();
}
void glLoop()
{
Triangle(20,120,40,20,80,20,0.0,0.0,1.0);
glFlush();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,100);
glutInitWindowSize(400,300);
glutCreateWindow("OpenGL window");
init();
glutDisplayFunc(glLoop);
glutMainLoop();
return 0;
}
And when I compile it with g++ main.cpp -lGL -lGLU -lglut
, I get this error:
/tmp/ccSGyfe8.o: In function `glLoop()':
main.cpp:(.text+0xf3): undefined reference to `Triangle(int, int, int, int, int, int, float, float, float)'
collect2: error: ld returned 1 exit status
Can anyone help me to fix it?