achint.akv

04-09-2011, 01:27 PM

I am an OpenGl newbie. Can someone please help.

Can someone find an error in this code to draw a grid in the xz plane in 3D

I am always getting a blank window.

My other programs work perfectly fine(even those involving 3D)

#include<GL/glut.h>

#define N 20

#define dx 50;

#define dz 50;

GLint x[N],z[N];

GLint i,j;

void display()

{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

x[0]=0;

z[0]=0;

for(i=1;i<N;i++)

x[i]=x[0]+dx;

for(i=1;i<N;i++)

z[i]=z[0]+dz;

glColor3f(0.0,0.0,1.0);

for(i=0;i<N;i++)

{

glBegin(GL_LINE_STRIP);

for(j=0;j<N;j++)

glVertex3f(x[i],x[i],z[j]);

glEnd();

}

glColor3f(0.0,0.0,1.0);

for(i=0;i<N;i++)

{

glBegin(GL_LINE_STRIP);

for(j=0;j<N;j++)

glVertex3f(x[j],x[i],z[i]);

glEnd();

}

glFlush();

}

void myinit()

{

glOrtho(0,400,0,400,0,400);

glClearColor(0,0,0,1);

glEnable(GL_DEPTH_TEST);

}

void main(int argc,char** argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPT H);

//glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(200,200);

glutCreateWindow("grid");

glutDisplayFunc(display);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum(-100,100,-100,100,100,2000);

glMatrixMode(GL_MODELVIEW);

glTranslatef(-240,-150,220);

glRotatef(-30,1,0,0);

myinit();

glutMainLoop();

}

Can someone find an error in this code to draw a grid in the xz plane in 3D

I am always getting a blank window.

My other programs work perfectly fine(even those involving 3D)

#include<GL/glut.h>

#define N 20

#define dx 50;

#define dz 50;

GLint x[N],z[N];

GLint i,j;

void display()

{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

x[0]=0;

z[0]=0;

for(i=1;i<N;i++)

x[i]=x[0]+dx;

for(i=1;i<N;i++)

z[i]=z[0]+dz;

glColor3f(0.0,0.0,1.0);

for(i=0;i<N;i++)

{

glBegin(GL_LINE_STRIP);

for(j=0;j<N;j++)

glVertex3f(x[i],x[i],z[j]);

glEnd();

}

glColor3f(0.0,0.0,1.0);

for(i=0;i<N;i++)

{

glBegin(GL_LINE_STRIP);

for(j=0;j<N;j++)

glVertex3f(x[j],x[i],z[i]);

glEnd();

}

glFlush();

}

void myinit()

{

glOrtho(0,400,0,400,0,400);

glClearColor(0,0,0,1);

glEnable(GL_DEPTH_TEST);

}

void main(int argc,char** argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPT H);

//glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(200,200);

glutCreateWindow("grid");

glutDisplayFunc(display);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum(-100,100,-100,100,100,2000);

glMatrixMode(GL_MODELVIEW);

glTranslatef(-240,-150,220);

glRotatef(-30,1,0,0);

myinit();

glutMainLoop();

}