我设计了一个OPENGL图形填充程序,但为什么提示GLbyte数组是非法类型呢?求高手 附上程序

#include<gl/glut.h>
int n=0;
float a0=200,b0=200,a1=400,b1=200,a2=400,b2=400,a3=200,b3=400;
int winWidth=600,winHeight=500;
void Initial(void)
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
}
void ChangeSize(int w,int h)
{
winWidth=600,winHeight=550;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,winWidth,0.0,winHeight);
}
void Display()
{
glColor3f(1.0f,1.0f,1.0f);
GLubyte fly[]=
{
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,
};
glEnable(GL_POLYGON_STIPPLE);
glPolygonStipple(fly);
glRectf(5,5,800,800);
glutSwapBuffers();
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(400,300);
glutInitWindowPosition(100,100);
glutCreateWindow("2008082269-hezhilong");
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize);
Initial();
glutMainLoop();
return 0;
}
最新回答
永不言弃

2024-04-19 06:51:55

glut.h内部:
#include <GL/gl.h>
#include <GL/glu.h>
GLbyte在gl.h文件内定义
追问
GLbtye不是glut,h自带的吗?要定义的话怎么定义?
追答
为了跨平台方便吧。所以opengl都对数据类型用宏进行定义。

既然是宏,编译找不到宏定义,自然没办法通过。
gl.h文件中已定义了
typedef signed char GLbyte;

所以你的问题只要再添加即可(下面两个头文件在你安装VC后就有了,并且其环境变量已设定好了,编译器会找到路径的)
#include
#include
追问
……你试下我的程序在你那能不能运行好吗?我按你说的改了之后还是提示GLubyte非法
追答
调试过了,不用加
#include
#include
因为glut.h既然包含这两个头文件,自然会加载进去,前提是环境路径已经配置好。
Glubyte,你在vc中右键,看能不能跳到gl.h这个头文件,如果失败,手动配置好环境。