here is code that should create a grid based on the inputted number of rows and columns, the problem is its not printing the entire grid for example for a 3 X 3 grid it will draw to the screen this
|||_
|||_
|||_
i cant figure out why its not printing the whole grid
here is my code
#include <Gl/glut.h>
#include <iostream.h>
#include <stdlib.h>
#define winH 480
#define winW 640
int window,rows=0,cols=0;
int north[50][50],east[50][50];
void init(void)
{
glViewport(0,0,winW,winH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,100.0,0.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0,0.0,0.0,0.0);
}
void keypress(unsigned char key, int x, int y)
{
if (key==27)
{
glutDestroyWindow(window);
exit(0);
}
}
void idle(void)
{
for(int x=0;x<rows;x++){
for(int y=0;y<cols;y++){
if(x>-1 && y>-1)
north[x][y]=1;
else north[x][y]=0;
if(x>-1 && y>-1)
east[x][y]=1;
else east[x][y]=0;
}
}
glutPostRedisplay();
}
void gl_Draw(void)
{
int x1,x2,x3,x4;
int y1,y2,y3,y4;
int i,j;
glClear(GL_COLOR_BUFFER_BIT);
for(i=0,x1=30,x2=34,x3=30,x4=30;i<rows+1;i++,x1+=4,x2+=4,x3+=4,x4+=4){
for(j=0,y1=20,y2=20,y3=25,y4=20;j<cols+1;j++,y1+=5,y2+=5,y3+=5,y4+=5){
if(north[i][j]==1 && east[i][j]==1)
{
glBegin(GL_LINES);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glVertex2i(x3,y3);
glVertex2i(x4,y4);
glEnd();
}
}
}
glutSwapBuffers();
}
void main (int argc,char** argv)
{
cout<<"Welcome to the maze"<<endl<<endl;
cout<<"Enter in the rows:";
cin>>rows;
cout<<endl;
cout<<"Enter in the columns:";
cin>>cols;
cout<<endl;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(winW,winH);
glutInitWindowPosition(100,100);
window=glutCreateWindow("Project1-The Maze");
glutDisplayFunc(&gl_Draw);
glutIdleFunc(&idle);
glutKeyboardFunc(&keypress);
init();
glutMainLoop();
}