为什么一定要#include "glos.h"?

znr 2003-04-13 08:31:49
我用VC++6.0,最初先调试了来自BBS水木清华站的OPENGL源代码,多以
#include "glos.h"
#include <GL/gl.h>
#include <GL/glaux.h>
#include "windows.h" 为头文件.
我将其改为
#include <windows.h>
#include <GL/gl.h>
#include <GL/glaux.h> 后,运行成功.

举例一个源代码如下:
//////////////////////////////////////////////////////////////////
//weitu.cpp
#include <windows.h>
#include <gl/gl.h>
#include <gl/glaux.h>

void myinit(void);
void CALLBACK display(void);
void CALLBACK reshape(GLsizei w,GLsizei h);
//定义字符位图,从下到上(即第一个数据是字模的最下一行,依次类推):
// 11111111
// 11111111
// 11000011
// 11000011
// 11000011
// 11111111
// 11111111
// 11000011
// 11000011
// 11000011
// 11111111
// 11111111
//组成一个 8 字
GLubyte rasters[12]={0xff,0xff,0xc3,0xc3,0xc3,0xff,0xff,
0xc3,0xc3,0xc3,0xff,0xff};

void myinit(void)
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(0,0,500,500);
auxInitWindow("sample1");
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);

//描述位图数据在计算机内存中的存储方式,不必深究
glPixelStorei(GL_UNPACK_ALIGNMENT,1);

}

void CALLBACK reshape(GLsizei w,GLsizei h)
{

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//先定义红色填充:
glColor3f(1.0,0.0,1.0);
glRasterPos2i(100,200);
//在2个不同位置绘制 8 (紫色)
glBitmap(8,12,0.0,0.0,20.0,20.0,rasters);
glBitmap(8,12,0.0,0.0,20.0,20.0,rasters);

//绘制另一个 8 (黄色)
glColor3f(1.0,1.0,0.0);
glRasterPos2i(150,200);
glBitmap(8,12,0.0,0.0,0.0,0.0,rasters);

glFlush();
}
void main(void)
{
myinit();

auxReshapeFunc(reshape);
auxMainLoop(display);
}
//end of sample
///////////////////////////////////////////////////////

现在,我开始调试<<OpenGL基础图形编程>>中的源代码,多以
#include "glos.h"
#include <GL/gl.h>
#include <GL/glaux.h>为头文件.
我将其改为
#include <windows.h>
#include <GL/gl.h>
#include <GL/glaux.h> 后,编译出错,为什么?

举例一个源代码如下:
//位图字符例程

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


void myinit(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
void CALLBACK display(void);

GLubyte rasters[12] = {
    0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc,
    0xfc, 0xc0, 0xc0, 0xc0, 0xff, 0xff};

void myinit(void)
{
  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
  glClearColor (0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
}

void CALLBACK display(void)
{
  glColor3f (1.0, 0.0, 1.0);
  glRasterPos2i (100, 200);
  glBitmap (8, 12, 0.0, 0.0, 20.0, 20.0, rasters);
  glBitmap (8, 12, 0.0, 0.0, 0.0, 0.0, rasters);
  glColor3f (1.0, 1.0, 0.0);
  glRasterPos2i (150, 200);
  glBitmap (8, 12, 0.0, 0.0, 0.0, 0.0, rasters);

  glFlush();
}

void CALLBACK myReshape(GLsizei w, GLsizei h)
{
  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho (0, w, 0, h, -1.0, 1.0);
  glMatrixMode(GL_MODELVIEW);
}

void main(void)
{
  auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
  auxInitPosition (0, 0, 500, 500);
  auxInitWindow ("Bitmap");
  myinit();
  auxReshapeFunc (myReshape);
  auxMainLoop(display);
}

//以上程序运行结果是显示三个相同的字符F。
//OpenGL函数库只提供了最底层操作,即用glRasterPos*()和glBitmap()
//在屏幕上定位和画一个位图。

为什么一定要#include "glos.h"? 而"glos.h"又不在OPENGL的开发库中,
教程中对"glos.h"的介绍,远不如gl.h,glu.h,glut.h,glaux.h多.

我在WINXP里,也没有找到"glos.h".还要上网去下载"glos.h"吗?
...全文
1109 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
znr 2003-04-26
  • 打赏
  • 举报
回复
我结帖
谢谢maplexp(老猪) 100分
znr 2003-04-24
  • 打赏
  • 举报
回复
首先,感谢你的帮助。
是程序中每一行都有不可见字符,导致了编译的错误。我是从另一个文档剪贴了程序进入VC++6的,我后来在每一行首DELETE两个字符,就成功编译了。
maplexp 2003-04-14
  • 打赏
  • 举报
回复
有缩进的代码行的前面几个空的地方
znr 2003-04-14
  • 打赏
  • 举报
回复
看了老猪的回复,我收获不小.
我是新建的C++ SOURSE FILE,编译时才创建项目工作区,应该相当于空项目吧?
我以前的.CPP文件顺利运行成功,都没有#include "stdafx.h".
哪个不可见字符0xa1,在哪里呀?
maplexp 2003-04-13
  • 打赏
  • 举报
回复
glos.h的很简单,就是根据编译所在的操作系统include操作系统的头文件,在windows下是可以改成#include <windows.h>的。
你这个程序编译不过去有几个原因,我拿下来编译,你的程序里面有一个不可见字符0xa1,把它查找替换成空格,另外如果你新建项目时不是选的空项目,可能需要预编译头文件,在最前面加上#include "stdafx.h"

4,445

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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