问题如图,刚学计算机图形学,按照帖子配置环境,仍有错误。
无意间,调整了下include的顺序,,,emmm,居然解决了???
原来的代码:
#include <gl\glut.h>
#include<windows.h>
void draw() {
double x=(0.25+0.5)/2;//剧中
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.1, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.8+x, -0.005);
glVertex2f(-0.9+x, -0.005);
glVertex2f(-0.9+x, -0.095 );
glVertex2f(-0.8+x, -0.095);
glEnd();
//H
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.6+x, -0.005);
glVertex2f(-0.6+x, -0.095);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.7+x, -0.05);
glVertex2f(-0.6+x, -0.05);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.7+x, -0.005);
glVertex2f(-0.7+x, -0.095);
glEnd();
//E
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.4+x, -0.005);
glVertex2f(-0.5+x, -0.005);
glVertex2f(-0.5+x, -0.095);
glVertex2f(-0.4+x, -0.095);
glEnd();
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.4+x, -0.05);
glVertex2f(-0.5+x, -0.05);
glEnd();
//N
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.2+x, 0.0);
glVertex2f(-0.2+x, -0.1);
glVertex2f(-0.3+x, 0.0);
glVertex2f(-0.3+x, -0.1);
glEnd();
//X
glColor3f(0.5, 0.0, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(x, 0);
glVertex2f(-0.1+x, -0.1);
glEnd();
glColor3f(0.5, 0.0, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.1+x, 0.0);
glVertex2f(x, -0.1);
glEnd();
glColor3f(0, 0.9, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2f(0.1+x, 0.0);
glVertex2f(0.1+x, -0.1);
glVertex2f(0.2+x, -0.1);
glVertex2f(0.2+x, 0);
glEnd();
glFlush();
}
void reshape(int x, int y) {
int dis = x > y ? y : x; //取小的
glViewport(0, 0, dis, dis);
}
void main() {
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
glutCreateWindow("chen");
glutDisplayFunc(draw);
glutMainLoop();
}
后来的代码调整了引入的顺序:
#include<windows.h>
#include <gl\glut.h>
void draw() {
double x=(0.25+0.5)/2;//剧中
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.1, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.8+x, -0.005);
glVertex2f(-0.9+x, -0.005);
glVertex2f(-0.9+x, -0.095 );
glVertex2f(-0.8+x, -0.095);
glEnd();
//H
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.6+x, -0.005);
glVertex2f(-0.6+x, -0.095);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.7+x, -0.05);
glVertex2f(-0.6+x, -0.05);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.7+x, -0.005);
glVertex2f(-0.7+x, -0.095);
glEnd();
//E
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.4+x, -0.005);
glVertex2f(-0.5+x, -0.005);
glVertex2f(-0.5+x, -0.095);
glVertex2f(-0.4+x, -0.095);
glEnd();
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.4+x, -0.05);
glVertex2f(-0.5+x, -0.05);
glEnd();
//N
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.2+x, 0.0);
glVertex2f(-0.2+x, -0.1);
glVertex2f(-0.3+x, 0.0);
glVertex2f(-0.3+x, -0.1);
glEnd();
//X
glColor3f(0.5, 0.0, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(x, 0);
glVertex2f(-0.1+x, -0.1);
glEnd();
glColor3f(0.5, 0.0, 0.5);
glBegin(GL_LINE_STRIP);
glVertex2f(-0.1+x, 0.0);
glVertex2f(x, -0.1);
glEnd();
glColor3f(0, 0.9, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2f(0.1+x, 0.0);
glVertex2f(0.1+x, -0.1);
glVertex2f(0.2+x, -0.1);
glVertex2f(0.2+x, 0);
glEnd();
glFlush();
}
void reshape(int x, int y) {
int dis = x > y ? y : x; //取小的
glViewport(0, 0, dis, dis);
}
void main() {
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
glutCreateWindow("chen");
glutDisplayFunc(draw);
glutMainLoop();
}
编译运行结果:
记录一下这个问题,蹲个解释。