opengl编译问题,解决重奖(microsoft对opengl的打压)

kesoft 2003-11-29 03:36:06
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdlib.h>
#include "aux.h"

/* Clear the screen. Set the current color to white.
* Draw the wire frame cube.
*/
void display (void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
glTranslatef (0.0, 0.0, -5.0); /* viewing transformation */
glScalef (1.0, 2.0, 1.0); /* modeling transformation */
auxWireCube(1.0); /* draw the cube */
glFlush();
}

void myinit (void) {
glShadeModel (GL_FLAT);
}

/* Called when the window is first opened and whenever
* the window is reconfigured (moved or resized).
*/
void myReshape(int w, int h)
{
glMatrixMode (GL_PROJECTION); /* prepare for and then */
glLoadIdentity (); /* define the projection */
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); /* transformation */
glMatrixMode (GL_MODELVIEW); /* back to modelview matrix */
glViewport (0, 0, w, h); /* define the viewport */
}

/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
auxInitPosition (0, 0, 500, 500);
auxInitWindow (argv[0]);
myinit ();
auxReshapeFunc (myReshape);
auxMainLoop(display);
}

-----------------------------------

编译是,输出为:
------ 已启动生成: 项目: cube, 配置: Debug Win32 ------
正在编译...
cube.cpp
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : error C2144: 语法错误 : “void”的前面应有“;”
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : error C2501: “WINGDIAPI” : 缺少存储类或类型说明符
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : error C2146: 语法错误 : 缺少“;”(在标识符“glAccum”的前面)
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2144: 语法错误 : “void”的前面应有“;”
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2501: “WINGDIAPI” : 缺少存储类或类型说明符
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2086: “int WINGDIAPI” : 重定义
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : 参见“WINGDIAPI”的声明
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2146: 语法错误 : 缺少“;”(在标识符“glClearIndex”的前面)
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2182: “APIENTRY” : 非法使用“void”类型
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1166) : error C2086: “int APIENTRY” : 重定义
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : 参见“APIENTRY”的声明
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2144: 语法错误 : “void”的前面应有“;”
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2501: “WINGDIAPI” : 缺少存储类或类型说明符
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2086: “int WINGDIAPI” : 重定义
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : 参见“WINGDIAPI”的声明
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2146: 语法错误 : 缺少“;”(在标识符“glClearStencil”的前面)
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2182: “APIENTRY” : 非法使用“void”类型
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1167) : error C2086: “int APIENTRY” : 重定义
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : 参见“APIENTRY”的声明
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1168) : error C2144: 语法错误 : “void”的前面应有“;”
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1168) : error C2501: “WINGDIAPI” : 缺少存储类或类型说明符
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1168) : error C2086: “int WINGDIAPI” : 重定义
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1152) : 参见“WINGDIAPI”的声明
.
.
.
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1169) : error C2144: 语法错误 : “void”的前面应有“;”
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1169) : error C2501: “WINGDIAPI” : 缺少存储类或类型说明符
d:\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\gl\GL.h(1169) : fatal error C1003: 错误计数超过 100;正在停止编译

生成日志保存在“file://d:\我的项目\OpenGL\cube\Debug\BuildLog.htm”中
cube - 102 错误,0 警告
---------------------- 完成 ---------------------

生成: 0 已成功, 1 已失败, 0 已跳过

-----------------------------------

用的是vs.net 2003,输出说gl.h出错,这难道要我改gl.h?
各位遇到过这种问题没?怎么解决的?
如果是gl.h的问题,只能说明microsoft对opengl实行打压,这样会失去人心的
...全文
789 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluecrystle 2010-06-11
  • 打赏
  • 举报
回复
我想问问为什么在前边加上<windows.h>文件就可以了呢?请哪位高手可以指点一下啊?
kesoft 2003-12-03
  • 打赏
  • 举报
回复
解决了,谢谢各位,是头文件的次序搞错了,windows.h必须放在gl.h等的前面
uuq 2003-12-02
  • 打赏
  • 举报
回复
可以到http://debug.vimgate.com/opengl/下载
潘李亮 2003-12-02
  • 打赏
  • 举报
回复
我记得Microsoft在文档里明确的说了
应该在#include <gl/gl.h>前#include<windows.h>

至于各位说的连接问题。我从来没有遇见过,
我一般都import了这几个库:
glu32.lib
opengl32.lib
至于glaux我是从来不用的。
太老了。
jfm_super 2003-11-30
  • 打赏
  • 举报
回复
从msdn的帮助中看到wgl系列的函数在wingdi.h中,.net环境下,不知道为什么不可以。
我看了stdafx.h中包含有windows.h的头文件。


/ stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//

#pragma once


#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料
// Windows 头文件:
#include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

// TODO: 在此处引用程序要求的附加头文件

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


仍然有如下错误:

openglwin32 error LNK2019: 无法解析的外部符号 __imp__wglCreateContext@4 ,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用

Leon8086 2003-11-30
  • 打赏
  • 举报
回复
那是个link错误,可能还需要什么连接库。
yisan 2003-11-29
  • 打赏
  • 举报
回复
wgl系列函数放在了<windows.h>中,你要使用就必须包含这个.
jlcclyc 2003-11-29
  • 打赏
  • 举报
回复
#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#include "aux.h"
在程序前面加上这些东西,在我机器上通过,没任何问题。
抬头看路 2003-11-29
  • 打赏
  • 举报
回复
第一个问题,你应该在#include <gl/gl.h>前面加上#include<windows.h>
jfm_super 2003-11-29
  • 打赏
  • 举报
回复
为什么还有如下错误:
OpenGlApp error LNK2019: 无法解析的外部符号 __imp__wglDeleteContext@4 ,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
OpenGlApp error LNK2019: 无法解析的外部符号 __imp__wglMakeCurrent@8 ,该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
OpenGlApp error LNK2019: 无法解析的外部符号 __imp__wglCreateContext@4 ,该符号在函数 "void __cdecl setupPixelFormat(struct HDC__ *)" (?setupPixelFormat@@YAXPAUHDC__@@@Z) 中被引用
OpenGlApp fatal error LNK1120: 3 个无法解析的外部命令


我碰到这个问题,希望指点。
kesoft 2003-11-29
  • 打赏
  • 举报
回复
加过了,没用,有人用vs.net 2003吗?
好像2003里面好多东西都变了,比如不支持libci.lib运行时库
如果有人在2003里编译通过了opengl的程序,给我看看,好吗?
火云洞红孩儿 2003-11-29
  • 打赏
  • 举报
回复
有必要打压opengl吗?DX与opengl又不冲突…
火云洞红孩儿 2003-11-29
  • 打赏
  • 举报
回复
lib 里加opengl32.lib glu32.lib glaux.lib
kesoft 2003-11-29
  • 打赏
  • 举报
回复
有哪个地方可以下载新版本的gl.h(或sdk)?

8,303

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧