   A Grid of Cylinders
I want to generate a grid (20 x 20) of cylinders.below is  the code.Problem is the the output is not a grid, rather a row of 40 cylinders.I want each row to have 20 cylinders and there should be 20 such rows. Where can I be problem. #define SIZE  25#include <GL/glut.h>#include <stdio.h>#include <stdlib.h>GLuint startList;float left = -20;float right = 20;float  bottomnear = 20.0f;float  bottomfar  = -20.0f;int size = SIZE; float  color[5][3] = { {1.0f, 0.0f, 0.0f}, {0.0f,1.0f,0.0f},  {0.0f,0.0f,1.0f},  {1.0f,1.0f,1.0f},  {1.0f,0.0f,0.0f} };int  NoofCyclinders = NOOFCYCLINDERS;GLUquadricObj *qobj;void init(void) {   glClearColor(0.0, 0.0, 0.0, 0.0);   glEnable(GL_DEPTH_TEST);   startList = glGenLists(4);   qobj = gluNewQuadric();   gluQuadricDrawStyle(qobj, GLU_FILL); /* flat shaded */   gluQuadricNormals(qobj, GLU_SMOOTH);   glNewList(startList+1, GL_COMPILE); gluCylinder(qobj, 0.4, 0.4, 2.0, 25, 15);   glEndList();}void display(void){   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   glShadeModel (GL_SMOOTH);   glColor3f(1,0,0);   for(int z= bottomfar ; z< bottomnear; z+=1)   {for(int x= left ; x< right; x+=1){glPushMatrix();printf("x = %d, z = %d\n",x, z);glTranslatef(x,0,z);//glColor3f(color[][0],color[z][1],color[z][2]);glRotatef(150.0, 1.0, 0.0, 0.0);glCallList(startList+1);glPopMatrix();}  }  glFlush();}void reshape (int w, int h){   glViewport(0, 0, (GLsizei) w, (GLsizei) h);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   if (w <= h) glOrtho(-size, size, -size*(GLfloat)h/(GLfloat)w,   size*(GLfloat)h/(GLfloat)w, -size, size);   else glOrtho(-size*(GLfloat)w/(GLfloat)h,    size*(GLfloat)w/(GLfloat)h, -size, size, -size, size);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();}int main(int argc, char** argv){   glutInit(&argc, argv);   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);   glutInitWindowSize(500, 500);    glutInitWindowPosition(100, 100);   glutCreateWindow(argv[0]);   init();   glutDisplayFunc(display);    glutReshapeFunc(reshape);   glutKeyboardFunc(keyboard);   glutMainLoop();   return 0;}
  You are looking down the Z-axis, so you are actually drawing 40 rows, but they are on top of each other, completely obscuring each other because of the ortographic projection.Change this line: glTranslatef(x,0,z), to glTranslatef(x,z,0) instead. When you want to move the cylinder up and down the screen with your current transformations, Y needs to be changed, not Z.   ;  Thanks Erik. I want to create such an image .How can we implement  cylinders with such an orientation.Also, Like in this image, I want plane on which the cylinders are kept. Following is the code, But I am not getting the required  planeglPushMatrix( );glTranslatef(0.0,1.0f,0.0);glRotatef(20.0f,1.0f,0.0f,0.0f);glBegin(GL_QUADS);glVertex3f(-20.0f,0.0f,20.0f);glVertex3f(20.0f,0.0,20.0f);glVertex3f(20.0f,0.0f,-20.0f);glVertex3f(-20.0f,0.0f,-20.0f);glEnd();glPopMatrix( );;  Hey guys, could you plz help for my graphics project?I want to prepare a page using mesh... and it should have the flipping effect... i m stuck in this from so long... who ever knws just help me out as soon as possible..i m using visual c++ with opengl;  For that you shouldn't use ortographic projection (glOrtho), but rather perspective projection (gluPerspective). You could check out for example the NeHe tutorials for help on displaying shapes with perspective and a camera.[Edited by - Erik Rufelt on August 7, 2010 7:26:56 PM]