codeblocks配置opengl找不到函数的奇怪问题的简单解决

问题如图,刚学计算机图形学,按照帖子配置环境,仍有错误。

无意间,调整了下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();
}

编译运行结果:

 

记录一下这个问题,蹲个解释。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心宿二、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值