问题如图,刚学计算机图形学,按照
帖子配置环境,仍有错误。
无意间,调整了下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();
}
编译运行结果:

记录一下这个问题,蹲个解释。
博主在学习计算机图形学时遇到一个问题,环境配置后代码仍有错误。通过调整#include头文件的顺序,原本的错误意外地得到了解决。代码展示了使用OpenGL和GLUT绘制图形的过程,包括'HENX'四个字母。文章记录了这个现象,期待有解释。

3365

被折叠的 条评论
为什么被折叠?



