1

I am trying to draw line in c# using sharpgl but when i compile the code it gives me the console with full of white color not the line,how to solve this this problem or is there any mistake in my code.Here is the code.

private static int width = 400, height = 300;
static void Main(string[] args)
{

Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_SINGLE | Glut.GLUT_RGB);
Glut.glutInitWindowSize(width, height);
Glut.glutCreateWindow("OpenGL Tutorial");

init();
Glut.glutDisplayFunc(OnDisplay);
Glut.glutMainLoop();
}
private static void OnDisplay()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glColor3f(0.0f, 0.4f, 0.2f);
Gl.glBegin(Gl.GL_LINES);

Gl.glVertex2i(180, 15);
Gl.glVertex2i(10, 145);
Gl.glEnd();
Gl.glFlush();
}
static void init()
{
Gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glOrtho(0.0, 200.0, 0.0, 1.0, -1.0, 1.0);

}
Sandip
  • 981
  • 1
  • 6
  • 22
Adeel Khan
  • 13
  • 1
  • 6

1 Answers1

3

Your line is entirely outside the visible coordinate range. The call to glOrtho() specifies the range of coordinates that are mapped to your window rectangle:

Gl.glOrtho(0.0, 200.0, 0.0, 1.0, -1.0, 1.0);

The 3rd and 4th parameter of this call define bottom and top, i.e. the range for the y-coordinates. Therefore, the visible range of y-coordinates will be [0.0, 1.0].

In the vertices specified for your line:

Gl.glVertex2i(180, 15);
Gl.glVertex2i(10, 145);

both vertices are far outside this range, having y-coordinates of 15 and 145.

You should be able to see the line if you extend the range of the y-coordinates. For example, using the same range as for the x-coordinates:

Gl.glOrtho(0.0, 200.0, 0.0, 200.0, -1.0, 1.0);
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133