Create Line at CodeBlocks

 

1. Source Code

#include<GL/glut.h>

void renderScene(void);
void setup();
void myInit(void);

int main (int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
    glutInitWindowSize(400,400);
    glutCreateWindow("5302410121_Tugas 2");
    glutInitWindowPosition(100,50);
    setup();
    glutDisplayFunc(renderScene);
    glutMainLoop();

    return 0;
}

void setup()
{
    glClearColor(0.5f,0.0f,0.5f,0.5f);
    glColor3f(0.0f, 1.75f, 1.0f);
    glPointSize(2.0);
    gluOrtho2D(0.0,500.0,0.0,500.0);
}

void renderScene(void)
{
    int x;
    float x0,x1,b,y1,y0;
    float y=0;
    x0=10;
    x1=400;
    y0=10;
    y1=450;
    float m=(y1-y0)/(x1-x0);
    b=y1-(m*x1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POINTS);
    glVertex2i(x0,y0);
    glEnd();

    glBegin(GL_POINTS);
    glVertex2i(x1,y1);
    glEnd();
    for(x=x0; x<x1; x++)
    {
        y=(m*x)+b;
        glBegin(GL_POINTS);
        glVertex2i(x,y);
        glEnd();
    }
    glFlush();
}
  
2. Setting 

Komentar