#include<windows.h>
#include <gl/glut.h>
struct GLPoint{
GLint x, y;
};
GLPoint pt; //全局变量,一定要在这里,不能再main()函数中。
const GLint screenWidth = 100;
const GLint screenHeight = 100;
void myDisplay(void);
void myInit(void);
void moveTo(GLint, GLint);
void LineTo(GLint, GLint);
int main(int argc, char ** argv){
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutInitWindowPosition(100,150);
glutCreateWindow("MoveTo & LineTo Function.");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
void LineTo(GLint x , GLint y){
glBegin(GL_LINES);
glVertex2i(pt.x,pt.y);
glVertex2i(x,y);
glEnd();
glFlush();
pt.x = x;
pt.y = y;
}
void moveTo(GLint x, GLint y){
pt.x = x;
pt.y = y;
}
void myDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
moveTo(0,0);
LineTo(100,100);
}
void myInit(void){
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
#include <gl/glut.h>
struct GLPoint{
GLint x, y;
};
GLPoint pt; //全局变量,一定要在这里,不能再main()函数中。
const GLint screenWidth = 100;
const GLint screenHeight = 100;
void myDisplay(void);
void myInit(void);
void moveTo(GLint, GLint);
void LineTo(GLint, GLint);
int main(int argc, char ** argv){
// (0,0) 到 (100,100)的直线
glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutInitWindowPosition(100,150);
glutCreateWindow("MoveTo & LineTo Function.");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
void LineTo(GLint x , GLint y){
glBegin(GL_LINES);
glVertex2i(pt.x,pt.y);
glVertex2i(x,y);
glEnd();
glFlush();
pt.x = x;
pt.y = y;
}
void moveTo(GLint x, GLint y){
pt.x = x;
pt.y = y;
}
void myDisplay(void){
glClear(GL_COLOR_BUFFER_BIT);
moveTo(0,0);
LineTo(100,100);
}
void myInit(void){
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}