MFC中配置OpenGL所遇到的一些问题

1.

首先需在stdafx.h中加入以下头文件

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <gl/glaux.h>

此处切记要加在
// _AFX_NO_AFXCMN_SUPPORT



//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
之间, “Microsoft Visual C++ will insert additional declarations immediately before the previous line”已提示你要这样做了

如果你将Opengl库头文件放在stdafx.h的开始或其他位置

会出现如下连接错误:

c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ';' before type 'void'
c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found

一般网上都会教你再加#include <windows.h>

那样的话又会提示“WINDOWS.H already included. ”如此以来便陷入死锁的境地。当然,非MFC的WIN32程序在使用OpenGL时确实应该将#include <windows.h>放在【opengl……】.h之前,这是必须的,但MFC则无须。

关键时opengl配置库文件要放入正确位置。

2:

在C[project]view.h中切记不要随便加入变量,因为MFC中,有好多cpp扩入了C[project]view的头文件,会出现重定义,在配置MFC 中的OpenGL环境是误看了内容,将

HGLRC m_hRC;    //Rendering Context
    CDC* m_pDC;        //Device Context

当做了全局变量放在C[project]view的头文件中,导致Link时出现错误如下:

myOpenGLView.obj : error LNK2005: "struct HGLRC__ * m_hRC" (?m_hRC@@3PAUHGLRC__@@A) already defined in myOpenGL.obj
myOpenGLView.obj : error LNK2005: "class CDC * m_pDC" (?m_pDC@@3PAVCDC@@A) already defined in myOpenGL.obj

Creating browse info file....

找到解决办法对于此类“error LNK2005……already defined”的错误,一般而言是因变量重复定义了且又被几个.c(pp)所包含

参考如:点击打开链接


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值