I'm trying to make my rectangles appear on screen, but it appears blank when I run the program.

#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>


using namespace std;

struct GLPoint
{
  GLint x;
  GLint y;
};


void init(void) 
{
   glClearColor (1.0, 1.0, 1.0, 0.0);
   glShadeModel (GL_SMOOTH);
}


void display(void)
{
   int x;
   int y; 
   int x1;
   int y1;
   int x2;
   int y2;
   int x3;
   int y3;
   int x4;
   int y4;
   x1 = x;
   y1 = y;
   x2 = x +100;
   y2 = y;
   x3 = x;
   y3 = y + 75;
   x4 = x + 100;
   y4 = y + 75;
   glClear (GL_COLOR_BUFFER_BIT);
   glColor3f(0.0, 0.0, 0.0);
   glBegin(GL_QUADS);
   glVertex2i(x1, y1 );
   glVertex2i(x2, y2 );
   glVertex2i(x3, y3 );
   glVertex2i(x4, y4 );
   glEnd();

 while(y <= 525)
    {
     while(x <= 700)
      {
        x = x + 100;

      glBegin(GL_QUADS);
      glVertex2i(x1, y1 );
      glVertex2i(x2, y2 );
      glVertex2i(x3, y3 );
      glVertex2i(x4, y4 );
      glEnd();
      }
      y = y + 75;
      x = 0;
      glBegin(GL_QUADS);
      glVertex2i(x1, y1 );
      glVertex2i(x2, y2 );
      glVertex2i(x3, y3 );
      glVertex2i(x4, y4 );
      glEnd();
     }
glFlush();
}

void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0);
         break;
   }
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (800, 600); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}
int x;    // Not initialising x and y.
   int y; 
   int x1;
   int y1;
   int x2; 
   int y2;
   int x3;
   int y3;
   int x4;
   int y4;
   x1 = x;
   y1 = y;
   x2 = x +100;
   y2 = y;
   x3 = x;
   y3 = y + 75;
   x4 = x + 100;
   y4 = y + 75;

@OP
You are assigning x and y to x1 and y1. But x and y are uninitialized.

Don't you just love simple logic errors that you miss -__-
Thanks a lot.

Now just need to figure how to make the rectangles clickable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.