How would you draw a vertical line in C++ using OpenGL?

  c++, drawing

This is the code for the horizontal line.Assignment6.cpp : This file contains the ‘main’ function. Program execution begins and ends there.

void drawLine(int xStart, int yStart, int xEnd, int yEnd) // draw a line from integer
{ // point (xStart, yStart) to
glBegin(GL_LINES); // (xEnd, yEnd)
glVertex2i((GLint)xStart, (GLint)yStart); // line start point
glVertex2i((GLint)xEnd, (GLint)yEnd); // line end point
glEnd();
}

void myDisplayFunction(void) // this is your function
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen

drawLine(0, 511, 511, 0);
glColor3d(0.0, 0.0, 0.0);                   // set black drawing color
setPixel(50, 400);                      // set pixel
setPixel(461, 400);                     // set pixel

glFlush();                          // send all output to display

}

void main(int argc, char** argv) // start of main program
{

glutInit(&argc, argv);                      // initialize the GLUT library
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);               // set the display mode
glutInitWindowSize(512, 512);                       // set window screen size
glutInitWindowPosition(100, 100);                   // set window position on screen
glutCreateWindow("Cierra Hawkins");             // open the screen window with title


glutDisplayFunc(myDisplayFunction);                 // register the callback function

glClearColor(1.0f, 1.0f, 1.0f, 0.0f);               // set white background color
glColor3d(0.0, 0.0, 0.0);                           // set black drawing color
gluOrtho2D(0.0, 511.0, 0.0, 511.0);                 // specify screen coordinates
                                  // bottom left = (0,0)
                                  // top right = (511, 511)

glutMainLoop();                         // go into a perpetual loop

}

Source: Windows Questions C++

LEAVE A COMMENT