一.
1
void myDisplay(void)
{
// 请在此添加你的代码
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(3);
glBegin(GL_POINTS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-0.4f, -0.4f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(0.4f, 0.4f);
glEnd();
glFlush();
}
2.
void myDisplay(void)
{
// 请在此添加你的代码
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0f, 1.0f, 1.0f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f);
glVertex2f (0.0f, 1.0f);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex2f (0.8f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f);
glVertex2f (-0.8f, -0.5f);
glEnd ();
glPointSize(3);
glBegin (GL_POINTS);
glColor3f (1.0f, 0.0f, 0.0f);
glVertex2f (-0.4f, -0.4f);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex2f (0.0f, 0.0f);
glColor3f (0.0f, 0.0f, 1.0f);
glVertex2f (0.4f, 0.4f);
glEnd ();
glFlush();
}
3. void myDisplay(void)
{
// 请在此添加你的代码
/********** Begin ********/
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0f, 0.0f, 0.0f);
glRectf(25.0, 25.0, 75.0, 75.0);
glPointSize(10);
glBegin (GL_POINTS);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex2f (0.0f, 0.0f);
glEnd ();
//LineDDA(0, 0, 200, 300);
glBegin (GL_LINES);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex2f (100.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex2f (180.0f, 240.0f);
glEnd ();
/********** End **********/
glFlush();
}
void Init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}
4.
void LineDDA(int x0,int y0,int x1,int y1/*,int color*/)
{
int x, dy, dx, y;
float m;
dx=x1-x0;
dy=y1-y0;
m=dy/dx;
y=y0;
glColor3f (1.0f, 1.0f, 0.0f);
glPointSize(1);
for(x=x0;x<=x1; x++)
{
glBegin (GL_POINTS);
glVertex2i (x, (int)(y+0.5));
glEnd ();
y+=m;
}
}
void myDisplay(void)
{
// 请在此添加你的代码
/********** Begin ********/
LineDDA( 0, 0, 200,300 );
/********** End **********/
glFlush();
}
void Init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}
5.
void MidPLine(int x1, int y1, int xn, int yn)
{
// 请在此添加你的代码
int dx, dy,dt,db,d,x,y;
dx = xn - x1;
dy = yn - y1;
d = dx - 2*dy;
dt = 2*dx - 2*dy;
db = -2*dy;
x = x1, y = y1;
glColor3f(0.0f,3.0f,0.0f);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd;
while(x < xn){
if(d < 0){
x ++;
y ++;
d += dt;
}
else{
x ++;
d += db;
}
glBegin (GL_POINTS);
glVertex2i ((int)(x), (int)(y));
glEnd ();
}
glFlush();
}
void myDisplay(void)
{
// 请在此添加你的代码
/********** Begin ********/
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
MidPLine( 10, 50, 300, 260);
/********** End **********/
glFlush();
}
void Init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
}