I am new to opengl and am trying to mix basic shapes to create a 2d scene.
I have a perimeter made up of lines and want a rectangle on the screen in a different colour(I am going to eventually construct a car out of this).
The sahapes place on the screen but are the same colour. My code is below. Any help is much appreciated.
void myInit(void)
{
glClearColor(1.0,1.0,1.0, 1.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void perimeter(void)
{
glBegin(GL_LINES);
glVertex2i(10,10);
glVertex2i(10, 470);
glVertex2i(10, 470);
glVertex2i(630, 470);
glVertex2i(630, 470);
glVertex2i(630, 10);
glVertex2i(630, 10);
glVertex2i(10,10);
}
void car(void)
{
glColor3f(1.0f, 0.0f, 0.0f);
glRecti(20, 74, 124, 88);
glEnd();
}
void test(void)
{
glClear(GL_COLOR_BUFFER_BIT);
car();
perimeter();
glEnd();
glFlush();
}
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100,150);
glutCreateWindow(“Car Park”);
glutDisplayFunc(test);
myInit();
glutMainLoop();
}