I have created a 3D Mesh using glut. The code is as below. My problem here is whenever I try changing y-axis translation of any point either it doesn’t change or it isnt visible. But when I change y-axis of a set of points as given in the line-comment it works.
#include <GL/glut.h>
#include <stdio.h>
void init(void)
{
glClearColor(0,0,0,0);
}
void idleFunction(void)
{
glutPostRedisplay();
}
void DrawCube(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,-6.5);
glPointSize(2.0);
for(float i=-2.0;i<=2.0;i+=0.05)
for(float j=-1.0;j<=4.0;j+=0.1)
{
// if(i>=-0.5 &&i<=-0.4 && j>1.0 &&j<1.26){ *****This works*****
if (i==-1.8){ // ******This doesn't******
glBegin(GL_POINTS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(i,-0.2f,j);
glEnd();
}
else
{
glBegin(GL_POINTS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( i,-1.0f, j);
glEnd();
}
}
glFlush();
}
void reshape(int x, int y)
{
glViewport(0,0,x,y); //Use the whole window for rendering
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50,(float)x/(float)y,3.5,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
//we initizlilze the glut. functions
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(DrawCube);
glutReshapeFunc(reshape);
glutIdleFunc(idleFunction);
glutMainLoop();
return 0;
}