GL_LINES

Hi, I’m new to OpenGL.
I have a problem: usig c++ Builder 5.0, I can’t draw lines unsing:

glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-0.5f, -0.3f);
glVertex2f(0.5f, 0.3f);
glEnd();

What I have to do?

(I’m sorry for my English, but I am Italian)

Nothing wrong with that piece of code, so you have to show more. How do you set up the window? The modelview and projection matrix? Any other states enabled?

Getting a line on the screen involves more than just sending the vertices.

Here the code:

void __fastcall TForm1::OpenGLPanel1Paint(TObject *Sender)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLineWidth(10.0);
glBegin(GL_LINES);
//vertex 1/2 for one line
glColor3f( 0.0f, 1.0f, 0.0f);
glVertex2f(-0.5f, -0.3f);
//vertex 2/2 for one line

    glVertex2f(0.5f, 0.3f);

glEnd();
glFlush();
}

void __fastcall TForm1::OpenGLPanel1Resize(TObject *Sender)
{
glViewport(0,0,(GLsizei)OpenGLPanel1->Width,(GLsizei)OpenGLPanel1->Height);
}

void __fastcall TForm1::OpenGLPanel1Init(TObject *Sender)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
glMatrixMode(GL_MODELVIEW);
}

And where do you create the rendering context? More than what you posted is required to get an OpenGL program running.

I have downloaded the OpenGL_DP libraries form the net, it creates an OpenGLPanel and now on you can draw anything. For example the same code I’ve posted with
glBegin(GL_POLYGON) works very well. It is only GL_LINES that doesn’t work.

Ok, I suppose that library takes care of the rendering context and all that stuff then.

If you add a third vertex, and replace GL_LINES with GL_POLYGON, does it work then? Or do you mean that another program but with similar code works?

What happens if you don’t change line width and don’t enable line smooth?

Now it works! I don’t know why, but it works.