guys anything wrong with the following code to draw 3D line

glLineWidth(2.5);
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3f(-200.0, -5.0, 0.5);
glVertex3f(200.0,-5.0,0.5);
glEnd();

Code looks fine. Is it not working?

nop!
a blank screen comes as output

You will need to post more of your code.

#include<stdio.h>
#include<glut.h>

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glLineWidth(2.5);
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3f(10.0, 5.0, 0.5);
glVertex3f(200.0,50.0,0.5);
glEnd();
glFlush();
}

void myinit()
{
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
void myReshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)h/(GLfloat)w,-2.0,2.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(“ATRY”);
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
myinit();
glutMainLoop();
}

Don’t load the identity matrix in your display function, as it will reset the orthographic projection if you don’t resize the window.

First of all the background color you set is not being displayed.
This is because you asked for double buffering but never call glutSwapBuffers.
It must be called at the end of your display() routine.
Set the ClearColor to something other than black or white for debugging purposes.
Once you are SURE the window is being cleared to the correct color, change it back to black or white.

The call to gluOrtho2D in your myInit routine is not doing anything because
it’s being overridden by the glOrtho calls in your ReShape function. In fact,
the only line that’s doing anything in your myInit routine is the call to glClearColor.
You can comment out all the other lines in myInit.

The glOrtho calls in myReshape are setting the bounds of your window.
Those calls set the x bounds from -2.0 to +2.0.
You are trying to draw a line with x coordinates from 10 to 200.
Of course it’s not going to show up. It’s totally outside the bounds of the window.
Try commenting out the glOrtho calls and replacing them with -

glOrtho (0.0, 300.0, 0.0, 300.0, -10.0, 10.0);

It worked for me. After that works for you, you can try to get more sophisticated with the glOrtho call.

:)thanks it worked!