CodeBlocks新建GLUT 项目,测试程序出现 函数 undefined reference to ‘imp__glViewport’错误

codeBlocks配置好opengl 后新建一个 GLUT工程,会自动在main函数下生产一个测试程序。

如果出现编译错误,函数未定义

||=== Build: Debug in test3 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `resize':|
undefined reference to `_imp__glViewport'|
undefined reference to `_imp__glMatrixMode'|
undefined reference to `_imp__glLoadIdentity'|
undefined reference to `_imp__glFrustum'|
undefined reference to `_imp__glMatrixMode'|
undefined reference to `_imp__glLoadIdentity'|
 

解决办法,在代码第一行,加上宏定义 #define _STDCALL_SUPPORTED,代码前几行如下图

#define _STDCALL_SUPPORTED
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>

static int slices = 16;
static int stacks = 16;

/* GLUT callback Handlers */

static void resize(int width, int height)
{
    const float ar = (float) width / (float) height;

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}

重新编译运行,结果如下图

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值